emacroh5lib 1.0.15 → 1.0.19

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,876 +0,0 @@
1
- import { Component, Prop, Vue, Watch } from "vue-property-decorator";
2
-
3
-
4
- const styleMapping = {
5
- y: {
6
- t: 'top',
7
- m: 'marginTop',
8
- b: 'bottom',
9
- },
10
- x: {
11
- l: 'left',
12
- m: 'marginLeft',
13
- r: 'right',
14
- },
15
- };
16
-
17
- function addEvents(events) {
18
- events.forEach((cb, eventName) => {
19
- document.documentElement.addEventListener(eventName, cb);
20
- });
21
- }
22
-
23
- function removeEvents(events) {
24
- events.forEach((cb, eventName) => {
25
- document.documentElement.removeEventListener(eventName, cb);
26
- });
27
- }
28
-
29
-
30
-
31
- @Component({ name: 'DragResizeViewTs' })
32
- export default class DragResizeViewTs extends Vue {
33
-
34
-
35
- @Prop({
36
- type: String,
37
- required: false,
38
- default: ''
39
- }) name;
40
-
41
-
42
- @Prop({ type: Number, default: 8 }) stickSize;
43
- @Prop({ type: Number, default: 1 }) parentScaleX;
44
- @Prop({ type: Number, default: 1 }) parentScaleY;
45
- @Prop({ type: Boolean, default: false, }) isActive;
46
- @Prop({ type: Boolean, default: false, }) preventActiveBehavior;
47
- @Prop({ type: Boolean, default: true, }) isDraggable;
48
- @Prop({ type: Boolean, default: true, }) isResizable;
49
- @Prop({ type: Boolean, default: false, }) aspectRatio;
50
- @Prop({
51
- type: Boolean, default: false,
52
- }) parentLimitation;
53
- @Prop({
54
- type: Boolean, default: false,
55
- }) snapToGrid;
56
-
57
- @Prop({
58
- type: Number,
59
- default: 50,
60
- validator(val) {
61
- return val >= 0;
62
- },
63
- }) gridX;
64
-
65
- @Prop({
66
- type: Number,
67
- default: 50,
68
- validator(val) {
69
- return val >= 0;
70
- },
71
- }) gridY;
72
-
73
- @Prop({
74
- type: Number,
75
- default: 0,
76
- validator(val) {
77
- return val >= 0;
78
- },
79
- }) parentW;
80
-
81
- @Prop({
82
- type: Number,
83
- default: 0,
84
- validator(val) {
85
- return val >= 0;
86
- },
87
- }) parentH;
88
-
89
- @Prop({
90
- type: [String, Number],
91
- default: 200,
92
- validator(val) {
93
- return (typeof val === 'string') ? val === 'auto' : val >= 0;
94
- },
95
- }) w;
96
-
97
- @Prop({
98
- type: [String, Number],
99
- default: 200,
100
- validator(val) {
101
- return (typeof val === 'string') ? val === 'auto' : val >= 0;
102
- },
103
- }) h;
104
-
105
- @Prop({
106
- type: Number,
107
- default: 50,
108
- validator(val) {
109
- return val >= 0;
110
- },
111
- }) minw;
112
-
113
- @Prop({
114
- type: Number,
115
- default: 50,
116
- validator(val) {
117
- return val >= 0;
118
- },
119
- }) minh;
120
-
121
- @Prop({
122
- type: Number,
123
- default: 0,
124
- validator(val) {
125
- return typeof val === 'number';
126
- },
127
- }) x;
128
-
129
- @Prop({
130
- type: Number,
131
- default: 0,
132
- validator(val) {
133
- return typeof val === 'number';
134
- },
135
- }) y;
136
- @Prop({
137
- type: [String, Number],
138
- default: 'auto',
139
- validator(val) {
140
- return (typeof val === 'string') ? val === 'auto' : val >= 0;
141
- },
142
- }) z;
143
- @Prop({
144
- type: String,
145
- default: null,
146
- }) dragHandle;
147
-
148
- @Prop({
149
- type: String,
150
- default: null,
151
- }) dragCancel;
152
-
153
- @Prop({
154
- type: Array,
155
- default() {
156
- return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'];
157
- },
158
- }) sticks;
159
-
160
- @Prop({
161
- type: String,
162
- default: 'both',
163
- validator(val) {
164
- return ['x', 'y', 'both', 'none'].indexOf(val) !== -1;
165
- },
166
- }) axis;
167
-
168
- @Prop({
169
- type: String,
170
- required: false,
171
- default: '',
172
- }) contentClass;
173
-
174
- @Prop({
175
- type: Boolean,
176
- required: false,
177
- default: false
178
- }) isStorage;
179
-
180
- public emits = ['clicked', 'dragging', 'dragstop', 'resizing', 'resizestop', 'activated', 'deactivated']
181
-
182
- public fixAspectRatio = null
183
- public active = false
184
- public zIndex?;
185
- public parentWidth?;
186
- public parentHeight?;
187
- public left;
188
- public top?;
189
- public right?;
190
- public bottom?;
191
- public minHeight?;
192
- public stickDrag = false;
193
- public bodyDrag = false;
194
- public dimensionsBeforeMove: any;
195
- public limits: any;
196
- public currentStick: any;
197
- public aspectFactor: any;
198
- public domEvents: any;
199
- public parentElement: any;
200
- public _uid: any;
201
-
202
- beforeCreate() {
203
- this.stickDrag = false;
204
- this.bodyDrag = false;
205
- this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
206
- this.limits = {
207
- left: { min: null, max: null },
208
- right: { min: null, max: null },
209
- top: { min: null, max: null },
210
- bottom: { min: null, max: null },
211
- };
212
-
213
- this.currentStick = null;
214
- }
215
-
216
-
217
- mounted() {
218
- this.parentElement = this.$el.parentNode;
219
- this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth;
220
- this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight;
221
-
222
- this.left = this.x;
223
- this.top = this.y;
224
- this.right = this.parentWidth - (this.w === 'auto' ? (this.$refs.container as HTMLElement).scrollWidth : this.w) - this.left;
225
- this.bottom = this.parentHeight - (this.h === 'auto' ? (this.$refs.container as HTMLElement).scrollHeight : this.h) - this.top;
226
-
227
- this.domEvents = new Map([
228
- ['mousemove', this.move],
229
- ['mouseup', this.up],
230
- ['mouseleave', this.up],
231
- ['mousedown', this.deselect],
232
- ['touchmove', this.move],
233
- ['touchend', this.up],
234
- ['touchcancel', this.up],
235
- ['touchstart', this.up],
236
- ]);
237
-
238
- addEvents(this.domEvents);
239
-
240
- if (this.dragHandle) {
241
- [...this.$el.querySelectorAll(this.dragHandle)].forEach((dragHandle) => {
242
- dragHandle.setAttribute('data-drag-handle', this._uid);
243
- });
244
- }
245
-
246
- if (this.dragCancel) {
247
- [...this.$el.querySelectorAll(this.dragCancel)].forEach((cancelHandle) => {
248
- cancelHandle.setAttribute('data-drag-cancel', this._uid);
249
- });
250
- }
251
-
252
- if (this.name.trim() !== '' && this.isStorage) {
253
- let info = JSON.parse(localStorage.getItem("DragResizeView_Info_" + this.name) as string)
254
- if (info !== null) {
255
- this.left = info.left
256
- this.top = info.top
257
- this.right = info.right
258
- this.bottom = info.bottom
259
- }
260
- }
261
- }
262
-
263
- beforeDestroy() {
264
- removeEvents(this.domEvents);
265
- }
266
-
267
- deselect() {
268
- if (this.preventActiveBehavior) {
269
- return;
270
- }
271
- this.active = false;
272
- }
273
-
274
- move(ev) {
275
- if (!this.stickDrag && !this.bodyDrag) {
276
- return;
277
- }
278
-
279
- ev.stopPropagation();
280
-
281
- const pageX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
282
- const pageY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
283
-
284
- const { dimensionsBeforeMove } = this;
285
-
286
- const delta = {
287
- x: (dimensionsBeforeMove.pointerX - pageX) / this.parentScaleX,
288
- y: (dimensionsBeforeMove.pointerY - pageY) / this.parentScaleY,
289
- };
290
-
291
- if (this.stickDrag) {
292
- this.stickMove(delta);
293
- }
294
-
295
- if (this.bodyDrag) {
296
- if (this.axis === 'x') {
297
- delta.y = 0;
298
- } else if (this.axis === 'y') {
299
- delta.x = 0;
300
- } else if (this.axis === 'none') {
301
- return;
302
- }
303
- this.bodyMove(delta);
304
- }
305
- }
306
-
307
- up(ev) {
308
- if (this.stickDrag) {
309
- this.stickUp();
310
- } else if (this.bodyDrag) {
311
- this.bodyUp();
312
- }
313
-
314
- }
315
-
316
-
317
- bodyDown(ev) {
318
- const { target, button } = ev;
319
-
320
- if (!this.preventActiveBehavior) {
321
- this.active = true;
322
- }
323
-
324
- if (button && button !== 0) {
325
- return;
326
- }
327
-
328
- this.$emit('clicked', ev);
329
-
330
- if (!this.active) {
331
- return;
332
- }
333
-
334
- if (this.dragHandle && target.getAttribute('data-drag-handle') !== this._uid.toString()) {
335
- return;
336
- }
337
-
338
- if (this.dragCancel && target.getAttribute('data-drag-cancel') === this._uid.toString()) {
339
- return;
340
- }
341
-
342
- if (typeof ev.stopPropagation !== 'undefined') {
343
- ev.stopPropagation();
344
- }
345
-
346
- if (typeof ev.preventDefault !== 'undefined') {
347
- ev.preventDefault();
348
- }
349
-
350
- if (this.isDraggable) {
351
- this.bodyDrag = true;
352
- }
353
-
354
- const pointerX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
355
- const pointerY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
356
-
357
- this.saveDimensionsBeforeMove({ pointerX, pointerY });
358
-
359
- if (this.parentLimitation) {
360
- this.limits = this.calcDragLimitation();
361
- }
362
- }
363
-
364
- bodyMove(delta) {
365
- const { dimensionsBeforeMove, parentWidth, parentHeight, gridX, gridY, width, height } = this;
366
-
367
- let newTop = dimensionsBeforeMove.top - delta.y;
368
- let newBottom = dimensionsBeforeMove.bottom + delta.y;
369
- let newLeft = dimensionsBeforeMove.left - delta.x;
370
- let newRight = dimensionsBeforeMove.right + delta.x;
371
-
372
- if (this.snapToGrid) {
373
- let alignTop = true;
374
- let alignLeft = true;
375
-
376
- let diffT = newTop - Math.floor(newTop / gridY) * gridY;
377
- let diffB = (parentHeight - newBottom) - Math.floor((parentHeight - newBottom) / gridY) * gridY;
378
- let diffL = newLeft - Math.floor(newLeft / gridX) * gridX;
379
- let diffR = (parentWidth - newRight) - Math.floor((parentWidth - newRight) / gridX) * gridX;
380
-
381
- if (diffT > (gridY / 2)) {
382
- diffT -= gridY;
383
- }
384
- if (diffB > (gridY / 2)) {
385
- diffB -= gridY;
386
- }
387
- if (diffL > (gridX / 2)) {
388
- diffL -= gridX;
389
- }
390
- if (diffR > (gridX / 2)) {
391
- diffR -= gridX;
392
- }
393
-
394
- if (Math.abs(diffB) < Math.abs(diffT)) {
395
- alignTop = false;
396
- }
397
- if (Math.abs(diffR) < Math.abs(diffL)) {
398
- alignLeft = false;
399
- }
400
-
401
- newTop -= (alignTop ? diffT : diffB);
402
- newBottom = parentHeight - height - newTop;
403
- newLeft -= (alignLeft ? diffL : diffR);
404
- newRight = parentWidth - width - newLeft;
405
- }
406
-
407
- ({
408
- newLeft: this.left,
409
- newRight: this.right,
410
- newTop: this.top,
411
- newBottom: this.bottom,
412
- } = this.rectCorrectionByLimit({ newLeft, newRight, newTop, newBottom }));
413
-
414
- this.$emit('dragging', this.rect);
415
-
416
- this.storageElementInfo();
417
- }
418
-
419
- bodyUp() {
420
- this.bodyDrag = false;
421
- this.$emit('dragging', this.rect);
422
- this.$emit('dragstop', this.rect);
423
-
424
- this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
425
-
426
- this.limits = {
427
- left: { min: null, max: null },
428
- right: { min: null, max: null },
429
- top: { min: null, max: null },
430
- bottom: { min: null, max: null },
431
- };
432
- }
433
-
434
- stickDown(stick, ev, force = false) {
435
- if ((!this.isResizable || !this.active) && !force) {
436
- return;
437
- }
438
-
439
- this.stickDrag = true;
440
-
441
- const pointerX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
442
- const pointerY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
443
-
444
- this.saveDimensionsBeforeMove({ pointerX, pointerY });
445
-
446
- this.currentStick = stick;
447
-
448
- this.limits = this.calcResizeLimits();
449
- }
450
-
451
- saveDimensionsBeforeMove({ pointerX, pointerY }) {
452
- this.dimensionsBeforeMove.pointerX = pointerX;
453
- this.dimensionsBeforeMove.pointerY = pointerY;
454
-
455
- this.dimensionsBeforeMove.left = this.left;
456
- this.dimensionsBeforeMove.right = this.right;
457
- this.dimensionsBeforeMove.top = this.top;
458
- this.dimensionsBeforeMove.bottom = this.bottom;
459
-
460
- this.dimensionsBeforeMove.width = this.width;
461
- this.dimensionsBeforeMove.height = this.height;
462
-
463
- this.aspectFactor = this.width / this.height;
464
- }
465
-
466
- stickMove(delta) {
467
- const {
468
- currentStick,
469
- dimensionsBeforeMove,
470
- gridY,
471
- gridX,
472
- snapToGrid,
473
- parentHeight,
474
- parentWidth,
475
- } = this;
476
-
477
- let newTop = dimensionsBeforeMove.top;
478
- let newBottom = dimensionsBeforeMove.bottom;
479
- let newLeft = dimensionsBeforeMove.left;
480
- let newRight = dimensionsBeforeMove.right;
481
- switch (currentStick[0]) {
482
- case 'b':
483
- newBottom = dimensionsBeforeMove.bottom + delta.y;
484
-
485
- if (snapToGrid) {
486
- newBottom = parentHeight - Math.round((parentHeight - newBottom) / gridY) * gridY;
487
- }
488
-
489
- break;
490
-
491
- case 't':
492
- newTop = dimensionsBeforeMove.top - delta.y;
493
-
494
- if (snapToGrid) {
495
- newTop = Math.round(newTop / gridY) * gridY;
496
- }
497
-
498
- break;
499
- default:
500
- break;
501
- }
502
-
503
- switch (currentStick[1]) {
504
- case 'r':
505
- newRight = dimensionsBeforeMove.right + delta.x;
506
-
507
- if (snapToGrid) {
508
- newRight = parentWidth - Math.round((parentWidth - newRight) / gridX) * gridX;
509
- }
510
-
511
- break;
512
-
513
- case 'l':
514
- newLeft = dimensionsBeforeMove.left - delta.x;
515
-
516
- if (snapToGrid) {
517
- newLeft = Math.round(newLeft / gridX) * gridX;
518
- }
519
-
520
- break;
521
- default:
522
- break;
523
- }
524
-
525
- ({
526
- newLeft,
527
- newRight,
528
- newTop,
529
- newBottom,
530
- } = this.rectCorrectionByLimit({ newLeft, newRight, newTop, newBottom }));
531
-
532
- if (this.aspectRatio) {
533
- ({
534
- newLeft,
535
- newRight,
536
- newTop,
537
- newBottom,
538
- } = this.rectCorrectionByAspectRatio({ newLeft, newRight, newTop, newBottom }));
539
- }
540
-
541
- this.left = newLeft;
542
- this.right = newRight;
543
- this.top = newTop;
544
- this.bottom = newBottom;
545
-
546
- this.$emit('resizing', this.rect);
547
-
548
- this.storageElementInfo()
549
- }
550
-
551
- stickUp() {
552
- this.stickDrag = false;
553
- this.dimensionsBeforeMove = {
554
- pointerX: 0,
555
- pointerY: 0,
556
- x: 0,
557
- y: 0,
558
- w: 0,
559
- h: 0,
560
- };
561
- this.limits = {
562
- left: { min: null, max: null },
563
- right: { min: null, max: null },
564
- top: { min: null, max: null },
565
- bottom: { min: null, max: null },
566
- };
567
-
568
- this.$emit('resizing', this.rect);
569
- this.$emit('resizestop', this.rect);
570
- }
571
-
572
- calcDragLimitation() {
573
- const { parentWidth, parentHeight } = this;
574
-
575
- return {
576
- left: { min: 0, max: parentWidth - this.width },
577
- right: { min: 0, max: parentWidth - this.width },
578
- top: { min: 0, max: parentHeight - this.height },
579
- bottom: { min: 0, max: parentHeight - this.height },
580
- };
581
- }
582
-
583
- calcResizeLimits() {
584
- const { aspectFactor, width, height, bottom, top, left, right } = this;
585
- let { minh: minHeight, minw: minWidth } = this;
586
-
587
- const parentLim = this.parentLimitation ? 0 : null;
588
-
589
- if (this.aspectRatio) {
590
- if (minWidth / minHeight > aspectFactor) {
591
- minHeight = minWidth / aspectFactor;
592
- } else {
593
- minWidth = aspectFactor * minHeight;
594
- }
595
- }
596
-
597
- const limits = {
598
- left: { min: parentLim, max: left + (width - minWidth) },
599
- right: { min: parentLim, max: right + (width - minWidth) },
600
- top: { min: parentLim, max: top + (height - minHeight) },
601
- bottom: { min: parentLim, max: bottom + (height - minHeight) },
602
- };
603
-
604
- if (this.aspectRatio) {
605
- const aspectLimits = {
606
- left: {
607
- min: left - (Math.min(top, bottom) * aspectFactor) * 2,
608
- max: left + ((((height - minHeight) / 2) * aspectFactor) * 2),
609
- },
610
- right: {
611
- min: right - (Math.min(top, bottom) * aspectFactor) * 2,
612
- max: right + ((((height - minHeight) / 2) * aspectFactor) * 2),
613
- },
614
- top: {
615
- min: top - (Math.min(left, right) / aspectFactor) * 2,
616
- max: top + ((((width - minWidth) / 2) / aspectFactor) * 2),
617
- },
618
- bottom: {
619
- min: bottom - (Math.min(left, right) / aspectFactor) * 2,
620
- max: bottom + ((((width - minWidth) / 2) / aspectFactor) * 2),
621
- },
622
- };
623
-
624
- if (this.currentStick[0] === 'm') {
625
- limits.left = {
626
- min: Math.max(limits.left.min as number, aspectLimits.left.min),
627
- max: Math.min(limits.left.max, aspectLimits.left.max),
628
- };
629
- limits.right = {
630
- min: Math.max(limits.right.min as number, aspectLimits.right.min),
631
- max: Math.min(limits.right.max, aspectLimits.right.max),
632
- };
633
-
634
- } else if (this.currentStick[1] === 'm') {
635
- limits.top = {
636
- min: Math.max(limits.top.min as number, aspectLimits.top.min),
637
- max: Math.min(limits.top.max, aspectLimits.top.max),
638
- };
639
- limits.bottom = {
640
- min: Math.max(limits.bottom.min as number, aspectLimits.bottom.min),
641
- max: Math.min(limits.bottom.max, aspectLimits.bottom.max),
642
- };
643
- }
644
- }
645
-
646
- return limits;
647
- }
648
-
649
- sideCorrectionByLimit(limit, current) {
650
- let value = current;
651
-
652
- if (limit.min !== null && current < limit.min) {
653
- value = limit.min;
654
- } else if (limit.max !== null && limit.max < current) {
655
- value = limit.max;
656
- }
657
-
658
- return value;
659
- }
660
-
661
- rectCorrectionByLimit(rect) {
662
- const { limits } = this;
663
- let { newRight, newLeft, newBottom, newTop } = rect;
664
-
665
- newLeft = this.sideCorrectionByLimit(limits.left, newLeft);
666
- newRight = this.sideCorrectionByLimit(limits.right, newRight);
667
- newTop = this.sideCorrectionByLimit(limits.top, newTop);
668
- newBottom = this.sideCorrectionByLimit(limits.bottom, newBottom);
669
-
670
- return {
671
- newLeft,
672
- newRight,
673
- newTop,
674
- newBottom,
675
- };
676
- }
677
-
678
- rectCorrectionByAspectRatio(rect) {
679
- let { newLeft, newRight, newTop, newBottom } = rect;
680
- const { parentWidth, parentHeight, currentStick, aspectFactor, dimensionsBeforeMove } = this;
681
-
682
- let newWidth = parentWidth - newLeft - newRight;
683
- let newHeight = parentHeight - newTop - newBottom;
684
-
685
- if (currentStick[1] === 'm') {
686
- const deltaHeight = newHeight - dimensionsBeforeMove.height;
687
-
688
- newLeft -= (deltaHeight * aspectFactor) / 2;
689
- newRight -= (deltaHeight * aspectFactor) / 2;
690
- } else if (currentStick[0] === 'm') {
691
- const deltaWidth = newWidth - dimensionsBeforeMove.width;
692
-
693
- newTop -= (deltaWidth / aspectFactor) / 2;
694
- newBottom -= (deltaWidth / aspectFactor) / 2;
695
- } else if (newWidth / newHeight > aspectFactor) {
696
- newWidth = aspectFactor * newHeight;
697
-
698
- if (currentStick[1] === 'l') {
699
- newLeft = parentWidth - newRight - newWidth;
700
- } else {
701
- newRight = parentWidth - newLeft - newWidth;
702
- }
703
- } else {
704
- newHeight = newWidth / aspectFactor;
705
-
706
- if (currentStick[0] === 't') {
707
- newTop = parentHeight - newBottom - newHeight;
708
- } else {
709
- newBottom = parentHeight - newTop - newHeight;
710
- }
711
- }
712
-
713
- return { newLeft, newRight, newTop, newBottom };
714
- }
715
-
716
- storageElementInfo() {
717
-
718
- if (!this.isStorage)
719
- return
720
-
721
- if (this.name.trim() === "") {
722
- throw "unspecified name"
723
- }
724
-
725
- const info = { "left": this.rect.left, "top": this.rect.top, "right": this.right, "bottom": this.bottom }
726
- localStorage.setItem("DragResizeView_Info_" + this.name, JSON.stringify(info))
727
- }
728
-
729
- get positionStyle() {
730
- return {
731
- top: this.top + 'px',
732
- left: this.left + 'px',
733
- zIndex: this.zIndex,
734
- };
735
- }
736
-
737
- get sizeStyle() {
738
- return {
739
- width: this.w == 'auto' ? 'auto' : this.width + 'px',
740
- height: this.h == 'auto' ? 'auto' : this.height + 'px'
741
- };
742
- }
743
-
744
-
745
- get vdrStick() {
746
- return (stick) => {
747
- const stickStyle = {
748
- width: `${this.stickSize / this.parentScaleX}px`,
749
- height: `${this.stickSize / this.parentScaleY}px`,
750
- };
751
- stickStyle[styleMapping.y[stick[0]]] = `${this.stickSize / this.parentScaleX / -2}px`;
752
- stickStyle[styleMapping.x[stick[1]]] = `${this.stickSize / this.parentScaleX / -2}px`;
753
- return stickStyle;
754
- };
755
- }
756
-
757
- get width() {
758
- return this.parentWidth - this.left - this.right;
759
- }
760
-
761
- get height() {
762
- return this.parentHeight - this.top - this.bottom;
763
- }
764
-
765
- get rect() {
766
- return {
767
- left: Math.round(this.left),
768
- top: Math.round(this.top),
769
- width: Math.round(this.width),
770
- height: Math.round(this.height),
771
- };
772
- }
773
-
774
- @Watch('isActive', { immediate: false, deep: false })
775
- onActive(isActive) {
776
- if (isActive) {
777
- this.$emit('activated');
778
- } else {
779
- this.$emit('deactivated');
780
- }
781
- }
782
-
783
- @Watch('isActive', { immediate: true, deep: false })
784
- onIsActive(val) {
785
- this.active = val;
786
- }
787
-
788
- @Watch('z', { immediate: true, deep: false })
789
- onZ(val) {
790
- if (val >= 0 || val === 'auto') {
791
- this.zIndex = val;
792
- }
793
- }
794
-
795
- @Watch('x', { immediate: false, deep: false })
796
- onX(newVal, oldVal) {
797
- if (this.stickDrag || this.bodyDrag || (newVal === this.left)) {
798
- return;
799
- }
800
-
801
- const delta = oldVal - newVal;
802
-
803
- this.bodyDown({ pageX: this.left, pageY: this.top });
804
- this.bodyMove({ x: delta, y: 0 });
805
-
806
- this.$nextTick(() => {
807
- this.bodyUp();
808
- });
809
- }
810
-
811
- @Watch('y', { immediate: false, deep: false })
812
- onY(newVal, oldVal) {
813
- if (this.stickDrag || this.bodyDrag || (newVal === this.top)) {
814
- return;
815
- }
816
-
817
- const delta = oldVal - newVal;
818
-
819
- this.bodyDown({ pageX: this.left, pageY: this.top });
820
- this.bodyMove({ x: 0, y: delta });
821
-
822
- this.$nextTick(() => {
823
- this.bodyUp();
824
- });
825
- }
826
-
827
- @Watch('w', { immediate: false, deep: false })
828
- onW(newVal, oldVal) {
829
- if (this.stickDrag || this.bodyDrag || (newVal === this.width)) {
830
- return;
831
- }
832
-
833
- const stick = 'mr';
834
- const delta = oldVal - newVal;
835
-
836
- this.stickDown(stick, { pageX: this.right, pageY: this.top + (this.height / 2) }, true);
837
- this.stickMove({ x: delta, y: 0 });
838
-
839
- this.$nextTick(() => {
840
- this.stickUp();
841
- });
842
- }
843
-
844
- @Watch('h', { immediate: false, deep: false })
845
- onH(newVal, oldVal) {
846
- if (this.stickDrag || this.bodyDrag || (newVal === this.height)) {
847
- return;
848
- }
849
-
850
- const stick = 'bm';
851
- const delta = oldVal - newVal;
852
-
853
- this.stickDown(stick, { pageX: this.left + (this.width / 2), pageY: this.bottom }, true);
854
- this.stickMove({ x: 0, y: delta });
855
-
856
- this.$nextTick(() => {
857
- this.stickUp();
858
- });
859
- }
860
-
861
- @Watch('parentW', { immediate: false, deep: false })
862
- onParentW(val) {
863
- this.right = val - this.width - this.left;
864
- this.parentWidth = val;
865
- }
866
-
867
-
868
- @Watch('parentH', { immediate: false, deep: false })
869
- onParentH(val) {
870
- this.bottom = val - this.height - this.top;
871
- this.parentHeight = val;
872
- }
873
-
874
- }
875
-
876
-