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