UNPKG

qwc2

Version:
208 lines (207 loc) 10.5 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Copyright 2025 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import React from 'react'; import PropTypes from 'prop-types'; import MiscUtils from '../utils/MiscUtils'; import './style/ExportSelection.css'; var ExportSelection = /*#__PURE__*/function (_React$Component) { function ExportSelection() { var _this; _classCallCheck(this, ExportSelection); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, ExportSelection, [].concat(args)); _defineProperty(_this, "state", { x: 0, y: 0, width: 0, height: 0, frameRatio: null }); _defineProperty(_this, "startMoveSelection", function (ev) { if (ev.ctrlKey) { return; } var startStateX = _this.state.x; var startStateY = _this.state.y; var onMouseMove = function onMouseMove(event) { _this.setState({ x: startStateX + event.clientX - ev.clientX, y: startStateY + event.clientY - ev.clientY }); }; ev.view.addEventListener('pointermove', onMouseMove); ev.view.addEventListener('pointerup', function () { ev.view.removeEventListener('pointermove', onMouseMove); _this.props.onFrameChanged(_this.state); }, { once: true }); MiscUtils.killEvent(ev); }); _defineProperty(_this, "startResizeSelection", function (ev, sx, sy) { if (ev.ctrlKey) { return; } var _this$state = _this.state, x = _this$state.x, y = _this$state.y, width = _this$state.width, height = _this$state.height, frameRatio = _this$state.frameRatio; var onMouseMove = function onMouseMove(event) { var dx = event.clientX - ev.clientX; var dy = event.clientY - ev.clientY; var newwidth = width + dx * sx; var newheight = height + dy * sy; if (frameRatio) { if (sx !== 0) { newheight = Math.round(newwidth * frameRatio); } else { newwidth = Math.round(newheight / frameRatio); } } var newx = sx < 0 ? x + (width - newwidth) : x; var newy = sy < 0 ? y + (height - newheight) : y; if (sx === 0) { newx += 0.5 * (width - newwidth); } if (sy === 0) { newy += 0.5 * (height - newheight); } _this.setState({ x: newx, y: newy, width: newwidth, height: newheight }); }; ev.view.addEventListener('pointermove', onMouseMove); ev.view.addEventListener('pointerup', function () { ev.view.removeEventListener('pointermove', onMouseMove); _this.props.onFrameChanged(_this.state); }, { once: true }); MiscUtils.killEvent(ev); }); return _this; } _inherits(ExportSelection, _React$Component); return _createClass(ExportSelection, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this2 = this; if (this.props.frame !== prevProps.frame) { this.setState(_objectSpread({}, this.props.frame)); } if (this.props.frameRatio !== prevProps.frameRatio) { this.setState(function (state) { var newheight = _this2.props.frameRatio ? Math.round(state.width * _this2.props.frameRatio) : state.height; return { frameRatio: _this2.props.frameRatio, y: state.y + 0.5 * (state.height - newheight), height: newheight }; }, function () { _this2.props.onFrameChanged(_this2.state); }); } } }, { key: "render", value: function render() { var _this3 = this; var boxStyle = { left: this.state.x + 'px', top: this.state.y + 'px', width: this.state.width + 'px', height: this.state.height + 'px' }; return /*#__PURE__*/React.createElement("div", { className: "export-selection-container" }, /*#__PURE__*/React.createElement("div", { className: "export-selection", onContextMenu: MiscUtils.killEvent, onPointerDown: this.startMoveSelection, style: boxStyle }, /*#__PURE__*/React.createElement("span", { className: "export-selection-label" }, this.state.width + " x " + this.state.height), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-top", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, 0, -1); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-bottom", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, 0, 1); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-left", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, -1, 0); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-right", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, 1, 0); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-topleft", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, -1, -1); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-topright", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, 1, -1); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-bottomleft", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, -1, 1); } }), /*#__PURE__*/React.createElement("div", { className: "export-selection-resize-bottomright", onPointerDown: function onPointerDown(ev) { return _this3.startResizeSelection(ev, 1, 1); } }))); } }]); }(React.Component); _defineProperty(ExportSelection, "propTypes", { frame: PropTypes.shape({ x: PropTypes.number, y: PropTypes.number, width: PropTypes.number, height: PropTypes.number }), frameRatio: PropTypes.number, mapElement: PropTypes.object, onFrameChanged: PropTypes.func }); export { ExportSelection as default };