vgapp 1.2.3 → 1.2.4

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.
@@ -1,231 +1,233 @@
1
- const DEFAULT_OPTIONS = {
2
- enable: false,
1
+ const DEFAULT_OPTIONS = {
2
+ enable: false,
3
3
  minWidth: 300,
4
4
  minHeight: 160,
5
5
  edgeSize: 8,
6
6
  debug: false,
7
7
  };
8
-
9
- const DIRECTION_TO_CURSOR = {
10
- n: 'ns-resize',
11
- s: 'ns-resize',
12
- e: 'ew-resize',
13
- w: 'ew-resize',
14
- ne: 'nesw-resize',
15
- sw: 'nesw-resize',
16
- nw: 'nwse-resize',
17
- se: 'nwse-resize',
18
- };
19
-
20
- class VGModalResize {
21
- constructor(modalElement, dialogElement, options = {}) {
22
- this._modalElement = modalElement;
23
- this._dialogElement = dialogElement;
24
- this._contentElement = this._dialogElement ? this._dialogElement.querySelector('.vg-modal-content') : null;
25
- this._options = this._normalizeOptions(options);
26
- this._pointerId = null;
27
- this._direction = '';
28
- this._startX = 0;
29
- this._startY = 0;
30
- this._currentX = 0;
31
- this._currentY = 0;
32
- this._startWidth = 0;
33
- this._startHeight = 0;
34
- this._startLeft = 0;
35
- this._startTop = 0;
36
- this._startRight = 0;
37
- this._startBottom = 0;
38
- this._isEnabled = false;
39
- this._observer = null;
40
- this._syncFrameId = null;
41
- this._resizeFrameId = null;
42
- this._lockedIframes = [];
43
- this._debugElement = null;
44
- this._previousMaxWidth = '';
45
- this._previousMaxHeight = '';
46
- this._previousPointerEvents = '';
47
- this._previousMinHeight = '';
48
- this._previousOverflow = '';
49
- this._previousTransition = '';
50
- this._previousWillChange = '';
51
- this._previousContentHeight = '';
52
- this._previousContentMaxHeight = '';
53
- this._previousContentOverflow = '';
54
-
55
- this._onPointerDown = this._onPointerDown.bind(this);
56
- this._onPointerMove = this._onPointerMove.bind(this);
57
- this._onPointerUp = this._onPointerUp.bind(this);
58
- this._onPointerLeave = this._onPointerLeave.bind(this);
59
- this._applyResizePosition = this._applyResizePosition.bind(this);
60
- }
61
-
62
- setOptions(options = {}) {
63
- this._options = this._normalizeOptions(options, this._options);
64
- this._updateDebugOverlay();
65
- }
66
-
67
- enable() {
68
- if (!this._dialogElement || this._isEnabled) return;
69
-
70
- this._updateDebugOverlay();
71
- this._modalElement.addEventListener('pointermove', this._onPointerMove);
72
- this._modalElement.addEventListener('pointerdown', this._onPointerDown);
73
- this._modalElement.addEventListener('pointerleave', this._onPointerLeave);
74
- this._startObserveSizeChanges();
75
- this._isEnabled = true;
76
- }
77
-
78
- disable() {
79
- if (!this._isEnabled) return;
80
-
81
- this._modalElement.removeEventListener('pointermove', this._onPointerMove);
82
- this._modalElement.removeEventListener('pointerdown', this._onPointerDown);
83
- this._modalElement.removeEventListener('pointerleave', this._onPointerLeave);
84
- document.removeEventListener('pointermove', this._onPointerMove);
85
- document.removeEventListener('pointerup', this._onPointerUp);
86
- document.removeEventListener('pointercancel', this._onPointerUp);
87
- this._cancelResizeFrame();
88
- this._stopObserveSizeChanges();
89
- this._pointerId = null;
90
- this._direction = '';
91
- this._dialogElement.style.cursor = '';
92
- delete this._modalElement.dataset.vgModalResizing;
93
- this._unlockEmbeddedFrames();
94
- this._restoreResizeStyles();
95
- this._setDebugVisibility(false);
96
- this._isEnabled = false;
97
- }
98
-
99
- syncToViewport() {
100
- if (this._modalElement && this._modalElement.dataset.vgModalDragging === 'true') return;
101
- if (!this._isPreparedForInteraction()) return;
102
-
103
- const rect = this._dialogElement.getBoundingClientRect();
104
- const currentWidth = this._dialogElement.offsetWidth || rect.width;
105
- const currentHeight = this._dialogElement.offsetHeight || rect.height;
106
- const currentLeftValue = Number.parseFloat(this._dialogElement.style.left);
107
- const currentTopValue = Number.parseFloat(this._dialogElement.style.top);
108
- const currentLeft = Number.isFinite(currentLeftValue) ? currentLeftValue : rect.left;
109
- const currentTop = Number.isFinite(currentTopValue) ? currentTopValue : rect.top;
110
- const maxWidth = window.innerWidth;
111
- const maxHeight = window.innerHeight;
112
- const width = Math.max(this._options.minWidth, Math.min(currentWidth, maxWidth));
113
- const height = Math.max(this._options.minHeight, Math.min(currentHeight, maxHeight));
114
- const maxLeft = Math.max(0, window.innerWidth - width);
115
- const maxTop = Math.max(0, window.innerHeight - height);
116
- const left = Math.min(maxLeft, Math.max(0, currentLeft));
117
- const top = Math.min(maxTop, Math.max(0, currentTop));
118
-
119
- if (Math.abs(currentWidth - width) > 0.5) {
120
- this._dialogElement.style.width = `${width}px`;
121
- }
122
-
123
- if (Math.abs(currentHeight - height) > 0.5) {
124
- this._dialogElement.style.height = `${height}px`;
125
- }
126
-
127
- this._dialogElement.style.left = `${left}px`;
128
- this._dialogElement.style.top = `${top}px`;
129
- this._updateDebugValues();
130
- }
131
-
132
- _onPointerDown(event) {
133
- if (event.button !== 0) return;
134
- if (event.defaultPrevented) return;
135
-
136
- const direction = this._getDirectionFromPointer(event);
137
- if (!direction) return;
138
-
139
- event.preventDefault();
140
- this._pointerId = event.pointerId;
141
- this._direction = direction;
142
-
143
- const rect = this._dialogElement.getBoundingClientRect();
144
- this._applyResizeStyles();
145
- this._preparePosition(rect);
146
- this._startX = event.clientX;
147
- this._startY = event.clientY;
148
- this._currentX = event.clientX;
149
- this._currentY = event.clientY;
150
- this._startWidth = rect.width;
151
- this._startHeight = rect.height;
152
- this._startLeft = rect.left;
153
- this._startTop = rect.top;
154
- this._startRight = rect.right;
155
- this._startBottom = rect.bottom;
156
- this._lockEmbeddedFrames();
157
- this._modalElement.dataset.vgModalResizing = 'true';
158
- this._setDebugVisibility(true);
159
- this._updateDebugValues();
160
-
161
- document.addEventListener('pointermove', this._onPointerMove);
162
- document.addEventListener('pointerup', this._onPointerUp);
163
- document.addEventListener('pointercancel', this._onPointerUp);
164
- }
165
-
166
- _onPointerMove(event) {
167
- if (this._pointerId === null) {
168
- const direction = this._getDirectionFromPointer(event);
169
- this._dialogElement.style.cursor = direction ? DIRECTION_TO_CURSOR[direction] : '';
170
- return;
171
- }
172
-
173
- if (event.pointerId !== this._pointerId) return;
174
-
175
- this._currentX = event.clientX;
176
- this._currentY = event.clientY;
177
- if (this._resizeFrameId !== null) return;
178
- this._resizeFrameId = window.requestAnimationFrame(this._applyResizePosition);
179
- }
180
-
181
- _applyResizePosition() {
182
- this._resizeFrameId = null;
183
- if (this._pointerId === null) return;
184
-
185
- const deltaX = this._currentX - this._startX;
186
- const deltaY = this._currentY - this._startY;
187
- let width = this._startWidth;
188
- let height = this._startHeight;
189
- let left = this._startLeft;
190
- let top = this._startTop;
191
-
192
- if (this._direction.includes('e')) {
193
- const maxWidth = Math.max(this._options.minWidth, window.innerWidth - this._startLeft);
194
- width = Math.min(maxWidth, Math.max(this._options.minWidth, this._startWidth + deltaX));
195
- }
196
-
197
- if (this._direction.includes('s')) {
198
- const maxHeight = Math.max(this._options.minHeight, window.innerHeight - this._startTop);
199
- height = Math.min(maxHeight, Math.max(this._options.minHeight, this._startHeight + deltaY));
200
- }
201
-
202
- if (this._direction.includes('w')) {
203
- const maxLeft = this._startRight - this._options.minWidth;
204
- left = Math.min(maxLeft, Math.max(0, this._startLeft + deltaX));
205
- width = this._startRight - left;
206
- }
207
-
208
- if (this._direction.includes('n')) {
209
- const maxTop = this._startBottom - this._options.minHeight;
210
- top = Math.min(maxTop, Math.max(0, this._startTop + deltaY));
211
- height = this._startBottom - top;
212
- }
213
-
214
- this._dialogElement.style.left = `${left}px`;
215
- this._dialogElement.style.top = `${top}px`;
216
- this._dialogElement.style.width = `${width}px`;
217
- this._dialogElement.style.height = `${height}px`;
218
- this._updateDebugValues();
219
- }
220
-
221
- _onPointerUp(event) {
222
- if (event.pointerId !== this._pointerId) return;
223
-
224
- document.removeEventListener('pointermove', this._onPointerMove);
225
- document.removeEventListener('pointerup', this._onPointerUp);
226
- document.removeEventListener('pointercancel', this._onPointerUp);
227
- this._cancelResizeFrame();
228
- this._applyResizePosition();
8
+
9
+ const DIRECTION_TO_CURSOR = {
10
+ n: 'ns-resize',
11
+ s: 'ns-resize',
12
+ e: 'ew-resize',
13
+ w: 'ew-resize',
14
+ ne: 'nesw-resize',
15
+ sw: 'nesw-resize',
16
+ nw: 'nwse-resize',
17
+ se: 'nwse-resize',
18
+ };
19
+
20
+ class VGModalResize {
21
+ constructor(modalElement, dialogElement, options = {}) {
22
+ this._modalElement = modalElement;
23
+ this._dialogElement = dialogElement;
24
+ this._contentElement = this._dialogElement ? this._dialogElement.querySelector('.vg-modal-content') : null;
25
+ this._options = this._normalizeOptions(options);
26
+ this._pointerId = null;
27
+ this._direction = '';
28
+ this._startX = 0;
29
+ this._startY = 0;
30
+ this._currentX = 0;
31
+ this._currentY = 0;
32
+ this._startWidth = 0;
33
+ this._startHeight = 0;
34
+ this._startLeft = 0;
35
+ this._startTop = 0;
36
+ this._startRight = 0;
37
+ this._startBottom = 0;
38
+ this._isEnabled = false;
39
+ this._observer = null;
40
+ this._syncFrameId = null;
41
+ this._resizeFrameId = null;
42
+ this._lockedIframes = [];
43
+ this._debugElement = null;
44
+ this._previousMaxWidth = '';
45
+ this._previousMaxHeight = '';
46
+ this._previousPointerEvents = '';
47
+ this._previousMinHeight = '';
48
+ this._previousOverflow = '';
49
+ this._previousTransition = '';
50
+ this._previousWillChange = '';
51
+ this._previousContentHeight = '';
52
+ this._previousContentMaxHeight = '';
53
+ this._previousContentOverflow = '';
54
+
55
+ this._onPointerDown = this._onPointerDown.bind(this);
56
+ this._onPointerMove = this._onPointerMove.bind(this);
57
+ this._onPointerUp = this._onPointerUp.bind(this);
58
+ this._onPointerLeave = this._onPointerLeave.bind(this);
59
+ this._applyResizePosition = this._applyResizePosition.bind(this);
60
+ }
61
+
62
+ setOptions(options = {}) {
63
+ this._options = this._normalizeOptions(options, this._options);
64
+ this._updateDebugOverlay();
65
+ }
66
+
67
+ enable() {
68
+ if (!this._dialogElement || this._isEnabled) return;
69
+
70
+ this._updateDebugOverlay();
71
+ this._modalElement.addEventListener('pointermove', this._onPointerMove);
72
+ this._modalElement.addEventListener('pointerdown', this._onPointerDown);
73
+ this._modalElement.addEventListener('pointerleave', this._onPointerLeave);
74
+ this._startObserveSizeChanges();
75
+ this._isEnabled = true;
76
+ }
77
+
78
+ disable() {
79
+ if (!this._isEnabled) return;
80
+
81
+ this._modalElement.removeEventListener('pointermove', this._onPointerMove);
82
+ this._modalElement.removeEventListener('pointerdown', this._onPointerDown);
83
+ this._modalElement.removeEventListener('pointerleave', this._onPointerLeave);
84
+ document.removeEventListener('pointermove', this._onPointerMove);
85
+ document.removeEventListener('pointerup', this._onPointerUp);
86
+ document.removeEventListener('pointercancel', this._onPointerUp);
87
+ this._cancelResizeFrame();
88
+ this._stopObserveSizeChanges();
89
+ this._pointerId = null;
90
+ this._direction = '';
91
+ this._dialogElement.style.cursor = '';
92
+ delete this._modalElement.dataset.vgModalResizing;
93
+ this._unlockEmbeddedFrames();
94
+ this._restoreResizeStyles();
95
+ this._setDebugVisibility(false);
96
+ this._isEnabled = false;
97
+ }
98
+
99
+ syncToViewport() {
100
+ if (this._modalElement && this._modalElement.dataset.vgModalDragging === 'true') return;
101
+ if (!this._isPreparedForInteraction()) return;
102
+
103
+ const rect = this._dialogElement.getBoundingClientRect();
104
+ const currentWidth = this._dialogElement.offsetWidth || rect.width;
105
+ const currentHeight = this._dialogElement.offsetHeight || rect.height;
106
+ const currentLeftValue = Number.parseFloat(this._dialogElement.style.left);
107
+ const currentTopValue = Number.parseFloat(this._dialogElement.style.top);
108
+ const currentLeft = Number.isFinite(currentLeftValue) ? currentLeftValue : rect.left;
109
+ const currentTop = Number.isFinite(currentTopValue) ? currentTopValue : rect.top;
110
+ const maxWidth = window.innerWidth;
111
+ const maxHeight = window.innerHeight;
112
+ const width = Math.max(this._options.minWidth, Math.min(currentWidth, maxWidth));
113
+ const height = Math.max(this._options.minHeight, Math.min(currentHeight, maxHeight));
114
+ const maxLeft = Math.max(0, window.innerWidth - width);
115
+ const maxTop = Math.max(0, window.innerHeight - height);
116
+ const left = Math.min(maxLeft, Math.max(0, currentLeft));
117
+ const top = Math.min(maxTop, Math.max(0, currentTop));
118
+
119
+ if (Math.abs(currentWidth - width) > 0.5) {
120
+ this._dialogElement.style.width = `${width}px`;
121
+ }
122
+
123
+ if (Math.abs(currentHeight - height) > 0.5) {
124
+ this._dialogElement.style.height = `${height}px`;
125
+ }
126
+
127
+ this._dialogElement.style.left = `${left}px`;
128
+ this._dialogElement.style.top = `${top}px`;
129
+ this._updateDebugValues();
130
+
131
+ }
132
+
133
+ _onPointerDown(event) {
134
+ if (event.button !== 0) return;
135
+ if (event.defaultPrevented) return;
136
+
137
+ const direction = this._getDirectionFromPointer(event);
138
+ if (!direction) return;
139
+
140
+ event.preventDefault();
141
+ this._pointerId = event.pointerId;
142
+ this._direction = direction;
143
+
144
+ const rect = this._dialogElement.getBoundingClientRect();
145
+ this._applyResizeStyles();
146
+ this._preparePosition(rect);
147
+ this._startX = event.clientX;
148
+ this._startY = event.clientY;
149
+ this._currentX = event.clientX;
150
+ this._currentY = event.clientY;
151
+ this._startWidth = rect.width;
152
+ this._startHeight = rect.height;
153
+ this._startLeft = rect.left;
154
+ this._startTop = rect.top;
155
+ this._startRight = rect.right;
156
+ this._startBottom = rect.bottom;
157
+ this._lockEmbeddedFrames();
158
+ this._modalElement.dataset.vgModalResizing = 'true';
159
+ this._setDebugVisibility(true);
160
+ this._updateDebugValues();
161
+
162
+ document.addEventListener('pointermove', this._onPointerMove);
163
+ document.addEventListener('pointerup', this._onPointerUp);
164
+ document.addEventListener('pointercancel', this._onPointerUp);
165
+ }
166
+
167
+ _onPointerMove(event) {
168
+ if (this._pointerId === null) {
169
+ const direction = this._getDirectionFromPointer(event);
170
+ this._dialogElement.style.cursor = direction ? DIRECTION_TO_CURSOR[direction] : '';
171
+ return;
172
+ }
173
+
174
+ if (event.pointerId !== this._pointerId) return;
175
+
176
+ this._currentX = event.clientX;
177
+ this._currentY = event.clientY;
178
+ if (this._resizeFrameId !== null) return;
179
+ this._resizeFrameId = window.requestAnimationFrame(this._applyResizePosition);
180
+ }
181
+
182
+ _applyResizePosition() {
183
+ this._resizeFrameId = null;
184
+ if (this._pointerId === null) return;
185
+
186
+ const deltaX = this._currentX - this._startX;
187
+ const deltaY = this._currentY - this._startY;
188
+ let width = this._startWidth;
189
+ let height = this._startHeight;
190
+ let left = this._startLeft;
191
+ let top = this._startTop;
192
+
193
+ if (this._direction.includes('e')) {
194
+ const maxWidth = Math.max(this._options.minWidth, window.innerWidth - this._startLeft);
195
+ width = Math.min(maxWidth, Math.max(this._options.minWidth, this._startWidth + deltaX));
196
+ }
197
+
198
+ if (this._direction.includes('s')) {
199
+ const maxHeight = Math.max(this._options.minHeight, window.innerHeight - this._startTop);
200
+ height = Math.min(maxHeight, Math.max(this._options.minHeight, this._startHeight + deltaY));
201
+ }
202
+
203
+ if (this._direction.includes('w')) {
204
+ const maxLeft = this._startRight - this._options.minWidth;
205
+ left = Math.min(maxLeft, Math.max(0, this._startLeft + deltaX));
206
+ width = this._startRight - left;
207
+ }
208
+
209
+ if (this._direction.includes('n')) {
210
+ const maxTop = this._startBottom - this._options.minHeight;
211
+ top = Math.min(maxTop, Math.max(0, this._startTop + deltaY));
212
+ height = this._startBottom - top;
213
+ }
214
+
215
+ this._dialogElement.style.left = `${left}px`;
216
+ this._dialogElement.style.top = `${top}px`;
217
+ this._dialogElement.style.width = `${width}px`;
218
+ this._dialogElement.style.height = `${height}px`;
219
+ this._updateDebugValues();
220
+
221
+ }
222
+
223
+ _onPointerUp(event) {
224
+ if (event.pointerId !== this._pointerId) return;
225
+
226
+ document.removeEventListener('pointermove', this._onPointerMove);
227
+ document.removeEventListener('pointerup', this._onPointerUp);
228
+ document.removeEventListener('pointercancel', this._onPointerUp);
229
+ this._cancelResizeFrame();
230
+ this._applyResizePosition();
229
231
  this._pointerId = null;
230
232
  this._direction = '';
231
233
  delete this._modalElement.dataset.vgModalResizing;
@@ -233,116 +235,116 @@ class VGModalResize {
233
235
  this._setDebugVisibility(this._options.debug);
234
236
  this._updateDebugValues();
235
237
  }
236
-
237
- _onPointerLeave() {
238
- if (this._pointerId !== null) return;
239
- this._dialogElement.style.cursor = '';
240
- }
241
-
242
- _getDirectionFromPointer(event) {
243
- const rect = this._dialogElement.getBoundingClientRect();
244
- const offsetX = event.clientX - rect.left;
245
- const offsetY = event.clientY - rect.top;
246
- const edgeSize = this._options.edgeSize;
247
- const insideDialog = offsetX >= 0 && offsetX <= rect.width && offsetY >= 0 && offsetY <= rect.height;
248
- if (!insideDialog) return '';
249
-
250
- const nearTop = offsetY >= 0 && offsetY <= edgeSize;
251
- const nearBottom = offsetY <= rect.height && offsetY >= rect.height - edgeSize;
252
- const nearLeft = offsetX >= 0 && offsetX <= edgeSize;
253
- const nearRight = offsetX <= rect.width && offsetX >= rect.width - edgeSize;
254
-
255
- if (nearTop && nearLeft) return 'nw';
256
- if (nearTop && nearRight) return 'ne';
257
- if (nearBottom && nearLeft) return 'sw';
258
- if (nearBottom && nearRight) return 'se';
259
- if (nearTop) return 'n';
260
- if (nearBottom) return 's';
261
- if (nearLeft) return 'w';
262
- if (nearRight) return 'e';
263
-
264
- return '';
265
- }
266
-
267
- _preparePosition(rect) {
268
- this._dialogElement.style.position = 'fixed';
269
- this._dialogElement.style.margin = '0';
270
- this._dialogElement.style.left = `${rect.left}px`;
271
- this._dialogElement.style.top = `${rect.top}px`;
272
- this._dialogElement.style.width = `${rect.width}px`;
273
- this._dialogElement.style.height = `${rect.height}px`;
274
- this._dialogElement.style.transform = 'none';
275
- }
276
-
277
- _isPreparedForInteraction() {
278
- return this._dialogElement.style.position === 'fixed' && this._dialogElement.style.transform === 'none';
279
- }
280
-
281
- _startObserveSizeChanges() {
282
- if (typeof ResizeObserver === 'undefined' || this._observer) return;
283
-
284
- this._observer = new ResizeObserver(() => {
285
- if (this._pointerId !== null) return;
286
- if (this._modalElement && this._modalElement.dataset.vgModalDragging === 'true') return;
287
- if (this._syncFrameId !== null) return;
288
-
289
- this._syncFrameId = window.requestAnimationFrame(() => {
290
- this._syncFrameId = null;
291
- this.syncToViewport();
292
- });
293
- });
294
-
295
- this._observer.observe(this._dialogElement);
296
- }
297
-
298
- _stopObserveSizeChanges() {
299
- if (this._observer) {
300
- this._observer.disconnect();
301
- this._observer = null;
302
- }
303
-
304
- if (this._syncFrameId !== null) {
305
- window.cancelAnimationFrame(this._syncFrameId);
306
- this._syncFrameId = null;
307
- }
308
- }
309
-
310
- _applyResizeStyles() {
311
- this._previousMaxWidth = this._dialogElement.style.maxWidth;
312
- this._previousMaxHeight = this._dialogElement.style.maxHeight;
313
- this._previousPointerEvents = this._dialogElement.style.pointerEvents;
314
- this._previousMinHeight = this._dialogElement.style.minHeight;
315
- this._previousOverflow = this._dialogElement.style.overflow;
316
- this._previousTransition = this._dialogElement.style.transition;
317
- this._previousWillChange = this._dialogElement.style.willChange;
318
-
319
- this._dialogElement.style.maxWidth = 'none';
320
- this._dialogElement.style.maxHeight = 'none';
321
- this._dialogElement.style.pointerEvents = 'auto';
322
- this._dialogElement.style.minHeight = `${this._options.minHeight}px`;
323
- this._dialogElement.style.overflow = 'hidden';
324
- this._dialogElement.style.transition = 'none';
325
- this._dialogElement.style.willChange = 'left, top, width, height';
326
-
327
- if (this._contentElement) {
328
- this._previousContentHeight = this._contentElement.style.height;
329
- this._previousContentMaxHeight = this._contentElement.style.maxHeight;
330
- this._previousContentOverflow = this._contentElement.style.overflow;
331
- this._contentElement.style.height = '100%';
332
- this._contentElement.style.maxHeight = '100%';
333
- this._contentElement.style.overflow = 'auto';
334
- }
335
- }
336
-
238
+
239
+ _onPointerLeave() {
240
+ if (this._pointerId !== null) return;
241
+ this._dialogElement.style.cursor = '';
242
+ }
243
+
244
+ _getDirectionFromPointer(event) {
245
+ const rect = this._dialogElement.getBoundingClientRect();
246
+ const offsetX = event.clientX - rect.left;
247
+ const offsetY = event.clientY - rect.top;
248
+ const edgeSize = this._options.edgeSize;
249
+ const insideDialog = offsetX >= 0 && offsetX <= rect.width && offsetY >= 0 && offsetY <= rect.height;
250
+ if (!insideDialog) return '';
251
+
252
+ const nearTop = offsetY >= 0 && offsetY <= edgeSize;
253
+ const nearBottom = offsetY <= rect.height && offsetY >= rect.height - edgeSize;
254
+ const nearLeft = offsetX >= 0 && offsetX <= edgeSize;
255
+ const nearRight = offsetX <= rect.width && offsetX >= rect.width - edgeSize;
256
+
257
+ if (nearTop && nearLeft) return 'nw';
258
+ if (nearTop && nearRight) return 'ne';
259
+ if (nearBottom && nearLeft) return 'sw';
260
+ if (nearBottom && nearRight) return 'se';
261
+ if (nearTop) return 'n';
262
+ if (nearBottom) return 's';
263
+ if (nearLeft) return 'w';
264
+ if (nearRight) return 'e';
265
+
266
+ return '';
267
+ }
268
+
269
+ _preparePosition(rect) {
270
+ this._dialogElement.style.position = 'fixed';
271
+ this._dialogElement.style.margin = '0';
272
+ this._dialogElement.style.left = `${rect.left}px`;
273
+ this._dialogElement.style.top = `${rect.top}px`;
274
+ this._dialogElement.style.width = `${rect.width}px`;
275
+ this._dialogElement.style.height = `${rect.height}px`;
276
+ this._dialogElement.style.transform = 'none';
277
+ }
278
+
279
+ _isPreparedForInteraction() {
280
+ return this._dialogElement.style.position === 'fixed' && this._dialogElement.style.transform === 'none';
281
+ }
282
+
283
+ _startObserveSizeChanges() {
284
+ if (typeof ResizeObserver === 'undefined' || this._observer) return;
285
+
286
+ this._observer = new ResizeObserver(() => {
287
+ if (this._pointerId !== null) return;
288
+ if (this._modalElement && this._modalElement.dataset.vgModalDragging === 'true') return;
289
+ if (this._syncFrameId !== null) return;
290
+
291
+ this._syncFrameId = window.requestAnimationFrame(() => {
292
+ this._syncFrameId = null;
293
+ this.syncToViewport();
294
+ });
295
+ });
296
+
297
+ this._observer.observe(this._dialogElement);
298
+ }
299
+
300
+ _stopObserveSizeChanges() {
301
+ if (this._observer) {
302
+ this._observer.disconnect();
303
+ this._observer = null;
304
+ }
305
+
306
+ if (this._syncFrameId !== null) {
307
+ window.cancelAnimationFrame(this._syncFrameId);
308
+ this._syncFrameId = null;
309
+ }
310
+ }
311
+
312
+ _applyResizeStyles() {
313
+ this._previousMaxWidth = this._dialogElement.style.maxWidth;
314
+ this._previousMaxHeight = this._dialogElement.style.maxHeight;
315
+ this._previousPointerEvents = this._dialogElement.style.pointerEvents;
316
+ this._previousMinHeight = this._dialogElement.style.minHeight;
317
+ this._previousOverflow = this._dialogElement.style.overflow;
318
+ this._previousTransition = this._dialogElement.style.transition;
319
+ this._previousWillChange = this._dialogElement.style.willChange;
320
+
321
+ this._dialogElement.style.maxWidth = 'none';
322
+ this._dialogElement.style.maxHeight = 'none';
323
+ this._dialogElement.style.pointerEvents = 'auto';
324
+ this._dialogElement.style.minHeight = `${this._options.minHeight}px`;
325
+ this._dialogElement.style.overflow = 'hidden';
326
+ this._dialogElement.style.transition = 'none';
327
+ this._dialogElement.style.willChange = 'left, top, width, height';
328
+
329
+ if (this._contentElement) {
330
+ this._previousContentHeight = this._contentElement.style.height;
331
+ this._previousContentMaxHeight = this._contentElement.style.maxHeight;
332
+ this._previousContentOverflow = this._contentElement.style.overflow;
333
+ this._contentElement.style.height = '100%';
334
+ this._contentElement.style.maxHeight = '100%';
335
+ this._contentElement.style.overflow = 'auto';
336
+ }
337
+ }
338
+
337
339
  _restoreResizeStyles() {
338
340
  this._dialogElement.style.maxWidth = this._previousMaxWidth;
339
341
  this._dialogElement.style.maxHeight = this._previousMaxHeight;
340
342
  this._dialogElement.style.pointerEvents = this._previousPointerEvents;
341
- this._dialogElement.style.minHeight = this._previousMinHeight;
342
- this._dialogElement.style.overflow = this._previousOverflow;
343
- this._dialogElement.style.transition = this._previousTransition;
344
- this._dialogElement.style.willChange = this._previousWillChange;
345
-
343
+ this._dialogElement.style.minHeight = this._previousMinHeight;
344
+ this._dialogElement.style.overflow = this._previousOverflow;
345
+ this._dialogElement.style.transition = this._previousTransition;
346
+ this._dialogElement.style.willChange = this._previousWillChange;
347
+
346
348
  if (this._contentElement) {
347
349
  this._contentElement.style.height = this._previousContentHeight;
348
350
  this._contentElement.style.maxHeight = this._previousContentMaxHeight;
@@ -351,85 +353,85 @@ class VGModalResize {
351
353
  }
352
354
 
353
355
  _normalizeOptions(options, base = DEFAULT_OPTIONS) {
354
- const merged = {...base, ...options};
355
- const minWidth = Number(merged.minWidth);
356
- const minHeight = Number(merged.minHeight);
357
- const edgeSize = Number(merged.edgeSize);
358
-
359
- return {
360
- ...merged,
361
- minWidth: Number.isFinite(minWidth) && minWidth > 0 ? minWidth : DEFAULT_OPTIONS.minWidth,
362
- minHeight: Number.isFinite(minHeight) && minHeight > 0 ? minHeight : DEFAULT_OPTIONS.minHeight,
363
- edgeSize: Number.isFinite(edgeSize) && edgeSize > 0 ? edgeSize : DEFAULT_OPTIONS.edgeSize,
364
- debug: Boolean(merged.debug),
365
- };
366
- }
367
-
368
- _cancelResizeFrame() {
369
- if (this._resizeFrameId === null) return;
370
- window.cancelAnimationFrame(this._resizeFrameId);
371
- this._resizeFrameId = null;
372
- }
373
-
374
- _lockEmbeddedFrames() {
375
- if (!this._dialogElement || this._lockedIframes.length) return;
376
-
377
- const iframes = this._dialogElement.querySelectorAll('iframe');
378
- for (const frame of iframes) {
379
- this._lockedIframes.push({
380
- element: frame,
381
- pointerEvents: frame.style.pointerEvents,
382
- });
383
- frame.style.pointerEvents = 'none';
384
- }
385
- }
386
-
387
- _unlockEmbeddedFrames() {
388
- if (!this._lockedIframes.length) return;
389
-
390
- for (const item of this._lockedIframes) {
391
- item.element.style.pointerEvents = item.pointerEvents;
392
- }
393
- this._lockedIframes = [];
394
- }
395
-
396
- _updateDebugOverlay() {
397
- if (!this._options.debug) {
398
- this._setDebugVisibility(false);
399
- return;
400
- }
401
-
402
- if (!this._debugElement) {
403
- this._debugElement = document.createElement('div');
404
- this._debugElement.style.position = 'absolute';
405
- this._debugElement.style.left = '8px';
406
- this._debugElement.style.bottom = '8px';
407
- this._debugElement.style.zIndex = '6';
408
- this._debugElement.style.padding = '4px 6px';
409
- this._debugElement.style.borderRadius = '4px';
410
- this._debugElement.style.background = 'rgba(0, 0, 0, 0.72)';
411
- this._debugElement.style.color = '#fff';
412
- this._debugElement.style.fontSize = '11px';
413
- this._debugElement.style.lineHeight = '1.3';
414
- this._debugElement.style.pointerEvents = 'none';
415
- this._dialogElement.append(this._debugElement);
416
- }
417
-
356
+ const merged = {...base, ...options};
357
+ const minWidth = Number(merged.minWidth);
358
+ const minHeight = Number(merged.minHeight);
359
+ const edgeSize = Number(merged.edgeSize);
360
+
361
+ return {
362
+ ...merged,
363
+ minWidth: Number.isFinite(minWidth) && minWidth > 0 ? minWidth : DEFAULT_OPTIONS.minWidth,
364
+ minHeight: Number.isFinite(minHeight) && minHeight > 0 ? minHeight : DEFAULT_OPTIONS.minHeight,
365
+ edgeSize: Number.isFinite(edgeSize) && edgeSize > 0 ? edgeSize : DEFAULT_OPTIONS.edgeSize,
366
+ debug: Boolean(merged.debug),
367
+ };
368
+ }
369
+
370
+ _cancelResizeFrame() {
371
+ if (this._resizeFrameId === null) return;
372
+ window.cancelAnimationFrame(this._resizeFrameId);
373
+ this._resizeFrameId = null;
374
+ }
375
+
376
+ _lockEmbeddedFrames() {
377
+ if (!this._dialogElement || this._lockedIframes.length) return;
378
+
379
+ const iframes = this._dialogElement.querySelectorAll('iframe');
380
+ for (const frame of iframes) {
381
+ this._lockedIframes.push({
382
+ element: frame,
383
+ pointerEvents: frame.style.pointerEvents,
384
+ });
385
+ frame.style.pointerEvents = 'none';
386
+ }
387
+ }
388
+
389
+ _unlockEmbeddedFrames() {
390
+ if (!this._lockedIframes.length) return;
391
+
392
+ for (const item of this._lockedIframes) {
393
+ item.element.style.pointerEvents = item.pointerEvents;
394
+ }
395
+ this._lockedIframes = [];
396
+ }
397
+
398
+ _updateDebugOverlay() {
399
+ if (!this._options.debug) {
400
+ this._setDebugVisibility(false);
401
+ return;
402
+ }
403
+
404
+ if (!this._debugElement) {
405
+ this._debugElement = document.createElement('div');
406
+ this._debugElement.style.position = 'absolute';
407
+ this._debugElement.style.left = '8px';
408
+ this._debugElement.style.bottom = '8px';
409
+ this._debugElement.style.zIndex = '6';
410
+ this._debugElement.style.padding = '4px 6px';
411
+ this._debugElement.style.borderRadius = '4px';
412
+ this._debugElement.style.background = 'rgba(0, 0, 0, 0.72)';
413
+ this._debugElement.style.color = '#fff';
414
+ this._debugElement.style.fontSize = '11px';
415
+ this._debugElement.style.lineHeight = '1.3';
416
+ this._debugElement.style.pointerEvents = 'none';
417
+ this._dialogElement.append(this._debugElement);
418
+ }
419
+
418
420
  this._setDebugVisibility(true);
419
421
  this._updateDebugValues();
420
422
  }
421
-
422
- _setDebugVisibility(visible) {
423
- if (!this._debugElement) return;
424
- this._debugElement.style.display = visible ? 'block' : 'none';
425
- }
426
-
427
- _updateDebugValues() {
428
- if (!this._debugElement || !this._options.debug) return;
429
-
430
- const rect = this._dialogElement.getBoundingClientRect();
431
- this._debugElement.textContent = `w:${Math.round(rect.width)} h:${Math.round(rect.height)} x:${Math.round(rect.left)} y:${Math.round(rect.top)}`;
432
- }
433
- }
434
-
435
- export default VGModalResize;
423
+
424
+ _setDebugVisibility(visible) {
425
+ if (!this._debugElement) return;
426
+ this._debugElement.style.display = visible ? 'block' : 'none';
427
+ }
428
+
429
+ _updateDebugValues() {
430
+ if (!this._debugElement || !this._options.debug) return;
431
+
432
+ const rect = this._dialogElement.getBoundingClientRect();
433
+ this._debugElement.textContent = `w:${Math.round(rect.width)} h:${Math.round(rect.height)} x:${Math.round(rect.left)} y:${Math.round(rect.top)}`;
434
+ }
435
+ }
436
+
437
+ export default VGModalResize;