@inweb/viewer-three 26.1.2 → 26.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/viewer-three.module.js +15 -2349
- package/dist/viewer-three.module.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,2315 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { draggersRegistry, commandsRegistry, componentsRegistry, Options, CANVAS_EVENTS } from "@inweb/viewer-core";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
6
|
-
|
|
7
|
-
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
|
8
|
-
|
|
9
|
-
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
10
|
-
|
|
11
|
-
class CommandsRegistry {
|
|
12
|
-
constructor() {
|
|
13
|
-
this._commands = new Map;
|
|
14
|
-
}
|
|
15
|
-
registerCommand(id, handler, description, thisArg) {
|
|
16
|
-
this._commands.set(id, {
|
|
17
|
-
id: id,
|
|
18
|
-
handler: handler,
|
|
19
|
-
thisArg: thisArg,
|
|
20
|
-
description: description
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
registerCommandAlias(id, alias) {
|
|
24
|
-
this.registerCommand(alias, ((viewer, ...args) => this.executeCommand(id, viewer, ...args)));
|
|
25
|
-
}
|
|
26
|
-
getCommand(id) {
|
|
27
|
-
return this._commands.get(id);
|
|
28
|
-
}
|
|
29
|
-
getCommands() {
|
|
30
|
-
const map = new Map;
|
|
31
|
-
this._commands.forEach(((value, key) => map.set(key, value)));
|
|
32
|
-
return map;
|
|
33
|
-
}
|
|
34
|
-
executeCommand(id, viewer, ...args) {
|
|
35
|
-
const command = this._commands.get(id);
|
|
36
|
-
if (!command) {
|
|
37
|
-
if (viewer) {
|
|
38
|
-
const isDraggerCommand = viewer.draggers.includes(id);
|
|
39
|
-
if (isDraggerCommand) return viewer.setActiveDragger(id);
|
|
40
|
-
}
|
|
41
|
-
console.warn(`Command '${id}' not found`);
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
const {handler: handler, thisArg: thisArg} = command;
|
|
45
|
-
const result = handler.apply(thisArg, [ viewer, ...args ]);
|
|
46
|
-
viewer === null || viewer === undefined ? undefined : viewer.emit({
|
|
47
|
-
type: "command",
|
|
48
|
-
data: id,
|
|
49
|
-
args: args
|
|
50
|
-
});
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const _commandsRegistry = new Map;
|
|
56
|
-
|
|
57
|
-
function commandsRegistry(viewerType = "") {
|
|
58
|
-
let result = _commandsRegistry.get(viewerType);
|
|
59
|
-
if (!result) {
|
|
60
|
-
result = new CommandsRegistry;
|
|
61
|
-
_commandsRegistry.set(viewerType, result);
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class Dragger {
|
|
67
|
-
constructor(viewer) {
|
|
68
|
-
this.name = "";
|
|
69
|
-
}
|
|
70
|
-
dispose() {}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
class DraggersRegistry {
|
|
74
|
-
constructor() {
|
|
75
|
-
this._draggers = new Map;
|
|
76
|
-
}
|
|
77
|
-
registerDragger(name, provider) {
|
|
78
|
-
this._draggers.set(name, provider);
|
|
79
|
-
}
|
|
80
|
-
registerDraggerAlias(name, alias) {
|
|
81
|
-
const provider = this.getDragger(name);
|
|
82
|
-
if (provider) this.registerDragger(alias, (viewer => provider(viewer)));
|
|
83
|
-
}
|
|
84
|
-
getDragger(name) {
|
|
85
|
-
return this._draggers.get(name);
|
|
86
|
-
}
|
|
87
|
-
getDraggers() {
|
|
88
|
-
const map = new Map;
|
|
89
|
-
this._draggers.forEach(((value, key) => map.set(key, value)));
|
|
90
|
-
return map;
|
|
91
|
-
}
|
|
92
|
-
createDragger(name, viewer) {
|
|
93
|
-
const provider = this.getDragger(name);
|
|
94
|
-
if (!provider) return null;
|
|
95
|
-
const dragger = provider(viewer);
|
|
96
|
-
dragger.name = name;
|
|
97
|
-
return dragger;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const _draggersRegistry = new Map;
|
|
102
|
-
|
|
103
|
-
function draggersRegistry(viewerType = "") {
|
|
104
|
-
let result = _draggersRegistry.get(viewerType);
|
|
105
|
-
if (!result) {
|
|
106
|
-
result = new DraggersRegistry;
|
|
107
|
-
_draggersRegistry.set(viewerType, result);
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
class Component {
|
|
113
|
-
constructor(viewer) {
|
|
114
|
-
this.name = "";
|
|
115
|
-
}
|
|
116
|
-
dispose() {}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
class Components {
|
|
120
|
-
constructor() {
|
|
121
|
-
this._components = new Map;
|
|
122
|
-
}
|
|
123
|
-
registerComponent(name, provider) {
|
|
124
|
-
this._components.set(name, provider);
|
|
125
|
-
}
|
|
126
|
-
registerComponentAlias(name, alias) {
|
|
127
|
-
const provider = this.getComponent(name);
|
|
128
|
-
if (provider) this.registerComponent(alias, (viewer => provider(viewer)));
|
|
129
|
-
}
|
|
130
|
-
getComponent(name) {
|
|
131
|
-
return this._components.get(name);
|
|
132
|
-
}
|
|
133
|
-
getComponents() {
|
|
134
|
-
const map = new Map;
|
|
135
|
-
this._components.forEach(((value, key) => map.set(key, value)));
|
|
136
|
-
return map;
|
|
137
|
-
}
|
|
138
|
-
createComponent(name, viewer) {
|
|
139
|
-
const provider = this.getComponent(name);
|
|
140
|
-
if (!provider) return null;
|
|
141
|
-
const component = provider(viewer);
|
|
142
|
-
component.name = name;
|
|
143
|
-
return component;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const _components = new Map;
|
|
148
|
-
|
|
149
|
-
function componentsRegistry(viewerType = "") {
|
|
150
|
-
let result = _components.get(viewerType);
|
|
151
|
-
if (!result) {
|
|
152
|
-
result = new Components;
|
|
153
|
-
_components.set(viewerType, result);
|
|
154
|
-
}
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function defaultOptions() {
|
|
159
|
-
return {
|
|
160
|
-
showWCS: true,
|
|
161
|
-
cameraAnimation: true,
|
|
162
|
-
antialiasing: true,
|
|
163
|
-
groundShadow: false,
|
|
164
|
-
shadows: false,
|
|
165
|
-
cameraAxisXSpeed: 4,
|
|
166
|
-
cameraAxisYSpeed: 1,
|
|
167
|
-
ambientOcclusion: false,
|
|
168
|
-
enableStreamingMode: true,
|
|
169
|
-
enablePartialMode: false,
|
|
170
|
-
memoryLimit: 3294967296,
|
|
171
|
-
cuttingPlaneFillColor: {
|
|
172
|
-
red: 255,
|
|
173
|
-
green: 152,
|
|
174
|
-
blue: 0
|
|
175
|
-
},
|
|
176
|
-
edgesColor: {
|
|
177
|
-
r: 255,
|
|
178
|
-
g: 152,
|
|
179
|
-
b: 0
|
|
180
|
-
},
|
|
181
|
-
facesColor: {
|
|
182
|
-
r: 255,
|
|
183
|
-
g: 152,
|
|
184
|
-
b: 0
|
|
185
|
-
},
|
|
186
|
-
edgesVisibility: true,
|
|
187
|
-
edgesOverlap: true,
|
|
188
|
-
facesOverlap: false,
|
|
189
|
-
facesTransparancy: 200,
|
|
190
|
-
enableCustomHighlight: true,
|
|
191
|
-
sceneGraph: false,
|
|
192
|
-
edgeModel: true,
|
|
193
|
-
reverseZoomWheel: false,
|
|
194
|
-
enableZoomWheel: true,
|
|
195
|
-
enableGestures: true,
|
|
196
|
-
geometryType: "vsfx",
|
|
197
|
-
rulerUnit: "Default"
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
class Options {
|
|
202
|
-
constructor(emitter) {
|
|
203
|
-
this._emitter = emitter;
|
|
204
|
-
this._data = defaultOptions();
|
|
205
|
-
this.loadFromStorage();
|
|
206
|
-
}
|
|
207
|
-
static defaults() {
|
|
208
|
-
return defaultOptions();
|
|
209
|
-
}
|
|
210
|
-
notifierChangeEvent() {
|
|
211
|
-
console.warn("Options.notifierChangeEvent() has been deprecated since 25.3 and will be removed in a future release, use Options.change() instead.");
|
|
212
|
-
this.change();
|
|
213
|
-
}
|
|
214
|
-
change() {
|
|
215
|
-
if (this._emitter !== undefined) {
|
|
216
|
-
this.saveToStorage();
|
|
217
|
-
this._emitter.emit({
|
|
218
|
-
type: "optionschange",
|
|
219
|
-
data: this
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
saveToStorage() {
|
|
224
|
-
if (typeof window !== "undefined") try {
|
|
225
|
-
localStorage.setItem("od-client-settings", JSON.stringify(this.data));
|
|
226
|
-
} catch (error) {
|
|
227
|
-
console.error("Cannot save client settings.", error);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
loadFromStorage() {
|
|
231
|
-
if (typeof window !== "undefined") try {
|
|
232
|
-
const item = localStorage.getItem("od-client-settings");
|
|
233
|
-
if (item) {
|
|
234
|
-
const data = JSON.parse(item);
|
|
235
|
-
this.data = {
|
|
236
|
-
...data
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
} catch (error) {
|
|
240
|
-
console.error("Cannot load client settings.", error);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
resetToDefaults(fields) {
|
|
244
|
-
if (fields !== undefined) {
|
|
245
|
-
const defaults = Options.defaults();
|
|
246
|
-
const resetData = fields.reduce(((acc, field) => {
|
|
247
|
-
acc[field] = defaults[field];
|
|
248
|
-
return acc;
|
|
249
|
-
}), {});
|
|
250
|
-
this.data = {
|
|
251
|
-
...this.data,
|
|
252
|
-
...resetData
|
|
253
|
-
};
|
|
254
|
-
} else {
|
|
255
|
-
this.data = {
|
|
256
|
-
...this.data,
|
|
257
|
-
...Options.defaults()
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
get data() {
|
|
262
|
-
return this._data;
|
|
263
|
-
}
|
|
264
|
-
set data(value) {
|
|
265
|
-
const enablePartialMode = value.enableStreamingMode ? value.enablePartialMode : false;
|
|
266
|
-
const sceneGraph = enablePartialMode ? false : value.sceneGraph;
|
|
267
|
-
this._data = {
|
|
268
|
-
...Options.defaults(),
|
|
269
|
-
...this._data,
|
|
270
|
-
...value,
|
|
271
|
-
enablePartialMode: enablePartialMode,
|
|
272
|
-
sceneGraph: sceneGraph
|
|
273
|
-
};
|
|
274
|
-
this.change();
|
|
275
|
-
}
|
|
276
|
-
get showWCS() {
|
|
277
|
-
return this._data.showWCS;
|
|
278
|
-
}
|
|
279
|
-
set showWCS(value) {
|
|
280
|
-
this._data.showWCS = value;
|
|
281
|
-
this.change();
|
|
282
|
-
}
|
|
283
|
-
get cameraAnimation() {
|
|
284
|
-
return this._data.cameraAnimation;
|
|
285
|
-
}
|
|
286
|
-
set cameraAnimation(value) {
|
|
287
|
-
this._data.cameraAnimation = value;
|
|
288
|
-
this.change();
|
|
289
|
-
}
|
|
290
|
-
get antialiasing() {
|
|
291
|
-
return this._data.antialiasing;
|
|
292
|
-
}
|
|
293
|
-
set antialiasing(value) {
|
|
294
|
-
this._data.antialiasing = value;
|
|
295
|
-
this.change();
|
|
296
|
-
}
|
|
297
|
-
get groundShadow() {
|
|
298
|
-
return this._data.groundShadow;
|
|
299
|
-
}
|
|
300
|
-
set groundShadow(value) {
|
|
301
|
-
this._data.groundShadow = value;
|
|
302
|
-
this.change();
|
|
303
|
-
}
|
|
304
|
-
get shadows() {
|
|
305
|
-
return this._data.shadows;
|
|
306
|
-
}
|
|
307
|
-
set shadows(value) {
|
|
308
|
-
this._data.shadows = value;
|
|
309
|
-
this.change();
|
|
310
|
-
}
|
|
311
|
-
get cameraAxisXSpeed() {
|
|
312
|
-
return this._data.cameraAxisXSpeed;
|
|
313
|
-
}
|
|
314
|
-
set cameraAxisXSpeed(value) {
|
|
315
|
-
this._data.cameraAxisXSpeed = value;
|
|
316
|
-
this.change();
|
|
317
|
-
}
|
|
318
|
-
get cameraAxisYSpeed() {
|
|
319
|
-
return this._data.cameraAxisYSpeed;
|
|
320
|
-
}
|
|
321
|
-
set cameraAxisYSpeed(value) {
|
|
322
|
-
this.cameraAxisYSpeed = value;
|
|
323
|
-
this.change();
|
|
324
|
-
}
|
|
325
|
-
get ambientOcclusion() {
|
|
326
|
-
return this._data.ambientOcclusion;
|
|
327
|
-
}
|
|
328
|
-
set ambientOcclusion(value) {
|
|
329
|
-
this._data.ambientOcclusion = value;
|
|
330
|
-
this.change();
|
|
331
|
-
}
|
|
332
|
-
get enableStreamingMode() {
|
|
333
|
-
return this._data.enableStreamingMode;
|
|
334
|
-
}
|
|
335
|
-
set enableStreamingMode(value) {
|
|
336
|
-
this._data.enableStreamingMode = value;
|
|
337
|
-
if (!value) this._data.enablePartialMode = false;
|
|
338
|
-
this.change();
|
|
339
|
-
}
|
|
340
|
-
get enablePartialMode() {
|
|
341
|
-
return this._data.enablePartialMode;
|
|
342
|
-
}
|
|
343
|
-
set enablePartialMode(value) {
|
|
344
|
-
this._data.enablePartialMode = value;
|
|
345
|
-
if (value) {
|
|
346
|
-
this._data.enableStreamingMode = true;
|
|
347
|
-
this._data.sceneGraph = false;
|
|
348
|
-
}
|
|
349
|
-
this.change();
|
|
350
|
-
}
|
|
351
|
-
get memoryLimit() {
|
|
352
|
-
return this._data.memoryLimit;
|
|
353
|
-
}
|
|
354
|
-
set memoryLimit(value) {
|
|
355
|
-
this._data.memoryLimit = value;
|
|
356
|
-
this.change();
|
|
357
|
-
}
|
|
358
|
-
get cuttingPlaneFillColor() {
|
|
359
|
-
return this._data.cuttingPlaneFillColor;
|
|
360
|
-
}
|
|
361
|
-
set cuttingPlaneFillColor(value) {
|
|
362
|
-
this._data.cuttingPlaneFillColor = value;
|
|
363
|
-
this.change();
|
|
364
|
-
}
|
|
365
|
-
get edgesColor() {
|
|
366
|
-
return this._data.edgesColor;
|
|
367
|
-
}
|
|
368
|
-
set edgesColor(value) {
|
|
369
|
-
this._data.edgesColor = value;
|
|
370
|
-
this.change();
|
|
371
|
-
}
|
|
372
|
-
get facesColor() {
|
|
373
|
-
return this._data.facesColor;
|
|
374
|
-
}
|
|
375
|
-
set facesColor(value) {
|
|
376
|
-
this._data.facesColor = value;
|
|
377
|
-
this.change();
|
|
378
|
-
}
|
|
379
|
-
get edgesVisibility() {
|
|
380
|
-
return this._data.edgesVisibility;
|
|
381
|
-
}
|
|
382
|
-
set edgesVisibility(value) {
|
|
383
|
-
this._data.edgesVisibility = value;
|
|
384
|
-
this.change();
|
|
385
|
-
}
|
|
386
|
-
get edgesOverlap() {
|
|
387
|
-
return this._data.edgesOverlap;
|
|
388
|
-
}
|
|
389
|
-
set edgesOverlap(value) {
|
|
390
|
-
this._data.edgesOverlap = value;
|
|
391
|
-
this.change();
|
|
392
|
-
}
|
|
393
|
-
get facesOverlap() {
|
|
394
|
-
return this._data.facesOverlap;
|
|
395
|
-
}
|
|
396
|
-
set facesOverlap(value) {
|
|
397
|
-
this._data.facesOverlap = value;
|
|
398
|
-
this.change();
|
|
399
|
-
}
|
|
400
|
-
get facesTransparancy() {
|
|
401
|
-
return this._data.facesTransparancy;
|
|
402
|
-
}
|
|
403
|
-
set facesTransparancy(value) {
|
|
404
|
-
this._data.facesTransparancy = value;
|
|
405
|
-
this.change();
|
|
406
|
-
}
|
|
407
|
-
get enableCustomHighlight() {
|
|
408
|
-
return this._data.enableCustomHighlight;
|
|
409
|
-
}
|
|
410
|
-
set enableCustomHighlight(value) {
|
|
411
|
-
this._data.enableCustomHighlight = value;
|
|
412
|
-
this.change();
|
|
413
|
-
}
|
|
414
|
-
get sceneGraph() {
|
|
415
|
-
return this._data.sceneGraph;
|
|
416
|
-
}
|
|
417
|
-
set sceneGraph(value) {
|
|
418
|
-
this._data.sceneGraph = value;
|
|
419
|
-
if (value) this._data.enablePartialMode = false;
|
|
420
|
-
this.change();
|
|
421
|
-
}
|
|
422
|
-
get edgeModel() {
|
|
423
|
-
return Boolean(this._data.edgeModel);
|
|
424
|
-
}
|
|
425
|
-
set edgeModel(value) {
|
|
426
|
-
this._data.edgeModel = Boolean(value);
|
|
427
|
-
this.change();
|
|
428
|
-
}
|
|
429
|
-
get reverseZoomWheel() {
|
|
430
|
-
return this._data.reverseZoomWheel;
|
|
431
|
-
}
|
|
432
|
-
set reverseZoomWheel(value) {
|
|
433
|
-
this._data.reverseZoomWheel = !!value;
|
|
434
|
-
this.change();
|
|
435
|
-
}
|
|
436
|
-
get enableZoomWheel() {
|
|
437
|
-
return this._data.enableZoomWheel;
|
|
438
|
-
}
|
|
439
|
-
set enableZoomWheel(value) {
|
|
440
|
-
this._data.enableZoomWheel = !!value;
|
|
441
|
-
this.change();
|
|
442
|
-
}
|
|
443
|
-
get enableGestures() {
|
|
444
|
-
return this._data.enableGestures;
|
|
445
|
-
}
|
|
446
|
-
set enableGestures(value) {
|
|
447
|
-
this._data.enableGestures = !!value;
|
|
448
|
-
this.change();
|
|
449
|
-
}
|
|
450
|
-
get geometryType() {
|
|
451
|
-
return this._data.geometryType;
|
|
452
|
-
}
|
|
453
|
-
set geometryType(value) {
|
|
454
|
-
this._data.geometryType = value;
|
|
455
|
-
this.change();
|
|
456
|
-
}
|
|
457
|
-
get rulerUnit() {
|
|
458
|
-
return this._data.rulerUnit;
|
|
459
|
-
}
|
|
460
|
-
set rulerUnit(value) {
|
|
461
|
-
this._data.rulerUnit = value;
|
|
462
|
-
this.change();
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
const CanvasEvents = [ "click", "contextmenu", "dblclick", "mousedown", "mouseleave", "mousemove", "mouseup", "pointercancel", "pointerdown", "pointerleave", "pointermove", "pointerup", "touchcancel", "touchend", "touchmove", "touchstart", "wheel" ];
|
|
467
|
-
|
|
468
|
-
const CANVAS_EVENTS = CanvasEvents;
|
|
469
|
-
|
|
470
|
-
class WorldTransform {
|
|
471
|
-
screenToWorld(position) {
|
|
472
|
-
return {
|
|
473
|
-
x: position.x,
|
|
474
|
-
y: position.y,
|
|
475
|
-
z: 0
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
worldToScreen(position) {
|
|
479
|
-
return {
|
|
480
|
-
x: position.x,
|
|
481
|
-
y: position.y
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
getScale() {
|
|
485
|
-
return {
|
|
486
|
-
x: 1,
|
|
487
|
-
y: 1,
|
|
488
|
-
z: 1
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
class MarkupColor {
|
|
494
|
-
constructor(r, g, b) {
|
|
495
|
-
this.setColor(r, g, b);
|
|
496
|
-
}
|
|
497
|
-
asHex() {
|
|
498
|
-
return "#" + this.HEX;
|
|
499
|
-
}
|
|
500
|
-
asRGB() {
|
|
501
|
-
return {
|
|
502
|
-
r: this.R,
|
|
503
|
-
g: this.G,
|
|
504
|
-
b: this.B
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
setColor(r, g, b) {
|
|
508
|
-
this.R = r;
|
|
509
|
-
this.G = g;
|
|
510
|
-
this.B = b;
|
|
511
|
-
this.HEX = this.rgbToHex(r, g, b);
|
|
512
|
-
}
|
|
513
|
-
rgbToHex(r, g, b) {
|
|
514
|
-
const valueToHex = c => {
|
|
515
|
-
const hex = c.toString(16);
|
|
516
|
-
return hex === "0" ? "00" : hex;
|
|
517
|
-
};
|
|
518
|
-
return valueToHex(r) + valueToHex(g) + valueToHex(b);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
|
|
523
|
-
|
|
524
|
-
class KonvaLine {
|
|
525
|
-
constructor(params, ref = null) {
|
|
526
|
-
var _a, _b;
|
|
527
|
-
if (ref) {
|
|
528
|
-
this._ref = ref;
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
if (!params) params = {};
|
|
532
|
-
if (!params.points) params.points = [ {
|
|
533
|
-
x: 50,
|
|
534
|
-
y: 50
|
|
535
|
-
}, {
|
|
536
|
-
x: 100,
|
|
537
|
-
y: 100
|
|
538
|
-
} ];
|
|
539
|
-
const konvaPoints = [];
|
|
540
|
-
params.points.forEach((point => konvaPoints.push(point.x, point.y)));
|
|
541
|
-
this._ref = new Konva.Line({
|
|
542
|
-
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
543
|
-
strokeWidth: (_b = params.width) !== null && _b !== undefined ? _b : 4,
|
|
544
|
-
globalCompositeOperation: "source-over",
|
|
545
|
-
lineCap: "round",
|
|
546
|
-
lineJoin: "round",
|
|
547
|
-
points: konvaPoints,
|
|
548
|
-
draggable: true,
|
|
549
|
-
strokeScaleEnabled: false,
|
|
550
|
-
dash: LineTypeSpecs.get(params.type) || []
|
|
551
|
-
});
|
|
552
|
-
this._ref.on("transform", (e => {
|
|
553
|
-
const attrs = e.target.attrs;
|
|
554
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
555
|
-
}));
|
|
556
|
-
this._ref.id(this._ref._id.toString());
|
|
557
|
-
}
|
|
558
|
-
ref() {
|
|
559
|
-
return this._ref;
|
|
560
|
-
}
|
|
561
|
-
id() {
|
|
562
|
-
return this._ref.id();
|
|
563
|
-
}
|
|
564
|
-
enableMouseEditing(value) {
|
|
565
|
-
this._ref.draggable(value);
|
|
566
|
-
}
|
|
567
|
-
type() {
|
|
568
|
-
return "Line";
|
|
569
|
-
}
|
|
570
|
-
getColor() {
|
|
571
|
-
return this._ref.stroke();
|
|
572
|
-
}
|
|
573
|
-
setColor(hex) {
|
|
574
|
-
this._ref.stroke(hex);
|
|
575
|
-
}
|
|
576
|
-
getRotation() {
|
|
577
|
-
return this._ref.rotation();
|
|
578
|
-
}
|
|
579
|
-
setRotation(degrees) {
|
|
580
|
-
this._ref.rotation(degrees);
|
|
581
|
-
}
|
|
582
|
-
getZIndex() {
|
|
583
|
-
return this._ref.zIndex();
|
|
584
|
-
}
|
|
585
|
-
setZIndex(zIndex) {
|
|
586
|
-
this._ref.zIndex(zIndex);
|
|
587
|
-
}
|
|
588
|
-
delete() {
|
|
589
|
-
this._ref.destroy();
|
|
590
|
-
this._ref = null;
|
|
591
|
-
}
|
|
592
|
-
getPoints() {
|
|
593
|
-
return this._ref.points();
|
|
594
|
-
}
|
|
595
|
-
setLineWidth(size) {
|
|
596
|
-
this._ref.strokeWidth(size);
|
|
597
|
-
}
|
|
598
|
-
getLineWidth() {
|
|
599
|
-
return this._ref.strokeWidth();
|
|
600
|
-
}
|
|
601
|
-
getLineType() {
|
|
602
|
-
const typeSpecs = this._ref.dash() || [];
|
|
603
|
-
let type;
|
|
604
|
-
switch (typeSpecs) {
|
|
605
|
-
case LineTypeSpecs.get("dot"):
|
|
606
|
-
type = "dot";
|
|
607
|
-
break;
|
|
608
|
-
|
|
609
|
-
case LineTypeSpecs.get("dash"):
|
|
610
|
-
type = "dash";
|
|
611
|
-
break;
|
|
612
|
-
|
|
613
|
-
default:
|
|
614
|
-
type = "solid";
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
return type;
|
|
618
|
-
}
|
|
619
|
-
setLineType(type) {
|
|
620
|
-
const specs = LineTypeSpecs.get(type);
|
|
621
|
-
if (specs) this._ref.dash(specs);
|
|
622
|
-
}
|
|
623
|
-
addPoints(points) {
|
|
624
|
-
let newPoints = this._ref.points();
|
|
625
|
-
points.forEach((point => {
|
|
626
|
-
newPoints = newPoints.concat([ point.x, point.y ]);
|
|
627
|
-
}));
|
|
628
|
-
this._ref.points(newPoints);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
class KonvaText {
|
|
633
|
-
constructor(params, ref = null) {
|
|
634
|
-
var _a, _b, _c;
|
|
635
|
-
this.TEXT_FONT_FAMILY = "Calibri";
|
|
636
|
-
if (ref) {
|
|
637
|
-
this._ref = ref;
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
if (!params) params = {};
|
|
641
|
-
if (!params.position) params.position = {
|
|
642
|
-
x: 100,
|
|
643
|
-
y: 100
|
|
644
|
-
};
|
|
645
|
-
if (!params.text) params.text = "default";
|
|
646
|
-
this._ref = new Konva.Text({
|
|
647
|
-
x: params.position.x,
|
|
648
|
-
y: params.position.y,
|
|
649
|
-
text: params.text,
|
|
650
|
-
fontSize: (_a = params.fontSize) !== null && _a !== undefined ? _a : 34,
|
|
651
|
-
fontFamily: this.TEXT_FONT_FAMILY,
|
|
652
|
-
fill: (_b = params.color) !== null && _b !== undefined ? _b : "#ff0000",
|
|
653
|
-
align: "left",
|
|
654
|
-
draggable: true,
|
|
655
|
-
rotation: (_c = params.rotation) !== null && _c !== undefined ? _c : 0
|
|
656
|
-
});
|
|
657
|
-
this._ref.width(this._ref.getTextWidth());
|
|
658
|
-
this._ref.on("transform", (e => {
|
|
659
|
-
const attrs = e.target.attrs;
|
|
660
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
661
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
662
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
663
|
-
let newWidth = this._ref.width();
|
|
664
|
-
if (scaleByX) newWidth *= attrs.scaleX;
|
|
665
|
-
let newHeight = this._ref.height();
|
|
666
|
-
if (scaleByY) newHeight *= attrs.scaleY;
|
|
667
|
-
const minWidth = 50;
|
|
668
|
-
if (newWidth < minWidth) newWidth = minWidth;
|
|
669
|
-
if (newHeight < Math.round(this.getFontSize())) newHeight = Math.round(this.getFontSize());
|
|
670
|
-
if (scaleByX) {
|
|
671
|
-
this._ref.width(newWidth);
|
|
672
|
-
}
|
|
673
|
-
if (scaleByY) {
|
|
674
|
-
this._ref.height(newHeight);
|
|
675
|
-
}
|
|
676
|
-
this._ref.scale({
|
|
677
|
-
x: 1,
|
|
678
|
-
y: 1
|
|
679
|
-
});
|
|
680
|
-
}));
|
|
681
|
-
this._ref.id(this._ref._id.toString());
|
|
682
|
-
}
|
|
683
|
-
ref() {
|
|
684
|
-
return this._ref;
|
|
685
|
-
}
|
|
686
|
-
id() {
|
|
687
|
-
return this._ref.id();
|
|
688
|
-
}
|
|
689
|
-
enableMouseEditing(value) {
|
|
690
|
-
this._ref.draggable(value);
|
|
691
|
-
}
|
|
692
|
-
type() {
|
|
693
|
-
return "Text";
|
|
694
|
-
}
|
|
695
|
-
getColor() {
|
|
696
|
-
return this._ref.fill();
|
|
697
|
-
}
|
|
698
|
-
setColor(hex) {
|
|
699
|
-
this._ref.fill(hex);
|
|
700
|
-
}
|
|
701
|
-
getRotation() {
|
|
702
|
-
return this._ref.rotation();
|
|
703
|
-
}
|
|
704
|
-
setRotation(degrees) {
|
|
705
|
-
this._ref.rotation(degrees);
|
|
706
|
-
}
|
|
707
|
-
getZIndex() {
|
|
708
|
-
return this._ref.zIndex();
|
|
709
|
-
}
|
|
710
|
-
setZIndex(zIndex) {
|
|
711
|
-
this._ref.zIndex(zIndex);
|
|
712
|
-
}
|
|
713
|
-
delete() {
|
|
714
|
-
this._ref.destroy();
|
|
715
|
-
this._ref = null;
|
|
716
|
-
}
|
|
717
|
-
getText() {
|
|
718
|
-
return this._ref.text();
|
|
719
|
-
}
|
|
720
|
-
setText(text) {
|
|
721
|
-
this._ref.text(text);
|
|
722
|
-
}
|
|
723
|
-
getPosition() {
|
|
724
|
-
return this._ref.getPosition();
|
|
725
|
-
}
|
|
726
|
-
setPosition(x, y) {
|
|
727
|
-
this._ref.setPosition({
|
|
728
|
-
x: x,
|
|
729
|
-
y: y
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
getFontSize() {
|
|
733
|
-
return this._ref.fontSize();
|
|
734
|
-
}
|
|
735
|
-
setFontSize(size) {
|
|
736
|
-
this._ref.fontSize(size);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
class KonvaRectangle {
|
|
741
|
-
constructor(params, ref = null) {
|
|
742
|
-
var _a, _b, _c, _d;
|
|
743
|
-
if (ref) {
|
|
744
|
-
this._ref = ref;
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
if (!params) params = {};
|
|
748
|
-
if (!params.position) params.position = {
|
|
749
|
-
x: 100,
|
|
750
|
-
y: 100
|
|
751
|
-
};
|
|
752
|
-
this._ref = new Konva.Rect({
|
|
753
|
-
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
754
|
-
strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
|
|
755
|
-
globalCompositeOperation: "source-over",
|
|
756
|
-
lineCap: "round",
|
|
757
|
-
lineJoin: "round",
|
|
758
|
-
x: params.position.x,
|
|
759
|
-
y: params.position.y,
|
|
760
|
-
width: (_c = params.width) !== null && _c !== undefined ? _c : 200,
|
|
761
|
-
height: (_d = params.height) !== null && _d !== undefined ? _d : 200,
|
|
762
|
-
draggable: true,
|
|
763
|
-
strokeScaleEnabled: false
|
|
764
|
-
});
|
|
765
|
-
this._ref.on("transform", (e => {
|
|
766
|
-
const attrs = e.target.attrs;
|
|
767
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
768
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
769
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
770
|
-
let newWidth = this._ref.width();
|
|
771
|
-
if (scaleByX) newWidth *= attrs.scaleX;
|
|
772
|
-
let newHeight = this._ref.height();
|
|
773
|
-
if (scaleByY) newHeight *= attrs.scaleY;
|
|
774
|
-
const minWidth = 50;
|
|
775
|
-
const minHeight = 50;
|
|
776
|
-
if (newWidth < minWidth) newWidth = minWidth;
|
|
777
|
-
if (newHeight < minHeight) newHeight = minHeight;
|
|
778
|
-
if (scaleByX) {
|
|
779
|
-
this._ref.width(newWidth);
|
|
780
|
-
}
|
|
781
|
-
if (scaleByY) {
|
|
782
|
-
this._ref.height(newHeight);
|
|
783
|
-
}
|
|
784
|
-
this._ref.scale({
|
|
785
|
-
x: 1,
|
|
786
|
-
y: 1
|
|
787
|
-
});
|
|
788
|
-
}));
|
|
789
|
-
this._ref.id(this._ref._id.toString());
|
|
790
|
-
}
|
|
791
|
-
getPosition() {
|
|
792
|
-
return this._ref.position();
|
|
793
|
-
}
|
|
794
|
-
getWidth() {
|
|
795
|
-
return this._ref.width();
|
|
796
|
-
}
|
|
797
|
-
getHeigth() {
|
|
798
|
-
return this._ref.height();
|
|
799
|
-
}
|
|
800
|
-
setWidth(w) {
|
|
801
|
-
this._ref.width(w);
|
|
802
|
-
}
|
|
803
|
-
setHeight(h) {
|
|
804
|
-
this._ref.height(h);
|
|
805
|
-
}
|
|
806
|
-
setPosition(x, y) {
|
|
807
|
-
this._ref.setPosition({
|
|
808
|
-
x: x,
|
|
809
|
-
y: y
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
ref() {
|
|
813
|
-
return this._ref;
|
|
814
|
-
}
|
|
815
|
-
id() {
|
|
816
|
-
return this._ref.id();
|
|
817
|
-
}
|
|
818
|
-
enableMouseEditing(value) {
|
|
819
|
-
this._ref.draggable(value);
|
|
820
|
-
}
|
|
821
|
-
type() {
|
|
822
|
-
return "Rectangle";
|
|
823
|
-
}
|
|
824
|
-
getColor() {
|
|
825
|
-
return this._ref.stroke();
|
|
826
|
-
}
|
|
827
|
-
setColor(hex) {
|
|
828
|
-
this._ref.stroke(hex);
|
|
829
|
-
}
|
|
830
|
-
getRotation() {
|
|
831
|
-
return this._ref.rotation();
|
|
832
|
-
}
|
|
833
|
-
setRotation(degrees) {
|
|
834
|
-
this._ref.rotation(degrees);
|
|
835
|
-
}
|
|
836
|
-
getZIndex() {
|
|
837
|
-
return this._ref.zIndex();
|
|
838
|
-
}
|
|
839
|
-
setZIndex(zIndex) {
|
|
840
|
-
this._ref.zIndex(zIndex);
|
|
841
|
-
}
|
|
842
|
-
delete() {
|
|
843
|
-
this._ref.destroy();
|
|
844
|
-
this._ref = null;
|
|
845
|
-
}
|
|
846
|
-
setLineWidth(size) {
|
|
847
|
-
this._ref.strokeWidth(size);
|
|
848
|
-
}
|
|
849
|
-
getLineWidth() {
|
|
850
|
-
return this._ref.strokeWidth();
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
class KonvaEllipse {
|
|
855
|
-
constructor(params, ref = null) {
|
|
856
|
-
var _a, _b;
|
|
857
|
-
if (ref) {
|
|
858
|
-
this._ref = ref;
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
if (!params) params = {};
|
|
862
|
-
if (!params.position) params.position = {
|
|
863
|
-
x: 100,
|
|
864
|
-
y: 100
|
|
865
|
-
};
|
|
866
|
-
if (!params.radius) params.radius = {
|
|
867
|
-
x: 25,
|
|
868
|
-
y: 25
|
|
869
|
-
};
|
|
870
|
-
this._ref = new Konva.Ellipse({
|
|
871
|
-
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
872
|
-
strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
|
|
873
|
-
globalCompositeOperation: "source-over",
|
|
874
|
-
lineCap: "round",
|
|
875
|
-
lineJoin: "round",
|
|
876
|
-
x: params.position.x,
|
|
877
|
-
y: params.position.y,
|
|
878
|
-
radiusX: params.radius.x,
|
|
879
|
-
radiusY: params.radius.y,
|
|
880
|
-
draggable: true,
|
|
881
|
-
strokeScaleEnabled: false
|
|
882
|
-
});
|
|
883
|
-
this._ref.on("transform", (e => {
|
|
884
|
-
const attrs = e.target.attrs;
|
|
885
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
886
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
887
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
888
|
-
let newRadiusX = this._ref.radiusX();
|
|
889
|
-
if (scaleByX) newRadiusX *= attrs.scaleX;
|
|
890
|
-
let newRadiusY = this._ref.radiusY();
|
|
891
|
-
if (scaleByY) newRadiusY *= attrs.scaleY;
|
|
892
|
-
const minRadiusX = 25;
|
|
893
|
-
const minRadiusY = 25;
|
|
894
|
-
if (newRadiusX < minRadiusX) newRadiusX = minRadiusX;
|
|
895
|
-
if (newRadiusY < minRadiusY) newRadiusY = minRadiusY;
|
|
896
|
-
if (e.evt.ctrlKey || e.evt.shiftKey) {
|
|
897
|
-
if (scaleByX) {
|
|
898
|
-
this._ref.radius({
|
|
899
|
-
x: newRadiusX,
|
|
900
|
-
y: newRadiusX
|
|
901
|
-
});
|
|
902
|
-
} else {
|
|
903
|
-
this._ref.radius({
|
|
904
|
-
x: newRadiusY,
|
|
905
|
-
y: newRadiusY
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
} else {
|
|
909
|
-
this._ref.radius({
|
|
910
|
-
x: newRadiusX,
|
|
911
|
-
y: newRadiusY
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
this._ref.scale({
|
|
915
|
-
x: 1,
|
|
916
|
-
y: 1
|
|
917
|
-
});
|
|
918
|
-
}));
|
|
919
|
-
this._ref.id(this._ref._id.toString());
|
|
920
|
-
}
|
|
921
|
-
getPosition() {
|
|
922
|
-
return this._ref.position();
|
|
923
|
-
}
|
|
924
|
-
setPosition(x, y) {
|
|
925
|
-
this._ref.setPosition({
|
|
926
|
-
x: x,
|
|
927
|
-
y: y
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
getRadiusX() {
|
|
931
|
-
return this._ref.radiusX();
|
|
932
|
-
}
|
|
933
|
-
setRadiusX(r) {
|
|
934
|
-
this._ref.radiusX(r);
|
|
935
|
-
}
|
|
936
|
-
getRadiusY() {
|
|
937
|
-
return this._ref.radiusY();
|
|
938
|
-
}
|
|
939
|
-
setRadiusY(r) {
|
|
940
|
-
this._ref.radiusY(r);
|
|
941
|
-
}
|
|
942
|
-
getLineWidth() {
|
|
943
|
-
return this._ref.strokeWidth();
|
|
944
|
-
}
|
|
945
|
-
setLineWidth(size) {
|
|
946
|
-
this._ref.strokeWidth(size);
|
|
947
|
-
}
|
|
948
|
-
ref() {
|
|
949
|
-
return this._ref;
|
|
950
|
-
}
|
|
951
|
-
id() {
|
|
952
|
-
return this._ref.id();
|
|
953
|
-
}
|
|
954
|
-
enableMouseEditing(value) {
|
|
955
|
-
this._ref.draggable(value);
|
|
956
|
-
}
|
|
957
|
-
type() {
|
|
958
|
-
return "Ellipse";
|
|
959
|
-
}
|
|
960
|
-
getColor() {
|
|
961
|
-
return this._ref.stroke();
|
|
962
|
-
}
|
|
963
|
-
setColor(hex) {
|
|
964
|
-
this._ref.stroke(hex);
|
|
965
|
-
}
|
|
966
|
-
getRotation() {
|
|
967
|
-
return this._ref.rotation();
|
|
968
|
-
}
|
|
969
|
-
setRotation(degrees) {
|
|
970
|
-
this._ref.rotation(degrees);
|
|
971
|
-
}
|
|
972
|
-
getZIndex() {
|
|
973
|
-
return this._ref.zIndex();
|
|
974
|
-
}
|
|
975
|
-
setZIndex(zIndex) {
|
|
976
|
-
this._ref.zIndex(zIndex);
|
|
977
|
-
}
|
|
978
|
-
delete() {
|
|
979
|
-
this._ref.destroy();
|
|
980
|
-
this._ref = null;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
class KonvaArrow {
|
|
985
|
-
constructor(params, ref = null) {
|
|
986
|
-
var _a, _b;
|
|
987
|
-
if (ref) {
|
|
988
|
-
this._ref = ref;
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (!params) params = {};
|
|
992
|
-
if (!params.start) params.start = {
|
|
993
|
-
x: 50,
|
|
994
|
-
y: 50
|
|
995
|
-
};
|
|
996
|
-
if (!params.end) params.end = {
|
|
997
|
-
x: 100,
|
|
998
|
-
y: 100
|
|
999
|
-
};
|
|
1000
|
-
this._ref = new Konva.Arrow({
|
|
1001
|
-
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
1002
|
-
fill: (_b = params.color) !== null && _b !== undefined ? _b : "#ff0000",
|
|
1003
|
-
strokeWidth: 4,
|
|
1004
|
-
globalCompositeOperation: "source-over",
|
|
1005
|
-
lineCap: "round",
|
|
1006
|
-
lineJoin: "round",
|
|
1007
|
-
points: [ params.start.x, params.start.y, params.end.x, params.end.y ],
|
|
1008
|
-
draggable: true,
|
|
1009
|
-
strokeScaleEnabled: false
|
|
1010
|
-
});
|
|
1011
|
-
this._ref.on("transform", (e => {
|
|
1012
|
-
const attrs = e.target.attrs;
|
|
1013
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
1014
|
-
}));
|
|
1015
|
-
this._ref.id(this._ref._id.toString());
|
|
1016
|
-
}
|
|
1017
|
-
ref() {
|
|
1018
|
-
return this._ref;
|
|
1019
|
-
}
|
|
1020
|
-
id() {
|
|
1021
|
-
return this._ref.id();
|
|
1022
|
-
}
|
|
1023
|
-
enableMouseEditing(value) {
|
|
1024
|
-
this._ref.draggable(value);
|
|
1025
|
-
}
|
|
1026
|
-
type() {
|
|
1027
|
-
return "Arrow";
|
|
1028
|
-
}
|
|
1029
|
-
getColor() {
|
|
1030
|
-
return this._ref.stroke();
|
|
1031
|
-
}
|
|
1032
|
-
setColor(hex) {
|
|
1033
|
-
this._ref.stroke(hex);
|
|
1034
|
-
this._ref.fill(hex);
|
|
1035
|
-
}
|
|
1036
|
-
getRotation() {
|
|
1037
|
-
return this._ref.rotation();
|
|
1038
|
-
}
|
|
1039
|
-
setRotation(degrees) {
|
|
1040
|
-
this._ref.rotation(degrees);
|
|
1041
|
-
}
|
|
1042
|
-
getZIndex() {
|
|
1043
|
-
return this._ref.zIndex();
|
|
1044
|
-
}
|
|
1045
|
-
setZIndex(zIndex) {
|
|
1046
|
-
this._ref.zIndex(zIndex);
|
|
1047
|
-
}
|
|
1048
|
-
delete() {
|
|
1049
|
-
this._ref.destroy();
|
|
1050
|
-
this._ref = null;
|
|
1051
|
-
}
|
|
1052
|
-
getPoints() {
|
|
1053
|
-
const points = this._ref.points();
|
|
1054
|
-
return [ {
|
|
1055
|
-
x: points[0],
|
|
1056
|
-
y: points[1]
|
|
1057
|
-
}, {
|
|
1058
|
-
x: points[2],
|
|
1059
|
-
y: points[3]
|
|
1060
|
-
} ];
|
|
1061
|
-
}
|
|
1062
|
-
setPoints(points) {
|
|
1063
|
-
if (points.length === 2) {
|
|
1064
|
-
this._ref.points([ points[0].x, points[0].y, points[1].x, points[1].y ]);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
getStartPoint() {
|
|
1068
|
-
const points = this._ref.points();
|
|
1069
|
-
return {
|
|
1070
|
-
x: points[0],
|
|
1071
|
-
y: points[1]
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
setStartPoint(x, y) {
|
|
1075
|
-
const points = this._ref.points();
|
|
1076
|
-
this._ref.points([ x, y, points[2], points[3] ]);
|
|
1077
|
-
}
|
|
1078
|
-
getEndPoint() {
|
|
1079
|
-
const points = this._ref.points();
|
|
1080
|
-
return {
|
|
1081
|
-
x: points[2],
|
|
1082
|
-
y: points[3]
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
setEndPoint(x, y) {
|
|
1086
|
-
const points = this._ref.points();
|
|
1087
|
-
this._ref.points([ points[0], points[1], x, y ]);
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
class KonvaImage {
|
|
1092
|
-
constructor(params, ref = null) {
|
|
1093
|
-
var _a, _b;
|
|
1094
|
-
this._ratio = 1;
|
|
1095
|
-
this.EPSILON = 1e-5;
|
|
1096
|
-
this.BASE64_HEADER_START = "data:image/";
|
|
1097
|
-
this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
|
|
1098
|
-
if (ref) {
|
|
1099
|
-
if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
|
|
1100
|
-
if (ref.height() <= this.EPSILON) ref.height(32);
|
|
1101
|
-
if (ref.width() <= this.EPSILON) ref.width(32);
|
|
1102
|
-
this._ref = ref;
|
|
1103
|
-
this._canvasImage = ref.image();
|
|
1104
|
-
this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
if (!params) params = {};
|
|
1108
|
-
if (!params.position) params.position = {
|
|
1109
|
-
x: 50,
|
|
1110
|
-
y: 50
|
|
1111
|
-
};
|
|
1112
|
-
if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
|
|
1113
|
-
this._canvasImage = new Image;
|
|
1114
|
-
this._canvasImage.onload = () => {
|
|
1115
|
-
this._ref.image(this._canvasImage);
|
|
1116
|
-
if (this._ref.height() <= this.EPSILON) this._ref.height(this._canvasImage.height);
|
|
1117
|
-
if (this._ref.width() <= this.EPSILON) this._ref.width(this._canvasImage.width);
|
|
1118
|
-
this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
|
|
1119
|
-
if ((params.width <= this.EPSILON || params.height <= this.EPSILON) && (params.maxWidth >= this.EPSILON || params.maxWidth >= this.EPSILON)) {
|
|
1120
|
-
const heightOutOfCanvas = params.maxHeight - this._canvasImage.height;
|
|
1121
|
-
const widthOutOfCanvas = params.maxWidth - this._canvasImage.width;
|
|
1122
|
-
if (heightOutOfCanvas <= this.EPSILON || widthOutOfCanvas <= this.EPSILON) {
|
|
1123
|
-
if (widthOutOfCanvas <= this.EPSILON && widthOutOfCanvas < heightOutOfCanvas / this._ratio) {
|
|
1124
|
-
this._ref.height(params.maxWidth * this._ratio);
|
|
1125
|
-
this._ref.width(params.maxWidth);
|
|
1126
|
-
} else {
|
|
1127
|
-
this._ref.width(params.maxHeight / this._ratio);
|
|
1128
|
-
this._ref.height(params.maxHeight);
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
};
|
|
1133
|
-
this._canvasImage.onerror = () => {
|
|
1134
|
-
this._canvasImage.onerror = function() {};
|
|
1135
|
-
this._canvasImage.src = this.BASE64_NOT_FOUND;
|
|
1136
|
-
};
|
|
1137
|
-
this._canvasImage.src = params.src;
|
|
1138
|
-
this._ref = new Konva.Image({
|
|
1139
|
-
x: params.position.x,
|
|
1140
|
-
y: params.position.y,
|
|
1141
|
-
image: this._canvasImage,
|
|
1142
|
-
width: (_a = params.width) !== null && _a !== undefined ? _a : 0,
|
|
1143
|
-
height: (_b = params.height) !== null && _b !== undefined ? _b : 0,
|
|
1144
|
-
draggable: true
|
|
1145
|
-
});
|
|
1146
|
-
this._ref.on("transform", (e => {
|
|
1147
|
-
const attrs = e.target.attrs;
|
|
1148
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
1149
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
1150
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
1151
|
-
let newWidth = this._ref.width();
|
|
1152
|
-
if (scaleByX) newWidth *= attrs.scaleX;
|
|
1153
|
-
let newHeight = this._ref.height();
|
|
1154
|
-
if (scaleByY) newHeight *= attrs.scaleY;
|
|
1155
|
-
if (e.evt.ctrlKey || e.evt.shiftKey) {
|
|
1156
|
-
if (scaleByX) {
|
|
1157
|
-
this._ref.width(newWidth);
|
|
1158
|
-
this._ref.height(newWidth * this._ratio);
|
|
1159
|
-
} else {
|
|
1160
|
-
this._ref.width(newHeight / this._ratio);
|
|
1161
|
-
this._ref.height(newHeight);
|
|
1162
|
-
}
|
|
1163
|
-
} else {
|
|
1164
|
-
if (scaleByX) {
|
|
1165
|
-
this._ref.width(newWidth);
|
|
1166
|
-
}
|
|
1167
|
-
if (scaleByY) {
|
|
1168
|
-
this._ref.height(newHeight);
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
this._ref.scale({
|
|
1172
|
-
x: 1,
|
|
1173
|
-
y: 1
|
|
1174
|
-
});
|
|
1175
|
-
}));
|
|
1176
|
-
this._ref.id(this._ref._id.toString());
|
|
1177
|
-
}
|
|
1178
|
-
getSrc() {
|
|
1179
|
-
return this._canvasImage.src;
|
|
1180
|
-
}
|
|
1181
|
-
setSrc(src) {
|
|
1182
|
-
this._canvasImage.src = src;
|
|
1183
|
-
}
|
|
1184
|
-
getWidth() {
|
|
1185
|
-
return this._ref.width();
|
|
1186
|
-
}
|
|
1187
|
-
setWidth(w) {
|
|
1188
|
-
this._ref.width(w);
|
|
1189
|
-
this._ref.height(w * this._ratio);
|
|
1190
|
-
}
|
|
1191
|
-
getHeight() {
|
|
1192
|
-
return this._ref.height();
|
|
1193
|
-
}
|
|
1194
|
-
setHeight(h) {
|
|
1195
|
-
this._ref.height(h);
|
|
1196
|
-
this._ref.width(h / this._ratio);
|
|
1197
|
-
}
|
|
1198
|
-
ref() {
|
|
1199
|
-
return this._ref;
|
|
1200
|
-
}
|
|
1201
|
-
id() {
|
|
1202
|
-
return this._ref.id();
|
|
1203
|
-
}
|
|
1204
|
-
enableMouseEditing(value) {
|
|
1205
|
-
this._ref.draggable(value);
|
|
1206
|
-
}
|
|
1207
|
-
type() {
|
|
1208
|
-
return "Image";
|
|
1209
|
-
}
|
|
1210
|
-
getRotation() {
|
|
1211
|
-
return this._ref.rotation();
|
|
1212
|
-
}
|
|
1213
|
-
setRotation(degrees) {
|
|
1214
|
-
this._ref.rotation(degrees);
|
|
1215
|
-
}
|
|
1216
|
-
getZIndex() {
|
|
1217
|
-
return this._ref.zIndex();
|
|
1218
|
-
}
|
|
1219
|
-
setZIndex(zIndex) {
|
|
1220
|
-
this._ref.zIndex(zIndex);
|
|
1221
|
-
}
|
|
1222
|
-
delete() {
|
|
1223
|
-
this._ref.destroy();
|
|
1224
|
-
this._ref = null;
|
|
1225
|
-
}
|
|
1226
|
-
getPosition() {
|
|
1227
|
-
return this._ref.getPosition();
|
|
1228
|
-
}
|
|
1229
|
-
setPosition(x, y) {
|
|
1230
|
-
this._ref.setPosition({
|
|
1231
|
-
x: x,
|
|
1232
|
-
y: y
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
3
|
+
export * from "@inweb/viewer-core";
|
|
1236
4
|
|
|
1237
|
-
|
|
1238
|
-
constructor(params, ref = null) {
|
|
1239
|
-
var _a, _b, _c, _d;
|
|
1240
|
-
if (ref) {
|
|
1241
|
-
this._ref = ref;
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
if (!params) params = {};
|
|
1245
|
-
if (!params.position) params.position = {
|
|
1246
|
-
x: 100,
|
|
1247
|
-
y: 100
|
|
1248
|
-
};
|
|
1249
|
-
const arcRadius = 16;
|
|
1250
|
-
this._ref = new Konva.Shape({
|
|
1251
|
-
x: params.position.x,
|
|
1252
|
-
y: params.position.y,
|
|
1253
|
-
width: (_a = params.width) !== null && _a !== undefined ? _a : 200,
|
|
1254
|
-
height: (_b = params.height) !== null && _b !== undefined ? _b : 200,
|
|
1255
|
-
stroke: (_c = params.color) !== null && _c !== undefined ? _c : "#ff0000",
|
|
1256
|
-
strokeWidth: (_d = params.lineWidth) !== null && _d !== undefined ? _d : 4,
|
|
1257
|
-
draggable: true,
|
|
1258
|
-
strokeScaleEnabled: false,
|
|
1259
|
-
globalCompositeOperation: "source-over",
|
|
1260
|
-
sceneFunc: (context, shape) => {
|
|
1261
|
-
function calculateMidpoint(position, width, height) {
|
|
1262
|
-
const midX = position.x + width / 2;
|
|
1263
|
-
const midY = position.y + height / 2;
|
|
1264
|
-
return {
|
|
1265
|
-
x: midX,
|
|
1266
|
-
y: midY
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
const points = [ {
|
|
1270
|
-
x: 0,
|
|
1271
|
-
y: 0
|
|
1272
|
-
}, {
|
|
1273
|
-
x: 0 + this._ref.width(),
|
|
1274
|
-
y: 0
|
|
1275
|
-
}, {
|
|
1276
|
-
x: 0 + this._ref.width(),
|
|
1277
|
-
y: 0 + this._ref.height()
|
|
1278
|
-
}, {
|
|
1279
|
-
x: 0,
|
|
1280
|
-
y: 0 + this._ref.height()
|
|
1281
|
-
}, {
|
|
1282
|
-
x: 0,
|
|
1283
|
-
y: 0
|
|
1284
|
-
} ];
|
|
1285
|
-
const midPoint = calculateMidpoint({
|
|
1286
|
-
x: 0,
|
|
1287
|
-
y: 0
|
|
1288
|
-
}, this._ref.width(), this._ref.height());
|
|
1289
|
-
const baseArcLength = 30;
|
|
1290
|
-
context.beginPath();
|
|
1291
|
-
for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
|
|
1292
|
-
let approxArcLength = baseArcLength;
|
|
1293
|
-
const dx = points[iPoint + 1].x - points[iPoint].x;
|
|
1294
|
-
const dy = points[iPoint + 1].y - points[iPoint].y;
|
|
1295
|
-
const length = Math.sqrt(dx * dx + dy * dy);
|
|
1296
|
-
const arcCount = Math.floor(length / approxArcLength);
|
|
1297
|
-
const lengthMod = length % approxArcLength;
|
|
1298
|
-
approxArcLength = baseArcLength + arcCount / lengthMod;
|
|
1299
|
-
let pX = points[iPoint].x + dx / arcCount / 2;
|
|
1300
|
-
let pY = points[iPoint].y + dy / arcCount / 2;
|
|
1301
|
-
const pEndX = points[iPoint + 1].x;
|
|
1302
|
-
const pEndY = points[iPoint + 1].y;
|
|
1303
|
-
const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
|
|
1304
|
-
const startAngle = endAngle + Math.PI;
|
|
1305
|
-
const counterClockwise = pX > midPoint.x && pY > midPoint.y;
|
|
1306
|
-
for (let iArc = 0; iArc < arcCount; iArc++) {
|
|
1307
|
-
if (counterClockwise) {
|
|
1308
|
-
context.arc(pX, pY, arcRadius, endAngle, startAngle);
|
|
1309
|
-
} else {
|
|
1310
|
-
context.arc(pX, pY, arcRadius, startAngle, endAngle);
|
|
1311
|
-
}
|
|
1312
|
-
pX += dx / arcCount;
|
|
1313
|
-
pY += dy / arcCount;
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
context.closePath();
|
|
1317
|
-
context.fillStrokeShape(shape);
|
|
1318
|
-
}
|
|
1319
|
-
});
|
|
1320
|
-
this._ref.className = "Cloud";
|
|
1321
|
-
this._ref.on("transform", (e => {
|
|
1322
|
-
const attrs = e.target.attrs;
|
|
1323
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
1324
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
1325
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
1326
|
-
let newWidth = this._ref.width();
|
|
1327
|
-
if (scaleByX) newWidth *= attrs.scaleX;
|
|
1328
|
-
let newHeight = this._ref.height();
|
|
1329
|
-
if (scaleByY) newHeight *= attrs.scaleY;
|
|
1330
|
-
const minWidth = 100;
|
|
1331
|
-
const minHeight = 100;
|
|
1332
|
-
if (newWidth < minWidth) newWidth = minWidth;
|
|
1333
|
-
if (newHeight < minHeight) newHeight = minHeight;
|
|
1334
|
-
if (scaleByX) {
|
|
1335
|
-
this._ref.width(newWidth);
|
|
1336
|
-
}
|
|
1337
|
-
if (scaleByY) {
|
|
1338
|
-
this._ref.height(newHeight);
|
|
1339
|
-
}
|
|
1340
|
-
this._ref.scale({
|
|
1341
|
-
x: 1,
|
|
1342
|
-
y: 1
|
|
1343
|
-
});
|
|
1344
|
-
}));
|
|
1345
|
-
this._ref.getSelfRect = () => ({
|
|
1346
|
-
x: 0 - arcRadius,
|
|
1347
|
-
y: 0 - arcRadius,
|
|
1348
|
-
width: this._ref.width() + 2 * arcRadius,
|
|
1349
|
-
height: this._ref.height() + 2 * arcRadius
|
|
1350
|
-
});
|
|
1351
|
-
this._ref.id(this._ref._id.toString());
|
|
1352
|
-
}
|
|
1353
|
-
ref() {
|
|
1354
|
-
return this._ref;
|
|
1355
|
-
}
|
|
1356
|
-
id() {
|
|
1357
|
-
return this._ref.id();
|
|
1358
|
-
}
|
|
1359
|
-
enableMouseEditing(value) {
|
|
1360
|
-
this._ref.draggable(value);
|
|
1361
|
-
}
|
|
1362
|
-
type() {
|
|
1363
|
-
return "Cloud";
|
|
1364
|
-
}
|
|
1365
|
-
getColor() {
|
|
1366
|
-
return this._ref.stroke();
|
|
1367
|
-
}
|
|
1368
|
-
setColor(hex) {
|
|
1369
|
-
this._ref.stroke(hex);
|
|
1370
|
-
}
|
|
1371
|
-
getRotation() {
|
|
1372
|
-
return this._ref.rotation();
|
|
1373
|
-
}
|
|
1374
|
-
setRotation(degrees) {
|
|
1375
|
-
this._ref.rotation(degrees);
|
|
1376
|
-
}
|
|
1377
|
-
getZIndex() {
|
|
1378
|
-
return this._ref.zIndex();
|
|
1379
|
-
}
|
|
1380
|
-
setZIndex(zIndex) {
|
|
1381
|
-
this._ref.zIndex(zIndex);
|
|
1382
|
-
}
|
|
1383
|
-
delete() {
|
|
1384
|
-
this._ref.destroy();
|
|
1385
|
-
this._ref = null;
|
|
1386
|
-
}
|
|
1387
|
-
getPosition() {
|
|
1388
|
-
return this._ref.position();
|
|
1389
|
-
}
|
|
1390
|
-
setPosition(x, y) {
|
|
1391
|
-
this._ref.position({
|
|
1392
|
-
x: x,
|
|
1393
|
-
y: y
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
getWidth() {
|
|
1397
|
-
return this._ref.width();
|
|
1398
|
-
}
|
|
1399
|
-
setWidth(w) {
|
|
1400
|
-
this._ref.width(w);
|
|
1401
|
-
}
|
|
1402
|
-
getHeigth() {
|
|
1403
|
-
return this._ref.height();
|
|
1404
|
-
}
|
|
1405
|
-
setHeight(h) {
|
|
1406
|
-
this._ref.height(h);
|
|
1407
|
-
}
|
|
1408
|
-
getLineWidth() {
|
|
1409
|
-
return this._ref.strokeWidth();
|
|
1410
|
-
}
|
|
1411
|
-
setLineWidth(size) {
|
|
1412
|
-
this._ref.strokeWidth(size);
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
5
|
+
import { Markup } from "@inweb/markup";
|
|
1415
6
|
|
|
1416
|
-
|
|
1417
|
-
SelectMarkup: {
|
|
1418
|
-
name: "SelectMarkup",
|
|
1419
|
-
initializer: null
|
|
1420
|
-
},
|
|
1421
|
-
Line: {
|
|
1422
|
-
name: "Line",
|
|
1423
|
-
initializer: (ref, params = null) => new KonvaLine(params, ref)
|
|
1424
|
-
},
|
|
1425
|
-
Text: {
|
|
1426
|
-
name: "Text",
|
|
1427
|
-
initializer: (ref, params = null) => new KonvaText(params, ref)
|
|
1428
|
-
},
|
|
1429
|
-
Rectangle: {
|
|
1430
|
-
name: "Rect",
|
|
1431
|
-
initializer: (ref, params = null) => new KonvaRectangle(params, ref)
|
|
1432
|
-
},
|
|
1433
|
-
Ellipse: {
|
|
1434
|
-
name: "Ellipse",
|
|
1435
|
-
initializer: (ref, params = null) => new KonvaEllipse(params, ref)
|
|
1436
|
-
},
|
|
1437
|
-
Arrow: {
|
|
1438
|
-
name: "Arrow",
|
|
1439
|
-
initializer: (ref, params = null) => new KonvaArrow(params, ref)
|
|
1440
|
-
},
|
|
1441
|
-
Image: {
|
|
1442
|
-
name: "Image",
|
|
1443
|
-
initializer: (ref, params = null) => new KonvaImage(params, ref)
|
|
1444
|
-
},
|
|
1445
|
-
Cloud: {
|
|
1446
|
-
name: "Cloud",
|
|
1447
|
-
initializer: (ref, params = null) => new KonvaCloud(params, ref)
|
|
1448
|
-
}
|
|
1449
|
-
};
|
|
7
|
+
export * from "@inweb/markup";
|
|
1450
8
|
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
const draggerName = event.data;
|
|
1461
|
-
this._markupContainer.className = this._container.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
|
|
1462
|
-
this.removeTextInput();
|
|
1463
|
-
this.removeImageInput();
|
|
1464
|
-
this.enableEditMode(draggerName);
|
|
1465
|
-
};
|
|
1466
|
-
this.resizeContainer = entries => {
|
|
1467
|
-
const {width: width, height: height} = entries[0].contentRect;
|
|
1468
|
-
if (!width || !height) return;
|
|
1469
|
-
if (!this._konvaStage) return;
|
|
1470
|
-
this._konvaStage.width(width);
|
|
1471
|
-
this._konvaStage.height(height);
|
|
1472
|
-
};
|
|
1473
|
-
this.pan = event => {
|
|
1474
|
-
const newPos = {
|
|
1475
|
-
x: this._konvaStage.x() + event.dX,
|
|
1476
|
-
y: this._konvaStage.y() + event.dY
|
|
1477
|
-
};
|
|
1478
|
-
this._konvaStage.position(newPos);
|
|
1479
|
-
};
|
|
1480
|
-
this.zoomAt = event => {
|
|
1481
|
-
const newScale = this._konvaStage.scaleX() * event.data;
|
|
1482
|
-
this._konvaStage.scale({
|
|
1483
|
-
x: newScale,
|
|
1484
|
-
y: newScale
|
|
1485
|
-
});
|
|
1486
|
-
const newPos = {
|
|
1487
|
-
x: event.x - (event.x - this._konvaStage.x()) * event.data,
|
|
1488
|
-
y: event.y - (event.y - this._konvaStage.y()) * event.data
|
|
1489
|
-
};
|
|
1490
|
-
this._konvaStage.position(newPos);
|
|
1491
|
-
};
|
|
1492
|
-
this.redirectToViewer = event => {
|
|
1493
|
-
if (this._viewer) this._viewer.emit(event);
|
|
1494
|
-
};
|
|
1495
|
-
this.getRelativePointPosition = (point, node) => {
|
|
1496
|
-
const transform = node.getAbsoluteTransform().copy();
|
|
1497
|
-
transform.invert();
|
|
1498
|
-
return transform.point(point);
|
|
1499
|
-
};
|
|
1500
|
-
this.getRelativePointerPosition = node => this.getRelativePointPosition(node.getStage().getPointerPosition(), node);
|
|
1501
|
-
}
|
|
1502
|
-
initialize(container, containerEvents, viewer, worldTransformer) {
|
|
1503
|
-
if (!Konva) throw new Error('Markup error: Konva is not initialized. Forgot to add <script src="https://unpkg.com/konva@9/konva.min.js"><\/script> to your page?');
|
|
1504
|
-
this._viewer = viewer;
|
|
1505
|
-
this._worldTransformer = worldTransformer !== null && worldTransformer !== undefined ? worldTransformer : new WorldTransform;
|
|
1506
|
-
this._container = container;
|
|
1507
|
-
this._containerEvents = containerEvents !== null && containerEvents !== undefined ? containerEvents : [];
|
|
1508
|
-
this._markupContainer = document.createElement("div");
|
|
1509
|
-
this._markupContainer.id = "markup-container";
|
|
1510
|
-
this._markupContainer.style.position = "absolute";
|
|
1511
|
-
this._markupContainer.style.top = "0px";
|
|
1512
|
-
this._markupContainer.style.left = "0px";
|
|
1513
|
-
this._markupContainer.style.outline = "0px";
|
|
1514
|
-
this._markupContainer.style.pointerEvents = "none";
|
|
1515
|
-
const parentDiv = this._container.parentElement;
|
|
1516
|
-
parentDiv.appendChild(this._markupContainer);
|
|
1517
|
-
this._resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
1518
|
-
this._resizeObserver.observe(parentDiv);
|
|
1519
|
-
this._markupColor.setColor(255, 0, 0);
|
|
1520
|
-
this.initializeKonva();
|
|
1521
|
-
if (this._viewer) {
|
|
1522
|
-
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1523
|
-
this._viewer.addEventListener("pan", this.pan);
|
|
1524
|
-
this._viewer.addEventListener("zoomat", this.zoomAt);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
dispose() {
|
|
1528
|
-
var _a, _b;
|
|
1529
|
-
if (this._viewer) {
|
|
1530
|
-
this._viewer.removeEventListener("zoomat", this.zoomAt);
|
|
1531
|
-
this._viewer.removeEventListener("pan", this.pan);
|
|
1532
|
-
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1533
|
-
}
|
|
1534
|
-
this.destroyKonva();
|
|
1535
|
-
(_a = this._resizeObserver) === null || _a === undefined ? undefined : _a.disconnect();
|
|
1536
|
-
this._resizeObserver = undefined;
|
|
1537
|
-
(_b = this._markupContainer) === null || _b === undefined ? undefined : _b.remove();
|
|
1538
|
-
this._markupContainer = undefined;
|
|
1539
|
-
this._container = undefined;
|
|
1540
|
-
this._viewer = undefined;
|
|
1541
|
-
this._worldTransformer = undefined;
|
|
1542
|
-
this._markupIsActive = false;
|
|
1543
|
-
}
|
|
1544
|
-
syncOverlay() {}
|
|
1545
|
-
clearOverlay() {
|
|
1546
|
-
this.removeTextInput();
|
|
1547
|
-
this.removeImageInput();
|
|
1548
|
-
this.clearSelected();
|
|
1549
|
-
this.getObjects().forEach((obj => obj.delete()));
|
|
1550
|
-
}
|
|
1551
|
-
getMarkupColor() {
|
|
1552
|
-
return this._markupColor.asRGB();
|
|
1553
|
-
}
|
|
1554
|
-
setMarkupColor(r, g, b) {
|
|
1555
|
-
this._markupColor.setColor(r, g, b);
|
|
1556
|
-
this._viewer.emit({
|
|
1557
|
-
type: "changemarkupcolor",
|
|
1558
|
-
data: {
|
|
1559
|
-
r: r,
|
|
1560
|
-
g: g,
|
|
1561
|
-
b: b
|
|
1562
|
-
}
|
|
1563
|
-
});
|
|
1564
|
-
}
|
|
1565
|
-
colorizeAllMarkup(r, g, b) {
|
|
1566
|
-
const hexColor = new MarkupColor(r, g, b).asHex();
|
|
1567
|
-
this.getObjects().filter((obj => {
|
|
1568
|
-
var _a;
|
|
1569
|
-
return (_a = obj.setColor) === null || _a === undefined ? undefined : _a.call(obj, hexColor);
|
|
1570
|
-
}));
|
|
1571
|
-
}
|
|
1572
|
-
colorizeSelectedMarkups(r, g, b) {
|
|
1573
|
-
const hexColor = new MarkupColor(r, g, b).asHex();
|
|
1574
|
-
this.getSelectedObjects().filter((obj => {
|
|
1575
|
-
var _a;
|
|
1576
|
-
return (_a = obj.setColor) === null || _a === undefined ? undefined : _a.call(obj, hexColor);
|
|
1577
|
-
}));
|
|
1578
|
-
}
|
|
1579
|
-
setViewpoint(viewpoint) {
|
|
1580
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1581
|
-
this.clearSelected();
|
|
1582
|
-
this.removeTextInput();
|
|
1583
|
-
this.removeImageInput();
|
|
1584
|
-
this._konvaStage.scale({
|
|
1585
|
-
x: 1,
|
|
1586
|
-
y: 1
|
|
1587
|
-
});
|
|
1588
|
-
this._konvaStage.position({
|
|
1589
|
-
x: 0,
|
|
1590
|
-
y: 0
|
|
1591
|
-
});
|
|
1592
|
-
const markupColor = ((_a = viewpoint.custom_fields) === null || _a === undefined ? undefined : _a.markup_color) || {
|
|
1593
|
-
r: 255,
|
|
1594
|
-
g: 0,
|
|
1595
|
-
b: 0
|
|
1596
|
-
};
|
|
1597
|
-
this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
|
|
1598
|
-
(_b = viewpoint.lines) === null || _b === undefined ? undefined : _b.forEach((line => {
|
|
1599
|
-
const linePoints = [];
|
|
1600
|
-
line.points.forEach((point => {
|
|
1601
|
-
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
1602
|
-
linePoints.push(screenPoint.x);
|
|
1603
|
-
linePoints.push(screenPoint.y);
|
|
1604
|
-
}));
|
|
1605
|
-
this.addLine(linePoints, line.color, line.type, line.width, line.id);
|
|
1606
|
-
}));
|
|
1607
|
-
(_c = viewpoint.texts) === null || _c === undefined ? undefined : _c.forEach((text => {
|
|
1608
|
-
const screenPoint = this._worldTransformer.worldToScreen(text.position);
|
|
1609
|
-
this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
|
|
1610
|
-
}));
|
|
1611
|
-
(_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
|
|
1612
|
-
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
1613
|
-
this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
1614
|
-
}));
|
|
1615
|
-
(_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
|
|
1616
|
-
const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
|
|
1617
|
-
this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
|
|
1618
|
-
}));
|
|
1619
|
-
(_f = viewpoint.arrows) === null || _f === undefined ? undefined : _f.forEach((arrow => {
|
|
1620
|
-
const startPoint = this._worldTransformer.worldToScreen(arrow.start);
|
|
1621
|
-
const endPoint = this._worldTransformer.worldToScreen(arrow.end);
|
|
1622
|
-
this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
|
|
1623
|
-
}));
|
|
1624
|
-
(_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
|
|
1625
|
-
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
1626
|
-
this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
1627
|
-
}));
|
|
1628
|
-
(_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
|
|
1629
|
-
const screenPoint = this._worldTransformer.worldToScreen(image.position);
|
|
1630
|
-
this.addImage(screenPoint, image.src, image.width, image.height, image.id);
|
|
1631
|
-
}));
|
|
1632
|
-
}
|
|
1633
|
-
getViewpoint(viewpoint) {
|
|
1634
|
-
if (!viewpoint) viewpoint = {};
|
|
1635
|
-
viewpoint.lines = this.getMarkupLines();
|
|
1636
|
-
viewpoint.texts = this.getMarkupTexts();
|
|
1637
|
-
viewpoint.arrows = this.getMarkupArrows();
|
|
1638
|
-
viewpoint.clouds = this.getMarkupClouds();
|
|
1639
|
-
viewpoint.ellipses = this.getMarkupEllipses();
|
|
1640
|
-
viewpoint.images = this.getMarkupImages();
|
|
1641
|
-
viewpoint.rectangles = this.getMarkupRectangles();
|
|
1642
|
-
viewpoint.custom_fields = {
|
|
1643
|
-
markup_color: this.getMarkupColor()
|
|
1644
|
-
};
|
|
1645
|
-
viewpoint.snapshot = {
|
|
1646
|
-
data: this.combineMarkupWithDrawing()
|
|
1647
|
-
};
|
|
1648
|
-
return viewpoint;
|
|
1649
|
-
}
|
|
1650
|
-
enableEditMode(mode) {
|
|
1651
|
-
if (!mode || !MarkupMode2Konva[mode]) {
|
|
1652
|
-
this.clearSelected();
|
|
1653
|
-
this.removeTextInput();
|
|
1654
|
-
this.removeImageInput();
|
|
1655
|
-
this._markupContainer.style.pointerEvents = "none";
|
|
1656
|
-
this._markupIsActive = false;
|
|
1657
|
-
} else {
|
|
1658
|
-
this._markupMode = mode;
|
|
1659
|
-
this._markupContainer.style.pointerEvents = "all";
|
|
1660
|
-
this._markupIsActive = true;
|
|
1661
|
-
}
|
|
1662
|
-
return this;
|
|
1663
|
-
}
|
|
1664
|
-
createObject(type, params) {
|
|
1665
|
-
const konvaShape = MarkupMode2Konva[type];
|
|
1666
|
-
if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
|
|
1667
|
-
const object = konvaShape.initializer(null, params);
|
|
1668
|
-
this.addObject(object);
|
|
1669
|
-
return object;
|
|
1670
|
-
}
|
|
1671
|
-
getObjects() {
|
|
1672
|
-
const objects = [];
|
|
1673
|
-
Object.keys(MarkupMode2Konva).forEach((type => {
|
|
1674
|
-
const konvaShape = MarkupMode2Konva[type];
|
|
1675
|
-
this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
|
|
1676
|
-
}));
|
|
1677
|
-
return objects;
|
|
1678
|
-
}
|
|
1679
|
-
getSelectedObjects() {
|
|
1680
|
-
if (!this._konvaTransformer) return [];
|
|
1681
|
-
return this._konvaTransformer.nodes().map((ref => {
|
|
1682
|
-
const name = ref.className;
|
|
1683
|
-
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
1684
|
-
return konvaShape ? konvaShape.initializer(ref) : null;
|
|
1685
|
-
})).filter((x => x));
|
|
1686
|
-
}
|
|
1687
|
-
selectObjects(objects) {
|
|
1688
|
-
if (!this._konvaTransformer) return;
|
|
1689
|
-
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
1690
|
-
this._konvaTransformer.nodes(selectedObjs);
|
|
1691
|
-
}
|
|
1692
|
-
clearSelected() {
|
|
1693
|
-
if (this._konvaTransformer) this._konvaTransformer.nodes([]);
|
|
1694
|
-
}
|
|
1695
|
-
addObject(object) {
|
|
1696
|
-
if (object.type() === "Image") this._groupImages.add(object.ref()); else if (object.type() === "Text") this._groupTexts.add(object.ref()); else this._groupGeometry.add(object.ref());
|
|
1697
|
-
}
|
|
1698
|
-
konvaLayerFind(type) {
|
|
1699
|
-
if (!this._konvaLayer) return [];
|
|
1700
|
-
const konvaShape = MarkupMode2Konva[type];
|
|
1701
|
-
if (!konvaShape || !konvaShape.initializer) return [];
|
|
1702
|
-
return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer || ref.parent === this._groupImages || ref.parent === this._groupGeometry || ref.parent === this._groupTexts));
|
|
1703
|
-
}
|
|
1704
|
-
initializeKonva() {
|
|
1705
|
-
const stage = new Konva.Stage({
|
|
1706
|
-
container: this._markupContainer,
|
|
1707
|
-
width: this._container.clientWidth,
|
|
1708
|
-
height: this._container.clientHeight
|
|
1709
|
-
});
|
|
1710
|
-
this._konvaStage = stage;
|
|
1711
|
-
const layer = new Konva.Layer({
|
|
1712
|
-
pixelRation: window.devicePixelRatio
|
|
1713
|
-
});
|
|
1714
|
-
stage.add(layer);
|
|
1715
|
-
this._groupImages = new Konva.Group;
|
|
1716
|
-
layer.add(this._groupImages);
|
|
1717
|
-
this._groupGeometry = new Konva.Group;
|
|
1718
|
-
layer.add(this._groupGeometry);
|
|
1719
|
-
this._groupTexts = new Konva.Group;
|
|
1720
|
-
layer.add(this._groupTexts);
|
|
1721
|
-
this._konvaLayer = layer;
|
|
1722
|
-
const transformer = new Konva.Transformer({
|
|
1723
|
-
shouldOverdrawWholeArea: false,
|
|
1724
|
-
keepRatio: false,
|
|
1725
|
-
flipEnabled: false
|
|
1726
|
-
});
|
|
1727
|
-
layer.add(transformer);
|
|
1728
|
-
this._konvaTransformer = transformer;
|
|
1729
|
-
let isPaint = false;
|
|
1730
|
-
let lastLine;
|
|
1731
|
-
let mouseDownPos;
|
|
1732
|
-
let lastObj;
|
|
1733
|
-
stage.on("mousedown touchstart", (e => {
|
|
1734
|
-
if (!this._markupIsActive || e.target !== stage || this._markupMode === "Text" || this._markupMode === "Image") return;
|
|
1735
|
-
if (e.target === stage && transformer.nodes().length > 0) {
|
|
1736
|
-
transformer.nodes([]);
|
|
1737
|
-
return;
|
|
1738
|
-
}
|
|
1739
|
-
const pos = this.getRelativePointerPosition(stage);
|
|
1740
|
-
mouseDownPos = pos;
|
|
1741
|
-
isPaint = [ "Arrow", "Cloud", "Ellipse", "Line", "Rectangle" ].some((m => m === this._markupMode));
|
|
1742
|
-
if (this._markupMode === "Line") {
|
|
1743
|
-
lastLine = this.addLine([ pos.x, pos.y, pos.x, pos.y ]);
|
|
1744
|
-
}
|
|
1745
|
-
}));
|
|
1746
|
-
stage.on("mouseup touchend", (e => {
|
|
1747
|
-
if (!this._markupIsActive) return;
|
|
1748
|
-
if (isPaint) {
|
|
1749
|
-
const pos = this.getRelativePointerPosition(stage);
|
|
1750
|
-
const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
|
|
1751
|
-
const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
|
|
1752
|
-
const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
|
|
1753
|
-
const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
|
|
1754
|
-
const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
|
|
1755
|
-
if (defParams) {
|
|
1756
|
-
if (this._markupMode === "Rectangle") {
|
|
1757
|
-
this.addRectangle({
|
|
1758
|
-
x: startX,
|
|
1759
|
-
y: startY
|
|
1760
|
-
}, dX, dY);
|
|
1761
|
-
} else if (this._markupMode === "Ellipse") {
|
|
1762
|
-
this.addEllipse({
|
|
1763
|
-
x: startX,
|
|
1764
|
-
y: startY
|
|
1765
|
-
}, {
|
|
1766
|
-
x: dX / 2,
|
|
1767
|
-
y: dY / 2
|
|
1768
|
-
});
|
|
1769
|
-
} else if (this._markupMode === "Arrow") {
|
|
1770
|
-
this.addArrow({
|
|
1771
|
-
x: mouseDownPos.x,
|
|
1772
|
-
y: mouseDownPos.y
|
|
1773
|
-
}, {
|
|
1774
|
-
x: defParams ? mouseDownPos.x + 200 : pos.x,
|
|
1775
|
-
y: defParams ? startY : pos.y
|
|
1776
|
-
});
|
|
1777
|
-
} else if (this._markupMode === "Cloud") {
|
|
1778
|
-
this.addCloud({
|
|
1779
|
-
x: startX,
|
|
1780
|
-
y: startY
|
|
1781
|
-
}, Math.max(100, dX), Math.max(100, dY));
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
lastObj = undefined;
|
|
1786
|
-
isPaint = false;
|
|
1787
|
-
}));
|
|
1788
|
-
stage.on("mousemove touchmove", (e => {
|
|
1789
|
-
if (!this._markupIsActive) return;
|
|
1790
|
-
if (!isPaint) {
|
|
1791
|
-
return;
|
|
1792
|
-
}
|
|
1793
|
-
const pos = this.getRelativePointerPosition(stage);
|
|
1794
|
-
const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
|
|
1795
|
-
const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
|
|
1796
|
-
const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
|
|
1797
|
-
const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
|
|
1798
|
-
const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
|
|
1799
|
-
if (this._markupMode === "Line") {
|
|
1800
|
-
lastLine.addPoints([ {
|
|
1801
|
-
x: pos.x,
|
|
1802
|
-
y: pos.y
|
|
1803
|
-
} ]);
|
|
1804
|
-
} else if (this._markupMode === "Arrow") {
|
|
1805
|
-
if (lastObj) lastObj.setEndPoint(pos.x, pos.y); else lastObj = this.addArrow({
|
|
1806
|
-
x: mouseDownPos.x,
|
|
1807
|
-
y: mouseDownPos.y
|
|
1808
|
-
}, {
|
|
1809
|
-
x: pos.x,
|
|
1810
|
-
y: pos.y
|
|
1811
|
-
});
|
|
1812
|
-
} else if (this._markupMode === "Rectangle") {
|
|
1813
|
-
if (lastObj) {
|
|
1814
|
-
lastObj.setPosition(startX, startY);
|
|
1815
|
-
lastObj.setWidth(dX);
|
|
1816
|
-
lastObj.setHeight(dY);
|
|
1817
|
-
} else lastObj = this.addRectangle({
|
|
1818
|
-
x: startX,
|
|
1819
|
-
y: startY
|
|
1820
|
-
}, dX, dY);
|
|
1821
|
-
} else if (this._markupMode === "Ellipse") {
|
|
1822
|
-
if (lastObj) {
|
|
1823
|
-
lastObj.setPosition(startX, startY);
|
|
1824
|
-
lastObj.setRadiusX(dX);
|
|
1825
|
-
lastObj.setRadiusY(dY);
|
|
1826
|
-
} else lastObj = this.addEllipse({
|
|
1827
|
-
x: startX,
|
|
1828
|
-
y: startY
|
|
1829
|
-
}, {
|
|
1830
|
-
x: dX,
|
|
1831
|
-
y: dY
|
|
1832
|
-
});
|
|
1833
|
-
} else if (this._markupMode === "Cloud") {
|
|
1834
|
-
if (lastObj) {
|
|
1835
|
-
lastObj.setPosition(startX, startY);
|
|
1836
|
-
lastObj.setWidth(Math.max(100, dX));
|
|
1837
|
-
lastObj.setHeight(Math.max(100, dY));
|
|
1838
|
-
} else lastObj = this.addCloud({
|
|
1839
|
-
x: startX,
|
|
1840
|
-
y: startY
|
|
1841
|
-
}, dX, dY);
|
|
1842
|
-
}
|
|
1843
|
-
}));
|
|
1844
|
-
stage.on("click tap", (e => {
|
|
1845
|
-
if (!this._markupIsActive) return;
|
|
1846
|
-
if (e.target === stage) {
|
|
1847
|
-
if (this._markupMode === "Text") {
|
|
1848
|
-
if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
|
|
1849
|
-
const pos = this.getRelativePointerPosition(stage);
|
|
1850
|
-
this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
|
|
1851
|
-
}
|
|
1852
|
-
} else if (this._markupMode === "Image") {
|
|
1853
|
-
if (this._imageInputRef && this._imageInputRef.value) this.addImage({
|
|
1854
|
-
x: this._imageInputPos.x,
|
|
1855
|
-
y: this._imageInputPos.y
|
|
1856
|
-
}, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
|
|
1857
|
-
const pos = this.getRelativePointerPosition(stage);
|
|
1858
|
-
this.createImageInput(pos);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
transformer.nodes([]);
|
|
1862
|
-
return;
|
|
1863
|
-
}
|
|
1864
|
-
if (this._markupMode === "Text" || this._markupMode === "SelectMarkup") {
|
|
1865
|
-
if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
|
|
1866
|
-
if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else this.createTextInput({
|
|
1867
|
-
x: e.target.attrs.x,
|
|
1868
|
-
y: e.target.attrs.y
|
|
1869
|
-
}, e.evt.pageX, e.evt.pageY, e.target.attrs.rotation, e.target.attrs.text);
|
|
1870
|
-
return;
|
|
1871
|
-
} else {
|
|
1872
|
-
this.removeTextInput();
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
|
|
1876
|
-
if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
|
|
1877
|
-
if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
|
|
1878
|
-
x: e.target.attrs.x,
|
|
1879
|
-
y: e.target.attrs.y
|
|
1880
|
-
});
|
|
1881
|
-
return;
|
|
1882
|
-
} else {
|
|
1883
|
-
this.removeImageInput();
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
if (transformer.nodes().filter((x => x.className === "Cloud" || x.className === "Image")).length > 0 || e.target.className === "Cloud" || e.target.className === "Image") {
|
|
1887
|
-
transformer.rotateEnabled(false);
|
|
1888
|
-
} else {
|
|
1889
|
-
transformer.rotateEnabled(true);
|
|
1890
|
-
}
|
|
1891
|
-
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
1892
|
-
const isSelected = transformer.nodes().indexOf(e.target) >= 0;
|
|
1893
|
-
if (!metaPressed && !isSelected) {
|
|
1894
|
-
transformer.nodes([ e.target ]);
|
|
1895
|
-
} else if (metaPressed && isSelected) {
|
|
1896
|
-
const nodes = transformer.nodes().slice();
|
|
1897
|
-
nodes.splice(nodes.indexOf(e.target), 1);
|
|
1898
|
-
transformer.nodes(nodes);
|
|
1899
|
-
} else if (metaPressed && !isSelected) {
|
|
1900
|
-
const nodes = transformer.nodes().concat([ e.target ]);
|
|
1901
|
-
transformer.nodes(nodes);
|
|
1902
|
-
}
|
|
1903
|
-
}));
|
|
1904
|
-
const container = stage.container();
|
|
1905
|
-
container.tabIndex = 1;
|
|
1906
|
-
container.focus();
|
|
1907
|
-
container.addEventListener("keydown", (e => {
|
|
1908
|
-
if (!this._markupIsActive) return;
|
|
1909
|
-
if (e.code === "Delete") {
|
|
1910
|
-
this.getSelectedObjects().forEach((obj => obj.delete()));
|
|
1911
|
-
this.clearSelected();
|
|
1912
|
-
return;
|
|
1913
|
-
}
|
|
1914
|
-
e.preventDefault();
|
|
1915
|
-
}));
|
|
1916
|
-
}
|
|
1917
|
-
destroyKonva() {
|
|
1918
|
-
var _a;
|
|
1919
|
-
this.removeTextInput();
|
|
1920
|
-
this.removeImageInput();
|
|
1921
|
-
this.clearOverlay();
|
|
1922
|
-
(_a = this._konvaStage) === null || _a === undefined ? undefined : _a.destroy();
|
|
1923
|
-
this._groupImages = undefined;
|
|
1924
|
-
this._groupGeometry = undefined;
|
|
1925
|
-
this._groupTexts = undefined;
|
|
1926
|
-
this._konvaLayer = undefined;
|
|
1927
|
-
this._konvaTransformer = undefined;
|
|
1928
|
-
this._konvaStage = undefined;
|
|
1929
|
-
}
|
|
1930
|
-
getMarkupLines() {
|
|
1931
|
-
const lines = [];
|
|
1932
|
-
this.konvaLayerFind("Line").forEach((ref => {
|
|
1933
|
-
const linePoints = ref.points();
|
|
1934
|
-
if (!linePoints) return;
|
|
1935
|
-
const worldPoints = [];
|
|
1936
|
-
const absoluteTransform = ref.getAbsoluteTransform();
|
|
1937
|
-
for (let i = 0; i < linePoints.length; i += 2) {
|
|
1938
|
-
const atPoint = absoluteTransform.point({
|
|
1939
|
-
x: linePoints[i],
|
|
1940
|
-
y: linePoints[i + 1]
|
|
1941
|
-
});
|
|
1942
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1943
|
-
worldPoints.push(worldPoint);
|
|
1944
|
-
}
|
|
1945
|
-
const konvaLine = new KonvaLine(null, ref);
|
|
1946
|
-
const line = {
|
|
1947
|
-
id: konvaLine.id(),
|
|
1948
|
-
points: worldPoints,
|
|
1949
|
-
color: konvaLine.getColor() || "#ff0000",
|
|
1950
|
-
type: konvaLine.getLineType() || this.lineType,
|
|
1951
|
-
width: konvaLine.getLineWidth() || this.lineWidth
|
|
1952
|
-
};
|
|
1953
|
-
lines.push(line);
|
|
1954
|
-
}));
|
|
1955
|
-
return lines;
|
|
1956
|
-
}
|
|
1957
|
-
getMarkupTexts() {
|
|
1958
|
-
const texts = [];
|
|
1959
|
-
this.konvaLayerFind("Text").forEach((ref => {
|
|
1960
|
-
const textSize = .02;
|
|
1961
|
-
const textScale = this._worldTransformer.getScale();
|
|
1962
|
-
const position = ref.position();
|
|
1963
|
-
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
1964
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
1965
|
-
x: position.x,
|
|
1966
|
-
y: position.y
|
|
1967
|
-
});
|
|
1968
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1969
|
-
const shape = new KonvaText(null, ref);
|
|
1970
|
-
const text = {
|
|
1971
|
-
id: shape.id(),
|
|
1972
|
-
position: worldPoint,
|
|
1973
|
-
text: shape.getText(),
|
|
1974
|
-
text_size: textSize * textScale.y,
|
|
1975
|
-
angle: shape.getRotation(),
|
|
1976
|
-
color: shape.getColor(),
|
|
1977
|
-
font_size: shape.getFontSize() * stageAbsoluteTransform.getMatrix()[0]
|
|
1978
|
-
};
|
|
1979
|
-
texts.push(text);
|
|
1980
|
-
}));
|
|
1981
|
-
return texts;
|
|
1982
|
-
}
|
|
1983
|
-
getMarkupRectangles() {
|
|
1984
|
-
const rectangles = [];
|
|
1985
|
-
this.konvaLayerFind("Rectangle").forEach((ref => {
|
|
1986
|
-
const position = ref.position();
|
|
1987
|
-
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
1988
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
1989
|
-
x: position.x,
|
|
1990
|
-
y: position.y
|
|
1991
|
-
});
|
|
1992
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1993
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
1994
|
-
const shape = new KonvaRectangle(null, ref);
|
|
1995
|
-
const rectangle = {
|
|
1996
|
-
id: shape.id(),
|
|
1997
|
-
position: worldPoint,
|
|
1998
|
-
width: shape.getWidth() * scale,
|
|
1999
|
-
height: shape.getHeigth() * scale,
|
|
2000
|
-
line_width: shape.getLineWidth(),
|
|
2001
|
-
color: shape.getColor()
|
|
2002
|
-
};
|
|
2003
|
-
rectangles.push(rectangle);
|
|
2004
|
-
}));
|
|
2005
|
-
return rectangles;
|
|
2006
|
-
}
|
|
2007
|
-
getMarkupEllipses() {
|
|
2008
|
-
const ellipses = [];
|
|
2009
|
-
this.konvaLayerFind("Ellipse").forEach((ref => {
|
|
2010
|
-
const position = ref.position();
|
|
2011
|
-
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2012
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
2013
|
-
x: position.x,
|
|
2014
|
-
y: position.y
|
|
2015
|
-
});
|
|
2016
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2017
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2018
|
-
const shape = new KonvaEllipse(null, ref);
|
|
2019
|
-
const ellipse = {
|
|
2020
|
-
id: shape.id(),
|
|
2021
|
-
position: worldPoint,
|
|
2022
|
-
radius: {
|
|
2023
|
-
x: ref.getRadiusX() * scale,
|
|
2024
|
-
y: ref.getRadiusY() * scale
|
|
2025
|
-
},
|
|
2026
|
-
line_width: shape.getLineWidth(),
|
|
2027
|
-
color: shape.getColor()
|
|
2028
|
-
};
|
|
2029
|
-
ellipses.push(ellipse);
|
|
2030
|
-
}));
|
|
2031
|
-
return ellipses;
|
|
2032
|
-
}
|
|
2033
|
-
getMarkupArrows() {
|
|
2034
|
-
const arrows = [];
|
|
2035
|
-
this.konvaLayerFind("Arrow").forEach((ref => {
|
|
2036
|
-
const absoluteTransform = ref.getAbsoluteTransform();
|
|
2037
|
-
const atStartPoint = absoluteTransform.point({
|
|
2038
|
-
x: ref.points()[0],
|
|
2039
|
-
y: ref.points()[1]
|
|
2040
|
-
});
|
|
2041
|
-
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
2042
|
-
const atEndPoint = absoluteTransform.point({
|
|
2043
|
-
x: ref.points()[2],
|
|
2044
|
-
y: ref.points()[3]
|
|
2045
|
-
});
|
|
2046
|
-
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
2047
|
-
const shape = new KonvaArrow(null, ref);
|
|
2048
|
-
const arrow = {
|
|
2049
|
-
id: shape.id(),
|
|
2050
|
-
start: worldStartPoint,
|
|
2051
|
-
end: worldEndPoint,
|
|
2052
|
-
color: shape.getColor()
|
|
2053
|
-
};
|
|
2054
|
-
arrows.push(arrow);
|
|
2055
|
-
}));
|
|
2056
|
-
return arrows;
|
|
2057
|
-
}
|
|
2058
|
-
getMarkupImages() {
|
|
2059
|
-
const images = [];
|
|
2060
|
-
this.konvaLayerFind("Image").forEach((ref => {
|
|
2061
|
-
const position = ref.position();
|
|
2062
|
-
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2063
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
2064
|
-
x: position.x,
|
|
2065
|
-
y: position.y
|
|
2066
|
-
});
|
|
2067
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2068
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2069
|
-
const shape = new KonvaImage(null, ref);
|
|
2070
|
-
const image = {
|
|
2071
|
-
id: shape.id(),
|
|
2072
|
-
position: worldPoint,
|
|
2073
|
-
src: shape.getSrc(),
|
|
2074
|
-
width: shape.getWidth() * scale,
|
|
2075
|
-
height: shape.getHeight() * scale
|
|
2076
|
-
};
|
|
2077
|
-
images.push(image);
|
|
2078
|
-
}));
|
|
2079
|
-
return images;
|
|
2080
|
-
}
|
|
2081
|
-
getMarkupClouds() {
|
|
2082
|
-
const clouds = [];
|
|
2083
|
-
this.konvaLayerFind("Cloud").forEach((ref => {
|
|
2084
|
-
const position = ref.position();
|
|
2085
|
-
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2086
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
2087
|
-
x: position.x,
|
|
2088
|
-
y: position.y
|
|
2089
|
-
});
|
|
2090
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2091
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2092
|
-
const shape = new KonvaCloud(null, ref);
|
|
2093
|
-
const cloud = {
|
|
2094
|
-
id: shape.id(),
|
|
2095
|
-
position: worldPoint,
|
|
2096
|
-
width: shape.getWidth() * scale,
|
|
2097
|
-
height: shape.getHeigth() * scale,
|
|
2098
|
-
line_width: shape.getLineWidth(),
|
|
2099
|
-
color: shape.getColor()
|
|
2100
|
-
};
|
|
2101
|
-
clouds.push(cloud);
|
|
2102
|
-
}));
|
|
2103
|
-
return clouds;
|
|
2104
|
-
}
|
|
2105
|
-
combineMarkupWithDrawing() {
|
|
2106
|
-
this.clearSelected();
|
|
2107
|
-
const tempCanvas = document.createElement("canvas");
|
|
2108
|
-
if (this._konvaStage) {
|
|
2109
|
-
tempCanvas.width = this._konvaStage.width();
|
|
2110
|
-
tempCanvas.height = this._konvaStage.height();
|
|
2111
|
-
const ctx = tempCanvas.getContext("2d");
|
|
2112
|
-
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
2113
|
-
ctx.drawImage(this._konvaStage.toCanvas({
|
|
2114
|
-
pixelRatio: window.devicePixelRatio
|
|
2115
|
-
}), 0, 0);
|
|
2116
|
-
}
|
|
2117
|
-
return tempCanvas.toDataURL("image/jpeg", .25);
|
|
2118
|
-
}
|
|
2119
|
-
addLine(linePoints, color, type, width, id) {
|
|
2120
|
-
if (!linePoints || linePoints.length === 0) return;
|
|
2121
|
-
const points = [];
|
|
2122
|
-
for (let i = 0; i < linePoints.length; i += 2) {
|
|
2123
|
-
points.push({
|
|
2124
|
-
x: linePoints[i],
|
|
2125
|
-
y: linePoints[i + 1]
|
|
2126
|
-
});
|
|
2127
|
-
}
|
|
2128
|
-
const konvaLine = new KonvaLine({
|
|
2129
|
-
points: points,
|
|
2130
|
-
type: type || this.lineType,
|
|
2131
|
-
width: width || this.lineWidth,
|
|
2132
|
-
color: color || this._markupColor.asHex(),
|
|
2133
|
-
id: id
|
|
2134
|
-
});
|
|
2135
|
-
this.addObject(konvaLine);
|
|
2136
|
-
return konvaLine;
|
|
2137
|
-
}
|
|
2138
|
-
createTextInput(pos, inputX, inputY, angle, text) {
|
|
2139
|
-
if (!this._textInputRef) {
|
|
2140
|
-
this._textInputPos = pos;
|
|
2141
|
-
this._textInputAngle = angle;
|
|
2142
|
-
this._textInputRef = document.createElement("textarea");
|
|
2143
|
-
this._textInputRef.style.zIndex = "9999";
|
|
2144
|
-
this._textInputRef.style.position = "absolute";
|
|
2145
|
-
this._textInputRef.style.display = "block";
|
|
2146
|
-
this._textInputRef.style.top = inputY + "px";
|
|
2147
|
-
this._textInputRef.style.left = inputX + "px";
|
|
2148
|
-
this._textInputRef.style.fontSize = `${this.fontSize}px`;
|
|
2149
|
-
this._textInputRef.style.color = `${this._markupColor.asHex()}`;
|
|
2150
|
-
this._textInputRef.style.fontFamily = "Calibri";
|
|
2151
|
-
this._textInputRef.onkeydown = event => {
|
|
2152
|
-
if (event.key === "Enter" && !event.shiftKey) {
|
|
2153
|
-
event.preventDefault();
|
|
2154
|
-
this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
|
|
2155
|
-
}
|
|
2156
|
-
if (event.key === "Escape") {
|
|
2157
|
-
event.preventDefault();
|
|
2158
|
-
this.removeTextInput();
|
|
2159
|
-
}
|
|
2160
|
-
};
|
|
2161
|
-
if (text) this._textInputRef.value = text;
|
|
2162
|
-
document.body.appendChild(this._textInputRef);
|
|
2163
|
-
setTimeout((() => {
|
|
2164
|
-
this._textInputRef.focus();
|
|
2165
|
-
}), 50);
|
|
2166
|
-
} else {
|
|
2167
|
-
this.removeTextInput();
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
removeTextInput() {
|
|
2171
|
-
var _a;
|
|
2172
|
-
(_a = this._textInputRef) === null || _a === undefined ? undefined : _a.remove();
|
|
2173
|
-
this._textInputRef = null;
|
|
2174
|
-
this._textInputPos = null;
|
|
2175
|
-
this._textInputAngle = 0;
|
|
2176
|
-
}
|
|
2177
|
-
createImageInput(pos) {
|
|
2178
|
-
if (!this._imageInputRef) {
|
|
2179
|
-
const convertBase64 = file => new Promise(((resolve, reject) => {
|
|
2180
|
-
const fileReader = new FileReader;
|
|
2181
|
-
fileReader.readAsDataURL(file);
|
|
2182
|
-
fileReader.onload = () => {
|
|
2183
|
-
resolve(fileReader.result);
|
|
2184
|
-
};
|
|
2185
|
-
fileReader.onerror = error => {
|
|
2186
|
-
reject(error);
|
|
2187
|
-
};
|
|
2188
|
-
}));
|
|
2189
|
-
this._imageInputPos = pos;
|
|
2190
|
-
this._imageInputRef = document.createElement("input");
|
|
2191
|
-
this._imageInputRef.style.display = "none";
|
|
2192
|
-
this._imageInputRef.type = "file";
|
|
2193
|
-
this._imageInputRef.accept = "image/png, image/jpeg";
|
|
2194
|
-
this._imageInputRef.onchange = async event => {
|
|
2195
|
-
const file = event.target.files[0];
|
|
2196
|
-
const base64 = await convertBase64(file);
|
|
2197
|
-
this.addImage({
|
|
2198
|
-
x: this._imageInputPos.x,
|
|
2199
|
-
y: this._imageInputPos.y
|
|
2200
|
-
}, base64.toString(), 0, 0);
|
|
2201
|
-
};
|
|
2202
|
-
this._imageInputRef.oncancel = event => {
|
|
2203
|
-
this.removeImageInput();
|
|
2204
|
-
};
|
|
2205
|
-
document.body.appendChild(this._imageInputRef);
|
|
2206
|
-
setTimeout((() => {
|
|
2207
|
-
this._imageInputRef.click();
|
|
2208
|
-
}), 50);
|
|
2209
|
-
} else {
|
|
2210
|
-
this.removeImageInput();
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
removeImageInput() {
|
|
2214
|
-
var _a;
|
|
2215
|
-
(_a = this._imageInputRef) === null || _a === undefined ? undefined : _a.remove();
|
|
2216
|
-
this._imageInputRef = null;
|
|
2217
|
-
this._imageInputPos = null;
|
|
2218
|
-
}
|
|
2219
|
-
addText(text, position, angle, color, textSize, fontSize, id) {
|
|
2220
|
-
var _a;
|
|
2221
|
-
if (!text) return;
|
|
2222
|
-
(_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
|
|
2223
|
-
this.clearSelected();
|
|
2224
|
-
this.removeTextInput();
|
|
2225
|
-
const tolerance = 1e-6;
|
|
2226
|
-
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
2227
|
-
const size = .02;
|
|
2228
|
-
const scale = this._worldTransformer.getScale();
|
|
2229
|
-
fontSize = textSize / (scale.y / size) / 34;
|
|
2230
|
-
}
|
|
2231
|
-
const konvaText = new KonvaText({
|
|
2232
|
-
position: {
|
|
2233
|
-
x: position.x,
|
|
2234
|
-
y: position.y
|
|
2235
|
-
},
|
|
2236
|
-
text: text,
|
|
2237
|
-
rotation: angle,
|
|
2238
|
-
fontSize: fontSize || this.fontSize,
|
|
2239
|
-
color: color || this._markupColor.asHex(),
|
|
2240
|
-
id: id
|
|
2241
|
-
});
|
|
2242
|
-
this.addObject(konvaText);
|
|
2243
|
-
return konvaText;
|
|
2244
|
-
}
|
|
2245
|
-
addRectangle(position, width, height, lineWidth, color, id) {
|
|
2246
|
-
if (!position) return;
|
|
2247
|
-
const konvaRectangle = new KonvaRectangle({
|
|
2248
|
-
position: position,
|
|
2249
|
-
width: width,
|
|
2250
|
-
height: height,
|
|
2251
|
-
lineWidth: lineWidth || this.lineWidth,
|
|
2252
|
-
color: color || this._markupColor.asHex(),
|
|
2253
|
-
id: id
|
|
2254
|
-
});
|
|
2255
|
-
this.addObject(konvaRectangle);
|
|
2256
|
-
return konvaRectangle;
|
|
2257
|
-
}
|
|
2258
|
-
addEllipse(position, radius, lineWidth, color, id) {
|
|
2259
|
-
if (!position) return;
|
|
2260
|
-
const konvaEllipse = new KonvaEllipse({
|
|
2261
|
-
position: position,
|
|
2262
|
-
radius: radius,
|
|
2263
|
-
lineWidth: lineWidth,
|
|
2264
|
-
color: color || this._markupColor.asHex(),
|
|
2265
|
-
id: id
|
|
2266
|
-
});
|
|
2267
|
-
this.addObject(konvaEllipse);
|
|
2268
|
-
return konvaEllipse;
|
|
2269
|
-
}
|
|
2270
|
-
addArrow(start, end, color, id) {
|
|
2271
|
-
if (!start || !end) return;
|
|
2272
|
-
const konvaArrow = new KonvaArrow({
|
|
2273
|
-
start: start,
|
|
2274
|
-
end: end,
|
|
2275
|
-
color: color || this._markupColor.asHex(),
|
|
2276
|
-
id: id
|
|
2277
|
-
});
|
|
2278
|
-
this.addObject(konvaArrow);
|
|
2279
|
-
return konvaArrow;
|
|
2280
|
-
}
|
|
2281
|
-
addCloud(position, width, height, lineWidth, color, id) {
|
|
2282
|
-
if (!position || !width || !height) return;
|
|
2283
|
-
const konvaCloud = new KonvaCloud({
|
|
2284
|
-
position: position,
|
|
2285
|
-
width: width,
|
|
2286
|
-
height: height,
|
|
2287
|
-
color: color || this._markupColor.asHex(),
|
|
2288
|
-
lineWidth: lineWidth || this.lineWidth,
|
|
2289
|
-
id: id
|
|
2290
|
-
});
|
|
2291
|
-
this.addObject(konvaCloud);
|
|
2292
|
-
return konvaCloud;
|
|
2293
|
-
}
|
|
2294
|
-
addImage(position, src, width, height, id) {
|
|
2295
|
-
var _a;
|
|
2296
|
-
if (!position || !src) return;
|
|
2297
|
-
(_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
|
|
2298
|
-
this.clearSelected();
|
|
2299
|
-
this.removeImageInput();
|
|
2300
|
-
const konvaImage = new KonvaImage({
|
|
2301
|
-
position: position,
|
|
2302
|
-
src: src,
|
|
2303
|
-
width: width,
|
|
2304
|
-
height: height,
|
|
2305
|
-
maxWidth: this._konvaStage.width() - position.x,
|
|
2306
|
-
maxHeight: this._konvaStage.height() - position.y,
|
|
2307
|
-
id: id
|
|
2308
|
-
});
|
|
2309
|
-
this.addObject(konvaImage);
|
|
2310
|
-
return konvaImage;
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
9
|
+
import { Line, Vector3, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, MeshBasicMaterial, DoubleSide, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Vector2, Plane, Object3D, Matrix4, Vector4, Raycaster, Controls, Clock, Box3, Sphere, MathUtils, Color, PMREMGenerator, AmbientLight, DirectionalLight, OrthographicCamera, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, LoadingManager, LoaderUtils, Scene, PerspectiveCamera, WebGLRenderer, LinearToneMapping } from "three";
|
|
10
|
+
|
|
11
|
+
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
12
|
+
|
|
13
|
+
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
|
14
|
+
|
|
15
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
16
|
+
|
|
17
|
+
import { EventEmitter2 } from "@inweb/eventemitter2";
|
|
2313
18
|
|
|
2314
19
|
class PlaneHelper extends Line {
|
|
2315
20
|
constructor(plane, size = 1, color = 16776960, offset = new Vector3) {
|
|
@@ -4543,45 +2248,6 @@ class GLTFLoadingManager extends LoadingManager {
|
|
|
4543
2248
|
}
|
|
4544
2249
|
}
|
|
4545
2250
|
|
|
4546
|
-
class EventEmitter2 {
|
|
4547
|
-
constructor() {
|
|
4548
|
-
this._listeners = {};
|
|
4549
|
-
}
|
|
4550
|
-
addEventListener(type, listener) {
|
|
4551
|
-
if (this._listeners[type] === undefined) this._listeners[type] = [];
|
|
4552
|
-
this._listeners[type].push(listener);
|
|
4553
|
-
return this;
|
|
4554
|
-
}
|
|
4555
|
-
removeEventListener(type, listener) {
|
|
4556
|
-
if (this._listeners[type] === undefined) return this;
|
|
4557
|
-
const listeners = this._listeners[type].filter((x => x !== listener));
|
|
4558
|
-
if (listeners.length !== 0) this._listeners[type] = listeners; else delete this._listeners[type];
|
|
4559
|
-
return this;
|
|
4560
|
-
}
|
|
4561
|
-
removeAllListeners(type) {
|
|
4562
|
-
if (type) delete this._listeners[type]; else this._listeners = {};
|
|
4563
|
-
return this;
|
|
4564
|
-
}
|
|
4565
|
-
emitEvent(event) {
|
|
4566
|
-
if (this._listeners[event.type] === undefined) return false;
|
|
4567
|
-
const invoke = this._listeners[event.type].slice();
|
|
4568
|
-
invoke.forEach((listener => listener.call(this, event)));
|
|
4569
|
-
return true;
|
|
4570
|
-
}
|
|
4571
|
-
on(type, listener) {
|
|
4572
|
-
return this.addEventListener(type, listener);
|
|
4573
|
-
}
|
|
4574
|
-
off(type, listener) {
|
|
4575
|
-
return this.removeEventListener(type, listener);
|
|
4576
|
-
}
|
|
4577
|
-
emit(type, ...args) {
|
|
4578
|
-
if (typeof type === "string") return this.emitEvent({
|
|
4579
|
-
type: type,
|
|
4580
|
-
args: args
|
|
4581
|
-
}); else if (typeof type === "object") return this.emitEvent(type); else return false;
|
|
4582
|
-
}
|
|
4583
|
-
}
|
|
4584
|
-
|
|
4585
2251
|
class Viewer extends EventEmitter2 {
|
|
4586
2252
|
constructor(client) {
|
|
4587
2253
|
super();
|
|
@@ -4598,7 +2264,7 @@ class Viewer extends EventEmitter2 {
|
|
|
4598
2264
|
this.renderTime = 0;
|
|
4599
2265
|
this.render = this.render.bind(this);
|
|
4600
2266
|
this.update = this.update.bind(this);
|
|
4601
|
-
this._markup = new
|
|
2267
|
+
this._markup = new Markup;
|
|
4602
2268
|
}
|
|
4603
2269
|
get options() {
|
|
4604
2270
|
return this._options;
|
|
@@ -5083,5 +2749,5 @@ class Viewer extends EventEmitter2 {
|
|
|
5083
2749
|
}
|
|
5084
2750
|
}
|
|
5085
2751
|
|
|
5086
|
-
export {
|
|
2752
|
+
export { Viewer, commands, components, draggers };
|
|
5087
2753
|
//# sourceMappingURL=viewer-three.module.js.map
|