@inweb/markup 26.10.4 → 26.10.6

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.
@@ -1345,18 +1345,6 @@ const MarkupMode2Konva = {
1345
1345
  initializer: (ref, params = null, ...attr) => new KonvaCloud(params, ref, ...attr),
1346
1346
  },
1347
1347
  };
1348
- function debounce(func, wait) {
1349
- let timeout = null;
1350
- return (...args) => {
1351
- if (timeout) {
1352
- clearTimeout(timeout);
1353
- }
1354
- timeout = setTimeout(() => {
1355
- timeout = null;
1356
- func(...args);
1357
- }, wait);
1358
- };
1359
- }
1360
1348
  class KonvaMarkup {
1361
1349
  constructor() {
1362
1350
  this._markupIsActive = false;
@@ -1376,28 +1364,14 @@ class KonvaMarkup {
1376
1364
  this.removeImageInput();
1377
1365
  this.enableEditMode(draggerName);
1378
1366
  };
1379
- this.resizeContainer = (entries) => {
1380
- if (!entries || !entries[0] || !entries[0].contentRect)
1381
- return;
1382
- const { width, height } = entries[0].contentRect;
1383
- if (!width || !height)
1384
- return;
1385
- if (!this._konvaStage)
1367
+ this.resizeContainer = () => {
1368
+ const { offsetLeft, offsetTop, offsetWidth, offsetHeight } = this._container;
1369
+ if (!offsetWidth || !offsetHeight)
1386
1370
  return;
1387
- this._konvaStage.width(width);
1388
- this._konvaStage.height(height);
1389
- this.getObjects().forEach((markupObject) => {
1390
- markupObject.updateScreenCoordinates();
1391
- });
1392
- };
1393
- this.resizeViewer = (event) => {
1394
- const { width, height } = event;
1395
- if (!width || !height)
1396
- return;
1397
- if (!this._konvaStage)
1398
- return;
1399
- this._konvaStage.width(width);
1400
- this._konvaStage.height(height);
1371
+ this._markupContainer.style.left = `${offsetLeft}px`;
1372
+ this._markupContainer.style.top = `${offsetTop}px`;
1373
+ this._konvaStage.width(offsetWidth);
1374
+ this._konvaStage.height(offsetHeight);
1401
1375
  this.getObjects().forEach((markupObject) => {
1402
1376
  markupObject.updateScreenCoordinates();
1403
1377
  });
@@ -1426,8 +1400,6 @@ class KonvaMarkup {
1426
1400
  };
1427
1401
  }
1428
1402
  initialize(container, containerEvents, viewer, worldTransformer) {
1429
- if (!Konva)
1430
- 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?');
1431
1403
  this._viewer = viewer;
1432
1404
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform();
1433
1405
  this._container = container;
@@ -1438,15 +1410,10 @@ class KonvaMarkup {
1438
1410
  this._markupContainer.style.pointerEvents = "none";
1439
1411
  const parentDiv = this._container.parentElement;
1440
1412
  parentDiv.appendChild(this._markupContainer);
1441
- if (viewer) {
1442
- this._viewer.addEventListener("resize", this.resizeViewer);
1443
- }
1444
- else {
1445
- this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
1446
- this._resizeObserver.observe(parentDiv);
1447
- }
1448
1413
  this._markupColor.setColor(255, 0, 0);
1449
1414
  this.initializeKonva();
1415
+ this._resizeObserver = new ResizeObserver(this.resizeContainer);
1416
+ this._resizeObserver.observe(container);
1450
1417
  if (this._viewer) {
1451
1418
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
1452
1419
  this._viewer.addEventListener("pan", this.pan);
@@ -1460,9 +1427,9 @@ class KonvaMarkup {
1460
1427
  this._viewer.removeEventListener("pan", this.pan);
1461
1428
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
1462
1429
  }
1463
- this.destroyKonva();
1464
1430
  (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
1465
1431
  this._resizeObserver = undefined;
1432
+ this.destroyKonva();
1466
1433
  (_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
1467
1434
  this._markupContainer = undefined;
1468
1435
  this._container = undefined;