xctc-utils 1.6.47 → 1.6.49

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/README.md CHANGED
@@ -260,4 +260,7 @@ useUtils.findIdcardAge(idcard)
260
260
  #### 将数据复制到剪贴板函数
261
261
  ```
262
262
  useUtils.handleCopyValue(val)
263
- ```
263
+ ```
264
+
265
+
266
+ #### npm run build npm publish
@@ -0,0 +1,81 @@
1
+ export default class CanvasHooks {
2
+ canvasDataSource: any;
3
+ zoomDataSource: string;
4
+ dragLastPosDataSource: any;
5
+ dragElementDataSource: any;
6
+ targetObjectDataSource: any;
7
+ mousePointerDataSource: any;
8
+ canvasCreateElementsDataSource: any[];
9
+ canvasCreateTargetElementsDataSource: any[];
10
+ createSelectionRectDataSource: any;
11
+ canvasSelectionElementsDataSource: any[];
12
+ mouseWheelPointerDataSource: any;
13
+ defaultCreateDataList: any[];
14
+ private canvasConfig;
15
+ callBackEventConfig: any;
16
+ canvasHandleConfig: any;
17
+ canvasBackgroundImageTarget: any;
18
+ renderCanvasStatus: number;
19
+ mouseClickType: number;
20
+ mouseRightClickStatus: boolean;
21
+ mouseDragStatus: boolean;
22
+ canvasDragStatus: boolean;
23
+ canvasSelectionStatus: boolean;
24
+ createSelectionStatus: number;
25
+ canvasMenuShowStatus: boolean;
26
+ mouseClickTargetObjectStatus: number;
27
+ canvasAllSelectionStatus: boolean;
28
+ mouseWheelStatus: boolean;
29
+ defaultCreateDataListStatus: boolean;
30
+ mouseCanvasInRangeStatus: boolean;
31
+ constructor(config: any);
32
+ get canvasConfigData(): any;
33
+ createCanvasFn(config?: any): void;
34
+ disposeCanvasFn(): void;
35
+ canvasConfigDataFn(config: any): void;
36
+ registerCallBackEventFn(config?: any): void;
37
+ registerAllEventHandleFn(): void;
38
+ registerCanvasZoomChangeEventFn(): void;
39
+ registerMouseDropEventFn(options: any): void;
40
+ registerMouseOverEventFn(options: any): void;
41
+ registerMouseOutEventFn(options: any): void;
42
+ registerMouseDownEventFn(options: any): void;
43
+ registerMouseMoveEventFn(options: any): void;
44
+ registerMouseUpEventFn(options: any): void;
45
+ registerMouseWheelEventFn(options: any): void;
46
+ registerZoomHandleFn(options: any): void;
47
+ dragCreateElementDataFn(data: any): void;
48
+ createDragElementFn(): void;
49
+ initElement2CanvasFn(list: any[]): void;
50
+ getCreateElementStatusFn(index: any): void;
51
+ createCanvasSvgElementFn(item: any, index?: number): void;
52
+ createCanvasImageElementFn(item: any, index?: number): void;
53
+ getSelectionAllElementsFn(): any[] | undefined;
54
+ getSelectionElementsFn(item: any): any[] | undefined;
55
+ createSelectionRectFn(): void;
56
+ createAllSelectionRectFn(): void;
57
+ removeAllSelectionRectFn(): void;
58
+ updateSelectionRectFn(options: any): void;
59
+ createSelectionRectFinishFn(options: any): void;
60
+ getDomFn(id: string): false | HTMLElement;
61
+ init(): void;
62
+ elementSizeFn(id: string): {
63
+ height: number;
64
+ width: number;
65
+ };
66
+ createRightClickMenuFn(options: any): void;
67
+ hiddenRightClickMenuFn(): void;
68
+ createElementFn(domVal: any, id: string, index?: number): any;
69
+ previousStepFn(): void;
70
+ removeElementFn(id: any): void;
71
+ removeAllElementFn(): void;
72
+ resetElementSizeFn(): void;
73
+ setCanvasBaseConfigFn(zoom: any): void;
74
+ getCanvasActionDataFn(): {
75
+ zoom: any;
76
+ x: number;
77
+ y: number;
78
+ left: number;
79
+ top: number;
80
+ } | undefined;
81
+ }
@@ -0,0 +1,1087 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var fabric_1 = require("fabric");
15
+ // 初始化画布创建时需要的参数-默认值
16
+ var defaultConfig = {
17
+ width: 1000,
18
+ height: 800,
19
+ fireRightClick: true,
20
+ stopContextMenu: true,
21
+ backgroundImgUrl: "",
22
+ left: 0,
23
+ top: 0,
24
+ // repeat: 'no-repeat',
25
+ angle: 0,
26
+ selection: true,
27
+ selectable: true,
28
+ strokeWidth: 4,
29
+ scaleX: 1,
30
+ scaleY: 1,
31
+ stroke: "",
32
+ fill: "",
33
+ transparentCorners: false,
34
+ cornerColor: "",
35
+ hasControls: true,
36
+ hasRotatingPoint: true,
37
+ hasBorders: true,
38
+ lockMovementX: true,
39
+ lockMovementY: true,
40
+ lockScalingFlip: true // 防止翻转
41
+ };
42
+ var CanvasHooks = /** @class */ (function () {
43
+ function CanvasHooks(config) {
44
+ this.canvasDataSource = null;
45
+ this.zoomDataSource = "100";
46
+ this.canvasBackgroundImageTarget = null;
47
+ this.dragLastPosDataSource = "";
48
+ this.dragElementDataSource = "";
49
+ this.targetObjectDataSource = "";
50
+ this.mousePointerDataSource = "";
51
+ this.createSelectionRectDataSource = "";
52
+ this.canvasCreateElementsDataSource = [];
53
+ this.canvasSelectionElementsDataSource = [];
54
+ this.canvasCreateTargetElementsDataSource = [];
55
+ this.mouseWheelPointerDataSource = "";
56
+ this.defaultCreateDataList = [];
57
+ this.canvasConfig = config;
58
+ this.callBackEventConfig = "";
59
+ this.canvasHandleConfig = "";
60
+ this.renderCanvasStatus = 0;
61
+ this.mouseRightClickStatus = false;
62
+ this.mouseClickType = 0;
63
+ this.mouseDragStatus = false;
64
+ this.canvasDragStatus = true;
65
+ this.canvasSelectionStatus = false;
66
+ this.createSelectionStatus = 0;
67
+ this.canvasMenuShowStatus = false;
68
+ this.mouseClickTargetObjectStatus = 0;
69
+ this.canvasAllSelectionStatus = false;
70
+ this.mouseWheelStatus = false;
71
+ this.defaultCreateDataListStatus = false;
72
+ this.mouseCanvasInRangeStatus = false;
73
+ if (config === null || config === void 0 ? void 0 : config.init) {
74
+ // 是否默认加载画布
75
+ this.createCanvasFn();
76
+ }
77
+ }
78
+ Object.defineProperty(CanvasHooks.prototype, "canvasConfigData", {
79
+ get: function () {
80
+ return this.canvasConfig;
81
+ },
82
+ enumerable: false,
83
+ configurable: true
84
+ });
85
+ // 创建画布
86
+ CanvasHooks.prototype.createCanvasFn = function (config) {
87
+ var _ = this;
88
+ _.renderCanvasStatus = 1;
89
+ var canvasId = "";
90
+ // config 配置数据必须有画布ID参数
91
+ if (config && Object.keys(config).length && !config.hasOwnProperty("id")) {
92
+ console.error("createCanvasFn函数接收的参数必须包含画布对应的id");
93
+ return;
94
+ }
95
+ if (config && config.hasOwnProperty("id")) {
96
+ _.canvasConfig = config;
97
+ if (!_.getDomFn(_.canvasConfig.id)) {
98
+ console.error("未查询到id=" + _.canvasConfig.id + "的canvas元素");
99
+ return;
100
+ }
101
+ }
102
+ // 初始化画布渲染时的配置参数
103
+ var data = __assign(__assign({}, defaultConfig), _.canvasConfig);
104
+ if (!_.canvasConfig.hasOwnProperty("width")) {
105
+ data['width'] = _.elementSizeFn("canvasContainer").width;
106
+ }
107
+ if (!_.canvasConfig.hasOwnProperty("height")) {
108
+ data['height'] = _.elementSizeFn("canvasContainer").height;
109
+ }
110
+ var imgUrl = (data === null || data === void 0 ? void 0 : data.backgroundImgUrl) || "";
111
+ console.log("canvas--options", data);
112
+ canvasId = data.id;
113
+ if (imgUrl) {
114
+ fabric_1.fabric.Image.fromURL(imgUrl, function (img) {
115
+ _.renderCanvasStatus = 2;
116
+ _.canvasBackgroundImageTarget = img;
117
+ var _a = _.canvasConfig.actions, actions = _a === void 0 ? "" : _a;
118
+ var zoomValue = (actions === null || actions === void 0 ? void 0 : actions.zoom) || 1;
119
+ if (!_.canvasDataSource) {
120
+ _.canvasDataSource = new fabric_1.fabric.Canvas(canvasId, __assign({}, data));
121
+ if (zoomValue != 1) {
122
+ _.canvasDataSource.setZoom(zoomValue);
123
+ }
124
+ }
125
+ var canvasWidth = _.canvasDataSource.getWidth();
126
+ var canvasHeight = _.canvasDataSource.getHeight();
127
+ var imgWidth = img.width;
128
+ var imgHeight = img.height;
129
+ var scaleX = 1;
130
+ var scaleY = 1;
131
+ if (canvasWidth && canvasHeight && imgWidth && imgHeight) {
132
+ var imageAspectRatio = imgWidth / imgHeight;
133
+ var canvasAspectRatio = canvasWidth / canvasHeight;
134
+ if (imageAspectRatio > canvasAspectRatio) {
135
+ // 图片更宽,基于高度缩放
136
+ scaleY = canvasHeight / imgHeight;
137
+ scaleX = scaleY * imageAspectRatio;
138
+ }
139
+ else {
140
+ // 图片更高或宽高比相同,基于宽度缩放
141
+ scaleX = canvasWidth / imgWidth;
142
+ scaleY = scaleX / imageAspectRatio;
143
+ }
144
+ }
145
+ console.log("原始比例:", { scaleX: scaleX, scaleY: scaleY, width: imgWidth, height: imgHeight });
146
+ _.canvasDataSource.setBackgroundImage(img, _.canvasDataSource.renderAll.bind(_.canvasDataSource), {
147
+ originX: 'left',
148
+ originY: 'top',
149
+ left: 0,
150
+ top: 0,
151
+ // scaleX: scaleX,
152
+ // scaleY: scaleY,
153
+ width: imgWidth,
154
+ height: imgHeight,
155
+ });
156
+ _.renderCanvasStatus = 3;
157
+ _.registerAllEventHandleFn();
158
+ _.canvasDataSource.renderAll();
159
+ callBack(_.canvasDataSource);
160
+ });
161
+ }
162
+ else {
163
+ if (!_.canvasDataSource) {
164
+ _.canvasDataSource = new fabric_1.fabric.Canvas(canvasId, __assign({}, data));
165
+ _.renderCanvasStatus = 3;
166
+ _.registerAllEventHandleFn();
167
+ _.canvasDataSource.renderAll();
168
+ callBack(_.canvasDataSource);
169
+ }
170
+ }
171
+ // 如果配置里面有回调函数,则将当前画布数据对象返回
172
+ function callBack(data) {
173
+ var _a;
174
+ var cb = ((_a = _.canvasConfig) === null || _a === void 0 ? void 0 : _a.cb) || "";
175
+ if (cb instanceof Function) {
176
+ cb(data);
177
+ }
178
+ }
179
+ };
180
+ // 销毁画布
181
+ CanvasHooks.prototype.disposeCanvasFn = function () {
182
+ var _a, _b;
183
+ if (this.canvasDataSource) {
184
+ var el = (_a = this.canvasDataSource) === null || _a === void 0 ? void 0 : _a.getElement();
185
+ (_b = this.canvasDataSource) === null || _b === void 0 ? void 0 : _b.dispose();
186
+ el === null || el === void 0 ? void 0 : el.remove(); // 删除canvasDataSource元素
187
+ this.canvasDataSource = null;
188
+ }
189
+ };
190
+ // 关于画布相关配置数据
191
+ CanvasHooks.prototype.canvasConfigDataFn = function (config) {
192
+ /**
193
+ * rightButtonsDataSource 画布右键菜单列表数据
194
+ */
195
+ this.canvasHandleConfig = config || {};
196
+ };
197
+ // 注册回调事件--页面生成画布实例的时候,调用该函数
198
+ CanvasHooks.prototype.registerCallBackEventFn = function (config) {
199
+ console.log("canvasDataSource--", this.canvasDataSource);
200
+ if (!this.canvasDataSource) {
201
+ return;
202
+ }
203
+ if (config) {
204
+ this.callBackEventConfig = config;
205
+ }
206
+ };
207
+ // 执行注册事件
208
+ CanvasHooks.prototype.registerAllEventHandleFn = function () {
209
+ var _ = this;
210
+ _.dragLastPosDataSource = {
211
+ open: false,
212
+ lastPosX: null,
213
+ lastPosY: null,
214
+ };
215
+ console.log("registerAllEventHandleFn");
216
+ // 鼠标进入画布画布
217
+ _.canvasDataSource.on("mouse:over", function (options) {
218
+ _.registerMouseOverEventFn(options);
219
+ });
220
+ // 注册鼠标按下事件
221
+ _.canvasDataSource.on("mouse:down", function (options) {
222
+ _.registerMouseDownEventFn(options);
223
+ });
224
+ // 鼠标在画布内移动
225
+ _.canvasDataSource.on("mouse:move", function (options) {
226
+ _.registerMouseMoveEventFn(options);
227
+ });
228
+ // 鼠标移除画布
229
+ _.canvasDataSource.on("mouse:out", function (options) {
230
+ _.registerMouseOutEventFn(options);
231
+ });
232
+ // 鼠标抬起
233
+ _.canvasDataSource.on("mouse:up", function (options) {
234
+ _.registerMouseUpEventFn(options);
235
+ });
236
+ // 注册滚动事件
237
+ _.canvasDataSource.on('mouse:wheel', function (options) {
238
+ _.registerMouseWheelEventFn(options);
239
+ });
240
+ _.canvasDataSource.on('drop', function (options) {
241
+ _.registerMouseDropEventFn(options);
242
+ });
243
+ //监听画布缩放状态
244
+ _.canvasDataSource.on('zoom:changed', function (options) {
245
+ _.registerCanvasZoomChangeEventFn(options);
246
+ });
247
+ };
248
+ // 注册画布发生缩放监听事件
249
+ CanvasHooks.prototype.registerCanvasZoomChangeEventFn = function () {
250
+ var _ = this;
251
+ var zoom = _.canvasDataSource.getZoom();
252
+ };
253
+ // 拖拽事件注册
254
+ CanvasHooks.prototype.registerMouseDropEventFn = function (options) {
255
+ console.log("registerMouseDropEventFn");
256
+ var _ = this;
257
+ // 画布元素距离浏览器左侧和顶部的距离
258
+ var offset = {
259
+ left: _.canvasDataSource.getSelectionElement().getBoundingClientRect().left,
260
+ top: _.canvasDataSource.getSelectionElement().getBoundingClientRect().top
261
+ };
262
+ // 鼠标坐标转换成画布的坐标(未经过缩放和平移的坐标)
263
+ var point = {
264
+ x: options.e.x - offset.left,
265
+ y: options.e.y - offset.top,
266
+ };
267
+ // 转换后的坐标,restorePointerVpt 不受视窗变换的影响
268
+ var pointerVpt = _.canvasDataSource.restorePointerVpt(point);
269
+ //创建元素
270
+ _.mousePointerDataSource = pointerVpt;
271
+ console.log("_.mouseDragStatus=", _.mouseDragStatus);
272
+ _.createDragElementFn();
273
+ if (!_.mouseDragStatus) {
274
+ _.mouseDragStatus = true;
275
+ }
276
+ };
277
+ // 鼠标进入画布
278
+ CanvasHooks.prototype.registerMouseOverEventFn = function (options) {
279
+ console.log("registerMouseOutEventFn");
280
+ var _ = this;
281
+ _.mouseCanvasInRangeStatus = true;
282
+ };
283
+ // 鼠标移出画布
284
+ CanvasHooks.prototype.registerMouseOutEventFn = function (options) {
285
+ console.log("registerMouseOutEventFn");
286
+ var _ = this;
287
+ _.mouseCanvasInRangeStatus = false;
288
+ };
289
+ // 注册鼠标按下事件
290
+ CanvasHooks.prototype.registerMouseDownEventFn = function (options) {
291
+ console.log("registerMouseDownEventFn");
292
+ var _ = this;
293
+ _.mouseCanvasInRangeStatus = true;
294
+ _.mouseWheelPointerDataSource = options;
295
+ var event = options.e;
296
+ var activeTarget = options.target || options.activeTarget;
297
+ console.log("activeTarget==", activeTarget);
298
+ _.mouseDragStatus = false;
299
+ _.mouseWheelStatus = false;
300
+ _.mouseClickType = (options === null || options === void 0 ? void 0 : options.button) || 1; // 鼠标点击类型 1 左键 2中间滚轮 3右键
301
+ console.log("mouseClickType==", _.mouseClickType);
302
+ if (_.mouseRightClickStatus) {
303
+ // 如果当前处于右键状态,则不再继续执行任何操作
304
+ // 如果菜单属于显示状态,则关闭菜单
305
+ if (_.canvasMenuShowStatus) {
306
+ _.canvasMenuShowStatus = false;
307
+ _.mouseRightClickStatus = false;
308
+ _.hiddenRightClickMenuFn();
309
+ }
310
+ return;
311
+ }
312
+ // 鼠标左键点击操作
313
+ if (_.mouseClickType == 1) {
314
+ // 开启全选操作,禁止画布拖拽
315
+ if (_.canvasAllSelectionStatus) {
316
+ _.dragLastPosDataSource.open = false;
317
+ _.hiddenRightClickMenuFn();
318
+ return;
319
+ }
320
+ // 自定义绘制选择框选状态--开始绘制
321
+ if (_.canvasSelectionStatus) {
322
+ console.log("自定义绘制选择框选状态--开始绘制");
323
+ _.createSelectionStatus = 1;
324
+ var pointer = _.canvasDataSource.getPointer(options.e);
325
+ _.mousePointerDataSource = { x: pointer.x, y: pointer.y };
326
+ _.createSelectionRectFn(options);
327
+ return;
328
+ }
329
+ // 如果是鼠标左键点击画布,且此时处于右键状态,则关闭右键菜单,并将菜单状态初始化
330
+ if (_.mouseRightClickStatus) {
331
+ console.log("关闭右键菜单,并将菜单状态初始化");
332
+ _.mouseRightClickStatus = false;
333
+ _.canvasMenuShowStatus = false;
334
+ _.dragLastPosDataSource.open = true;
335
+ _.dragLastPosDataSource.lastPosX = event.clientX;
336
+ _.dragLastPosDataSource.lastPosY = event.clientY;
337
+ _.canvasDragStatus = true;
338
+ _.hiddenRightClickMenuFn();
339
+ return;
340
+ }
341
+ // 点击画布上的对象执行操作
342
+ if (activeTarget) {
343
+ // 画布上的数据对象被点击
344
+ if ((activeTarget === null || activeTarget === void 0 ? void 0 : activeTarget.elementKey) == "data") {
345
+ _.mouseClickTargetObjectStatus = 1;
346
+ return;
347
+ }
348
+ // 画布上的自定义绘制框被点击
349
+ if ((activeTarget === null || activeTarget === void 0 ? void 0 : activeTarget.renderType) == "frameSelection") {
350
+ _.mouseClickTargetObjectStatus = 1;
351
+ return;
352
+ }
353
+ }
354
+ else {
355
+ if (!_.canvasDragStatus) {
356
+ setTimeout(function () {
357
+ _.canvasDragStatus = true;
358
+ }, 0);
359
+ }
360
+ }
361
+ // 画布可拖拽状态
362
+ if (_.canvasDragStatus) {
363
+ // 如果当前点击了底层画布,则允许底层画布可以拖拽
364
+ console.log("允许底层画布可以拖拽");
365
+ if (!activeTarget) {
366
+ // 如果没有获取到具体的目标对象,则默认是点击了画布底图,即开启画布的拖拽
367
+ _.dragLastPosDataSource.open = true;
368
+ _.dragLastPosDataSource.lastPosX = event.clientX;
369
+ _.dragLastPosDataSource.lastPosY = event.clientY;
370
+ return;
371
+ }
372
+ }
373
+ else {
374
+ console.log("3333");
375
+ _.dragLastPosDataSource.open = false;
376
+ return;
377
+ }
378
+ }
379
+ // 中间滚轮操作,仅仅允许缩放,禁止拖拽操作
380
+ if (_.mouseClickType == 2) {
381
+ _.dragLastPosDataSource.open = false;
382
+ }
383
+ // 鼠标右键操作
384
+ if (_.mouseClickType == 3) {
385
+ // 激活右键状态
386
+ _.mouseRightClickStatus = true;
387
+ _.canvasMenuShowStatus = true;
388
+ // 创建右键选择菜单列表
389
+ _.createRightClickMenuFn(options);
390
+ }
391
+ };
392
+ // 注册鼠标移动事件
393
+ CanvasHooks.prototype.registerMouseMoveEventFn = function (options) {
394
+ var _ = this;
395
+ // 监听鼠标是否在画布范围内移动
396
+ var pointer = _.canvasDataSource.getPointer(options.e);
397
+ var inRange = pointer.x >= 0 && pointer.x <= _.canvasDataSource.width &&
398
+ pointer.y >= 0 && pointer.y <= _.canvasDataSource.height;
399
+ _.mouseCanvasInRangeStatus = inRange;
400
+ // 鼠标不在画布内,终止行为
401
+ if (!inRange) {
402
+ return;
403
+ }
404
+ var activeTarget = options.target || options.activeTarget;
405
+ _.mouseDragStatus = true;
406
+ _.mouseWheelStatus = true;
407
+ _.mouseWheelPointerDataSource = options;
408
+ if (_.mouseRightClickStatus) {
409
+ // 如果当前处于右键状态,则不再继续执行任何操作
410
+ return;
411
+ }
412
+ if (_.dragLastPosDataSource.open) {
413
+ var evt = options.e;
414
+ var vpt = _.canvasDataSource.viewportTransform;
415
+ vpt[4] += evt.clientX - _.dragLastPosDataSource.lastPosX;
416
+ vpt[5] += evt.clientY - _.dragLastPosDataSource.lastPosY;
417
+ _.canvasDataSource.requestRenderAll(); // 异步更新画板,提升性能
418
+ _.dragLastPosDataSource.lastPosX = evt.clientX;
419
+ _.dragLastPosDataSource.lastPosY = evt.clientY;
420
+ return;
421
+ }
422
+ // 画布上的对象被点击
423
+ if ((activeTarget === null || activeTarget === void 0 ? void 0 : activeTarget.elementKey) == "data") {
424
+ _.mouseClickTargetObjectStatus = 2;
425
+ return;
426
+ }
427
+ // 画布上的自定义绘制框被点击
428
+ if ((activeTarget === null || activeTarget === void 0 ? void 0 : activeTarget.renderType) == "frameSelection") {
429
+ _.mouseClickTargetObjectStatus = 2;
430
+ return;
431
+ }
432
+ // 更新自定义绘制图像数据
433
+ if (_.canvasSelectionStatus) {
434
+ _.createSelectionStatus = 2;
435
+ _.updateSelectionRectFn(options);
436
+ return;
437
+ }
438
+ };
439
+ // 注册鼠标抬起事件
440
+ CanvasHooks.prototype.registerMouseUpEventFn = function (options) {
441
+ console.log("registerMouseUpEventFn");
442
+ var _ = this;
443
+ // 鼠标不在画布内,终止行为
444
+ if (!_.mouseCanvasInRangeStatus) {
445
+ return;
446
+ }
447
+ var activeTarget = options.target || options.activeTarget;
448
+ var _a = _.callBackEventConfig || {}, activeTargetElementBackFn = _a.activeTargetElementBackFn, activeTargetSelectionRectBackFn = _a.activeTargetSelectionRectBackFn;
449
+ _.mouseWheelPointerDataSource = options;
450
+ console.log("activeTarget==", activeTarget);
451
+ console.log("_.canvasDataSource==", _.canvasDataSource.backgroundImage);
452
+ setTimeout(function () {
453
+ _.mouseWheelStatus = false;
454
+ }, 0);
455
+ if (_.mouseRightClickStatus) {
456
+ // 如果当前处于右键状态,则不再继续执行任何操作
457
+ return;
458
+ }
459
+ // 画布上的对象被点击
460
+ if ((activeTarget === null || activeTarget === void 0 ? void 0 : activeTarget.elementKey) == "data") {
461
+ // 如果是点击对象操作,并未执行拖动,则执行点击的回调函数
462
+ if (_.mouseClickTargetObjectStatus == 1) {
463
+ if (activeTargetElementBackFn instanceof Function) {
464
+ activeTargetElementBackFn(activeTarget);
465
+ }
466
+ }
467
+ setTimeout(function () {
468
+ _.mouseClickTargetObjectStatus = 3;
469
+ }, 0);
470
+ return;
471
+ }
472
+ if ((activeTarget === null || activeTarget === void 0 ? void 0 : activeTarget.renderType) == "frameSelection") {
473
+ // 点击了画布上自定义绘制的选择框
474
+ if (_.mouseClickTargetObjectStatus == 1) {
475
+ if (activeTargetSelectionRectBackFn instanceof Function) {
476
+ activeTargetSelectionRectBackFn(activeTarget);
477
+ }
478
+ }
479
+ setTimeout(function () {
480
+ _.mouseClickTargetObjectStatus = 3;
481
+ }, 0);
482
+ return;
483
+ }
484
+ // 允许画布拖动操作
485
+ if (_.dragLastPosDataSource.open) {
486
+ _.canvasDataSource.setViewportTransform(_.canvasDataSource.viewportTransform);
487
+ _.dragLastPosDataSource.open = false;
488
+ return;
489
+ }
490
+ // 右键选择自定义绘制框,并且绘制完成,抬起鼠标,结束当次绘制
491
+ if (_.canvasSelectionStatus && _.mouseClickType == 1) {
492
+ _.createSelectionRectFinishFn(options);
493
+ return;
494
+ }
495
+ // _.canvasDataSource.selection = true;
496
+ setTimeout(function () {
497
+ _.mouseDragStatus = false;
498
+ }, 0);
499
+ };
500
+ // 注册鼠标滚动事件
501
+ CanvasHooks.prototype.registerMouseWheelEventFn = function (options) {
502
+ var _a;
503
+ console.log("registerMouseWheelEventFn");
504
+ var _ = this;
505
+ _.mouseWheelPointerDataSource = options;
506
+ if (!_.canvasDataSource) {
507
+ return;
508
+ }
509
+ if ((_a = _.canvasConfig) === null || _a === void 0 ? void 0 : _a.zoom) {
510
+ _.registerZoomHandleFn(options);
511
+ }
512
+ };
513
+ // 滚动事件操作--画布缩放监听
514
+ CanvasHooks.prototype.registerZoomHandleFn = function (options) {
515
+ var _a;
516
+ console.log("registerZoomHandleFn");
517
+ var _ = this;
518
+ if (!_.canvasDataSource) {
519
+ return;
520
+ }
521
+ // 滚轮,向上滚一下是 -100,向下滚一下是 100
522
+ var delta = options.e.deltaY;
523
+ var zoom = _.canvasDataSource.getZoom(); // 获取画布当前缩放值
524
+ console.log("registerZoomHandleFn--zoom=", zoom);
525
+ zoom += 0.001 * delta;
526
+ if (zoom > 10)
527
+ zoom = 10; // 限制最大缩放级别
528
+ if (zoom < 0.2)
529
+ zoom = 0.2; // 限制最小缩放级别
530
+ _.zoomDataSource = (zoom * 100).toFixed(0);
531
+ // 以鼠标所在位置为原点缩放
532
+ _.canvasDataSource.zoomToPoint({
533
+ x: options.e.offsetX,
534
+ y: options.e.offsetY
535
+ }, zoom // 传入修改后的缩放级别
536
+ );
537
+ var fn = ((_a = _.callBackEventConfig) === null || _a === void 0 ? void 0 : _a.zoomListenEvent) || "";
538
+ if (fn && fn instanceof Function) {
539
+ fn(zoom, _.zoomDataSource);
540
+ }
541
+ };
542
+ // 页面上发生拖拽时,拖拽完成后的数据存储函数
543
+ CanvasHooks.prototype.dragCreateElementDataFn = function (data) {
544
+ var _ = this;
545
+ if (!_.canvasDataSource) {
546
+ return;
547
+ }
548
+ _.dragElementDataSource = data;
549
+ _.targetObjectDataSource = data;
550
+ };
551
+ // 拖拽进入画布元素创建
552
+ CanvasHooks.prototype.createDragElementFn = function () {
553
+ var _a, _b, _c, _d, _e;
554
+ var _ = this;
555
+ if (!_.canvasDataSource) {
556
+ return;
557
+ }
558
+ var type = ((_a = _.dragElementDataSource) === null || _a === void 0 ? void 0 : _a.renderType) || "image";
559
+ var top = (_b = _.mousePointerDataSource) === null || _b === void 0 ? void 0 : _b.y;
560
+ var left = ((_c = _.mousePointerDataSource) === null || _c === void 0 ? void 0 : _c.x) - (((_d = _.dragElementDataSource) === null || _d === void 0 ? void 0 : _d.width) / 2);
561
+ // 同一个对象是否允许多次创建 createMode = multiple 允许 传其他或不传不允许
562
+ _.targetObjectDataSource = _.dragElementDataSource;
563
+ if (!((_e = _.targetObjectDataSource) === null || _e === void 0 ? void 0 : _e.id)) {
564
+ console.error("拖入画布的元素没有唯一标识id字段,不能创建!");
565
+ return;
566
+ }
567
+ var item = __assign(__assign({}, _.dragElementDataSource), { top: top, left: left });
568
+ // 拖拽数据类型为SVG图片对象
569
+ if (type == "svg") {
570
+ _.createCanvasSvgElementFn(item);
571
+ }
572
+ else {
573
+ _.createCanvasImageElementFn(item);
574
+ }
575
+ };
576
+ // 默认加载一个列表数据到画布
577
+ CanvasHooks.prototype.initElement2CanvasFn = function (list) {
578
+ var _ = this;
579
+ _.defaultCreateDataListStatus = false;
580
+ if (!_.canvasDataSource) {
581
+ return;
582
+ }
583
+ if (list === null || list === void 0 ? void 0 : list.length) {
584
+ _.defaultCreateDataList = list;
585
+ list.forEach(function (item, index) {
586
+ if (item.hasOwnProperty("left") && item.hasOwnProperty("top")) {
587
+ var type = (item === null || item === void 0 ? void 0 : item.renderType) || "image";
588
+ if (type == "svg") {
589
+ _.createCanvasSvgElementFn(item, index);
590
+ }
591
+ else {
592
+ _.createCanvasImageElementFn(item, index);
593
+ }
594
+ }
595
+ });
596
+ }
597
+ };
598
+ CanvasHooks.prototype.getCreateElementStatusFn = function (index) {
599
+ var _ = this;
600
+ var list = _.defaultCreateDataList;
601
+ if (index >= 0 && (list === null || list === void 0 ? void 0 : list.length)) {
602
+ if (index == list.length - 1) {
603
+ setTimeout(function () {
604
+ _.resetElementSizeFn();
605
+ }, 100);
606
+ }
607
+ }
608
+ };
609
+ // 创建SVG到画布
610
+ CanvasHooks.prototype.createCanvasSvgElementFn = function (item, index) {
611
+ var _ = this;
612
+ if (!_.canvasDataSource) {
613
+ return;
614
+ }
615
+ var createDragElementBackFn = (_.callBackEventConfig || {}).createDragElementBackFn;
616
+ fabric_1.fabric.loadSVGFromURL(item === null || item === void 0 ? void 0 : item.address, function (objects) {
617
+ var svgObject = (objects === null || objects === void 0 ? void 0 : objects.length) ? objects[0] : "";
618
+ if (!svgObject) {
619
+ return;
620
+ }
621
+ console.log("createCanvasSvgElementFn-item=", item);
622
+ svgObject.set(__assign({ evented: true, originX: 'left', originY: 'top' }, item));
623
+ _.canvasDataSource.add(svgObject);
624
+ _.canvasDataSource.requestRenderAll();
625
+ _.mousePointerDataSource = null;
626
+ _.canvasCreateElementsDataSource.push(svgObject);
627
+ _.canvasCreateTargetElementsDataSource.push(svgObject);
628
+ _.getCreateElementStatusFn(index);
629
+ if (createDragElementBackFn instanceof Function) {
630
+ createDragElementBackFn(_.dragElementDataSource);
631
+ }
632
+ setTimeout(function () {
633
+ _.mouseDragStatus = false;
634
+ }, 0);
635
+ });
636
+ };
637
+ // 创建图片到画布
638
+ CanvasHooks.prototype.createCanvasImageElementFn = function (item, index) {
639
+ var _a;
640
+ var _ = this;
641
+ if (!_.canvasDataSource) {
642
+ return;
643
+ }
644
+ var createDragElementBackFn = (_.callBackEventConfig || {}).createDragElementBackFn;
645
+ fabric_1.fabric.Image.fromURL((_a = _.dragElementDataSource) === null || _a === void 0 ? void 0 : _a.address, function (img) {
646
+ img.set(__assign({}, item));
647
+ _.canvasDataSource.add(img);
648
+ _.canvasCreateElementsDataSource.push(img);
649
+ _.canvasCreateTargetElementsDataSource.push(img);
650
+ _.mousePointerDataSource = null;
651
+ _.canvasDataSource.requestRenderAll();
652
+ _.getCreateElementStatusFn(index);
653
+ setTimeout(function () {
654
+ _.mouseDragStatus = false;
655
+ }, 0);
656
+ if (createDragElementBackFn instanceof Function) {
657
+ createDragElementBackFn(_.dragElementDataSource);
658
+ }
659
+ }, function (exception) {
660
+ // 图片加载失败后的操作
661
+ console.error('createElement-exception-exception: ', exception);
662
+ // 这里可以显示文案或者进行其他错误处理
663
+ });
664
+ };
665
+ // 获取到所有被框选的对象
666
+ CanvasHooks.prototype.getSelectionAllElementsFn = function () {
667
+ var _ = this;
668
+ if (!_.canvasDataSource) {
669
+ return;
670
+ }
671
+ var dataList = [];
672
+ var selection = _.canvasSelectionElementsDataSource || [];
673
+ // 检查哪些图标在选择框内
674
+ _.canvasDataSource.forEachObject(function (obj) {
675
+ var isTarget = false;
676
+ selection.map(function (item) {
677
+ if (obj.intersectsWithObject(item)) {
678
+ isTarget = true;
679
+ }
680
+ });
681
+ if (isTarget && (obj === null || obj === void 0 ? void 0 : obj.elementKey) == "data") {
682
+ dataList.push(obj);
683
+ }
684
+ });
685
+ return dataList;
686
+ };
687
+ // 获取到指定选择框内被框选的对象
688
+ CanvasHooks.prototype.getSelectionElementsFn = function (item) {
689
+ var _ = this;
690
+ if (!_.canvasDataSource) {
691
+ return;
692
+ }
693
+ var dataList = [];
694
+ // 检查哪些图标在选择框内
695
+ _.canvasDataSource.forEachObject(function (obj) {
696
+ if (item && obj.intersectsWithObject(item) && (obj === null || obj === void 0 ? void 0 : obj.elementKey) == "data") {
697
+ dataList.push(obj);
698
+ }
699
+ });
700
+ return dataList;
701
+ };
702
+ // 创建自定义图像
703
+ CanvasHooks.prototype.createSelectionRectFn = function () {
704
+ var _a, _b;
705
+ var _ = this;
706
+ if (!_.canvasDataSource) {
707
+ return;
708
+ }
709
+ _.createSelectionRectDataSource = new fabric_1.fabric.Rect({
710
+ left: (_a = _.mousePointerDataSource) === null || _a === void 0 ? void 0 : _a.x,
711
+ top: (_b = _.mousePointerDataSource) === null || _b === void 0 ? void 0 : _b.y,
712
+ width: 0,
713
+ height: 0,
714
+ fill: 'rgba(0,0,255,0.1)',
715
+ stroke: 'blue',
716
+ // fill:"transparent",
717
+ strokeWidth: 1,
718
+ hasControls: true,
719
+ hasBorders: true,
720
+ selectable: true,
721
+ evented: true,
722
+ hoverCursor: 'move',
723
+ renderType: "frameSelection", // 代表框选
724
+ });
725
+ _.canvasDataSource.add(_.createSelectionRectDataSource);
726
+ _.canvasDataSource.requestRenderAll();
727
+ };
728
+ // 创建全选框
729
+ CanvasHooks.prototype.createAllSelectionRectFn = function () {
730
+ var _ = this;
731
+ if (!_.canvasDataSource) {
732
+ return;
733
+ }
734
+ _.createSelectionRectDataSource = new fabric_1.fabric.Rect({
735
+ left: 0,
736
+ top: 0,
737
+ width: _.canvasDataSource.getWidth(),
738
+ height: _.canvasDataSource.getHeight(),
739
+ fill: 'rgba(0,0,255,0.1)',
740
+ stroke: 'blue',
741
+ // fill:"transparent",
742
+ strokeWidth: 1,
743
+ hasControls: false,
744
+ hasBorders: false,
745
+ selectable: false,
746
+ evented: true,
747
+ hoverCursor: 'move',
748
+ renderType: "frameSelection", // 代表框选
749
+ });
750
+ _.canvasDataSource.add(_.createSelectionRectDataSource);
751
+ _.canvasDataSource.requestRenderAll();
752
+ };
753
+ // 删除全选对象选择框
754
+ CanvasHooks.prototype.removeAllSelectionRectFn = function () {
755
+ var _ = this;
756
+ if (!_.canvasDataSource) {
757
+ return;
758
+ }
759
+ _.canvasDataSource.remove(_.createSelectionRectDataSource);
760
+ _.canvasDataSource.requestRenderAll();
761
+ };
762
+ // 自定义选择框绘制数据更新
763
+ CanvasHooks.prototype.updateSelectionRectFn = function (options) {
764
+ var _a, _b;
765
+ var _ = this;
766
+ if (!_.canvasDataSource) {
767
+ return;
768
+ }
769
+ if (_.createSelectionRectDataSource) {
770
+ var pointer = _.canvasDataSource.getPointer(options.e);
771
+ var width = pointer.x - ((_a = _.mousePointerDataSource) === null || _a === void 0 ? void 0 : _a.x);
772
+ var height = pointer.y - ((_b = _.mousePointerDataSource) === null || _b === void 0 ? void 0 : _b.y);
773
+ _.createSelectionRectDataSource.set({ width: Math.abs(width), height: Math.abs(height) });
774
+ // _.createSelectionRectDataSource.setCoords(); // 更新控制点坐标
775
+ _.canvasDataSource.requestRenderAll();
776
+ _.createSelectionStatus = 3;
777
+ setTimeout(function () {
778
+ _.createSelectionStatus = 0;
779
+ }, 0);
780
+ }
781
+ };
782
+ // 自定义选择框绘制完成
783
+ CanvasHooks.prototype.createSelectionRectFinishFn = function (options) {
784
+ var _ = this;
785
+ if (!_.canvasDataSource) {
786
+ return;
787
+ }
788
+ _.canvasSelectionStatus = false;
789
+ _.isRightClick = false;
790
+ _.canvasDragStatus = true;
791
+ _.mouseRightClickStatus = false;
792
+ if (_.createSelectionRectDataSource) {
793
+ _.canvasSelectionElementsDataSource.push(_.createSelectionRectDataSource);
794
+ _.canvasCreateElementsDataSource.push(_.createSelectionRectDataSource);
795
+ _.createSelectionRectDataSource.setCoords(); // 更新控制点坐标
796
+ _.createSelectionRectDataSource = null; // 清除引用,结束绘制
797
+ }
798
+ };
799
+ // 获取对应的DOM元素
800
+ CanvasHooks.prototype.getDomFn = function (id) {
801
+ if (!id)
802
+ return false;
803
+ var dom = document.getElementById(id);
804
+ if (id && dom instanceof HTMLElement) {
805
+ return dom;
806
+ }
807
+ return false;
808
+ };
809
+ CanvasHooks.prototype.init = function () {
810
+ var _ = this;
811
+ };
812
+ // 获取画布容器的宽高
813
+ CanvasHooks.prototype.elementSizeFn = function (id) {
814
+ var _ = this;
815
+ var box = _.getDomFn(id);
816
+ if (!box) {
817
+ console.error("canvas外层必须套一层id=canvasContainer的DOM元素");
818
+ }
819
+ var height = box.clientHeight;
820
+ var width = box.clientWidth;
821
+ return {
822
+ height: height,
823
+ width: width
824
+ };
825
+ };
826
+ // 右键菜单管理
827
+ CanvasHooks.prototype.createRightClickMenuFn = function (options) {
828
+ var _ = this;
829
+ if (!_.canvasDataSource) {
830
+ return;
831
+ }
832
+ var rightButtonsDataSource = (_.canvasHandleConfig || {}).rightButtonsDataSource;
833
+ var rightButtonMenuClickBackFn = (_.callBackEventConfig || {}).rightButtonMenuClickBackFn;
834
+ if (!(rightButtonsDataSource === null || rightButtonsDataSource === void 0 ? void 0 : rightButtonsDataSource.length)) {
835
+ return;
836
+ }
837
+ var canvasContainer = _.getDomFn("canvasContainer");
838
+ var oldMenuBox = _.getDomFn("menuBox");
839
+ if (canvasContainer && oldMenuBox) {
840
+ canvasContainer === null || canvasContainer === void 0 ? void 0 : canvasContainer.removeChild(oldMenuBox);
841
+ }
842
+ var menuBox = _.createElementFn("menuBox", "div");
843
+ if (rightButtonsDataSource === null || rightButtonsDataSource === void 0 ? void 0 : rightButtonsDataSource.length) {
844
+ var ulBox_1 = _.createElementFn("ulBox", "ul");
845
+ ulBox_1.style = "\n list-style-type: none;\n padding:0px;\n margin:0px;\n ";
846
+ var liStype_1 = "\n padding:8px 12px;\n cursor: pointer;\n border-radius:4px;\n font-size:16px;\n ";
847
+ rightButtonsDataSource.forEach(function (item, index) {
848
+ var liItem = _.createElementFn("li", "liBox".concat(index + 1), index);
849
+ liItem.innerHTML = (item === null || item === void 0 ? void 0 : item.label) || "请传入label值";
850
+ liItem.style = liStype_1;
851
+ liItem.className = "right-menu-button";
852
+ liItem.addEventListener("click", function (event) {
853
+ // 点击右键菜单回调函数
854
+ console.log("rightButtonMenuClickBackFn==", rightButtonMenuClickBackFn);
855
+ if (rightButtonMenuClickBackFn instanceof Function) {
856
+ rightButtonMenuClickBackFn(event.target['data-index']);
857
+ }
858
+ _.canvasMenuShowStatus = false;
859
+ _.mouseRightClickStatus = false;
860
+ _.hiddenRightClickMenuFn();
861
+ });
862
+ liItem.addEventListener('mousemove', function () {
863
+ var lists = document.getElementsByClassName("right-menu-button");
864
+ for (var i = 0; i < lists.length; i++) {
865
+ var element = lists[i];
866
+ element.style.backgroundColor = "#fff";
867
+ element.style.color = "#333";
868
+ }
869
+ liItem.style.backgroundColor = '#0AC496';
870
+ liItem.style.color = '#fff';
871
+ liItem.style.fontWeight = "bold";
872
+ });
873
+ ulBox_1.appendChild(liItem);
874
+ });
875
+ menuBox.appendChild(ulBox_1);
876
+ }
877
+ if (menuBox) {
878
+ menuBox.id = "menuBox";
879
+ // 显示菜单,设置右键菜单位置
880
+ // 获取菜单组件的宽高
881
+ var menuWidth = menuBox.offsetWidth;
882
+ var menuHeight = menuBox.offsetHeight;
883
+ // 当前鼠标位置
884
+ var pointX = options.pointer.x;
885
+ var pointY = options.pointer.y;
886
+ // 计算菜单出现的位置
887
+ // 如果鼠标靠近画布右侧,菜单就出现在鼠标指针左侧
888
+ if (_.canvasDataSource.width - pointX <= menuWidth) {
889
+ pointX -= menuWidth;
890
+ }
891
+ // 如果鼠标靠近画布底部,菜单就出现在鼠标指针上方
892
+ if (_.canvasDataSource.height - pointY <= menuHeight) {
893
+ pointY -= menuHeight;
894
+ }
895
+ // 将菜单展示出来
896
+ menuBox.style = "\n visibility: visible;\n left: ".concat(pointX, "px;\n top: ").concat(pointY, "px;\n z-index: 10000000;\n padding:16px 12px;\n border-radius:4px;\n background-color:#fff;\n position: absolute;\n box-shadow: h-shadow v-shadow blur spread color inset;\n ");
897
+ if (canvasContainer) {
898
+ canvasContainer.appendChild(menuBox);
899
+ _.isRightClick = true;
900
+ _.canvasDragStatus = false; // 进行右键操作时,先禁用画布拖拽操作功能
901
+ }
902
+ else {
903
+ console.error("请在canvas元素外层包一个DIV容器,且id='canvasContainer'");
904
+ }
905
+ }
906
+ };
907
+ CanvasHooks.prototype.hiddenRightClickMenuFn = function () {
908
+ var _ = this;
909
+ var canvasContainer = _.getDomFn("canvasContainer");
910
+ var menuBox = _.getDomFn("menuBox");
911
+ if (canvasContainer && menuBox) {
912
+ canvasContainer === null || canvasContainer === void 0 ? void 0 : canvasContainer.removeChild(menuBox);
913
+ }
914
+ };
915
+ // 在画布上动态创建对象
916
+ CanvasHooks.prototype.createElementFn = function (domVal, id, index) {
917
+ var _ = this;
918
+ var element = _.getDomFn(id);
919
+ if (element) {
920
+ return;
921
+ }
922
+ else {
923
+ if (domVal) {
924
+ var dom = document.createElement(domVal);
925
+ dom.id = id;
926
+ if (typeof index == "undefined") {
927
+ index = 0;
928
+ }
929
+ if (index >= 0) {
930
+ dom['data-index'] = index;
931
+ }
932
+ return dom;
933
+ }
934
+ return;
935
+ }
936
+ };
937
+ // 执行返回上一步操作
938
+ CanvasHooks.prototype.previousStepFn = function () {
939
+ var _ = this;
940
+ if (!_.canvasDataSource) {
941
+ return;
942
+ }
943
+ var list = _.canvasCreateElementsDataSource;
944
+ var len = list.length;
945
+ if (len) {
946
+ var targetElement_1 = list[len - 1];
947
+ if (targetElement_1) {
948
+ _.canvasDataSource.remove(targetElement_1);
949
+ _.canvasCreateElementsDataSource.splice(len - 1, 1);
950
+ var index = _.canvasCreateTargetElementsDataSource.findIndex(function (citem) { return citem.id == targetElement_1.id; });
951
+ if (index >= 0) {
952
+ _.canvasCreateTargetElementsDataSource.splice(index, 1);
953
+ }
954
+ }
955
+ _.canvasDataSource.requestRenderAll();
956
+ }
957
+ };
958
+ // 移除画布上指定对象
959
+ CanvasHooks.prototype.removeElementFn = function (id) {
960
+ if (!id) {
961
+ return;
962
+ }
963
+ var _ = this;
964
+ if (!_.canvasDataSource) {
965
+ return;
966
+ }
967
+ var list = _.canvasCreateElementsDataSource;
968
+ var targetElement = list.find(function (obj) {
969
+ return obj.id === id;
970
+ });
971
+ if (targetElement) {
972
+ _.canvasDataSource.remove(targetElement);
973
+ }
974
+ _.canvasDataSource.requestRenderAll();
975
+ };
976
+ // 清空画布上所有对象
977
+ CanvasHooks.prototype.removeAllElementFn = function () {
978
+ var _ = this;
979
+ if (!_.canvasDataSource) {
980
+ return;
981
+ }
982
+ var list = _.canvasCreateElementsDataSource;
983
+ _.createSelectionRectDataSource = [];
984
+ _.canvasCreateElementsDataSource = [];
985
+ _.createSelectionRectDataSource = [];
986
+ _.dragElementDataSource = [];
987
+ _.canvasSelectionElementsDataSource = [];
988
+ _.canvasCreateTargetElementsDataSource = [];
989
+ _.defaultCreateDataList = [];
990
+ list.map(function (item) {
991
+ if (item) {
992
+ _.canvasDataSource.remove(item);
993
+ }
994
+ });
995
+ _.canvasDataSource.requestRenderAll();
996
+ };
997
+ // 对于画布出现缩放的情况,加载进入的数据会产生偏移处理
998
+ // 问题未解决,备注
999
+ CanvasHooks.prototype.resetElementSizeFn = function () {
1000
+ var _a;
1001
+ var _ = this;
1002
+ if (!_.canvasDataSource) {
1003
+ return;
1004
+ }
1005
+ var _b = _.canvasConfig.actions, actions = _b === void 0 ? "" : _b;
1006
+ var backgroundImage = ((_a = _.canvasDataSource) === null || _a === void 0 ? void 0 : _a.backgroundImage) || "";
1007
+ var zoomValue = (actions === null || actions === void 0 ? void 0 : actions.zoom) || 1;
1008
+ console.log("resetElementSizeFn-zoomValue=", zoomValue);
1009
+ var scaleX = (backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.scaleX) || 1;
1010
+ var scaleY = (backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.scaleY) || 1;
1011
+ if (zoomValue != 1) {
1012
+ // _.canvasDataSource.zoom = zoomValue
1013
+ scaleX = scaleX * zoomValue;
1014
+ scaleY = scaleY * zoomValue;
1015
+ }
1016
+ if (backgroundImage) {
1017
+ // backgroundImage.set({
1018
+ // scaleX:scaleX,
1019
+ // scaleY:scaleY,
1020
+ // })
1021
+ }
1022
+ // 默认加载完对象后,如果自动放大画布,则画布上元素的坐标需要做与画布同级别的缩放处理
1023
+ _.canvasDataSource.forEachObject(function (obj) {
1024
+ if (obj.elementType === 'icon') {
1025
+ // 重新计算位置
1026
+ // obj.set({
1027
+ // left: obj.left * zoomValue,
1028
+ // top: obj.top * zoomValue,
1029
+ // })
1030
+ // obj.setCoords(); // 更新对象的坐标
1031
+ }
1032
+ });
1033
+ _.canvasDataSource.requestRenderAll();
1034
+ };
1035
+ CanvasHooks.prototype.setCanvasBaseConfigFn = function (zoom) {
1036
+ var _a;
1037
+ var _ = this;
1038
+ if (!_.canvasDataSource) {
1039
+ return;
1040
+ }
1041
+ if (!zoom) {
1042
+ return;
1043
+ }
1044
+ var x = 0;
1045
+ var y = 0;
1046
+ if ((_a = _.mouseWheelPointerDataSource) === null || _a === void 0 ? void 0 : _a.e) {
1047
+ var _b = _.mouseWheelPointerDataSource.e, _c = _b.offsetX, offsetX = _c === void 0 ? 0 : _c, _d = _b.offsetY, offsetY = _d === void 0 ? 0 : _d;
1048
+ x = offsetX;
1049
+ y = offsetY;
1050
+ }
1051
+ _.canvasDataSource.zoomToPoint({
1052
+ x: x,
1053
+ y: y
1054
+ }, zoom // 传入修改后的缩放级别
1055
+ );
1056
+ _.canvasDataSource.requestRenderAll();
1057
+ };
1058
+ CanvasHooks.prototype.getCanvasActionDataFn = function () {
1059
+ var _a, _b, _c, _d, _e;
1060
+ var _ = this;
1061
+ if (!_.canvasDataSource) {
1062
+ return;
1063
+ }
1064
+ var zoom = _.canvasDataSource.getZoom();
1065
+ console.log("getCanvasActionDataFn--zoom=", zoom);
1066
+ var x = 0;
1067
+ var y = 0;
1068
+ var left = 0;
1069
+ var top = 0;
1070
+ if ((_a = _.mouseWheelPointerDataSource) === null || _a === void 0 ? void 0 : _a.e) {
1071
+ var _f = _.mouseWheelPointerDataSource.e, _g = _f.offsetX, offsetX = _g === void 0 ? 0 : _g, _h = _f.offsetY, offsetY = _h === void 0 ? 0 : _h;
1072
+ x = offsetX;
1073
+ y = offsetY;
1074
+ left = ((_c = (_b = _.mouseWheelPointerDataSource) === null || _b === void 0 ? void 0 : _b.absolutePointer) === null || _c === void 0 ? void 0 : _c.x) || 0;
1075
+ top = ((_e = (_d = _.mouseWheelPointerDataSource) === null || _d === void 0 ? void 0 : _d.absolutePointer) === null || _e === void 0 ? void 0 : _e.y) || 0;
1076
+ }
1077
+ return {
1078
+ zoom: zoom,
1079
+ x: x,
1080
+ y: y,
1081
+ left: left,
1082
+ top: top,
1083
+ };
1084
+ };
1085
+ return CanvasHooks;
1086
+ }());
1087
+ exports.default = CanvasHooks;
package/dist/index.js CHANGED
@@ -33,6 +33,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
33
  __setModuleDefault(result, mod);
34
34
  return result;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  var storage = __importStar(require("./storage"));
38
41
  var utils = __importStar(require("./utils"));
@@ -44,5 +47,8 @@ var isType = __importStar(require("./is"));
44
47
  var modal = __importStar(require("./modal"));
45
48
  var params = __importStar(require("./params"));
46
49
  var iframe = __importStar(require("./iframe"));
47
- var obj = __assign(__assign(__assign({}, storage), utils), { weixin: __assign({}, weixin), crypto: __assign({}, crypto), date: __assign({}, time), format: __assign({}, format), type: __assign({}, isType), modal: __assign({}, modal), params: __assign({}, params), iframe: __assign({}, iframe) });
50
+ var canvas_1 = __importDefault(require("./canvas"));
51
+ var obj = __assign(__assign(__assign({}, storage), utils), { weixin: __assign({}, weixin), crypto: __assign({}, crypto), date: __assign({}, time), format: __assign({}, format), type: __assign({}, isType), modal: __assign({}, modal), params: __assign({}, params), iframe: __assign({}, iframe), canvas: {
52
+ CanvasHooks: canvas_1.default,
53
+ } });
48
54
  exports.default = obj;
@@ -394,9 +394,10 @@ function configReady(config) {
394
394
  signature: data === null || data === void 0 ? void 0 : data.signature, //必填,生成的签名
395
395
  };
396
396
  var wx = initSdk();
397
+ console.log("wx.config.data:", obj);
397
398
  wx.config(obj);
398
399
  wx.ready(function (res) {
399
- (0, index_1.useSessionStorage)("configReadySuccess", "wx.ready");
400
+ (0, index_1.useSessionStorage)("configReadySuccess-wx.ready", res);
400
401
  if (config['cb'] && typeof config.cb === "function")
401
402
  config.cb();
402
403
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.6.47",
3
+ "version": "1.6.49",
4
4
  "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "crypto-js": "^4.1.1",
21
+ "fabric": "^5.3.0",
21
22
  "weixin-js-sdk": "^1.6.0"
22
23
  },
23
24
  "repository": {