| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.Handle = void 0;
- var tslib_1 = require("tslib");
- var core_1 = require("../../core");
- var util_1 = require("../../util");
- var constant_1 = require("./constant");
- var CLASS_NAMES = (0, util_1.classNames)({
- labelGroup: 'label-group',
- label: 'label',
- iconGroup: 'icon-group',
- icon: 'icon',
- iconRect: 'icon-rect',
- iconLine: 'icon-line',
- }, 'handle');
- var HandleIcon = /** @class */ (function (_super) {
- tslib_1.__extends(HandleIcon, _super);
- function HandleIcon() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- HandleIcon.prototype.render = function (attributes, container) {
- 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"]);
- // 默认手柄
- var width = size;
- var height = width * 2.4;
- var rect = (0, util_1.select)(container)
- .maybeAppendByClassName(CLASS_NAMES.iconRect, 'rect')
- .styles(tslib_1.__assign(tslib_1.__assign({}, iconStyle), { width: width, height: height, radius: radius, x: -width / 2, y: -height / 2 }));
- var x1 = (1 / 3) * width;
- var x2 = (2 / 3) * width;
- var y1 = (1 / 4) * height;
- var y2 = (3 / 4) * height;
- rect.maybeAppendByClassName("".concat(CLASS_NAMES.iconLine, "-1"), 'line').styles(tslib_1.__assign({ x1: x1, x2: x1, y1: y1, y2: y2 }, iconStyle));
- rect.maybeAppendByClassName("".concat(CLASS_NAMES.iconLine, "-2"), 'line').styles(tslib_1.__assign({ x1: x2, x2: x2, y1: y1, y2: y2 }, iconStyle));
- rect.node().setOrigin(width / 2, height / 2);
- if (orientation === 'vertical')
- container.setLocalEulerAngles(90);
- else
- container.setLocalEulerAngles(0);
- };
- return HandleIcon;
- }(core_1.GUI));
- var Handle = /** @class */ (function (_super) {
- tslib_1.__extends(Handle, _super);
- function Handle(options) {
- return _super.call(this, options, constant_1.HANDLE_DEFAULT_CFG) || this;
- }
- Handle.prototype.renderLabel = function (container) {
- var _this = this;
- var showLabel = this.attributes.showLabel;
- var style = (0, util_1.subStyleProps)(this.attributes, 'label');
- var _a = tslib_1.__read((0, util_1.splitStyle)(style, []), 2), labelStyle = _a[0], groupStyle = _a[1];
- var labelGroup = (0, util_1.select)(container).maybeAppendByClassName(CLASS_NAMES.labelGroup, 'g').styles(groupStyle);
- // @ts-ignore
- var _b = tslib_1.__assign(tslib_1.__assign({}, constant_1.HANDLE_LABEL_DEFAULT_CFG), labelStyle), text = _b.text, rest = tslib_1.__rest(_b, ["text"]);
- (0, util_1.ifShow)(!!showLabel, labelGroup, function (group) {
- _this.label = group.maybeAppendByClassName(CLASS_NAMES.label, 'text').styles(tslib_1.__assign(tslib_1.__assign({}, rest), { text: "".concat(text) }));
- /** avoid trigger event on label */
- _this.label.on('mousedown', function (e) {
- e.stopPropagation();
- });
- _this.label.on('touchstart', function (e) {
- e.stopPropagation();
- });
- });
- };
- Handle.prototype.renderIcon = function (container) {
- var orientation = this.attributes.orientation;
- var iconStyle = tslib_1.__assign(tslib_1.__assign({ orientation: orientation }, constant_1.HANDLE_ICON_DEFAULT_CFG), (0, util_1.subStyleProps)(this.attributes, 'icon'));
- var _a = this.attributes.iconShape, iconShape = _a === void 0 ? function () { return new HandleIcon({ style: iconStyle }); } : _a;
- var iconGroup = (0, util_1.select)(container).maybeAppendByClassName(CLASS_NAMES.iconGroup, 'g');
- iconGroup
- .selectAll(CLASS_NAMES.icon.class)
- .data([iconShape])
- .join(function (enter) { return enter.append(iconShape).attr('className', CLASS_NAMES.icon.name); }, function (update) { return update.update(iconStyle); }, function (exit) { return exit.remove(); });
- };
- Handle.prototype.render = function (attributes, container) {
- this.renderIcon(container);
- this.renderLabel(container);
- };
- return Handle;
- }(core_1.GUI));
- exports.Handle = Handle;
- //# sourceMappingURL=handle.js.map
|