perfect-gui 3.5.1 → 3.5.3
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/package.json +1 -1
- package/src/index.js +58 -30
- package/test/src/js/other.js +1 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import styles from './styles';
|
|
|
2
2
|
|
|
3
3
|
export default class GUI {
|
|
4
4
|
constructor(options = {}) {
|
|
5
|
+
// Process options
|
|
5
6
|
if ( options.container ) {
|
|
6
7
|
this.container = typeof options.container == "string" ? document.querySelector(options.container) : options.container;
|
|
7
8
|
this.position_type = 'absolute';
|
|
@@ -18,8 +19,17 @@ export default class GUI {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
this.name = (options != undefined && typeof options.name == "string") ? options.name : '';
|
|
22
|
+
|
|
21
23
|
this.backgroundColor = options.color || null;
|
|
22
24
|
|
|
25
|
+
this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)
|
|
26
|
+
if ( options.maxHeight ) {
|
|
27
|
+
this.initMaxHeight = options.maxHeight;
|
|
28
|
+
this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.screenCorner = this._parseScreenCorner(options.position);
|
|
32
|
+
|
|
23
33
|
if ( this instanceof GUI ) {
|
|
24
34
|
if ( typeof GUI[GUI.instanceCounter] != 'number' ) {
|
|
25
35
|
GUI[GUI.instanceCounter] = 0;
|
|
@@ -39,11 +49,35 @@ export default class GUI {
|
|
|
39
49
|
// Common styles
|
|
40
50
|
if (this.instanceId == 0) {
|
|
41
51
|
this._addStyles(`${styles(this.position_type)}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Instance specific styles
|
|
55
|
+
this._styleInstance();
|
|
56
|
+
|
|
57
|
+
if (options.autoRepositioning != false) {
|
|
58
|
+
window.addEventListener('resize', this._handleResize.bind(this));
|
|
42
59
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
60
|
+
|
|
61
|
+
this._addWrapper();
|
|
62
|
+
this.wrapper.setAttribute('data-corner-x', this.screenCorner.x);
|
|
63
|
+
this.wrapper.setAttribute('data-corner-y', this.screenCorner.y);
|
|
64
|
+
|
|
65
|
+
this.hasBeenDragged = false;
|
|
66
|
+
if (options.draggable == true) this._makeDraggable();
|
|
67
|
+
|
|
68
|
+
this.closed = false;
|
|
69
|
+
if (options.closed) this.toggleClose();
|
|
70
|
+
|
|
71
|
+
this.folders = [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_styleInstance() {
|
|
75
|
+
if (this.screenCorner.x == 'left') {
|
|
76
|
+
this.xOffset = 0;
|
|
77
|
+
} else {
|
|
78
|
+
this.xOffset = this.container.clientWidth - this.wrapperWidth - this._getScrollbarWidth(this.container);
|
|
79
|
+
}
|
|
80
|
+
|
|
47
81
|
if (this.instanceId > 0) {
|
|
48
82
|
let existingDomInstances = this.container.querySelectorAll('.p-gui');
|
|
49
83
|
for (let i = 0; i < existingDomInstances.length; i++) {
|
|
@@ -58,16 +92,13 @@ export default class GUI {
|
|
|
58
92
|
}
|
|
59
93
|
}
|
|
60
94
|
this.yOffset = 0;
|
|
61
|
-
this.position = {
|
|
95
|
+
this.position = {
|
|
96
|
+
prevX: this.xOffset,
|
|
97
|
+
prevY: this.yOffset,
|
|
98
|
+
x: this.xOffset,
|
|
99
|
+
y: this.yOffset
|
|
100
|
+
};
|
|
62
101
|
|
|
63
|
-
if ( options.maxHeight ) {
|
|
64
|
-
this.maxHeight = options.maxHeight;
|
|
65
|
-
} else {
|
|
66
|
-
this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)
|
|
67
|
-
}
|
|
68
|
-
window.addEventListener('resize', () => {
|
|
69
|
-
this.maxHeight = Math.min(options.maxHeight || '', Math.min(this.container.clientHeight, window.innerHeight));
|
|
70
|
-
});
|
|
71
102
|
this._addStyles(`#p-gui-${this.instanceId} {
|
|
72
103
|
width: ${this.wrapperWidth}px;
|
|
73
104
|
max-height: ${this.maxHeight}px;
|
|
@@ -75,20 +106,6 @@ export default class GUI {
|
|
|
75
106
|
${ this.screenCorner.y == 'top' ? '' : 'top: auto; bottom: 0;' }
|
|
76
107
|
${ this.backgroundColor ? 'background: ' + this.backgroundColor + ';' : '' }
|
|
77
108
|
}`);
|
|
78
|
-
|
|
79
|
-
if (options.autoRepositioning != false) window.addEventListener('resize', this._handleResize.bind(this));
|
|
80
|
-
|
|
81
|
-
this._addWrapper();
|
|
82
|
-
this.wrapper.setAttribute('data-corner-x', this.screenCorner.x);
|
|
83
|
-
this.wrapper.setAttribute('data-corner-y', this.screenCorner.y);
|
|
84
|
-
|
|
85
|
-
this.hasBeenDragged = false;
|
|
86
|
-
if (options.draggable == true) this._makeDraggable();
|
|
87
|
-
|
|
88
|
-
this.closed = false;
|
|
89
|
-
if (options.closed) this.toggleClose();
|
|
90
|
-
|
|
91
|
-
this.folders = [];
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
_folderConstructor(folderOptions) {
|
|
@@ -107,8 +124,20 @@ export default class GUI {
|
|
|
107
124
|
return parsedPosition;
|
|
108
125
|
}
|
|
109
126
|
|
|
127
|
+
_getScrollbarWidth(element) {
|
|
128
|
+
if (element === document.body) {
|
|
129
|
+
return window.innerWidth - document.documentElement.clientWidth;
|
|
130
|
+
} else {
|
|
131
|
+
return element.offsetWidth - element.clientWidth;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
110
135
|
_handleResize() {
|
|
111
|
-
|
|
136
|
+
this.maxHeight = Math.min(this.initMaxHeight, Math.min(this.container.clientHeight, window.innerHeight));
|
|
137
|
+
|
|
138
|
+
if (this.hasBeenDragged) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
112
141
|
|
|
113
142
|
this.xOffset = this.screenCorner.x == 'left' ? 0 : this.container.clientWidth - this.wrapperWidth;
|
|
114
143
|
if (this.instanceId > 0) {
|
|
@@ -131,8 +160,7 @@ export default class GUI {
|
|
|
131
160
|
}
|
|
132
161
|
|
|
133
162
|
_createElement(element) {
|
|
134
|
-
|
|
135
|
-
element.el = element.el ? element.el : 'div';
|
|
163
|
+
element.el = element.el || 'div';
|
|
136
164
|
var domElement = document.createElement(element.el);
|
|
137
165
|
if (element.id) domElement.id = element.id;
|
|
138
166
|
if (element.class) domElement.className = element.class;
|