emacroh5lib 1.0.18 → 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.
@@ -6,14 +6,9 @@
6
6
  </slot>
7
7
 
8
8
  <div ref="sticks" :style="sticksStyle">
9
-
10
-
11
-
12
9
  <div class="tl"></div>
13
10
  <div class="lm"></div>
14
11
  <div class="lb"></div>
15
-
16
-
17
12
  </div>
18
13
 
19
14
 
@@ -21,403 +16,414 @@
21
16
  </template>
22
17
 
23
18
  <script lang="ts">
24
- import { Component, Prop, Vue, Watch } from "vue-property-decorator";
25
-
26
- const styleMapping: any = {
27
- y: {
28
- t: 'top',
29
- m: 'marginTop',
30
- b: 'bottom',
31
- },
32
- x: {
33
- l: 'left',
34
- m: 'marginLeft',
35
- r: 'right',
36
- },
37
- };
38
-
39
- function addEvents(events: any) {
40
- events.forEach((cb: any, eventName: string) => {
41
- document.documentElement.addEventListener(eventName, cb);
42
- });
43
- }
44
-
45
- @Component({
46
- components: {}
47
- })
48
- export default class DrawView extends Vue {
49
-
50
- @Prop({
51
- type: String,
52
- required: false,
53
- default: ''
54
- }) name!: string;
55
-
56
-
57
- //#region
58
-
59
-
60
- @Prop({ type: Number, default: 8 }) stickSize!: number;
61
- @Prop({ type: Number, default: 1 }) parentScaleX!: number;
62
- @Prop({ type: Number, default: 1 }) parentScaleY!: number;
63
- @Prop({ type: Boolean, default: false, }) isActive!: boolean;
64
- @Prop({ type: Boolean, default: false, }) preventActiveBehavior!: boolean;
65
- @Prop({ type: Boolean, default: true, }) isDraggable!: boolean;
66
- @Prop({ type: Boolean, default: true, }) isResizable!: boolean;
67
- @Prop({ type: Boolean, default: false, }) aspectRatio!: boolean;
68
- @Prop({
69
- type: Boolean, default: false,
70
- }) parentLimitation!: boolean;
71
- @Prop({
72
- type: Boolean, default: false,
73
- }) snapToGrid!: number;
74
-
75
- @Prop({
76
- type: Number,
77
- default: 50,
78
- validator(val) {
79
- return val >= 0;
80
- },
81
- }) gridX!: number;
19
+ import { Component, Prop, Vue, Watch } from "vue-property-decorator";
82
20
 
83
- @Prop({
84
- type: Number,
85
- default: 50,
86
- validator(val) {
87
- return val >= 0;
21
+ const styleMapping: any = {
22
+ y: {
23
+ t: 'top',
24
+ m: 'marginTop',
25
+ b: 'bottom',
88
26
  },
89
- }) gridY!: number;
90
-
91
- @Prop({
92
- type: Number,
93
- default: 0,
94
- validator(val) {
95
- return val >= 0;
27
+ x: {
28
+ l: 'left',
29
+ m: 'marginLeft',
30
+ r: 'right',
96
31
  },
97
- }) parentW!: number;
32
+ };
98
33
 
99
- @Prop({
100
- type: Number,
101
- default: 0,
102
- validator(val) {
103
- return val >= 0;
104
- },
105
- }) parentH!: number;
34
+ function addEvents(events: any) {
35
+ events.forEach((cb: any, eventName: string) => {
36
+ document.documentElement.addEventListener(eventName, cb);
37
+ });
38
+ }
106
39
 
107
- @Prop({
108
- type: [String, Number],
109
- default: 200,
110
- validator(val) {
111
- return (typeof val === 'string') ? val === 'auto' : val >= 0;
112
- },
113
- }) w!: any;
40
+ @Component({
41
+ components: {}
42
+ })
43
+ export default class DrawView extends Vue {
44
+
45
+ @Prop({
46
+ type: String,
47
+ required: false,
48
+ default: ''
49
+ }) name!: string;
50
+
51
+
52
+ //#region
53
+
54
+
55
+ @Prop({ type: Number, default: 8 }) stickSize!: number;
56
+ @Prop({ type: Number, default: 1 }) parentScaleX!: number;
57
+ @Prop({ type: Number, default: 1 }) parentScaleY!: number;
58
+ @Prop({ type: Boolean, default: false, }) isActive!: boolean;
59
+ @Prop({ type: Boolean, default: false, }) preventActiveBehavior!: boolean;
60
+ @Prop({ type: Boolean, default: true, }) isDraggable!: boolean;
61
+ @Prop({ type: Boolean, default: true, }) isResizable!: boolean;
62
+ @Prop({ type: Boolean, default: false, }) aspectRatio!: boolean;
63
+ @Prop({
64
+ type: Boolean, default: false,
65
+ }) parentLimitation!: boolean;
66
+ @Prop({
67
+ type: Boolean, default: false,
68
+ }) snapToGrid!: number;
69
+
70
+ @Prop({
71
+ type: Number,
72
+ default: 50,
73
+ validator(val) {
74
+ return val >= 0;
75
+ },
76
+ }) gridX!: number;
77
+
78
+ @Prop({
79
+ type: Number,
80
+ default: 50,
81
+ validator(val) {
82
+ return val >= 0;
83
+ },
84
+ }) gridY!: number;
85
+
86
+ @Prop({
87
+ type: Number,
88
+ default: 0,
89
+ validator(val) {
90
+ return val >= 0;
91
+ },
92
+ }) parentW!: number;
93
+
94
+ @Prop({
95
+ type: Number,
96
+ default: 0,
97
+ validator(val) {
98
+ return val >= 0;
99
+ },
100
+ }) parentH!: number;
101
+
102
+ @Prop({
103
+ type: [String, Number],
104
+ default: 200,
105
+ validator(val) {
106
+ return (typeof val === 'string') ? val === 'auto' : val >= 0;
107
+ },
108
+ }) w!: any;
109
+
110
+ @Prop({
111
+ type: [String, Number],
112
+ default: 200,
113
+ validator(val) {
114
+ return (typeof val === 'string') ? val === 'auto' : val >= 0;
115
+ },
116
+ }) h!: any;
117
+
118
+ @Prop({
119
+ type: Number,
120
+ default: 50,
121
+ validator(val) {
122
+ return val >= 0;
123
+ },
124
+ }) minw!: number;
125
+
126
+ @Prop({
127
+ type: Number,
128
+ default: 50,
129
+ validator(val) {
130
+ return val >= 0;
131
+ },
132
+ }) minh!: number;
133
+
134
+ @Prop({
135
+ type: Number,
136
+ default: 0,
137
+ validator(val) {
138
+ return typeof val === 'number';
139
+ },
140
+ }) x!: number;
141
+
142
+ @Prop({
143
+ type: Number,
144
+ default: 0,
145
+ validator(val) {
146
+ return typeof val === 'number';
147
+ },
148
+ }) y!: number;
149
+ @Prop({
150
+ type: [String, Number],
151
+ default: 'auto',
152
+ validator(val) {
153
+ return (typeof val === 'string') ? val === 'auto' : val >= 0;
154
+ },
155
+ }) z!: string | number;
156
+ @Prop({
157
+ type: String,
158
+ default: null,
159
+ }) dragHandle!: string;
160
+
161
+ @Prop({
162
+ type: String,
163
+ default: null,
164
+ }) dragCancel!: string;
165
+
166
+ @Prop({
167
+ type: Array,
168
+ default() {
169
+ return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'];
170
+ },
171
+ }) sticks!: Array<string>;
172
+
173
+ @Prop({
174
+ type: String,
175
+ default: 'both',
176
+ validator(val) {
177
+ return ['x', 'y', 'both', 'none'].indexOf(val) !== -1;
178
+ },
179
+ }) axis!: string;
180
+
181
+ @Prop({
182
+ type: String,
183
+ required: false,
184
+ default: '',
185
+ }) contentClass!: boolean;
186
+
187
+ @Prop({
188
+ type: Boolean,
189
+ required: false,
190
+ default: false
191
+ }) isStorage!: boolean;
192
+
193
+ public fixAspectRatio = null
194
+ public active = false
195
+ public zIndex: number = 0;
196
+ public parentWidth = 0;
197
+ public parentHeight = 0;
198
+ public left = 0;
199
+ public top = 0;
200
+ public right = 50;
201
+ public bottom = 50;
202
+ public minHeight = 10;
203
+ public stickDrag = false;
204
+ public bodyDrag = false;
205
+ public dimensionsBeforeMove: any;
206
+ public limits: any;
207
+ public currentStick: any;
208
+ public aspectFactor: any;
209
+ public domEvents: any;
210
+ public parentElement: any;
211
+ public _uid: any;
212
+
213
+ public slot!: HTMLElement;
214
+
215
+ width = 10
216
+ height = 10
217
+
218
+ //#endregion
219
+
220
+
221
+ get vdrStick() {
222
+ return (stick: any) => {
223
+ const stickStyle: any = {
224
+ width: `${this.stickSize / this.parentScaleX}px`,
225
+ height: `${this.stickSize / this.parentScaleY}px`
226
+ };
227
+ stickStyle[styleMapping.y[stick[0]]] = `${this.stickSize / this.parentScaleX / -2}px`;
228
+ stickStyle[styleMapping.x[stick[1]]] = `${this.stickSize / this.parentScaleX / -2}px`;
229
+ return stickStyle;
230
+ };
231
+ }
114
232
 
115
- @Prop({
116
- type: [String, Number],
117
- default: 200,
118
- validator(val) {
119
- return (typeof val === 'string') ? val === 'auto' : val >= 0;
120
- },
121
- }) h!: any;
233
+ get containerStyle() {
234
+ return {
235
+ top: this.top + 'px',
236
+ left: this.left + 'px',
237
+ boxSizing: "border-box",
238
+ position: "absolute",
239
+ };
240
+ }
122
241
 
123
- @Prop({
124
- type: Number,
125
- default: 50,
126
- validator(val) {
127
- return val >= 0;
128
- },
129
- }) minw!: number;
242
+ get sticksStyle() {
243
+
244
+ return {
245
+ top: '0px',
246
+ left: '0px',
247
+ zIndex: 0,
248
+ boxSizing: "border-box",
249
+ position: "relative",
250
+ width: this.width + 'px',
251
+ height: this.height + 'px',
252
+ pointerEvents: "none"
253
+ };
254
+ }
130
255
 
131
- @Prop({
132
- type: Number,
133
- default: 50,
134
- validator(val) {
135
- return val >= 0;
136
- },
137
- }) minh!: number;
256
+ // get contentStyle(){
257
+ // return {
258
+ // top: this.top + 'px',
259
+ // left: this.left + 'px',
260
+ // zIndex: this.zIndex,
261
+ // position: "absolute",
262
+ // boxSizing: "border-box",
263
+ // width: this.width + "px",
264
+ // height: this.height + "px",
265
+ // };
266
+ // }
138
267
 
139
- @Prop({
140
- type: Number,
141
- default: 0,
142
- validator(val) {
143
- return typeof val === 'number';
144
- },
145
- }) x!: number;
146
268
 
147
- @Prop({
148
- type: Number,
149
- default: 0,
150
- validator(val) {
151
- return typeof val === 'number';
152
- },
153
- }) y!: number;
154
- @Prop({
155
- type: [String, Number],
156
- default: 'auto',
157
- validator(val) {
158
- return (typeof val === 'string') ? val === 'auto' : val >= 0;
159
- },
160
- }) z!: string | number;
161
- @Prop({
162
- type: String,
163
- default: null,
164
- }) dragHandle!: string;
165
-
166
- @Prop({
167
- type: String,
168
- default: null,
169
- }) dragCancel!: string;
170
-
171
- @Prop({
172
- type: Array,
173
- default() {
174
- return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'];
175
- },
176
- }) sticks!: Array<string>;
177
269
 
178
- @Prop({
179
- type: String,
180
- default: 'both',
181
- validator(val) {
182
- return ['x', 'y', 'both', 'none'].indexOf(val) !== -1;
183
- },
184
- }) axis!: string;
185
-
186
- @Prop({
187
- type: String,
188
- required: false,
189
- default: '',
190
- }) contentClass!: boolean;
191
-
192
- @Prop({
193
- type: Boolean,
194
- required: false,
195
- default: false
196
- }) isStorage!: boolean;
197
-
198
- public fixAspectRatio = null
199
- public active = false
200
- public zIndex: number = 0;
201
- public parentWidth = 0;
202
- public parentHeight = 0;
203
- public left = 0;
204
- public top = 0;
205
- public right = 50;
206
- public bottom = 50;
207
- public minHeight = 10;
208
- public stickDrag = false;
209
- public bodyDrag = false;
210
- public dimensionsBeforeMove: any;
211
- public limits: any;
212
- public currentStick: any;
213
- public aspectFactor: any;
214
- public domEvents: any;
215
- public parentElement: any;
216
- public _uid: any;
217
-
218
- public slot!: HTMLElement;
219
-
220
- width = 10
221
- height = 10
222
-
223
- //#endregion
224
-
225
-
226
- get vdrStick() {
227
- return (stick: any) => {
228
- const stickStyle: any = {
229
- width: `${this.stickSize / this.parentScaleX}px`,
230
- height: `${this.stickSize / this.parentScaleY}px`
270
+ beforeCreate() {
271
+ this.stickDrag = false;
272
+ this.stickDrag = false;
273
+ this.bodyDrag = false;
274
+ this.bodyDrag = false;
275
+ this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
276
+ this.limits = {
277
+ left: { min: null, max: null },
278
+ right: { min: null, max: null },
279
+ top: { min: null, max: null },
280
+ bottom: { min: null, max: null },
231
281
  };
232
- stickStyle[styleMapping.y[stick[0]]] = `${this.stickSize / this.parentScaleX / -2}px`;
233
- stickStyle[styleMapping.x[stick[1]]] = `${this.stickSize / this.parentScaleX / -2}px`;
234
- return stickStyle;
235
- };
236
- }
237
282
 
238
- get containerStyle() {
239
- return {
240
- top: this.top + 'px',
241
- left: this.left + 'px',
242
- boxSizing: "border-box",
243
- position: "absolute",
244
- };
245
- }
283
+ this.currentStick = null;
284
+ }
246
285
 
247
- get sticksStyle() {
248
-
249
- return {
250
- top: '0px',
251
- left: '0px',
252
- zIndex: 0,
253
- boxSizing: "border-box",
254
- position: "relative",
255
- width: this.width + 'px',
256
- height: this.height + 'px',
257
- pointerEvents: "none"
258
- };
259
- }
260
286
 
261
- // get contentStyle(){
262
- // return {
263
- // top: this.top + 'px',
264
- // left: this.left + 'px',
265
- // zIndex: this.zIndex,
266
- // position: "absolute",
267
- // boxSizing: "border-box",
268
- // width: this.width + "px",
269
- // height: this.height + "px",
270
- // };
271
- // }
272
-
273
-
274
-
275
- beforeCreate() {
276
- this.stickDrag = false;
277
- this.stickDrag = false;
278
- this.bodyDrag = false;
279
- this.bodyDrag = false;
280
- this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
281
- this.limits = {
282
- left: { min: null, max: null },
283
- right: { min: null, max: null },
284
- top: { min: null, max: null },
285
- bottom: { min: null, max: null },
286
- };
287
-
288
- this.currentStick = null;
289
- }
287
+ deselect() {
288
+ // if (this.preventActiveBehavior) {
289
+ // return;
290
+ // }
291
+ // this.active = true;
292
+ }
290
293
 
294
+ mounted() {
291
295
 
292
- deselect() {
293
- // if (this.preventActiveBehavior) {
294
- // return;
295
- // }
296
- // this.active = true;
297
- }
296
+ // this.parentElement = this.$el.parentNode;
297
+ // this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth;
298
+ // this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight;
298
299
 
299
- mounted() {
300
+ this.$nextTick(() => {
301
+ // console.log("父元素", this.$slots.test);
300
302
 
301
- // this.parentElement = this.$el.parentNode;
302
- // this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth;
303
- // this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight;
304
303
 
305
- this.$nextTick(() => {
306
- // console.log("父元素", this.$slots.test);
304
+ // let style = window.getComputedStyle(this.$slots.default[0].elm, null);
305
+ // let style = window.getDefaultComputedStyle(this.$slots.default[0].elm, null);
307
306
 
307
+ // console.log("父元素", style);
308
+ console.log("父元素", this.$slots.default![0]);
308
309
 
309
- // let style = window.getComputedStyle(this.$slots.default[0].elm, null);
310
- // let style = window.getDefaultComputedStyle(this.$slots.default[0].elm, null);
310
+ this.width = this.slot.clientWidth
311
+ this.height = this.slot.clientHeight
312
+ console.log("宽度", this.slot.clientHeight);
311
313
 
312
- // console.log("父元素", style);
313
- console.log("父元素", this.$slots.default![0]);
314
+ })
314
315
 
315
- this.width = this.slot.clientWidth
316
- this.height = this.slot.clientHeight
317
- console.log("宽度", this.slot.clientHeight);
318
316
 
319
- })
317
+ let start = { x: 0, y: 0 };
320
318
 
319
+ this.slot = this.$slots.default![0].elm as HTMLElement;
321
320
 
322
- let start = { x: 0, y: 0 };
323
321
 
324
- this.slot = this.$slots.default![0].elm as HTMLElement;
325
322
 
323
+ document.addEventListener("mousemove", (e) => {
326
324
 
325
+ if (!this.active)
326
+ return
327
327
 
328
- this.slot.addEventListener("mousemove", (e) => {
328
+ e.stopPropagation()
329
329
 
330
- if (!this.active)
331
- return
332
330
 
333
- // this.active = false
331
+ // this.active = false
334
332
 
335
- // console.log("mousemove pageX", e.pageX);
336
- // console.log("mousemove", start);
333
+ // console.log("mousemove pageX", e.pageX);
334
+ // console.log("mousemove", start);
337
335
 
338
- let l = e.pageX - start.x
339
- let t = e.pageY - start.y
336
+ let l = e.pageX - start.x
337
+ let t = e.pageY - start.y
340
338
 
341
- this.top = Math.floor(this.top + t)
342
- this.left = Math.floor(this.left + l)
339
+ this.top = Math.floor(this.top + t)
340
+ this.left = Math.floor(this.left + l)
343
341
 
344
- start.x = e.pageX
345
- start.y = e.pageY
342
+ start.x = e.pageX
343
+ start.y = e.pageY
346
344
 
347
345
 
348
- // console.log("t", this.$slots.default[0].elm.style);
346
+ // console.log("t", this.$slots.default[0].elm.style);
349
347
 
350
- })
351
- this.slot.addEventListener("mousedown", (e) => {
348
+ })
349
+ document.addEventListener("mousedown", (e) => {
352
350
 
353
- console.log("mousedown", e);
354
- this.active = true
351
+ console.log("mousedown", e);
352
+ this.active = true
355
353
 
356
- e.stopPropagation();
357
- start.x = e.pageX;
358
- start.y = e.pageY;
359
- })
360
- this.slot.addEventListener("mouseleave", (e) => {
361
354
 
362
- console.log("mouseleave", e);
363
- // this.active = false
364
- })
365
- this.slot.addEventListener("mouseup", (e) => {
355
+ // if (typeof e.stopPropagation !== 'undefined') {
356
+ // e.stopPropagation();
357
+ // }
366
358
 
367
- console.log("mouseleave", e);
368
- this.active = false
369
- })
359
+ // if (typeof e.preventDefault !== 'undefined') {
360
+ // e.preventDefault();
361
+ // }
370
362
 
371
- // console.log("父元素", this.$slots.default[0].elm);
363
+ start.x = e.pageX;
364
+ start.y = e.pageY;
365
+ })
366
+ document.addEventListener("mouseleave", (e) => {
372
367
 
373
- this.left = this.x;
374
- this.top = this.y;
375
- this.right = this.parentWidth - (this.w === 'auto' ? (this.$refs.container as HTMLElement).scrollWidth : this.w) - this.left;
376
- this.bottom = this.parentHeight - (this.h === 'auto' ? (this.$refs.container as HTMLElement).scrollHeight : this.h) - this.top;
368
+ console.log("mouseleave", e);
369
+ // this.active = false
370
+ })
371
+ document.addEventListener("mouseup", (e) => {
377
372
 
378
- // this.domEvents = new Map([
379
- // ['mousemove', this.move],
380
- // ['mouseup', this.up],
381
- // ['mouseleave', this.up],
382
- // ['mousedown', this.deselect],
383
- // ['touchmove', this.move],
384
- // ['touchend', this.up],
385
- // ['touchcancel', this.up],
386
- // ['touchstart', this.up],
387
- // ]);
373
+ console.log("mouseleave", e);
374
+ this.active = false
375
+ })
388
376
 
389
- // addEvents(this.domEvents);
377
+ // console.log("父元素", this.$slots.default[0].elm);
390
378
 
391
- if (this.dragHandle) {
392
- [...this.$el.querySelectorAll(this.dragHandle)].forEach((dragHandle) => {
393
- dragHandle.setAttribute('data-drag-handle', this._uid);
394
- });
395
- }
379
+ this.left = this.x;
380
+ this.top = this.y;
381
+ this.right = this.parentWidth - (this.w === 'auto' ? (this.$refs.container as HTMLElement).scrollWidth : this.w) - this.left;
382
+ this.bottom = this.parentHeight - (this.h === 'auto' ? (this.$refs.container as HTMLElement).scrollHeight : this.h) - this.top;
396
383
 
397
- if (this.dragCancel) {
398
- [...this.$el.querySelectorAll(this.dragCancel)].forEach((cancelHandle) => {
399
- cancelHandle.setAttribute('data-drag-cancel', this._uid);
400
- });
401
- }
384
+ // this.domEvents = new Map([
385
+ // ['mousemove', this.move],
386
+ // ['mouseup', this.up],
387
+ // ['mouseleave', this.up],
388
+ // ['mousedown', this.deselect],
389
+ // ['touchmove', this.move],
390
+ // ['touchend', this.up],
391
+ // ['touchcancel', this.up],
392
+ // ['touchstart', this.up],
393
+ // ]);
394
+
395
+ // addEvents(this.domEvents);
396
+
397
+ if (this.dragHandle) {
398
+ [...this.$el.querySelectorAll(this.dragHandle)].forEach((dragHandle) => {
399
+ dragHandle.setAttribute('data-drag-handle', this._uid);
400
+ });
401
+ }
402
+
403
+ if (this.dragCancel) {
404
+ [...this.$el.querySelectorAll(this.dragCancel)].forEach((cancelHandle) => {
405
+ cancelHandle.setAttribute('data-drag-cancel', this._uid);
406
+ });
407
+ }
402
408
 
403
- if (this.name.trim() !== '' && this.isStorage) {
404
- let info = JSON.parse(localStorage.getItem("DragResizeView_Rect_" + this.name) as string)
405
- if (info !== null
406
- && info.left !== null && info.top !== null
407
- && info.right !== null && info.bottom !== null) {
408
- this.left = info.left
409
- this.top = info.top
410
- this.right = info.right
411
- this.bottom = info.bottom
412
- } else {
413
- localStorage.removeItem("DragResizeView_Rect_" + this.name)
409
+ if (this.name.trim() !== '' && this.isStorage) {
410
+ let info = JSON.parse(localStorage.getItem("DragResizeView_Rect_" + this.name) as string)
411
+ if (info !== null
412
+ && info.left !== null && info.top !== null
413
+ && info.right !== null && info.bottom !== null) {
414
+ this.left = info.left
415
+ this.top = info.top
416
+ this.right = info.right
417
+ this.bottom = info.bottom
418
+ } else {
419
+ localStorage.removeItem("DragResizeView_Rect_" + this.name)
420
+ }
414
421
  }
415
422
  }
416
- }
417
423
 
418
- }
424
+ }
419
425
  </script>
420
426
 
421
427
  <style lang="less" scoped>
422
- @import "index.less";
423
- </style>
428
+ @import "index.less";
429
+ </style>