xctc-utils 1.6.55 → 1.6.58

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.
@@ -28,6 +28,7 @@ var create_1 = require("../handle/create");
28
28
  var query_1 = require("../handle/query");
29
29
  var update_1 = require("../handle/update");
30
30
  var changed_1 = require("../event/changed");
31
+ var index_2 = require("../event/index");
31
32
  // 初始化画布创建时需要的参数-默认值
32
33
  var defaultConfig = __assign({}, config_1.configDefaultValue.canvasDefaultValue);
33
34
  var CanvasHooks = /** @class */ (function () {
@@ -163,6 +164,10 @@ var CanvasHooks = /** @class */ (function () {
163
164
  function callBack(data) {
164
165
  var _a;
165
166
  var cb = ((_a = _.canvasConfig) === null || _a === void 0 ? void 0 : _a.cb) || "";
167
+ // 获取DOM元素
168
+ var targetElement = (0, utils_1.getDomFn)("canvasContainer");
169
+ // 添加事件监听器
170
+ document.addEventListener('mousemove', (0, index_2.checkMouseInElement)(targetElement));
166
171
  if (cb instanceof Function) {
167
172
  cb(data);
168
173
  }
@@ -231,6 +236,15 @@ var CanvasHooks = /** @class */ (function () {
231
236
  _.canvasDataSource.on('zoom:changed', function (options) {
232
237
  _.registerCanvasZoomChangeEventFn(options);
233
238
  });
239
+ _.canvasDataSource.on('contextmenu', function (options) {
240
+ var _a;
241
+ // 阻止默认行为(即阻止显示浏览器的上下文菜单)
242
+ (_a = options === null || options === void 0 ? void 0 : options.e) === null || _a === void 0 ? void 0 : _a.preventDefault();
243
+ });
244
+ // 附加的选项,如果你需要阻止整个页面的默认右键菜单
245
+ document.body.addEventListener('contextmenu', function (event) {
246
+ event === null || event === void 0 ? void 0 : event.preventDefault();
247
+ });
234
248
  };
235
249
  // 注册画布发生缩放监听事件
236
250
  CanvasHooks.prototype.registerCanvasZoomChangeEventFn = function () {
@@ -0,0 +1 @@
1
+ export declare function checkMouseInElement(element: any): (event: any) => boolean;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkMouseInElement = void 0;
4
+ var win = window || {};
5
+ function checkMouseInElement(element) {
6
+ return function (event) {
7
+ // 获取鼠标相对于文档的位置
8
+ var mouseX = event === null || event === void 0 ? void 0 : event.clientX;
9
+ var mouseY = event === null || event === void 0 ? void 0 : event.clientY;
10
+ // 获取目标元素的位置和尺寸
11
+ var rect = element === null || element === void 0 ? void 0 : element.getBoundingClientRect();
12
+ // 判断鼠标是否在元素内
13
+ var isInElement = (mouseX >= (rect === null || rect === void 0 ? void 0 : rect.left) &&
14
+ mouseX <= (rect === null || rect === void 0 ? void 0 : rect.right) &&
15
+ mouseY >= (rect === null || rect === void 0 ? void 0 : rect.top) &&
16
+ mouseY <= (rect === null || rect === void 0 ? void 0 : rect.bottom));
17
+ if (isInElement) {
18
+ console.log('鼠标在元素内部');
19
+ }
20
+ else {
21
+ console.log('鼠标不在元素内部');
22
+ }
23
+ win['mouseIsInElement'] = isInElement;
24
+ return isInElement;
25
+ };
26
+ }
27
+ exports.checkMouseInElement = checkMouseInElement;
@@ -16,6 +16,7 @@ function RegisterMouseDownEventFn(options) {
16
16
  _.mouseWheelStatus = false;
17
17
  _.mouseClickType = (options === null || options === void 0 ? void 0 : options.button) || 1; // 鼠标点击类型 1 左键 2中间滚轮 3右键
18
18
  console.log("mouseClickType==", _.mouseClickType);
19
+ console.log("mouseRightClickStatus==", _.mouseRightClickStatus);
19
20
  if (_.mouseRightClickStatus) {
20
21
  // 如果当前处于右键状态,则不再继续执行任何操作
21
22
  // 如果菜单属于显示状态,则关闭菜单
@@ -55,6 +56,7 @@ function RegisterMouseDownEventFn(options) {
55
56
  _.hiddenRightClickMenuFn();
56
57
  return;
57
58
  }
59
+ console.log("canvasDragStatus==", _.canvasDragStatus);
58
60
  // 点击画布上的对象执行操作
59
61
  if (activeTarget) {
60
62
  // 画布上的数据对象被点击
@@ -75,12 +77,15 @@ function RegisterMouseDownEventFn(options) {
75
77
  }, 0);
76
78
  }
77
79
  }
80
+ // console.log("mouseClickType==", _.mouseClickType );
78
81
  // 画布可拖拽状态
79
82
  if (_.canvasDragStatus) {
80
83
  // 如果当前点击了底层画布,则允许底层画布可以拖拽
81
84
  console.log("允许底层画布可以拖拽");
85
+ console.log("activeTarget==", activeTarget);
82
86
  if (!activeTarget) {
83
87
  // 如果没有获取到具体的目标对象,则默认是点击了画布底图,即开启画布的拖拽
88
+ console.log("如果没有获取到具体的目标对象,则默认是点击了画布底图,即开启画布的拖拽");
84
89
  _.dragLastPosDataSource.open = true;
85
90
  _.dragLastPosDataSource.lastPosX = event.clientX;
86
91
  _.dragLastPosDataSource.lastPosY = event.clientY;
@@ -88,7 +93,7 @@ function RegisterMouseDownEventFn(options) {
88
93
  }
89
94
  }
90
95
  else {
91
- console.log("3333");
96
+ console.log("画布不可拖拽状态");
92
97
  _.dragLastPosDataSource.open = false;
93
98
  return;
94
99
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RegisterMouseMoveEventFn = void 0;
4
4
  var is_1 = require("../is");
5
+ var win = window || {};
5
6
  function RegisterMouseMoveEventFn(options) {
6
7
  if (!(0, is_1.isObject)(options)) {
7
8
  return;
@@ -11,9 +12,10 @@ function RegisterMouseMoveEventFn(options) {
11
12
  var pointer = _.canvasDataSource.getPointer(options.e);
12
13
  var inRange = pointer.x >= 0 && pointer.x <= _.canvasDataSource.width &&
13
14
  pointer.y >= 0 && pointer.y <= _.canvasDataSource.height;
14
- _.mouseCanvasInRangeStatus = inRange;
15
+ _.mouseCanvasInRangeStatus = win['mouseIsInElement'];
15
16
  // 鼠标不在画布内,终止行为
16
- if (!inRange) {
17
+ if (!_.mouseCanvasInRangeStatus) {
18
+ console.log("鼠标不在画布内,终止行为");
17
19
  return;
18
20
  }
19
21
  var activeTarget = options.target || options.activeTarget;
@@ -15,7 +15,7 @@ function RegisterMouseUpEventFn(options) {
15
15
  var _a = _.callBackEventConfig || {}, activeTargetElementBackFn = _a.activeTargetElementBackFn, activeTargetSelectionRectBackFn = _a.activeTargetSelectionRectBackFn;
16
16
  _.mouseWheelPointerDataSource = options;
17
17
  console.log("activeTarget==", activeTarget);
18
- console.log("_.canvasDataSource==", _.canvasDataSource.backgroundImage);
18
+ console.log("_.canvasDataSource==", _.canvasDataSource);
19
19
  setTimeout(function () {
20
20
  _.mouseWheelStatus = false;
21
21
  }, 0);
@@ -160,12 +160,17 @@ function CreateAllSelectionRectFn(fabric) {
160
160
  if (!_.canvasDataSource) {
161
161
  return;
162
162
  }
163
+ var container = (0, utils_1.getDomFn)("canvasContainer");
164
+ console.log("xxx---", _.canvasDataSource.getWidth());
165
+ var containerWidth = container.offsetWidth;
166
+ var containerHeight = container.offsetWidth;
163
167
  _.createSelectionRectDataSource = new fabric.Rect({
164
168
  left: 0,
165
169
  top: 0,
166
170
  width: _.canvasDataSource.getWidth(),
167
171
  height: _.canvasDataSource.getHeight(),
168
- fill: 'rgba(0,0,255,0.1)',
172
+ // fill: 'rgba(0,0,255,0.1)',
173
+ fill: "red",
169
174
  stroke: 'blue',
170
175
  // fill:"transparent",
171
176
  strokeWidth: 1,
@@ -176,11 +181,13 @@ function CreateAllSelectionRectFn(fabric) {
176
181
  hoverCursor: 'move',
177
182
  renderType: "frameSelection", // 代表框选
178
183
  });
184
+ _.canvasDataSource.setDimensions({ width: containerWidth, height: containerHeight }, true);
179
185
  _.canvasDataSource.add(_.createSelectionRectDataSource);
180
186
  _.canvasDataSource.requestRenderAll();
181
187
  }
182
188
  exports.CreateAllSelectionRectFn = CreateAllSelectionRectFn;
183
189
  function CreateRightClickMenuFn(options) {
190
+ console.log("options111==", options);
184
191
  if (!(0, is_1.isObject)(options)) {
185
192
  return;
186
193
  }
@@ -211,6 +218,7 @@ function CreateRightClickMenuFn(options) {
211
218
  liItem.addEventListener("click", function (event) {
212
219
  // 点击右键菜单回调函数
213
220
  console.log("rightButtonMenuClickBackFn==", rightButtonMenuClickBackFn);
221
+ event.preventDefault();
214
222
  if (rightButtonMenuClickBackFn instanceof Function) {
215
223
  rightButtonMenuClickBackFn(event.target['data-index']);
216
224
  }
@@ -32,7 +32,7 @@ function QueryCanvasActionDataFn() {
32
32
  }
33
33
  exports.QueryCanvasActionDataFn = QueryCanvasActionDataFn;
34
34
  function QueryElementSizeFn(id) {
35
- if (!(0, is_1.isObject)(id)) {
35
+ if (!(0, is_1.isString)(id)) {
36
36
  return;
37
37
  }
38
38
  var _ = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.6.55",
3
+ "version": "1.6.58",
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",