@openglobus/og 0.14.4 → 0.15.0
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/css/og.css +377 -274
- package/dist/@openglobus/og.css +1 -1
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +18 -17
- package/src/og/Clock.js +218 -194
- package/src/og/Globe.js +1 -3
- package/src/og/Object3d.js +104 -145
- package/src/og/camera/Camera.js +23 -19
- package/src/og/cons.js +107 -107
- package/src/og/control/Atmosphere.js +396 -0
- package/src/og/control/CompassButton.js +11 -18
- package/src/og/control/Control.js +187 -188
- package/src/og/control/GeoImageDragControl.js +84 -66
- package/src/og/control/LayerSwitcher.js +46 -145
- package/src/og/control/Lighting.js +314 -186
- package/src/og/control/RulerSwitcher.js +24 -19
- package/src/og/control/SimpleSkyBackground.js +38 -12
- package/src/og/control/Sun.js +2 -0
- package/src/og/control/ZoomControl.js +30 -42
- package/src/og/control/ruler/RulerScene.js +5 -23
- package/src/og/control/selection/Selection.js +21 -50
- package/src/og/control/selection/SelectionScene.js +15 -29
- package/src/og/control/timeline/TimelineControl.js +99 -0
- package/src/og/control/timeline/TimelineModel.js +133 -0
- package/src/og/control/timeline/TimelineView.js +449 -0
- package/src/og/control/timeline/timelineUtils.js +132 -0
- package/src/og/entity/Entity.js +30 -3
- package/src/og/entity/EntityCollection.js +0 -2
- package/src/og/entity/GeoObject.js +72 -56
- package/src/og/entity/GeoObjectHandler.js +487 -656
- package/src/og/input/input.js +3 -1
- package/src/og/layer/CanvasTiles.js +39 -34
- package/src/og/layer/Layer.js +2 -0
- package/src/og/layer/Material.js +1 -8
- package/src/og/light/LightSource.js +2 -0
- package/src/og/quadTree/Node.js +2 -1
- package/src/og/renderer/Renderer.js +26 -42
- package/src/og/renderer/RendererEvents.js +4 -4
- package/src/og/scene/Planet.js +276 -59
- package/src/og/scene/RenderNode.js +27 -12
- package/src/og/segment/Segment.js +0 -5
- package/src/og/shaders/atmos.js +332 -0
- package/src/og/shaders/drawnode.js +475 -109
- package/src/og/shaders/geoObject.js +96 -51
- package/src/og/shaders/polyline.js +212 -17
- package/src/og/shaders/utils.js +88 -0
- package/src/og/terrain/GlobusTerrain.js +2 -2
- package/src/og/ui/Button.js +106 -0
- package/src/og/ui/ButtonGroup.js +57 -0
- package/src/og/ui/Dialog.js +242 -0
- package/src/og/ui/Slider.js +144 -0
- package/src/og/ui/ToggleButton.js +51 -0
- package/src/og/ui/View.js +190 -0
- package/src/og/utils/shared.js +51 -33
- package/src/og/webgl/Framebuffer.js +308 -387
- package/src/og/webgl/Handler.js +68 -21
- package/src/og/webgl/Multisample.js +8 -0
- package/types/Clock.d.ts +7 -2
- package/types/Object3d.d.ts +14 -3
- package/types/camera/Camera.d.ts +15 -14
- package/types/control/Atmosphere.d.ts +15 -0
- package/types/control/CompassButton.d.ts +1 -2
- package/types/control/GeoImageDragControl.d.ts +7 -1
- package/types/control/LayerSwitcher.d.ts +4 -5
- package/types/control/Lighting.d.ts +32 -7
- package/types/control/SimpleSkyBackground.d.ts +4 -0
- package/types/control/ZoomControl.d.ts +0 -1
- package/types/control/ruler/RulerScene.d.ts +0 -1
- package/types/control/selection/Selection.d.ts +2 -4
- package/types/control/selection/SelectionScene.d.ts +0 -1
- package/types/entity/Entity.d.ts +8 -0
- package/types/entity/GeoObject.d.ts +28 -22
- package/types/entity/GeoObjectHandler.d.ts +16 -56
- package/types/input/input.d.ts +2 -0
- package/types/layer/CanvasTiles.d.ts +1 -0
- package/types/layer/Layer.d.ts +1 -0
- package/types/math/Plane.d.ts +1 -1
- package/types/renderer/Renderer.d.ts +7 -1
- package/types/scene/Planet.d.ts +20 -2
- package/types/scene/RenderNode.d.ts +2 -1
- package/types/segment/Segment.d.ts +1 -1
- package/types/shaders/atmos.d.ts +4 -0
- package/types/shaders/drawnode.d.ts +3 -2
- package/types/shaders/utils.d.ts +1 -0
- package/types/terrain/GlobusTerrain.d.ts +1 -1
- package/types/ui/Button.d.ts +21 -0
- package/types/ui/Dialog.d.ts +41 -0
- package/types/ui/Slider.d.ts +30 -0
- package/types/ui/ToggleButton.d.ts +10 -0
- package/types/ui/View.d.ts +32 -0
- package/types/utils/shared.d.ts +16 -14
- package/types/webgl/Framebuffer.d.ts +2 -5
- package/types/webgl/Handler.d.ts +11 -9
- package/types/webgl/Multisample.d.ts +2 -0
- package/src/og/ajax.js +0 -204
- package/src/og/entity/Object3d.js +0 -504
- package/types/ajax.d.ts +0 -24
- /package/src/og/{control → ui}/UIhelpers.js +0 -0
- /package/types/{control → ui}/UIhelpers.d.ts +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { View } from './View.js';
|
|
4
|
+
import { stringTemplate } from '../utils/shared.js';
|
|
5
|
+
|
|
6
|
+
const TEMPLATE =
|
|
7
|
+
`<div class="og-button">
|
|
8
|
+
<div class="og-button-icon">{icon}</div>
|
|
9
|
+
<div class="og-button-text">{text}</div>
|
|
10
|
+
</div>`;
|
|
11
|
+
|
|
12
|
+
class Button extends View {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super({
|
|
15
|
+
template: stringTemplate(TEMPLATE, {
|
|
16
|
+
icon: options.icon || "",
|
|
17
|
+
text: options.text || ""
|
|
18
|
+
}),
|
|
19
|
+
...options,
|
|
20
|
+
eventList: ["click", "mousedown", "mouseup", "touchstart", "touchend", "touchcancel", ...(options.eventList || [])]
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
this.name = options.name || "";
|
|
24
|
+
|
|
25
|
+
this.$icon;
|
|
26
|
+
this.$text;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
render(params) {
|
|
30
|
+
super.render(params);
|
|
31
|
+
this.$icon = this.select(".og-button-icon");
|
|
32
|
+
this.$text = this.select(".og-button-text");
|
|
33
|
+
this.el.__og_button__ = this;
|
|
34
|
+
this._initEvents();
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_initEvents() {
|
|
39
|
+
this._onMouseClick_ = this._onMouseClick.bind(this);
|
|
40
|
+
this.el.addEventListener("click", this._onMouseClick_);
|
|
41
|
+
|
|
42
|
+
this._onMouseDown_ = this._onMouseDown.bind(this);
|
|
43
|
+
this.el.addEventListener("mousedown", this._onMouseDown_);
|
|
44
|
+
|
|
45
|
+
this._onMouseUp_ = this._onMouseUp.bind(this);
|
|
46
|
+
this.el.addEventListener("mouseup", this._onMouseUp_);
|
|
47
|
+
|
|
48
|
+
this._onTouchStart_ = this._onTouchStart.bind(this);
|
|
49
|
+
this.el.addEventListener("touchstart", this._onTouchStart_);
|
|
50
|
+
|
|
51
|
+
this._onTouchEnd_ = this._onTouchEnd.bind(this);
|
|
52
|
+
this.el.addEventListener("touchend", this._onTouchEnd_);
|
|
53
|
+
|
|
54
|
+
this._onTouchCancel_ = this._onTouchCancel.bind(this);
|
|
55
|
+
this.el.addEventListener("touchcancel", this._onTouchCancel_);
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
_onMouseDown(e) {
|
|
60
|
+
e = e || window.event;
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
this._events.dispatch(this._events.mousedown, this, e);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_onMouseUp(e) {
|
|
66
|
+
e = e || window.event;
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
this._events.dispatch(this._events.mouseup, this, e);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_onTouchStart(e) {
|
|
72
|
+
e = e || window.event;
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
this._events.dispatch(this._events.touchstart, this, e);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_onTouchEnd(e) {
|
|
78
|
+
e = e || window.event;
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
this._events.dispatch(this._events.touchend, this, e);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_onTouchCancel(e) {
|
|
84
|
+
e = e || window.event;
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
this._events.dispatch(this._events.touchcancel, this, e);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_onMouseClick(e) {
|
|
90
|
+
e = e || window.event;
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
this._events.dispatch(this._events.click, this, e);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
remove() {
|
|
96
|
+
this._clearEvents();
|
|
97
|
+
super.remove();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_clearEvents() {
|
|
101
|
+
this.el.removeEventListener("click", this._onMouseClick_);
|
|
102
|
+
this._onMouseClick_ = undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { Button }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { Events } from '../Events.js';
|
|
4
|
+
|
|
5
|
+
class ButtonGroup {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this._events = new Events(["change", ...(options.eventList || [])]);
|
|
8
|
+
|
|
9
|
+
this._buttons = options.buttons
|
|
10
|
+
for (let i = 0; i < this._buttons.length; i++) {
|
|
11
|
+
this._bindButton(this._buttons[i]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
on(eventName, callback, sender) {
|
|
16
|
+
this._events.on(eventName, callback, sender);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
off(eventName, callback) {
|
|
20
|
+
this._events.off(eventName, callback);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_bindButton(button) {
|
|
24
|
+
button.on("change", this._onChange, this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
add(button) {
|
|
28
|
+
this._buttons.push(button);
|
|
29
|
+
this._bindButton(button);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_onChange(isActive, btn) {
|
|
33
|
+
if (isActive) {
|
|
34
|
+
btn.preventClick = true;
|
|
35
|
+
for (let i = 0; i < this._buttons.length; i++) {
|
|
36
|
+
let bi = this._buttons[i];
|
|
37
|
+
if (!bi.isEqual(btn)) {
|
|
38
|
+
bi.setActive(false);
|
|
39
|
+
bi.preventClick = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this._events.dispatch(this._events.change, btn);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
remove(button) {
|
|
47
|
+
for (let i = 0; i < this._buttons.length; i++) {
|
|
48
|
+
if (this._buttons[i].isEqual(button)) {
|
|
49
|
+
this._buttons.splice(i);
|
|
50
|
+
button.off("change", this._onChange);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { ButtonGroup }
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { View } from './View.js';
|
|
4
|
+
import { getDefault, stringTemplate } from '../utils/shared.js';
|
|
5
|
+
import { Button } from './Button.js';
|
|
6
|
+
|
|
7
|
+
const TEMPLATE = `<div class="og-ddialog"
|
|
8
|
+
style="display:{display}; resize:{resize}; width: {width}px; {height}; top: {top}px; left: {left}px; min-height: {minHeight}; max-height: {maxHeight}; min-width: {minWidth}; max-width: {maxWidth};">
|
|
9
|
+
<div class="og-ddialog-header">
|
|
10
|
+
<div class="og-ddialog-header__title">{title}</div>
|
|
11
|
+
<div class="og-ddialog-header__buttons"></div>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="og-ddialog-container"></div>
|
|
14
|
+
</div>>`;
|
|
15
|
+
|
|
16
|
+
const CLOSE_ICON = `<svg className="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
|
17
|
+
<path d="M777.856 280.192l-33.92-33.952-231.872 231.872-231.84-231.872-33.984 33.888 231.872 231.904-231.84 231.84 33.888 33.984 231.904-231.904 231.84 231.872 33.952-33.888-231.872-231.904z"/>
|
|
18
|
+
</svg>`
|
|
19
|
+
|
|
20
|
+
class Dialog extends View {
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
super({
|
|
23
|
+
template: stringTemplate(TEMPLATE, {
|
|
24
|
+
title: options.title || "",
|
|
25
|
+
display: getDefault(options.visible, true) ? "flex" : "none",
|
|
26
|
+
resize: getDefault(options.resizable, true) ? "both" : "none",
|
|
27
|
+
width: options.width || 300,
|
|
28
|
+
height: options.height ? `height:${options.height || 200}` : "",
|
|
29
|
+
left: options.left || 0,
|
|
30
|
+
top: options.top || 0,
|
|
31
|
+
minHeight: options.minHeight ? `${options.minHeight}px` : 'unset',
|
|
32
|
+
maxHeight: options.maxHeight ? `${options.maxHeight}px` : 'unset',
|
|
33
|
+
minWidth: options.minWidth ? `${options.minWidth}px` : 'unset',
|
|
34
|
+
maxWidth: options.maxWidth ? `${options.maxWidth}px` : 'unset',
|
|
35
|
+
}),
|
|
36
|
+
...options,
|
|
37
|
+
eventList: ["resize", "focus", "visibility", "dragstart", "dragend", ...(options.eventList || [])],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this._startPosX = 0;
|
|
41
|
+
this._startPosY = 0;
|
|
42
|
+
|
|
43
|
+
this.$header;
|
|
44
|
+
this.$title;
|
|
45
|
+
this.$constainer;
|
|
46
|
+
this.$buttons;
|
|
47
|
+
|
|
48
|
+
this._closeBtn;
|
|
49
|
+
|
|
50
|
+
this.useHide = options.useHide || false;
|
|
51
|
+
|
|
52
|
+
this._visibility = getDefault(options.visible, true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static set __zIndex(n) {
|
|
56
|
+
this.__zIndex__ = n;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static get __zIndex() {
|
|
60
|
+
if (!this.__zIndex__ && this.__zIndex__ !== 0) {
|
|
61
|
+
this.__zIndex__ = 0;
|
|
62
|
+
}
|
|
63
|
+
return this.__zIndex__;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setContainer(htmlStr) {
|
|
67
|
+
this.$constainer.innerHTML = htmlStr;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get container() {
|
|
71
|
+
return this.$container;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get width() {
|
|
75
|
+
return this.el ? parseFloat(this.el.style.width) : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get height() {
|
|
79
|
+
return this.el ? parseFloat(this.el.style.height) : 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
bringToFront() {
|
|
83
|
+
this.el.style.zIndex = Dialog.__zIndex++;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render(params) {
|
|
87
|
+
super.render(params);
|
|
88
|
+
this.bringToFront();
|
|
89
|
+
this.$header = this.select(".og-ddialog-header");
|
|
90
|
+
this.$title = this.select(".og-ddialog-header__title");
|
|
91
|
+
this.$container = this.select(".og-ddialog-container");
|
|
92
|
+
this.$buttons = this.select(".og-ddialog-header__buttons");
|
|
93
|
+
this._initEvents();
|
|
94
|
+
this._initButtons();
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
show() {
|
|
99
|
+
if (!this._visibility) {
|
|
100
|
+
this._visibility = true;
|
|
101
|
+
this.el.style.display = "flex";
|
|
102
|
+
this.bringToFront();
|
|
103
|
+
this._events.dispatch(this._events.visibility, true, this);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
hide() {
|
|
108
|
+
if (this._visibility) {
|
|
109
|
+
this._visibility = false;
|
|
110
|
+
this.el.style.display = "none";
|
|
111
|
+
this._events.dispatch(this._events.visibility, false, this);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
close() {
|
|
116
|
+
if (this.useHide) {
|
|
117
|
+
this.hide();
|
|
118
|
+
} else {
|
|
119
|
+
this.remove();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setVisibility(visibility) {
|
|
124
|
+
if (visibility) {
|
|
125
|
+
this.show();
|
|
126
|
+
} else {
|
|
127
|
+
this.hide();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_initButtons() {
|
|
132
|
+
this._closeBtn = new Button({
|
|
133
|
+
icon: CLOSE_ICON,
|
|
134
|
+
classList: ["og-button-size__20"]
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
this._onCloseBtnClick_ = this._onCloseBtnClick.bind(this);
|
|
138
|
+
this._closeBtn.on("click", this._onCloseBtnClick_);
|
|
139
|
+
|
|
140
|
+
this._closeBtn.appendTo(this.$buttons);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_initEvents() {
|
|
144
|
+
this._onMouseDown_ = this._onMouseDown.bind(this);
|
|
145
|
+
this.$header.addEventListener("mousedown", this._onMouseDown_);
|
|
146
|
+
|
|
147
|
+
this._onMouseDownAll_ = this._onMouseDownAll.bind(this);
|
|
148
|
+
this.el.addEventListener("mousedown", this._onMouseDownAll_);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_onCloseBtnClick(e) {
|
|
152
|
+
this.close();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_onMouseDownAll() {
|
|
156
|
+
this.bringToFront();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_onMouseDown(e) {
|
|
160
|
+
e = e || window.event;
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
|
|
163
|
+
this._startDragging();
|
|
164
|
+
|
|
165
|
+
this._startPosX = e.clientX;
|
|
166
|
+
this._startPosY = e.clientY;
|
|
167
|
+
|
|
168
|
+
this._onMouseMove_ = this._onMouseMove.bind(this)
|
|
169
|
+
document.addEventListener("mousemove", this._onMouseMove_);
|
|
170
|
+
|
|
171
|
+
this._onMouseUp_ = this._onMouseUp.bind(this);
|
|
172
|
+
document.addEventListener("mouseup", this._onMouseUp_);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
setPosition(x, y) {
|
|
176
|
+
if (x != undefined) {
|
|
177
|
+
this.el.style.left = `${x}px`;
|
|
178
|
+
}
|
|
179
|
+
if (y != undefined) {
|
|
180
|
+
this.el.style.top = `${y}px`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_onMouseMove(e) {
|
|
185
|
+
e = e || window.event;
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
let dx = this._startPosX - e.clientX;
|
|
188
|
+
let dy = this._startPosY - e.clientY;
|
|
189
|
+
this._startPosX = e.clientX;
|
|
190
|
+
this._startPosY = e.clientY;
|
|
191
|
+
this.setPosition(this.el.offsetLeft - dx, this.el.offsetTop - dy);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
_startDragging() {
|
|
195
|
+
if (!this.el.classList.contains("dragging")) {
|
|
196
|
+
this.el.classList.add("dragging");
|
|
197
|
+
this._events.dispatch(this._events.dragstart, this);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_clearDragging() {
|
|
202
|
+
if (this.el.classList.contains("dragging")) {
|
|
203
|
+
this._events.dispatch(this._events.dragend, this);
|
|
204
|
+
this.el.classList.remove("dragging");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_onMouseUp() {
|
|
209
|
+
this._clearDragging();
|
|
210
|
+
|
|
211
|
+
document.removeEventListener("mouseup", this._onMouseUp_);
|
|
212
|
+
this._onMouseUp_ = undefined;
|
|
213
|
+
|
|
214
|
+
document.removeEventListener("mousemove", this._onMouseMove_);
|
|
215
|
+
this._onMouseMove_ = undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
remove() {
|
|
219
|
+
this._clearDragging();
|
|
220
|
+
this._clearEvents();
|
|
221
|
+
super.remove();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
_clearEvents() {
|
|
225
|
+
this._closeBtn.off("click", this._onCloseBtnClick_);
|
|
226
|
+
this._onCloseBtnClick_ = undefined;
|
|
227
|
+
|
|
228
|
+
document.removeEventListener("mouseup", this._onMouseUp_);
|
|
229
|
+
this._onMouseUp_ = undefined;
|
|
230
|
+
|
|
231
|
+
document.removeEventListener("mousemove", this._onMouseMove_);
|
|
232
|
+
this._onMouseMove_ = undefined;
|
|
233
|
+
|
|
234
|
+
this.$header.removeEventListener("mousedown", this._onMouseDown_);
|
|
235
|
+
this._onMouseDown_ = undefined;
|
|
236
|
+
|
|
237
|
+
this.el.removeEventListener("mousedown", this._onMouseDownAll_);
|
|
238
|
+
this._onMouseDownAll_ = undefined;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { Dialog }
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { View } from './View.js';
|
|
4
|
+
import { stringTemplate } from '../utils/shared.js';
|
|
5
|
+
import { clamp } from '../math.js';
|
|
6
|
+
|
|
7
|
+
const TEMPLATE = `<div class="og-slider">
|
|
8
|
+
<div class="og-slider-label">{label}</div>
|
|
9
|
+
<div class="og-slider-panel">
|
|
10
|
+
<div class="og-slider-progress"></div>
|
|
11
|
+
<div class="og-slider-pointer"></div>
|
|
12
|
+
</div>
|
|
13
|
+
<input type="number"/>
|
|
14
|
+
</div>`;
|
|
15
|
+
|
|
16
|
+
class Slider extends View {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
super({
|
|
19
|
+
template: stringTemplate(TEMPLATE, {
|
|
20
|
+
label: options.label || ""
|
|
21
|
+
}), ...options, eventList: ["change", ...(options.eventList || [])]
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
this._value = options.value || 0.0;
|
|
25
|
+
this._min = options.min || 0.0;
|
|
26
|
+
this._max = options.max || 1.0;
|
|
27
|
+
//this._step = options.step || ((this._max - this._min) / 10.0);
|
|
28
|
+
|
|
29
|
+
this._onResize_ = this._onResize.bind(this);
|
|
30
|
+
this._resizeObserver = new ResizeObserver(this._onResize_);
|
|
31
|
+
|
|
32
|
+
this.$label;
|
|
33
|
+
this.$pointer;
|
|
34
|
+
this.$progress;
|
|
35
|
+
this.$input;
|
|
36
|
+
this.$panel;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
render(params) {
|
|
40
|
+
super.render(params);
|
|
41
|
+
this.$label = this.select(".og-slider-label");
|
|
42
|
+
if (this.$label.innerHTML === "") {
|
|
43
|
+
this.$label.style.display = "none";
|
|
44
|
+
}
|
|
45
|
+
this.$pointer = this.select(".og-slider-pointer");
|
|
46
|
+
this.$progress = this.select(".og-slider-progress");
|
|
47
|
+
this.$panel = this.select(".og-slider-panel");
|
|
48
|
+
this.$input = this.select("input");
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
this._resizeObserver.observe(this.el);
|
|
52
|
+
|
|
53
|
+
this._initEvents();
|
|
54
|
+
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_onResize(e) {
|
|
59
|
+
this._setOffset(this._value * this.$panel.clientWidth / (this._max - this._min));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set value(val) {
|
|
63
|
+
if (val !== this._value) {
|
|
64
|
+
this._value = clamp(val, this._min, this._max);
|
|
65
|
+
this.$input.value = this._value.toString();
|
|
66
|
+
this._setOffset(this._value * this.$panel.clientWidth / (this._max - this._min));
|
|
67
|
+
this._events.dispatch(this._events.change, this._value, this);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get value() {
|
|
72
|
+
return this._value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_initEvents() {
|
|
76
|
+
this._onMouseDown_ = this._onMouseDown.bind(this);
|
|
77
|
+
this.$panel.addEventListener("mousedown", this._onMouseDown_);
|
|
78
|
+
|
|
79
|
+
this._onInput_ = this._onInput.bind(this);
|
|
80
|
+
this.$input.addEventListener("input", this._onInput_);
|
|
81
|
+
|
|
82
|
+
this._onMouseWheel_ = this._onMouseWheel.bind(this);
|
|
83
|
+
this.$panel.addEventListener("mousewheel", this._onMouseWheel_);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_onMouseWheel(e) {
|
|
87
|
+
e = e || window.event;
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
this.value = this._value + Math.sign(e.wheelDelta) * (this._max - this._min) / 100.0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_onInput(e) {
|
|
94
|
+
e = e || window.event;
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
this.value = parseFloat(e.target.value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_onMouseDown(e) {
|
|
101
|
+
e = e || window.event;
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
|
|
104
|
+
this._startPosX = e.clientX;
|
|
105
|
+
|
|
106
|
+
this.value = this._min + (this._max - this._min) * (e.offsetX / this.$panel.clientWidth);
|
|
107
|
+
|
|
108
|
+
this._onMouseMove_ = this._onMouseMove.bind(this)
|
|
109
|
+
document.addEventListener("mousemove", this._onMouseMove_);
|
|
110
|
+
|
|
111
|
+
this._onMouseUp_ = this._onMouseUp.bind(this);
|
|
112
|
+
document.addEventListener("mouseup", this._onMouseUp_);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_setOffset(x) {
|
|
116
|
+
if (x >= 0 && x <= this.$panel.clientWidth) {
|
|
117
|
+
this.$pointer.style.left = this.$progress.style.width = `${x * 100 / this.$panel.clientWidth}%`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_onMouseMove(e) {
|
|
122
|
+
e = e || window.event;
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
|
|
126
|
+
let rect = this.$panel.getBoundingClientRect();
|
|
127
|
+
let clientX = clamp(e.clientX, rect.left, rect.right);
|
|
128
|
+
let dx = this._startPosX - clientX;
|
|
129
|
+
this._startPosX = clientX;
|
|
130
|
+
this.value = (this.$pointer.offsetLeft - dx) * (this._max - this._min) / this.$panel.clientWidth;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
_onMouseUp() {
|
|
134
|
+
document.removeEventListener("mouseup", this._onMouseUp_);
|
|
135
|
+
this._onMouseUp_ = undefined;
|
|
136
|
+
|
|
137
|
+
document.removeEventListener("mousemove", this._onMouseMove_);
|
|
138
|
+
this._onMouseMove_ = undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
Slider
|
|
144
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { Button } from './Button.js';
|
|
4
|
+
|
|
5
|
+
class ToggleButton extends Button {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super({
|
|
8
|
+
...options,
|
|
9
|
+
eventList: ["change", ...(options.eventList || [])]
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
this._isActive = options.isActive || false;
|
|
13
|
+
|
|
14
|
+
this.preventClick = options.preventClick || false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setActive(isActive, stopPropagation) {
|
|
18
|
+
if (isActive !== this._isActive) {
|
|
19
|
+
this._isActive = isActive;
|
|
20
|
+
this._toggle();
|
|
21
|
+
if (!stopPropagation) {
|
|
22
|
+
this._events.dispatch(this._events.change, isActive, this);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_toggle() {
|
|
28
|
+
this.el.classList.toggle("og-button__active");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get isActive() {
|
|
32
|
+
return this._isActive;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render(params) {
|
|
36
|
+
super.render(params);
|
|
37
|
+
if (this._isActive) {
|
|
38
|
+
this._toggle();
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_onMouseClick(e) {
|
|
44
|
+
if (!this.preventClick) {
|
|
45
|
+
super._onMouseClick(e);
|
|
46
|
+
this.setActive(!this.isActive);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { ToggleButton }
|