ace-colorpicker-rpk 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +30 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- package/ChangeLogs.md +22 -0
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/addon/ace-colorpicker.css +1074 -0
- package/addon/ace-colorpicker.js +9602 -0
- package/addon/sample/colorpicker.html +199 -0
- package/config/rollup.config.dev.js +52 -0
- package/config/rollup.config.prod.js +53 -0
- package/dist/ace-colorpicker.css +1074 -0
- package/dist/ace-colorpicker.js +9736 -0
- package/dist/ace-colorpicker.min.js +1 -0
- package/gl.html +56 -0
- package/index.html +172 -0
- package/package.json +87 -0
- package/resources/image/ace-editor.png +0 -0
- package/resources/image/colorpaletts.png +0 -0
- package/resources/image/colorpicker.png +0 -0
- package/resources/image/grapes.jpg +0 -0
- package/resources/image/palette-type.png +0 -0
- package/resources/image/scalecolors-title.png +0 -0
- package/resources/image/scalecolors.png +0 -0
- package/resources/image/screen-shot.png +0 -0
- package/resources/image/sketch-type.png +0 -0
- package/src/colorpicker/BaseBox.js +94 -0
- package/src/colorpicker/BaseColorPicker.js +404 -0
- package/src/colorpicker/BaseModule.js +19 -0
- package/src/colorpicker/BaseSlider.js +97 -0
- package/src/colorpicker/BaseStore.js +71 -0
- package/src/colorpicker/UIElement.js +46 -0
- package/src/colorpicker/VerticalSlider.js +57 -0
- package/src/colorpicker/chromedevtool/ColorControl.js +47 -0
- package/src/colorpicker/chromedevtool/index.js +36 -0
- package/src/colorpicker/index.js +37 -0
- package/src/colorpicker/macos/ColorControl.js +47 -0
- package/src/colorpicker/macos/index.js +38 -0
- package/src/colorpicker/mini/ColorControl.js +40 -0
- package/src/colorpicker/mini/index.js +24 -0
- package/src/colorpicker/mini-vertical/ColorControl.js +35 -0
- package/src/colorpicker/mini-vertical/index.js +23 -0
- package/src/colorpicker/module/ColorManager.js +111 -0
- package/src/colorpicker/module/ColorSetsList.js +132 -0
- package/src/colorpicker/ring/ColorControl.js +47 -0
- package/src/colorpicker/ring/index.js +42 -0
- package/src/colorpicker/ui/ColorInformation.js +216 -0
- package/src/colorpicker/ui/ColorPalette.js +130 -0
- package/src/colorpicker/ui/ColorRing.js +68 -0
- package/src/colorpicker/ui/ColorSetsChooser.js +96 -0
- package/src/colorpicker/ui/ColorWheel.js +257 -0
- package/src/colorpicker/ui/CurrentColorSets.js +81 -0
- package/src/colorpicker/ui/CurrentColorSetsContextMenu.js +63 -0
- package/src/colorpicker/ui/control/Hue.js +40 -0
- package/src/colorpicker/ui/control/Opacity.js +65 -0
- package/src/colorpicker/ui/control/Value.js +50 -0
- package/src/colorpicker/ui/control/VerticalHue.js +39 -0
- package/src/colorpicker/ui/control/VerticalOpacity.js +55 -0
- package/src/colorpicker/vscode/ColorControl.js +40 -0
- package/src/colorpicker/vscode/index.js +82 -0
- package/src/colorpicker/xd/ColorControl.js +36 -0
- package/src/colorpicker/xd/index.js +36 -0
- package/src/extension/ace/colorview.js +198 -0
- package/src/extension/ace/index.js +11 -0
- package/src/index.js +12 -0
- package/src/scss/colorpicker.scss +65 -0
- package/src/scss/colorview.scss +32 -0
- package/src/scss/component/button.scss +33 -0
- package/src/scss/component/colorchooser.scss +141 -0
- package/src/scss/component/colorsets-contextmenu.scss +33 -0
- package/src/scss/component/colorsets.scss +89 -0
- package/src/scss/component/control.scss +93 -0
- package/src/scss/component/gradient-editor.scss +260 -0
- package/src/scss/component/gradient-picker.scss +241 -0
- package/src/scss/component/information.scss +141 -0
- package/src/scss/component/palette.scss +45 -0
- package/src/scss/index.scss +5 -0
- package/src/scss/mixins.scss +21 -0
- package/src/scss/themes/macos.scss +71 -0
- package/src/scss/themes/mini-vertical.scss +94 -0
- package/src/scss/themes/mini.scss +76 -0
- package/src/scss/themes/palette.scss +85 -0
- package/src/scss/themes/ring.scss +57 -0
- package/src/scss/themes/sketch.scss +172 -0
- package/src/scss/themes/vscode.scss +93 -0
- package/src/scss/themes/xd.scss +88 -0
- package/src/util/Blender.js +29 -0
- package/src/util/Canvas.js +128 -0
- package/src/util/Color.js +27 -0
- package/src/util/ColorNames.js +14 -0
- package/src/util/Dom.js +361 -0
- package/src/util/Event.js +30 -0
- package/src/util/EventMachin.js +349 -0
- package/src/util/GL.js +8 -0
- package/src/util/HueColor.js +49 -0
- package/src/util/ImageFilter.js +9 -0
- package/src/util/ImageLoader.js +137 -0
- package/src/util/Kmeans.js +237 -0
- package/src/util/Matrix.js +196 -0
- package/src/util/State.js +42 -0
- package/src/util/blend/composite.js +124 -0
- package/src/util/blend/non-separable.js +118 -0
- package/src/util/blend/separable.js +76 -0
- package/src/util/filter/StackBlur.js +517 -0
- package/src/util/filter/functions.js +829 -0
- package/src/util/filter/image/crop.js +16 -0
- package/src/util/filter/image/flipH.js +23 -0
- package/src/util/filter/image/flipV.js +25 -0
- package/src/util/filter/image/histogram.js +45 -0
- package/src/util/filter/image/index.js +18 -0
- package/src/util/filter/image/resize.js +18 -0
- package/src/util/filter/image/rotate.js +39 -0
- package/src/util/filter/image/rotateDegree.js +53 -0
- package/src/util/filter/index.js +11 -0
- package/src/util/filter/matrix/blur.js +12 -0
- package/src/util/filter/matrix/emboss.js +17 -0
- package/src/util/filter/matrix/gaussian-blur-5x.js +17 -0
- package/src/util/filter/matrix/gaussian-blur.js +16 -0
- package/src/util/filter/matrix/grayscale2.js +16 -0
- package/src/util/filter/matrix/index.js +58 -0
- package/src/util/filter/matrix/kirsch-horizontal.js +13 -0
- package/src/util/filter/matrix/kirsch-vertical.js +13 -0
- package/src/util/filter/matrix/laplacian-5x.js +16 -0
- package/src/util/filter/matrix/laplacian.js +14 -0
- package/src/util/filter/matrix/motion-blur-2.js +18 -0
- package/src/util/filter/matrix/motion-blur-3.js +19 -0
- package/src/util/filter/matrix/motion-blur.js +18 -0
- package/src/util/filter/matrix/negative.js +16 -0
- package/src/util/filter/matrix/normal.js +11 -0
- package/src/util/filter/matrix/sepia2.js +16 -0
- package/src/util/filter/matrix/sharpen.js +14 -0
- package/src/util/filter/matrix/sobel-horizontal.js +11 -0
- package/src/util/filter/matrix/sobel-vertical.js +11 -0
- package/src/util/filter/matrix/stack-blur.js +15 -0
- package/src/util/filter/matrix/transparency.js +16 -0
- package/src/util/filter/matrix/unsharp-masking.js +16 -0
- package/src/util/filter/multi/index.js +9 -0
- package/src/util/filter/multi/kirsch.js +7 -0
- package/src/util/filter/multi/sobel.js +7 -0
- package/src/util/filter/multi/vintage.js +7 -0
- package/src/util/filter/pixel/bitonal.js +24 -0
- package/src/util/filter/pixel/brightness.js +19 -0
- package/src/util/filter/pixel/brownie.js +23 -0
- package/src/util/filter/pixel/clip.js +21 -0
- package/src/util/filter/pixel/contrast.js +18 -0
- package/src/util/filter/pixel/gamma.js +13 -0
- package/src/util/filter/pixel/gradient.js +52 -0
- package/src/util/filter/pixel/grayscale.js +27 -0
- package/src/util/filter/pixel/hue.js +28 -0
- package/src/util/filter/pixel/index.js +52 -0
- package/src/util/filter/pixel/invert.js +16 -0
- package/src/util/filter/pixel/kodachrome.js +23 -0
- package/src/util/filter/pixel/matrix.js +28 -0
- package/src/util/filter/pixel/noise.js +24 -0
- package/src/util/filter/pixel/opacity.js +14 -0
- package/src/util/filter/pixel/polaroid.js +23 -0
- package/src/util/filter/pixel/saturation.js +30 -0
- package/src/util/filter/pixel/sepia.js +28 -0
- package/src/util/filter/pixel/shade.js +21 -0
- package/src/util/filter/pixel/shift.js +23 -0
- package/src/util/filter/pixel/solarize.js +23 -0
- package/src/util/filter/pixel/technicolor.js +23 -0
- package/src/util/filter/pixel/threshold-color.js +35 -0
- package/src/util/filter/pixel/threshold.js +7 -0
- package/src/util/filter/pixel/tint.js +20 -0
- package/src/util/functions/formatter.js +99 -0
- package/src/util/functions/fromCMYK.js +17 -0
- package/src/util/functions/fromHSL.js +52 -0
- package/src/util/functions/fromHSV.js +64 -0
- package/src/util/functions/fromLAB.js +99 -0
- package/src/util/functions/fromRGB.js +220 -0
- package/src/util/functions/fromYCrCb.js +16 -0
- package/src/util/functions/func.js +194 -0
- package/src/util/functions/image.js +145 -0
- package/src/util/functions/math.js +56 -0
- package/src/util/functions/mixin.js +164 -0
- package/src/util/functions/parser.js +294 -0
- package/src/util/gl/filter/index.js +9 -0
- package/src/util/gl/filter/matrix/blur.js +9 -0
- package/src/util/gl/filter/matrix/emboss.js +17 -0
- package/src/util/gl/filter/matrix/gaussian-blur-5x.js +15 -0
- package/src/util/gl/filter/matrix/gaussian-blur.js +19 -0
- package/src/util/gl/filter/matrix/grayscale2.js +13 -0
- package/src/util/gl/filter/matrix/index.js +55 -0
- package/src/util/gl/filter/matrix/kirsch-horizontal.js +11 -0
- package/src/util/gl/filter/matrix/kirsch-vertical.js +11 -0
- package/src/util/gl/filter/matrix/laplacian-5x.js +13 -0
- package/src/util/gl/filter/matrix/laplacian.js +11 -0
- package/src/util/gl/filter/matrix/motion-blur-2.js +17 -0
- package/src/util/gl/filter/matrix/motion-blur-3.js +17 -0
- package/src/util/gl/filter/matrix/motion-blur.js +17 -0
- package/src/util/gl/filter/matrix/negative.js +13 -0
- package/src/util/gl/filter/matrix/normal.js +8 -0
- package/src/util/gl/filter/matrix/sepia2.js +13 -0
- package/src/util/gl/filter/matrix/sharpen.js +11 -0
- package/src/util/gl/filter/matrix/sobel-horizontal.js +11 -0
- package/src/util/gl/filter/matrix/sobel-vertical.js +11 -0
- package/src/util/gl/filter/matrix/transparency.js +13 -0
- package/src/util/gl/filter/matrix/unsharp-masking.js +14 -0
- package/src/util/gl/filter/multi/index.js +9 -0
- package/src/util/gl/filter/multi/kirsch.js +7 -0
- package/src/util/gl/filter/multi/sobel.js +7 -0
- package/src/util/gl/filter/multi/vintage.js +7 -0
- package/src/util/gl/filter/pixel/bitonal.js +22 -0
- package/src/util/gl/filter/pixel/brightness.js +14 -0
- package/src/util/gl/filter/pixel/brownie.js +11 -0
- package/src/util/gl/filter/pixel/chaos.js +20 -0
- package/src/util/gl/filter/pixel/clip.js +20 -0
- package/src/util/gl/filter/pixel/contrast.js +16 -0
- package/src/util/gl/filter/pixel/gamma.js +16 -0
- package/src/util/gl/filter/pixel/gradient.js +59 -0
- package/src/util/gl/filter/pixel/grayscale.js +22 -0
- package/src/util/gl/filter/pixel/hue.js +19 -0
- package/src/util/gl/filter/pixel/index.js +54 -0
- package/src/util/gl/filter/pixel/invert.js +18 -0
- package/src/util/gl/filter/pixel/kodachrome.js +11 -0
- package/src/util/gl/filter/pixel/matrix.js +29 -0
- package/src/util/gl/filter/pixel/noise.js +18 -0
- package/src/util/gl/filter/pixel/opacity.js +17 -0
- package/src/util/gl/filter/pixel/polaroid.js +11 -0
- package/src/util/gl/filter/pixel/saturation.js +20 -0
- package/src/util/gl/filter/pixel/sepia.js +19 -0
- package/src/util/gl/filter/pixel/shade.js +20 -0
- package/src/util/gl/filter/pixel/shift.js +11 -0
- package/src/util/gl/filter/pixel/solarize.js +21 -0
- package/src/util/gl/filter/pixel/technicolor.js +11 -0
- package/src/util/gl/filter/pixel/threshold-color.js +15 -0
- package/src/util/gl/filter/pixel/threshold.js +7 -0
- package/src/util/gl/filter/pixel/tint.js +25 -0
- package/src/util/gl/filter/util.js +185 -0
- package/src/util/gl/functions.js +158 -0
- package/src/util/gl/index.js +543 -0
- package/src/util/index.js +17 -0
- package/stand.html +975 -0
- package/test/util.Blend.spec.js +15 -0
- package/test/util.Color.spec.js +200 -0
- package/test/util.Filter.spec.js +12 -0
- package/test/util.ImageFilter.spec.js +16 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
|
2
|
+
export function debounce (callback, delay) {
|
3
|
+
|
4
|
+
var t = undefined;
|
5
|
+
|
6
|
+
return function ($1, $2, $3, $4, $5) {
|
7
|
+
if (t) {
|
8
|
+
clearTimeout(t);
|
9
|
+
}
|
10
|
+
|
11
|
+
t = setTimeout(function () {
|
12
|
+
callback($1, $2, $3, $4, $5);
|
13
|
+
}, delay || 300);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
export function throttle (callback, delay) {
|
19
|
+
|
20
|
+
var t = undefined;
|
21
|
+
|
22
|
+
return function ($1, $2, $3, $4, $5) {
|
23
|
+
if (!t) {
|
24
|
+
t = setTimeout(function () {
|
25
|
+
callback($1, $2, $3, $4, $5);
|
26
|
+
t = null;
|
27
|
+
}, delay || 300);
|
28
|
+
}
|
29
|
+
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
export function keyEach (obj, callback) {
|
34
|
+
Object.keys(obj).forEach( (key, index) => {
|
35
|
+
callback (key, obj[key], index);
|
36
|
+
})
|
37
|
+
}
|
38
|
+
|
39
|
+
export function keyMap (obj, callback) {
|
40
|
+
return Object.keys(obj).map( (key, index) => {
|
41
|
+
return callback (key, obj[key], index);
|
42
|
+
})
|
43
|
+
}
|
44
|
+
|
45
|
+
export function get(obj, key, callback) {
|
46
|
+
|
47
|
+
var returnValue = defaultValue(obj[key], key);
|
48
|
+
|
49
|
+
if (isFunction( callback ) ) {
|
50
|
+
return callback(returnValue);
|
51
|
+
}
|
52
|
+
|
53
|
+
return returnValue;
|
54
|
+
}
|
55
|
+
|
56
|
+
export function defaultValue (value, defaultValue) {
|
57
|
+
return typeof value == 'undefined' ? defaultValue : value;
|
58
|
+
}
|
59
|
+
|
60
|
+
export function isUndefined (value) {
|
61
|
+
return typeof value == 'undefined' || value === null;
|
62
|
+
}
|
63
|
+
|
64
|
+
export function isNotUndefined (value) {
|
65
|
+
return isUndefined(value) === false;
|
66
|
+
}
|
67
|
+
|
68
|
+
export function isArray (value) {
|
69
|
+
return Array.isArray(value);
|
70
|
+
}
|
71
|
+
|
72
|
+
export function isBoolean (value) {
|
73
|
+
return typeof value == 'boolean'
|
74
|
+
}
|
75
|
+
|
76
|
+
export function isString (value) {
|
77
|
+
return typeof value == 'string'
|
78
|
+
}
|
79
|
+
|
80
|
+
export function isNotString (value) {
|
81
|
+
return isString(value) === false;
|
82
|
+
}
|
83
|
+
|
84
|
+
export function isObject (value) {
|
85
|
+
return typeof value == 'object' && !isArray(value) && !isNumber(value) && !isString(value) && value !== null;
|
86
|
+
}
|
87
|
+
|
88
|
+
export function isFunction (value) {
|
89
|
+
return typeof value == 'function'
|
90
|
+
}
|
91
|
+
|
92
|
+
export function isNumber (value) {
|
93
|
+
return typeof value == 'number';
|
94
|
+
}
|
95
|
+
|
96
|
+
export function clone (obj) {
|
97
|
+
return JSON.parse(JSON.stringify(obj));
|
98
|
+
}
|
99
|
+
|
100
|
+
export function cleanObject (obj) {
|
101
|
+
var realObject = {}
|
102
|
+
Object.keys(obj).filter(key => {
|
103
|
+
return !!obj[key]
|
104
|
+
}).forEach(key => {
|
105
|
+
realObject[key] = obj[key]
|
106
|
+
});
|
107
|
+
|
108
|
+
return realObject;
|
109
|
+
}
|
110
|
+
|
111
|
+
export function combineKeyArray (obj) {
|
112
|
+
Object.keys(obj).forEach(key => {
|
113
|
+
if (Array.isArray(obj[key])) {
|
114
|
+
obj[key] = obj[key].join(', ')
|
115
|
+
}
|
116
|
+
})
|
117
|
+
|
118
|
+
return obj;
|
119
|
+
}
|
120
|
+
|
121
|
+
export function repeat (count) {
|
122
|
+
return [...Array(count)];
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
const short_tag_regexp = /\<(\w*)([^\>]*)\/\>/gim;
|
127
|
+
|
128
|
+
const HTML_TAG = {
|
129
|
+
'image': true,
|
130
|
+
'input': true,
|
131
|
+
'br': true,
|
132
|
+
'path': true
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
export const html = (strings, ...args) => {
|
137
|
+
|
138
|
+
var results = strings.map((it, index) => {
|
139
|
+
|
140
|
+
var results = args[index] || ''
|
141
|
+
|
142
|
+
if (isFunction(results)) {
|
143
|
+
results = results()
|
144
|
+
}
|
145
|
+
|
146
|
+
if (!isArray(results)) {
|
147
|
+
results = [results]
|
148
|
+
}
|
149
|
+
|
150
|
+
results = results.map(r => {
|
151
|
+
if (isObject(r) && !isArray(r)) {
|
152
|
+
return Object.keys(r).map(key => {
|
153
|
+
return `${key}="${r[key]}"`
|
154
|
+
}).join(' ')
|
155
|
+
}
|
156
|
+
|
157
|
+
return r
|
158
|
+
}).join('')
|
159
|
+
|
160
|
+
return it + results;
|
161
|
+
}).join('');
|
162
|
+
|
163
|
+
results = results.replace(short_tag_regexp, function (match, p1) {
|
164
|
+
if (HTML_TAG[p1.toLowerCase()]) {
|
165
|
+
return match;
|
166
|
+
} else {
|
167
|
+
return match.replace('/>', `></${p1}>`)
|
168
|
+
}
|
169
|
+
})
|
170
|
+
|
171
|
+
return results;
|
172
|
+
}
|
173
|
+
|
174
|
+
export function CSS_TO_STRING(style) {
|
175
|
+
var newStyle = style;
|
176
|
+
|
177
|
+
return Object.keys(newStyle)
|
178
|
+
.filter(key => newStyle[key])
|
179
|
+
.map(key => `${key}: ${newStyle[key]}`)
|
180
|
+
.join(";");
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
export function STRING_TO_CSS (str) {
|
185
|
+
var style = {}
|
186
|
+
str.split(';').forEach(it => {
|
187
|
+
var [key, ...value] = it.split(':').map(it => it.trim())
|
188
|
+
if (key != '') {
|
189
|
+
style[key] = value.join(':');
|
190
|
+
}
|
191
|
+
})
|
192
|
+
|
193
|
+
return style;
|
194
|
+
}
|
@@ -0,0 +1,145 @@
|
|
1
|
+
import kmeans from '../Kmeans'
|
2
|
+
import ImageLoader from '../ImageLoader'
|
3
|
+
import Canvas from '../Canvas'
|
4
|
+
import GL from '../GL'
|
5
|
+
import { format } from './formatter'
|
6
|
+
|
7
|
+
export function palette(colors, k = 6, exportFormat = 'hex') {
|
8
|
+
|
9
|
+
if (colors.length > k) {
|
10
|
+
colors = kmeans(colors, k);
|
11
|
+
}
|
12
|
+
|
13
|
+
return colors.map(c => {
|
14
|
+
return format(c, exportFormat);
|
15
|
+
});
|
16
|
+
}
|
17
|
+
|
18
|
+
export function ImageToRGB(url, callbackOrOption = {}, callback) {
|
19
|
+
|
20
|
+
if (!callback) {
|
21
|
+
var img = new ImageLoader(url);
|
22
|
+
img.loadImage(() => {
|
23
|
+
if (typeof callbackOrOption == 'function') {
|
24
|
+
callbackOrOption(img.toRGB());
|
25
|
+
}
|
26
|
+
|
27
|
+
})
|
28
|
+
} else if (callback) {
|
29
|
+
var img = new ImageLoader(url, callbackOrOption);
|
30
|
+
img.loadImage(() => {
|
31
|
+
if (typeof callback == 'function') {
|
32
|
+
callback(img.toRGB());
|
33
|
+
}
|
34
|
+
|
35
|
+
})
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
export function ImageToCanvas (url, filter, callback, opt = { frameTimer: 'full' }) {
|
40
|
+
ImageToURL(url, filter, callback, Object.assign({
|
41
|
+
returnTo: 'canvas'
|
42
|
+
}, opt))
|
43
|
+
}
|
44
|
+
|
45
|
+
export function ImageToURL(url, filter, callback, opt = { frameTimer : 'full'}) {
|
46
|
+
var img = new ImageLoader(url);
|
47
|
+
img.loadImage(() => {
|
48
|
+
img.toArray(filter, function (datauri) {
|
49
|
+
if (typeof callback == 'function') {
|
50
|
+
callback(datauri)
|
51
|
+
}
|
52
|
+
}, opt);
|
53
|
+
})
|
54
|
+
}
|
55
|
+
|
56
|
+
export function GLToCanvas (url, filter, callback, opt = {}) {
|
57
|
+
var img = new ImageLoader(url);
|
58
|
+
img.load(() => {
|
59
|
+
GL.filter(img.newImage, filter, function done (datauri) {
|
60
|
+
if (typeof callback == 'function') {
|
61
|
+
callback(datauri)
|
62
|
+
}
|
63
|
+
}, opt)
|
64
|
+
})
|
65
|
+
}
|
66
|
+
|
67
|
+
export function histogram (url, callback, opt = {}) {
|
68
|
+
var img = new ImageLoader(url);
|
69
|
+
img.loadImage(() => {
|
70
|
+
if (typeof callback == 'function') {
|
71
|
+
callback(img.toHistogram(opt));
|
72
|
+
}
|
73
|
+
})
|
74
|
+
}
|
75
|
+
|
76
|
+
export function histogramToPoints (points, tension = 0.2) {
|
77
|
+
|
78
|
+
var controlPoints = [];
|
79
|
+
for(let i = 0; i < points.length; i++) {
|
80
|
+
var p = points[i]
|
81
|
+
if (i == 0) {
|
82
|
+
controlPoints[i] = []
|
83
|
+
continue;
|
84
|
+
}
|
85
|
+
|
86
|
+
if (i == points.length - 1) {
|
87
|
+
controlPoints[i] = []
|
88
|
+
continue;
|
89
|
+
}
|
90
|
+
|
91
|
+
var prevPoint = points[i-1]
|
92
|
+
var nextPoint = points[i+1]
|
93
|
+
|
94
|
+
// 기울기
|
95
|
+
var M = (nextPoint[1] - prevPoint[1]) / (nextPoint[0] - prevPoint[0])
|
96
|
+
|
97
|
+
var newControlPoint = [
|
98
|
+
prevPoint[0] + (nextPoint[0] - prevPoint[0]) * tension,
|
99
|
+
prevPoint[1] + (nextPoint[1] - prevPoint[1]) * tension
|
100
|
+
]
|
101
|
+
|
102
|
+
var controlPoint = [
|
103
|
+
[...prevPoint], /* start */
|
104
|
+
[...newControlPoint] /* end */
|
105
|
+
]
|
106
|
+
|
107
|
+
var P = Math.sqrt(Math.pow((p[0] - prevPoint[0]), 2) + Math.pow((p[1] - prevPoint[1]), 2))
|
108
|
+
var N = Math.sqrt(Math.pow((nextPoint[0] - p[0]), 2) + Math.pow((nextPoint[1] - p[1]), 2))
|
109
|
+
|
110
|
+
var rate = P / N
|
111
|
+
|
112
|
+
var dx = controlPoint[0][0] + (controlPoint[1][0] - controlPoint[0][0] ) * rate
|
113
|
+
var dy = controlPoint[0][1] + (controlPoint[1][1] - controlPoint[0][1] ) * rate
|
114
|
+
|
115
|
+
controlPoint[0][0] += p[0] - dx
|
116
|
+
controlPoint[0][1] += p[1] - dy
|
117
|
+
controlPoint[1][0] += p[0] - dx
|
118
|
+
controlPoint[1][1] += p[1] - dy
|
119
|
+
|
120
|
+
controlPoints[i] = controlPoint
|
121
|
+
}
|
122
|
+
|
123
|
+
return controlPoints
|
124
|
+
}
|
125
|
+
|
126
|
+
export function ImageToHistogram(url, callback, opt = { width: 200, height: 100 }) {
|
127
|
+
|
128
|
+
var img = new ImageLoader(url);
|
129
|
+
img.loadImage(() => {
|
130
|
+
Canvas.createHistogram (opt.width || 200, opt.height || 100, img.toHistogram(opt), function (canvas) {
|
131
|
+
if (typeof callback == 'function') callback(canvas.toDataURL('image/png'));
|
132
|
+
}, opt)
|
133
|
+
})
|
134
|
+
}
|
135
|
+
|
136
|
+
export default {
|
137
|
+
palette,
|
138
|
+
ImageToCanvas,
|
139
|
+
ImageToHistogram,
|
140
|
+
ImageToRGB,
|
141
|
+
ImageToURL,
|
142
|
+
GLToCanvas,
|
143
|
+
histogram,
|
144
|
+
histogramToPoints
|
145
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
export function round (n, k) {
|
2
|
+
k = typeof k == 'undefined' ? 1 : k;
|
3
|
+
return Math.round(n * k) / k;
|
4
|
+
}
|
5
|
+
|
6
|
+
|
7
|
+
export function degreeToRadian (angle) {
|
8
|
+
return angle * Math.PI / 180;
|
9
|
+
}
|
10
|
+
|
11
|
+
/**
|
12
|
+
*
|
13
|
+
* convert radian to degree
|
14
|
+
*
|
15
|
+
* @param {*} radian
|
16
|
+
* @returns {Number} 0..360
|
17
|
+
*/
|
18
|
+
export function radianToDegree(radian) {
|
19
|
+
var angle = radian * 180 / Math.PI;
|
20
|
+
|
21
|
+
|
22
|
+
if (angle < 0) { // 각도가 0보다 작으면 360 에서 반전시킨다.
|
23
|
+
angle = 360 + angle
|
24
|
+
}
|
25
|
+
|
26
|
+
return angle;
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
export function getXInCircle (angle, radius, centerX = 0) {
|
31
|
+
return centerX + radius * Math.cos(degreeToRadian (angle))
|
32
|
+
}
|
33
|
+
|
34
|
+
export function getYInCircle (angle, radius, centerY = 0) {
|
35
|
+
return centerY + radius * Math.sin(degreeToRadian(angle))
|
36
|
+
}
|
37
|
+
|
38
|
+
export function getXYInCircle (angle, radius, centerX = 0, centerY = 0) {
|
39
|
+
return {
|
40
|
+
x : getXInCircle(angle, radius, centerX),
|
41
|
+
y : getYInCircle(angle, radius, centerY)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
export function caculateAngle (rx, ry) {
|
46
|
+
return radianToDegree(Math.atan2(ry, rx))
|
47
|
+
}
|
48
|
+
|
49
|
+
export default {
|
50
|
+
round,
|
51
|
+
radianToDegree,
|
52
|
+
degreeToRadian,
|
53
|
+
getXInCircle,
|
54
|
+
getYInCircle,
|
55
|
+
caculateAngle
|
56
|
+
}
|
@@ -0,0 +1,164 @@
|
|
1
|
+
import { parse, convertMatchesArray, parseGradient } from './parser'
|
2
|
+
import { round } from './math'
|
3
|
+
import { format } from './formatter'
|
4
|
+
import { RGBtoHSV } from './fromRGB'
|
5
|
+
import { HSVtoRGB } from './fromHSV'
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @deprecated
|
9
|
+
*
|
10
|
+
* instead of this, use blend function
|
11
|
+
*
|
12
|
+
* @param {*} startColor
|
13
|
+
* @param {*} endColor
|
14
|
+
* @param {*} t
|
15
|
+
*/
|
16
|
+
export function interpolateRGB(startColor, endColor, t = 0.5, exportFormat = 'hex') {
|
17
|
+
var obj = {
|
18
|
+
r: round(startColor.r + (endColor.r - startColor.r) * t),
|
19
|
+
g: round(startColor.g + (endColor.g - startColor.g) * t),
|
20
|
+
b: round(startColor.b + (endColor.b - startColor.b) * t),
|
21
|
+
a: round(startColor.a + (endColor.a - startColor.a) * t, 100 )
|
22
|
+
};
|
23
|
+
|
24
|
+
return format(obj, obj.a < 1 ? 'rgb' : exportFormat);
|
25
|
+
|
26
|
+
}
|
27
|
+
|
28
|
+
export function scale(scale, count = 5) {
|
29
|
+
if (!scale) return [];
|
30
|
+
|
31
|
+
if (typeof scale === 'string') {
|
32
|
+
scale = convertMatchesArray(scale);
|
33
|
+
}
|
34
|
+
|
35
|
+
scale = scale || [];
|
36
|
+
var len = scale.length;
|
37
|
+
|
38
|
+
var colors = [];
|
39
|
+
for (var i = 0; i < len - 1; i++) {
|
40
|
+
for (var index = 0; index < count; index++) {
|
41
|
+
colors.push(blend(scale[i], scale[i + 1], (index / count)));
|
42
|
+
}
|
43
|
+
|
44
|
+
}
|
45
|
+
return colors;
|
46
|
+
}
|
47
|
+
|
48
|
+
export function blend(startColor, endColor, ratio = 0.5, format = 'hex') {
|
49
|
+
var s = parse(startColor);
|
50
|
+
var e = parse(endColor);
|
51
|
+
|
52
|
+
return interpolateRGB(s, e, ratio, format);
|
53
|
+
}
|
54
|
+
|
55
|
+
export function mix(startcolor, endColor, ratio = 0.5, format = 'hex') {
|
56
|
+
return blend(startcolor, endColor, ratio, format);
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
*
|
61
|
+
* @param {Color|String} c
|
62
|
+
*/
|
63
|
+
export function contrast(c) {
|
64
|
+
c = parse(c);
|
65
|
+
return (Math.round(c.r * 299) + Math.round(c.g * 587) + Math.round(c.b * 114)) / 1000;
|
66
|
+
}
|
67
|
+
|
68
|
+
export function contrastColor (c) {
|
69
|
+
return contrast(c) >= 128 ? 'black' : 'white'
|
70
|
+
}
|
71
|
+
|
72
|
+
export function gradient(colors, count = 10) {
|
73
|
+
colors = parseGradient(colors);
|
74
|
+
|
75
|
+
let newColors = []
|
76
|
+
let maxCount = count - (colors.length - 1)
|
77
|
+
let allCount = maxCount
|
78
|
+
|
79
|
+
for (var i = 1, len = colors.length; i < len; i++) {
|
80
|
+
|
81
|
+
var startColor = colors[i-1][0]
|
82
|
+
var endColor = colors[i][0]
|
83
|
+
|
84
|
+
// if it is second color
|
85
|
+
var rate = i == 1 ? colors[i][1] : colors[i][1] - colors[i-1][1]
|
86
|
+
|
87
|
+
// if it is last color
|
88
|
+
var colorCount = (i == colors.length - 1) ? allCount : Math.floor(rate * maxCount)
|
89
|
+
|
90
|
+
newColors = newColors.concat(scale([startColor, endColor], colorCount), [endColor])
|
91
|
+
|
92
|
+
allCount -= colorCount
|
93
|
+
}
|
94
|
+
return newColors;
|
95
|
+
}
|
96
|
+
|
97
|
+
export function scaleHSV(color, target = 'h', count = 9, exportFormat = 'rgb', min = 0, max = 1, dist = 100) {
|
98
|
+
var colorObj = parse(color);
|
99
|
+
var hsv = RGBtoHSV(colorObj);
|
100
|
+
var unit = ((max - min) * dist / count);
|
101
|
+
|
102
|
+
var results = [];
|
103
|
+
for (var i = 1; i <= count; i++) {
|
104
|
+
hsv[target] = Math.abs((dist - unit * i) / dist);
|
105
|
+
results.push(format(HSVtoRGB(hsv), exportFormat));
|
106
|
+
}
|
107
|
+
|
108
|
+
return results;
|
109
|
+
}
|
110
|
+
|
111
|
+
export function scaleH(color, count = 9, exportFormat = 'rgb', min = 0, max = 360) {
|
112
|
+
return scaleHSV(color, 'h', count, exportFormat, min, max, 1);
|
113
|
+
}
|
114
|
+
|
115
|
+
export function scaleS(color, count = 9, exportFormat = 'rgb', min = 0, max = 1) {
|
116
|
+
return scaleHSV(color, 's', count, exportFormat, min, max, 100);
|
117
|
+
}
|
118
|
+
|
119
|
+
export function scaleV(color, count = 9, exportFormat = 'rgb', min = 0, max = 1) {
|
120
|
+
return scaleHSV(color, 'v', count, exportFormat, min, max, 100);
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
/* predefined scale colors */
|
125
|
+
scale.parula = function (count) {
|
126
|
+
return scale(['#352a87', '#0f5cdd', '#00b5a6', '#ffc337', '#fdff00'], count);
|
127
|
+
};
|
128
|
+
|
129
|
+
scale.jet = function (count) {
|
130
|
+
return scale(['#00008f', '#0020ff', '#00ffff', '#51ff77', '#fdff00', '#ff0000', '#800000'], count);
|
131
|
+
}
|
132
|
+
|
133
|
+
scale.hsv = function (count) {
|
134
|
+
return scale(['#ff0000', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#ff00ff', '#ff0000'], count);
|
135
|
+
}
|
136
|
+
|
137
|
+
scale.hot = function (count) {
|
138
|
+
return scale(['#0b0000', '#ff0000', '#ffff00', '#ffffff'], count);
|
139
|
+
}
|
140
|
+
scale.pink = function (count) {
|
141
|
+
return scale(['#1e0000', '#bd7b7b', '#e7e5b2', '#ffffff'], count);
|
142
|
+
}
|
143
|
+
|
144
|
+
scale.bone = function (count) {
|
145
|
+
return scale(['#000000', '#4a4a68', '#a6c6c6', '#ffffff'], count);
|
146
|
+
}
|
147
|
+
|
148
|
+
scale.copper = function (count) {
|
149
|
+
return scale(['#000000', '#3d2618', '#9d623e', '#ffa167', '#ffc77f'], count);
|
150
|
+
}
|
151
|
+
|
152
|
+
export default {
|
153
|
+
interpolateRGB,
|
154
|
+
blend,
|
155
|
+
mix,
|
156
|
+
scale,
|
157
|
+
contrast,
|
158
|
+
contrastColor,
|
159
|
+
gradient,
|
160
|
+
scaleHSV,
|
161
|
+
scaleH,
|
162
|
+
scaleS,
|
163
|
+
scaleV
|
164
|
+
}
|