No Description

index.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var BaseMarker_1 = require("../BaseMarker");
  17. var ResizeGrip_1 = require("../BaseMarker/ResizeGrip");
  18. var SvgHelper_1 = require("../../renderer/SvgHelper");
  19. var LinearMarker = (function (_super) {
  20. __extends(LinearMarker, _super);
  21. function LinearMarker() {
  22. var _this = _super !== null && _super.apply(this, arguments) || this;
  23. _this.MIN_LENGTH = 20;
  24. _this.x1 = 0;
  25. _this.y1 = 0;
  26. _this.x2 = _this.width;
  27. _this.y2 = 0;
  28. _this.getLineLength = function (x1, y1, x2, y2) {
  29. var dx = Math.abs(x1 - x2);
  30. var dy = Math.abs(y1 - y2);
  31. return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
  32. };
  33. _this.addControlBox = function () {
  34. _this.controlBox = SvgHelper_1.SvgHelper.createGroup([['class', 'fc-whiteboard-line-control-box']]);
  35. _this.addToVisual(_this.controlBox);
  36. _this.addControlGrips();
  37. };
  38. _this.adjustControlBox = function () {
  39. _this.positionGrips();
  40. };
  41. _this.addControlGrips = function () {
  42. _this.controlGrips = {
  43. left: _this.createGrip(),
  44. right: _this.createGrip()
  45. };
  46. _this.positionGrips();
  47. };
  48. _this.createGrip = function () {
  49. var grip = new ResizeGrip_1.ResizeGrip();
  50. grip.visual.transform.baseVal.appendItem(SvgHelper_1.SvgHelper.createTransform());
  51. _this.controlBox.appendChild(grip.visual);
  52. grip.visual.addEventListener('mousedown', _this.gripMouseDown);
  53. grip.visual.addEventListener('mousemove', _this.gripMouseMove);
  54. grip.visual.addEventListener('mouseup', _this.gripMouseUp);
  55. grip.visual.addEventListener('touchstart', _this.onTouch, { passive: false });
  56. grip.visual.addEventListener('touchend', _this.onTouch, { passive: false });
  57. grip.visual.addEventListener('touchmove', _this.onTouch, { passive: false });
  58. return grip;
  59. };
  60. _this.positionGrips = function () {
  61. var gripSize = _this.controlGrips.left.GRIP_SIZE;
  62. var x1 = _this.x1 - gripSize / 2;
  63. var y1 = _this.y1 - gripSize / 2;
  64. var x2 = _this.x2 - gripSize / 2;
  65. var y2 = _this.y2 - gripSize / 2;
  66. _this.positionGrip(_this.controlGrips.left.visual, x1, y1);
  67. _this.positionGrip(_this.controlGrips.right.visual, x2, y2);
  68. };
  69. _this.positionGrip = function (grip, x, y) {
  70. var translate = grip.transform.baseVal.getItem(0);
  71. translate.setTranslate(x, y);
  72. grip.transform.baseVal.replaceItem(translate, 0);
  73. };
  74. _this.gripMouseDown = function (ev) {
  75. _this.isResizing = true;
  76. _this.activeGrip =
  77. ev.target === _this.controlGrips.left.visual
  78. ? _this.controlGrips.left
  79. : _this.controlGrips.right;
  80. _this.previousMouseX = ev.screenX;
  81. _this.previousMouseY = ev.screenY;
  82. ev.stopPropagation();
  83. };
  84. _this.gripMouseUp = function (ev) {
  85. _this.isResizing = false;
  86. _this.activeGrip = null;
  87. ev.stopPropagation();
  88. };
  89. _this.gripMouseMove = function (ev) {
  90. if (_this.isResizing) {
  91. _this.resize(ev.movementX, ev.movementY);
  92. }
  93. };
  94. return _this;
  95. }
  96. LinearMarker.prototype.endManipulation = function () {
  97. _super.prototype.endManipulation.call(this);
  98. this.isResizing = false;
  99. this.activeGrip = null;
  100. };
  101. LinearMarker.prototype.select = function () {
  102. _super.prototype.select.call(this);
  103. this.controlBox.style.display = '';
  104. };
  105. LinearMarker.prototype.deselect = function () {
  106. _super.prototype.deselect.call(this);
  107. this.controlBox.style.display = 'none';
  108. };
  109. LinearMarker.prototype.setup = function () {
  110. _super.prototype.setup.call(this);
  111. this.markerBgLine = SvgHelper_1.SvgHelper.createLine(0, 0, this.x2, 0, [
  112. ['stroke', 'transparent'],
  113. ['stroke-width', '30']
  114. ]);
  115. this.addToRenderVisual(this.markerBgLine);
  116. this.markerLine = SvgHelper_1.SvgHelper.createLine(0, 0, this.x2, 0);
  117. this.addToRenderVisual(this.markerLine);
  118. this.addControlBox();
  119. if (this.page && this.page.mode === 'mirror') {
  120. this.controlBox.style.display = 'none';
  121. }
  122. };
  123. LinearMarker.prototype.resize = function (x, y, onPosition) {
  124. if (this.activeGrip) {
  125. if (this.activeGrip === this.controlGrips.left &&
  126. this.getLineLength(this.x1 + x, this.y1 + 1, this.x2, this.y2) >= this.MIN_LENGTH) {
  127. this.x1 += x;
  128. this.y1 += y;
  129. this.markerBgLine.setAttribute('x1', this.x1.toString());
  130. this.markerBgLine.setAttribute('y1', this.y1.toString());
  131. this.markerLine.setAttribute('x1', this.x1.toString());
  132. this.markerLine.setAttribute('y1', this.y1.toString());
  133. if (onPosition) {
  134. onPosition('left');
  135. }
  136. }
  137. else if (this.activeGrip === this.controlGrips.right &&
  138. this.getLineLength(this.x1, this.y1, this.x2 + x, this.y2 + y) >= this.MIN_LENGTH) {
  139. this.x2 += x;
  140. this.y2 += y;
  141. this.markerBgLine.setAttribute('x2', this.x2.toString());
  142. this.markerBgLine.setAttribute('y2', this.y2.toString());
  143. this.markerLine.setAttribute('x2', this.x2.toString());
  144. this.markerLine.setAttribute('y2', this.y2.toString());
  145. if (onPosition) {
  146. onPosition('right');
  147. }
  148. }
  149. }
  150. this.adjustControlBox();
  151. };
  152. LinearMarker.prototype.resizeByEvent = function (x, y, pos) {
  153. if (pos === 'left') {
  154. this.activeGrip = this.controlGrips.left;
  155. }
  156. else {
  157. this.activeGrip = this.controlGrips.right;
  158. }
  159. this.resize(x, y);
  160. };
  161. LinearMarker.createMarker = function (page) {
  162. var marker = new LinearMarker();
  163. marker.page = page;
  164. marker.setup();
  165. return marker;
  166. };
  167. return LinearMarker;
  168. }(BaseMarker_1.BaseMarker));
  169. exports.LinearMarker = LinearMarker;