diff --git a/addon/codemirror-colorpicker.js b/addon/codemirror-colorpicker.js index 7570c29..5610d05 100644 --- a/addon/codemirror-colorpicker.js +++ b/addon/codemirror-colorpicker.js @@ -1887,426 +1887,148 @@ var Matrix = { } }; -function weight(arr) { - var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; +function crop() { + var startX = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var startY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var width = arguments[2]; + var height = arguments[3]; - return arr.map(function (i) { - return i * num; - }); -} -function repeat(value, num) { - var arr = new Array(num); - for (var i = 0; i < num; i++) { - arr[i] = value; - } - return arr; -} + var newBitmap = createBitmap(width * height * 4, width, height); -function colorMatrix(pixels, i, matrix) { - var r = pixels[i], - g = pixels[i + 1], - b = pixels[i + 2], - a = pixels[i + 3]; + return function (bitmap) { + for (var y = startY, realY = 0; y < height; y++, realY++) { + for (var x = startX, realX = 0; x < width; x++, realX++) { + newBitmap.pixels[realY * width * realX] = bitmap.pixels[y * width * x]; + } + } - pixels[i] = matrix[0] * r + matrix[1] * g + matrix[2] * b + matrix[3] * a; - pixels[i + 1] = matrix[4] * r + matrix[5] * g + matrix[6] * b + matrix[7] * a; - pixels[i + 2] = matrix[8] * r + matrix[9] * g + matrix[10] * b + matrix[11] * a; - pixels[i + 3] = matrix[12] * r + matrix[13] * g + matrix[14] * b + matrix[15] * a; + return newBitmap; + }; } -function makeFilter(filter, F) { - - if (typeof filter == 'function') { - return filter; - } - - if (typeof filter == 'string') { - filter = [filter]; - } - - var filterName = filter.shift(); - - if (typeof filterName == 'function') { - return filterName; - } - - var params = filter; +function resize(dstWidth, dstHeight) { + return function (bitmap) { - var filterFunction = F[filterName]; + var c = Canvas.drawPixels(bitmap); + var context = c.getContext('2d'); - if (!filterFunction) { - throw new Error(filterName + ' is not filter. please check filter name.'); - } - return filterFunction.apply(filterFunction, params); -} + c.width = dstWidth; + c.height = dstHeight; -function each$1(len, callback) { - for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { - callback(i, xyIndex); - } + return { + pixels: new Uint8ClampedArray(context.getImageData(0, 0, dstWidth, dstHeight).data), + width: dstWidth, + height: dstHeight + }; + }; } -function eachXY(len, width, callback) { - for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { - callback(i, xyIndex % width, Math.floor(xyIndex / width)); - } -} +function flipV() { + return function (bitmap) { -function createRandRange(min, max, count) { - var result = []; + var width = bitmap.width; + var height = bitmap.height; + var isCenter = height % 2 == 1 ? 1 : 0; - for (var i = 1; i <= count; i++) { - var num = Math.random() * (max - min) + min; - var sign = Math.floor(Math.random() * 10) % 2 == 0 ? -1 : 1; - result.push(sign * num); - } + var halfHeight = isCenter ? Math.floor(height / 2) : height / 2; - result.sort(); + for (var y = 0; y < halfHeight; y++) { + for (var x = 0; x < width; x++) { - var centerIndex = Math.floor(count / 2); - var a = result[centerIndex]; - result[centerIndex] = result[0]; - result[0] = a; + var startIndex = (y * width + x) * 4; + var endIndex = ((height - 1 - y) * width + x) * 4; + swapColor(bitmap.pixels, startIndex, endIndex); + } + } - return result; + return bitmap; + }; } -function createRandomCount() { - return [3 * 3, 4 * 4, 5 * 5, 6 * 6, 7 * 7, 8 * 8, 9 * 9, 10 * 10].sort(function (a, b) { - return 0.5 - Math.random(); - })[0]; -} +function flipH() { + return function (bitmap) { -function createBitmap(length, width, height) { - return { pixels: new Uint8ClampedArray(length), width: width, height: height }; -} + var width = bitmap.width; + var height = bitmap.height; + var isCenter = width % 2 == 1 ? 1 : 0; -function getBitmap(bitmap, area) { - return Canvas.getBitmap(bitmap, area); -} + var halfWidth = isCenter ? Math.floor(width / 2) : width / 2; -function putBitmap(bitmap, subBitmap, area) { - return Canvas.putBitmap(bitmap, subBitmap, area); -} + for (var y = 0; y < height; y++) { + for (var x = 0; x < halfWidth; x++) { -function parseParamNumber(param) { - if (typeof param === 'string') { - param = param.replace(/deg/, ''); - param = param.replace(/px/, ''); - } - return +param; -} + var startIndex = (y * width + x) * 4; + var endIndex = (y * width + (width - 1 - x)) * 4; + swapColor(bitmap.pixels, startIndex, endIndex); + } + } -var filter_regexp = /(([\w_\-]+)(\(([^\)]*)\))?)+/gi; -function pack$1(callback) { - return function (bitmap) { - each$1(bitmap.pixels.length, function (i, xyIndex) { - callback(bitmap.pixels, i, xyIndex); - }); return bitmap; }; } -var ColorListIndex = [0, 1, 2, 3]; - -function swapColor(pixels, startIndex, endIndex) { +function rotateDegree(angle) { + var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'center'; + var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'center'; - ColorListIndex.forEach(function (i) { - var temp = pixels[startIndex + i]; - pixels[startIndex + i] = pixels[endIndex + i]; - pixels[endIndex + i] = temp; - }); -} + // const r = F.radian(angle) -function packXY(callback) { return function (bitmap) { - eachXY(bitmap.pixels.length, bitmap.width, function (i, x, y) { - callback(bitmap.pixels, i, x, y); - }); - return bitmap; - }; -} + var newBitmap = createBitmap(bitmap.pixels.length, bitmap.width, bitmap.height); + var width = bitmap.width; + var height = bitmap.height; + if (cx == 'center') { + cx = Math.floor(width / 2); + } + if (cy == 'center') { + cy = Math.floor(height / 2); + } -function createBlurMatrix() { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3; + var translateMatrix = Matrix.CONSTANT.translate(-cx, -cy); + var translateMatrix2 = Matrix.CONSTANT.translate(cx, cy); + var shear1Matrix = Matrix.CONSTANT.shear1(angle); + var shear2Matrix = Matrix.CONSTANT.shear2(angle); - var count = Math.pow(amount, 2); - var value = 1 / count; - return repeat(value, count); -} + return packXY(function (pixels, i, x, y) { + // console.log(x, y, i) + var arr = Matrix.multiply(translateMatrix, [x, y, 1]); -function convolution(weights) { - var opaque = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); + arr = Matrix.multiply(shear2Matrix, arr).map(Math.round); + arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); + arr = Matrix.multiply(translateMatrix2, arr); - return function (_ref) { - var pixels = _ref.pixels, - width = _ref.width, - height = _ref.height; + var _arr = arr, + _arr2 = slicedToArray(_arr, 2), + x1 = _arr2[0], + y1 = _arr2[1]; - var side = Math.round(Math.sqrt(weights.length)); - var halfSide = Math.floor(side / 2); + if (x1 < 0) return; + if (y1 < 0) return; + if (x1 > width - 1) return; + if (y1 > height - 1) return; - var w = width; - var h = height; - var sw = w; - var sh = h; - var dst = new Uint8ClampedArray(pixels.length); - var alphaFac = opaque ? 1 : 0; + var endIndex = (y1 * width + x1) * 4; - for (var y = 0; y < h; y++) { - for (var x = 0; x < w; x++) { - var sy = y; - var sx = x; - var dstIndex = (y * w + x) * 4; + pixels[endIndex] = bitmap.pixels[i]; + pixels[endIndex + 1] = bitmap.pixels[i + 1]; + pixels[endIndex + 2] = bitmap.pixels[i + 2]; + pixels[endIndex + 3] = bitmap.pixels[i + 3]; + })(newBitmap); + }; +} - var r = 0, - g = 0, - b = 0, - a = 0; - for (var cy = 0; cy < side; cy++) { - for (var cx = 0; cx < side; cx++) { +function rotate() { + var degree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var scy = sy + cy - halfSide; - var scx = sx + cx - halfSide; + degree = parseParamNumber(degree); + degree = degree % 360; + return function (bitmap) { - if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { - var srcIndex = (scy * sw + scx) * 4; - var wt = weights[cy * side + cx]; - r += pixels[srcIndex] * wt; - g += pixels[srcIndex + 1] * wt; - b += pixels[srcIndex + 2] * wt; - a += pixels[srcIndex + 3] * wt; // weight 를 곱한 값을 계속 더한다. - } - } - } - - dst[dstIndex] = r; - dst[dstIndex + 1] = g; - dst[dstIndex + 2] = b; - dst[dstIndex + 3] = a + alphaFac * (255 - a); - } - } - - return { pixels: dst, width: sw, height: sh }; - }; -} - -function matches(str) { - var ret = Color.convertMatches(str); - var matches = ret.str.match(filter_regexp); - var result = []; - - if (!matches) { - return result; - } - - result = matches.map(function (it) { - return { filter: it, origin: Color.reverseMatches(it, ret.matches) }; - }); - - var pos = { next: 0 }; - result = result.map(function (item) { - - var startIndex = str.indexOf(item.origin, pos.next); - - item.startIndex = startIndex; - item.endIndex = startIndex + item.origin.length; - - item.arr = parseFilter(item.origin); - - pos.next = item.endIndex; - - return item; - }).filter(function (it) { - if (!it.arr.length) return false; - return true; - }); - - return result; -} - -/** - * Filter Parser - * - * F.parseFilter('blur(30)') == ['blue', '30'] - * F.parseFilter('gradient(white, black, 3)') == ['gradient', 'white', 'black', '3'] - * - * @param {String} filterString - */ -function parseFilter(filterString) { - - var ret = Color.convertMatches(filterString); - var matches = ret.str.match(filter_regexp); - - if (!matches[0]) { - return []; - } - - var arr = matches[0].split('('); - - var filterName = arr.shift(); - var filterParams = []; - - if (arr.length) { - filterParams = arr.shift().split(')')[0].split(',').map(function (f) { - return Color.reverseMatches(f, ret.matches); - }); - } - - var result = [filterName].concat(toConsumableArray(filterParams)).map(Color.trim); - - return result; -} - -function clamp(num) { - return Math.min(255, num); -} - -function crop() { - var startX = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var startY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - var width = arguments[2]; - var height = arguments[3]; - - - var newBitmap = createBitmap(width * height * 4, width, height); - - return function (bitmap) { - for (var y = startY, realY = 0; y < height; y++, realY++) { - for (var x = startX, realX = 0; x < width; x++, realX++) { - newBitmap.pixels[realY * width * realX] = bitmap.pixels[y * width * x]; - } - } - - return newBitmap; - }; -} - -function resize(dstWidth, dstHeight) { - return function (bitmap) { - - var c = Canvas.drawPixels(bitmap); - var context = c.getContext('2d'); - - c.width = dstWidth; - c.height = dstHeight; - - return { - pixels: new Uint8ClampedArray(context.getImageData(0, 0, dstWidth, dstHeight).data), - width: dstWidth, - height: dstHeight - }; - }; -} - -function flipV() { - return function (bitmap) { - - var width = bitmap.width; - var height = bitmap.height; - var isCenter = height % 2 == 1 ? 1 : 0; - - var halfHeight = isCenter ? Math.floor(height / 2) : height / 2; - - for (var y = 0; y < halfHeight; y++) { - for (var x = 0; x < width; x++) { - - var startIndex = (y * width + x) * 4; - var endIndex = ((height - 1 - y) * width + x) * 4; - swapColor(bitmap.pixels, startIndex, endIndex); - } - } - - return bitmap; - }; -} - -function flipH() { - return function (bitmap) { - - var width = bitmap.width; - var height = bitmap.height; - var isCenter = width % 2 == 1 ? 1 : 0; - - var halfWidth = isCenter ? Math.floor(width / 2) : width / 2; - - for (var y = 0; y < height; y++) { - for (var x = 0; x < halfWidth; x++) { - - var startIndex = (y * width + x) * 4; - var endIndex = (y * width + (width - 1 - x)) * 4; - swapColor(bitmap.pixels, startIndex, endIndex); - } - } - - return bitmap; - }; -} - -function rotateDegree(angle) { - var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'center'; - var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'center'; - - // const r = F.radian(angle) - - return function (bitmap) { - var newBitmap = createBitmap(bitmap.pixels.length, bitmap.width, bitmap.height); - var width = bitmap.width; - var height = bitmap.height; - - if (cx == 'center') { - cx = Math.floor(width / 2); - } - - if (cy == 'center') { - cy = Math.floor(height / 2); - } - - var translateMatrix = Matrix.CONSTANT.translate(-cx, -cy); - var translateMatrix2 = Matrix.CONSTANT.translate(cx, cy); - var shear1Matrix = Matrix.CONSTANT.shear1(angle); - var shear2Matrix = Matrix.CONSTANT.shear2(angle); - - return packXY(function (pixels, i, x, y) { - // console.log(x, y, i) - var arr = Matrix.multiply(translateMatrix, [x, y, 1]); - - arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); - arr = Matrix.multiply(shear2Matrix, arr).map(Math.round); - arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); - arr = Matrix.multiply(translateMatrix2, arr); - - var _arr = arr, - _arr2 = slicedToArray(_arr, 2), - x1 = _arr2[0], - y1 = _arr2[1]; - - if (x1 < 0) return; - if (y1 < 0) return; - if (x1 > width - 1) return; - if (y1 > height - 1) return; - - var endIndex = (y1 * width + x1) * 4; - - pixels[endIndex] = bitmap.pixels[i]; - pixels[endIndex + 1] = bitmap.pixels[i + 1]; - pixels[endIndex + 2] = bitmap.pixels[i + 2]; - pixels[endIndex + 3] = bitmap.pixels[i + 3]; - })(newBitmap); - }; -} - -function rotate() { - var degree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - - degree = parseParamNumber(degree); - degree = degree % 360; - return function (bitmap) { - - if (degree == 0) return bitmap; + if (degree == 0) return bitmap; if (degree == 90 || degree == 270) { var newBitmap = createBitmap(bitmap.pixels.length, bitmap.height, bitmap.width); @@ -3150,172 +2872,489 @@ function stackBlurCanvasRGBA(bitmap, top_x, top_y, radius) { stackOut = stackOut.next; - yi += 4; - } - yw += width; - } + yi += 4; + } + yw += width; + } + + for (x = 0; x < width; x++) { + g_in_sum = b_in_sum = r_in_sum = g_sum = b_sum = r_sum = 0; + + yi = x << 2; + r_out_sum = radiusPlus1 * (pr = pixels[yi]); + g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]); + b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]); + + r_sum += sumFactor * pr; + g_sum += sumFactor * pg; + b_sum += sumFactor * pb; + + stack = stackStart; + + for (i = 0; i < radiusPlus1; i++) { + stack.r = pr; + stack.g = pg; + stack.b = pb; + stack = stack.next; + } + + yp = width; + + for (i = 1; i <= radius; i++) { + yi = yp + x << 2; + + r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i); + g_sum += (stack.g = pg = pixels[yi + 1]) * rbs; + b_sum += (stack.b = pb = pixels[yi + 2]) * rbs; + + r_in_sum += pr; + g_in_sum += pg; + b_in_sum += pb; + + stack = stack.next; + + if (i < heightMinus1) { + yp += width; + } + } + + yi = x; + stackIn = stackStart; + stackOut = stackEnd; + for (y = 0; y < height; y++) { + p = yi << 2; + pixels[p] = r_sum * mul_sum >> shg_sum; + pixels[p + 1] = g_sum * mul_sum >> shg_sum; + pixels[p + 2] = b_sum * mul_sum >> shg_sum; + + r_sum -= r_out_sum; + g_sum -= g_out_sum; + b_sum -= b_out_sum; + + r_out_sum -= stackIn.r; + g_out_sum -= stackIn.g; + b_out_sum -= stackIn.b; + + p = x + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width << 2; + + r_sum += r_in_sum += stackIn.r = pixels[p]; + g_sum += g_in_sum += stackIn.g = pixels[p + 1]; + b_sum += b_in_sum += stackIn.b = pixels[p + 2]; + + stackIn = stackIn.next; + + r_out_sum += pr = stackOut.r; + g_out_sum += pg = stackOut.g; + b_out_sum += pb = stackOut.b; + + r_in_sum -= pr; + g_in_sum -= pg; + b_in_sum -= pb; + + stackOut = stackOut.next; + + yi += width; + } + } + + return bitmap; +} + +function stackBlur () { + var radius = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10; + var hasAlphaChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + radius = parseParamNumber(radius); + + return function (bitmap) { + return stackBlurImage(bitmap, radius, hasAlphaChannel); + }; +} + +function transparency() { + var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; + + amount = parseParamNumber(amount); + return convolution(weight([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 1], amount / 100)); +} + +function unsharpMasking() { + var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 256; + + amount = parseParamNumber(amount); + return convolution(weight([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1], -1 / amount)); +} + +var matrix = { + blur: blur, + emboss: emboss, + gaussianBlur: gaussianBlur, + 'gaussian-blur': gaussianBlur, + gaussianBlur5x: gaussianBlur5x, + 'gaussian-blur-5x': gaussianBlur5x, + grayscale2: grayscale2, + identity: identity, + kirschHorizontal: kirschHorizontal, + 'kirsch-horizontal': kirschHorizontal, + kirschVertical: kirschVertical, + 'kirsch-vertical': kirschVertical, + laplacian: laplacian, + laplacian5x: laplacian5x, + 'laplacian-5x': laplacian5x, + motionBlur: motionBlur, + 'motion-blur': motionBlur, + motionBlur2: motionBlur2, + 'motion-blur-2': motionBlur2, + motionBlur3: motionBlur3, + 'motion-blur-3': motionBlur3, + negative: negative, + random: random, + sepia2: sepia2, + sharpen: sharpen, + sobelHorizontal: sobelHorizontal, + 'sobel-horizontal': sobelHorizontal, + sobelVertical: sobelVertical, + 'sobel-vertical': sobelVertical, + stackBlur: stackBlur, + 'stack-blur': stackBlur, + transparency: transparency, + unsharpMasking: unsharpMasking, + 'unsharp-masking': unsharpMasking +}; + +function kirsch() { + return filter('kirsch-horizontal kirsch-vertical'); +} + +function sobel() { + return filter('sobel-horizontal sobel-vertical'); +} + +function vintage() { + return filter('brightness(15) saturation(-20) gamma(1.8)'); +} + +var multi$1 = { + kirsch: kirsch, + sobel: sobel, + vintage: vintage +}; + +var ImageFilter$1 = _extends({}, image, pixel, matrix, multi$1); + +var _functions; + +var functions = (_functions = { + partial: partial, + multi: multi, + merge: merge, + weight: weight, + repeat: repeat, + colorMatrix: colorMatrix, + each: each$1, + eachXY: eachXY, + createRandomCount: createRandomCount, + createRandRange: createRandRange, + createBitmap: createBitmap, + createBlurMatrix: createBlurMatrix, + pack: pack$1, + packXY: packXY, + getBitmap: getBitmap, + putBitmap: putBitmap, + radian: radian, + convolution: convolution, + parseParamNumber: parseParamNumber, + filter: filter, + clamp: clamp +}, defineProperty(_functions, 'multi', multi), defineProperty(_functions, 'merge', merge), defineProperty(_functions, 'matches', matches), defineProperty(_functions, 'parseFilter', parseFilter), defineProperty(_functions, 'partial', partial), _functions); + +var LocalFilter = functions; + +function weight(arr) { + var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + + return arr.map(function (i) { + return i * num; + }); +} + +function repeat(value, num) { + var arr = new Array(num); + for (var i = 0; i < num; i++) { + arr[i] = value; + } + return arr; +} + +function colorMatrix(pixels, i, matrix) { + var r = pixels[i], + g = pixels[i + 1], + b = pixels[i + 2], + a = pixels[i + 3]; + + pixels[i] = matrix[0] * r + matrix[1] * g + matrix[2] * b + matrix[3] * a; + pixels[i + 1] = matrix[4] * r + matrix[5] * g + matrix[6] * b + matrix[7] * a; + pixels[i + 2] = matrix[8] * r + matrix[9] * g + matrix[10] * b + matrix[11] * a; + pixels[i + 3] = matrix[12] * r + matrix[13] * g + matrix[14] * b + matrix[15] * a; +} + +function makeFilter(filter) { + + if (typeof filter == 'function') { + return filter; + } + + if (typeof filter == 'string') { + filter = [filter]; + } + + var filterName = filter.shift(); + + if (typeof filterName == 'function') { + return filterName; + } + + var params = filter; + + var filterFunction = ImageFilter$1[filterName] || LocalFilter[filterName]; + + if (!filterFunction) { + throw new Error(filterName + ' is not filter. please check filter name.'); + } + return filterFunction.apply(filterFunction, params); +} + +function each$1(len, callback) { + for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { + callback(i, xyIndex); + } +} + +function eachXY(len, width, callback) { + for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { + callback(i, xyIndex % width, Math.floor(xyIndex / width)); + } +} + +function createRandRange(min, max, count) { + var result = []; + + for (var i = 1; i <= count; i++) { + var num = Math.random() * (max - min) + min; + var sign = Math.floor(Math.random() * 10) % 2 == 0 ? -1 : 1; + result.push(sign * num); + } + + result.sort(); + + var centerIndex = Math.floor(count / 2); + var a = result[centerIndex]; + result[centerIndex] = result[0]; + result[0] = a; + + return result; +} + +function createRandomCount() { + return [3 * 3, 4 * 4, 5 * 5, 6 * 6, 7 * 7, 8 * 8, 9 * 9, 10 * 10].sort(function (a, b) { + return 0.5 - Math.random(); + })[0]; +} + +function createBitmap(length, width, height) { + return { pixels: new Uint8ClampedArray(length), width: width, height: height }; +} + +function getBitmap(bitmap, area) { + return Canvas.getBitmap(bitmap, area); +} + +function putBitmap(bitmap, subBitmap, area) { + return Canvas.putBitmap(bitmap, subBitmap, area); +} + +function parseParamNumber(param) { + if (typeof param === 'string') { + param = param.replace(/deg/, ''); + param = param.replace(/px/, ''); + } + return +param; +} + +var filter_regexp = /(([\w_\-]+)(\(([^\)]*)\))?)+/gi; +function pack$1(callback) { + return function (bitmap) { + each$1(bitmap.pixels.length, function (i, xyIndex) { + callback(bitmap.pixels, i, xyIndex); + }); + return bitmap; + }; +} + +var ColorListIndex = [0, 1, 2, 3]; + +function swapColor(pixels, startIndex, endIndex) { + + ColorListIndex.forEach(function (i) { + var temp = pixels[startIndex + i]; + pixels[startIndex + i] = pixels[endIndex + i]; + pixels[endIndex + i] = temp; + }); +} + +function packXY(callback) { + return function (bitmap) { + eachXY(bitmap.pixels.length, bitmap.width, function (i, x, y) { + callback(bitmap.pixels, i, x, y); + }); + return bitmap; + }; +} + +function radian(degree) { + return Matrix.CONSTANT.radian(degree); +} - for (x = 0; x < width; x++) { - g_in_sum = b_in_sum = r_in_sum = g_sum = b_sum = r_sum = 0; +function createBlurMatrix() { + var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3; - yi = x << 2; - r_out_sum = radiusPlus1 * (pr = pixels[yi]); - g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]); - b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]); + var count = Math.pow(amount, 2); + var value = 1 / count; + return repeat(value, count); +} - r_sum += sumFactor * pr; - g_sum += sumFactor * pg; - b_sum += sumFactor * pb; +function convolution(weights) { + var opaque = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - stack = stackStart; + return function (_ref) { + var pixels = _ref.pixels, + width = _ref.width, + height = _ref.height; - for (i = 0; i < radiusPlus1; i++) { - stack.r = pr; - stack.g = pg; - stack.b = pb; - stack = stack.next; - } + var side = Math.round(Math.sqrt(weights.length)); + var halfSide = Math.floor(side / 2); - yp = width; + var w = width; + var h = height; + var sw = w; + var sh = h; + var dst = new Uint8ClampedArray(pixels.length); + var alphaFac = opaque ? 1 : 0; - for (i = 1; i <= radius; i++) { - yi = yp + x << 2; + for (var y = 0; y < h; y++) { + for (var x = 0; x < w; x++) { + var sy = y; + var sx = x; + var dstIndex = (y * w + x) * 4; - r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i); - g_sum += (stack.g = pg = pixels[yi + 1]) * rbs; - b_sum += (stack.b = pb = pixels[yi + 2]) * rbs; + var r = 0, + g = 0, + b = 0, + a = 0; + for (var cy = 0; cy < side; cy++) { + for (var cx = 0; cx < side; cx++) { - r_in_sum += pr; - g_in_sum += pg; - b_in_sum += pb; + var scy = sy + cy - halfSide; + var scx = sx + cx - halfSide; - stack = stack.next; + if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { + var srcIndex = (scy * sw + scx) * 4; + var wt = weights[cy * side + cx]; + r += pixels[srcIndex] * wt; + g += pixels[srcIndex + 1] * wt; + b += pixels[srcIndex + 2] * wt; + a += pixels[srcIndex + 3] * wt; // weight 를 곱한 값을 계속 더한다. + } + } + } - if (i < heightMinus1) { - yp += width; + dst[dstIndex] = r; + dst[dstIndex + 1] = g; + dst[dstIndex + 2] = b; + dst[dstIndex + 3] = a + alphaFac * (255 - a); } } - yi = x; - stackIn = stackStart; - stackOut = stackEnd; - for (y = 0; y < height; y++) { - p = yi << 2; - pixels[p] = r_sum * mul_sum >> shg_sum; - pixels[p + 1] = g_sum * mul_sum >> shg_sum; - pixels[p + 2] = b_sum * mul_sum >> shg_sum; + return { pixels: dst, width: sw, height: sh }; + }; +} - r_sum -= r_out_sum; - g_sum -= g_out_sum; - b_sum -= b_out_sum; +function matches(str) { + var ret = Color.convertMatches(str); + var matches = ret.str.match(filter_regexp); + var result = []; - r_out_sum -= stackIn.r; - g_out_sum -= stackIn.g; - b_out_sum -= stackIn.b; + if (!matches) { + return result; + } - p = x + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width << 2; + result = matches.map(function (it) { + return { filter: it, origin: Color.reverseMatches(it, ret.matches) }; + }); - r_sum += r_in_sum += stackIn.r = pixels[p]; - g_sum += g_in_sum += stackIn.g = pixels[p + 1]; - b_sum += b_in_sum += stackIn.b = pixels[p + 2]; + var pos = { next: 0 }; + result = result.map(function (item) { - stackIn = stackIn.next; + var startIndex = str.indexOf(item.origin, pos.next); - r_out_sum += pr = stackOut.r; - g_out_sum += pg = stackOut.g; - b_out_sum += pb = stackOut.b; + item.startIndex = startIndex; + item.endIndex = startIndex + item.origin.length; - r_in_sum -= pr; - g_in_sum -= pg; - b_in_sum -= pb; + item.arr = parseFilter(item.origin); - stackOut = stackOut.next; + pos.next = item.endIndex; - yi += width; - } - } + return item; + }).filter(function (it) { + if (!it.arr.length) return false; + return true; + }); - return bitmap; + return result; } -function stackBlur () { - var radius = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10; - var hasAlphaChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - - radius = parseParamNumber(radius); - - return function (bitmap) { - return stackBlurImage(bitmap, radius, hasAlphaChannel); - }; -} +/** + * Filter Parser + * + * F.parseFilter('blur(30)') == ['blue', '30'] + * F.parseFilter('gradient(white, black, 3)') == ['gradient', 'white', 'black', '3'] + * + * @param {String} filterString + */ +function parseFilter(filterString) { -function transparency() { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; + var ret = Color.convertMatches(filterString); + var matches = ret.str.match(filter_regexp); - amount = parseParamNumber(amount); - return convolution(weight([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 1], amount / 100)); -} + if (!matches[0]) { + return []; + } -function unsharpMasking() { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 256; + var arr = matches[0].split('('); - amount = parseParamNumber(amount); - return convolution(weight([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1], -1 / amount)); -} + var filterName = arr.shift(); + var filterParams = []; -var matrix = { - blur: blur, - emboss: emboss, - gaussianBlur: gaussianBlur, - 'gaussian-blur': gaussianBlur, - gaussianBlur5x: gaussianBlur5x, - 'gaussian-blur-5x': gaussianBlur5x, - grayscale2: grayscale2, - identity: identity, - kirschHorizontal: kirschHorizontal, - 'kirsch-horizontal': kirschHorizontal, - kirschVertical: kirschVertical, - 'kirsch-vertical': kirschVertical, - laplacian: laplacian, - laplacian5x: laplacian5x, - 'laplacian-5x': laplacian5x, - motionBlur: motionBlur, - 'motion-blur': motionBlur, - motionBlur2: motionBlur2, - 'motion-blur-2': motionBlur2, - motionBlur3: motionBlur3, - 'motion-blur-3': motionBlur3, - negative: negative, - random: random, - sepia2: sepia2, - sharpen: sharpen, - sobelHorizontal: sobelHorizontal, - 'sobel-horizontal': sobelHorizontal, - sobelVertical: sobelVertical, - 'sobel-vertical': sobelVertical, - stackBlur: stackBlur, - 'stack-blur': stackBlur, - transparency: transparency, - unsharpMasking: unsharpMasking, - 'unsharp-masking': unsharpMasking -}; + if (arr.length) { + filterParams = arr.shift().split(')')[0].split(',').map(function (f) { + return Color.reverseMatches(f, ret.matches); + }); + } -var ImageFilter$1 = _extends({}, image, pixel, matrix); + var result = [filterName].concat(toConsumableArray(filterParams)).map(Color.trim); -// TODO: worker run -Object.assign(ImageFilter$1, { - pack: pack$1, - packXY: packXY, - swapColor: swapColor -}); + return result; +} -var F = ImageFilter$1; +function clamp(num) { + return Math.min(255, num); +} -F.filter = function (str) { - return F.merge(matches(str).map(function (it) { +function filter(str) { + return merge(matches(str).map(function (it) { return it.arr; })); -}; +} /** * @@ -3324,13 +3363,13 @@ F.filter = function (str) { * ImageFilter.multi('blur', 'grayscale', 'sharpen', ['blur', 3], function (bitmap) { return bitmap }); * */ -F.multi = function () { +function multi() { for (var _len = arguments.length, filters = Array(_len), _key = 0; _key < _len; _key++) { filters[_key] = arguments[_key]; } filters = filters.map(function (filter) { - return makeFilter(filter, F); + return makeFilter(filter); }); return function (bitmap) { @@ -3338,11 +3377,11 @@ F.multi = function () { return f(bitmap); }, bitmap); }; -}; +} -F.merge = function (filters) { - return F.multi.apply(F, toConsumableArray(filters)); -}; +function merge(filters) { + return multi.apply(undefined, toConsumableArray(filters)); +} /** * apply filter into special area @@ -3353,7 +3392,7 @@ F.merge = function (filters) { * @param {{x, y, width, height}} area * @param {*} filters */ -F.partial = function (area) { +function partial(area) { var allFilter = null; for (var _len2 = arguments.length, filters = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { @@ -3361,61 +3400,18 @@ F.partial = function (area) { } if (filters.length == 1 && typeof filters[0] === 'string') { - allFilter = F.filter(filters[0]); + allFilter = filter(filters[0]); } else { - allFilter = F.merge(filters); + allFilter = merge(filters); } return function (bitmap) { return putBitmap(bitmap, allFilter(getBitmap(bitmap, area)), area); }; -}; - -F.counter = function (filter) { - var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; - - var filters = []; - - for (var i = 0; i < count; i++) { - filters.push(filter); - } - - return F.multi.apply(F, filters); -}; - -/** - * multi filter - */ - -F.laplacian.grayscale = function () { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; - - return F.filter('grayscale laplacian(' + amount); -}; - -F.laplacian5x.grayscale = function () { - return F.filter('grayscale laplacian5x'); -}; - -F.kirsch = function () { - return F.filter('kirsch-horizontal kirsch-vertical'); -}; - -F.kirsch.grayscale = function () { - return F.filter('grayscale kirsch'); -}; - -F.sobel = function () { - return F.filter('sobel-horizontal sobel-vertical'); -}; - -F.sobel.grayscale = function () { - return F.filter('grayscale sobel'); -}; +} -F.vintage = function () { - return F.filter('brightness(15) saturation(-20) gamma(1.8)'); -}; +// TODO: worker run +var ImageFilter = Object.assign({}, ImageFilter$1, functions); var counter = 0; var cached = []; @@ -6193,7 +6189,7 @@ var index = { Color: color, ColorNames: ColorNames, ColorPicker: ColorPicker, - ImageFilter: ImageFilter$1, + ImageFilter: ImageFilter, HueColor: HueColor, Canvas: Canvas, ImageLoader: ImageLoader diff --git a/dist/codemirror-colorpicker.js b/dist/codemirror-colorpicker.js index b4ca738..2dac9a9 100644 --- a/dist/codemirror-colorpicker.js +++ b/dist/codemirror-colorpicker.js @@ -1889,427 +1889,149 @@ var Matrix = { } }; -function weight(arr) { - var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; +function crop() { + var startX = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var startY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var width = arguments[2]; + var height = arguments[3]; - return arr.map(function (i) { - return i * num; - }); -} -function repeat(value, num) { - var arr = new Array(num); - for (var i = 0; i < num; i++) { - arr[i] = value; - } - return arr; -} + var newBitmap = createBitmap(width * height * 4, width, height); -function colorMatrix(pixels, i, matrix) { - var r = pixels[i], - g = pixels[i + 1], - b = pixels[i + 2], - a = pixels[i + 3]; + return function (bitmap) { + for (var y = startY, realY = 0; y < height; y++, realY++) { + for (var x = startX, realX = 0; x < width; x++, realX++) { + newBitmap.pixels[realY * width * realX] = bitmap.pixels[y * width * x]; + } + } - pixels[i] = matrix[0] * r + matrix[1] * g + matrix[2] * b + matrix[3] * a; - pixels[i + 1] = matrix[4] * r + matrix[5] * g + matrix[6] * b + matrix[7] * a; - pixels[i + 2] = matrix[8] * r + matrix[9] * g + matrix[10] * b + matrix[11] * a; - pixels[i + 3] = matrix[12] * r + matrix[13] * g + matrix[14] * b + matrix[15] * a; + return newBitmap; + }; } -function makeFilter(filter, F) { - - if (typeof filter == 'function') { - return filter; - } - - if (typeof filter == 'string') { - filter = [filter]; - } - - var filterName = filter.shift(); - - if (typeof filterName == 'function') { - return filterName; - } - - var params = filter; +// Image manupulate +function resize(dstWidth, dstHeight) { + return function (bitmap) { - var filterFunction = F[filterName]; + var c = Canvas.drawPixels(bitmap); + var context = c.getContext('2d'); - if (!filterFunction) { - throw new Error(filterName + ' is not filter. please check filter name.'); - } - return filterFunction.apply(filterFunction, params); -} + c.width = dstWidth; + c.height = dstHeight; -function each$1(len, callback) { - for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { - callback(i, xyIndex); - } + return { + pixels: new Uint8ClampedArray(context.getImageData(0, 0, dstWidth, dstHeight).data), + width: dstWidth, + height: dstHeight + }; + }; } -function eachXY(len, width, callback) { - for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { - callback(i, xyIndex % width, Math.floor(xyIndex / width)); - } -} +function flipV() { + return function (bitmap) { -function createRandRange(min, max, count) { - var result = []; + var width = bitmap.width; + var height = bitmap.height; + var isCenter = height % 2 == 1 ? 1 : 0; - for (var i = 1; i <= count; i++) { - var num = Math.random() * (max - min) + min; - var sign = Math.floor(Math.random() * 10) % 2 == 0 ? -1 : 1; - result.push(sign * num); - } + var halfHeight = isCenter ? Math.floor(height / 2) : height / 2; - result.sort(); + for (var y = 0; y < halfHeight; y++) { + for (var x = 0; x < width; x++) { - var centerIndex = Math.floor(count / 2); - var a = result[centerIndex]; - result[centerIndex] = result[0]; - result[0] = a; + var startIndex = (y * width + x) * 4; + var endIndex = ((height - 1 - y) * width + x) * 4; + swapColor(bitmap.pixels, startIndex, endIndex); + } + } - return result; + return bitmap; + }; } -function createRandomCount() { - return [3 * 3, 4 * 4, 5 * 5, 6 * 6, 7 * 7, 8 * 8, 9 * 9, 10 * 10].sort(function (a, b) { - return 0.5 - Math.random(); - })[0]; -} +function flipH() { + return function (bitmap) { -function createBitmap(length, width, height) { - return { pixels: new Uint8ClampedArray(length), width: width, height: height }; -} + var width = bitmap.width; + var height = bitmap.height; + var isCenter = width % 2 == 1 ? 1 : 0; -function getBitmap(bitmap, area) { - return Canvas.getBitmap(bitmap, area); -} + var halfWidth = isCenter ? Math.floor(width / 2) : width / 2; -function putBitmap(bitmap, subBitmap, area) { - return Canvas.putBitmap(bitmap, subBitmap, area); -} + for (var y = 0; y < height; y++) { + for (var x = 0; x < halfWidth; x++) { -function parseParamNumber(param) { - if (typeof param === 'string') { - param = param.replace(/deg/, ''); - param = param.replace(/px/, ''); - } - return +param; -} + var startIndex = (y * width + x) * 4; + var endIndex = (y * width + (width - 1 - x)) * 4; + swapColor(bitmap.pixels, startIndex, endIndex); + } + } -var filter_regexp = /(([\w_\-]+)(\(([^\)]*)\))?)+/gi; -function pack$1(callback) { - return function (bitmap) { - each$1(bitmap.pixels.length, function (i, xyIndex) { - callback(bitmap.pixels, i, xyIndex); - }); return bitmap; }; } -var ColorListIndex = [0, 1, 2, 3]; - -function swapColor(pixels, startIndex, endIndex) { +function rotateDegree(angle) { + var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'center'; + var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'center'; - ColorListIndex.forEach(function (i) { - var temp = pixels[startIndex + i]; - pixels[startIndex + i] = pixels[endIndex + i]; - pixels[endIndex + i] = temp; - }); -} + // const r = F.radian(angle) -function packXY(callback) { return function (bitmap) { - eachXY(bitmap.pixels.length, bitmap.width, function (i, x, y) { - callback(bitmap.pixels, i, x, y); - }); - return bitmap; - }; -} + var newBitmap = createBitmap(bitmap.pixels.length, bitmap.width, bitmap.height); + var width = bitmap.width; + var height = bitmap.height; + if (cx == 'center') { + cx = Math.floor(width / 2); + } + if (cy == 'center') { + cy = Math.floor(height / 2); + } -function createBlurMatrix() { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3; + var translateMatrix = Matrix.CONSTANT.translate(-cx, -cy); + var translateMatrix2 = Matrix.CONSTANT.translate(cx, cy); + var shear1Matrix = Matrix.CONSTANT.shear1(angle); + var shear2Matrix = Matrix.CONSTANT.shear2(angle); - var count = Math.pow(amount, 2); - var value = 1 / count; - return repeat(value, count); -} + return packXY(function (pixels, i, x, y) { + // console.log(x, y, i) + var arr = Matrix.multiply(translateMatrix, [x, y, 1]); -function convolution(weights) { - var opaque = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); + arr = Matrix.multiply(shear2Matrix, arr).map(Math.round); + arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); + arr = Matrix.multiply(translateMatrix2, arr); - return function (_ref) { - var pixels = _ref.pixels, - width = _ref.width, - height = _ref.height; + var _arr = arr, + _arr2 = slicedToArray(_arr, 2), + x1 = _arr2[0], + y1 = _arr2[1]; - var side = Math.round(Math.sqrt(weights.length)); - var halfSide = Math.floor(side / 2); + if (x1 < 0) return; + if (y1 < 0) return; + if (x1 > width - 1) return; + if (y1 > height - 1) return; - var w = width; - var h = height; - var sw = w; - var sh = h; - var dst = new Uint8ClampedArray(pixels.length); - var alphaFac = opaque ? 1 : 0; + var endIndex = (y1 * width + x1) * 4; - for (var y = 0; y < h; y++) { - for (var x = 0; x < w; x++) { - var sy = y; - var sx = x; - var dstIndex = (y * w + x) * 4; + pixels[endIndex] = bitmap.pixels[i]; + pixels[endIndex + 1] = bitmap.pixels[i + 1]; + pixels[endIndex + 2] = bitmap.pixels[i + 2]; + pixels[endIndex + 3] = bitmap.pixels[i + 3]; + })(newBitmap); + }; +} - var r = 0, - g = 0, - b = 0, - a = 0; - for (var cy = 0; cy < side; cy++) { - for (var cx = 0; cx < side; cx++) { +function rotate() { + var degree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var scy = sy + cy - halfSide; - var scx = sx + cx - halfSide; + degree = parseParamNumber(degree); + degree = degree % 360; + return function (bitmap) { - if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { - var srcIndex = (scy * sw + scx) * 4; - var wt = weights[cy * side + cx]; - r += pixels[srcIndex] * wt; - g += pixels[srcIndex + 1] * wt; - b += pixels[srcIndex + 2] * wt; - a += pixels[srcIndex + 3] * wt; // weight 를 곱한 값을 계속 더한다. - } - } - } - - dst[dstIndex] = r; - dst[dstIndex + 1] = g; - dst[dstIndex + 2] = b; - dst[dstIndex + 3] = a + alphaFac * (255 - a); - } - } - - return { pixels: dst, width: sw, height: sh }; - }; -} - -function matches(str) { - var ret = Color.convertMatches(str); - var matches = ret.str.match(filter_regexp); - var result = []; - - if (!matches) { - return result; - } - - result = matches.map(function (it) { - return { filter: it, origin: Color.reverseMatches(it, ret.matches) }; - }); - - var pos = { next: 0 }; - result = result.map(function (item) { - - var startIndex = str.indexOf(item.origin, pos.next); - - item.startIndex = startIndex; - item.endIndex = startIndex + item.origin.length; - - item.arr = parseFilter(item.origin); - - pos.next = item.endIndex; - - return item; - }).filter(function (it) { - if (!it.arr.length) return false; - return true; - }); - - return result; -} - -/** - * Filter Parser - * - * F.parseFilter('blur(30)') == ['blue', '30'] - * F.parseFilter('gradient(white, black, 3)') == ['gradient', 'white', 'black', '3'] - * - * @param {String} filterString - */ -function parseFilter(filterString) { - - var ret = Color.convertMatches(filterString); - var matches = ret.str.match(filter_regexp); - - if (!matches[0]) { - return []; - } - - var arr = matches[0].split('('); - - var filterName = arr.shift(); - var filterParams = []; - - if (arr.length) { - filterParams = arr.shift().split(')')[0].split(',').map(function (f) { - return Color.reverseMatches(f, ret.matches); - }); - } - - var result = [filterName].concat(toConsumableArray(filterParams)).map(Color.trim); - - return result; -} - -function clamp(num) { - return Math.min(255, num); -} - -function crop() { - var startX = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var startY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - var width = arguments[2]; - var height = arguments[3]; - - - var newBitmap = createBitmap(width * height * 4, width, height); - - return function (bitmap) { - for (var y = startY, realY = 0; y < height; y++, realY++) { - for (var x = startX, realX = 0; x < width; x++, realX++) { - newBitmap.pixels[realY * width * realX] = bitmap.pixels[y * width * x]; - } - } - - return newBitmap; - }; -} - -// Image manupulate -function resize(dstWidth, dstHeight) { - return function (bitmap) { - - var c = Canvas.drawPixels(bitmap); - var context = c.getContext('2d'); - - c.width = dstWidth; - c.height = dstHeight; - - return { - pixels: new Uint8ClampedArray(context.getImageData(0, 0, dstWidth, dstHeight).data), - width: dstWidth, - height: dstHeight - }; - }; -} - -function flipV() { - return function (bitmap) { - - var width = bitmap.width; - var height = bitmap.height; - var isCenter = height % 2 == 1 ? 1 : 0; - - var halfHeight = isCenter ? Math.floor(height / 2) : height / 2; - - for (var y = 0; y < halfHeight; y++) { - for (var x = 0; x < width; x++) { - - var startIndex = (y * width + x) * 4; - var endIndex = ((height - 1 - y) * width + x) * 4; - swapColor(bitmap.pixels, startIndex, endIndex); - } - } - - return bitmap; - }; -} - -function flipH() { - return function (bitmap) { - - var width = bitmap.width; - var height = bitmap.height; - var isCenter = width % 2 == 1 ? 1 : 0; - - var halfWidth = isCenter ? Math.floor(width / 2) : width / 2; - - for (var y = 0; y < height; y++) { - for (var x = 0; x < halfWidth; x++) { - - var startIndex = (y * width + x) * 4; - var endIndex = (y * width + (width - 1 - x)) * 4; - swapColor(bitmap.pixels, startIndex, endIndex); - } - } - - return bitmap; - }; -} - -function rotateDegree(angle) { - var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'center'; - var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'center'; - - // const r = F.radian(angle) - - return function (bitmap) { - var newBitmap = createBitmap(bitmap.pixels.length, bitmap.width, bitmap.height); - var width = bitmap.width; - var height = bitmap.height; - - if (cx == 'center') { - cx = Math.floor(width / 2); - } - - if (cy == 'center') { - cy = Math.floor(height / 2); - } - - var translateMatrix = Matrix.CONSTANT.translate(-cx, -cy); - var translateMatrix2 = Matrix.CONSTANT.translate(cx, cy); - var shear1Matrix = Matrix.CONSTANT.shear1(angle); - var shear2Matrix = Matrix.CONSTANT.shear2(angle); - - return packXY(function (pixels, i, x, y) { - // console.log(x, y, i) - var arr = Matrix.multiply(translateMatrix, [x, y, 1]); - - arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); - arr = Matrix.multiply(shear2Matrix, arr).map(Math.round); - arr = Matrix.multiply(shear1Matrix, arr).map(Math.round); - arr = Matrix.multiply(translateMatrix2, arr); - - var _arr = arr, - _arr2 = slicedToArray(_arr, 2), - x1 = _arr2[0], - y1 = _arr2[1]; - - if (x1 < 0) return; - if (y1 < 0) return; - if (x1 > width - 1) return; - if (y1 > height - 1) return; - - var endIndex = (y1 * width + x1) * 4; - - pixels[endIndex] = bitmap.pixels[i]; - pixels[endIndex + 1] = bitmap.pixels[i + 1]; - pixels[endIndex + 2] = bitmap.pixels[i + 2]; - pixels[endIndex + 3] = bitmap.pixels[i + 3]; - })(newBitmap); - }; -} - -function rotate() { - var degree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - - degree = parseParamNumber(degree); - degree = degree % 360; - return function (bitmap) { - - if (degree == 0) return bitmap; + if (degree == 0) return bitmap; if (degree == 90 || degree == 270) { var newBitmap = createBitmap(bitmap.pixels.length, bitmap.height, bitmap.width); @@ -3195,172 +2917,489 @@ function stackBlurCanvasRGBA(bitmap, top_x, top_y, radius) { stackOut = stackOut.next; - yi += 4; - } - yw += width; - } + yi += 4; + } + yw += width; + } + + for (x = 0; x < width; x++) { + g_in_sum = b_in_sum = r_in_sum = g_sum = b_sum = r_sum = 0; + + yi = x << 2; + r_out_sum = radiusPlus1 * (pr = pixels[yi]); + g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]); + b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]); + + r_sum += sumFactor * pr; + g_sum += sumFactor * pg; + b_sum += sumFactor * pb; + + stack = stackStart; + + for (i = 0; i < radiusPlus1; i++) { + stack.r = pr; + stack.g = pg; + stack.b = pb; + stack = stack.next; + } + + yp = width; + + for (i = 1; i <= radius; i++) { + yi = yp + x << 2; + + r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i); + g_sum += (stack.g = pg = pixels[yi + 1]) * rbs; + b_sum += (stack.b = pb = pixels[yi + 2]) * rbs; + + r_in_sum += pr; + g_in_sum += pg; + b_in_sum += pb; + + stack = stack.next; + + if (i < heightMinus1) { + yp += width; + } + } + + yi = x; + stackIn = stackStart; + stackOut = stackEnd; + for (y = 0; y < height; y++) { + p = yi << 2; + pixels[p] = r_sum * mul_sum >> shg_sum; + pixels[p + 1] = g_sum * mul_sum >> shg_sum; + pixels[p + 2] = b_sum * mul_sum >> shg_sum; + + r_sum -= r_out_sum; + g_sum -= g_out_sum; + b_sum -= b_out_sum; + + r_out_sum -= stackIn.r; + g_out_sum -= stackIn.g; + b_out_sum -= stackIn.b; + + p = x + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width << 2; + + r_sum += r_in_sum += stackIn.r = pixels[p]; + g_sum += g_in_sum += stackIn.g = pixels[p + 1]; + b_sum += b_in_sum += stackIn.b = pixels[p + 2]; + + stackIn = stackIn.next; + + r_out_sum += pr = stackOut.r; + g_out_sum += pg = stackOut.g; + b_out_sum += pb = stackOut.b; + + r_in_sum -= pr; + g_in_sum -= pg; + b_in_sum -= pb; + + stackOut = stackOut.next; + + yi += width; + } + } + + return bitmap; +} + +function stackBlur () { + var radius = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10; + var hasAlphaChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + radius = parseParamNumber(radius); + + return function (bitmap) { + return stackBlurImage(bitmap, radius, hasAlphaChannel); + }; +} + +function transparency() { + var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; + + amount = parseParamNumber(amount); + return convolution(weight([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 1], amount / 100)); +} + +function unsharpMasking() { + var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 256; + + amount = parseParamNumber(amount); + return convolution(weight([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1], -1 / amount)); +} + +var matrix = { + blur: blur, + emboss: emboss, + gaussianBlur: gaussianBlur, + 'gaussian-blur': gaussianBlur, + gaussianBlur5x: gaussianBlur5x, + 'gaussian-blur-5x': gaussianBlur5x, + grayscale2: grayscale2, + identity: identity, + kirschHorizontal: kirschHorizontal, + 'kirsch-horizontal': kirschHorizontal, + kirschVertical: kirschVertical, + 'kirsch-vertical': kirschVertical, + laplacian: laplacian, + laplacian5x: laplacian5x, + 'laplacian-5x': laplacian5x, + motionBlur: motionBlur, + 'motion-blur': motionBlur, + motionBlur2: motionBlur2, + 'motion-blur-2': motionBlur2, + motionBlur3: motionBlur3, + 'motion-blur-3': motionBlur3, + negative: negative, + random: random, + sepia2: sepia2, + sharpen: sharpen, + sobelHorizontal: sobelHorizontal, + 'sobel-horizontal': sobelHorizontal, + sobelVertical: sobelVertical, + 'sobel-vertical': sobelVertical, + stackBlur: stackBlur, + 'stack-blur': stackBlur, + transparency: transparency, + unsharpMasking: unsharpMasking, + 'unsharp-masking': unsharpMasking +}; + +function kirsch() { + return filter('kirsch-horizontal kirsch-vertical'); +} + +function sobel() { + return filter('sobel-horizontal sobel-vertical'); +} + +function vintage() { + return filter('brightness(15) saturation(-20) gamma(1.8)'); +} + +var multi$1 = { + kirsch: kirsch, + sobel: sobel, + vintage: vintage +}; + +var ImageFilter$1 = _extends({}, image, pixel, matrix, multi$1); + +var _functions; + +var functions = (_functions = { + partial: partial, + multi: multi, + merge: merge, + weight: weight, + repeat: repeat, + colorMatrix: colorMatrix, + each: each$1, + eachXY: eachXY, + createRandomCount: createRandomCount, + createRandRange: createRandRange, + createBitmap: createBitmap, + createBlurMatrix: createBlurMatrix, + pack: pack$1, + packXY: packXY, + getBitmap: getBitmap, + putBitmap: putBitmap, + radian: radian, + convolution: convolution, + parseParamNumber: parseParamNumber, + filter: filter, + clamp: clamp +}, defineProperty(_functions, 'multi', multi), defineProperty(_functions, 'merge', merge), defineProperty(_functions, 'matches', matches), defineProperty(_functions, 'parseFilter', parseFilter), defineProperty(_functions, 'partial', partial), _functions); + +var LocalFilter = functions; + +function weight(arr) { + var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + + return arr.map(function (i) { + return i * num; + }); +} + +function repeat(value, num) { + var arr = new Array(num); + for (var i = 0; i < num; i++) { + arr[i] = value; + } + return arr; +} + +function colorMatrix(pixels, i, matrix) { + var r = pixels[i], + g = pixels[i + 1], + b = pixels[i + 2], + a = pixels[i + 3]; + + pixels[i] = matrix[0] * r + matrix[1] * g + matrix[2] * b + matrix[3] * a; + pixels[i + 1] = matrix[4] * r + matrix[5] * g + matrix[6] * b + matrix[7] * a; + pixels[i + 2] = matrix[8] * r + matrix[9] * g + matrix[10] * b + matrix[11] * a; + pixels[i + 3] = matrix[12] * r + matrix[13] * g + matrix[14] * b + matrix[15] * a; +} + +function makeFilter(filter) { + + if (typeof filter == 'function') { + return filter; + } + + if (typeof filter == 'string') { + filter = [filter]; + } + + var filterName = filter.shift(); + + if (typeof filterName == 'function') { + return filterName; + } + + var params = filter; + + var filterFunction = ImageFilter$1[filterName] || LocalFilter[filterName]; + + if (!filterFunction) { + throw new Error(filterName + ' is not filter. please check filter name.'); + } + return filterFunction.apply(filterFunction, params); +} + +function each$1(len, callback) { + for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { + callback(i, xyIndex); + } +} + +function eachXY(len, width, callback) { + for (var i = 0, xyIndex = 0; i < len; i += 4, xyIndex++) { + callback(i, xyIndex % width, Math.floor(xyIndex / width)); + } +} + +function createRandRange(min, max, count) { + var result = []; + + for (var i = 1; i <= count; i++) { + var num = Math.random() * (max - min) + min; + var sign = Math.floor(Math.random() * 10) % 2 == 0 ? -1 : 1; + result.push(sign * num); + } + + result.sort(); + + var centerIndex = Math.floor(count / 2); + var a = result[centerIndex]; + result[centerIndex] = result[0]; + result[0] = a; + + return result; +} + +function createRandomCount() { + return [3 * 3, 4 * 4, 5 * 5, 6 * 6, 7 * 7, 8 * 8, 9 * 9, 10 * 10].sort(function (a, b) { + return 0.5 - Math.random(); + })[0]; +} + +function createBitmap(length, width, height) { + return { pixels: new Uint8ClampedArray(length), width: width, height: height }; +} + +function getBitmap(bitmap, area) { + return Canvas.getBitmap(bitmap, area); +} + +function putBitmap(bitmap, subBitmap, area) { + return Canvas.putBitmap(bitmap, subBitmap, area); +} + +function parseParamNumber(param) { + if (typeof param === 'string') { + param = param.replace(/deg/, ''); + param = param.replace(/px/, ''); + } + return +param; +} + +var filter_regexp = /(([\w_\-]+)(\(([^\)]*)\))?)+/gi; +function pack$1(callback) { + return function (bitmap) { + each$1(bitmap.pixels.length, function (i, xyIndex) { + callback(bitmap.pixels, i, xyIndex); + }); + return bitmap; + }; +} + +var ColorListIndex = [0, 1, 2, 3]; + +function swapColor(pixels, startIndex, endIndex) { + + ColorListIndex.forEach(function (i) { + var temp = pixels[startIndex + i]; + pixels[startIndex + i] = pixels[endIndex + i]; + pixels[endIndex + i] = temp; + }); +} + +function packXY(callback) { + return function (bitmap) { + eachXY(bitmap.pixels.length, bitmap.width, function (i, x, y) { + callback(bitmap.pixels, i, x, y); + }); + return bitmap; + }; +} + +function radian(degree) { + return Matrix.CONSTANT.radian(degree); +} - for (x = 0; x < width; x++) { - g_in_sum = b_in_sum = r_in_sum = g_sum = b_sum = r_sum = 0; +function createBlurMatrix() { + var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3; - yi = x << 2; - r_out_sum = radiusPlus1 * (pr = pixels[yi]); - g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]); - b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]); + var count = Math.pow(amount, 2); + var value = 1 / count; + return repeat(value, count); +} - r_sum += sumFactor * pr; - g_sum += sumFactor * pg; - b_sum += sumFactor * pb; +function convolution(weights) { + var opaque = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - stack = stackStart; + return function (_ref) { + var pixels = _ref.pixels, + width = _ref.width, + height = _ref.height; - for (i = 0; i < radiusPlus1; i++) { - stack.r = pr; - stack.g = pg; - stack.b = pb; - stack = stack.next; - } + var side = Math.round(Math.sqrt(weights.length)); + var halfSide = Math.floor(side / 2); - yp = width; + var w = width; + var h = height; + var sw = w; + var sh = h; + var dst = new Uint8ClampedArray(pixels.length); + var alphaFac = opaque ? 1 : 0; - for (i = 1; i <= radius; i++) { - yi = yp + x << 2; + for (var y = 0; y < h; y++) { + for (var x = 0; x < w; x++) { + var sy = y; + var sx = x; + var dstIndex = (y * w + x) * 4; - r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i); - g_sum += (stack.g = pg = pixels[yi + 1]) * rbs; - b_sum += (stack.b = pb = pixels[yi + 2]) * rbs; + var r = 0, + g = 0, + b = 0, + a = 0; + for (var cy = 0; cy < side; cy++) { + for (var cx = 0; cx < side; cx++) { - r_in_sum += pr; - g_in_sum += pg; - b_in_sum += pb; + var scy = sy + cy - halfSide; + var scx = sx + cx - halfSide; - stack = stack.next; + if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { + var srcIndex = (scy * sw + scx) * 4; + var wt = weights[cy * side + cx]; + r += pixels[srcIndex] * wt; + g += pixels[srcIndex + 1] * wt; + b += pixels[srcIndex + 2] * wt; + a += pixels[srcIndex + 3] * wt; // weight 를 곱한 값을 계속 더한다. + } + } + } - if (i < heightMinus1) { - yp += width; + dst[dstIndex] = r; + dst[dstIndex + 1] = g; + dst[dstIndex + 2] = b; + dst[dstIndex + 3] = a + alphaFac * (255 - a); } } - yi = x; - stackIn = stackStart; - stackOut = stackEnd; - for (y = 0; y < height; y++) { - p = yi << 2; - pixels[p] = r_sum * mul_sum >> shg_sum; - pixels[p + 1] = g_sum * mul_sum >> shg_sum; - pixels[p + 2] = b_sum * mul_sum >> shg_sum; + return { pixels: dst, width: sw, height: sh }; + }; +} - r_sum -= r_out_sum; - g_sum -= g_out_sum; - b_sum -= b_out_sum; +function matches(str) { + var ret = Color.convertMatches(str); + var matches = ret.str.match(filter_regexp); + var result = []; - r_out_sum -= stackIn.r; - g_out_sum -= stackIn.g; - b_out_sum -= stackIn.b; + if (!matches) { + return result; + } - p = x + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width << 2; + result = matches.map(function (it) { + return { filter: it, origin: Color.reverseMatches(it, ret.matches) }; + }); - r_sum += r_in_sum += stackIn.r = pixels[p]; - g_sum += g_in_sum += stackIn.g = pixels[p + 1]; - b_sum += b_in_sum += stackIn.b = pixels[p + 2]; + var pos = { next: 0 }; + result = result.map(function (item) { - stackIn = stackIn.next; + var startIndex = str.indexOf(item.origin, pos.next); - r_out_sum += pr = stackOut.r; - g_out_sum += pg = stackOut.g; - b_out_sum += pb = stackOut.b; + item.startIndex = startIndex; + item.endIndex = startIndex + item.origin.length; - r_in_sum -= pr; - g_in_sum -= pg; - b_in_sum -= pb; + item.arr = parseFilter(item.origin); - stackOut = stackOut.next; + pos.next = item.endIndex; - yi += width; - } - } + return item; + }).filter(function (it) { + if (!it.arr.length) return false; + return true; + }); - return bitmap; + return result; } -function stackBlur () { - var radius = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10; - var hasAlphaChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - - radius = parseParamNumber(radius); - - return function (bitmap) { - return stackBlurImage(bitmap, radius, hasAlphaChannel); - }; -} +/** + * Filter Parser + * + * F.parseFilter('blur(30)') == ['blue', '30'] + * F.parseFilter('gradient(white, black, 3)') == ['gradient', 'white', 'black', '3'] + * + * @param {String} filterString + */ +function parseFilter(filterString) { -function transparency() { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; + var ret = Color.convertMatches(filterString); + var matches = ret.str.match(filter_regexp); - amount = parseParamNumber(amount); - return convolution(weight([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 1], amount / 100)); -} + if (!matches[0]) { + return []; + } -function unsharpMasking() { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 256; + var arr = matches[0].split('('); - amount = parseParamNumber(amount); - return convolution(weight([1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1], -1 / amount)); -} + var filterName = arr.shift(); + var filterParams = []; -var matrix = { - blur: blur, - emboss: emboss, - gaussianBlur: gaussianBlur, - 'gaussian-blur': gaussianBlur, - gaussianBlur5x: gaussianBlur5x, - 'gaussian-blur-5x': gaussianBlur5x, - grayscale2: grayscale2, - identity: identity, - kirschHorizontal: kirschHorizontal, - 'kirsch-horizontal': kirschHorizontal, - kirschVertical: kirschVertical, - 'kirsch-vertical': kirschVertical, - laplacian: laplacian, - laplacian5x: laplacian5x, - 'laplacian-5x': laplacian5x, - motionBlur: motionBlur, - 'motion-blur': motionBlur, - motionBlur2: motionBlur2, - 'motion-blur-2': motionBlur2, - motionBlur3: motionBlur3, - 'motion-blur-3': motionBlur3, - negative: negative, - random: random, - sepia2: sepia2, - sharpen: sharpen, - sobelHorizontal: sobelHorizontal, - 'sobel-horizontal': sobelHorizontal, - sobelVertical: sobelVertical, - 'sobel-vertical': sobelVertical, - stackBlur: stackBlur, - 'stack-blur': stackBlur, - transparency: transparency, - unsharpMasking: unsharpMasking, - 'unsharp-masking': unsharpMasking -}; + if (arr.length) { + filterParams = arr.shift().split(')')[0].split(',').map(function (f) { + return Color.reverseMatches(f, ret.matches); + }); + } -var ImageFilter$1 = _extends({}, image, pixel, matrix); + var result = [filterName].concat(toConsumableArray(filterParams)).map(Color.trim); -// TODO: worker run -Object.assign(ImageFilter$1, { - pack: pack$1, - packXY: packXY, - swapColor: swapColor -}); + return result; +} -var F = ImageFilter$1; +function clamp(num) { + return Math.min(255, num); +} -F.filter = function (str) { - return F.merge(matches(str).map(function (it) { +function filter(str) { + return merge(matches(str).map(function (it) { return it.arr; })); -}; +} /** * @@ -3369,13 +3408,13 @@ F.filter = function (str) { * ImageFilter.multi('blur', 'grayscale', 'sharpen', ['blur', 3], function (bitmap) { return bitmap }); * */ -F.multi = function () { +function multi() { for (var _len = arguments.length, filters = Array(_len), _key = 0; _key < _len; _key++) { filters[_key] = arguments[_key]; } filters = filters.map(function (filter) { - return makeFilter(filter, F); + return makeFilter(filter); }); return function (bitmap) { @@ -3383,11 +3422,11 @@ F.multi = function () { return f(bitmap); }, bitmap); }; -}; +} -F.merge = function (filters) { - return F.multi.apply(F, toConsumableArray(filters)); -}; +function merge(filters) { + return multi.apply(undefined, toConsumableArray(filters)); +} /** * apply filter into special area @@ -3398,7 +3437,7 @@ F.merge = function (filters) { * @param {{x, y, width, height}} area * @param {*} filters */ -F.partial = function (area) { +function partial(area) { var allFilter = null; for (var _len2 = arguments.length, filters = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { @@ -3406,61 +3445,18 @@ F.partial = function (area) { } if (filters.length == 1 && typeof filters[0] === 'string') { - allFilter = F.filter(filters[0]); + allFilter = filter(filters[0]); } else { - allFilter = F.merge(filters); + allFilter = merge(filters); } return function (bitmap) { return putBitmap(bitmap, allFilter(getBitmap(bitmap, area)), area); }; -}; - -F.counter = function (filter) { - var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; - - var filters = []; - - for (var i = 0; i < count; i++) { - filters.push(filter); - } - - return F.multi.apply(F, filters); -}; - -/** - * multi filter - */ - -F.laplacian.grayscale = function () { - var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; - - return F.filter('grayscale laplacian(' + amount); -}; - -F.laplacian5x.grayscale = function () { - return F.filter('grayscale laplacian5x'); -}; - -F.kirsch = function () { - return F.filter('kirsch-horizontal kirsch-vertical'); -}; - -F.kirsch.grayscale = function () { - return F.filter('grayscale kirsch'); -}; - -F.sobel = function () { - return F.filter('sobel-horizontal sobel-vertical'); -}; - -F.sobel.grayscale = function () { - return F.filter('grayscale sobel'); -}; +} -F.vintage = function () { - return F.filter('brightness(15) saturation(-20) gamma(1.8)'); -}; +// TODO: worker run +var ImageFilter = Object.assign({}, ImageFilter$1, functions); var counter = 0; var cached = []; @@ -6238,7 +6234,7 @@ var index = { Color: color, ColorNames: ColorNames, ColorPicker: ColorPicker, - ImageFilter: ImageFilter$1, + ImageFilter: ImageFilter, HueColor: HueColor, Canvas: Canvas, ImageLoader: ImageLoader diff --git a/dist/codemirror-colorpicker.min.js b/dist/codemirror-colorpicker.min.js index cc2d0ab..a81305c 100644 --- a/dist/codemirror-colorpicker.min.js +++ b/dist/codemirror-colorpicker.min.js @@ -1 +1 @@ -var CodeMirrorColorPicker=function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e={aliceblue:"rgb(240, 248, 255)",antiquewhite:"rgb(250, 235, 215)",aqua:"rgb(0, 255, 255)",aquamarine:"rgb(127, 255, 212)",azure:"rgb(240, 255, 255)",beige:"rgb(245, 245, 220)",bisque:"rgb(255, 228, 196)",black:"rgb(0, 0, 0)",blanchedalmond:"rgb(255, 235, 205)",blue:"rgb(0, 0, 255)",blueviolet:"rgb(138, 43, 226)",brown:"rgb(165, 42, 42)",burlywood:"rgb(222, 184, 135)",cadetblue:"rgb(95, 158, 160)",chartreuse:"rgb(127, 255, 0)",chocolate:"rgb(210, 105, 30)",coral:"rgb(255, 127, 80)",cornflowerblue:"rgb(100, 149, 237)",cornsilk:"rgb(255, 248, 220)",crimson:"rgb(237, 20, 61)",cyan:"rgb(0, 255, 255)",darkblue:"rgb(0, 0, 139)",darkcyan:"rgb(0, 139, 139)",darkgoldenrod:"rgb(184, 134, 11)",darkgray:"rgb(169, 169, 169)",darkgrey:"rgb(169, 169, 169)",darkgreen:"rgb(0, 100, 0)",darkkhaki:"rgb(189, 183, 107)",darkmagenta:"rgb(139, 0, 139)",darkolivegreen:"rgb(85, 107, 47)",darkorange:"rgb(255, 140, 0)",darkorchid:"rgb(153, 50, 204)",darkred:"rgb(139, 0, 0)",darksalmon:"rgb(233, 150, 122)",darkseagreen:"rgb(143, 188, 143)",darkslateblue:"rgb(72, 61, 139)",darkslategray:"rgb(47, 79, 79)",darkslategrey:"rgb(47, 79, 79)",darkturquoise:"rgb(0, 206, 209)",darkviolet:"rgb(148, 0, 211)",deeppink:"rgb(255, 20, 147)",deepskyblue:"rgb(0, 191, 255)",dimgray:"rgb(105, 105, 105)",dimgrey:"rgb(105, 105, 105)",dodgerblue:"rgb(30, 144, 255)",firebrick:"rgb(178, 34, 34)",floralwhite:"rgb(255, 250, 240)",forestgreen:"rgb(34, 139, 34)",fuchsia:"rgb(255, 0, 255)",gainsboro:"rgb(220, 220, 220)",ghostwhite:"rgb(248, 248, 255)",gold:"rgb(255, 215, 0)",goldenrod:"rgb(218, 165, 32)",gray:"rgb(128, 128, 128)",grey:"rgb(128, 128, 128)",green:"rgb(0, 128, 0)",greenyellow:"rgb(173, 255, 47)",honeydew:"rgb(240, 255, 240)",hotpink:"rgb(255, 105, 180)",indianred:"rgb(205, 92, 92)",indigo:"rgb(75, 0, 130)",ivory:"rgb(255, 255, 240)",khaki:"rgb(240, 230, 140)",lavender:"rgb(230, 230, 250)",lavenderblush:"rgb(255, 240, 245)",lawngreen:"rgb(124, 252, 0)",lemonchiffon:"rgb(255, 250, 205)",lightblue:"rgb(173, 216, 230)",lightcoral:"rgb(240, 128, 128)",lightcyan:"rgb(224, 255, 255)",lightgoldenrodyellow:"rgb(250, 250, 210)",lightgreen:"rgb(144, 238, 144)",lightgray:"rgb(211, 211, 211)",lightgrey:"rgb(211, 211, 211)",lightpink:"rgb(255, 182, 193)",lightsalmon:"rgb(255, 160, 122)",lightseagreen:"rgb(32, 178, 170)",lightskyblue:"rgb(135, 206, 250)",lightslategray:"rgb(119, 136, 153)",lightslategrey:"rgb(119, 136, 153)",lightsteelblue:"rgb(176, 196, 222)",lightyellow:"rgb(255, 255, 224)",lime:"rgb(0, 255, 0)",limegreen:"rgb(50, 205, 50)",linen:"rgb(250, 240, 230)",magenta:"rgb(255, 0, 255)",maroon:"rgb(128, 0, 0)",mediumaquamarine:"rgb(102, 205, 170)",mediumblue:"rgb(0, 0, 205)",mediumorchid:"rgb(186, 85, 211)",mediumpurple:"rgb(147, 112, 219)",mediumseagreen:"rgb(60, 179, 113)",mediumslateblue:"rgb(123, 104, 238)",mediumspringgreen:"rgb(0, 250, 154)",mediumturquoise:"rgb(72, 209, 204)",mediumvioletred:"rgb(199, 21, 133)",midnightblue:"rgb(25, 25, 112)",mintcream:"rgb(245, 255, 250)",mistyrose:"rgb(255, 228, 225)",moccasin:"rgb(255, 228, 181)",navajowhite:"rgb(255, 222, 173)",navy:"rgb(0, 0, 128)",oldlace:"rgb(253, 245, 230)",olive:"rgb(128, 128, 0)",olivedrab:"rgb(107, 142, 35)",orange:"rgb(255, 165, 0)",orangered:"rgb(255, 69, 0)",orchid:"rgb(218, 112, 214)",palegoldenrod:"rgb(238, 232, 170)",palegreen:"rgb(152, 251, 152)",paleturquoise:"rgb(175, 238, 238)",palevioletred:"rgb(219, 112, 147)",papayawhip:"rgb(255, 239, 213)",peachpuff:"rgb(255, 218, 185)",peru:"rgb(205, 133, 63)",pink:"rgb(255, 192, 203)",plum:"rgb(221, 160, 221)",powderblue:"rgb(176, 224, 230)",purple:"rgb(128, 0, 128)",rebeccapurple:"rgb(102, 51, 153)",red:"rgb(255, 0, 0)",rosybrown:"rgb(188, 143, 143)",royalblue:"rgb(65, 105, 225)",saddlebrown:"rgb(139, 69, 19)",salmon:"rgb(250, 128, 114)",sandybrown:"rgb(244, 164, 96)",seagreen:"rgb(46, 139, 87)",seashell:"rgb(255, 245, 238)",sienna:"rgb(160, 82, 45)",silver:"rgb(192, 192, 192)",skyblue:"rgb(135, 206, 235)",slateblue:"rgb(106, 90, 205)",slategray:"rgb(112, 128, 144)",slategrey:"rgb(112, 128, 144)",snow:"rgb(255, 250, 250)",springgreen:"rgb(0, 255, 127)",steelblue:"rgb(70, 130, 180)",tan:"rgb(210, 180, 140)",teal:"rgb(0, 128, 128)",thistle:"rgb(216, 191, 216)",tomato:"rgb(255, 99, 71)",turquoise:"rgb(64, 224, 208)",violet:"rgb(238, 130, 238)",wheat:"rgb(245, 222, 179)",white:"rgb(255, 255, 255)",whitesmoke:"rgb(245, 245, 245)",yellow:"rgb(255, 255, 0)",yellowgreen:"rgb(154, 205, 50)",transparent:"rgba(0, 0, 0, 0)"};var r={isColorName:function(t){return!!e[t]},getColorByName:function(t){return e[t]}};function i(t,e){if(t.length!==e.length)return!1;for(var r=0,i=t.length;r0)u=s(h);else u=e[Math.floor(a()*e.length)];o=!i(u,c),n[l]=u}return o}function c(t,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"linear";t=t,e=e||Math.max(2,Math.ceil(Math.sqrt(t.length/2)));var s=r||"euclidean";"string"==typeof s&&(s=n[s]);for(var c=0,u=function(){return(c=(9301*c+49297)%233280)/233280},f=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"linear";return o[r](t.length,e).map(function(e){return t[e]})}(t,e,a),v=!0,g=0;v;){if(v=h(e,t,l(e,t,f,s),f,!1,u),++g%i==0)break}return f}var u={create:function(t,e){var r=document.createElement("canvas");return r.width=t||0,r.height=e||0,r},drawPixels:function(t){var e=this.create(t.width,t.height),r=e.getContext("2d"),i=r.getImageData(0,0,e.width,e.height);return i.data.set(t.pixels),r.putImageData(i,0,0),e},createHistogram:function(t,e,r,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{black:!0,red:!1,green:!1,blue:!1},o=this.create(t,e),a=o.getContext("2d");a.clearRect(0,0,t,e),a.fillStyle="white",a.fillRect(0,0,t,e),a.globalAlpha=.7;var s={black:!1};n.black?s.black=!1:s.black=!0,n.red?s.red=!1:s.red=!0,n.green?s.green=!1:s.green=!0,n.blue?s.blue=!1:s.blue=!0,Object.keys(r).forEach(function(i){if(!s[i]){var n=r[i],o=Math.max.apply(Math,n),l=t/n.length;a.fillStyle=i,n.forEach(function(t,r){var i=e*(t/o),n=r*l;a.fillRect(n,e-i,l,i)})}}),"function"==typeof i&&i(o)},getHistogram:function(t){for(var e,r,i=new Array(256),n=new Array(256),o=new Array(256),a=new Array(256),s=0;s<256;s++)i[s]=0,n[s]=0,o[s]=0,a[s]=0;return r=function(t,e){var r=Math.round(x.brightness(t[e],t[e+1],t[e+2]));i[r]++,n[t[e]]++,o[t[e+1]]++,a[t[e+2]]++},function(t,e){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};v(this,t),this.isLoaded=!1,this.imageUrl=e,this.opt=r,this.initialize()}return g(t,[{key:"initialize",value:function(){this.canvas=this.createCanvas(),this.context=this.canvas.getContext("2d")}},{key:"createCanvas",value:function(){return document.createElement("canvas")}},{key:"load",value:function(t){this.loadImage(t)}},{key:"loadImage",value:function(t){var e=this,r=this.context,i=new Image;i.onload=function(){var n=i.height/i.width;e.opt.canvasWidth&&e.opt.canvasHeight?(e.canvas.width=e.opt.canvasWidth,e.canvas.height=e.opt.canvasHeight):(e.canvas.width=e.opt.maxWidth?e.opt.maxWidth:i.width,e.canvas.height=e.canvas.width*n),r.drawImage(i,0,0,i.width,i.height,0,0,e.canvas.width,e.canvas.height),e.isLoaded=!0,t&&t()},this.getImageUrl(function(t){i.src=t})}},{key:"getImageUrl",value:function(t){if("string"==typeof this.imageUrl)return t(this.imageUrl);if(this.imageUrl instanceof Blob){var e=new FileReader;e.onload=function(e){t(e.target.result)},e.readAsDataURL(this.imageUrl)}}},{key:"getRGBA",value:function(t,e,r,i){return[t,e,r,i]}},{key:"toArray",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this.context.getImageData(0,0,this.canvas.width,this.canvas.height),i=r.width,n=r.height,o={pixels:new Uint8ClampedArray(r.data),width:i,height:n};return t&&(o=t(o)),u.drawPixels(o).toDataURL(e.outputFormat||"image/png")}},{key:"toHistogram",value:function(t){var e=this.context.getImageData(0,0,this.canvas.width,this.canvas.height),r=e.width,i=e.height,n={pixels:new Uint8ClampedArray(e.data),width:r,height:i};return u.getHistogram(n)}},{key:"toRGB",value:function(){for(var t=this.context.getImageData(0,0,this.canvas.width,this.canvas.height).data,e=[],r=0,i=t.length;r-1||e[n].indexOf("rgb")>-1||e[n].indexOf("hsl")>-1)i.push({color:e[n]});else{var a=r.getColorByName(e[n]);a&&i.push({color:e[n],nameColor:a})}var s={next:0};return i.forEach(function(e){var r=t.indexOf(e.color,s.next);e.startIndex=r,e.endIndex=r+e.color.length,s.next=e.endIndex}),i},convertMatches:function(t){var e=this.matches(t);return e.forEach(function(e,r){t=t.replace(e.color,"@"+r)}),{str:t,matches:e}},convertMatchesArray:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:",",i=this.convertMatches(t);return i.str.split(r).map(function(t,r){return t=e.trim(t),i.matches[r]&&(t=t.replace("@"+r,i.matches[r].color)),t})},reverseMatches:function(t,e){return e.forEach(function(e,r){t=t.replace("@"+r,e.color)}),t},trim:function(t){return t.replace(/^\s+|\s+$/g,"")},round:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return Math.round(t*e)/e},format:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgba(0, 0, 0, 0)";return Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]}),"hex"==e?this.hex(t):"rgb"==e?this.rgb(t,r):"hsl"==e?this.hsl(t):t},hex:function(t){Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]});var e=t.r.toString(16);t.r<16&&(e="0"+e);var r=t.g.toString(16);t.g<16&&(r="0"+r);var i=t.b.toString(16);return t.b<16&&(i="0"+i),"#"+e+r+i},rgb:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgba(0, 0, 0, 0)";if(Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]}),void 0!==t)return 1==t.a||void 0===t.a?isNaN(t.r)?e:"rgb("+t.r+","+t.g+","+t.b+")":"rgba("+t.r+","+t.g+","+t.b+","+t.a+")"},hsl:function(t){return Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]}),1==t.a||void 0===t.a?"hsl("+t.h+","+t.s+"%,"+t.l+"%)":"hsla("+t.h+","+t.s+"%,"+t.l+"%,"+t.a+")"},parse:function(t){if("string"==typeof t){if(r.isColorName(t)&&(t=r.getColorByName(t)),t.indexOf("rgb(")>-1){for(var e=0,i=(o=t.replace("rgb(","").replace(")","").split(",")).length;e-1){for(e=0,i=(o=t.replace("rgba(","").replace(")","").split(",")).length;e-1){for(e=0,i=(o=t.replace("hsl(","").replace(")","").split(",")).length;e-1){for(e=0,i=(o=t.replace("hsla(","").replace(")","").split(",")).length;e>16,g:(65280&t)>>8,b:(255&t)>>0,a:1};return n=Object.assign(n,this.RGBtoHSL(n))}if(0<=t&&t<=4294967295){n={type:"hex",r:(4278190080&t)>>24,g:(16711680&t)>>16,b:(65280&t)>>8,a:(255&t)/255};return n=Object.assign(n,this.RGBtoHSL(n))}}return t},HSVtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,r=i.v}var n=t,o=r;360==n&&(n=0);var a=e*o,s=a*(1-Math.abs(n/60%2-1)),l=o-a,h=[];return 0<=n&&n<60?h=[a,s,0]:60<=n&&n<120?h=[s,a,0]:120<=n&&n<180?h=[0,a,s]:180<=n&&n<240?h=[0,s,a]:240<=n&&n<300?h=[s,0,a]:300<=n&&n<360&&(h=[a,0,s]),{r:this.round(255*(h[0]+l)),g:this.round(255*(h[1]+l)),b:this.round(255*(h[2]+l))}},RGBtoHSV:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=t/255,o=e/255,a=r/255,s=Math.max(n,o,a),l=s-Math.min(n,o,a),h=0;0==l?h=0:s==n?h=(o-a)/l%6*60:s==o?h=60*((a-n)/l+2):s==a&&(h=60*((n-o)/l+4)),h<0&&(h=360+h);return{h:h,s:0==s?0:l/s,v:s}},HSVtoHSL:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,r=i.v}var n=this.HSVtoRGB(t,e,r);return this.RGBtoHSL(n.r,n.g,n.b)},RGBtoCMYK:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=t/255,o=e/255,a=r/255,s=1-Math.max(n,o,a);return{c:(1-n-s)/(1-s),m:(1-o-s)/(1-s),y:(1-a-s)/(1-s),k:s}},CMYKtoRGB:function(t,e,r,i){if(1==arguments.length){var n=arguments[0];t=n.c,e=n.m,r=n.y,i=n.k}return{r:255*(1-t)*(1-i),g:255*(1-e)*(1-i),b:255*(1-r)*(1-i)}},RGBtoHSL:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}t/=255,e/=255,r/=255;var n,o,a=Math.max(t,e,r),s=Math.min(t,e,r),l=(a+s)/2;if(a==s)n=o=0;else{var h=a-s;switch(o=l>.5?h/(2-a-s):h/(a+s),a){case t:n=(e-r)/h+(e1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t},HSLtoHSV:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,i.v}var n=this.HSLtoRGB(t,e,r);return this.RGBtoHSV(n.r,n.g,n.b)},HSLtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,r=i.l}var n,o,a;if(t/=360,r/=100,0==(e/=100))n=o=a=r;else{var s=r<.5?r*(1+e):r+e-r*e,l=2*r-s;n=this.HUEtoRGB(l,s,t+1/3),o=this.HUEtoRGB(l,s,t),a=this.HUEtoRGB(l,s,t-1/3)}return{r:this.round(255*n),g:this.round(255*o),b:this.round(255*a)}},c:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.gray((t+e+r)/3>90?0:255)},gray:function(t){return{r:t,g:t,b:t}},RGBtoSimpleGray:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.gray(Math.ceil((t+e+r)/3))},RGBtoGray:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.gray(this.RGBtoYCrCb(t,e,r).y)},brightness:function(t,e,r){return Math.ceil(.2126*t+.7152*e+.0722*r)},RGBtoYCrCb:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=this.brightness(t,e,r);return{y:n,cr:.713*(t-n),cb:.564*(r-n)}},YCrCbtoRGB:function(t,e,r,i){if(1==arguments.length){var n=arguments[0];t=n.y,e=n.cr,r=n.cb;i=(i=n.bit)||0}var o=t+1.402*(e-i),a=t-.344*(r-i)-.714*(e-i),s=t+1.772*(r-i);return{r:Math.ceil(o),g:Math.ceil(a),b:Math.ceil(s)}},ReverseRGB:function(t){return t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t},XYZtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.x,e=i.y,r=i.z}var n=t/100,o=e/100,a=r/100,s=3.2406*n+-1.5372*o+-.4986*a,l=-.9689*n+1.8758*o+.0415*a,h=.0557*n+-.204*o+1.057*a;return s=this.ReverseRGB(s),l=this.ReverseRGB(l),h=this.ReverseRGB(h),{r:this.round(255*s),g:this.round(255*l),b:this.round(255*h)}},PivotRGB:function(t){return 100*(t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)},RGBtoXYZ:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=t/255,o=e/255,a=r/255;return{x:.4124*(n=this.PivotRGB(n))+.3576*(o=this.PivotRGB(o))+.1805*(a=this.PivotRGB(a)),y:.2126*n+.7152*o+.0722*a,z:.0193*n+.1192*o+.9505*a}},ReverseXyz:function(t){return Math.pow(t,3)>.008856?Math.pow(t,3):(t-16/116)/7.787},LABtoXYZ:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.l,e=i.a,r=i.b}var n=(t+16)/116,o=e/500+n,a=n-r/200;return n=this.ReverseXyz(n),{x:95.047*(o=this.ReverseXyz(o)),y:100*n,z:108.883*(a=this.ReverseXyz(a))}},PivotXyz:function(t){return t>.008856?Math.pow(t,1/3):(7.787*t+16)/116},XYZtoLAB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.x,e=i.y,r=i.z}var n=t/95.047,o=e/100,a=r/108.883;return n=this.PivotXyz(n),{l:116*(o=this.PivotXyz(o))-16,a:500*(n-o),b:200*(o-(a=this.PivotXyz(a)))}},RGBtoLAB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.XYZtoLAB(this.RGBtoXYZ(t,e,r))},LABtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.l,e=i.a,r=i.b}return this.XYZtoRGB(this.LABtoXYZ(t,e,r))},blend:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hex",n=this.parse(t),o=this.parse(e);return this.interpolateRGB(n,o,r,i)},mix:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hex";return this.blend(t,e,r,i)},contrast:function(t){t=this.parse(t);var e=(Math.round(299*t.r)+Math.round(587*t.g)+Math.round(114*t.b))/1e3;return e},contrastColor:function(t){return this.contrast(t)>=128?"black":"white"},interpolateRGB:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hex",n={r:this.round(t.r+(e.r-t.r)*r),g:this.round(t.g+(e.g-t.g)*r),b:this.round(t.b+(e.b-t.b)*r),a:this.round(t.a+(e.a-t.a)*r,100)};return this.format(n,n.a<1?"rgb":i)},scale:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;if(!t)return[];"string"==typeof t&&(t=this.convertMatchesArray(t));for(var r=(t=t||[]).length,i=[],n=0;n0){var i=(1-t.filter(function(t){return"*"!=t[1]&&1!=t[1]}).map(function(t){return t[1]}).reduce(function(t,e){return t+e},0))/r;t.forEach(function(e,r){"*"==e[1]&&r>0&&(t.length-1==r||(e[1]=i))})}return t},gradient:function(t){for(var e=[],r=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:10)-((t=this.parseGradient(t)).length-1),i=r,n=1,o=t.length;n1&&void 0!==arguments[1]?arguments[1]:"h",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:9,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"rgb",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1,a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:100,s=this.parse(t),l=this.RGBtoHSV(s),h=(o-n)*a/r,c=[],u=1;u<=r;u++)l[e]=Math.abs((a-h*u)/a),c.push(this.format(this.HSVtoRGB(l),i));return c},scaleH:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgb",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:360;return this.scaleHSV(t,"h",e,r,i,n,1)},scaleS:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgb",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1;return this.scaleHSV(t,"s",e,r,i,n,100)},scaleV:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgb",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1;return this.scaleHSV(t,"v",e,r,i,n,100)},palette:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"hex";return t.length>r&&(t=c(t,r)),t.map(function(t){return e.format(t,i)})},ImageToRGB:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];if(r){if(r){var i;(i=new C(t,e)).loadImage(function(){"function"==typeof r&&r(i.toRGB())})}}else(i=new C(t)).loadImage(function(){"function"==typeof e&&e(i.toRGB())})},ImageToURL:function(t,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=new C(t);n.loadImage(function(){"function"==typeof r&&r(n.toArray(e,i))})},histogram:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=new C(t);i.loadImage(function(){"function"==typeof e&&e(i.toHistogram(r))})},ImageToHistogram:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{width:200,height:100},i=new C(t);i.loadImage(function(){u.createHistogram(r.width||200,r.height||100,i.toHistogram(r),function(t){"function"==typeof e&&e(t.toDataURL("image/png"))},r)})}};x.scale.parula=function(t){return x.scale(["#352a87","#0f5cdd","#00b5a6","#ffc337","#fdff00"],t)},x.scale.jet=function(t){return x.scale(["#00008f","#0020ff","#00ffff","#51ff77","#fdff00","#ff0000","#800000"],t)},x.scale.hsv=function(t){return x.scale(["#ff0000","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff","#ff0000"],t)},x.scale.hot=function(t){return x.scale(["#0b0000","#ff0000","#ffff00","#ffffff"],t)},x.scale.pink=function(t){return x.scale(["#1e0000","#bd7b7b","#e7e5b2","#ffffff"],t)},x.scale.bone=function(t){return x.scale(["#000000","#4a4a68","#a6c6c6","#ffffff"],t)},x.scale.copper=function(t){return x.scale(["#000000","#3d2618","#9d623e","#ffa167","#ffc77f"],t)};var _=[{rgb:"#ff0000",start:0},{rgb:"#ffff00",start:.17},{rgb:"#00ff00",start:.33},{rgb:"#00ffff",start:.5},{rgb:"#0000ff",start:.67},{rgb:"#ff00ff",start:.83},{rgb:"#ff0000",start:1}];!function(){for(var t=0,e=_.length;t=t){e=_[i-1],r=_[i];break}return e&&r?x.interpolateRGB(e,r,(t-e.start)/(r.start-e.start)):_[0].rgb}},S={identity:function(){return[1,0,0,0,1,0,0,0,1]},stretching:function(t){return[t,0,0,0,1,0,0,0,1]},squeezing:function(t){return[t,0,0,0,1/t,0,0,0,1]},scale:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return[t=t||0===t?t:1,0,0,0,e=e||0===e?e:1,0,0,0,1]},scaleX:function(t){return this.scale(t)},scaleY:function(t){return this.scale(1,t)},translate:function(t,e){return[1,0,t,0,1,e,0,0,1]},rotate:function(t){var e=this.radian(t);return[Math.cos(e),-Math.sin(e),0,Math.sin(e),Math.cos(e),0,0,0,1]},rotate90:function(){return[0,-1,0,1,0,0,0,0,1]},rotate180:function(){return[-1,0,0,0,-1,0,0,0,1]},rotate270:function(){return[0,1,0,-1,0,0,0,0,1]},radian:function(t){return t*Math.PI/180},skew:function(t,e){var r=this.radian(t),i=this.radian(e);return[1,Math.tan(r),0,Math.tan(i),1,0,0,0,1]},skewX:function(t){var e=this.radian(t);return[1,Math.tan(e),0,0,1,0,0,0,1]},skewY:function(t){var e=this.radian(t);return[1,0,0,Math.tan(e),1,0,0,0,1]},shear1:function(t){return[1,-Math.tan(this.radian(t)/2),0,0,1,0,0,0,1]},shear2:function(t){return[1,0,0,Math.sin(this.radian(t)),1,0,0,0,1]}},M={CONSTANT:S,radian:function(t){return S.radian(t)},multiply:function(t,e){return[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[3]*e[0]+t[4]*e[1]+t[5]*e[2],t[6]*e[0]+t[7]*e[1]+t[8]*e[2]]},identity:function(t){return this.multiply(S.identity(),t)},translate:function(t,e,r){return this.multiply(S.translate(t,e),r)},rotate:function(t,e){return this.multiply(S.rotate(t),e)},shear1:function(t,e){return this.multiply(S.shear1(t),e)},shear2:function(t,e){return this.multiply(S.shear2(t),e)},rotateShear:function(t,e){var r=e;return r=this.shear1(t,r),r=this.shear2(t,r),r=this.shear1(t,r)}};function H(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return t.map(function(t){return t*e})}function B(t,e,r){var i=t[e],n=t[e+1],o=t[e+2],a=t[e+3];t[e]=r[0]*i+r[1]*n+r[2]*o+r[3]*a,t[e+1]=r[4]*i+r[5]*n+r[6]*o+r[7]*a,t[e+2]=r[8]*i+r[9]*n+r[10]*o+r[11]*a,t[e+3]=r[12]*i+r[13]*n+r[14]*o+r[15]*a}function R(t,e,r){return{pixels:new Uint8ClampedArray(t),width:e,height:r}}function E(t){return"string"==typeof t&&(t=(t=t.replace(/deg/,"")).replace(/px/,"")),+t}var A=/(([\w_\-]+)(\(([^\)]*)\))?)+/gi;function O(t){return function(e){return function(t,e){for(var r=0,i=0;r0&&void 0!==arguments[0]?arguments[0]:3,e=Math.pow(t,2);return function(t,e){for(var r=new Array(e),i=0;i1&&void 0!==arguments[1])||arguments[1];return function(r){for(var i=r.pixels,n=r.width,o=r.height,a=Math.round(Math.sqrt(t.length)),s=Math.floor(a/2),l=n,h=o,c=l,u=h,f=new Uint8ClampedArray(i.length),v=e?1:0,g=0;g=0&&$=0&&S1&&void 0!==arguments[1]?arguments[1]:"center",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"center";return function(i){var n=R(i.pixels.length,i.width,i.height),o=i.width,a=i.height;"center"==e&&(e=Math.floor(o/2)),"center"==r&&(r=Math.floor(a/2));var s=M.CONSTANT.translate(-e,-r),l=M.CONSTANT.translate(e,r),h=M.CONSTANT.shear1(t),c=M.CONSTANT.shear2(t);return F(function(t,e,r,n){var u=M.multiply(s,[r,n,1]);u=M.multiply(h,u).map(Math.round),u=M.multiply(c,u).map(Math.round),u=M.multiply(h,u).map(Math.round),u=M.multiply(l,u);var f=b(u,2),v=f[0],g=f[1];if(!(v<0||g<0||v>o-1||g>a-1)){var d=4*(g*o+v);t[d]=i.pixels[e],t[d+1]=i.pixels[e+1],t[d+2]=i.pixels[e+2],t[d+3]=i.pixels[e+3]}})(n)}}function z(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:200,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=E(t);var i=(e=E(e))/100;return O(function(e,n){var o=i*x.brightness(e[n],e[n+1],e[n+2])>=t?255:0;r?0==o&&(e[n]=e[n+1]=e[n+2]=0):e[n]=e[n+1]=e[n+2]=Math.round(o)})}function j(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([1,2,1,2,4,2,1,2,1],1/16*((t=E(t))/100)))}function V(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([1,4,6,4,1,4,16,24,16,4,6,24,36,24,6,4,16,24,16,4,1,4,6,4,1],1/256*((t=E(t))/100)))}function U(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=E(t),P([5,5,5,-3,0,-3,-3,-3,-3])}function X(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=E(t),P([5,-3,-3,5,0,-3,5,-3,-3])}function Y(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,24,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],(t=E(t))/100))}function q(){return P(H([1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1],1/9))}function K(){return P(H([1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1],1/9))}function W(){return P(H([1,0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,0,0,1,0,1,0,0,0,1,0,0,0,1],1/9))}function Z(){return P([-1,-2,-1,0,0,0,1,2,1])}function J(){return P([-1,0,1,-2,0,2,-1,0,1])}var Q=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],tt=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function et(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}function rt(t,e,r){return r?function(t,e,r,i){if(isNaN(i)||i<1)return t;i|=0;var n,o,a,s,l,h,c,u,f,v,g,d,p,m,y,b,k,C,w,x,_,$,S,M,H=t.pixels,B=t.width,R=t.height,E=i+i+1,A=B-1,O=R-1,I=i+1,L=I*(I+1)/2,F=new et,G=F;for(a=1;a>z,0!=S?(S=255/S,H[h]=(u*T>>z)*S,H[h+1]=(f*T>>z)*S,H[h+2]=(v*T>>z)*S):H[h]=H[h+1]=H[h+2]=0,u-=d,f-=p,v-=m,g-=y,d-=N.r,p-=N.g,m-=N.b,y-=N.a,s=c+((s=n+i+1)>z,S>0?(S=255/S,H[s]=(u*T>>z)*S,H[s+1]=(f*T>>z)*S,H[s+2]=(v*T>>z)*S):H[s]=H[s+1]=H[s+2]=0,u-=d,f-=p,v-=m,g-=y,d-=N.r,p-=N.g,m-=N.b,y-=N.a,s=n+((s=o+I)0&&void 0!==arguments[0]?arguments[0]:10,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t=E(t),function(r){return rt(r,t,e)}}function nt(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:256;return P(H([1,4,6,4,1,4,16,24,16,4,6,24,-476,24,6,4,16,24,16,4,1,4,6,4,1],-1/(t=E(t))))}var ot=d({},{crop:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments[2],i=arguments[3],n=R(r*i*4,r,i);return function(o){for(var a=e,s=0;a0&&void 0!==arguments[0]?arguments[0]:0;return t=E(t),t%=360,function(e){if(0==t)return e;if(90==t||270==t)var r=R(e.pixels.length,e.height,e.width);else{if(180!=t)return T(t)(e);r=R(e.pixels.length,e.width,e.height)}return e.width,e.height,F(function(i,n,o,a){if(90==t)var s=4*(o*r.width+(r.width-1-a));else 270==t?s=4*((r.height-1-o)*r.width+a):180==t&&(s=4*((r.height-1-a)*r.width+(r.width-1-o)));r.pixels[s]=e.pixels[n],r.pixels[s+1]=e.pixels[n+1],r.pixels[s+2]=e.pixels[n+2],r.pixels[s+3]=e.pixels[n+3]})(e),r}},rotateDegree:T,"rotate-degree":T},{bitonal:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:100;return t=x.parse(t),e=x.parse(e),O(function(i,n){i[n]+i[n+1]+i[n+2]<=r?(i[n]=t.r,i[n+1]=t.g,i[n+2]=t.b):(i[n]=e.r,i[n+1]=e.g,i[n+2]=e.b)})},brightness:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;t=E(t);var e=Math.floor(t/100*255);return O(function(t,r){t[r]+=e,t[r+1]+=e,t[r+2]+=e})},clip:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;t=E(t);var e=2.55*Math.abs(t);return O(function(t,r){for(var i=r,n=r+2;i<=n;i++)t[i]>255-e?t[i]=255:t[i]0&&void 0!==arguments[0]?arguments[0]:0;t=E(t);var e=Math.max((128+t)/128,0);return O(function(t,r){t[r]=t[r]*e,t[r+1]=t[r+1]*e,t[r+2]=t[r+2]*e})},gamma:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=E(t),O(function(e,r){e[r]=255*Math.pow(e[r]/255,t),e[r+1]=255*Math.pow(e[r+1]/255,t),e[r+2]=255*Math.pow(e[r+2]/255,t)})},gradient:function(){var t=[].concat(Array.prototype.slice.call(arguments));1===t.length&&"string"==typeof t[0]&&(t=x.convertMatchesArray(t[0]));var e=(t=t.map(function(t){return x.matches(t).length?{type:"param",value:t}:{type:"scale",value:t}})).filter(function(t){return"scale"==t.type})[0];e=e?+e.value:256,t=t.filter(function(t){return"param"==t.type}).map(function(t){return t.value}).join(",");var r=x.gradient(t,e).map(function(t){return x.parse(t)});return O(function(t,i){var n=D(x.brightness(t[i],t[i+1],t[i+2])),o=D(Math.floor(n*(e/256))),a=r[o];t[i]=a.r,t[i+1]=a.g,t[i+2]=a.b,t[i+3]=D(Math.floor(256*a.a))})},grayscale:function(t){var e=(t=E(t))/100;return e>1&&(e=1),O(function(t,r){B(t,r,[.2126+.7874*(1-e),.7152-.7152*(1-e),.0722-.0722*(1-e),0,.2126-.2126*(1-e),.7152+.2848*(1-e),.0722-.0722*(1-e),0,.2126-.2126*(1-e),.7152-.7152*(1-e),.0722+.9278*(1-e),0,0,0,0,1])})},hue:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:360;return t=E(t),O(function(e,r){var i=e[r],n=e[r+1],o=e[r+2],a=Color.RGBtoHSV(i,n,o),s=a.h;s+=Math.abs(t),s%=360,a.h=s;var l=Color.HSVtoRGB(a);e[r]=l.r,e[r+1]=l.g,e[r+2]=l.b})},invert:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=E(t))/100;return O(function(t,r){t[r]=(255-t[r])*e,t[r+1]=(255-t[r+1])*e,t[r+2]=(255-t[r+2])*e})},noise:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=E(t),O(function(e,r){var i=5*Math.abs(t),n=-i,o=i,a=Math.round(n+Math.random()*(o-n));e[r]+=a,e[r+1]+=a,e[r+2]+=a})},opacity:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=E(t))/100;return O(function(t,r){t[r+3]*=e})},saturation:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=E(t))/100,r=1-Math.abs(e);return O(function(t,e){B(t,e,[r,0,0,0,0,r,0,0,0,0,r,0,0,0,0,r])})},sepia:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=E(t))/100;return e>1&&(e=1),O(function(t,r){B(t,r,[.393+.607*(1-e),.769-.769*(1-e),.189-.189*(1-e),0,.349-.349*(1-e),.686+.314*(1-e),.168-.168*(1-e),0,.272-.272*(1-e),.534-.534*(1-e),.131+.869*(1-e),0,0,0,0,1])})},shade:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return t=E(t),e=E(e),r=E(r),O(function(i,n){i[n]*=t,i[n+1]*=e,i[n+2]*=r})},solarize:function(t,e,r){return t=E(t),e=E(e),r=E(r),O(function(i,n){i[n]0&&void 0!==arguments[0]?arguments[0]:200,arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,!1)},"threshold-color":z},{blur:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3;return P(G(t=E(t)))},emboss:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;return P([-2*(t=E(t)),-t,0,-t,1,t,0,t,2*t])},gaussianBlur:j,"gaussian-blur":j,gaussianBlur5x:V,"gaussian-blur-5x":V,grayscale2:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([.3,.3,.3,0,0,.59,.59,.59,0,0,.11,.11,.11,0,0,0,0,0,0,0,0,0,0,0,0],(t=E(t))/100))},identity:function(){return P([0,0,0,0,1,0,0,0,0])},kirschHorizontal:U,"kirsch-horizontal":U,kirschVertical:X,"kirsch-vertical":X,laplacian:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([-1,-1,-1,-1,8,-1,-1,-1,-1],(t=E(t))/100))},laplacian5x:Y,"laplacian-5x":Y,motionBlur:q,"motion-blur":q,motionBlur2:K,"motion-blur-2":K,motionBlur3:W,"motion-blur-3":W,negative:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([-1,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0,0,0,1,0,1,1,1,1,1],(t=E(t))/100))},random:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[9,16,25,36,49,64,81,100].sort(function(t,e){return.5-Math.random()})[0];return t=E(t),function(t,r,i){return P(function(t,e,r){for(var i=[],n=1;n<=r;n++){var o=Math.random()*(e-t)+t,a=Math.floor(10*Math.random())%2==0?-1:1;i.push(a*o)}i.sort();var s=Math.floor(r/2),l=i[s];return i[s]=i[0],i[0]=l,i}(-1,5,e))(t,r,i)}},sepia2:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([.393,.349,.272,0,0,.769,.686,.534,0,0,.189,.168,.131,0,0,0,0,0,0,0,0,0,0,0,0],(t=E(t))/100))},sharpen:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([0,-1,0,-1,5,-1,0,-1,0],(t=E(t))/100))},sobelHorizontal:Z,"sobel-horizontal":Z,sobelVertical:J,"sobel-vertical":J,stackBlur:it,"stack-blur":it,transparency:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return P(H([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,.3,0,0,0,0,0,1],(t=E(t))/100))},unsharpMasking:nt,"unsharp-masking":nt});Object.assign(ot,{pack:O,packXY:F,swapColor:L});var at=ot;at.filter=function(t){return at.merge(N(t).map(function(t){return t.arr}))},at.multi=function(){for(var t=arguments.length,e=Array(t),r=0;r1?r-1:0),n=1;n1&&void 0!==arguments[1]?arguments[1]:1,r=[],i=0;i0&&void 0!==arguments[0]?arguments[0]:100;return at.filter("grayscale laplacian("+t)},at.laplacian5x.grayscale=function(){return at.filter("grayscale laplacian5x")},at.kirsch=function(){return at.filter("kirsch-horizontal kirsch-vertical")},at.kirsch.grayscale=function(){return at.filter("grayscale kirsch")},at.sobel=function(){return at.filter("sobel-horizontal sobel-vertical")},at.sobel.grayscale=function(){return at.filter("grayscale sobel")},at.vintage=function(){return at.filter("brightness(15) saturation(-20) gamma(1.8)")};var st=0,lt=[],ht=function(){function t(e,r,i){if(v(this,t),"string"!=typeof e)this.el=e;else{var n=document.createElement(e);for(var o in this.uniqId=st++,r&&(n.className=r),i=i||{})n.setAttribute(o,i[o]);this.el=n}}return g(t,[{key:"attr",value:function(t,e){return 1==arguments.length?this.el.getAttribute(t):(this.el.setAttribute(t,e),this)}},{key:"closest",value:function(e){for(var r=this,i=!1;!(i=r.hasClass(e));){if(!r.el.parentNode)return null;r=new t(r.el.parentNode)}return i?r:null}},{key:"removeClass",value:function(t){this.el.className=(" "+this.el.className+" ").replace(" "+t+" "," ").trim()}},{key:"hasClass",value:function(t){return!!this.el.className&&(" "+this.el.className+" ").indexOf(" "+t+" ")>-1}},{key:"addClass",value:function(t){this.hasClass(t)||(this.el.className=this.el.className+" "+t)}},{key:"toggleClass",value:function(t){this.hasClass(t)?this.removeClass(t):this.addClass(t)}},{key:"html",value:function(t){return"string"==typeof t?this.el.innerHTML=t:this.empty().append(t),this}},{key:"empty",value:function(){return this.html("")}},{key:"append",value:function(t){return"string"==typeof t?this.el.appendChild(document.createTextNode(t)):this.el.appendChild(t.el||t),this}},{key:"appendTo",value:function(t){return(t.el?t.el:t).appendChild(this.el),this}},{key:"remove",value:function(){return this.el.parentNode&&this.el.parentNode.removeChild(this.el),this}},{key:"text",value:function(){return this.el.textContent}},{key:"css",value:function(t,e){var r=this;if(2==arguments.length)this.el.style[t]=e;else if(1==arguments.length){if("string"==typeof t)return getComputedStyle(this.el)[t];var i=t||{};Object.keys(i).forEach(function(t){r.el.style[t]=i[t]})}return this}},{key:"cssFloat",value:function(t){return parseFloat(this.css(t))}},{key:"cssInt",value:function(t){return parseInt(this.css(t))}},{key:"offset",value:function(){var t=this.el.getBoundingClientRect();return{top:t.top+document.documentElement.scrollTop,left:t.left+document.documentElement.scrollLeft}}},{key:"position",value:function(){return this.el.style.top?{top:parseFloat(this.css("top")),left:parseFloat(this.css("left"))}:this.el.getBoundingClientRect()}},{key:"width",value:function(){return this.el.offsetWidth}},{key:"contentWidth",value:function(){return this.width()-this.cssFloat("padding-left")-this.cssFloat("padding-right")}},{key:"height",value:function(){return this.el.offsetHeight}},{key:"contentHeight",value:function(){return this.height()-this.cssFloat("padding-top")-this.cssFloat("padding-bottom")}},{key:"dataKey",value:function(t){return this.uniqId+"."+t}},{key:"data",value:function(t,e){if(2!=arguments.length){if(1==arguments.length)return lt[this.dataKey(t)];var r=Object.keys(lt),i=this.uniqId+".";return r.filter(function(t){return 0==t.indexOf(i)}).map(function(t){return lt[t]})}return lt[this.dataKey(t)]=e,this}},{key:"val",value:function(t){return 0==arguments.length?this.el.value:(1==arguments.length&&(this.el.value=t),this)}},{key:"int",value:function(){return parseInt(this.val(),10)}},{key:"float",value:function(){return parseFloat(this.val())}},{key:"show",value:function(){return this.css("display","block")}},{key:"hide",value:function(){return this.css("display","none")}},{key:"toggle",value:function(){return"none"==this.css("display")?this.show():this.hide()}},{key:"scrollTop",value:function(){return this.el===document.body?document.documentElement.scrollTop:this.el.scrollTop}},{key:"scrollLeft",value:function(){return this.el===document.body?document.documentElement.scrollLeft:this.el.scrollLeft}},{key:"on",value:function(t,e,r,i){return this.el.addEventListener(t,e,r,i),this}},{key:"off",value:function(t,e){return this.el.removeEventListener(t,e),this}},{key:"getElement",value:function(){return this.el}},{key:"createChild",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=new t(e,r,i);return o.css(n),this.append(o),o}}]),t}(),ct={addEvent:function(t,e,r){t.addEventListener(e,r)},removeEvent:function(t,e,r){t.removeEventListener(e,r)},pos:function(t){return t.touches&&t.touches[0]?t.touches[0]:t}},ut=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};v(this,t),this.masterObj=e,this.settingObj=r}return g(t,[{key:"set",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.settingObj[t]=e||r}},{key:"init",value:function(t){if(!this.has(t)){var e=t.split("."),r=this.masterObj[e[0]]||this.masterObj,i=e.pop();if(r[i]){for(var n=arguments.length,o=Array(n>1?n-1:0),a=1;a1&&void 0!==arguments[1]?arguments[1]:"";return this.init(t,e),this.settingObj[t]||e}},{key:"has",value:function(t){return!!this.settingObj[t]}}]),t}(),ft=/^(click|mouse(down|up|move|enter|leave)|key(down|up|press)|contextmenu|change|input)/gi,vt=["Control","Shift","Alt","Meta"],gt=function(){function t(){v(this,t),this.state=new ut(this)}return g(t,[{key:"initializeEvent",value:function(){this.initializeEventMachin()}},{key:"destroy",value:function(){this.destroyEventMachin()}},{key:"destroyEventMachin",value:function(){this.removeEventAll()}},{key:"initializeEventMachin",value:function(){this.filterProps(ft).forEach(this.parseEvent.bind(this))}},{key:"filterProps",value:function(t){return Object.getOwnPropertyNames(this.__proto__).filter(function(e){return e.match(t)})}},{key:"parseEvent",value:function(t){var e=t.split(" ");this.bindingEvent(e,this[t].bind(this))}},{key:"getDefaultDomElement",value:function(t){var e=void 0;return(e=t?this[t]||window[t]:this.el||this.$el||this.$root)instanceof ht?e.getElement():e}},{key:"getDefaultEventObject",value:function(t){var e=this,r=t.split("."),i=r.shift(),n=r.includes("Control"),o=r.includes("Shift"),a=r.includes("Alt"),s=r.includes("Meta"),l=(r=r.filter(function(t){return!1===vt.includes(t)})).filter(function(t){return!!e[t]});return{eventName:i,isControl:n,isShift:o,isAlt:a,isMeta:s,codes:r=r.filter(function(t){return!1===l.includes(t)}).map(function(t){return t.toLowerCase()}),checkMethodList:l}}},{key:"bindingEvent",value:function(t,e){var r,i=(r=t,Array.isArray(r)?r:Array.from(r)),n=i[0],o=i[1],a=i.slice(2);o=this.getDefaultDomElement(o);var s=this.getDefaultEventObject(n);s.dom=o,s.delegate=a.join(" "),this.addEvent(s,e)}},{key:"matchPath",value:function(t,e){return t?t.matches(e)?t:this.matchPath(t.parentElement,e):null}},{key:"getBindings",value:function(){return this._bindings||this.initBindings(),this._bindings}},{key:"addBinding",value:function(t){this.getBindings().push(t)}},{key:"initBindings",value:function(){this._bindings=[]}},{key:"checkEventType",value:function(t,e){var r=this,i=!t.ctrlKey||e.isControl,n=!t.shiftKey||e.isShift,o=!t.altKey||e.isAlt,a=!t.metaKey||e.isMeta,s=!0;e.codes.length&&(s=e.codes.includes(t.code.toLowerCase())||e.codes.includes(t.key.toLowerCase()));var l=!0;return e.checkMethodList.length&&(l=e.checkMethodList.every(function(e){return r[e].call(r,t)})),i&&o&&n&&a&&s&&l}},{key:"makeCallback",value:function(t,e){var r=this;return t.delegate?function(i){if(r.checkEventType(i,t)){var n=r.matchPath(i.target||i.srcElement,t.delegate);if(n)return i.delegateTarget=n,i.$delegateTarget=new ht(n),e(i)}}:function(i){if(r.checkEventType(i,t))return e(i)}}},{key:"addEvent",value:function(t,e){t.callback=this.makeCallback(t,e),this.addBinding(t),ct.addEvent(t.dom,t.eventName,t.callback)}},{key:"removeEventAll",value:function(){var t=this;this.getBindings().forEach(function(e){t.removeEvent(e)}),this.initBindings()}},{key:"removeEvent",value:function(t){var e=t.eventName,r=t.dom,i=t.callback;ct.removeEvent(r,e,i)}}]),t}(),dt=function(t){function e(t){v(this,e);var r=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return m(e,gt),g(e,[{key:"initialize",value:function(){this.$el=new ht("div","control"),this.$hue=this.$el.createChild("div","hue"),this.$opacity=this.$el.createChild("div","opacity"),this.$controlPattern=this.$el.createChild("div","empty"),this.$controlColor=this.$el.createChild("div","color"),this.$hueContainer=this.$hue.createChild("div","hue-container"),this.$drag_bar=this.$hueContainer.createChild("div","drag-bar"),this.drag_bar_pos={},this.$opacityContainer=this.$opacity.createChild("div","opacity-container"),this.$opacityColorBar=this.$opacityContainer.createChild("div","color-bar"),this.$opacity_drag_bar=this.$opacityContainer.createChild("div","drag-bar2"),this.opacity_drag_bar_pos={}}},{key:"setBackgroundColor",value:function(t){this.$controlColor.css("background-color",t)}},{key:"refresh",value:function(){this.setColorUI()}},{key:"setColorUI",value:function(){var t=this.state.get("$el.width")*this.colorpicker.currentS,e=this.state.get("$el.height")*(1-this.colorpicker.currentV);this.$drag_pointer.css({left:t+"px",top:e+"px"})}},{key:"setOpacityColorBar",value:function(t){var e=x.parse(t);e.a=0;var r=x.format(e,"rgb");e.a=1;var i=x.format(e,"rgb");this.$opacityColorBar.css("background","linear-gradient(to right, "+r+", "+i+")")}},{key:"setOpacity",value:function(t){var e,r=this.$opacityContainer.offset().left,i=r+this.state.get("$opacityContainer.width"),n=ct.pos(t).clientX;e=ni?100:(n-r)/(i-r)*100;var o=this.state.get("$opacityContainer.width")*(e/100);this.$opacity_drag_bar.css({left:o-Math.ceil(this.state.get("$opacity_drag_bar.width")/2)+"px"}),this.opacity_drag_bar_pos={x:o},this.colorpicker.setCurrentA(this.caculateOpacity()),this.colorpicker.currentFormat(),this.colorpicker.setInputColor()}},{key:"setInputColor",value:function(){this.setBackgroundColor(this.colorpicker.getFormattedColor("rgb"));var t=this.colorpicker.convertRGB(),e=x.format(t,"rgb");this.setOpacityColorBar(e)}},{key:"setColorUI",value:function(){var t=this.state.get("$hueContainer.width")*(this.colorpicker.currentH/360);this.$drag_bar.css({left:t-7.5+"px"}),this.drag_bar_pos={x:t};var e=this.state.get("$opacityContainer.width")*(this.colorpicker.currentA||0);this.$opacity_drag_bar.css({left:e-7.5+"px"}),this.opacity_drag_bar_pos={x:e}}},{key:"caculateH",value:function(){return{h:(this.drag_bar_pos||{x:0}).x/this.state.get("$hueContainer.width")*360}}},{key:"caculateOpacity",value:function(){var t=this.opacity_drag_bar_pos||{x:0},e=Math.round(t.x/this.state.get("$opacityContainer.width")*100)/100;return isNaN(e)?1:e}},{key:"EventDocumentMouseMove",value:function(t){this.isHueDown&&this.setHueColor(t),this.isOpacityDown&&this.setOpacity(t)}},{key:"EventDocumentMouseUp",value:function(t){this.isHueDown=!1,this.isOpacityDown=!1}},{key:"setControlColor",value:function(t){this.$controlColor.css("background-color",t)}},{key:"setHueColor",value:function(t){var e,r=this.$hueContainer.offset().left,i=r+this.state.get("$hueContainer.width"),n=t?ct.pos(t).clientX:r+(i-r)*(this.colorpicker.currentH/360);e=ni?100:(n-r)/(i-r)*100;var o=this.state.get("$hueContainer.width")*(e/100);this.$drag_bar.css({left:o-Math.ceil(this.state.get("$drag_bar.width")/2)+"px"}),this.drag_bar_pos={x:o};var a=$.checkHueColor(e/100);this.colorpicker.setBackgroundColor(a),this.colorpicker.setCurrentH(e/100*360),this.colorpicker.setInputColor()}},{key:"setOnlyHueColor",value:function(){var t,e=this.$hueContainer.offset().left,r=e+this.state.get("$hueContainer.width"),i=e+(r-e)*(this.colorpicker.currentH/360);t=ir?100:(i-e)/(r-e)*100;var n=this.state.get("$hueContainer.width")*(t/100);this.$drag_bar.css({left:n-Math.ceil(this.state.get("$drag_bar.width")/2)+"px"}),this.drag_bar_pos={x:n};var o=$.checkHueColor(t/100);this.colorpicker.setBackgroundColor(o),this.colorpicker.setCurrentH(t/100*360)}},{key:"mousedown $drag_bar",value:function(t){t.preventDefault(),this.isHueDown=!0}},{key:"mousedown $opacity_drag_bar",value:function(t){t.preventDefault(),this.isOpacityDown=!0}},{key:"mousedown $hueContainer",value:function(t){this.isHueDown=!0,this.setHueColor(t)}},{key:"mousedown $opacityContainer",value:function(t){this.isOpacityDown=!0,this.setOpacity(t)}}]),e}(),pt=function(t){function e(t){v(this,e);var r=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return m(e,gt),g(e,[{key:"initialize",value:function(){this.$el=new ht("div","information hex"),this.$informationChange=this.$el.createChild("div","information-change"),this.$formatChangeButton=this.$informationChange.createChild("button","format-change-button arrow-button",{type:"button"}),this.$el.append(this.makeInputFieldHex()),this.$el.append(this.makeInputFieldRgb()),this.$el.append(this.makeInputFieldHsl()),this.format="hex"}},{key:"makeInputFieldHex",value:function(){var t=new ht("div","information-item hex"),e=t.createChild("div","input-field hex");return this.$hexCode=e.createChild("input","input",{type:"text"}),e.createChild("div","title").html("HEX"),t}},{key:"makeInputFieldRgb",value:function(){var t=new ht("div","information-item rgb"),e=t.createChild("div","input-field rgb-r");return this.$rgb_r=e.createChild("input","input",{type:"number",step:1,min:0,max:255}),e.createChild("div","title").html("R"),e=t.createChild("div","input-field rgb-g"),this.$rgb_g=e.createChild("input","input",{type:"number",step:1,min:0,max:255}),e.createChild("div","title").html("G"),e=t.createChild("div","input-field rgb-b"),this.$rgb_b=e.createChild("input","input",{type:"number",step:1,min:0,max:255}),e.createChild("div","title").html("B"),e=t.createChild("div","input-field rgb-a"),this.$rgb_a=e.createChild("input","input",{type:"number",step:.01,min:0,max:1}),e.createChild("div","title").html("A"),t}},{key:"makeInputFieldHsl",value:function(){var t=new ht("div","information-item hsl"),e=t.createChild("div","input-field hsl-h");return this.$hsl_h=e.createChild("input","input",{type:"number",step:1,min:0,max:360}),e.createChild("div","title").html("H"),e=t.createChild("div","input-field hsl-s"),this.$hsl_s=e.createChild("input","input",{type:"number",step:1,min:0,max:100}),e.createChild("div","postfix").html("%"),e.createChild("div","title").html("S"),e=t.createChild("div","input-field hsl-l"),this.$hsl_l=e.createChild("input","input",{type:"number",step:1,min:0,max:100}),e.createChild("div","postfix").html("%"),e.createChild("div","title").html("L"),e=t.createChild("div","input-field hsl-a"),this.$hsl_a=e.createChild("input","input",{type:"number",step:.01,min:0,max:1}),e.createChild("div","title").html("A"),t}},{key:"currentFormat",value:function(){var t=this.format||"hex";if(this.colorpicker.currentA<1&&"hex"==t){this.$el.removeClass(t),this.$el.addClass("rgb"),this.format="rgb",this.colorpicker.setInputColor()}}},{key:"setCurrentFormat",value:function(t){this.format=t,this.initFormat()}},{key:"initFormat",value:function(){var t=this.format||"hex";this.$el.removeClass("hex"),this.$el.removeClass("rgb"),this.$el.removeClass("hsl"),this.$el.addClass(t)}},{key:"nextFormat",value:function(){var t=this.format||"hex",e="hex";"hex"==t?e="rgb":"rgb"==t?e="hsl":"hsl"==t&&(e=1==this.colorpicker.currentA?"hex":"rgb"),this.$el.removeClass(t),this.$el.addClass(e),this.format=e,this.setInputColor(),this.colorpicker.changeInputColorAfterNextFormat()}},{key:"setRGBInput",value:function(t,e,r){this.$rgb_r.val(t),this.$rgb_g.val(e),this.$rgb_b.val(r),this.$rgb_a.val(this.colorpicker.currentA)}},{key:"setHSLInput",value:function(t,e,r){this.$hsl_h.val(t),this.$hsl_s.val(e),this.$hsl_l.val(r),this.$hsl_a.val(this.colorpicker.currentA)}},{key:"getHexFormat",value:function(){return x.format({r:this.$rgb_r.int(),g:this.$rgb_g.int(),b:this.$rgb_b.int()},"hex",this.colorpicker.opt.color)}},{key:"getRgbFormat",value:function(){return x.format({r:this.$rgb_r.int(),g:this.$rgb_g.int(),b:this.$rgb_b.int(),a:this.$rgb_a.float()},"rgb",this.colorpicker.opt.color)}},{key:"getHslFormat",value:function(){return x.format({h:this.$hsl_h.val(),s:this.$hsl_s.val(),l:this.$hsl_l.val(),a:this.$hsl_a.float()},"hsl",this.colorpicker.opt.color)}},{key:"convertRGB",value:function(){return this.colorpicker.convertRGB()}},{key:"convertHEX",value:function(){return this.colorpicker.convertHEX()}},{key:"convertHSL",value:function(){return this.colorpicker.convertHSL()}},{key:"getFormattedColor",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"hex"==(t=t||this.getFormat())?this.$hexCode.val():"rgb"==t?this.getRgbFormat(e):"hsl"==t?this.getHslFormat(e):void 0}},{key:"getFormat",value:function(){return this.format||"hex"}},{key:"setInputColor",value:function(){var t=this.getFormat(),e=null;if("hex"==t){this.$hexCode.val(this.convertHEX());e=this.convertRGB();this.setRGBInput(e.r,e.g,e.b,e.a)}else if("rgb"==t){e=this.convertRGB();this.setRGBInput(e.r,e.g,e.b,e.a),this.$hexCode.val(this.convertHEX())}else if("hsl"==t){var r=this.convertHSL();this.setHSLInput(r.h,r.s,r.l,r.a)}}},{key:"checkNumberKey",value:function(t){return ct.checkNumberKey(t)}},{key:"checkNotNumberKey",value:function(t){return!ct.checkNumberKey(t)}},{key:"changeRgbColor",value:function(){this.colorpicker.changeInformationColor(this.getRgbFormat())}},{key:"changeHslColor",value:function(){this.colorpicker.changeInformationColor(this.getHslFormat())}},{key:"change $rgb_r",value:function(t){this.changeRgbColor()}},{key:"change $rgb_g",value:function(t){this.changeRgbColor()}},{key:"change $rgb_b",value:function(t){this.changeRgbColor()}},{key:"change $rgb_a",value:function(t){this.changeRgbColor()}},{key:"change $hsl_h",value:function(t){this.changeHslColor()}},{key:"change $hsl_s",value:function(t){this.changeHslColor()}},{key:"change $hsl_l",value:function(t){this.changeHslColor()}},{key:"change $hsl_a",value:function(t){this.changeHslColor()}},{key:"keydown $hexCode",value:function(t){if(t.which<65||t.which>70)return this.checkNumberKey(t)}},{key:"keyup $hexCode",value:function(t){var e=this.$hexCode.val();"#"==e.charAt(0)&&7==e.length&&(this.colorpicker.changeInformationColor(e),this.setInputColor())}},{key:"click $formatChangeButton",value:function(t){this.nextFormat()}},{key:"refresh",value:function(){}}]),e}(),mt=function(t){function e(t){v(this,e);var r=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return m(e,gt),g(e,[{key:"initialize",value:function(){this.$el=new ht("div","color"),this.$saturation=this.$el.createChild("div","saturation"),this.$value=this.$saturation.createChild("div","value"),this.$drag_pointer=this.$value.createChild("div","drag-pointer")}},{key:"setBackgroundColor",value:function(t){this.$el.css("background-color",t)}},{key:"refresh",value:function(){this.setColorUI()}},{key:"caculateSV",value:function(){var t=this.drag_pointer_pos||{x:0,y:0},e=this.state.get("$el.width"),r=this.state.get("$el.height");return{s:t.x/e,v:(r-t.y)/r,width:e,height:r}}},{key:"setColorUI",value:function(){var t=this.state.get("$el.width")*this.colorpicker.currentS,e=this.state.get("$el.height")*(1-this.colorpicker.currentV);this.$drag_pointer.css({left:t-5+"px",top:e-5+"px"}),this.drag_pointer_pos={x:t,y:e}}},{key:"setMainColor",value:function(t){t.preventDefault();var e=this.$el.position(),r=this.state.get("$el.contentWidth"),i=this.state.get("$el.contentHeight"),n=t.clientX-e.left,o=t.clientY-e.top;n<0?n=0:n>r&&(n=r),o<0?o=0:o>i&&(o=i),this.$drag_pointer.css({left:n-5+"px",top:o-5+"px"}),this.drag_pointer_pos={x:n,y:o},this.colorpicker.caculateHSV(),this.colorpicker.setInputColor()}},{key:"EventDocumentMouseUp",value:function(t){this.isDown=!1}},{key:"EventDocumentMouseMove",value:function(t){this.isDown&&this.setMainColor(t)}},{key:"mousedown",value:function(t){this.isDown=!0,this.setMainColor(t)}},{key:"mouseup",value:function(t){this.isDown=!1}}]),e}(),yt="data-colorsets-index",bt=function(t){function e(t){v(this,e);var r=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return m(e,gt),g(e,[{key:"initialize",value:function(){this.$el=new ht("div","color-chooser");var t=this.$el.createChild("div","color-chooser-container"),e=t.createChild("div","colorsets-item colorsets-item-header");e.createChild("h1","title").html("Color Paletts"),this.$toggleButton=e.createChild("span","items").html("×"),this.$colorsetsList=t.createChild("div","colorsets-list"),this.refresh()}},{key:"refresh",value:function(){this.$colorsetsList.html(this.makeColorSetsList())}},{key:"makeColorItemList",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5,r=new ht("div"),i=0;i1&&void 0!==arguments[1]&&arguments[1];if("object"==(void 0===t?"undefined":f(t))){if(!t.r||!t.g||!t.b)return;e?this.callbackColorValue(x.format(t,"hex")):this.initColor(x.format(t,"hex"))}else"string"==typeof t&&(e?this.callbackColorValue(t):this.initColor(t))}},{key:"getColor",value:function(t){this.caculateHSV();var e=this.convertRGB();return t?x.format(e,t):e}},{key:"definePositionForArrow",value:function(t,e,r){}},{key:"definePosition",value:function(t){var e=this.$root.width(),r=this.$root.height(),i=t.left-this.$body.scrollLeft();e+i>window.innerWidth&&(i-=e+i-window.innerWidth),i<0&&(i=0);var n=t.top-this.$body.scrollTop();r+n>window.innerHeight&&(n-=r+n-window.innerHeight),n<0&&(n=0),this.$root.css({left:i+"px",top:n+"px"})}},{key:"getInitalizePosition",value:function(){return"inline"==this.opt.position?{position:"relative",left:"auto",top:"auto",display:"inline-block"}:{position:"fixed",left:"-10000px",top:"-10000px"}}},{key:"show",value:function(t,e,r){this.destroy(),this.initializeEvent(),this.$root.appendTo(this.$body),this.$root.css(this.getInitalizePosition()).show(),this.definePosition(t),this.isColorPickerShow=!0,this.isShortCut=t.isShortCut||!1,this.initColor(e),this.colorpickerCallback=r,this.hideDelay=t.hideDelay||2e3,this.hideDelay>0&&this.setHideDelay(this.hideDelay)}},{key:"setHideDelay",value:function(t){var e=this;t=t||0,this.$root.off("mouseenter"),this.$root.off("mouseleave"),this.$root.on("mouseenter",function(){clearTimeout(e.timerCloseColorPicker)}),this.$root.on("mouseleave",function(){clearTimeout(e.timerCloseColorPicker),e.timerCloseColorPicker=setTimeout(e.hide.bind(e),t)}),clearTimeout(this.timerCloseColorPicker),this.timerCloseColorPicker=setTimeout(this.hide.bind(this),t)}},{key:"hide",value:function(){this.isColorPickerShow&&(this.destroy(),this.$root.hide(),this.$root.remove(),this.isColorPickerShow=!1)}},{key:"convertRGB",value:function(){return x.HSVtoRGB(this.currentH,this.currentS,this.currentV)}},{key:"convertHEX",value:function(){return x.format(this.convertRGB(),"hex")}},{key:"convertHSL",value:function(){return x.HSVtoHSL(this.currentH,this.currentS,this.currentV)}},{key:"getCurrentColor",value:function(){return this.information.getFormattedColor()}},{key:"getFormattedColor",value:function(t){if("rgb"==(t=t||"hex"))return(r=this.convertRGB()).a=this.currentA,x.format(r,"rgb");if("hsl"==t){var e=this.convertHSL();return e.a=this.currentA,x.format(e,"hsl")}var r=this.convertRGB();return x.format(r,"hex")}},{key:"setInputColor",value:function(t){this.information.setInputColor(t),this.control.setInputColor(t),this.callbackColorValue()}},{key:"changeInputColorAfterNextFormat",value:function(){this.control.setInputColor(),this.callbackColorValue()}},{key:"callbackColorValue",value:function(t){t=t||this.getCurrentColor(),isNaN(this.currentA)||("function"==typeof this.opt.onChange&&this.opt.onChange.call(this,t),"function"==typeof this.colorpickerCallback&&this.colorpickerCallback(t))}},{key:"caculateHSV",value:function(){var t=this.palette.caculateSV(),e=this.control.caculateH(),r=t.s,i=t.v,n=e.h;0==t.width&&(n=0,r=0,i=0),this.currentH=n,this.currentS=r,this.currentV=i}},{key:"setColorUI",value:function(){this.control.setColorUI(),this.palette.setColorUI()}},{key:"setCurrentHSV",value:function(t,e,r,i){this.currentA=i,this.currentH=t,this.currentS=e,this.currentV=r}},{key:"setCurrentH",value:function(t){this.currentH=t}},{key:"setCurrentA",value:function(t){this.currentA=t}},{key:"setBackgroundColor",value:function(t){this.palette.setBackgroundColor(t)}},{key:"setCurrentFormat",value:function(t){this.format=t,this.information.setCurrentFormat(t)}},{key:"getHSV",value:function(t){return"hsl"==t.type?x.HSLtoHSV(t):x.RGBtoHSV(t)}},{key:"initColor",value:function(t,e){var r=t||"#FF0000",i=x.parse(r);e=e||i.type,this.setCurrentFormat(e);var n=this.getHSV(i);this.setCurrentHSV(n.h,n.s,n.v,i.a),this.setColorUI(),this.setHueColor(),this.setInputColor()}},{key:"changeInformationColor",value:function(t){var e=t||"#FF0000",r=x.parse(e),i=this.getHSV(r);this.setCurrentHSV(i.h,i.s,i.v,r.a),this.setColorUI(),this.setHueColor(),this.control.setInputColor(),this.callbackColorValue()}},{key:"setHueColor",value:function(){this.control.setOnlyHueColor()}},{key:"checkColorPickerClass",value:function(t){var e=new ht(t).closest("codemirror-colorview"),r=new ht(t).closest("codemirror-colorpicker"),i=new ht(t).closest("CodeMirror");t.nodeName;return!!(r||e||i)}},{key:"checkInHtml",value:function(t){return"HTML"==t.nodeName}},{key:"mouseup document",value:function(t){this.palette.EventDocumentMouseUp(t),this.control.EventDocumentMouseUp(t),this.checkInHtml(t.target)||0==this.checkColorPickerClass(t.target)&&this.hide()}},{key:"mousemove document",value:function(t){this.palette.EventDocumentMouseMove(t),this.control.EventDocumentMouseMove(t)}},{key:"initializeEvent",value:function(){this.initializeEventMachin(),this.palette.initializeEvent(),this.control.initializeEvent(),this.information.initializeEvent(),this.currentColorSets.initializeEvent(),this.colorSetsChooser.initializeEvent(),this.contextMenu.initializeEvent()}},{key:"currentFormat",value:function(){this.information.currentFormat()}},{key:"toggleColorChooser",value:function(){this.colorSetsChooser.toggle()}},{key:"refreshColorSetsChooser",value:function(){this.colorSetsChooser.refresh()}},{key:"getColorSetsList",value:function(){return this.colorSetsList.getColorSetsList()}},{key:"setCurrentColorSets",value:function(t){this.colorSetsList.setCurrentColorSets(t),this.currentColorSets.refresh()}},{key:"setColorSets",value:function(t){this.colorSetsList.setUserList(t)}},{key:"destroy",value:function(){p(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this.control.destroy(),this.palette.destroy(),this.information.destroy(),this.colorSetsChooser.destroy(),this.colorSetsList.destroy(),this.currentColorSets.destroy(),this.contextMenu.destroy(),this.colorpickerCallback=void 0}}]),e}(),$t="codemirror-colorview",St="codemirror-colorview-background",Mt=["comment"];function Ht(t,e){"setValue"==e.origin?(t.state.colorpicker.close_color_picker(),t.state.colorpicker.init_color_update(),t.state.colorpicker.style_color_update()):t.state.colorpicker.style_color_update(t.getCursor().line)}function Bt(t,e){t.state.colorpicker.isUpdate||(t.state.colorpicker.isUpdate=!0,t.state.colorpicker.close_color_picker(),t.state.colorpicker.init_color_update(),t.state.colorpicker.style_color_update())}function Rt(t,e){Ht(t,{origin:"setValue"})}function Et(t,e){t.state.colorpicker.keyup(e)}function At(t,e){t.state.colorpicker.is_edit_mode()&&t.state.colorpicker.check_mousedown(e)}function Ot(t,e){Ht(t,{origin:"setValue"})}function It(t){t.state.colorpicker.close_color_picker()}var Lt=function(){function t(e,r){v(this,t),r="boolean"==typeof r?{mode:"edit"}:Object.assign({mode:"edit"},r||{}),this.opt=r,this.cm=e,this.markers={},this.excluded_token=this.opt.excluded_token||Mt,this.opt.colorpicker?this.colorpicker=this.opt.colorpicker(this.opt):this.colorpicker=new _t(this.opt),this.init_event()}return g(t,[{key:"init_event",value:function(){var t,e,r,i,n;this.cm.on("mousedown",At),this.cm.on("keyup",Et),this.cm.on("change",Ht),this.cm.on("update",Bt),this.cm.on("refresh",Rt),this.onPasteCallback=(t=this.cm,e=Ot,function(r){e.call(this,t,r)}),this.cm.getWrapperElement().addEventListener("paste",this.onPasteCallback),this.is_edit_mode()&&this.cm.on("scroll",(r=It,i=50,n=void 0,function(t,e){n&&clearTimeout(n),n=setTimeout(function(){r(t,e)},i||300)}))}},{key:"is_edit_mode",value:function(){return"edit"==this.opt.mode}},{key:"is_view_mode",value:function(){return"view"==this.opt.mode}},{key:"destroy",value:function(){this.cm.off("mousedown",At),this.cm.off("keyup",Et),this.cm.off("change",Ht),this.cm.getWrapperElement().removeEventListener("paste",this.onPasteCallback),this.is_edit_mode()&&this.cm.off("scroll")}},{key:"hasClass",value:function(t,e){return!!t.className&&(" "+t.className+" ").indexOf(" "+e+" ")>-1}},{key:"check_mousedown",value:function(t){this.hasClass(t.target,St)?this.open_color_picker(t.target.parentNode):this.close_color_picker()}},{key:"popup_color_picker",value:function(t){var e=this.cm.getCursor(),r=this,i={lineNo:e.line,ch:e.ch,color:t||"#FFFFFF",isShortCut:!0};Object.keys(this.markers).forEach(function(t){if(("#"+t).indexOf("#"+i.lineNo+":")>-1){var e=r.markers[t];e.ch<=i.ch&&i.ch<=e.ch+e.color.length&&(i.ch=e.ch,i.color=e.color,i.nameColor=e.nameColor)}}),this.open_color_picker(i)}},{key:"open_color_picker",value:function(t){var e=t.lineNo,r=t.ch,i=t.nameColor,n=t.color;if(this.colorpicker){var o=this,a=n,s=this.cm.charCoords({line:e,ch:r});this.colorpicker.show({left:s.left,top:s.bottom,isShortCut:t.isShortCut||!1,hideDelay:o.opt.hideDelay||2e3},i||n,function(t){o.cm.replaceRange(t,{line:e,ch:r},{line:e,ch:r+a.length},"*colorpicker"),a=t})}}},{key:"close_color_picker",value:function(t){this.colorpicker&&this.colorpicker.hide()}},{key:"key",value:function(t,e){return[t,e].join(":")}},{key:"keyup",value:function(t){this.colorpicker&&("Escape"==t.key?this.colorpicker.hide():0==this.colorpicker.isShortCut&&this.colorpicker.hide())}},{key:"init_color_update",value:function(){this.markers={}}},{key:"style_color_update",value:function(t){if(t)this.match(t);else for(var e=this.cm.lineCount(),r=0;r-1)&&(delete this.markers[s],n[o].marker.clear())}}},{key:"match_result",value:function(t){return x.matches(t.text)}},{key:"submatch",value:function(t,e){var r=this;this.empty_marker(t,e);var i={next:0};this.match_result(e).forEach(function(n){r.render(i,t,e,n.color,n.nameColor)})}},{key:"match",value:function(t){var e=this.cm.getLineHandle(t),r=this;this.cm.operation(function(){r.submatch(t,e)})}},{key:"make_element",value:function(){var t=document.createElement("div");return t.className=$t,this.is_edit_mode()?t.title="open color picker":t.title="",t.back_element=this.make_background_element(),t.appendChild(t.back_element),t}},{key:"make_background_element",value:function(){var t=document.createElement("div");return t.className=St,t}},{key:"set_state",value:function(t,e,r,i){var n=this.create_marker(t,e);return n.lineNo=t,n.ch=e,n.color=r,n.nameColor=i,n}},{key:"create_marker",value:function(t,e){var r=this.key(t,e);return this.markers[r]||(this.markers[r]=this.make_element()),this.markers[r]}},{key:"has_marker",value:function(t,e){var r=this.key(t,e);return!!this.markers[r]}},{key:"update_element",value:function(t,e){t.back_element.style.backgroundColor=e}},{key:"set_mark",value:function(t,e,r){this.cm.setBookmark({line:t,ch:e},{widget:r,handleMouseEvents:!0})}},{key:"is_excluded_token",value:function(t,e){for(var r=this.cm.getTokenTypeAt({line:t,ch:e}),i=0,n=0,o=this.excluded_token.length;n0}},{key:"render",value:function(t,e,r,i,n){var o=r.text.indexOf(i,t.next);if(!0!==this.is_excluded_token(e,o)){if(t.next=o+i.length,this.has_marker(e,o))return this.update_element(this.create_marker(e,o),n||i),void this.set_state(e,o,i,n);var a=this.create_marker(e,o);this.update_element(a,n||i),this.set_state(e,o,i,n||i),this.set_mark(e,o,a)}}}]),t}();return t&&t.defineOption("colorpicker",!1,function(e,r,i){i&&i!=t.Init&&e.state.colorpicker&&(e.state.colorpicker.destroy(),e.state.colorpicker=null),r&&(e.state.colorpicker=new Lt(e,r))}),{Color:x,ColorNames:r,ColorPicker:_t,ImageFilter:ot,HueColor:$,Canvas:u,ImageLoader:C}}(CodeMirror); +var CodeMirrorColorPicker=function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e={aliceblue:"rgb(240, 248, 255)",antiquewhite:"rgb(250, 235, 215)",aqua:"rgb(0, 255, 255)",aquamarine:"rgb(127, 255, 212)",azure:"rgb(240, 255, 255)",beige:"rgb(245, 245, 220)",bisque:"rgb(255, 228, 196)",black:"rgb(0, 0, 0)",blanchedalmond:"rgb(255, 235, 205)",blue:"rgb(0, 0, 255)",blueviolet:"rgb(138, 43, 226)",brown:"rgb(165, 42, 42)",burlywood:"rgb(222, 184, 135)",cadetblue:"rgb(95, 158, 160)",chartreuse:"rgb(127, 255, 0)",chocolate:"rgb(210, 105, 30)",coral:"rgb(255, 127, 80)",cornflowerblue:"rgb(100, 149, 237)",cornsilk:"rgb(255, 248, 220)",crimson:"rgb(237, 20, 61)",cyan:"rgb(0, 255, 255)",darkblue:"rgb(0, 0, 139)",darkcyan:"rgb(0, 139, 139)",darkgoldenrod:"rgb(184, 134, 11)",darkgray:"rgb(169, 169, 169)",darkgrey:"rgb(169, 169, 169)",darkgreen:"rgb(0, 100, 0)",darkkhaki:"rgb(189, 183, 107)",darkmagenta:"rgb(139, 0, 139)",darkolivegreen:"rgb(85, 107, 47)",darkorange:"rgb(255, 140, 0)",darkorchid:"rgb(153, 50, 204)",darkred:"rgb(139, 0, 0)",darksalmon:"rgb(233, 150, 122)",darkseagreen:"rgb(143, 188, 143)",darkslateblue:"rgb(72, 61, 139)",darkslategray:"rgb(47, 79, 79)",darkslategrey:"rgb(47, 79, 79)",darkturquoise:"rgb(0, 206, 209)",darkviolet:"rgb(148, 0, 211)",deeppink:"rgb(255, 20, 147)",deepskyblue:"rgb(0, 191, 255)",dimgray:"rgb(105, 105, 105)",dimgrey:"rgb(105, 105, 105)",dodgerblue:"rgb(30, 144, 255)",firebrick:"rgb(178, 34, 34)",floralwhite:"rgb(255, 250, 240)",forestgreen:"rgb(34, 139, 34)",fuchsia:"rgb(255, 0, 255)",gainsboro:"rgb(220, 220, 220)",ghostwhite:"rgb(248, 248, 255)",gold:"rgb(255, 215, 0)",goldenrod:"rgb(218, 165, 32)",gray:"rgb(128, 128, 128)",grey:"rgb(128, 128, 128)",green:"rgb(0, 128, 0)",greenyellow:"rgb(173, 255, 47)",honeydew:"rgb(240, 255, 240)",hotpink:"rgb(255, 105, 180)",indianred:"rgb(205, 92, 92)",indigo:"rgb(75, 0, 130)",ivory:"rgb(255, 255, 240)",khaki:"rgb(240, 230, 140)",lavender:"rgb(230, 230, 250)",lavenderblush:"rgb(255, 240, 245)",lawngreen:"rgb(124, 252, 0)",lemonchiffon:"rgb(255, 250, 205)",lightblue:"rgb(173, 216, 230)",lightcoral:"rgb(240, 128, 128)",lightcyan:"rgb(224, 255, 255)",lightgoldenrodyellow:"rgb(250, 250, 210)",lightgreen:"rgb(144, 238, 144)",lightgray:"rgb(211, 211, 211)",lightgrey:"rgb(211, 211, 211)",lightpink:"rgb(255, 182, 193)",lightsalmon:"rgb(255, 160, 122)",lightseagreen:"rgb(32, 178, 170)",lightskyblue:"rgb(135, 206, 250)",lightslategray:"rgb(119, 136, 153)",lightslategrey:"rgb(119, 136, 153)",lightsteelblue:"rgb(176, 196, 222)",lightyellow:"rgb(255, 255, 224)",lime:"rgb(0, 255, 0)",limegreen:"rgb(50, 205, 50)",linen:"rgb(250, 240, 230)",magenta:"rgb(255, 0, 255)",maroon:"rgb(128, 0, 0)",mediumaquamarine:"rgb(102, 205, 170)",mediumblue:"rgb(0, 0, 205)",mediumorchid:"rgb(186, 85, 211)",mediumpurple:"rgb(147, 112, 219)",mediumseagreen:"rgb(60, 179, 113)",mediumslateblue:"rgb(123, 104, 238)",mediumspringgreen:"rgb(0, 250, 154)",mediumturquoise:"rgb(72, 209, 204)",mediumvioletred:"rgb(199, 21, 133)",midnightblue:"rgb(25, 25, 112)",mintcream:"rgb(245, 255, 250)",mistyrose:"rgb(255, 228, 225)",moccasin:"rgb(255, 228, 181)",navajowhite:"rgb(255, 222, 173)",navy:"rgb(0, 0, 128)",oldlace:"rgb(253, 245, 230)",olive:"rgb(128, 128, 0)",olivedrab:"rgb(107, 142, 35)",orange:"rgb(255, 165, 0)",orangered:"rgb(255, 69, 0)",orchid:"rgb(218, 112, 214)",palegoldenrod:"rgb(238, 232, 170)",palegreen:"rgb(152, 251, 152)",paleturquoise:"rgb(175, 238, 238)",palevioletred:"rgb(219, 112, 147)",papayawhip:"rgb(255, 239, 213)",peachpuff:"rgb(255, 218, 185)",peru:"rgb(205, 133, 63)",pink:"rgb(255, 192, 203)",plum:"rgb(221, 160, 221)",powderblue:"rgb(176, 224, 230)",purple:"rgb(128, 0, 128)",rebeccapurple:"rgb(102, 51, 153)",red:"rgb(255, 0, 0)",rosybrown:"rgb(188, 143, 143)",royalblue:"rgb(65, 105, 225)",saddlebrown:"rgb(139, 69, 19)",salmon:"rgb(250, 128, 114)",sandybrown:"rgb(244, 164, 96)",seagreen:"rgb(46, 139, 87)",seashell:"rgb(255, 245, 238)",sienna:"rgb(160, 82, 45)",silver:"rgb(192, 192, 192)",skyblue:"rgb(135, 206, 235)",slateblue:"rgb(106, 90, 205)",slategray:"rgb(112, 128, 144)",slategrey:"rgb(112, 128, 144)",snow:"rgb(255, 250, 250)",springgreen:"rgb(0, 255, 127)",steelblue:"rgb(70, 130, 180)",tan:"rgb(210, 180, 140)",teal:"rgb(0, 128, 128)",thistle:"rgb(216, 191, 216)",tomato:"rgb(255, 99, 71)",turquoise:"rgb(64, 224, 208)",violet:"rgb(238, 130, 238)",wheat:"rgb(245, 222, 179)",white:"rgb(255, 255, 255)",whitesmoke:"rgb(245, 245, 245)",yellow:"rgb(255, 255, 0)",yellowgreen:"rgb(154, 205, 50)",transparent:"rgba(0, 0, 0, 0)"};var r={isColorName:function(t){return!!e[t]},getColorByName:function(t){return e[t]}};function i(t,e){if(t.length!==e.length)return!1;for(var r=0,i=t.length;r0)u=s(h);else u=e[Math.floor(a()*e.length)];o=!i(u,c),n[l]=u}return o}function c(t,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"linear";t=t,e=e||Math.max(2,Math.ceil(Math.sqrt(t.length/2)));var s=r||"euclidean";"string"==typeof s&&(s=n[s]);for(var c=0,u=function(){return(c=(9301*c+49297)%233280)/233280},f=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"linear";return o[r](t.length,e).map(function(e){return t[e]})}(t,e,a),v=!0,g=0;v;){if(v=h(e,t,l(e,t,f,s),f,!1,u),++g%i==0)break}return f}var u={create:function(t,e){var r=document.createElement("canvas");return r.width=t||0,r.height=e||0,r},drawPixels:function(t){var e=this.create(t.width,t.height),r=e.getContext("2d"),i=r.getImageData(0,0,e.width,e.height);return i.data.set(t.pixels),r.putImageData(i,0,0),e},createHistogram:function(t,e,r,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{black:!0,red:!1,green:!1,blue:!1},o=this.create(t,e),a=o.getContext("2d");a.clearRect(0,0,t,e),a.fillStyle="white",a.fillRect(0,0,t,e),a.globalAlpha=.7;var s={black:!1};n.black?s.black=!1:s.black=!0,n.red?s.red=!1:s.red=!0,n.green?s.green=!1:s.green=!0,n.blue?s.blue=!1:s.blue=!0,Object.keys(r).forEach(function(i){if(!s[i]){var n=r[i],o=Math.max.apply(Math,n),l=t/n.length;a.fillStyle=i,n.forEach(function(t,r){var i=e*(t/o),n=r*l;a.fillRect(n,e-i,l,i)})}}),"function"==typeof i&&i(o)},getHistogram:function(t){for(var e,r,i=new Array(256),n=new Array(256),o=new Array(256),a=new Array(256),s=0;s<256;s++)i[s]=0,n[s]=0,o[s]=0,a[s]=0;return r=function(t,e){var r=Math.round(_.brightness(t[e],t[e+1],t[e+2]));i[r]++,n[t[e]]++,o[t[e+1]]++,a[t[e+2]]++},function(t,e){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};v(this,t),this.isLoaded=!1,this.imageUrl=e,this.opt=r,this.initialize()}return g(t,[{key:"initialize",value:function(){this.canvas=this.createCanvas(),this.context=this.canvas.getContext("2d")}},{key:"createCanvas",value:function(){return document.createElement("canvas")}},{key:"load",value:function(t){this.loadImage(t)}},{key:"loadImage",value:function(t){var e=this,r=this.context,i=new Image;i.onload=function(){var n=i.height/i.width;e.opt.canvasWidth&&e.opt.canvasHeight?(e.canvas.width=e.opt.canvasWidth,e.canvas.height=e.opt.canvasHeight):(e.canvas.width=e.opt.maxWidth?e.opt.maxWidth:i.width,e.canvas.height=e.canvas.width*n),r.drawImage(i,0,0,i.width,i.height,0,0,e.canvas.width,e.canvas.height),e.isLoaded=!0,t&&t()},this.getImageUrl(function(t){i.src=t})}},{key:"getImageUrl",value:function(t){if("string"==typeof this.imageUrl)return t(this.imageUrl);if(this.imageUrl instanceof Blob){var e=new FileReader;e.onload=function(e){t(e.target.result)},e.readAsDataURL(this.imageUrl)}}},{key:"getRGBA",value:function(t,e,r,i){return[t,e,r,i]}},{key:"toArray",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this.context.getImageData(0,0,this.canvas.width,this.canvas.height),i=r.width,n=r.height,o={pixels:new Uint8ClampedArray(r.data),width:i,height:n};return t&&(o=t(o)),u.drawPixels(o).toDataURL(e.outputFormat||"image/png")}},{key:"toHistogram",value:function(t){var e=this.context.getImageData(0,0,this.canvas.width,this.canvas.height),r=e.width,i=e.height,n={pixels:new Uint8ClampedArray(e.data),width:r,height:i};return u.getHistogram(n)}},{key:"toRGB",value:function(){for(var t=this.context.getImageData(0,0,this.canvas.width,this.canvas.height).data,e=[],r=0,i=t.length;r-1||e[n].indexOf("rgb")>-1||e[n].indexOf("hsl")>-1)i.push({color:e[n]});else{var a=r.getColorByName(e[n]);a&&i.push({color:e[n],nameColor:a})}var s={next:0};return i.forEach(function(e){var r=t.indexOf(e.color,s.next);e.startIndex=r,e.endIndex=r+e.color.length,s.next=e.endIndex}),i},convertMatches:function(t){var e=this.matches(t);return e.forEach(function(e,r){t=t.replace(e.color,"@"+r)}),{str:t,matches:e}},convertMatchesArray:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:",",i=this.convertMatches(t);return i.str.split(r).map(function(t,r){return t=e.trim(t),i.matches[r]&&(t=t.replace("@"+r,i.matches[r].color)),t})},reverseMatches:function(t,e){return e.forEach(function(e,r){t=t.replace("@"+r,e.color)}),t},trim:function(t){return t.replace(/^\s+|\s+$/g,"")},round:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return Math.round(t*e)/e},format:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgba(0, 0, 0, 0)";return Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]}),"hex"==e?this.hex(t):"rgb"==e?this.rgb(t,r):"hsl"==e?this.hsl(t):t},hex:function(t){Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]});var e=t.r.toString(16);t.r<16&&(e="0"+e);var r=t.g.toString(16);t.g<16&&(r="0"+r);var i=t.b.toString(16);return t.b<16&&(i="0"+i),"#"+e+r+i},rgb:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgba(0, 0, 0, 0)";if(Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]}),void 0!==t)return 1==t.a||void 0===t.a?isNaN(t.r)?e:"rgb("+t.r+","+t.g+","+t.b+")":"rgba("+t.r+","+t.g+","+t.b+","+t.a+")"},hsl:function(t){return Array.isArray(t)&&(t={r:t[0],g:t[1],b:t[2],a:t[3]}),1==t.a||void 0===t.a?"hsl("+t.h+","+t.s+"%,"+t.l+"%)":"hsla("+t.h+","+t.s+"%,"+t.l+"%,"+t.a+")"},parse:function(t){if("string"==typeof t){if(r.isColorName(t)&&(t=r.getColorByName(t)),t.indexOf("rgb(")>-1){for(var e=0,i=(o=t.replace("rgb(","").replace(")","").split(",")).length;e-1){for(e=0,i=(o=t.replace("rgba(","").replace(")","").split(",")).length;e-1){for(e=0,i=(o=t.replace("hsl(","").replace(")","").split(",")).length;e-1){for(e=0,i=(o=t.replace("hsla(","").replace(")","").split(",")).length;e>16,g:(65280&t)>>8,b:(255&t)>>0,a:1};return n=Object.assign(n,this.RGBtoHSL(n))}if(0<=t&&t<=4294967295){n={type:"hex",r:(4278190080&t)>>24,g:(16711680&t)>>16,b:(65280&t)>>8,a:(255&t)/255};return n=Object.assign(n,this.RGBtoHSL(n))}}return t},HSVtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,r=i.v}var n=t,o=r;360==n&&(n=0);var a=e*o,s=a*(1-Math.abs(n/60%2-1)),l=o-a,h=[];return 0<=n&&n<60?h=[a,s,0]:60<=n&&n<120?h=[s,a,0]:120<=n&&n<180?h=[0,a,s]:180<=n&&n<240?h=[0,s,a]:240<=n&&n<300?h=[s,0,a]:300<=n&&n<360&&(h=[a,0,s]),{r:this.round(255*(h[0]+l)),g:this.round(255*(h[1]+l)),b:this.round(255*(h[2]+l))}},RGBtoHSV:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=t/255,o=e/255,a=r/255,s=Math.max(n,o,a),l=s-Math.min(n,o,a),h=0;0==l?h=0:s==n?h=(o-a)/l%6*60:s==o?h=60*((a-n)/l+2):s==a&&(h=60*((n-o)/l+4)),h<0&&(h=360+h);return{h:h,s:0==s?0:l/s,v:s}},HSVtoHSL:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,r=i.v}var n=this.HSVtoRGB(t,e,r);return this.RGBtoHSL(n.r,n.g,n.b)},RGBtoCMYK:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=t/255,o=e/255,a=r/255,s=1-Math.max(n,o,a);return{c:(1-n-s)/(1-s),m:(1-o-s)/(1-s),y:(1-a-s)/(1-s),k:s}},CMYKtoRGB:function(t,e,r,i){if(1==arguments.length){var n=arguments[0];t=n.c,e=n.m,r=n.y,i=n.k}return{r:255*(1-t)*(1-i),g:255*(1-e)*(1-i),b:255*(1-r)*(1-i)}},RGBtoHSL:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}t/=255,e/=255,r/=255;var n,o,a=Math.max(t,e,r),s=Math.min(t,e,r),l=(a+s)/2;if(a==s)n=o=0;else{var h=a-s;switch(o=l>.5?h/(2-a-s):h/(a+s),a){case t:n=(e-r)/h+(e1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t},HSLtoHSV:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,i.v}var n=this.HSLtoRGB(t,e,r);return this.RGBtoHSV(n.r,n.g,n.b)},HSLtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.h,e=i.s,r=i.l}var n,o,a;if(t/=360,r/=100,0==(e/=100))n=o=a=r;else{var s=r<.5?r*(1+e):r+e-r*e,l=2*r-s;n=this.HUEtoRGB(l,s,t+1/3),o=this.HUEtoRGB(l,s,t),a=this.HUEtoRGB(l,s,t-1/3)}return{r:this.round(255*n),g:this.round(255*o),b:this.round(255*a)}},c:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.gray((t+e+r)/3>90?0:255)},gray:function(t){return{r:t,g:t,b:t}},RGBtoSimpleGray:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.gray(Math.ceil((t+e+r)/3))},RGBtoGray:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.gray(this.RGBtoYCrCb(t,e,r).y)},brightness:function(t,e,r){return Math.ceil(.2126*t+.7152*e+.0722*r)},RGBtoYCrCb:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=this.brightness(t,e,r);return{y:n,cr:.713*(t-n),cb:.564*(r-n)}},YCrCbtoRGB:function(t,e,r,i){if(1==arguments.length){var n=arguments[0];t=n.y,e=n.cr,r=n.cb;i=(i=n.bit)||0}var o=t+1.402*(e-i),a=t-.344*(r-i)-.714*(e-i),s=t+1.772*(r-i);return{r:Math.ceil(o),g:Math.ceil(a),b:Math.ceil(s)}},ReverseRGB:function(t){return t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t},XYZtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.x,e=i.y,r=i.z}var n=t/100,o=e/100,a=r/100,s=3.2406*n+-1.5372*o+-.4986*a,l=-.9689*n+1.8758*o+.0415*a,h=.0557*n+-.204*o+1.057*a;return s=this.ReverseRGB(s),l=this.ReverseRGB(l),h=this.ReverseRGB(h),{r:this.round(255*s),g:this.round(255*l),b:this.round(255*h)}},PivotRGB:function(t){return 100*(t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)},RGBtoXYZ:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}var n=t/255,o=e/255,a=r/255;return{x:.4124*(n=this.PivotRGB(n))+.3576*(o=this.PivotRGB(o))+.1805*(a=this.PivotRGB(a)),y:.2126*n+.7152*o+.0722*a,z:.0193*n+.1192*o+.9505*a}},ReverseXyz:function(t){return Math.pow(t,3)>.008856?Math.pow(t,3):(t-16/116)/7.787},LABtoXYZ:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.l,e=i.a,r=i.b}var n=(t+16)/116,o=e/500+n,a=n-r/200;return n=this.ReverseXyz(n),{x:95.047*(o=this.ReverseXyz(o)),y:100*n,z:108.883*(a=this.ReverseXyz(a))}},PivotXyz:function(t){return t>.008856?Math.pow(t,1/3):(7.787*t+16)/116},XYZtoLAB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.x,e=i.y,r=i.z}var n=t/95.047,o=e/100,a=r/108.883;return n=this.PivotXyz(n),{l:116*(o=this.PivotXyz(o))-16,a:500*(n-o),b:200*(o-(a=this.PivotXyz(a)))}},RGBtoLAB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.r,e=i.g,r=i.b}return this.XYZtoLAB(this.RGBtoXYZ(t,e,r))},LABtoRGB:function(t,e,r){if(1==arguments.length){var i=arguments[0];t=i.l,e=i.a,r=i.b}return this.XYZtoRGB(this.LABtoXYZ(t,e,r))},blend:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hex",n=this.parse(t),o=this.parse(e);return this.interpolateRGB(n,o,r,i)},mix:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hex";return this.blend(t,e,r,i)},contrast:function(t){t=this.parse(t);var e=(Math.round(299*t.r)+Math.round(587*t.g)+Math.round(114*t.b))/1e3;return e},contrastColor:function(t){return this.contrast(t)>=128?"black":"white"},interpolateRGB:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hex",n={r:this.round(t.r+(e.r-t.r)*r),g:this.round(t.g+(e.g-t.g)*r),b:this.round(t.b+(e.b-t.b)*r),a:this.round(t.a+(e.a-t.a)*r,100)};return this.format(n,n.a<1?"rgb":i)},scale:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;if(!t)return[];"string"==typeof t&&(t=this.convertMatchesArray(t));for(var r=(t=t||[]).length,i=[],n=0;n0){var i=(1-t.filter(function(t){return"*"!=t[1]&&1!=t[1]}).map(function(t){return t[1]}).reduce(function(t,e){return t+e},0))/r;t.forEach(function(e,r){"*"==e[1]&&r>0&&(t.length-1==r||(e[1]=i))})}return t},gradient:function(t){for(var e=[],r=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:10)-((t=this.parseGradient(t)).length-1),i=r,n=1,o=t.length;n1&&void 0!==arguments[1]?arguments[1]:"h",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:9,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"rgb",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1,a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:100,s=this.parse(t),l=this.RGBtoHSV(s),h=(o-n)*a/r,c=[],u=1;u<=r;u++)l[e]=Math.abs((a-h*u)/a),c.push(this.format(this.HSVtoRGB(l),i));return c},scaleH:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgb",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:360;return this.scaleHSV(t,"h",e,r,i,n,1)},scaleS:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgb",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1;return this.scaleHSV(t,"s",e,r,i,n,100)},scaleV:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgb",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1;return this.scaleHSV(t,"v",e,r,i,n,100)},palette:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"hex";return t.length>r&&(t=c(t,r)),t.map(function(t){return e.format(t,i)})},ImageToRGB:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];if(r){if(r){var i;(i=new w(t,e)).loadImage(function(){"function"==typeof r&&r(i.toRGB())})}}else(i=new w(t)).loadImage(function(){"function"==typeof e&&e(i.toRGB())})},ImageToURL:function(t,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=new w(t);n.loadImage(function(){"function"==typeof r&&r(n.toArray(e,i))})},histogram:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=new w(t);i.loadImage(function(){"function"==typeof e&&e(i.toHistogram(r))})},ImageToHistogram:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{width:200,height:100},i=new w(t);i.loadImage(function(){u.createHistogram(r.width||200,r.height||100,i.toHistogram(r),function(t){"function"==typeof e&&e(t.toDataURL("image/png"))},r)})}};_.scale.parula=function(t){return _.scale(["#352a87","#0f5cdd","#00b5a6","#ffc337","#fdff00"],t)},_.scale.jet=function(t){return _.scale(["#00008f","#0020ff","#00ffff","#51ff77","#fdff00","#ff0000","#800000"],t)},_.scale.hsv=function(t){return _.scale(["#ff0000","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff","#ff0000"],t)},_.scale.hot=function(t){return _.scale(["#0b0000","#ff0000","#ffff00","#ffffff"],t)},_.scale.pink=function(t){return _.scale(["#1e0000","#bd7b7b","#e7e5b2","#ffffff"],t)},_.scale.bone=function(t){return _.scale(["#000000","#4a4a68","#a6c6c6","#ffffff"],t)},_.scale.copper=function(t){return _.scale(["#000000","#3d2618","#9d623e","#ffa167","#ffc77f"],t)};var $=[{rgb:"#ff0000",start:0},{rgb:"#ffff00",start:.17},{rgb:"#00ff00",start:.33},{rgb:"#00ffff",start:.5},{rgb:"#0000ff",start:.67},{rgb:"#ff00ff",start:.83},{rgb:"#ff0000",start:1}];!function(){for(var t=0,e=$.length;t=t){e=$[i-1],r=$[i];break}return e&&r?_.interpolateRGB(e,r,(t-e.start)/(r.start-e.start)):$[0].rgb}},M={identity:function(){return[1,0,0,0,1,0,0,0,1]},stretching:function(t){return[t,0,0,0,1,0,0,0,1]},squeezing:function(t){return[t,0,0,0,1/t,0,0,0,1]},scale:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return[t=t||0===t?t:1,0,0,0,e=e||0===e?e:1,0,0,0,1]},scaleX:function(t){return this.scale(t)},scaleY:function(t){return this.scale(1,t)},translate:function(t,e){return[1,0,t,0,1,e,0,0,1]},rotate:function(t){var e=this.radian(t);return[Math.cos(e),-Math.sin(e),0,Math.sin(e),Math.cos(e),0,0,0,1]},rotate90:function(){return[0,-1,0,1,0,0,0,0,1]},rotate180:function(){return[-1,0,0,0,-1,0,0,0,1]},rotate270:function(){return[0,1,0,-1,0,0,0,0,1]},radian:function(t){return t*Math.PI/180},skew:function(t,e){var r=this.radian(t),i=this.radian(e);return[1,Math.tan(r),0,Math.tan(i),1,0,0,0,1]},skewX:function(t){var e=this.radian(t);return[1,Math.tan(e),0,0,1,0,0,0,1]},skewY:function(t){var e=this.radian(t);return[1,0,0,Math.tan(e),1,0,0,0,1]},shear1:function(t){return[1,-Math.tan(this.radian(t)/2),0,0,1,0,0,0,1]},shear2:function(t){return[1,0,0,Math.sin(this.radian(t)),1,0,0,0,1]}},H={CONSTANT:M,radian:function(t){return M.radian(t)},multiply:function(t,e){return[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[3]*e[0]+t[4]*e[1]+t[5]*e[2],t[6]*e[0]+t[7]*e[1]+t[8]*e[2]]},identity:function(t){return this.multiply(M.identity(),t)},translate:function(t,e,r){return this.multiply(M.translate(t,e),r)},rotate:function(t,e){return this.multiply(M.rotate(t),e)},shear1:function(t,e){return this.multiply(M.shear1(t),e)},shear2:function(t,e){return this.multiply(M.shear2(t),e)},rotateShear:function(t,e){var r=e;return r=this.shear1(t,r),r=this.shear2(t,r),r=this.shear1(t,r)}};function B(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"center",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"center";return function(i){var n=nt(i.pixels.length,i.width,i.height),o=i.width,a=i.height;"center"==e&&(e=Math.floor(o/2)),"center"==r&&(r=Math.floor(a/2));var s=H.CONSTANT.translate(-e,-r),l=H.CONSTANT.translate(e,r),h=H.CONSTANT.shear1(t),c=H.CONSTANT.shear2(t);return ft(function(t,e,r,n){var u=H.multiply(s,[r,n,1]);u=H.multiply(h,u).map(Math.round),u=H.multiply(c,u).map(Math.round),u=H.multiply(h,u).map(Math.round),u=H.multiply(l,u);var f=k(u,2),v=f[0],g=f[1];if(!(v<0||g<0||v>o-1||g>a-1)){var d=4*(g*o+v);t[d]=i.pixels[e],t[d+1]=i.pixels[e+1],t[d+2]=i.pixels[e+2],t[d+3]=i.pixels[e+3]}})(n)}}function R(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:200,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=st(t);var i=(e=st(e))/100;return ht(function(e,n){var o=i*_.brightness(e[n],e[n+1],e[n+2])>=t?255:0;r?0==o&&(e[n]=e[n+1]=e[n+2]=0):e[n]=e[n+1]=e[n+2]=Math.round(o)})}function E(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([1,2,1,2,4,2,1,2,1],1/16*((t=st(t))/100)))}function A(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([1,4,6,4,1,4,16,24,16,4,6,24,36,24,6,4,16,24,16,4,1,4,6,4,1],1/256*((t=st(t))/100)))}function O(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=st(t),gt([5,5,5,-3,0,-3,-3,-3,-3])}function I(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=st(t),gt([5,-3,-3,5,0,-3,5,-3,-3])}function L(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,24,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],(t=st(t))/100))}function F(){return gt(Z([1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1],1/9))}function G(){return gt(Z([1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1],1/9))}function P(){return gt(Z([1,0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,0,0,1,0,1,0,0,0,1,0,0,0,1],1/9))}function N(){return gt([-1,-2,-1,0,0,0,1,2,1])}function T(){return gt([-1,0,1,-2,0,2,-1,0,1])}var D=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],z=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function j(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}function V(t,e,r){return r?function(t,e,r,i){if(isNaN(i)||i<1)return t;i|=0;var n,o,a,s,l,h,c,u,f,v,g,d,p,m,y,b,k,C,w,x,_,$,S,M,H=t.pixels,B=t.width,R=t.height,E=i+i+1,A=B-1,O=R-1,I=i+1,L=I*(I+1)/2,F=new j,G=F;for(a=1;a>U,0!=S?(S=255/S,H[h]=(u*V>>U)*S,H[h+1]=(f*V>>U)*S,H[h+2]=(v*V>>U)*S):H[h]=H[h+1]=H[h+2]=0,u-=d,f-=p,v-=m,g-=y,d-=N.r,p-=N.g,m-=N.b,y-=N.a,s=c+((s=n+i+1)>U,S>0?(S=255/S,H[s]=(u*V>>U)*S,H[s+1]=(f*V>>U)*S,H[s+2]=(v*V>>U)*S):H[s]=H[s+1]=H[s+2]=0,u-=d,f-=p,v-=m,g-=y,d-=N.r,p-=N.g,m-=N.b,y-=N.a,s=n+((s=o+I)0&&void 0!==arguments[0]?arguments[0]:10,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t=st(t),function(r){return V(r,t,e)}}function X(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:256;return gt(Z([1,4,6,4,1,4,16,24,16,4,6,24,-476,24,6,4,16,24,16,4,1,4,6,4,1],-1/(t=st(t))))}var Y,q=p({},{crop:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments[2],i=arguments[3],n=nt(r*i*4,r,i);return function(o){for(var a=e,s=0;a0&&void 0!==arguments[0]?arguments[0]:0;return t=st(t),t%=360,function(e){if(0==t)return e;if(90==t||270==t)var r=nt(e.pixels.length,e.height,e.width);else{if(180!=t)return B(t)(e);r=nt(e.pixels.length,e.width,e.height)}return e.width,e.height,ft(function(i,n,o,a){if(90==t)var s=4*(o*r.width+(r.width-1-a));else 270==t?s=4*((r.height-1-o)*r.width+a):180==t&&(s=4*((r.height-1-a)*r.width+(r.width-1-o)));r.pixels[s]=e.pixels[n],r.pixels[s+1]=e.pixels[n+1],r.pixels[s+2]=e.pixels[n+2],r.pixels[s+3]=e.pixels[n+3]})(e),r}},rotateDegree:B,"rotate-degree":B},{bitonal:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:100;return t=_.parse(t),e=_.parse(e),ht(function(i,n){i[n]+i[n+1]+i[n+2]<=r?(i[n]=t.r,i[n+1]=t.g,i[n+2]=t.b):(i[n]=e.r,i[n+1]=e.g,i[n+2]=e.b)})},brightness:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;t=st(t);var e=Math.floor(t/100*255);return ht(function(t,r){t[r]+=e,t[r+1]+=e,t[r+2]+=e})},clip:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;t=st(t);var e=2.55*Math.abs(t);return ht(function(t,r){for(var i=r,n=r+2;i<=n;i++)t[i]>255-e?t[i]=255:t[i]0&&void 0!==arguments[0]?arguments[0]:0;t=st(t);var e=Math.max((128+t)/128,0);return ht(function(t,r){t[r]=t[r]*e,t[r+1]=t[r+1]*e,t[r+2]=t[r+2]*e})},gamma:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=st(t),ht(function(e,r){e[r]=255*Math.pow(e[r]/255,t),e[r+1]=255*Math.pow(e[r+1]/255,t),e[r+2]=255*Math.pow(e[r+2]/255,t)})},gradient:function(){var t=[].concat(Array.prototype.slice.call(arguments));1===t.length&&"string"==typeof t[0]&&(t=_.convertMatchesArray(t[0]));var e=(t=t.map(function(t){return _.matches(t).length?{type:"param",value:t}:{type:"scale",value:t}})).filter(function(t){return"scale"==t.type})[0];e=e?+e.value:256,t=t.filter(function(t){return"param"==t.type}).map(function(t){return t.value}).join(",");var r=_.gradient(t,e).map(function(t){return _.parse(t)});return ht(function(t,i){var n=mt(_.brightness(t[i],t[i+1],t[i+2])),o=mt(Math.floor(n*(e/256))),a=r[o];t[i]=a.r,t[i+1]=a.g,t[i+2]=a.b,t[i+3]=mt(Math.floor(256*a.a))})},grayscale:function(t){var e=(t=st(t))/100;return e>1&&(e=1),ht(function(t,r){Q(t,r,[.2126+.7874*(1-e),.7152-.7152*(1-e),.0722-.0722*(1-e),0,.2126-.2126*(1-e),.7152+.2848*(1-e),.0722-.0722*(1-e),0,.2126-.2126*(1-e),.7152-.7152*(1-e),.0722+.9278*(1-e),0,0,0,0,1])})},hue:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:360;return t=st(t),ht(function(e,r){var i=e[r],n=e[r+1],o=e[r+2],a=Color.RGBtoHSV(i,n,o),s=a.h;s+=Math.abs(t),s%=360,a.h=s;var l=Color.HSVtoRGB(a);e[r]=l.r,e[r+1]=l.g,e[r+2]=l.b})},invert:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=st(t))/100;return ht(function(t,r){t[r]=(255-t[r])*e,t[r+1]=(255-t[r+1])*e,t[r+2]=(255-t[r+2])*e})},noise:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t=st(t),ht(function(e,r){var i=5*Math.abs(t),n=-i,o=i,a=Math.round(n+Math.random()*(o-n));e[r]+=a,e[r+1]+=a,e[r+2]+=a})},opacity:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=st(t))/100;return ht(function(t,r){t[r+3]*=e})},saturation:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=st(t))/100,r=1-Math.abs(e);return ht(function(t,e){Q(t,e,[r,0,0,0,0,r,0,0,0,0,r,0,0,0,0,r])})},sepia:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=(t=st(t))/100;return e>1&&(e=1),ht(function(t,r){Q(t,r,[.393+.607*(1-e),.769-.769*(1-e),.189-.189*(1-e),0,.349-.349*(1-e),.686+.314*(1-e),.168-.168*(1-e),0,.272-.272*(1-e),.534-.534*(1-e),.131+.869*(1-e),0,0,0,0,1])})},shade:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return t=st(t),e=st(e),r=st(r),ht(function(i,n){i[n]*=t,i[n+1]*=e,i[n+2]*=r})},solarize:function(t,e,r){return t=st(t),e=st(e),r=st(r),ht(function(i,n){i[n]0&&void 0!==arguments[0]?arguments[0]:200,arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,!1)},"threshold-color":R},{blur:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3;return gt(vt(t=st(t)))},emboss:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;return gt([-2*(t=st(t)),-t,0,-t,1,t,0,t,2*t])},gaussianBlur:E,"gaussian-blur":E,gaussianBlur5x:A,"gaussian-blur-5x":A,grayscale2:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([.3,.3,.3,0,0,.59,.59,.59,0,0,.11,.11,.11,0,0,0,0,0,0,0,0,0,0,0,0],(t=st(t))/100))},identity:function(){return gt([0,0,0,0,1,0,0,0,0])},kirschHorizontal:O,"kirsch-horizontal":O,kirschVertical:I,"kirsch-vertical":I,laplacian:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([-1,-1,-1,-1,8,-1,-1,-1,-1],(t=st(t))/100))},laplacian5x:L,"laplacian-5x":L,motionBlur:F,"motion-blur":F,motionBlur2:G,"motion-blur-2":G,motionBlur3:P,"motion-blur-3":P,negative:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([-1,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0,0,0,1,0,1,1,1,1,1],(t=st(t))/100))},random:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:it();return t=st(t),function(t,r,i){return gt(rt(-1,5,e))(t,r,i)}},sepia2:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([.393,.349,.272,0,0,.769,.686,.534,0,0,.189,.168,.131,0,0,0,0,0,0,0,0,0,0,0,0],(t=st(t))/100))},sharpen:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([0,-1,0,-1,5,-1,0,-1,0],(t=st(t))/100))},sobelHorizontal:N,"sobel-horizontal":N,sobelVertical:T,"sobel-vertical":T,stackBlur:U,"stack-blur":U,transparency:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return gt(Z([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,.3,0,0,0,0,0,1],(t=st(t))/100))},unsharpMasking:X,"unsharp-masking":X},{kirsch:function(){return yt("kirsch-horizontal kirsch-vertical")},sobel:function(){return yt("sobel-horizontal sobel-vertical")},vintage:function(){return yt("brightness(15) saturation(-20) gamma(1.8)")}}),K=(d(Y={partial:Ct,multi:bt,merge:kt,weight:Z,repeat:J,colorMatrix:Q,each:tt,eachXY:et,createRandomCount:it,createRandRange:rt,createBitmap:nt,createBlurMatrix:vt,pack:ht,packXY:ft,getBitmap:ot,putBitmap:at,radian:function(t){return H.CONSTANT.radian(t)},convolution:gt,parseParamNumber:st,filter:yt,clamp:mt},"multi",bt),d(Y,"merge",kt),d(Y,"matches",dt),d(Y,"parseFilter",pt),d(Y,"partial",Ct),Y),W=K;function Z(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return t.map(function(t){return t*e})}function J(t,e){for(var r=new Array(e),i=0;i0&&void 0!==arguments[0]?arguments[0]:3,e=Math.pow(t,2);return J(1/e,e)}function gt(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return function(r){for(var i=r.pixels,n=r.width,o=r.height,a=Math.round(Math.sqrt(t.length)),s=Math.floor(a/2),l=n,h=o,c=l,u=h,f=new Uint8ClampedArray(i.length),v=e?1:0,g=0;g=0&&$=0&&S1?r-1:0),n=1;n-1}},{key:"addClass",value:function(t){this.hasClass(t)||(this.el.className=this.el.className+" "+t)}},{key:"toggleClass",value:function(t){this.hasClass(t)?this.removeClass(t):this.addClass(t)}},{key:"html",value:function(t){return"string"==typeof t?this.el.innerHTML=t:this.empty().append(t),this}},{key:"empty",value:function(){return this.html("")}},{key:"append",value:function(t){return"string"==typeof t?this.el.appendChild(document.createTextNode(t)):this.el.appendChild(t.el||t),this}},{key:"appendTo",value:function(t){return(t.el?t.el:t).appendChild(this.el),this}},{key:"remove",value:function(){return this.el.parentNode&&this.el.parentNode.removeChild(this.el),this}},{key:"text",value:function(){return this.el.textContent}},{key:"css",value:function(t,e){var r=this;if(2==arguments.length)this.el.style[t]=e;else if(1==arguments.length){if("string"==typeof t)return getComputedStyle(this.el)[t];var i=t||{};Object.keys(i).forEach(function(t){r.el.style[t]=i[t]})}return this}},{key:"cssFloat",value:function(t){return parseFloat(this.css(t))}},{key:"cssInt",value:function(t){return parseInt(this.css(t))}},{key:"offset",value:function(){var t=this.el.getBoundingClientRect();return{top:t.top+document.documentElement.scrollTop,left:t.left+document.documentElement.scrollLeft}}},{key:"position",value:function(){return this.el.style.top?{top:parseFloat(this.css("top")),left:parseFloat(this.css("left"))}:this.el.getBoundingClientRect()}},{key:"width",value:function(){return this.el.offsetWidth}},{key:"contentWidth",value:function(){return this.width()-this.cssFloat("padding-left")-this.cssFloat("padding-right")}},{key:"height",value:function(){return this.el.offsetHeight}},{key:"contentHeight",value:function(){return this.height()-this.cssFloat("padding-top")-this.cssFloat("padding-bottom")}},{key:"dataKey",value:function(t){return this.uniqId+"."+t}},{key:"data",value:function(t,e){if(2!=arguments.length){if(1==arguments.length)return _t[this.dataKey(t)];var r=Object.keys(_t),i=this.uniqId+".";return r.filter(function(t){return 0==t.indexOf(i)}).map(function(t){return _t[t]})}return _t[this.dataKey(t)]=e,this}},{key:"val",value:function(t){return 0==arguments.length?this.el.value:(1==arguments.length&&(this.el.value=t),this)}},{key:"int",value:function(){return parseInt(this.val(),10)}},{key:"float",value:function(){return parseFloat(this.val())}},{key:"show",value:function(){return this.css("display","block")}},{key:"hide",value:function(){return this.css("display","none")}},{key:"toggle",value:function(){return"none"==this.css("display")?this.show():this.hide()}},{key:"scrollTop",value:function(){return this.el===document.body?document.documentElement.scrollTop:this.el.scrollTop}},{key:"scrollLeft",value:function(){return this.el===document.body?document.documentElement.scrollLeft:this.el.scrollLeft}},{key:"on",value:function(t,e,r,i){return this.el.addEventListener(t,e,r,i),this}},{key:"off",value:function(t,e){return this.el.removeEventListener(t,e),this}},{key:"getElement",value:function(){return this.el}},{key:"createChild",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=new t(e,r,i);return o.css(n),this.append(o),o}}]),t}(),St={addEvent:function(t,e,r){t.addEventListener(e,r)},removeEvent:function(t,e,r){t.removeEventListener(e,r)},pos:function(t){return t.touches&&t.touches[0]?t.touches[0]:t}},Mt=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};v(this,t),this.masterObj=e,this.settingObj=r}return g(t,[{key:"set",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.settingObj[t]=e||r}},{key:"init",value:function(t){if(!this.has(t)){var e=t.split("."),r=this.masterObj[e[0]]||this.masterObj,i=e.pop();if(r[i]){for(var n=arguments.length,o=Array(n>1?n-1:0),a=1;a1&&void 0!==arguments[1]?arguments[1]:"";return this.init(t,e),this.settingObj[t]||e}},{key:"has",value:function(t){return!!this.settingObj[t]}}]),t}(),Ht=/^(click|mouse(down|up|move|enter|leave)|key(down|up|press)|contextmenu|change|input)/gi,Bt=["Control","Shift","Alt","Meta"],Rt=function(){function t(){v(this,t),this.state=new Mt(this)}return g(t,[{key:"initializeEvent",value:function(){this.initializeEventMachin()}},{key:"destroy",value:function(){this.destroyEventMachin()}},{key:"destroyEventMachin",value:function(){this.removeEventAll()}},{key:"initializeEventMachin",value:function(){this.filterProps(Ht).forEach(this.parseEvent.bind(this))}},{key:"filterProps",value:function(t){return Object.getOwnPropertyNames(this.__proto__).filter(function(e){return e.match(t)})}},{key:"parseEvent",value:function(t){var e=t.split(" ");this.bindingEvent(e,this[t].bind(this))}},{key:"getDefaultDomElement",value:function(t){var e=void 0;return(e=t?this[t]||window[t]:this.el||this.$el||this.$root)instanceof $t?e.getElement():e}},{key:"getDefaultEventObject",value:function(t){var e=this,r=t.split("."),i=r.shift(),n=r.includes("Control"),o=r.includes("Shift"),a=r.includes("Alt"),s=r.includes("Meta"),l=(r=r.filter(function(t){return!1===Bt.includes(t)})).filter(function(t){return!!e[t]});return{eventName:i,isControl:n,isShift:o,isAlt:a,isMeta:s,codes:r=r.filter(function(t){return!1===l.includes(t)}).map(function(t){return t.toLowerCase()}),checkMethodList:l}}},{key:"bindingEvent",value:function(t,e){var r,i=(r=t,Array.isArray(r)?r:Array.from(r)),n=i[0],o=i[1],a=i.slice(2);o=this.getDefaultDomElement(o);var s=this.getDefaultEventObject(n);s.dom=o,s.delegate=a.join(" "),this.addEvent(s,e)}},{key:"matchPath",value:function(t,e){return t?t.matches(e)?t:this.matchPath(t.parentElement,e):null}},{key:"getBindings",value:function(){return this._bindings||this.initBindings(),this._bindings}},{key:"addBinding",value:function(t){this.getBindings().push(t)}},{key:"initBindings",value:function(){this._bindings=[]}},{key:"checkEventType",value:function(t,e){var r=this,i=!t.ctrlKey||e.isControl,n=!t.shiftKey||e.isShift,o=!t.altKey||e.isAlt,a=!t.metaKey||e.isMeta,s=!0;e.codes.length&&(s=e.codes.includes(t.code.toLowerCase())||e.codes.includes(t.key.toLowerCase()));var l=!0;return e.checkMethodList.length&&(l=e.checkMethodList.every(function(e){return r[e].call(r,t)})),i&&o&&n&&a&&s&&l}},{key:"makeCallback",value:function(t,e){var r=this;return t.delegate?function(i){if(r.checkEventType(i,t)){var n=r.matchPath(i.target||i.srcElement,t.delegate);if(n)return i.delegateTarget=n,i.$delegateTarget=new $t(n),e(i)}}:function(i){if(r.checkEventType(i,t))return e(i)}}},{key:"addEvent",value:function(t,e){t.callback=this.makeCallback(t,e),this.addBinding(t),St.addEvent(t.dom,t.eventName,t.callback)}},{key:"removeEventAll",value:function(){var t=this;this.getBindings().forEach(function(e){t.removeEvent(e)}),this.initBindings()}},{key:"removeEvent",value:function(t){var e=t.eventName,r=t.dom,i=t.callback;St.removeEvent(r,e,i)}}]),t}(),Et=function(t){function e(t){v(this,e);var r=b(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return y(e,Rt),g(e,[{key:"initialize",value:function(){this.$el=new $t("div","control"),this.$hue=this.$el.createChild("div","hue"),this.$opacity=this.$el.createChild("div","opacity"),this.$controlPattern=this.$el.createChild("div","empty"),this.$controlColor=this.$el.createChild("div","color"),this.$hueContainer=this.$hue.createChild("div","hue-container"),this.$drag_bar=this.$hueContainer.createChild("div","drag-bar"),this.drag_bar_pos={},this.$opacityContainer=this.$opacity.createChild("div","opacity-container"),this.$opacityColorBar=this.$opacityContainer.createChild("div","color-bar"),this.$opacity_drag_bar=this.$opacityContainer.createChild("div","drag-bar2"),this.opacity_drag_bar_pos={}}},{key:"setBackgroundColor",value:function(t){this.$controlColor.css("background-color",t)}},{key:"refresh",value:function(){this.setColorUI()}},{key:"setColorUI",value:function(){var t=this.state.get("$el.width")*this.colorpicker.currentS,e=this.state.get("$el.height")*(1-this.colorpicker.currentV);this.$drag_pointer.css({left:t+"px",top:e+"px"})}},{key:"setOpacityColorBar",value:function(t){var e=_.parse(t);e.a=0;var r=_.format(e,"rgb");e.a=1;var i=_.format(e,"rgb");this.$opacityColorBar.css("background","linear-gradient(to right, "+r+", "+i+")")}},{key:"setOpacity",value:function(t){var e,r=this.$opacityContainer.offset().left,i=r+this.state.get("$opacityContainer.width"),n=St.pos(t).clientX;e=ni?100:(n-r)/(i-r)*100;var o=this.state.get("$opacityContainer.width")*(e/100);this.$opacity_drag_bar.css({left:o-Math.ceil(this.state.get("$opacity_drag_bar.width")/2)+"px"}),this.opacity_drag_bar_pos={x:o},this.colorpicker.setCurrentA(this.caculateOpacity()),this.colorpicker.currentFormat(),this.colorpicker.setInputColor()}},{key:"setInputColor",value:function(){this.setBackgroundColor(this.colorpicker.getFormattedColor("rgb"));var t=this.colorpicker.convertRGB(),e=_.format(t,"rgb");this.setOpacityColorBar(e)}},{key:"setColorUI",value:function(){var t=this.state.get("$hueContainer.width")*(this.colorpicker.currentH/360);this.$drag_bar.css({left:t-7.5+"px"}),this.drag_bar_pos={x:t};var e=this.state.get("$opacityContainer.width")*(this.colorpicker.currentA||0);this.$opacity_drag_bar.css({left:e-7.5+"px"}),this.opacity_drag_bar_pos={x:e}}},{key:"caculateH",value:function(){return{h:(this.drag_bar_pos||{x:0}).x/this.state.get("$hueContainer.width")*360}}},{key:"caculateOpacity",value:function(){var t=this.opacity_drag_bar_pos||{x:0},e=Math.round(t.x/this.state.get("$opacityContainer.width")*100)/100;return isNaN(e)?1:e}},{key:"EventDocumentMouseMove",value:function(t){this.isHueDown&&this.setHueColor(t),this.isOpacityDown&&this.setOpacity(t)}},{key:"EventDocumentMouseUp",value:function(t){this.isHueDown=!1,this.isOpacityDown=!1}},{key:"setControlColor",value:function(t){this.$controlColor.css("background-color",t)}},{key:"setHueColor",value:function(t){var e,r=this.$hueContainer.offset().left,i=r+this.state.get("$hueContainer.width"),n=t?St.pos(t).clientX:r+(i-r)*(this.colorpicker.currentH/360);e=ni?100:(n-r)/(i-r)*100;var o=this.state.get("$hueContainer.width")*(e/100);this.$drag_bar.css({left:o-Math.ceil(this.state.get("$drag_bar.width")/2)+"px"}),this.drag_bar_pos={x:o};var a=S.checkHueColor(e/100);this.colorpicker.setBackgroundColor(a),this.colorpicker.setCurrentH(e/100*360),this.colorpicker.setInputColor()}},{key:"setOnlyHueColor",value:function(){var t,e=this.$hueContainer.offset().left,r=e+this.state.get("$hueContainer.width"),i=e+(r-e)*(this.colorpicker.currentH/360);t=ir?100:(i-e)/(r-e)*100;var n=this.state.get("$hueContainer.width")*(t/100);this.$drag_bar.css({left:n-Math.ceil(this.state.get("$drag_bar.width")/2)+"px"}),this.drag_bar_pos={x:n};var o=S.checkHueColor(t/100);this.colorpicker.setBackgroundColor(o),this.colorpicker.setCurrentH(t/100*360)}},{key:"mousedown $drag_bar",value:function(t){t.preventDefault(),this.isHueDown=!0}},{key:"mousedown $opacity_drag_bar",value:function(t){t.preventDefault(),this.isOpacityDown=!0}},{key:"mousedown $hueContainer",value:function(t){this.isHueDown=!0,this.setHueColor(t)}},{key:"mousedown $opacityContainer",value:function(t){this.isOpacityDown=!0,this.setOpacity(t)}}]),e}(),At=function(t){function e(t){v(this,e);var r=b(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return y(e,Rt),g(e,[{key:"initialize",value:function(){this.$el=new $t("div","information hex"),this.$informationChange=this.$el.createChild("div","information-change"),this.$formatChangeButton=this.$informationChange.createChild("button","format-change-button arrow-button",{type:"button"}),this.$el.append(this.makeInputFieldHex()),this.$el.append(this.makeInputFieldRgb()),this.$el.append(this.makeInputFieldHsl()),this.format="hex"}},{key:"makeInputFieldHex",value:function(){var t=new $t("div","information-item hex"),e=t.createChild("div","input-field hex");return this.$hexCode=e.createChild("input","input",{type:"text"}),e.createChild("div","title").html("HEX"),t}},{key:"makeInputFieldRgb",value:function(){var t=new $t("div","information-item rgb"),e=t.createChild("div","input-field rgb-r");return this.$rgb_r=e.createChild("input","input",{type:"number",step:1,min:0,max:255}),e.createChild("div","title").html("R"),e=t.createChild("div","input-field rgb-g"),this.$rgb_g=e.createChild("input","input",{type:"number",step:1,min:0,max:255}),e.createChild("div","title").html("G"),e=t.createChild("div","input-field rgb-b"),this.$rgb_b=e.createChild("input","input",{type:"number",step:1,min:0,max:255}),e.createChild("div","title").html("B"),e=t.createChild("div","input-field rgb-a"),this.$rgb_a=e.createChild("input","input",{type:"number",step:.01,min:0,max:1}),e.createChild("div","title").html("A"),t}},{key:"makeInputFieldHsl",value:function(){var t=new $t("div","information-item hsl"),e=t.createChild("div","input-field hsl-h");return this.$hsl_h=e.createChild("input","input",{type:"number",step:1,min:0,max:360}),e.createChild("div","title").html("H"),e=t.createChild("div","input-field hsl-s"),this.$hsl_s=e.createChild("input","input",{type:"number",step:1,min:0,max:100}),e.createChild("div","postfix").html("%"),e.createChild("div","title").html("S"),e=t.createChild("div","input-field hsl-l"),this.$hsl_l=e.createChild("input","input",{type:"number",step:1,min:0,max:100}),e.createChild("div","postfix").html("%"),e.createChild("div","title").html("L"),e=t.createChild("div","input-field hsl-a"),this.$hsl_a=e.createChild("input","input",{type:"number",step:.01,min:0,max:1}),e.createChild("div","title").html("A"),t}},{key:"currentFormat",value:function(){var t=this.format||"hex";if(this.colorpicker.currentA<1&&"hex"==t){this.$el.removeClass(t),this.$el.addClass("rgb"),this.format="rgb",this.colorpicker.setInputColor()}}},{key:"setCurrentFormat",value:function(t){this.format=t,this.initFormat()}},{key:"initFormat",value:function(){var t=this.format||"hex";this.$el.removeClass("hex"),this.$el.removeClass("rgb"),this.$el.removeClass("hsl"),this.$el.addClass(t)}},{key:"nextFormat",value:function(){var t=this.format||"hex",e="hex";"hex"==t?e="rgb":"rgb"==t?e="hsl":"hsl"==t&&(e=1==this.colorpicker.currentA?"hex":"rgb"),this.$el.removeClass(t),this.$el.addClass(e),this.format=e,this.setInputColor(),this.colorpicker.changeInputColorAfterNextFormat()}},{key:"setRGBInput",value:function(t,e,r){this.$rgb_r.val(t),this.$rgb_g.val(e),this.$rgb_b.val(r),this.$rgb_a.val(this.colorpicker.currentA)}},{key:"setHSLInput",value:function(t,e,r){this.$hsl_h.val(t),this.$hsl_s.val(e),this.$hsl_l.val(r),this.$hsl_a.val(this.colorpicker.currentA)}},{key:"getHexFormat",value:function(){return _.format({r:this.$rgb_r.int(),g:this.$rgb_g.int(),b:this.$rgb_b.int()},"hex",this.colorpicker.opt.color)}},{key:"getRgbFormat",value:function(){return _.format({r:this.$rgb_r.int(),g:this.$rgb_g.int(),b:this.$rgb_b.int(),a:this.$rgb_a.float()},"rgb",this.colorpicker.opt.color)}},{key:"getHslFormat",value:function(){return _.format({h:this.$hsl_h.val(),s:this.$hsl_s.val(),l:this.$hsl_l.val(),a:this.$hsl_a.float()},"hsl",this.colorpicker.opt.color)}},{key:"convertRGB",value:function(){return this.colorpicker.convertRGB()}},{key:"convertHEX",value:function(){return this.colorpicker.convertHEX()}},{key:"convertHSL",value:function(){return this.colorpicker.convertHSL()}},{key:"getFormattedColor",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"hex"==(t=t||this.getFormat())?this.$hexCode.val():"rgb"==t?this.getRgbFormat(e):"hsl"==t?this.getHslFormat(e):void 0}},{key:"getFormat",value:function(){return this.format||"hex"}},{key:"setInputColor",value:function(){var t=this.getFormat(),e=null;if("hex"==t){this.$hexCode.val(this.convertHEX());e=this.convertRGB();this.setRGBInput(e.r,e.g,e.b,e.a)}else if("rgb"==t){e=this.convertRGB();this.setRGBInput(e.r,e.g,e.b,e.a),this.$hexCode.val(this.convertHEX())}else if("hsl"==t){var r=this.convertHSL();this.setHSLInput(r.h,r.s,r.l,r.a)}}},{key:"checkNumberKey",value:function(t){return St.checkNumberKey(t)}},{key:"checkNotNumberKey",value:function(t){return!St.checkNumberKey(t)}},{key:"changeRgbColor",value:function(){this.colorpicker.changeInformationColor(this.getRgbFormat())}},{key:"changeHslColor",value:function(){this.colorpicker.changeInformationColor(this.getHslFormat())}},{key:"change $rgb_r",value:function(t){this.changeRgbColor()}},{key:"change $rgb_g",value:function(t){this.changeRgbColor()}},{key:"change $rgb_b",value:function(t){this.changeRgbColor()}},{key:"change $rgb_a",value:function(t){this.changeRgbColor()}},{key:"change $hsl_h",value:function(t){this.changeHslColor()}},{key:"change $hsl_s",value:function(t){this.changeHslColor()}},{key:"change $hsl_l",value:function(t){this.changeHslColor()}},{key:"change $hsl_a",value:function(t){this.changeHslColor()}},{key:"keydown $hexCode",value:function(t){if(t.which<65||t.which>70)return this.checkNumberKey(t)}},{key:"keyup $hexCode",value:function(t){var e=this.$hexCode.val();"#"==e.charAt(0)&&7==e.length&&(this.colorpicker.changeInformationColor(e),this.setInputColor())}},{key:"click $formatChangeButton",value:function(t){this.nextFormat()}},{key:"refresh",value:function(){}}]),e}(),Ot=function(t){function e(t){v(this,e);var r=b(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return y(e,Rt),g(e,[{key:"initialize",value:function(){this.$el=new $t("div","color"),this.$saturation=this.$el.createChild("div","saturation"),this.$value=this.$saturation.createChild("div","value"),this.$drag_pointer=this.$value.createChild("div","drag-pointer")}},{key:"setBackgroundColor",value:function(t){this.$el.css("background-color",t)}},{key:"refresh",value:function(){this.setColorUI()}},{key:"caculateSV",value:function(){var t=this.drag_pointer_pos||{x:0,y:0},e=this.state.get("$el.width"),r=this.state.get("$el.height");return{s:t.x/e,v:(r-t.y)/r,width:e,height:r}}},{key:"setColorUI",value:function(){var t=this.state.get("$el.width")*this.colorpicker.currentS,e=this.state.get("$el.height")*(1-this.colorpicker.currentV);this.$drag_pointer.css({left:t-5+"px",top:e-5+"px"}),this.drag_pointer_pos={x:t,y:e}}},{key:"setMainColor",value:function(t){t.preventDefault();var e=this.$el.position(),r=this.state.get("$el.contentWidth"),i=this.state.get("$el.contentHeight"),n=t.clientX-e.left,o=t.clientY-e.top;n<0?n=0:n>r&&(n=r),o<0?o=0:o>i&&(o=i),this.$drag_pointer.css({left:n-5+"px",top:o-5+"px"}),this.drag_pointer_pos={x:n,y:o},this.colorpicker.caculateHSV(),this.colorpicker.setInputColor()}},{key:"EventDocumentMouseUp",value:function(t){this.isDown=!1}},{key:"EventDocumentMouseMove",value:function(t){this.isDown&&this.setMainColor(t)}},{key:"mousedown",value:function(t){this.isDown=!0,this.setMainColor(t)}},{key:"mouseup",value:function(t){this.isDown=!1}}]),e}(),It="data-colorsets-index",Lt=function(t){function e(t){v(this,e);var r=b(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return r.colorpicker=t,r.initialize(),r}return y(e,Rt),g(e,[{key:"initialize",value:function(){this.$el=new $t("div","color-chooser");var t=this.$el.createChild("div","color-chooser-container"),e=t.createChild("div","colorsets-item colorsets-item-header");e.createChild("h1","title").html("Color Paletts"),this.$toggleButton=e.createChild("span","items").html("×"),this.$colorsetsList=t.createChild("div","colorsets-list"),this.refresh()}},{key:"refresh",value:function(){this.$colorsetsList.html(this.makeColorSetsList())}},{key:"makeColorItemList",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5,r=new $t("div"),i=0;i1&&void 0!==arguments[1]&&arguments[1];if("object"==(void 0===t?"undefined":f(t))){if(!t.r||!t.g||!t.b)return;e?this.callbackColorValue(_.format(t,"hex")):this.initColor(_.format(t,"hex"))}else"string"==typeof t&&(e?this.callbackColorValue(t):this.initColor(t))}},{key:"getColor",value:function(t){this.caculateHSV();var e=this.convertRGB();return t?_.format(e,t):e}},{key:"definePositionForArrow",value:function(t,e,r){}},{key:"definePosition",value:function(t){var e=this.$root.width(),r=this.$root.height(),i=t.left-this.$body.scrollLeft();e+i>window.innerWidth&&(i-=e+i-window.innerWidth),i<0&&(i=0);var n=t.top-this.$body.scrollTop();r+n>window.innerHeight&&(n-=r+n-window.innerHeight),n<0&&(n=0),this.$root.css({left:i+"px",top:n+"px"})}},{key:"getInitalizePosition",value:function(){return"inline"==this.opt.position?{position:"relative",left:"auto",top:"auto",display:"inline-block"}:{position:"fixed",left:"-10000px",top:"-10000px"}}},{key:"show",value:function(t,e,r){this.destroy(),this.initializeEvent(),this.$root.appendTo(this.$body),this.$root.css(this.getInitalizePosition()).show(),this.definePosition(t),this.isColorPickerShow=!0,this.isShortCut=t.isShortCut||!1,this.initColor(e),this.colorpickerCallback=r,this.hideDelay=t.hideDelay||2e3,this.hideDelay>0&&this.setHideDelay(this.hideDelay)}},{key:"setHideDelay",value:function(t){var e=this;t=t||0,this.$root.off("mouseenter"),this.$root.off("mouseleave"),this.$root.on("mouseenter",function(){clearTimeout(e.timerCloseColorPicker)}),this.$root.on("mouseleave",function(){clearTimeout(e.timerCloseColorPicker),e.timerCloseColorPicker=setTimeout(e.hide.bind(e),t)}),clearTimeout(this.timerCloseColorPicker),this.timerCloseColorPicker=setTimeout(this.hide.bind(this),t)}},{key:"hide",value:function(){this.isColorPickerShow&&(this.destroy(),this.$root.hide(),this.$root.remove(),this.isColorPickerShow=!1)}},{key:"convertRGB",value:function(){return _.HSVtoRGB(this.currentH,this.currentS,this.currentV)}},{key:"convertHEX",value:function(){return _.format(this.convertRGB(),"hex")}},{key:"convertHSL",value:function(){return _.HSVtoHSL(this.currentH,this.currentS,this.currentV)}},{key:"getCurrentColor",value:function(){return this.information.getFormattedColor()}},{key:"getFormattedColor",value:function(t){if("rgb"==(t=t||"hex"))return(r=this.convertRGB()).a=this.currentA,_.format(r,"rgb");if("hsl"==t){var e=this.convertHSL();return e.a=this.currentA,_.format(e,"hsl")}var r=this.convertRGB();return _.format(r,"hex")}},{key:"setInputColor",value:function(t){this.information.setInputColor(t),this.control.setInputColor(t),this.callbackColorValue()}},{key:"changeInputColorAfterNextFormat",value:function(){this.control.setInputColor(),this.callbackColorValue()}},{key:"callbackColorValue",value:function(t){t=t||this.getCurrentColor(),isNaN(this.currentA)||("function"==typeof this.opt.onChange&&this.opt.onChange.call(this,t),"function"==typeof this.colorpickerCallback&&this.colorpickerCallback(t))}},{key:"caculateHSV",value:function(){var t=this.palette.caculateSV(),e=this.control.caculateH(),r=t.s,i=t.v,n=e.h;0==t.width&&(n=0,r=0,i=0),this.currentH=n,this.currentS=r,this.currentV=i}},{key:"setColorUI",value:function(){this.control.setColorUI(),this.palette.setColorUI()}},{key:"setCurrentHSV",value:function(t,e,r,i){this.currentA=i,this.currentH=t,this.currentS=e,this.currentV=r}},{key:"setCurrentH",value:function(t){this.currentH=t}},{key:"setCurrentA",value:function(t){this.currentA=t}},{key:"setBackgroundColor",value:function(t){this.palette.setBackgroundColor(t)}},{key:"setCurrentFormat",value:function(t){this.format=t,this.information.setCurrentFormat(t)}},{key:"getHSV",value:function(t){return"hsl"==t.type?_.HSLtoHSV(t):_.RGBtoHSV(t)}},{key:"initColor",value:function(t,e){var r=t||"#FF0000",i=_.parse(r);e=e||i.type,this.setCurrentFormat(e);var n=this.getHSV(i);this.setCurrentHSV(n.h,n.s,n.v,i.a),this.setColorUI(),this.setHueColor(),this.setInputColor()}},{key:"changeInformationColor",value:function(t){var e=t||"#FF0000",r=_.parse(e),i=this.getHSV(r);this.setCurrentHSV(i.h,i.s,i.v,r.a),this.setColorUI(),this.setHueColor(),this.control.setInputColor(),this.callbackColorValue()}},{key:"setHueColor",value:function(){this.control.setOnlyHueColor()}},{key:"checkColorPickerClass",value:function(t){var e=new $t(t).closest("codemirror-colorview"),r=new $t(t).closest("codemirror-colorpicker"),i=new $t(t).closest("CodeMirror");t.nodeName;return!!(r||e||i)}},{key:"checkInHtml",value:function(t){return"HTML"==t.nodeName}},{key:"mouseup document",value:function(t){this.palette.EventDocumentMouseUp(t),this.control.EventDocumentMouseUp(t),this.checkInHtml(t.target)||0==this.checkColorPickerClass(t.target)&&this.hide()}},{key:"mousemove document",value:function(t){this.palette.EventDocumentMouseMove(t),this.control.EventDocumentMouseMove(t)}},{key:"initializeEvent",value:function(){this.initializeEventMachin(),this.palette.initializeEvent(),this.control.initializeEvent(),this.information.initializeEvent(),this.currentColorSets.initializeEvent(),this.colorSetsChooser.initializeEvent(),this.contextMenu.initializeEvent()}},{key:"currentFormat",value:function(){this.information.currentFormat()}},{key:"toggleColorChooser",value:function(){this.colorSetsChooser.toggle()}},{key:"refreshColorSetsChooser",value:function(){this.colorSetsChooser.refresh()}},{key:"getColorSetsList",value:function(){return this.colorSetsList.getColorSetsList()}},{key:"setCurrentColorSets",value:function(t){this.colorSetsList.setCurrentColorSets(t),this.currentColorSets.refresh()}},{key:"setColorSets",value:function(t){this.colorSetsList.setUserList(t)}},{key:"destroy",value:function(){m(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this.control.destroy(),this.palette.destroy(),this.information.destroy(),this.colorSetsChooser.destroy(),this.colorSetsList.destroy(),this.currentColorSets.destroy(),this.contextMenu.destroy(),this.colorpickerCallback=void 0}}]),e}(),Dt="codemirror-colorview",zt="codemirror-colorview-background",jt=["comment"];function Vt(t,e){"setValue"==e.origin?(t.state.colorpicker.close_color_picker(),t.state.colorpicker.init_color_update(),t.state.colorpicker.style_color_update()):t.state.colorpicker.style_color_update(t.getCursor().line)}function Ut(t,e){t.state.colorpicker.isUpdate||(t.state.colorpicker.isUpdate=!0,t.state.colorpicker.close_color_picker(),t.state.colorpicker.init_color_update(),t.state.colorpicker.style_color_update())}function Xt(t,e){Vt(t,{origin:"setValue"})}function Yt(t,e){t.state.colorpicker.keyup(e)}function qt(t,e){t.state.colorpicker.is_edit_mode()&&t.state.colorpicker.check_mousedown(e)}function Kt(t,e){Vt(t,{origin:"setValue"})}function Wt(t){t.state.colorpicker.close_color_picker()}var Zt=function(){function t(e,r){v(this,t),r="boolean"==typeof r?{mode:"edit"}:Object.assign({mode:"edit"},r||{}),this.opt=r,this.cm=e,this.markers={},this.excluded_token=this.opt.excluded_token||jt,this.opt.colorpicker?this.colorpicker=this.opt.colorpicker(this.opt):this.colorpicker=new Tt(this.opt),this.init_event()}return g(t,[{key:"init_event",value:function(){var t,e,r,i,n;this.cm.on("mousedown",qt),this.cm.on("keyup",Yt),this.cm.on("change",Vt),this.cm.on("update",Ut),this.cm.on("refresh",Xt),this.onPasteCallback=(t=this.cm,e=Kt,function(r){e.call(this,t,r)}),this.cm.getWrapperElement().addEventListener("paste",this.onPasteCallback),this.is_edit_mode()&&this.cm.on("scroll",(r=Wt,i=50,n=void 0,function(t,e){n&&clearTimeout(n),n=setTimeout(function(){r(t,e)},i||300)}))}},{key:"is_edit_mode",value:function(){return"edit"==this.opt.mode}},{key:"is_view_mode",value:function(){return"view"==this.opt.mode}},{key:"destroy",value:function(){this.cm.off("mousedown",qt),this.cm.off("keyup",Yt),this.cm.off("change",Vt),this.cm.getWrapperElement().removeEventListener("paste",this.onPasteCallback),this.is_edit_mode()&&this.cm.off("scroll")}},{key:"hasClass",value:function(t,e){return!!t.className&&(" "+t.className+" ").indexOf(" "+e+" ")>-1}},{key:"check_mousedown",value:function(t){this.hasClass(t.target,zt)?this.open_color_picker(t.target.parentNode):this.close_color_picker()}},{key:"popup_color_picker",value:function(t){var e=this.cm.getCursor(),r=this,i={lineNo:e.line,ch:e.ch,color:t||"#FFFFFF",isShortCut:!0};Object.keys(this.markers).forEach(function(t){if(("#"+t).indexOf("#"+i.lineNo+":")>-1){var e=r.markers[t];e.ch<=i.ch&&i.ch<=e.ch+e.color.length&&(i.ch=e.ch,i.color=e.color,i.nameColor=e.nameColor)}}),this.open_color_picker(i)}},{key:"open_color_picker",value:function(t){var e=t.lineNo,r=t.ch,i=t.nameColor,n=t.color;if(this.colorpicker){var o=this,a=n,s=this.cm.charCoords({line:e,ch:r});this.colorpicker.show({left:s.left,top:s.bottom,isShortCut:t.isShortCut||!1,hideDelay:o.opt.hideDelay||2e3},i||n,function(t){o.cm.replaceRange(t,{line:e,ch:r},{line:e,ch:r+a.length},"*colorpicker"),a=t})}}},{key:"close_color_picker",value:function(t){this.colorpicker&&this.colorpicker.hide()}},{key:"key",value:function(t,e){return[t,e].join(":")}},{key:"keyup",value:function(t){this.colorpicker&&("Escape"==t.key?this.colorpicker.hide():0==this.colorpicker.isShortCut&&this.colorpicker.hide())}},{key:"init_color_update",value:function(){this.markers={}}},{key:"style_color_update",value:function(t){if(t)this.match(t);else for(var e=this.cm.lineCount(),r=0;r-1)&&(delete this.markers[s],n[o].marker.clear())}}},{key:"match_result",value:function(t){return _.matches(t.text)}},{key:"submatch",value:function(t,e){var r=this;this.empty_marker(t,e);var i={next:0};this.match_result(e).forEach(function(n){r.render(i,t,e,n.color,n.nameColor)})}},{key:"match",value:function(t){var e=this.cm.getLineHandle(t),r=this;this.cm.operation(function(){r.submatch(t,e)})}},{key:"make_element",value:function(){var t=document.createElement("div");return t.className=Dt,this.is_edit_mode()?t.title="open color picker":t.title="",t.back_element=this.make_background_element(),t.appendChild(t.back_element),t}},{key:"make_background_element",value:function(){var t=document.createElement("div");return t.className=zt,t}},{key:"set_state",value:function(t,e,r,i){var n=this.create_marker(t,e);return n.lineNo=t,n.ch=e,n.color=r,n.nameColor=i,n}},{key:"create_marker",value:function(t,e){var r=this.key(t,e);return this.markers[r]||(this.markers[r]=this.make_element()),this.markers[r]}},{key:"has_marker",value:function(t,e){var r=this.key(t,e);return!!this.markers[r]}},{key:"update_element",value:function(t,e){t.back_element.style.backgroundColor=e}},{key:"set_mark",value:function(t,e,r){this.cm.setBookmark({line:t,ch:e},{widget:r,handleMouseEvents:!0})}},{key:"is_excluded_token",value:function(t,e){for(var r=this.cm.getTokenTypeAt({line:t,ch:e}),i=0,n=0,o=this.excluded_token.length;n0}},{key:"render",value:function(t,e,r,i,n){var o=r.text.indexOf(i,t.next);if(!0!==this.is_excluded_token(e,o)){if(t.next=o+i.length,this.has_marker(e,o))return this.update_element(this.create_marker(e,o),n||i),void this.set_state(e,o,i,n);var a=this.create_marker(e,o);this.update_element(a,n||i),this.set_state(e,o,i,n||i),this.set_mark(e,o,a)}}}]),t}();return t&&t.defineOption("colorpicker",!1,function(e,r,i){i&&i!=t.Init&&e.state.colorpicker&&(e.state.colorpicker.destroy(),e.state.colorpicker=null),r&&(e.state.colorpicker=new Zt(e,r))}),{Color:_,ColorNames:r,ColorPicker:Tt,ImageFilter:wt,HueColor:S,Canvas:u,ImageLoader:w}}(CodeMirror); diff --git a/index.html b/index.html index 4d1e51b..10d3e4a 100644 --- a/index.html +++ b/index.html @@ -672,8 +672,11 @@

Image Filter

- -
+ + +
+ +
@@ -737,11 +740,7 @@

Image Filter

-
-
- - -
+
@@ -766,26 +765,7 @@

Image Filter

-
- - - - - - - - - - - - - - - - -
- -
+ @@ -985,34 +965,8 @@

Default Html Sample

document.getElementById('filtered-image').src = url; }) } - - function filter_count () { - var args = Array.prototype.slice.call(arguments); - var file = document.getElementById('imageforfilter').files[0]; - var ImageFilter = CodeMirrorColorPicker.ImageFilter; - document.getElementById('sampled-image').src = URL.createObjectURL(file); - Color.ImageToURL(file, ImageFilter.counter(ImageFilter.merge(args), 100), function (url) { - document.getElementById('filtered-image').src = url; - }) - } - function filter_custom () { - var file = document.getElementById('imageforfilter').files[0]; - var ImageFilter = CodeMirrorColorPicker.ImageFilter; - document.getElementById('sampled-image').src = URL.createObjectURL(file); - - var items = document.querySelectorAll(".weights input[type=number]"); - var weights = []; - [].forEach.call(items, function (it) { - weights.push(+it.value); - }) - - Color.ImageToURL(file, ImageFilter.convolution(weights), function (url) { - document.getElementById('filtered-image').src = url; - }) - } - function shuffle(a) { var j, x, i; for (i = a.length - 1; i > 0; i--) { diff --git a/package.json b/package.json index af6629d..541e6aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codemirror-colorpicker", - "version": "1.8.0", + "version": "1.8.1", "description": "colorpicker for codemirror", "main": "./dist/codemirror-colorpicker.js", "scripts": { diff --git a/src/util/ImageFilter.js b/src/util/ImageFilter.js index 251fab4..8ae427c 100644 --- a/src/util/ImageFilter.js +++ b/src/util/ImageFilter.js @@ -1,120 +1,6 @@ // TODO: worker run -import { - makeFilter, - getBitmap, - putBitmap, - pack, - packXY, - swapColor, - matches -} from './filter/functions' +import FilterFunctions from './filter/functions' -import ImageFilter from './filter/index' +import FilterList from './filter/index' -Object.assign(ImageFilter, { - pack, - packXY, - swapColor -}) - -let F = ImageFilter - -F.filter = function (str) { - return F.merge(matches(str).map(it => { - return it.arr - })) -} - -/** - * - * multiply filters - * - * ImageFilter.multi('blur', 'grayscale', 'sharpen', ['blur', 3], function (bitmap) { return bitmap }); - * - */ -F.multi = function (...filters) { - filters = filters.map(filter => { - return makeFilter(filter, F); - }) - - return function (bitmap) { - return filters.reduce((bitmap, f) => { - return f(bitmap); - }, bitmap) - } -} - - -F.merge = function (filters) { - return F.multi(...filters); -} - -/** - * apply filter into special area - * - * F.partial({x,y,width,height}, filter, filter, filter ) - * F.partial({x,y,width,height}, 'filter' ) - * - * @param {{x, y, width, height}} area - * @param {*} filters - */ -F.partial = function (area, ...filters) { - var allFilter = null - if (filters.length == 1 && typeof filters[0] === 'string') { - allFilter = F.filter(filters[0]) - } else { - allFilter = F.merge(filters) - } - - return (bitmap) => { - return putBitmap(bitmap, allFilter(getBitmap(bitmap, area)), area); - } -} - -F.counter = function (filter, count = 1) { - var filters = []; - - for (var i = 0; i < count; i++) { - filters.push(filter); - } - - return F.multi(...filters); -} - - -/** - * multi filter - */ - - -F.laplacian.grayscale = function (amount = 100) { - return F.filter(`grayscale laplacian(${amount}`) -} - - -F.laplacian5x.grayscale = function () { - return F.filter('grayscale laplacian5x'); -} - - -F.kirsch = function () { - return F.filter('kirsch-horizontal kirsch-vertical'); -} - -F.kirsch.grayscale = function () { - return F.filter('grayscale kirsch'); -} - -F.sobel = function () { - return F.filter('sobel-horizontal sobel-vertical'); -} - -F.sobel.grayscale = function () { - return F.filter('grayscale sobel'); -} - -F.vintage = function () { - return F.filter(`brightness(15) saturation(-20) gamma(1.8)`) -} - -export default ImageFilter \ No newline at end of file +export default Object.assign({}, FilterList, FilterFunctions) diff --git a/src/util/blur/StackBlur.js b/src/util/filter/StackBlur.js similarity index 100% rename from src/util/blur/StackBlur.js rename to src/util/filter/StackBlur.js diff --git a/src/util/filter/functions.js b/src/util/filter/functions.js index 71de287..607c2a2 100644 --- a/src/util/filter/functions.js +++ b/src/util/filter/functions.js @@ -1,5 +1,39 @@ import Canvas from '../Canvas' import Matrix from '../Matrix' +import ImageFilter from './index' + +const functions = { + partial, + multi, + merge, + weight, + repeat, + colorMatrix, + each, + eachXY, + createRandomCount, + createRandRange, + createBitmap, + createBlurMatrix, + pack, + packXY, + getBitmap, + putBitmap, + radian, + convolution, + parseParamNumber, + filter, + clamp, + multi, + merge, + matches, + parseFilter, + partial +} + +const LocalFilter = functions + +export default functions export function weight(arr, num = 1) { return arr.map(i => { @@ -25,7 +59,7 @@ export function colorMatrix(pixels, i, matrix) { } -export function makeFilter(filter, F) { +export function makeFilter(filter) { if (typeof filter == 'function') { return filter; @@ -43,7 +77,7 @@ export function makeFilter(filter, F) { const params = filter; - const filterFunction = F[filterName]; + const filterFunction = ImageFilter[filterName] || LocalFilter[filterName] ; if (!filterFunction) { throw new Error(`${filterName} is not filter. please check filter name.`) @@ -272,3 +306,57 @@ export function parseFilter (filterString) { export function clamp (num) {ß return Math.min(255, num) } + + + +export function filter (str) { + return merge(matches(str).map(it => { + return it.arr + })) +} + +/** + * + * multiply filters + * + * ImageFilter.multi('blur', 'grayscale', 'sharpen', ['blur', 3], function (bitmap) { return bitmap }); + * + */ +export function multi (...filters) { + filters = filters.map(filter => { + return makeFilter(filter); + }) + + return function (bitmap) { + return filters.reduce((bitmap, f) => { + return f(bitmap); + }, bitmap) + } +} + + +export function merge (filters) { + return multi(...filters); +} + +/** + * apply filter into special area + * + * F.partial({x,y,width,height}, filter, filter, filter ) + * F.partial({x,y,width,height}, 'filter' ) + * + * @param {{x, y, width, height}} area + * @param {*} filters + */ +export function partial (area, ...filters) { + var allFilter = null + if (filters.length == 1 && typeof filters[0] === 'string') { + allFilter = filter(filters[0]) + } else { + allFilter = merge(filters) + } + + return (bitmap) => { + return putBitmap(bitmap, allFilter(getBitmap(bitmap, area)), area); + } +} \ No newline at end of file diff --git a/src/util/filter/index.js b/src/util/filter/index.js index 3d6599d..81d3110 100644 --- a/src/util/filter/index.js +++ b/src/util/filter/index.js @@ -1,9 +1,11 @@ import image from './image/index' import pixel from './pixel/index' import matrix from './matrix/index' +import multi from './multi/index' -export default { +export default { ...image, ...pixel, - ...matrix + ...matrix, + ...multi } \ No newline at end of file diff --git a/src/util/filter/matrix/stack-blur.js b/src/util/filter/matrix/stack-blur.js index c81ec1e..1e77f3d 100644 --- a/src/util/filter/matrix/stack-blur.js +++ b/src/util/filter/matrix/stack-blur.js @@ -2,7 +2,7 @@ import { parseParamNumber } from '../functions' -import StackBlur from '../../blur/StackBlur' +import StackBlur from '../StackBlur' export default function (radius = 10, hasAlphaChannel = true) { radius = parseParamNumber(radius) diff --git a/src/util/filter/multi/index.js b/src/util/filter/multi/index.js new file mode 100644 index 0000000..0af4419 --- /dev/null +++ b/src/util/filter/multi/index.js @@ -0,0 +1,9 @@ +import kirsch from './kirsch' +import sobel from './sobel' +import vintage from './vintage' + +export default { + kirsch, + sobel, + vintage +} \ No newline at end of file diff --git a/src/util/filter/multi/kirsch.js b/src/util/filter/multi/kirsch.js new file mode 100644 index 0000000..625bca5 --- /dev/null +++ b/src/util/filter/multi/kirsch.js @@ -0,0 +1,7 @@ +import { + filter +} from '../functions' + +export default function kirsch () { + return filter('kirsch-horizontal kirsch-vertical'); +} \ No newline at end of file diff --git a/src/util/filter/multi/sobel.js b/src/util/filter/multi/sobel.js new file mode 100644 index 0000000..eafe05c --- /dev/null +++ b/src/util/filter/multi/sobel.js @@ -0,0 +1,7 @@ +import { + filter +} from '../functions' + +export default function sobel () { + return filter('sobel-horizontal sobel-vertical'); +} \ No newline at end of file diff --git a/src/util/filter/multi/vintage.js b/src/util/filter/multi/vintage.js new file mode 100644 index 0000000..6fd7261 --- /dev/null +++ b/src/util/filter/multi/vintage.js @@ -0,0 +1,7 @@ +import { + filter +} from '../functions' + +export default function vintage () { + return filter(`brightness(15) saturation(-20) gamma(1.8)`) +} \ No newline at end of file