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,349 @@
|
|
1
|
+
import Event from './Event'
|
2
|
+
import Dom from './Dom'
|
3
|
+
import State from './State'
|
4
|
+
|
5
|
+
const CHECK_EVENT_PATTERN = /^(click|mouse(down|up|move|enter|leave)|touch(start|move|end)|key(down|up|press)|contextmenu|change|input)/ig;
|
6
|
+
const CHECK_LOAD_PATTERN = /^load (.*)/ig;
|
7
|
+
const EVENT_SAPARATOR = ' '
|
8
|
+
const META_KEYS = ['Control', 'Shift', 'Alt', 'Meta'];
|
9
|
+
|
10
|
+
export default class EventMachin {
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
this.state = new State(this);
|
14
|
+
this.refs = {}
|
15
|
+
|
16
|
+
this.childComponents = this.components()
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* 자식으로 사용할 컴포넌트를 생성해준다.
|
21
|
+
* 생성 시점에 $store 객체가 자동으로 공유된다.
|
22
|
+
* 모든 데이타는 $store 기준으로 작성한다.
|
23
|
+
*/
|
24
|
+
newChildComponents () {
|
25
|
+
const childKeys = Object.keys(this.childComponents)
|
26
|
+
childKeys.forEach(key => {
|
27
|
+
const Component = this.childComponents[key]
|
28
|
+
|
29
|
+
this[key] = new Component(this);
|
30
|
+
})
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* 부모가 정의한 template 과 그 안에서 동작하는 자식 컴포넌트들을 다 합쳐서
|
35
|
+
* 최종 element 를 만들어준다.
|
36
|
+
*
|
37
|
+
* 그리고 자동으로 load 되어질게 있으면 로드 해준다.
|
38
|
+
*/
|
39
|
+
render () {
|
40
|
+
// 1. 나의 template 을 만들어내고
|
41
|
+
this.$el = this.parseTemplate(this.template())
|
42
|
+
this.refs.$el = this.$el;
|
43
|
+
|
44
|
+
// 개별 객체 셋팅하고
|
45
|
+
this.parseTarget()
|
46
|
+
|
47
|
+
// 데이타 로드 하고
|
48
|
+
this.load()
|
49
|
+
|
50
|
+
this.afterRender()
|
51
|
+
|
52
|
+
}
|
53
|
+
|
54
|
+
afterRender() { }
|
55
|
+
|
56
|
+
/**
|
57
|
+
* 자식 컴포넌트로 사용될 객체 정의
|
58
|
+
*/
|
59
|
+
components () {
|
60
|
+
return {}
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Class 기반으로 $el 을 생성하기 위해서
|
65
|
+
* 선언형으로 html 템플릿을 정의한다.
|
66
|
+
*
|
67
|
+
* @param {*} html
|
68
|
+
*/
|
69
|
+
parseTemplate (html) {
|
70
|
+
const $el = new Dom("div").html(html).firstChild()
|
71
|
+
|
72
|
+
// ref element 정리
|
73
|
+
var refs = $el.findAll('[ref]');
|
74
|
+
|
75
|
+
[...refs].forEach(node => {
|
76
|
+
const name = node.getAttribute('ref')
|
77
|
+
this.refs[name] = new Dom(node);
|
78
|
+
})
|
79
|
+
|
80
|
+
return $el;
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* target 으로 지정된 자식 컴포넌트를 대체해준다.
|
85
|
+
*/
|
86
|
+
parseTarget () {
|
87
|
+
const $el = this.$el;
|
88
|
+
const targets = $el.findAll('[target]');
|
89
|
+
|
90
|
+
[...targets].forEach(node => {
|
91
|
+
const targetComponentName = node.getAttribute('target')
|
92
|
+
const refName = node.getAttribute('ref') || targetComponentName
|
93
|
+
|
94
|
+
var Component = this.childComponents[targetComponentName]
|
95
|
+
var instance = new Component(this);
|
96
|
+
this[refName] = instance
|
97
|
+
this.refs[refName] = instance.$el
|
98
|
+
|
99
|
+
if (instance) {
|
100
|
+
instance.render()
|
101
|
+
var $parent = new Dom(node.parentNode)
|
102
|
+
$parent.replace(node, instance.$el.el)
|
103
|
+
}
|
104
|
+
})
|
105
|
+
}
|
106
|
+
|
107
|
+
// load function이 정의된 객체는 load 를 실행해준다.
|
108
|
+
load () {
|
109
|
+
|
110
|
+
this.filterProps(CHECK_LOAD_PATTERN).forEach(callbackName => {
|
111
|
+
const elName = callbackName.split('load ')[1]
|
112
|
+
|
113
|
+
if (this.refs[elName]) {
|
114
|
+
this.refs[elName].html(this.parseTemplate(this[callbackName].call(this)))
|
115
|
+
}
|
116
|
+
})
|
117
|
+
}
|
118
|
+
|
119
|
+
// 기본 템플릿 지정
|
120
|
+
template () {
|
121
|
+
return '<div></div>';
|
122
|
+
}
|
123
|
+
|
124
|
+
initialize() {
|
125
|
+
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* 이벤트를 초기화한다.
|
130
|
+
*/
|
131
|
+
initializeEvent () {
|
132
|
+
this.initializeEventMachin();
|
133
|
+
|
134
|
+
// 자식 이벤트도 같이 초기화 한다.
|
135
|
+
// 그래서 이 메소드는 부모에서 한번만 불려도 된다.
|
136
|
+
Object.keys(this.childComponents).forEach(key => {
|
137
|
+
if (this[key]) this[key].initializeEvent()
|
138
|
+
})
|
139
|
+
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* 자원을 해제한다.
|
144
|
+
* 이것도 역시 자식 컴포넌트까지 제어하기 때문에 가장 최상위 부모에서 한번만 호출되도 된다.
|
145
|
+
*/
|
146
|
+
destroy() {
|
147
|
+
this.destroyEventMachin();
|
148
|
+
// this.refs = {}
|
149
|
+
|
150
|
+
Object.keys(this.childComponents).forEach(key => {
|
151
|
+
if (this[key]) this[key].destroy()
|
152
|
+
})
|
153
|
+
|
154
|
+
}
|
155
|
+
|
156
|
+
destroyEventMachin () {
|
157
|
+
this.removeEventAll();
|
158
|
+
}
|
159
|
+
|
160
|
+
initializeEventMachin () {
|
161
|
+
this.filterProps(CHECK_EVENT_PATTERN).forEach(this.parseEvent.bind(this));
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* property 수집하기
|
166
|
+
* 상위 클래스의 모든 property 를 수집해서 리턴한다.
|
167
|
+
*/
|
168
|
+
collectProps () {
|
169
|
+
|
170
|
+
if (!this.collapsedProps) {
|
171
|
+
var p = this.__proto__
|
172
|
+
var results = []
|
173
|
+
do {
|
174
|
+
results.push(...Object.getOwnPropertyNames(p))
|
175
|
+
p = p.__proto__;
|
176
|
+
} while( p );
|
177
|
+
|
178
|
+
this.collapsedProps = results
|
179
|
+
}
|
180
|
+
|
181
|
+
return this.collapsedProps;
|
182
|
+
}
|
183
|
+
|
184
|
+
filterProps (pattern) {
|
185
|
+
return this.collectProps().filter(key => {
|
186
|
+
return key.match(pattern);
|
187
|
+
});
|
188
|
+
}
|
189
|
+
|
190
|
+
parseEvent (key) {
|
191
|
+
let arr = key.split(EVENT_SAPARATOR) ;
|
192
|
+
|
193
|
+
this.bindingEvent(arr,this[key].bind(this));
|
194
|
+
}
|
195
|
+
|
196
|
+
getDefaultDomElement (dom) {
|
197
|
+
let el;
|
198
|
+
|
199
|
+
if (dom) {
|
200
|
+
el = this.refs[dom] || this[dom] || window[dom];
|
201
|
+
} else {
|
202
|
+
el = this.el || this.$el || this.$root;
|
203
|
+
}
|
204
|
+
|
205
|
+
if (el instanceof Dom) {
|
206
|
+
return el.getElement();
|
207
|
+
}
|
208
|
+
|
209
|
+
return el;
|
210
|
+
}
|
211
|
+
|
212
|
+
getDefaultEventObject (eventName) {
|
213
|
+
let arr = eventName.split('.');
|
214
|
+
const realEventName = arr.shift();
|
215
|
+
|
216
|
+
const isControl = arr.includes('Control');
|
217
|
+
const isShift = arr.includes('Shift');
|
218
|
+
const isAlt = arr.includes('Alt');
|
219
|
+
const isMeta = arr.includes('Meta');
|
220
|
+
|
221
|
+
arr = arr.filter((code) => {
|
222
|
+
return META_KEYS.includes(code) === false;
|
223
|
+
});
|
224
|
+
|
225
|
+
const checkMethodList = arr.filter(code => {
|
226
|
+
return !!this[code];
|
227
|
+
});
|
228
|
+
|
229
|
+
arr = arr.filter(code => {
|
230
|
+
return checkMethodList.includes(code) === false;
|
231
|
+
}).map(code => {
|
232
|
+
return code.toLowerCase()
|
233
|
+
});
|
234
|
+
|
235
|
+
return {
|
236
|
+
eventName : realEventName,
|
237
|
+
isControl,
|
238
|
+
isShift,
|
239
|
+
isAlt,
|
240
|
+
isMeta,
|
241
|
+
codes : arr,
|
242
|
+
checkMethodList: checkMethodList
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
bindingEvent ([ eventName, dom, ...delegate], callback) {
|
247
|
+
dom = this.getDefaultDomElement(dom);
|
248
|
+
let eventObject = this.getDefaultEventObject(eventName);
|
249
|
+
|
250
|
+
eventObject.dom = dom;
|
251
|
+
eventObject.delegate = delegate.join(EVENT_SAPARATOR);
|
252
|
+
|
253
|
+
this.addEvent(eventObject, callback);
|
254
|
+
}
|
255
|
+
|
256
|
+
matchPath(el, selector) {
|
257
|
+
if (el) {
|
258
|
+
if (el.matches(selector)) { return el; }
|
259
|
+
return this.matchPath(el.parentElement, selector);
|
260
|
+
}
|
261
|
+
return null;
|
262
|
+
}
|
263
|
+
|
264
|
+
getBindings () {
|
265
|
+
|
266
|
+
if (!this._bindings) {
|
267
|
+
this.initBindings();
|
268
|
+
}
|
269
|
+
|
270
|
+
return this._bindings;
|
271
|
+
}
|
272
|
+
|
273
|
+
addBinding (obj) {
|
274
|
+
this.getBindings().push(obj);
|
275
|
+
}
|
276
|
+
|
277
|
+
initBindings() {
|
278
|
+
this._bindings = [];
|
279
|
+
}
|
280
|
+
|
281
|
+
checkEventType (e, eventObject ) {
|
282
|
+
var onlyControl = eventObject.isControl ? e.ctrlKey : true;
|
283
|
+
var onlyShift = eventObject.isShift ? e.shiftKey : true;
|
284
|
+
var onlyAlt = eventObject.isAlt ? e.altKey : true;
|
285
|
+
var onlyMeta = eventObject.isMeta ? e.metaKey : true;
|
286
|
+
|
287
|
+
var hasKeyCode = true;
|
288
|
+
if (eventObject.codes.length) {
|
289
|
+
hasKeyCode = eventObject.codes.includes(e.code.toLowerCase()) || eventObject.codes.includes(e.key.toLowerCase());
|
290
|
+
}
|
291
|
+
|
292
|
+
var isAllCheck = true;
|
293
|
+
if (eventObject.checkMethodList.length) { // 체크 메소드들은 모든 메소드를 다 적용해야한다.
|
294
|
+
isAllCheck = eventObject.checkMethodList.every(method => {
|
295
|
+
return this[method].call(this, e);
|
296
|
+
});
|
297
|
+
}
|
298
|
+
|
299
|
+
return (onlyControl && onlyAlt && onlyShift && onlyMeta && hasKeyCode && isAllCheck);
|
300
|
+
}
|
301
|
+
|
302
|
+
makeCallback ( eventObject, callback) {
|
303
|
+
if (eventObject.delegate) {
|
304
|
+
return (e) => {
|
305
|
+
e.xy = Event.posXY(e);
|
306
|
+
if (this.checkEventType(e, eventObject)) {
|
307
|
+
const delegateTarget = this.matchPath(e.target || e.srcElement, eventObject.delegate);
|
308
|
+
|
309
|
+
if (delegateTarget) { // delegate target 이 있는 경우만 callback 실행
|
310
|
+
e.delegateTarget = delegateTarget;
|
311
|
+
e.$delegateTarget = new Dom(delegateTarget);
|
312
|
+
return callback(e);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
}
|
317
|
+
} else {
|
318
|
+
return (e) => {
|
319
|
+
e.xy = Event.posXY(e);
|
320
|
+
if (this.checkEventType(e, eventObject)) {
|
321
|
+
return callback(e);
|
322
|
+
}
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
addEvent(eventObject, callback) {
|
328
|
+
eventObject.callback = this.makeCallback(eventObject, callback)
|
329
|
+
this.addBinding(eventObject);
|
330
|
+
|
331
|
+
var options = true;
|
332
|
+
if (eventObject.eventName === 'touchstart') {
|
333
|
+
options = { passive : true }
|
334
|
+
}
|
335
|
+
|
336
|
+
Event.addEvent(eventObject.dom, eventObject.eventName, eventObject.callback, options)
|
337
|
+
}
|
338
|
+
|
339
|
+
removeEventAll () {
|
340
|
+
this.getBindings().forEach(obj => {
|
341
|
+
this.removeEvent(obj);
|
342
|
+
});
|
343
|
+
this.initBindings();
|
344
|
+
}
|
345
|
+
|
346
|
+
removeEvent({eventName, dom, callback}) {
|
347
|
+
Event.removeEvent(dom, eventName, callback);
|
348
|
+
}
|
349
|
+
}
|
package/src/util/GL.js
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
import Color from './Color';
|
2
|
+
|
3
|
+
const hue_color = [
|
4
|
+
{ rgb : '#ff0000', start : .0 },
|
5
|
+
{ rgb : '#ffff00', start : .17 },
|
6
|
+
{ rgb : '#00ff00', start : .33 },
|
7
|
+
{ rgb : '#00ffff', start : .50 },
|
8
|
+
{ rgb : '#0000ff', start : .67 },
|
9
|
+
{ rgb : '#ff00ff', start : .83 },
|
10
|
+
{ rgb : '#ff0000', start : 1 }
|
11
|
+
];
|
12
|
+
|
13
|
+
function checkHueColor(p) {
|
14
|
+
var startColor, endColor;
|
15
|
+
|
16
|
+
for(var i = 0; i < hue_color.length;i++) {
|
17
|
+
if (hue_color[i].start >= p) {
|
18
|
+
startColor = hue_color[i-1];
|
19
|
+
endColor = hue_color[i];
|
20
|
+
break;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
if (startColor && endColor) {
|
25
|
+
return Color.interpolateRGB(startColor, endColor, (p - startColor.start)/(endColor.start - startColor.start));
|
26
|
+
}
|
27
|
+
|
28
|
+
return hue_color[0].rgb;
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
function initHueColors () {
|
33
|
+
for(var i = 0, len = hue_color.length; i < len; i++) {
|
34
|
+
var hue = hue_color[i];
|
35
|
+
|
36
|
+
var obj = Color.parse(hue.rgb);
|
37
|
+
|
38
|
+
hue.r = obj.r;
|
39
|
+
hue.g = obj.g;
|
40
|
+
hue.b = obj.b;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
initHueColors();
|
45
|
+
|
46
|
+
export default {
|
47
|
+
colors : hue_color,
|
48
|
+
checkHueColor
|
49
|
+
};
|
@@ -0,0 +1,137 @@
|
|
1
|
+
import Canvas from './Canvas'
|
2
|
+
|
3
|
+
|
4
|
+
class ImageLoader {
|
5
|
+
constructor(url, opt = {}) {
|
6
|
+
this.isLoaded = false;
|
7
|
+
this.imageUrl = url;
|
8
|
+
this.opt = opt;
|
9
|
+
this.initialize();
|
10
|
+
}
|
11
|
+
|
12
|
+
initialize () {
|
13
|
+
this.canvas = this.createCanvas();
|
14
|
+
this.context = this.canvas.getContext('2d');
|
15
|
+
}
|
16
|
+
|
17
|
+
createCanvas () {
|
18
|
+
return document.createElement('canvas');
|
19
|
+
}
|
20
|
+
|
21
|
+
load (callback) {
|
22
|
+
this.loadImage(callback);
|
23
|
+
}
|
24
|
+
|
25
|
+
loadImage (callback) {
|
26
|
+
var ctx = this.context;
|
27
|
+
this.newImage = new Image();
|
28
|
+
const img = this.newImage
|
29
|
+
img.onload = () => {
|
30
|
+
var ratio = img.height / img.width;
|
31
|
+
|
32
|
+
if (this.opt.canvasWidth && this.opt.canvasHeight) {
|
33
|
+
this.canvas.width = this.opt.canvasWidth;
|
34
|
+
this.canvas.height = this.opt.canvasHeight;
|
35
|
+
} else {
|
36
|
+
this.canvas.width = this.opt.maxWidth ? this.opt.maxWidth : img.width;
|
37
|
+
this.canvas.height = this.canvas.width * ratio;
|
38
|
+
}
|
39
|
+
|
40
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, this.canvas.width, this.canvas.height);
|
41
|
+
this.isLoaded = true;
|
42
|
+
callback && callback();
|
43
|
+
};
|
44
|
+
|
45
|
+
this.getImageUrl(function (url) {
|
46
|
+
img.src = url;
|
47
|
+
});
|
48
|
+
}
|
49
|
+
|
50
|
+
load (callback) {
|
51
|
+
this.newImage = new Image();
|
52
|
+
const img = this.newImage
|
53
|
+
img.onload = () => {
|
54
|
+
this.isLoaded = true;
|
55
|
+
callback && callback();
|
56
|
+
};
|
57
|
+
|
58
|
+
this.getImageUrl(function (url) {
|
59
|
+
img.src = url;
|
60
|
+
});
|
61
|
+
}
|
62
|
+
|
63
|
+
getImageUrl (callback) {
|
64
|
+
if (typeof this.imageUrl == 'string') {
|
65
|
+
return callback(this.imageUrl);
|
66
|
+
} else if (this.imageUrl instanceof Blob) {
|
67
|
+
var reader = new FileReader();
|
68
|
+
|
69
|
+
reader.onload = function (ev) {
|
70
|
+
callback (ev.target.result);
|
71
|
+
}
|
72
|
+
|
73
|
+
reader.readAsDataURL(this.imageUrl);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
getRGBA (r, g, b, a) {
|
78
|
+
return [r, g, b, a];
|
79
|
+
}
|
80
|
+
|
81
|
+
toArray(filter, callback, opt = {}) {
|
82
|
+
var imagedata = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
83
|
+
var width = imagedata.width;
|
84
|
+
var height = imagedata.height;
|
85
|
+
|
86
|
+
var pixels = new Uint8ClampedArray(imagedata.data);
|
87
|
+
|
88
|
+
let bitmap = { pixels, width, height }
|
89
|
+
|
90
|
+
if (!filter) {
|
91
|
+
filter = (function () {
|
92
|
+
return (bitmap, done) => {
|
93
|
+
done(bitmap)
|
94
|
+
}
|
95
|
+
})()
|
96
|
+
}
|
97
|
+
|
98
|
+
filter(bitmap, function (newBitmap) {
|
99
|
+
var tmpCanvas = Canvas.drawPixels(newBitmap);
|
100
|
+
|
101
|
+
if (opt.returnTo == 'canvas') {
|
102
|
+
callback(tmpCanvas)
|
103
|
+
} else {
|
104
|
+
callback(tmpCanvas.toDataURL(opt.outputFormat || 'image/png'))
|
105
|
+
}
|
106
|
+
|
107
|
+
}, opt)
|
108
|
+
}
|
109
|
+
|
110
|
+
toHistogram (opt) {
|
111
|
+
var imagedata = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
112
|
+
var width = imagedata.width;
|
113
|
+
var height = imagedata.height;
|
114
|
+
|
115
|
+
var pixels = new Uint8ClampedArray(imagedata.data);
|
116
|
+
|
117
|
+
let bitmap = { pixels, width, height }
|
118
|
+
|
119
|
+
return Canvas.getHistogram(bitmap)
|
120
|
+
}
|
121
|
+
|
122
|
+
toRGB () {
|
123
|
+
var imagedata = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
124
|
+
|
125
|
+
var rgba = imagedata.data;
|
126
|
+
var results = [];
|
127
|
+
for (var i = 0, len = rgba.length; i < len; i += 4){
|
128
|
+
results[results.length] = [rgba[i + 0],rgba[i + 1],rgba[i + 2],rgba[i + 3]];
|
129
|
+
}
|
130
|
+
|
131
|
+
return results;
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
export default ImageLoader;
|