emacroh5lib 1.0.2 → 1.0.5

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