1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "./connector-util", "./tools", "@syncfusion/ej2-base"], function (require, exports, ej2_drawings_1, ej2_drawings_2, ej2_drawings_3, ej2_drawings_4, connector_util_1, tools_1, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function findActiveElement(event, pdfBase, pdfViewer, isOverlapped) {
if (pdfViewer && pdfBase.activeElements.activePageID > -1) {
var objects = findObjectsUnderMouse(pdfBase, pdfViewer, event);
var object = findObjectUnderMouse(objects, event, pdfBase, pdfViewer);
if (isOverlapped) {
return objects;
}
return object;
}
return undefined;
}
exports.findActiveElement = findActiveElement;
function findObjectsUnderMouse(pdfBase, pdfViewer, event) {
var pt = pdfBase.currentPosition || { x: event.offsetX, y: event.offsetY };
pt = { x: pt.x / pdfBase.getZoomFactor(), y: pt.y / pdfBase.getZoomFactor() };
var pageTable = pdfViewer.getPageTable(pdfBase.activeElements.activePageID);
var objArray = findObjects(pt, pageTable.objects, pdfViewer.touchPadding);
return objArray;
}
exports.findObjectsUnderMouse = findObjectsUnderMouse;
function findObjectUnderMouse(objects, event, pdfBase, pdfViewer) {
var actualTarget = null;
var touchArg;
var offsetX;
var offsetY;
if (event && event.type && event.type.indexOf('touch') !== -1) {
touchArg = event;
if (pdfViewer.annotation) {
var pageDiv = pdfBase.getElement('_pageDiv_' + pdfViewer.annotation.getEventPageNumber(event));
if (pageDiv) {
var pageCurrentRect = pageDiv.getBoundingClientRect();
offsetX = touchArg.changedTouches[0].clientX - pageCurrentRect.left;
offsetY = touchArg.changedTouches[0].clientY - pageCurrentRect.top;
}
}
}
else if (event && event.target && event.path && event.target.parentElement && event.target.parentElement.classList.contains('foreign-object')) {
var targetParentRect = event.path[4].getBoundingClientRect();
offsetX = event.clientX - targetParentRect.left;
offsetY = event.clientY - targetParentRect.top;
}
else if (event.target && event.target.parentElement && event.target.parentElement.classList.contains('foreign-object')) {
var targetParentRect = event.target.offsetParent.offsetParent.offsetParent.getBoundingClientRect();
offsetX = event.clientX - targetParentRect.left;
offsetY = event.clientY - targetParentRect.top;
}
else if (event.target && event.target.parentElement && event.target.parentElement.parentElement && event.target.parentElement.parentElement.classList.contains('foreign-object')) {
var targetParentRect = void 0;
if (event.target.offsetParent && event.target.offsetParent.offsetParent &&
event.target.offsetParent.offsetParent.offsetParent && event.target.offsetParent.offsetParent.offsetParent.offsetParent) {
targetParentRect = event.target.offsetParent.offsetParent.offsetParent.offsetParent.getBoundingClientRect();
offsetX = event.clientX - targetParentRect.left;
offsetY = event.clientY - targetParentRect.top;
}
else if (event.target.parentElement.offsetParent && event.target.parentElement.offsetParent.offsetParent) {
targetParentRect = event.target.parentElement.offsetParent.offsetParent.getBoundingClientRect();
offsetX = event.clientX - targetParentRect.left;
offsetY = event.clientY - targetParentRect.top;
}
}
else {
offsetX = !isNaN(event.offsetX) ? event.offsetX : (event.position ? event.position.x : 0);
offsetY = !isNaN(event.offsetY) ? event.offsetY : (event.position ? event.position.y : 0);
}
var offsetForSelector = pdfViewer.touchPadding / 2;
var boundsDiff = 0;
for (var i = 0; i < objects.length; i++) {
if (!(objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'Distance' || objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'Line' || objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'LineWidthArrowHead' || pdfBase.tool instanceof tools_1.LineTool)) {
var bounds = objects[parseInt(i.toString(), 10)].wrapper.bounds;
var rotationValue = 0;
if (objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'Stamp' || objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'Image') {
rotationValue = 25;
}
if ((((bounds.x - offsetForSelector) * pdfBase.getZoomFactor()) < offsetX) &&
(((bounds.x + bounds.width + offsetForSelector) * pdfBase.getZoomFactor()) > offsetX) &&
(((bounds.y - offsetForSelector - rotationValue) * pdfBase.getZoomFactor()) < offsetY) &&
(((bounds.y + bounds.height + offsetForSelector) * pdfBase.getZoomFactor()) > offsetY)) {
if (pdfBase.tool instanceof tools_1.NodeDrawingTool || pdfBase.tool instanceof tools_1.StampTool) {
actualTarget = objects[parseInt(i.toString(), 10)];
}
else {
if (!boundsDiff) {
actualTarget = objects[parseInt(i.toString(), 10)];
boundsDiff = (offsetX - ((bounds.x - offsetForSelector) * pdfBase.getZoomFactor())) +
(((bounds.x + bounds.width + offsetForSelector) * pdfBase.getZoomFactor()) - offsetX) +
(offsetY - ((bounds.y - offsetForSelector - rotationValue) * pdfBase.getZoomFactor())) +
(((bounds.y + bounds.height + offsetForSelector) * pdfBase.getZoomFactor()) - offsetY);
}
else {
var objectBounds = (offsetX - ((bounds.x - offsetForSelector) * pdfBase.getZoomFactor())) +
(((bounds.x + bounds.width + offsetForSelector) * pdfBase.getZoomFactor()) - offsetX) +
(offsetY - ((bounds.y - offsetForSelector - rotationValue) * pdfBase.getZoomFactor())) +
(((bounds.y + bounds.height + offsetForSelector) * pdfBase.getZoomFactor()) - offsetY);
if (boundsDiff > objectBounds) {
actualTarget = objects[parseInt(i.toString(), 10)];
boundsDiff = objectBounds;
}
else if (boundsDiff === objectBounds) {
actualTarget = objects[parseInt(i.toString(), 10)];
boundsDiff = objectBounds;
}
else if ((objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'Image') || (objects[parseInt(i.toString(), 10)].shapeAnnotationType === 'Stamp')) {
actualTarget = objects[parseInt(i.toString(), 10)];
}
}
}
}
}
else {
var pt = { x: offsetX / pdfBase.getZoomFactor(), y: offsetY / pdfBase.getZoomFactor() };
var obj = findElementUnderMouse(objects[parseInt(i.toString(), 10)], pt, offsetForSelector);
var isOver = connector_util_1.isPointOverConnector(objects[parseInt(i.toString(), 10)], pt);
if (obj && !isOver) {
var newpoint = CalculateLeaderPoints(objects[parseInt(i.toString(), 10)], obj);
if (newpoint) {
var rect = ej2_drawings_2.Rect.toBounds([newpoint, newpoint]);
rect.Inflate(10);
if (rect.containsPoint(pt)) {
isOver = true;
}
}
}
if (obj && isOver) {
actualTarget = objects[parseInt(i.toString(), 10)];
}
}
}
return actualTarget;
}
exports.findObjectUnderMouse = findObjectUnderMouse;
function CalculateLeaderPoints(selector, currentobject) {
var leaderCount = 0;
var sourcePoint = selector.sourcePoint;
var targetPoint = selector.targetPoint;
if (selector.shapeAnnotationType === 'Distance') {
var segment = currentobject;
var newPoint1 = void 0;
var angle = ej2_drawings_3.Point.findAngle(selector.sourcePoint, selector.targetPoint);
if (segment.id.indexOf('leader') > -1) {
var center = selector.wrapper.children[0].bounds.center;
if (leaderCount === 0 && segment.id.indexOf('leader1') > -1) {
newPoint1 = { x: selector.sourcePoint.x, y: selector.sourcePoint.y - selector.leaderHeight };
center = sourcePoint;
}
else {
newPoint1 = { x: selector.targetPoint.x, y: selector.targetPoint.y - selector.leaderHeight };
center = targetPoint;
}
var matrix = ej2_drawings_3.identityMatrix();
ej2_drawings_3.rotateMatrix(matrix, angle, center.x, center.y);
var rotatedPoint = ej2_drawings_4.transformPointByMatrix(matrix, { x: newPoint1.x, y: newPoint1.y });
return rotatedPoint;
}
}
}
exports.CalculateLeaderPoints = CalculateLeaderPoints;
function findElementUnderMouse(obj, position, padding) {
return findTargetShapeElement(obj.wrapper, position, padding);
}
exports.findElementUnderMouse = findElementUnderMouse;
function insertObject(obj, key, collection) {
if (collection.length === 0) {
collection.push(obj);
}
else if (collection.length === 1) {
if (collection[0]["" + key] > obj["" + key]) {
collection.splice(0, 0, obj);
}
else {
collection.push(obj);
}
}
else if (collection.length > 1) {
var low = 0;
var high = collection.length - 1;
var mid = Math.floor((low + high) / 2);
while (mid !== low) {
if (collection[parseInt(mid.toString(), 10)]["" + key] < obj["" + key]) {
low = mid;
mid = Math.floor((low + high) / 2);
}
else if (collection[parseInt(mid.toString(), 10)]["" + key] > obj["" + key]) {
high = mid;
mid = Math.floor((low + high) / 2);
}
}
if (collection[parseInt(high.toString(), 10)]["" + key] < obj["" + key]) {
collection.push(obj);
}
else if (collection[parseInt(low.toString(), 10)]["" + key] > obj["" + key]) {
collection.splice(low, 0, obj);
}
else if ((collection[parseInt(low.toString(), 10)]["" + key] < obj["" + key]) && collection[parseInt(high.toString(), 10)]["" + key] > obj["" + key]) {
collection.splice(high, 0, obj);
}
}
}
exports.insertObject = insertObject;
function findTargetShapeElement(container, position, padding) {
if (container && container.children) {
for (var i = container.children.length - 1; i >= 0; i--) {
var shapeElement = container.children[parseInt(i.toString(), 10)];
var touchPadding = padding;
if (!ej2_base_1.isNullOrUndefined(shapeElement.children) && shapeElement.children.length > 0) {
for (var j = shapeElement.children.length - 1; j >= 0; j--) {
var currentTarget = shapeElement.children[parseInt(j.toString(), 10)];
if (currentTarget && currentTarget.bounds.containsPoint(position, touchPadding)) {
if (currentTarget instanceof ej2_drawings_4.Container) {
var targetElement = this.findTargetElement(currentTarget, position);
if (targetElement) {
return targetElement;
}
}
if (currentTarget.bounds.containsPoint(position, touchPadding)) {
return currentTarget;
}
}
}
}
else {
if (shapeElement && shapeElement.bounds.containsPoint(position, touchPadding)) {
if (shapeElement instanceof ej2_drawings_4.Container) {
var targetElement = this.findTargetElement(shapeElement, position);
if (targetElement) {
return targetElement;
}
}
if (shapeElement.bounds.containsPoint(position, touchPadding)) {
return shapeElement;
}
}
}
}
}
if (container && container.bounds.containsPoint(position, padding) && container.style.fill !== 'none') {
var element = container;
var paddingValue = 10;
var rotateThumbDistance = 30;
var matrix = ej2_drawings_3.identityMatrix();
ej2_drawings_3.rotateMatrix(matrix, element.parentTransform, element.offsetX, element.offsetY);
var x = element.offsetX - element.pivot.x * element.actualSize.width;
var y = element.offsetY - element.pivot.y * element.actualSize.height;
var rotateThumb = {
x: x + ((element.pivot.x === 0.5 ? element.pivot.x * 2 : element.pivot.x) * element.actualSize.width / 2),
y: y - rotateThumbDistance
};
rotateThumb = ej2_drawings_4.transformPointByMatrix(matrix, rotateThumb);
if (ej2_drawings_1.contains(position, rotateThumb, paddingValue)) {
return container;
}
}
return null;
}
exports.findTargetShapeElement = findTargetShapeElement;
function findObjects(region, objCollection, touchPadding) {
var objects = [];
for (var _i = 0, objCollection_1 = objCollection; _i < objCollection_1.length; _i++) {
var obj = objCollection_1[_i];
if (findElementUnderMouse(obj, region, touchPadding) || ((obj.shapeAnnotationType === 'Stamp') && findElementUnderMouse(obj, region, 40))) {
insertObject(obj, 'zIndex', objects);
}
}
return objects;
}
exports.findObjects = findObjects;
function findActivePage(event) {
var activePageID = undefined;
if (event.target && event.target.wrapper) {
return event.target.pageIndex;
}
if (event.target) {
var elementIdColl = event.target.id.split('_');
if (elementIdColl.length > 0) {
activePageID = parseInt(elementIdColl[elementIdColl.length - 1], 10);
}
}
return activePageID;
}
exports.findActivePage = findActivePage;
var ActiveElements = (function () {
function ActiveElements() {
this.activePage = undefined;
this.activePageID = undefined;
}
Object.defineProperty(ActiveElements.prototype, "activePageID", {
get: function () {
return this.activePage;
},
set: function (offset) {
this.activePage = offset;
},
enumerable: true,
configurable: true
});
return ActiveElements;
}());
exports.ActiveElements = ActiveElements;
});
|