handle.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Handle = void 0;
  4. var tslib_1 = require("tslib");
  5. var core_1 = require("../../core");
  6. var util_1 = require("../../util");
  7. var constant_1 = require("./constant");
  8. var CLASS_NAMES = (0, util_1.classNames)({
  9. labelGroup: 'label-group',
  10. label: 'label',
  11. iconGroup: 'icon-group',
  12. icon: 'icon',
  13. iconRect: 'icon-rect',
  14. iconLine: 'icon-line',
  15. }, 'handle');
  16. var HandleIcon = /** @class */ (function (_super) {
  17. tslib_1.__extends(HandleIcon, _super);
  18. function HandleIcon() {
  19. return _super !== null && _super.apply(this, arguments) || this;
  20. }
  21. HandleIcon.prototype.render = function (attributes, container) {
  22. var _a = attributes.size, size = _a === void 0 ? 10 : _a, _b = attributes.radius, radius = _b === void 0 ? size / 4 : _b, orientation = attributes.orientation, iconStyle = tslib_1.__rest(attributes, ["size", "radius", "orientation"]);
  23. // 默认手柄
  24. var width = size;
  25. var height = width * 2.4;
  26. var rect = (0, util_1.select)(container)
  27. .maybeAppendByClassName(CLASS_NAMES.iconRect, 'rect')
  28. .styles(tslib_1.__assign(tslib_1.__assign({}, iconStyle), { width: width, height: height, radius: radius, x: -width / 2, y: -height / 2 }));
  29. var x1 = (1 / 3) * width;
  30. var x2 = (2 / 3) * width;
  31. var y1 = (1 / 4) * height;
  32. var y2 = (3 / 4) * height;
  33. rect.maybeAppendByClassName("".concat(CLASS_NAMES.iconLine, "-1"), 'line').styles(tslib_1.__assign({ x1: x1, x2: x1, y1: y1, y2: y2 }, iconStyle));
  34. rect.maybeAppendByClassName("".concat(CLASS_NAMES.iconLine, "-2"), 'line').styles(tslib_1.__assign({ x1: x2, x2: x2, y1: y1, y2: y2 }, iconStyle));
  35. rect.node().setOrigin(width / 2, height / 2);
  36. if (orientation === 'vertical')
  37. container.setLocalEulerAngles(90);
  38. else
  39. container.setLocalEulerAngles(0);
  40. };
  41. return HandleIcon;
  42. }(core_1.GUI));
  43. var Handle = /** @class */ (function (_super) {
  44. tslib_1.__extends(Handle, _super);
  45. function Handle(options) {
  46. return _super.call(this, options, constant_1.HANDLE_DEFAULT_CFG) || this;
  47. }
  48. Handle.prototype.renderLabel = function (container) {
  49. var _this = this;
  50. var showLabel = this.attributes.showLabel;
  51. var style = (0, util_1.subStyleProps)(this.attributes, 'label');
  52. var _a = tslib_1.__read((0, util_1.splitStyle)(style, []), 2), labelStyle = _a[0], groupStyle = _a[1];
  53. var labelGroup = (0, util_1.select)(container).maybeAppendByClassName(CLASS_NAMES.labelGroup, 'g').styles(groupStyle);
  54. // @ts-ignore
  55. var _b = tslib_1.__assign(tslib_1.__assign({}, constant_1.HANDLE_LABEL_DEFAULT_CFG), labelStyle), text = _b.text, rest = tslib_1.__rest(_b, ["text"]);
  56. (0, util_1.ifShow)(!!showLabel, labelGroup, function (group) {
  57. _this.label = group.maybeAppendByClassName(CLASS_NAMES.label, 'text').styles(tslib_1.__assign(tslib_1.__assign({}, rest), { text: "".concat(text) }));
  58. /** avoid trigger event on label */
  59. _this.label.on('mousedown', function (e) {
  60. e.stopPropagation();
  61. });
  62. _this.label.on('touchstart', function (e) {
  63. e.stopPropagation();
  64. });
  65. });
  66. };
  67. Handle.prototype.renderIcon = function (container) {
  68. var orientation = this.attributes.orientation;
  69. var iconStyle = tslib_1.__assign(tslib_1.__assign({ orientation: orientation }, constant_1.HANDLE_ICON_DEFAULT_CFG), (0, util_1.subStyleProps)(this.attributes, 'icon'));
  70. var _a = this.attributes.iconShape, iconShape = _a === void 0 ? function () { return new HandleIcon({ style: iconStyle }); } : _a;
  71. var iconGroup = (0, util_1.select)(container).maybeAppendByClassName(CLASS_NAMES.iconGroup, 'g');
  72. iconGroup
  73. .selectAll(CLASS_NAMES.icon.class)
  74. .data([iconShape])
  75. .join(function (enter) { return enter.append(iconShape).attr('className', CLASS_NAMES.icon.name); }, function (update) { return update.update(iconStyle); }, function (exit) { return exit.remove(); });
  76. };
  77. Handle.prototype.render = function (attributes, container) {
  78. this.renderIcon(container);
  79. this.renderLabel(container);
  80. };
  81. return Handle;
  82. }(core_1.GUI));
  83. exports.Handle = Handle;
  84. //# sourceMappingURL=handle.js.map