No Description

index.js 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. if (_this.page && _this.page.mode === 'mirror') {
  59. grip.visual.style.visibility = 'hidden';
  60. }
  61. return grip;
  62. };
  63. _this.gripMouseDown = function (ev) {
  64. _this.isResizing = true;
  65. _this.activeGrip =
  66. ev.target === _this.controlGrips.left.visual
  67. ? _this.controlGrips.left
  68. : _this.controlGrips.right;
  69. _this.previousMouseX = ev.screenX;
  70. _this.previousMouseY = ev.screenY;
  71. ev.stopPropagation();
  72. };
  73. _this.gripMouseUp = function (ev) {
  74. _this.isResizing = false;
  75. _this.activeGrip = null;
  76. ev.stopPropagation();
  77. };
  78. _this.gripMouseMove = function (ev) {
  79. if (_this.isResizing) {
  80. _this.resize(ev.movementX, ev.movementY);
  81. }
  82. };
  83. _this.positionLine = function (bound) {
  84. _this.x1 = bound.x1;
  85. _this.y1 = bound.y1;
  86. _this.x2 = bound.x2;
  87. _this.y2 = bound.y2;
  88. _this.markerBgLine.setAttribute('x1', _this.x1.toString());
  89. _this.markerBgLine.setAttribute('y1', _this.y1.toString());
  90. _this.markerLine.setAttribute('x2', _this.x2.toString());
  91. _this.markerLine.setAttribute('y2', _this.y2.toString());
  92. };
  93. _this.positionGrips = function () {
  94. var gripSize = _this.controlGrips.left.GRIP_SIZE;
  95. var x1 = _this.x1 - gripSize / 2;
  96. var y1 = _this.y1 - gripSize / 2;
  97. var x2 = _this.x2 - gripSize / 2;
  98. var y2 = _this.y2 - gripSize / 2;
  99. _this.positionGrip(_this.controlGrips.left.visual, x1, y1);
  100. _this.positionGrip(_this.controlGrips.right.visual, x2, y2);
  101. };
  102. _this.positionGrip = function (grip, x, y) {
  103. var translate = grip.transform.baseVal.getItem(0);
  104. translate.setTranslate(x, y);
  105. grip.transform.baseVal.replaceItem(translate, 0);
  106. };
  107. return _this;
  108. }
  109. LinearMarker.prototype.captureSnap = function () {
  110. var baseSnap = _super.prototype.captureSnap.call(this);
  111. baseSnap.linearSnap = {
  112. x1: this.x1,
  113. y1: this.y1,
  114. x2: this.x2,
  115. y2: this.y2
  116. };
  117. return baseSnap;
  118. };
  119. LinearMarker.prototype.applySnap = function (snap) {
  120. _super.prototype.applySnap.call(this, snap);
  121. if (snap.linearSnap) {
  122. this.positionLine(snap.linearSnap);
  123. }
  124. };
  125. LinearMarker.prototype.endManipulation = function () {
  126. _super.prototype.endManipulation.call(this);
  127. this.isResizing = false;
  128. this.activeGrip = null;
  129. };
  130. LinearMarker.prototype.select = function () {
  131. _super.prototype.select.call(this);
  132. this.controlBox.style.display = '';
  133. };
  134. LinearMarker.prototype.deselect = function () {
  135. _super.prototype.deselect.call(this);
  136. this.controlBox.style.display = 'none';
  137. };
  138. LinearMarker.prototype.init = function () {
  139. _super.prototype.init.call(this);
  140. this.markerBgLine = SvgHelper_1.SvgHelper.createLine(0, 0, this.x2, 0, [
  141. ['stroke', 'transparent'],
  142. ['stroke-width', '30']
  143. ]);
  144. this.addToRenderVisual(this.markerBgLine);
  145. this.markerLine = SvgHelper_1.SvgHelper.createLine(0, 0, this.x2, 0);
  146. this.addToRenderVisual(this.markerLine);
  147. this.addControlBox();
  148. if (this.page && this.page.mode === 'mirror') {
  149. this.controlBox.style.display = 'none';
  150. }
  151. };
  152. LinearMarker.prototype.resize = function (x, y, onPosition) {
  153. if (this.activeGrip) {
  154. if (this.activeGrip === this.controlGrips.left &&
  155. this.getLineLength(this.x1 + x, this.y1 + 1, this.x2, this.y2) >= this.MIN_LENGTH) {
  156. this.x1 += x;
  157. this.y1 += y;
  158. this.markerBgLine.setAttribute('x1', this.x1.toString());
  159. this.markerBgLine.setAttribute('y1', this.y1.toString());
  160. this.markerLine.setAttribute('x1', this.x1.toString());
  161. this.markerLine.setAttribute('y1', this.y1.toString());
  162. if (onPosition) {
  163. onPosition('left');
  164. }
  165. }
  166. else if (this.activeGrip === this.controlGrips.right &&
  167. this.getLineLength(this.x1, this.y1, this.x2 + x, this.y2 + y) >= this.MIN_LENGTH) {
  168. this.x2 += x;
  169. this.y2 += y;
  170. this.markerBgLine.setAttribute('x2', this.x2.toString());
  171. this.markerBgLine.setAttribute('y2', this.y2.toString());
  172. this.markerLine.setAttribute('x2', this.x2.toString());
  173. this.markerLine.setAttribute('y2', this.y2.toString());
  174. if (onPosition) {
  175. onPosition('right');
  176. }
  177. }
  178. }
  179. this.adjustControlBox();
  180. };
  181. LinearMarker.prototype.resizeByEvent = function (x, y, pos) {
  182. if (pos === 'left') {
  183. this.activeGrip = this.controlGrips.left;
  184. }
  185. else {
  186. this.activeGrip = this.controlGrips.right;
  187. }
  188. this.resize(x, y);
  189. };
  190. LinearMarker.createMarker = function (page) {
  191. var marker = new LinearMarker();
  192. marker.page = page;
  193. marker.init();
  194. return marker;
  195. };
  196. return LinearMarker;
  197. }(BaseMarker_1.BaseMarker));
  198. exports.LinearMarker = LinearMarker;