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.
@@ -0,0 +1,3 @@
1
+ <template src="./vue-drag-resize.html"></template>
2
+ <script src="./vue-drag-resize.js"></script>
3
+ <style src="./vue-drag-resize.css"></style>
@@ -0,0 +1,98 @@
1
+ .vdr {
2
+ // width: 100%;
3
+ // height: 100%;
4
+ background-color: transparent;
5
+ position: absolute;
6
+ }
7
+
8
+ .vdr.active:before {
9
+ content: '';
10
+ width: 100%;
11
+ height: 100%;
12
+ position: absolute;
13
+ top: 0;
14
+ left: 0;
15
+ box-sizing: border-box;
16
+ outline: 1px dashed #d6d6d6;
17
+
18
+
19
+ }
20
+
21
+ .vdr-stick {
22
+ box-sizing: border-box;
23
+ position: absolute;
24
+ font-size: 1px;
25
+ background: #ffffff;
26
+ border: 2px solid #6c6c6c;
27
+ box-shadow: 0 0 2px #bbb;
28
+ pointer-events: visible;
29
+ }
30
+
31
+ .inactive .vdr-stick {
32
+ display: none;
33
+ }
34
+
35
+ .vdr-stick-tl,
36
+ .vdr-stick-br {
37
+ cursor: nwse-resize;
38
+ }
39
+
40
+ .vdr-stick-tm,
41
+ .vdr-stick-bm {
42
+ left: 50%;
43
+ cursor: ns-resize;
44
+ }
45
+
46
+ .vdr-stick-tr,
47
+ .vdr-stick-bl {
48
+ cursor: nesw-resize;
49
+ }
50
+
51
+ .vdr-stick-ml,
52
+ .vdr-stick-mr {
53
+ top: 50%;
54
+ cursor: ew-resize;
55
+ }
56
+
57
+ .vdr-stick.not-resizable {
58
+ display: none;
59
+ }
60
+
61
+ .content-container {
62
+ display: block;
63
+ position: relative;
64
+ }
65
+
66
+
67
+ .tl{
68
+ position: absolute;
69
+ top: -2px;
70
+ left: -2px;
71
+ width: 4px !important;
72
+ height: 4px !important;
73
+ background-color: #f00;
74
+ pointer-events: visible;
75
+ cursor: nwse-resize;
76
+ }
77
+
78
+ .lm{
79
+ position: absolute;
80
+ top: calc(50% - 2px);
81
+ left: -2px;
82
+ width: 4px !important;
83
+ height: 4px !important;
84
+ background-color: #fff;
85
+ pointer-events: visible;
86
+ cursor: ew-resize;
87
+ }
88
+
89
+ .lb{
90
+ position: absolute;
91
+ bottom: -2px;
92
+ left: -2px;
93
+ width: 4px !important;
94
+ height: 4px !important;
95
+ background-color: #f00;
96
+ pointer-events: visible;
97
+ cursor: nesw-resize;
98
+ }
@@ -0,0 +1,429 @@
1
+ <template>
2
+ <div class="vdr" :style="containerStyle">
3
+
4
+
5
+ <slot>
6
+ </slot>
7
+
8
+ <div ref="sticks" :style="sticksStyle">
9
+ <div class="tl"></div>
10
+ <div class="lm"></div>
11
+ <div class="lb"></div>
12
+ </div>
13
+
14
+
15
+ </div>
16
+ </template>
17
+
18
+ <script lang="ts">
19
+ import { Component, Prop, Vue, Watch } from "vue-property-decorator";
20
+
21
+ const styleMapping: any = {
22
+ y: {
23
+ t: 'top',
24
+ m: 'marginTop',
25
+ b: 'bottom',
26
+ },
27
+ x: {
28
+ l: 'left',
29
+ m: 'marginLeft',
30
+ r: 'right',
31
+ },
32
+ };
33
+
34
+ function addEvents(events: any) {
35
+ events.forEach((cb: any, eventName: string) => {
36
+ document.documentElement.addEventListener(eventName, cb);
37
+ });
38
+ }
39
+
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
+ }
232
+
233
+ get containerStyle() {
234
+ return {
235
+ top: this.top + 'px',
236
+ left: this.left + 'px',
237
+ boxSizing: "border-box",
238
+ position: "absolute",
239
+ };
240
+ }
241
+
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
+ }
255
+
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
+ // }
267
+
268
+
269
+
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 },
281
+ };
282
+
283
+ this.currentStick = null;
284
+ }
285
+
286
+
287
+ deselect() {
288
+ // if (this.preventActiveBehavior) {
289
+ // return;
290
+ // }
291
+ // this.active = true;
292
+ }
293
+
294
+ mounted() {
295
+
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;
299
+
300
+ this.$nextTick(() => {
301
+ // console.log("父元素", this.$slots.test);
302
+
303
+
304
+ // let style = window.getComputedStyle(this.$slots.default[0].elm, null);
305
+ // let style = window.getDefaultComputedStyle(this.$slots.default[0].elm, null);
306
+
307
+ // console.log("父元素", style);
308
+ console.log("父元素", this.$slots.default![0]);
309
+
310
+ this.width = this.slot.clientWidth
311
+ this.height = this.slot.clientHeight
312
+ console.log("宽度", this.slot.clientHeight);
313
+
314
+ })
315
+
316
+
317
+ let start = { x: 0, y: 0 };
318
+
319
+ this.slot = this.$slots.default![0].elm as HTMLElement;
320
+
321
+
322
+
323
+ document.addEventListener("mousemove", (e) => {
324
+
325
+ if (!this.active)
326
+ return
327
+
328
+ e.stopPropagation()
329
+
330
+
331
+ // this.active = false
332
+
333
+ // console.log("mousemove pageX", e.pageX);
334
+ // console.log("mousemove", start);
335
+
336
+ let l = e.pageX - start.x
337
+ let t = e.pageY - start.y
338
+
339
+ this.top = Math.floor(this.top + t)
340
+ this.left = Math.floor(this.left + l)
341
+
342
+ start.x = e.pageX
343
+ start.y = e.pageY
344
+
345
+
346
+ // console.log("t", this.$slots.default[0].elm.style);
347
+
348
+ })
349
+ document.addEventListener("mousedown", (e) => {
350
+
351
+ console.log("mousedown", e);
352
+ this.active = true
353
+
354
+
355
+ // if (typeof e.stopPropagation !== 'undefined') {
356
+ // e.stopPropagation();
357
+ // }
358
+
359
+ // if (typeof e.preventDefault !== 'undefined') {
360
+ // e.preventDefault();
361
+ // }
362
+
363
+ start.x = e.pageX;
364
+ start.y = e.pageY;
365
+ })
366
+ document.addEventListener("mouseleave", (e) => {
367
+
368
+ console.log("mouseleave", e);
369
+ // this.active = false
370
+ })
371
+ document.addEventListener("mouseup", (e) => {
372
+
373
+ console.log("mouseleave", e);
374
+ this.active = false
375
+ })
376
+
377
+ // console.log("父元素", this.$slots.default[0].elm);
378
+
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;
383
+
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
+ }
408
+
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
+ }
421
+ }
422
+ }
423
+
424
+ }
425
+ </script>
426
+
427
+ <style lang="less" scoped>
428
+ @import "index.less";
429
+ </style>
@@ -12,6 +12,7 @@
12
12
  position: absolute;
13
13
  top: 0;
14
14
  left: 0;
15
+ background-color: red;
15
16
  }
16
17
 
17
18
  .list {
@@ -22,4 +23,14 @@
22
23
  right: 300px;
23
24
  box-shadow: 0 0 2px #AAA;
24
25
  background-color: white;
26
+ }
27
+
28
+ .filler2 {
29
+ width: 100px;
30
+ height: 100px;
31
+ display: inline-block;
32
+ position: absolute;
33
+ top: 0;
34
+ left: 0;
35
+ background-color: red;
25
36
  }
@@ -22,6 +22,10 @@
22
22
 
23
23
  </div>
24
24
 
25
+ <Draw>
26
+ <div class="filler2">111</div>
27
+ </Draw>
28
+
25
29
 
26
30
  </div>
27
31
  </template>
@@ -30,6 +34,7 @@
30
34
  import { Component, Vue } from "vue-property-decorator";
31
35
  import ImageViewer from "@/views/ImageViewer/index.vue";
32
36
  import DragResizeView from "@/views/DragResizeView/index.vue";
37
+ import Draw from "@/views/Draw/index.vue";
33
38
 
34
39
  import { formatJson, export_json_to_excel, number_to_excel, testToExcel } from "./Export2Excel"
35
40
 
@@ -40,7 +45,8 @@ import LAY_EXCEL from 'lay-excel';
40
45
  @Component({
41
46
  components: {
42
47
  ImageViewer,
43
- DragResizeView
48
+ DragResizeView,
49
+ Draw
44
50
  },
45
51
  mounted() {
46
52
 
package/tsconfig.json CHANGED
@@ -5,13 +5,13 @@
5
5
  "sourceMap": true, // 是否生成sourceMap(用于浏览器调试)
6
6
  "noImplicitAny": false,
7
7
  "noUnusedLocals": false,
8
- "noUnusedParameters": true,
8
+ "noUnusedParameters": false,
9
9
  "declaration": true, // 是否生成声明文件
10
10
  "declarationDir": "./dist/types/", // 声明文件打包的位置
11
11
  "declarationMap": false, // 是否生成声明文件map文件(便于调试)
12
12
  "moduleResolution": "node",
13
13
  "module": "esnext",
14
- "target": "esnext", // 转化成的目标语言
14
+ "target": "es6", // 转化成的目标语言
15
15
  "baseUrl": "./",
16
16
  "strict": true,
17
17
  "jsx": "preserve",
@@ -20,7 +20,7 @@
20
20
  "esModuleInterop": true,
21
21
  "allowSyntheticDefaultImports": true,
22
22
  "forceConsistentCasingInFileNames": true,
23
- "useDefineForClassFields": true,
23
+ "useDefineForClassFields": true,
24
24
  "types": [
25
25
  "node",
26
26
  "webpack-env",
package/webpack.config.js CHANGED
@@ -35,6 +35,7 @@ const config = {
35
35
  open: true,
36
36
  host: "localhost",
37
37
  },
38
+ optimization: { sideEffects: true },
38
39
  externals: {
39
40
  './cptable': 'var cptable'
40
41
  },
@@ -76,7 +77,8 @@ const config = {
76
77
  },
77
78
  {
78
79
  test: /\.less$/i,
79
- use: [stylesHandler, "css-loader", "postcss-loader", "less-loader"],
80
+ use: ['style-loader', 'css-loader', 'less-loader'],
81
+ // use: [stylesHandler, "css-loader", "postcss-loader", "less-loader"], // 会丢失样式
80
82
  },
81
83
  {
82
84
  test: /\.css$/i,
@@ -1,3 +0,0 @@
1
- <template src="./vue-drag-resize.html"></template>
2
- <script src="./vue-drag-resize.ts"></script>
3
- <style src="./vue-drag-resize.css"></style>
@@ -1,17 +0,0 @@
1
- <div class="vdr" :style="positionStyle"
2
- :class="`${(active || isActive) ? 'active' : 'inactive'} ${contentClass ? contentClass: ''}`"
3
- @mousedown="bodyDown($event)"
4
- @touchstart="bodyDown($event)"
5
- @touchend="up($event)">
6
- <div :style="sizeStyle" class="content-container" ref="container">
7
- <slot></slot>
8
- </div>
9
- <div
10
- v-for="stick in sticks"
11
- class="vdr-stick"
12
- :class="['vdr-stick-' + stick, isResizable ? '' : 'not-resizable']"
13
- @mousedown.stop.prevent="stickDown(stick, $event)"
14
- @touchstart.stop.prevent="stickDown(stick, $event)"
15
- :style="vdrStick(stick)">
16
- </div>
17
- </div>