@idraw/core 0.2.0-alpha.2 → 0.2.0-alpha.3

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/index.cjs.js CHANGED
@@ -2377,25 +2377,71 @@ var Helper = (function () {
2377
2377
  }
2378
2378
  return null;
2379
2379
  };
2380
- Helper.prototype.isPointInElementWrapperDot = function (p) {
2380
+ Helper.prototype.isPointInElementWrapperDot = function (p, data) {
2381
2381
  var _a, _b;
2382
2382
  var ctx = this._ctx;
2383
- var uuid = (_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid;
2383
+ var uuid = ((_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid) || null;
2384
+ var directIdx = null;
2384
2385
  var direction = null;
2385
2386
  if (!this._helperConfig.selectedElementWrapper) {
2386
- return [null, null];
2387
+ return [uuid, direction, directIdx];
2387
2388
  }
2388
2389
  var wrapper = this._helperConfig.selectedElementWrapper;
2389
2390
  var dots = [
2390
- wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
2391
- wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
2392
- wrapper.dots.rotate,
2391
+ wrapper.dots.right,
2392
+ wrapper.dots.topRight,
2393
+ wrapper.dots.top,
2394
+ wrapper.dots.topLeft,
2395
+ wrapper.dots.left,
2396
+ wrapper.dots.bottomLeft,
2397
+ wrapper.dots.bottom,
2398
+ wrapper.dots.bottomRight,
2393
2399
  ];
2394
2400
  var directionNames = [
2395
- 'top-left', 'top', 'top-right', 'right',
2396
- 'bottom-right', 'bottom', 'bottom-left', 'left',
2397
- 'rotate',
2401
+ 'right',
2402
+ 'top-right',
2403
+ 'top',
2404
+ 'top-left',
2405
+ 'left',
2406
+ 'bottom-left',
2407
+ 'bottom',
2408
+ 'bottom-right',
2398
2409
  ];
2410
+ var angleMoveNum = 0;
2411
+ if (data && uuid) {
2412
+ var elemIdx = this.getElementIndexByUUID(uuid);
2413
+ if (elemIdx !== null && elemIdx >= 0) {
2414
+ var elem = data.elements[elemIdx];
2415
+ var angle = elem.angle;
2416
+ if (angle < 0) {
2417
+ angle += 360;
2418
+ }
2419
+ if (angle < 45) {
2420
+ angleMoveNum = 0;
2421
+ }
2422
+ else if (angle < 90) {
2423
+ angleMoveNum = 1;
2424
+ }
2425
+ else if (angle < 135) {
2426
+ angleMoveNum = 2;
2427
+ }
2428
+ else if (angle < 180) {
2429
+ angleMoveNum = 3;
2430
+ }
2431
+ else if (angle < 225) {
2432
+ angleMoveNum = 4;
2433
+ }
2434
+ else if (angle < 270) {
2435
+ angleMoveNum = 5;
2436
+ }
2437
+ else if (angle < 315) {
2438
+ angleMoveNum = 6;
2439
+ }
2440
+ }
2441
+ }
2442
+ if (angleMoveNum > 0) {
2443
+ directionNames = directionNames.slice(-angleMoveNum).concat(directionNames.slice(0, -angleMoveNum));
2444
+ }
2399
2445
  rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2400
2446
  for (var i = 0; i < dots.length; i++) {
2401
2447
  var dot = dots[i];
@@ -2406,11 +2452,23 @@ var Helper = (function () {
2406
2452
  direction = directionNames[i];
2407
2453
  }
2408
2454
  if (direction) {
2455
+ directIdx = i;
2409
2456
  break;
2410
2457
  }
2411
2458
  }
2412
2459
  });
2413
- return [uuid, direction];
2460
+ if (direction === null) {
2461
+ rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2462
+ var dot = wrapper.dots.rotate;
2463
+ ctx.beginPath();
2464
+ ctx.arc(dot.x, dot.y, wrapper.dotSize, 0, Math.PI * 2);
2465
+ ctx.closePath();
2466
+ if (ctx.isPointInPath(p.x, p.y)) {
2467
+ direction = 'rotate';
2468
+ }
2469
+ });
2470
+ }
2471
+ return [uuid, direction, directIdx];
2414
2472
  };
2415
2473
  Helper.prototype.isPointInElementList = function (p, data) {
2416
2474
  var _a, _b;
@@ -2936,9 +2994,13 @@ var Mapper = (function () {
2936
2994
  if (!this.isEffectivePoint(p)) {
2937
2995
  return { cursor: cursor, elementUUID: elementUUID };
2938
2996
  }
2939
- var _a = this[_helper$1].isPointInElementWrapperDot(p), uuid = _a[0], direction = _a[1];
2997
+ var _a = this[_helper$1].isPointInElementWrapperDot(p, data), uuid = _a[0], direction = _a[1];
2940
2998
  if (uuid && direction) {
2941
2999
  switch (direction) {
3000
+ case 'top-right': {
3001
+ cursor = 'ne-resize';
3002
+ break;
3003
+ }
2942
3004
  case 'top-left': {
2943
3005
  cursor = 'nw-resize';
2944
3006
  break;
@@ -2947,10 +3009,6 @@ var Mapper = (function () {
2947
3009
  cursor = 'n-resize';
2948
3010
  break;
2949
3011
  }
2950
- case 'top-right': {
2951
- cursor = 'ne-resize';
2952
- break;
2953
- }
2954
3012
  case 'right': {
2955
3013
  cursor = 'e-resize';
2956
3014
  break;
@@ -3372,7 +3430,7 @@ function handlePoint(core) {
3372
3430
  core[_tempData].set('mode', Mode.SELECT_ELEMENT_LIST);
3373
3431
  }
3374
3432
  else {
3375
- var _d = core[_helper].isPointInElementWrapperDot(point), uuid = _d[0], direction = _d[1];
3433
+ var _d = core[_helper].isPointInElementWrapperDot(point, core[_data]), uuid = _d[0], direction = _d[1];
3376
3434
  if (uuid && direction) {
3377
3435
  core[_tempData].set('mode', Mode.SELECT_ELEMENT_WRAPPER_DOT);
3378
3436
  core[_tempData].set('selectedDotDirection', direction);
package/dist/index.es.js CHANGED
@@ -2375,25 +2375,71 @@ var Helper = (function () {
2375
2375
  }
2376
2376
  return null;
2377
2377
  };
2378
- Helper.prototype.isPointInElementWrapperDot = function (p) {
2378
+ Helper.prototype.isPointInElementWrapperDot = function (p, data) {
2379
2379
  var _a, _b;
2380
2380
  var ctx = this._ctx;
2381
- var uuid = (_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid;
2381
+ var uuid = ((_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid) || null;
2382
+ var directIdx = null;
2382
2383
  var direction = null;
2383
2384
  if (!this._helperConfig.selectedElementWrapper) {
2384
- return [null, null];
2385
+ return [uuid, direction, directIdx];
2385
2386
  }
2386
2387
  var wrapper = this._helperConfig.selectedElementWrapper;
2387
2388
  var dots = [
2388
- wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
2389
- wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
2390
- wrapper.dots.rotate,
2389
+ wrapper.dots.right,
2390
+ wrapper.dots.topRight,
2391
+ wrapper.dots.top,
2392
+ wrapper.dots.topLeft,
2393
+ wrapper.dots.left,
2394
+ wrapper.dots.bottomLeft,
2395
+ wrapper.dots.bottom,
2396
+ wrapper.dots.bottomRight,
2391
2397
  ];
2392
2398
  var directionNames = [
2393
- 'top-left', 'top', 'top-right', 'right',
2394
- 'bottom-right', 'bottom', 'bottom-left', 'left',
2395
- 'rotate',
2399
+ 'right',
2400
+ 'top-right',
2401
+ 'top',
2402
+ 'top-left',
2403
+ 'left',
2404
+ 'bottom-left',
2405
+ 'bottom',
2406
+ 'bottom-right',
2396
2407
  ];
2408
+ var angleMoveNum = 0;
2409
+ if (data && uuid) {
2410
+ var elemIdx = this.getElementIndexByUUID(uuid);
2411
+ if (elemIdx !== null && elemIdx >= 0) {
2412
+ var elem = data.elements[elemIdx];
2413
+ var angle = elem.angle;
2414
+ if (angle < 0) {
2415
+ angle += 360;
2416
+ }
2417
+ if (angle < 45) {
2418
+ angleMoveNum = 0;
2419
+ }
2420
+ else if (angle < 90) {
2421
+ angleMoveNum = 1;
2422
+ }
2423
+ else if (angle < 135) {
2424
+ angleMoveNum = 2;
2425
+ }
2426
+ else if (angle < 180) {
2427
+ angleMoveNum = 3;
2428
+ }
2429
+ else if (angle < 225) {
2430
+ angleMoveNum = 4;
2431
+ }
2432
+ else if (angle < 270) {
2433
+ angleMoveNum = 5;
2434
+ }
2435
+ else if (angle < 315) {
2436
+ angleMoveNum = 6;
2437
+ }
2438
+ }
2439
+ }
2440
+ if (angleMoveNum > 0) {
2441
+ directionNames = directionNames.slice(-angleMoveNum).concat(directionNames.slice(0, -angleMoveNum));
2442
+ }
2397
2443
  rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2398
2444
  for (var i = 0; i < dots.length; i++) {
2399
2445
  var dot = dots[i];
@@ -2404,11 +2450,23 @@ var Helper = (function () {
2404
2450
  direction = directionNames[i];
2405
2451
  }
2406
2452
  if (direction) {
2453
+ directIdx = i;
2407
2454
  break;
2408
2455
  }
2409
2456
  }
2410
2457
  });
2411
- return [uuid, direction];
2458
+ if (direction === null) {
2459
+ rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2460
+ var dot = wrapper.dots.rotate;
2461
+ ctx.beginPath();
2462
+ ctx.arc(dot.x, dot.y, wrapper.dotSize, 0, Math.PI * 2);
2463
+ ctx.closePath();
2464
+ if (ctx.isPointInPath(p.x, p.y)) {
2465
+ direction = 'rotate';
2466
+ }
2467
+ });
2468
+ }
2469
+ return [uuid, direction, directIdx];
2412
2470
  };
2413
2471
  Helper.prototype.isPointInElementList = function (p, data) {
2414
2472
  var _a, _b;
@@ -2934,9 +2992,13 @@ var Mapper = (function () {
2934
2992
  if (!this.isEffectivePoint(p)) {
2935
2993
  return { cursor: cursor, elementUUID: elementUUID };
2936
2994
  }
2937
- var _a = this[_helper$1].isPointInElementWrapperDot(p), uuid = _a[0], direction = _a[1];
2995
+ var _a = this[_helper$1].isPointInElementWrapperDot(p, data), uuid = _a[0], direction = _a[1];
2938
2996
  if (uuid && direction) {
2939
2997
  switch (direction) {
2998
+ case 'top-right': {
2999
+ cursor = 'ne-resize';
3000
+ break;
3001
+ }
2940
3002
  case 'top-left': {
2941
3003
  cursor = 'nw-resize';
2942
3004
  break;
@@ -2945,10 +3007,6 @@ var Mapper = (function () {
2945
3007
  cursor = 'n-resize';
2946
3008
  break;
2947
3009
  }
2948
- case 'top-right': {
2949
- cursor = 'ne-resize';
2950
- break;
2951
- }
2952
3010
  case 'right': {
2953
3011
  cursor = 'e-resize';
2954
3012
  break;
@@ -3370,7 +3428,7 @@ function handlePoint(core) {
3370
3428
  core[_tempData].set('mode', Mode.SELECT_ELEMENT_LIST);
3371
3429
  }
3372
3430
  else {
3373
- var _d = core[_helper].isPointInElementWrapperDot(point), uuid = _d[0], direction = _d[1];
3431
+ var _d = core[_helper].isPointInElementWrapperDot(point, core[_data]), uuid = _d[0], direction = _d[1];
3374
3432
  if (uuid && direction) {
3375
3433
  core[_tempData].set('mode', Mode.SELECT_ELEMENT_WRAPPER_DOT);
3376
3434
  core[_tempData].set('selectedDotDirection', direction);
@@ -2378,25 +2378,71 @@ var iDrawCore = (function () {
2378
2378
  }
2379
2379
  return null;
2380
2380
  };
2381
- Helper.prototype.isPointInElementWrapperDot = function (p) {
2381
+ Helper.prototype.isPointInElementWrapperDot = function (p, data) {
2382
2382
  var _a, _b;
2383
2383
  var ctx = this._ctx;
2384
- var uuid = (_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid;
2384
+ var uuid = ((_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid) || null;
2385
+ var directIdx = null;
2385
2386
  var direction = null;
2386
2387
  if (!this._helperConfig.selectedElementWrapper) {
2387
- return [null, null];
2388
+ return [uuid, direction, directIdx];
2388
2389
  }
2389
2390
  var wrapper = this._helperConfig.selectedElementWrapper;
2390
2391
  var dots = [
2391
- wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
2392
- wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
2393
- wrapper.dots.rotate,
2392
+ wrapper.dots.right,
2393
+ wrapper.dots.topRight,
2394
+ wrapper.dots.top,
2395
+ wrapper.dots.topLeft,
2396
+ wrapper.dots.left,
2397
+ wrapper.dots.bottomLeft,
2398
+ wrapper.dots.bottom,
2399
+ wrapper.dots.bottomRight,
2394
2400
  ];
2395
2401
  var directionNames = [
2396
- 'top-left', 'top', 'top-right', 'right',
2397
- 'bottom-right', 'bottom', 'bottom-left', 'left',
2398
- 'rotate',
2402
+ 'right',
2403
+ 'top-right',
2404
+ 'top',
2405
+ 'top-left',
2406
+ 'left',
2407
+ 'bottom-left',
2408
+ 'bottom',
2409
+ 'bottom-right',
2399
2410
  ];
2411
+ var angleMoveNum = 0;
2412
+ if (data && uuid) {
2413
+ var elemIdx = this.getElementIndexByUUID(uuid);
2414
+ if (elemIdx !== null && elemIdx >= 0) {
2415
+ var elem = data.elements[elemIdx];
2416
+ var angle = elem.angle;
2417
+ if (angle < 0) {
2418
+ angle += 360;
2419
+ }
2420
+ if (angle < 45) {
2421
+ angleMoveNum = 0;
2422
+ }
2423
+ else if (angle < 90) {
2424
+ angleMoveNum = 1;
2425
+ }
2426
+ else if (angle < 135) {
2427
+ angleMoveNum = 2;
2428
+ }
2429
+ else if (angle < 180) {
2430
+ angleMoveNum = 3;
2431
+ }
2432
+ else if (angle < 225) {
2433
+ angleMoveNum = 4;
2434
+ }
2435
+ else if (angle < 270) {
2436
+ angleMoveNum = 5;
2437
+ }
2438
+ else if (angle < 315) {
2439
+ angleMoveNum = 6;
2440
+ }
2441
+ }
2442
+ }
2443
+ if (angleMoveNum > 0) {
2444
+ directionNames = directionNames.slice(-angleMoveNum).concat(directionNames.slice(0, -angleMoveNum));
2445
+ }
2400
2446
  rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2401
2447
  for (var i = 0; i < dots.length; i++) {
2402
2448
  var dot = dots[i];
@@ -2407,11 +2453,23 @@ var iDrawCore = (function () {
2407
2453
  direction = directionNames[i];
2408
2454
  }
2409
2455
  if (direction) {
2456
+ directIdx = i;
2410
2457
  break;
2411
2458
  }
2412
2459
  }
2413
2460
  });
2414
- return [uuid, direction];
2461
+ if (direction === null) {
2462
+ rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2463
+ var dot = wrapper.dots.rotate;
2464
+ ctx.beginPath();
2465
+ ctx.arc(dot.x, dot.y, wrapper.dotSize, 0, Math.PI * 2);
2466
+ ctx.closePath();
2467
+ if (ctx.isPointInPath(p.x, p.y)) {
2468
+ direction = 'rotate';
2469
+ }
2470
+ });
2471
+ }
2472
+ return [uuid, direction, directIdx];
2415
2473
  };
2416
2474
  Helper.prototype.isPointInElementList = function (p, data) {
2417
2475
  var _a, _b;
@@ -2937,9 +2995,13 @@ var iDrawCore = (function () {
2937
2995
  if (!this.isEffectivePoint(p)) {
2938
2996
  return { cursor: cursor, elementUUID: elementUUID };
2939
2997
  }
2940
- var _a = this[_helper$1].isPointInElementWrapperDot(p), uuid = _a[0], direction = _a[1];
2998
+ var _a = this[_helper$1].isPointInElementWrapperDot(p, data), uuid = _a[0], direction = _a[1];
2941
2999
  if (uuid && direction) {
2942
3000
  switch (direction) {
3001
+ case 'top-right': {
3002
+ cursor = 'ne-resize';
3003
+ break;
3004
+ }
2943
3005
  case 'top-left': {
2944
3006
  cursor = 'nw-resize';
2945
3007
  break;
@@ -2948,10 +3010,6 @@ var iDrawCore = (function () {
2948
3010
  cursor = 'n-resize';
2949
3011
  break;
2950
3012
  }
2951
- case 'top-right': {
2952
- cursor = 'ne-resize';
2953
- break;
2954
- }
2955
3013
  case 'right': {
2956
3014
  cursor = 'e-resize';
2957
3015
  break;
@@ -3373,7 +3431,7 @@ var iDrawCore = (function () {
3373
3431
  core[_tempData].set('mode', Mode.SELECT_ELEMENT_LIST);
3374
3432
  }
3375
3433
  else {
3376
- var _d = core[_helper].isPointInElementWrapperDot(point), uuid = _d[0], direction = _d[1];
3434
+ var _d = core[_helper].isPointInElementWrapperDot(point, core[_data]), uuid = _d[0], direction = _d[1];
3377
3435
  if (uuid && direction) {
3378
3436
  core[_tempData].set('mode', Mode.SELECT_ELEMENT_WRAPPER_DOT);
3379
3437
  core[_tempData].set('selectedDotDirection', direction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idraw/core",
3
- "version": "0.2.0-alpha.2",
3
+ "version": "0.2.0-alpha.3",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -23,14 +23,14 @@
23
23
  "author": "chenshenhai",
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@idraw/types": "^0.2.0-alpha.2"
26
+ "@idraw/types": "^0.2.0-alpha.3"
27
27
  },
28
28
  "dependencies": {
29
- "@idraw/board": "^0.2.0-alpha.2",
30
- "@idraw/util": "^0.2.0-alpha.2"
29
+ "@idraw/board": "^0.2.0-alpha.3",
30
+ "@idraw/util": "^0.2.0-alpha.3"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "534215ec0c2581308ebc554b37a97dbae2e93484"
35
+ "gitHead": "4fbf7534ee4ab6e4a44973cdc747f1d490f63457"
36
36
  }