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,404 @@
|
|
1
|
+
import Dom from '../util/Dom'
|
2
|
+
import ColorSetsList from './module/ColorSetsList'
|
3
|
+
import UIElement from './UIElement'
|
4
|
+
import ColorManager from './module/ColorManager';
|
5
|
+
import BaseStore from './BaseStore';
|
6
|
+
|
7
|
+
export default class BaseColorPicker extends UIElement {
|
8
|
+
|
9
|
+
constructor (opt) {
|
10
|
+
super(opt);
|
11
|
+
|
12
|
+
this.isColorPickerShow = false;
|
13
|
+
this.isShortCut = false;
|
14
|
+
this.hideDelay = +(typeof this.opt.hideDeplay == 'undefined' ? 2000 : this.opt.hideDelay);
|
15
|
+
this.timerCloseColorPicker;
|
16
|
+
this.autoHide = this.opt.autoHide || true;
|
17
|
+
this.outputFormat = this.opt.outputFormat
|
18
|
+
this.$checkColorPickerClass = this.checkColorPickerClass.bind(this);
|
19
|
+
|
20
|
+
}
|
21
|
+
|
22
|
+
initialize () {
|
23
|
+
this.$body = null;
|
24
|
+
this.$root = null;
|
25
|
+
|
26
|
+
this.$store = new BaseStore({
|
27
|
+
modules: [
|
28
|
+
ColorManager,
|
29
|
+
ColorSetsList
|
30
|
+
]
|
31
|
+
});
|
32
|
+
|
33
|
+
this.callbackChange = () => {
|
34
|
+
this.callbackColorValue()
|
35
|
+
}
|
36
|
+
|
37
|
+
this.callbackLastUpdate = () => {
|
38
|
+
this.callbackLastUpdateColorValue()
|
39
|
+
}
|
40
|
+
|
41
|
+
this.colorpickerShowCallback = function () { };
|
42
|
+
this.colorpickerHideCallback = function () { };
|
43
|
+
this.colorpickerLastUpdateCallback = function () { };
|
44
|
+
|
45
|
+
|
46
|
+
this.$body = new Dom(this.getContainer());
|
47
|
+
this.$root = new Dom('div', this.opt.containerClass);
|
48
|
+
|
49
|
+
// append colorpicker to container (ex : body)
|
50
|
+
if (this.opt.position == 'inline') {
|
51
|
+
this.$body.append(this.$root);
|
52
|
+
}
|
53
|
+
|
54
|
+
if (this.opt.type) { // to change css style
|
55
|
+
this.$root.addClass(this.opt.type);
|
56
|
+
}
|
57
|
+
|
58
|
+
if (this.opt.hideInformation) {
|
59
|
+
this.$root.addClass('hide-information')
|
60
|
+
}
|
61
|
+
|
62
|
+
if (this.opt.hideColorsets) {
|
63
|
+
this.$root.addClass('hide-colorsets')
|
64
|
+
}
|
65
|
+
|
66
|
+
this.$arrow = new Dom('div', 'arrow');
|
67
|
+
|
68
|
+
this.$root.append(this.$arrow);
|
69
|
+
|
70
|
+
this.$store.dispatch('/setUserPalette', this.opt.colorSets);
|
71
|
+
|
72
|
+
this.render()
|
73
|
+
|
74
|
+
this.$root.append(this.$el)
|
75
|
+
|
76
|
+
this.initColorWithoutChangeEvent(this.opt.color);
|
77
|
+
|
78
|
+
// 이벤트 연결
|
79
|
+
this.initializeEvent();
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
initColorWithoutChangeEvent (color) {
|
84
|
+
this.$store.dispatch('/initColor', color);
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* public method
|
89
|
+
*
|
90
|
+
*/
|
91
|
+
|
92
|
+
/**
|
93
|
+
*
|
94
|
+
* show colorpicker with position
|
95
|
+
*
|
96
|
+
* @param {{left, top, hideDelay, isShortCut}} opt
|
97
|
+
* @param {String|Object} color
|
98
|
+
* @param {Function} showCallback it is called when colorpicker is shown
|
99
|
+
* @param {Function} hideCallback it is called once when colorpicker is hidden
|
100
|
+
*/
|
101
|
+
show(opt, color, showCallback, hideCallback, lastUpdateCallback) {
|
102
|
+
|
103
|
+
// 매번 이벤트를 지우고 다시 생성할 필요가 없어서 초기화 코드는 지움.
|
104
|
+
// this.destroy();
|
105
|
+
// this.initializeEvent();
|
106
|
+
// define colorpicker callback
|
107
|
+
this.colorpickerShowCallback = showCallback;
|
108
|
+
this.colorpickerHideCallback = hideCallback;
|
109
|
+
this.colorpickerLastUpdateCallback = lastUpdateCallback;
|
110
|
+
this.$root.css(this.getInitalizePosition()).show();
|
111
|
+
|
112
|
+
|
113
|
+
this.isColorPickerShow = true;
|
114
|
+
this.isShortCut = opt.isShortCut || false;
|
115
|
+
this.outputFormat = opt.outputFormat
|
116
|
+
|
117
|
+
// define hide delay
|
118
|
+
this.hideDelay = +(typeof opt.hideDelay == 'undefined' ? 2000 : opt.hideDelay );
|
119
|
+
if (this.hideDelay > 0) {
|
120
|
+
this.setHideDelay(this.hideDelay);
|
121
|
+
}
|
122
|
+
|
123
|
+
this.$root.appendTo(this.$body);
|
124
|
+
this.definePosition(opt);
|
125
|
+
this.initColorWithoutChangeEvent(color);
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
*
|
130
|
+
* initialize color for colorpicker
|
131
|
+
*
|
132
|
+
* @param {String|Object} newColor
|
133
|
+
* @param {String} format hex, rgb, hsl
|
134
|
+
*/
|
135
|
+
initColor(newColor, format) {
|
136
|
+
this.$store.dispatch('/changeColor', newColor, format);
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
/**
|
141
|
+
* hide colorpicker
|
142
|
+
*
|
143
|
+
*/
|
144
|
+
hide() {
|
145
|
+
if (this.isColorPickerShow) {
|
146
|
+
// this.destroy();
|
147
|
+
this.$root.hide();
|
148
|
+
this.$root.remove(); // not empty
|
149
|
+
this.isColorPickerShow = false;
|
150
|
+
|
151
|
+
this.callbackHideColorValue()
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* set to colors in current sets that you see
|
157
|
+
* @param {Array} colors
|
158
|
+
*/
|
159
|
+
setColorsInPalette (colors = []) {
|
160
|
+
this.$store.dispatch('/setCurrentColorAll', colors);
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* refresh all color palette
|
165
|
+
*
|
166
|
+
* @param {*} list
|
167
|
+
*/
|
168
|
+
setUserPalette (list = []) {
|
169
|
+
this.$store.dispatch('/setUserPalette', list);
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
/**
|
174
|
+
* private method
|
175
|
+
*/
|
176
|
+
|
177
|
+
getOption(key) {
|
178
|
+
return this.opt[key];
|
179
|
+
}
|
180
|
+
|
181
|
+
setOption (key, value) {
|
182
|
+
this.opt[key] = value;
|
183
|
+
}
|
184
|
+
|
185
|
+
isType (key) {
|
186
|
+
return this.getOption('type') == key;
|
187
|
+
}
|
188
|
+
|
189
|
+
isPaletteType() {
|
190
|
+
return this.isType('palette');
|
191
|
+
}
|
192
|
+
|
193
|
+
isSketchType() {
|
194
|
+
return this.isType('sketch');
|
195
|
+
}
|
196
|
+
|
197
|
+
getContainer () {
|
198
|
+
return this.opt.container || document.body;
|
199
|
+
}
|
200
|
+
|
201
|
+
getColor(type) {
|
202
|
+
return this.$store.dispatch('/toColor', type);
|
203
|
+
}
|
204
|
+
|
205
|
+
definePositionForArrow(opt, elementScreenLeft, elementScreenTop) {
|
206
|
+
// console.log(arguments)
|
207
|
+
}
|
208
|
+
|
209
|
+
definePosition(opt) {
|
210
|
+
|
211
|
+
var width = this.$root.width();
|
212
|
+
var height = this.$root.height();
|
213
|
+
|
214
|
+
// set left position for color picker
|
215
|
+
var elementScreenLeft = opt.left - this.$body.scrollLeft();
|
216
|
+
if (width + elementScreenLeft > window.innerWidth) {
|
217
|
+
elementScreenLeft -= (width + elementScreenLeft) - window.innerWidth;
|
218
|
+
}
|
219
|
+
if (elementScreenLeft < 0) { elementScreenLeft = 0; }
|
220
|
+
|
221
|
+
// set top position for color picker
|
222
|
+
var elementScreenTop = opt.top - this.$body.scrollTop();
|
223
|
+
var elementScreenBottom = opt.bottom - this.$body.scrollTop();
|
224
|
+
if (height / 2 + elementScreenBottom > window.innerHeight) {
|
225
|
+
elementScreenTop = elementScreenTop - height + this.$body.scrollTop();
|
226
|
+
} else {
|
227
|
+
elementScreenTop = elementScreenBottom + this.$body.scrollTop() + 1;
|
228
|
+
}
|
229
|
+
if (elementScreenTop < 0) { elementScreenTop = 0; }
|
230
|
+
|
231
|
+
// set position
|
232
|
+
this.$root.css({
|
233
|
+
left: (elementScreenLeft) + 'px',
|
234
|
+
top: (elementScreenTop) + 'px'
|
235
|
+
});
|
236
|
+
|
237
|
+
// this.definePositionForArrow(opt, elementScreenLeft, elementScreenTop);
|
238
|
+
}
|
239
|
+
|
240
|
+
getInitalizePosition() {
|
241
|
+
if (this.opt.position == 'inline') {
|
242
|
+
return {
|
243
|
+
position: 'relative',
|
244
|
+
left: 'auto',
|
245
|
+
top: 'auto',
|
246
|
+
display: 'inline-block'
|
247
|
+
}
|
248
|
+
} else {
|
249
|
+
return {
|
250
|
+
position: 'absolute', // color picker has fixed position
|
251
|
+
left: '-10000px',
|
252
|
+
top: '-10000px'
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
isAbsolute () {
|
258
|
+
return this.opt.position !== 'inline'
|
259
|
+
}
|
260
|
+
|
261
|
+
// Event Bindings
|
262
|
+
'mouseup.isAbsolute document' (e) {
|
263
|
+
|
264
|
+
this.__isMouseDown = false;
|
265
|
+
// when color picker clicked in outside
|
266
|
+
if (this.checkInHtml(e.target)) {
|
267
|
+
//this.setHideDelay(hideDelay);
|
268
|
+
} else if (this.checkColorPickerClass(e.target) == false) {
|
269
|
+
this.hide();
|
270
|
+
} else {
|
271
|
+
if (!this.__isMouseIn) {
|
272
|
+
clearTimeout(this.timerCloseColorPicker);
|
273
|
+
this.timerCloseColorPicker = setTimeout(this.hide.bind(this), this.delayTime || this.hideDelay);
|
274
|
+
}
|
275
|
+
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
'keyup.isAbsolute.escape $root' (e) {
|
280
|
+
this.hide();
|
281
|
+
}
|
282
|
+
|
283
|
+
'mouseover.isAbsolute $root' (e) {
|
284
|
+
clearTimeout(this.timerCloseColorPicker);
|
285
|
+
// this.__isMouseDown = true;
|
286
|
+
}
|
287
|
+
|
288
|
+
'mousemove.isAbsolute $root' (e) {
|
289
|
+
clearTimeout(this.timerCloseColorPicker)
|
290
|
+
}
|
291
|
+
|
292
|
+
'mouseenter.isAbsolute $root' (e) {
|
293
|
+
clearTimeout(this.timerCloseColorPicker);
|
294
|
+
this.__isMouseIn = true;
|
295
|
+
}
|
296
|
+
|
297
|
+
'mouseleave.isAbsolute $root' (e) {
|
298
|
+
this.__isMouseIn = false;
|
299
|
+
if (!this.__isMouseDown) {
|
300
|
+
clearTimeout(this.timerCloseColorPicker);
|
301
|
+
this.timerCloseColorPicker = setTimeout(this.hide.bind(this), this.delayTime || this.hideDelay);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
'mousedown.isAbsolute $root' (e) {
|
306
|
+
this.__isMouseDown = true;
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
setHideDelay(delayTime) {
|
311
|
+
this.delayTime = delayTime || 0;
|
312
|
+
}
|
313
|
+
|
314
|
+
runHideDelay () {
|
315
|
+
|
316
|
+
if (this.isColorPickerShow) {
|
317
|
+
this.setHideDelay();
|
318
|
+
// const hideCallback = this.setHideDelay(delayTime);
|
319
|
+
|
320
|
+
// this.timerCloseColorPicker = setTimeout(hideCallback, delayTime);
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
callbackColorValue(color) {
|
326
|
+
color = color || this.getCurrentColor();
|
327
|
+
|
328
|
+
if (typeof this.opt.onChange == 'function') {
|
329
|
+
this.opt.onChange.call(this, color);
|
330
|
+
}
|
331
|
+
|
332
|
+
if (typeof this.colorpickerShowCallback == 'function') {
|
333
|
+
this.colorpickerShowCallback(color);
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
callbackLastUpdateColorValue(color) {
|
338
|
+
color = color || this.getCurrentColor();
|
339
|
+
|
340
|
+
if (typeof this.opt.onLastUpdate == 'function') {
|
341
|
+
this.opt.onLastUpdate.call(this, color);
|
342
|
+
}
|
343
|
+
|
344
|
+
if (typeof this.colorpickerLastUpdateCallback == 'function') {
|
345
|
+
this.colorpickerLastUpdateCallback(color);
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
callbackHideColorValue(color) {
|
351
|
+
color = color || this.getCurrentColor();
|
352
|
+
if (typeof this.opt.onHide == 'function') {
|
353
|
+
this.opt.onHide.call(this, color);
|
354
|
+
}
|
355
|
+
|
356
|
+
if (typeof this.colorpickerHideCallback == 'function') {
|
357
|
+
this.colorpickerHideCallback(color);
|
358
|
+
}
|
359
|
+
}
|
360
|
+
|
361
|
+
getCurrentColor() {
|
362
|
+
return this.$store.dispatch('/toColor', this.outputFormat);
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
checkColorPickerClass(el) {
|
367
|
+
var hasColorView = new Dom(el).closest('ace-colorview');
|
368
|
+
var hasColorPicker = new Dom(el).closest('ace-colorpicker');
|
369
|
+
|
370
|
+
return !!(hasColorPicker || hasColorView);
|
371
|
+
}
|
372
|
+
|
373
|
+
checkInHtml(el) {
|
374
|
+
var IsInHtml = el.nodeName == 'HTML';
|
375
|
+
|
376
|
+
return IsInHtml;
|
377
|
+
}
|
378
|
+
|
379
|
+
initializeStoreEvent () {
|
380
|
+
super.initializeStoreEvent()
|
381
|
+
|
382
|
+
this.$store.on('changeColor', this.callbackChange)
|
383
|
+
this.$store.on('lastUpdateColor', this.callbackLastUpdate)
|
384
|
+
this.$store.on('changeFormat', this.callbackChange)
|
385
|
+
}
|
386
|
+
|
387
|
+
destroy() {
|
388
|
+
super.destroy();
|
389
|
+
|
390
|
+
this.$store.off('changeColor', this.callbackChange);
|
391
|
+
this.$store.off('lastUpdateColor', this.callbackLastUpdate)
|
392
|
+
this.$store.off('changeFormat', this.callbackChange);
|
393
|
+
|
394
|
+
this.callbackChange = undefined;
|
395
|
+
this.callbackLastUpdate = undefined;
|
396
|
+
|
397
|
+
// remove color picker callback
|
398
|
+
this.colorpickerShowCallback = undefined;
|
399
|
+
this.colorpickerHideCallback = undefined;
|
400
|
+
}
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export default class BaseModule {
|
2
|
+
constructor ($store) {
|
3
|
+
this.$store = $store;
|
4
|
+
this.initialize();
|
5
|
+
}
|
6
|
+
|
7
|
+
initialize() {
|
8
|
+
this.filterProps().forEach(key => {
|
9
|
+
this.$store.action(key, this);
|
10
|
+
});
|
11
|
+
}
|
12
|
+
|
13
|
+
filterProps (pattern = '/') {
|
14
|
+
return Object.getOwnPropertyNames(this.__proto__).filter(key => {
|
15
|
+
return key.startsWith(pattern);
|
16
|
+
});
|
17
|
+
}
|
18
|
+
|
19
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
import Event from '../util/Event'
|
3
|
+
import BaseBox from './BaseBox';
|
4
|
+
|
5
|
+
export default class BaseSlider extends BaseBox {
|
6
|
+
|
7
|
+
constructor (opt) {
|
8
|
+
super(opt)
|
9
|
+
|
10
|
+
this.minValue = 0 // min domain value
|
11
|
+
this.maxValue = 1 // max domain value
|
12
|
+
this.source = 'base-slider'
|
13
|
+
}
|
14
|
+
|
15
|
+
/* slider container's min and max position */
|
16
|
+
getMinMaxPosition () {
|
17
|
+
var min = this.getMinPosition();
|
18
|
+
var width = this.getMaxDist()
|
19
|
+
var max = min + width;
|
20
|
+
|
21
|
+
return { min, max, width }
|
22
|
+
}
|
23
|
+
|
24
|
+
/** get current position on page */
|
25
|
+
getCurrent (value) {
|
26
|
+
return min + this.getMaxDist() * value;
|
27
|
+
}
|
28
|
+
|
29
|
+
/** get min position on slider container */
|
30
|
+
getMinPosition () {
|
31
|
+
return this.refs.$container.offset().left;
|
32
|
+
}
|
33
|
+
|
34
|
+
getMaxDist () {
|
35
|
+
return this.state.get('$container.width');
|
36
|
+
}
|
37
|
+
|
38
|
+
/** get dist for position value */
|
39
|
+
getDist (current) {
|
40
|
+
var {min, max} = this.getMinMaxPosition()
|
41
|
+
|
42
|
+
var dist;
|
43
|
+
if (current < min) {
|
44
|
+
dist = 0;
|
45
|
+
} else if (current > max) {
|
46
|
+
dist = 100;
|
47
|
+
} else {
|
48
|
+
dist = (current - min) / (max - min) * 100;
|
49
|
+
}
|
50
|
+
|
51
|
+
return dist;
|
52
|
+
}
|
53
|
+
|
54
|
+
/** get caculated dist for domain value */
|
55
|
+
getCaculatedDist (e) {
|
56
|
+
var current = e ? this.getMousePosition(e) : this.getCurrent(this.getDefaultValue() / this.maxValue);
|
57
|
+
var dist = this.getDist(current);
|
58
|
+
|
59
|
+
return dist;
|
60
|
+
}
|
61
|
+
|
62
|
+
/** get default value used in slider container */
|
63
|
+
getDefaultValue () {
|
64
|
+
return 0
|
65
|
+
}
|
66
|
+
|
67
|
+
/** set mosue position */
|
68
|
+
setMousePosition (x) {
|
69
|
+
this.refs.$bar.css({ left : (x) + 'px' });
|
70
|
+
}
|
71
|
+
|
72
|
+
/** set mouse position in page */
|
73
|
+
getMousePosition (e) {
|
74
|
+
return Event.pos(e).pageX;
|
75
|
+
}
|
76
|
+
|
77
|
+
refresh () {
|
78
|
+
this.setColorUI()
|
79
|
+
}
|
80
|
+
|
81
|
+
/** set drag bar position */
|
82
|
+
setColorUI(v) {
|
83
|
+
|
84
|
+
v = v || this.getDefaultValue();
|
85
|
+
|
86
|
+
if (v <= this.minValue) {
|
87
|
+
this.refs.$bar.addClass('first').removeClass('last')
|
88
|
+
} else if (v >= this.maxValue) {
|
89
|
+
this.refs.$bar.addClass('last').removeClass('first')
|
90
|
+
} else {
|
91
|
+
this.refs.$bar.removeClass('last').removeClass('first')
|
92
|
+
}
|
93
|
+
|
94
|
+
this.setMousePosition(this.getMaxDist() * ( (v || 0) / this.maxValue));
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
export default class BaseStore {
|
2
|
+
constructor (opt) {
|
3
|
+
this.callbacks = []
|
4
|
+
this.actions = []
|
5
|
+
this.modules = opt.modules || []
|
6
|
+
|
7
|
+
this.initialize()
|
8
|
+
}
|
9
|
+
|
10
|
+
initialize () {
|
11
|
+
this.initializeModule();
|
12
|
+
}
|
13
|
+
|
14
|
+
initializeModule () {
|
15
|
+
this.modules.forEach(Module => {
|
16
|
+
var instance = new Module(this);
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
action (action, context) {
|
21
|
+
this.actions[action] = { context, callback: context[action] };
|
22
|
+
}
|
23
|
+
|
24
|
+
dispatch (action) {
|
25
|
+
var args = [...arguments];
|
26
|
+
var action = args.shift();
|
27
|
+
|
28
|
+
var m = this.actions[action];
|
29
|
+
|
30
|
+
if (m) {
|
31
|
+
return m.callback.apply(m.context, [this, ...args]);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
module (ModuleObject) {
|
36
|
+
// this.action()
|
37
|
+
}
|
38
|
+
|
39
|
+
on (event, callback) {
|
40
|
+
this.callbacks.push({ event, callback })
|
41
|
+
}
|
42
|
+
|
43
|
+
off (event, callback) {
|
44
|
+
|
45
|
+
if (arguments.length == 0) {
|
46
|
+
this.callbacks = []
|
47
|
+
} else if (arguments.length == 1) {
|
48
|
+
this.callbacks = this.callbacks.filter(f => {
|
49
|
+
return f.event != event
|
50
|
+
})
|
51
|
+
} else if (arguments.length == 2) {
|
52
|
+
this.callbacks = this.callbacks.filter(f => {
|
53
|
+
return f.event != event && f.callback != callback
|
54
|
+
})
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
emit () {
|
60
|
+
var args = [...arguments];
|
61
|
+
var event = args.shift();
|
62
|
+
|
63
|
+
this.callbacks.filter(f => {
|
64
|
+
return (f.event == event)
|
65
|
+
}).forEach(f => {
|
66
|
+
if (f && typeof f.callback == 'function') {
|
67
|
+
f.callback(...args);
|
68
|
+
}
|
69
|
+
})
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import EventMachin from "../util/EventMachin";
|
2
|
+
|
3
|
+
const CHECK_STORE_EVENT_PATTERN = /^@/
|
4
|
+
|
5
|
+
class UIElement extends EventMachin {
|
6
|
+
constructor (opt) {
|
7
|
+
super(opt)
|
8
|
+
|
9
|
+
this.opt = opt || {};
|
10
|
+
|
11
|
+
if (opt && opt.$store) {
|
12
|
+
this.$store = opt.$store
|
13
|
+
}
|
14
|
+
|
15
|
+
this.initialize();
|
16
|
+
|
17
|
+
this.initializeStoreEvent();
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* initialize store event
|
22
|
+
*
|
23
|
+
* you can define '@xxx' method(event) in UIElement
|
24
|
+
*
|
25
|
+
*
|
26
|
+
*/
|
27
|
+
initializeStoreEvent () {
|
28
|
+
this.storeEvents = {}
|
29
|
+
this.filterProps(CHECK_STORE_EVENT_PATTERN).forEach((key) => {
|
30
|
+
const arr = key.split('@')
|
31
|
+
arr.shift();
|
32
|
+
const event = arr.join('@');
|
33
|
+
|
34
|
+
this.storeEvents[event] = this[key].bind(this)
|
35
|
+
this.$store.on(event, this.storeEvents[event]);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
destoryStoreEvent () {
|
40
|
+
Object.keys(this.storeEvents).forEach(event => {
|
41
|
+
this.$store.off(event, this.storeEvents[event])
|
42
|
+
})
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
export default UIElement
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import Event from '../util/Event'
|
2
|
+
import BaseSlider from "./BaseSlider";
|
3
|
+
|
4
|
+
export default class VerticalSlider extends BaseSlider {
|
5
|
+
|
6
|
+
constructor (opt) {
|
7
|
+
super(opt)
|
8
|
+
|
9
|
+
this.source = 'vertical-slider'
|
10
|
+
}
|
11
|
+
|
12
|
+
/** get max height for vertical slider */
|
13
|
+
getMaxDist () {
|
14
|
+
return this.state.get('$container.height');
|
15
|
+
}
|
16
|
+
|
17
|
+
/** set mouse pointer for vertical slider */
|
18
|
+
setMousePosition (y) {
|
19
|
+
this.refs.$bar.css({ top : (y) + 'px' });
|
20
|
+
}
|
21
|
+
|
22
|
+
/** get mouse position by pageY for vertical slider */
|
23
|
+
getMousePosition (e) {
|
24
|
+
return Event.pos(e).pageY;
|
25
|
+
}
|
26
|
+
|
27
|
+
/** get min position for vertial slider */
|
28
|
+
getMinPosition () {
|
29
|
+
return this.refs.$container.offset().top;
|
30
|
+
}
|
31
|
+
|
32
|
+
/** get caculated dist for domain value */
|
33
|
+
getCaculatedDist (e) {
|
34
|
+
var current = e ? this.getMousePosition(e) : this.getCurrent(this.getDefaultValue() / this.maxValue);
|
35
|
+
var dist = 100 - this.getDist(current);
|
36
|
+
|
37
|
+
return dist;
|
38
|
+
}
|
39
|
+
|
40
|
+
/** set drag bar position */
|
41
|
+
setColorUI(v) {
|
42
|
+
|
43
|
+
v = v || this.getDefaultValue();
|
44
|
+
|
45
|
+
if (v <= this.minValue) {
|
46
|
+
this.refs.$bar.addClass('first').removeClass('last')
|
47
|
+
} else if (v >= this.maxValue) {
|
48
|
+
this.refs.$bar.addClass('last').removeClass('first')
|
49
|
+
} else {
|
50
|
+
this.refs.$bar.removeClass('last').removeClass('first')
|
51
|
+
}
|
52
|
+
|
53
|
+
var per = 1 - ( (v || 0) / this.maxValue);
|
54
|
+
|
55
|
+
this.setMousePosition(this.getMaxDist() * per );
|
56
|
+
}
|
57
|
+
}
|