uiik 1.3.0-beta.4 → 1.3.2

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/index.esm.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * uiik v1.3.0-beta.4
2
+ * uiik v1.3.2
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
- * c) 2021-2023 @holyhigh2 may be freely distributed under the MIT license
5
+ * c) 2021-2024 @holyhigh2 may be freely distributed under the MIT license
6
6
  */
7
- import { isDefined, isString, isNumber, isArrayLike, isElement, isEmpty, isArray, isFunction, isBoolean, isUndefined } from 'myfx/is';
7
+ import { isDefined, isNumber, isNaN, isString, isArrayLike, isElement, isEmpty, isArray, isFunction, isBoolean, isUndefined } from 'myfx/is';
8
8
  import { find, map, toArray, each, reject, includes, some, flatMap, size } from 'myfx/collection';
9
9
  import { get, assign, merge } from 'myfx/object';
10
10
  import { split, test } from 'myfx/string';
@@ -47,45 +47,47 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
47
47
 
48
48
  const UtMap = new WeakMap();
49
49
  class UiiTransform {
50
- constructor(el) {
50
+ constructor(el, useTransform = true) {
51
51
  this.angle = 0;
52
52
  this.el = el;
53
+ this.useTransform = useTransform;
53
54
  this.normalize(el);
54
55
  UtMap.set(el, this);
55
56
  }
56
57
  normalize(el) {
57
- let { x, y } = normalize(el || this.el);
58
- this.x = x;
59
- this.y = y;
58
+ let { offx, offy } = normalize(el || this.el, this.useTransform);
59
+ this.offx = offx * -1;
60
+ this.offy = offy * -1;
60
61
  return this;
61
62
  }
62
63
  moveTo(x, y) {
63
64
  this.x = x;
64
65
  this.y = y;
65
- moveTo(this.el, this.x, this.y);
66
+ (this.useTransform ? transformMoveTo : moveTo)(this.el, this.x + this.offx, this.y + this.offy);
66
67
  }
67
68
  moveToX(x) {
68
69
  this.x = x;
69
- moveTo(this.el, this.x, this.y);
70
+ (this.useTransform ? transformMoveTo : moveTo)(this.el, this.x + this.offx, NaN);
70
71
  }
71
72
  moveToY(y) {
72
73
  this.y = y;
73
- moveTo(this.el, this.x, this.y);
74
+ (this.useTransform ? transformMoveTo : moveTo)(this.el, NaN, this.y + this.offy);
74
75
  }
75
76
  rotateTo(deg, cx, cy) {
76
77
  this.angle = deg;
77
78
  rotateTo(this.el, deg, cx, cy);
78
79
  }
79
80
  }
80
- function normalize(el) {
81
+ function normalize(el, useTransform) {
81
82
  const style = window.getComputedStyle(el);
83
+ let offx = 0, offy = 0;
82
84
  let x = 0, y = 0;
85
+ let mx = 0, my = 0;
83
86
  if (el instanceof HTMLElement) {
84
- x = (parseFloat(style.left) || 0) + (parseFloat(style.marginLeft) || 0);
85
- y = (parseFloat(style.top) || 0) + (parseFloat(style.marginTop) || 0);
86
- el.style.setProperty("left", "0", "important");
87
- el.style.setProperty("top", "0", "important");
88
- el.style.setProperty("margin", "0", "important");
87
+ x = parseFloat(style.left) || 0;
88
+ y = parseFloat(style.top) || 0;
89
+ mx = parseFloat(style.marginLeft) || 0;
90
+ my = parseFloat(style.marginTop) || 0;
89
91
  }
90
92
  else {
91
93
  x =
@@ -94,24 +96,30 @@ function normalize(el) {
94
96
  y =
95
97
  parseFloat(get(el, "y.baseVal.value") || get(el, "cy.baseVal.value")) ||
96
98
  0;
97
- el.removeAttribute("x");
98
- el.removeAttribute("y");
99
- el.removeAttribute("cx");
100
- el.removeAttribute("cy");
101
- }
102
- const { x: tx, y: ty } = getTranslate(el);
103
- x += tx || 0;
104
- y += ty || 0;
105
- moveTo(el, x, y);
106
- return { x, y };
99
+ }
100
+ if (useTransform) {
101
+ (offx = x), (offy = y);
102
+ }
103
+ else {
104
+ (offx = 0), (offy = 0);
105
+ }
106
+ return { offx: offx + mx, offy: offy + my };
107
107
  }
108
- function wrapper(el) {
108
+ function wrapper(el, useTransform = true) {
109
109
  let ut = UtMap.get(el);
110
110
  if (ut)
111
111
  return ut.normalize(el);
112
- return new UiiTransform(el);
112
+ return new UiiTransform(el, useTransform);
113
113
  }
114
114
  function transformMove(transofrmStr, x, y, unit = false) {
115
+ if (!isNumber(x) || isNaN(x)) {
116
+ return (`translateY(${y}${unit ? "px" : ""}) ` +
117
+ transofrmStr.replace(/translateY\([^)]+?\)/, "").trim());
118
+ }
119
+ if (!isNumber(y) || isNaN(x)) {
120
+ return (`translateX(${x}${unit ? "px" : ""}) ` +
121
+ transofrmStr.replace(/translateX\([^)]+?\)/, "").trim());
122
+ }
115
123
  return (`translate(${x}${unit ? "px" : ""},${y}${unit ? "px" : ""}) ` +
116
124
  transofrmStr.replace(/translate\([^)]+?\)/, "").trim());
117
125
  }
@@ -120,6 +128,14 @@ function getTranslate(el) {
120
128
  let transformStr = "";
121
129
  if (el instanceof SVGGraphicsElement) {
122
130
  transformStr = el.getAttribute("transform") || "";
131
+ if (!transformStr) {
132
+ xVal =
133
+ parseFloat(get(el, "x.baseVal.value") || get(el, "cx.baseVal.value")) ||
134
+ 0;
135
+ yVal =
136
+ parseFloat(get(el, "y.baseVal.value") || get(el, "cy.baseVal.value")) ||
137
+ 0;
138
+ }
123
139
  }
124
140
  else {
125
141
  let style = el.style;
@@ -147,11 +163,26 @@ function getTranslate(el) {
147
163
  }
148
164
  function moveTo(el, x, y) {
149
165
  if (el instanceof SVGGraphicsElement) {
150
- el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", x, y));
166
+ if (x)
167
+ el.setAttribute("x", x + "");
168
+ if (y)
169
+ el.setAttribute("y", y + "");
170
+ }
171
+ else {
172
+ let style = el.style;
173
+ if (x)
174
+ style.left = x + "px";
175
+ if (y)
176
+ style.top = y + "px";
177
+ }
178
+ }
179
+ function transformMoveTo(el, x, y) {
180
+ if (el instanceof SVGGraphicsElement) {
181
+ el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", x || 0, y || 0));
151
182
  }
152
183
  else {
153
184
  let style = el.style;
154
- style.transform = transformMove(style.transform || "", x, y, true);
185
+ style.transform = transformMove(style.transform || "", x || 0, y || 0, true);
155
186
  }
156
187
  }
157
188
  const EXP_GET_TRANSLATE = /translate\(\s*(?<x>[\d.-]+)\D*,\s*(?<y>[\d.-]+)\D*\)/gim;
@@ -200,6 +231,7 @@ function rotateTo(el, deg, cx, cy) {
200
231
 
201
232
  const ONE_ANG = Math.PI / 180;
202
233
  const ONE_RAD = 180 / Math.PI;
234
+ const THRESHOLD = 3;
203
235
  function getBox(child, parent) {
204
236
  const rect = child.getBoundingClientRect();
205
237
  const rs = { x: 0, y: 0, w: rect.width, h: rect.height };
@@ -279,33 +311,30 @@ function getStyleXy(el) {
279
311
  return { x, y };
280
312
  }
281
313
  function getStyleSize(el, cStyle) {
314
+ if ("getBBox" in el) {
315
+ let { width, height } = el.getBBox();
316
+ return { w: width, h: height };
317
+ }
282
318
  if (!cStyle)
283
319
  cStyle = window.getComputedStyle(el);
284
320
  const w = parseFloat(cStyle.width);
285
321
  const h = parseFloat(cStyle.height);
286
322
  return { w, h };
287
323
  }
288
- const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<e>[\d.-]+)\s*,\s*(?<f>[\d.-]+)\s*\)/;
289
324
  function getMatrixInfo(el, recur = false) {
290
- const rs = _getMatrixInfo(el);
325
+ const rs = { scale: 1, angle: 0, x: 0, y: 0 };
326
+ let a = 1, b = 0;
327
+ let elCStyle = window.getComputedStyle(el);
328
+ let matrix = new DOMMatrix(elCStyle.transform);
291
329
  if (recur) {
292
330
  let p = el.parentElement;
293
- while (p && p.tagName !== "BODY") {
294
- let prs = _getMatrixInfo(p);
295
- rs.scale *= prs.scale;
331
+ while (p && p.tagName !== "BODY" && p.tagName.toLowerCase() !== "svg") {
332
+ let pCStyle = window.getComputedStyle(p);
333
+ const pMatrix = new DOMMatrix(pCStyle.transform);
334
+ matrix = matrix.multiply(pMatrix);
296
335
  p = p.parentElement;
297
336
  }
298
337
  }
299
- return rs;
300
- }
301
- function _getMatrixInfo(el) {
302
- const rs = { scale: 1, angle: 0, x: 0, y: 0 };
303
- let a = 1, b = 0;
304
- let elCStyle;
305
- if (el instanceof SVGGraphicsElement || el instanceof HTMLElement) {
306
- elCStyle = window.getComputedStyle(el);
307
- }
308
- let matrix = _getMatrix(elCStyle.transform);
309
338
  if (matrix) {
310
339
  a = matrix.a;
311
340
  b = matrix.b;
@@ -318,30 +347,11 @@ function _getMatrixInfo(el) {
318
347
  rs.angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
319
348
  return rs;
320
349
  }
321
- function _getMatrix(transform) {
322
- let matrix = null;
323
- if (window.WebKitCSSMatrix) {
324
- matrix = new WebKitCSSMatrix(transform);
325
- }
326
- else {
327
- const matched = transform.match(EXP_MATRIX);
328
- if (matched && matched.groups) {
329
- matrix = {
330
- a: parseFloat(matched.groups.a),
331
- b: parseFloat(matched.groups.b),
332
- c: parseFloat(matched.groups.c),
333
- d: parseFloat(matched.groups.d),
334
- e: parseFloat(matched.groups.e),
335
- f: parseFloat(matched.groups.f),
336
- };
337
- }
338
- }
339
- return matrix;
340
- }
341
350
  function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
342
351
  if (!elRect) {
343
352
  elRect = el.getBoundingClientRect();
344
353
  }
354
+ let rx = elRect.x, ry = elRect.y;
345
355
  if (!elCStyle) {
346
356
  elCStyle = window.getComputedStyle(el);
347
357
  }
@@ -350,20 +360,20 @@ function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
350
360
  }
351
361
  const scale = matrixInfo.scale;
352
362
  let x = event.clientX -
353
- elRect.x -
363
+ rx -
354
364
  (parseFloat(elCStyle.borderLeftWidth) || 0) * scale +
355
365
  el.scrollLeft * scale;
356
366
  let y = event.clientY -
357
- elRect.y -
367
+ ry -
358
368
  (parseFloat(elCStyle.borderTopWidth) || 0) * scale +
359
369
  el.scrollTop * scale;
360
- return { x: x / scale, y: y / scale };
370
+ return { x: x / scale, y: y / scale, scale };
361
371
  }
362
- function getRectInContainer(el, container) {
372
+ function getRectInContainer(el, container, matrixInfo) {
363
373
  const elRect = el.getBoundingClientRect();
364
374
  const containerRect = container.getBoundingClientRect();
365
375
  const elCStyle = window.getComputedStyle(container);
366
- const matrixInfo = getMatrixInfo(container);
376
+ matrixInfo = matrixInfo || getMatrixInfo(container, true);
367
377
  const scale = matrixInfo.scale;
368
378
  let x = elRect.x -
369
379
  containerRect.x -
@@ -380,6 +390,12 @@ function getRectInContainer(el, container) {
380
390
  h: elRect.height / scale,
381
391
  };
382
392
  }
393
+ function getRectCenter(el, matrixInfo) {
394
+ const panelRect = getRectInContainer(el, el.parentElement, matrixInfo);
395
+ let x = Math.round(panelRect.x + panelRect.w / 2);
396
+ let y = Math.round(panelRect.y + panelRect.h / 2);
397
+ return { x, y };
398
+ }
383
399
  function getCenterXy(el, ox, oy) {
384
400
  const cStyle = window.getComputedStyle(el);
385
401
  const center = cStyle.transformOrigin;
@@ -399,7 +415,19 @@ function getCenterXy(el, ox, oy) {
399
415
  return { sx: startX, sy: startY, x: startX + ox, y: startY + oy, ox, oy };
400
416
  }
401
417
  function getCenterXySVG(el, ox, oy) {
402
- const { x, y } = getTranslate(el);
418
+ let elRect = el.getBoundingClientRect();
419
+ let svgRect = el.ownerSVGElement.getBoundingClientRect();
420
+ let x = elRect.x - svgRect.x;
421
+ let y = elRect.y - svgRect.y;
422
+ const shadowDom = el.cloneNode();
423
+ rotateTo(shadowDom, 0);
424
+ const parentEl = el.parentElement;
425
+ if (parentEl) {
426
+ parentEl.appendChild(shadowDom);
427
+ const offsetXY = getRectInContainer(shadowDom, parentEl);
428
+ (offsetXY.x), (offsetXY.y);
429
+ parentEl.removeChild(shadowDom);
430
+ }
403
431
  return { sx: x, sy: y, x: x + ox, y: y + oy, ox, oy };
404
432
  }
405
433
  function getVertex(el, ox, oy) {
@@ -407,7 +435,9 @@ function getVertex(el, ox, oy) {
407
435
  const w = parseFloat(cStyle.width);
408
436
  const h = parseFloat(cStyle.height);
409
437
  const { originX, originY } = parseOxy(ox, oy, w, h);
410
- const { x, y, sx, sy } = el instanceof SVGGraphicsElement ? getCenterXySVG(el, originX, originY) : getCenterXy(el);
438
+ const { x, y, sx, sy } = el instanceof SVGGraphicsElement
439
+ ? getCenterXySVG(el, originX, originY)
440
+ : getCenterXy(el);
411
441
  const { angle } = getMatrixInfo(el);
412
442
  return calcVertex(w, h, x, y, sx, sy, angle * ONE_ANG);
413
443
  }
@@ -419,28 +449,43 @@ function calcVertex(w, h, cx, cy, sx, sy, radian) {
419
449
  { x: w, y: h },
420
450
  ];
421
451
  return map(originVertex, ({ x, y }) => {
422
- const nx = (x - cx + sx) * Math.cos(radian) -
423
- (y - cy + sy) * Math.sin(radian);
424
- const ny = (x - cx + sx) * Math.sin(radian) +
425
- (y - cy + sy) * Math.cos(radian);
452
+ const nx = (x - cx + sx) * Math.cos(radian) - (y - cy + sy) * Math.sin(radian);
453
+ const ny = (x - cx + sx) * Math.sin(radian) + (y - cy + sy) * Math.cos(radian);
426
454
  return { x: cx + nx, y: cy + ny };
427
455
  });
428
456
  }
429
- function parseOxy(ox, oy, w, h) {
457
+ function parseOxy(ox, oy, w, h, el) {
430
458
  let originX = 0, originY = 0;
459
+ let transformOrigin;
431
460
  if (isString(ox)) {
432
461
  originX = (parseFloat(ox) / 100) * w;
433
462
  }
434
463
  else if (isNumber(ox)) {
435
464
  originX = ox;
436
465
  }
466
+ else if (el) {
467
+ if (!transformOrigin)
468
+ transformOrigin = window.getComputedStyle(el).transformOrigin;
469
+ const centerPair = transformOrigin.split(" ");
470
+ originX = parseFloat(centerPair[0]);
471
+ }
437
472
  if (isString(oy)) {
438
473
  originY = (parseFloat(oy) / 100) * h;
439
474
  }
440
475
  else if (isNumber(oy)) {
441
476
  originY = oy;
442
477
  }
478
+ else if (el) {
479
+ if (!transformOrigin)
480
+ transformOrigin = window.getComputedStyle(el).transformOrigin;
481
+ const centerPair = transformOrigin.split(" ");
482
+ originY = parseFloat(centerPair[1]);
483
+ }
443
484
  return { originX, originY };
485
+ }
486
+ function normalizeVector(x, y) {
487
+ let len = Math.sqrt(x * x + y * y);
488
+ return { x: x / len, y: y / len };
444
489
  }
445
490
 
446
491
  var _Uii_listeners;
@@ -537,9 +582,10 @@ class Uii {
537
582
  e.preventDefault();
538
583
  return false;
539
584
  }
585
+ let matrixInfo = getMatrixInfo(el, true);
540
586
  const pointerMove = (ev) => {
541
- const offX = ev.clientX - originPosX;
542
- const offY = ev.clientY - originPosY;
587
+ const offX = (ev.clientX - originPosX) / matrixInfo.scale;
588
+ const offY = (ev.clientY - originPosY) / matrixInfo.scale;
543
589
  if (!dragging) {
544
590
  if (Math.abs(offX) > threshold || Math.abs(offY) > threshold) {
545
591
  dragging = true;
@@ -622,7 +668,6 @@ class Uii {
622
668
  _Uii_listeners = new WeakMap();
623
669
 
624
670
  var _Splittable_instances, _Splittable_checkDirection, _Splittable_bindHandle;
625
- const THRESHOLD$4 = 1;
626
671
  const CLASS_SPLITTABLE = "uii-splittable";
627
672
  const CLASS_SPLITTABLE_HANDLE = "uii-splittable-handle";
628
673
  const CLASS_SPLITTABLE_HANDLE_GHOST = "uii-splittable-handle-ghost";
@@ -691,8 +736,17 @@ class Splittable extends Uii {
691
736
  dom2 = h.nextElementSibling;
692
737
  }
693
738
  else {
694
- dom2 = getRootEl(h, con);
695
- dom1 = dom2.previousElementSibling;
739
+ let domCon = getRootEl(h, con);
740
+ let domL = domCon.previousElementSibling;
741
+ let domR = domCon.nextElementSibling;
742
+ if (domL && !domL.querySelector(this.opts.handle)) {
743
+ dom1 = domL;
744
+ dom2 = domCon;
745
+ }
746
+ else {
747
+ dom1 = domCon;
748
+ dom2 = domR;
749
+ }
696
750
  }
697
751
  __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, dom1, dom2, h);
698
752
  });
@@ -766,6 +820,7 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
766
820
  const dom2Style = dom2.style;
767
821
  const ghost = opts.ghost;
768
822
  const ghostClass = opts.ghostClass;
823
+ const ghostTo = opts.ghostTo;
769
824
  let ghostNode = null;
770
825
  let sticked = 'none';
771
826
  if (originSize < minSize1 / 2) {
@@ -789,7 +844,8 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
789
844
  ghostNode.className =
790
845
  ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
791
846
  }
792
- currentTarget.parentNode.appendChild(ghostNode);
847
+ let ghostParent = ghostTo ? (isString(ghostTo) ? document.querySelector(ghostTo) : ghostTo) : currentTarget.parentNode;
848
+ ghostParent.appendChild(ghostNode);
793
849
  onClone && onClone({ clone: ghostNode }, ev);
794
850
  }
795
851
  }
@@ -831,10 +887,10 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
831
887
  anotherSize = blockSize - ds1 - splitterSize;
832
888
  if (ghostNode) {
833
889
  if (dir === 'v') {
834
- ghostNode.style.top = startPos + ds1 - handleSize / 2 + 'px';
890
+ ghostNode.style.top = startPos + ds1 - splitterSize / 2 + 'px';
835
891
  }
836
892
  else {
837
- ghostNode.style.left = startPos + ds1 - handleSize / 2 + 'px';
893
+ ghostNode.style.left = startPos + ds1 - splitterSize / 2 + 'px';
838
894
  }
839
895
  }
840
896
  else {
@@ -849,16 +905,16 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
849
905
  onSticky && onSticky({ size1: ds1, size2: anotherSize, position: sticked }, ev);
850
906
  }
851
907
  if (dir === 'v') {
852
- currentStyle.top = dom2.offsetTop - handleSize / 2 + 'px';
908
+ currentStyle.top = dom2.offsetTop - splitterSize / 2 + 'px';
853
909
  }
854
910
  else {
855
- currentStyle.left = dom2.offsetLeft - handleSize / 2 + 'px';
911
+ currentStyle.left = dom2.offsetLeft - splitterSize / 2 + 'px';
856
912
  }
857
913
  }
858
914
  onSplit && onSplit({ size1: ds1, size2: anotherSize }, ev);
859
915
  });
860
916
  onPointerEnd((args) => {
861
- var _a, _b;
917
+ var _a;
862
918
  const { ev, currentStyle } = args;
863
919
  switch (dir) {
864
920
  case 'v':
@@ -880,17 +936,17 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
880
936
  dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
881
937
  }
882
938
  if (dir === 'v') {
883
- currentStyle.top = startPos + ds1 - handleSize / 2 + 'px';
939
+ currentStyle.top = startPos + ds1 - splitterSize / 2 + 'px';
884
940
  }
885
941
  else {
886
- currentStyle.left = startPos + ds1 - handleSize / 2 + 'px';
942
+ currentStyle.left = startPos + ds1 - splitterSize / 2 + 'px';
887
943
  }
888
- ((_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = ghostNode.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
944
+ (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
889
945
  }
890
946
  onEnd && onEnd({ size1: originSize, size2: originSize1 }, ev);
891
947
  });
892
948
  }, {
893
- threshold: THRESHOLD$4,
949
+ threshold: THRESHOLD,
894
950
  lockPage: true
895
951
  });
896
952
  };
@@ -898,7 +954,6 @@ function newSplittable(container, opts) {
898
954
  return new Splittable(container, opts);
899
955
  }
900
956
 
901
- const THRESHOLD$3 = 2;
902
957
  const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
903
958
  const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
904
959
  const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
@@ -934,14 +989,12 @@ class Resizable extends Uii {
934
989
  const onPointerDown = opts.onPointerDown;
935
990
  if (onPointerDown && onPointerDown(ev) === false)
936
991
  return true;
937
- let container = panel instanceof SVGGraphicsElement
938
- ? panel.ownerSVGElement
939
- : panel.parentElement;
940
- let setOrigin = !(panel instanceof SVGGraphicsElement);
941
- let matrixInfo = getMatrixInfo(panel);
942
- const offset = getRectInContainer(panel, container);
992
+ let container = panel.parentElement;
993
+ let matrixInfo = getMatrixInfo(panel, true);
994
+ const offset = getRectInContainer(panel, container, matrixInfo);
943
995
  const offsetParentRect = container.getBoundingClientRect();
944
996
  const offsetParentCStyle = window.getComputedStyle(container);
997
+ let setOrigin = !(panel instanceof SVGGraphicsElement) && matrixInfo.angle != 0;
945
998
  const { w, h } = getStyleSize(panel);
946
999
  const originW = w;
947
1000
  const originH = h;
@@ -985,10 +1038,10 @@ class Resizable extends Uii {
985
1038
  toTransformOrigin = "0 0";
986
1039
  break;
987
1040
  }
988
- let minWidth;
989
- let minHeight;
990
- let maxWidth;
991
- let maxHeight;
1041
+ let minWidth = 1;
1042
+ let minHeight = 1;
1043
+ let maxWidth = 9999;
1044
+ let maxHeight = 9999;
992
1045
  if (isArray(opts.minSize)) {
993
1046
  minWidth = opts.minSize[0];
994
1047
  minHeight = opts.minSize[1];
@@ -1020,9 +1073,8 @@ class Resizable extends Uii {
1020
1073
  let currentVertex;
1021
1074
  let refPoint;
1022
1075
  let k1;
1023
- let startOx = 0;
1024
- let startOy = 0;
1025
1076
  let sX = 0, sY = 0;
1077
+ let startPointXy;
1026
1078
  onPointerStart(function (args) {
1027
1079
  var _a;
1028
1080
  const { ev } = args;
@@ -1056,16 +1108,17 @@ class Resizable extends Uii {
1056
1108
  const w = parseFloat(cStyle.width);
1057
1109
  const h = parseFloat(cStyle.height);
1058
1110
  const oxy = parseOxy(opts.ox, opts.oy, w, h);
1059
- startOx = oxy.originX;
1060
- startOy = oxy.originY;
1061
- const { x, y, sx, sy } = panel instanceof SVGGraphicsElement
1062
- ? getCenterXySVG(panel, startOx, startOy)
1063
- : getCenterXy(panel);
1064
- let centerX = x, centerY = y;
1111
+ oxy.originX;
1112
+ oxy.originY;
1113
+ const panelRect = getRectInContainer(panel, panel.parentElement, matrixInfo);
1114
+ let centerX = Math.round(panelRect.x + panelRect.w / 2);
1115
+ let centerY = Math.round(panelRect.y + panelRect.h / 2);
1116
+ let sx = Math.round(centerX - originW / 2);
1117
+ let sy = Math.round(centerY - originH / 2);
1118
+ transform.x = sx;
1119
+ transform.y = sy;
1065
1120
  const deg = matrixInfo.angle * ONE_ANG;
1066
- currentVertex =
1067
- vertexBeforeTransform =
1068
- calcVertex(originW, originH, centerX, centerY, sx, sy, deg);
1121
+ currentVertex = vertexBeforeTransform = calcVertex(originW, originH, centerX, centerY, sx, sy, deg);
1069
1122
  switch (dir) {
1070
1123
  case "s":
1071
1124
  case "e":
@@ -1094,26 +1147,27 @@ class Resizable extends Uii {
1094
1147
  style.transformOrigin = toTransformOrigin;
1095
1148
  }
1096
1149
  else {
1097
- style.transformOrigin = `${centerX - transform.x}px ${centerY - transform.y}px`;
1150
+ style.transformOrigin = `${centerX - sx}px ${centerY - sy}px`;
1098
1151
  }
1099
1152
  }
1100
1153
  if (panel instanceof SVGGraphicsElement) {
1101
1154
  sX = matrixInfo.x - currentVertex[0].x;
1102
1155
  sY = matrixInfo.y - currentVertex[0].y;
1103
1156
  }
1104
- onStart && onStart.call(uiik, { w: originW, h: originH, transform }, ev);
1157
+ startPointXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle, matrixInfo);
1158
+ onStart &&
1159
+ onStart.call(uiik, { w: originW, h: originH, transform }, ev);
1105
1160
  });
1106
1161
  onPointerMove((args) => {
1107
- const { ev } = args;
1108
- const currentXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle);
1109
- let newX = currentXy.x;
1110
- let newY = currentXy.y;
1111
- let angle = Math.atan2(newY - refPoint.y, newX - refPoint.x) * ONE_RAD -
1112
- matrixInfo.angle;
1113
- let hyLen = Math.sqrt((newX - refPoint.x) * (newX - refPoint.x) +
1114
- (newY - refPoint.y) * (newY - refPoint.y));
1162
+ const { ev, offX, offY } = args;
1163
+ let newX = startPointXy.x + offX;
1164
+ let newY = startPointXy.y + offY;
1165
+ const rpx = refPoint.x;
1166
+ const rpy = refPoint.y;
1167
+ let angle = Math.atan2(newY - rpy, newX - rpx) * ONE_RAD - matrixInfo.angle;
1168
+ let hyLen = Math.sqrt((newX - rpx) * (newX - rpx) + (newY - rpy) * (newY - rpy));
1115
1169
  let pl1 = Math.abs(k1 === Infinity
1116
- ? newY - refPoint.y
1170
+ ? newY - refPoint.y / matrixInfo.scale
1117
1171
  : hyLen * Math.cos(angle * ONE_ANG));
1118
1172
  let pl2 = Math.sqrt(hyLen * hyLen - pl1 * pl1);
1119
1173
  let w = originW;
@@ -1121,6 +1175,18 @@ class Resizable extends Uii {
1121
1175
  let y = originY;
1122
1176
  let x = originX;
1123
1177
  let angl = 0;
1178
+ switch (dir) {
1179
+ case "w":
1180
+ case "sw":
1181
+ angl =
1182
+ Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1183
+ break;
1184
+ case "n":
1185
+ case "ne":
1186
+ case "nw":
1187
+ angl =
1188
+ Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1189
+ }
1124
1190
  switch (dir) {
1125
1191
  case "s":
1126
1192
  h = pl2;
@@ -1128,17 +1194,63 @@ class Resizable extends Uii {
1128
1194
  case "e":
1129
1195
  w = pl1;
1130
1196
  break;
1197
+ case "n":
1198
+ h = pl2;
1199
+ if (angl === 90) {
1200
+ h = newY - currentVertex[2].y;
1201
+ }
1202
+ break;
1203
+ case "w":
1204
+ w = pl1;
1205
+ if (angl === 0) {
1206
+ w = newX - currentVertex[1].x;
1207
+ }
1208
+ break;
1209
+ case "nw":
1210
+ w = pl1;
1211
+ h = pl2;
1212
+ if (matrixInfo.angle === 180) {
1213
+ w = newX - currentVertex[3].x;
1214
+ h = newY - currentVertex[3].y;
1215
+ }
1216
+ break;
1131
1217
  case "se":
1218
+ case "sw":
1219
+ case "ne":
1132
1220
  w = pl1;
1133
1221
  h = pl2;
1134
1222
  break;
1223
+ }
1224
+ if (minHeight && h < minHeight)
1225
+ h = minHeight;
1226
+ if (maxHeight && h > maxHeight)
1227
+ h = maxHeight;
1228
+ if (minWidth && w < minWidth) {
1229
+ w = minWidth;
1230
+ }
1231
+ if (maxWidth && w > maxWidth)
1232
+ w = maxWidth;
1233
+ let hLine, wLine;
1234
+ switch (dir) {
1235
+ case "s":
1236
+ hLine = { p1: currentVertex[1], p2: currentVertex[0] };
1237
+ h = limitWH(newX, newY, hLine, h, minHeight);
1238
+ break;
1239
+ case "e":
1240
+ wLine = { p1: currentVertex[0], p2: currentVertex[2] };
1241
+ w = limitWH(newX, newY, wLine, w, minWidth);
1242
+ break;
1243
+ case "se":
1244
+ wLine = { p1: currentVertex[0], p2: currentVertex[2] };
1245
+ hLine = { p1: currentVertex[1], p2: currentVertex[0] };
1246
+ w = limitWH(newX, newY, wLine, w, minWidth);
1247
+ h = limitWH(newX, newY, hLine, h, minHeight);
1248
+ break;
1135
1249
  case "n":
1136
- h = pl2;
1137
- angl =
1138
- Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1250
+ hLine = { p1: currentVertex[2], p2: currentVertex[3] };
1251
+ h = limitWH(newX, newY, hLine, h, minHeight);
1139
1252
  let plh;
1140
1253
  if (angl === 90) {
1141
- h = newY - currentVertex[2].y;
1142
1254
  x = currentVertex[2].x;
1143
1255
  y = newY;
1144
1256
  }
@@ -1154,12 +1266,10 @@ class Resizable extends Uii {
1154
1266
  }
1155
1267
  break;
1156
1268
  case "w":
1157
- w = pl1;
1158
- angl =
1159
- Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1269
+ wLine = { p1: currentVertex[3], p2: currentVertex[1] };
1270
+ w = limitWH(newX, newY, wLine, w, minWidth);
1160
1271
  let plw;
1161
1272
  if (angl === 0) {
1162
- w = newX - currentVertex[1].x;
1163
1273
  x = newX;
1164
1274
  y = currentVertex[1].y;
1165
1275
  }
@@ -1175,20 +1285,59 @@ class Resizable extends Uii {
1175
1285
  }
1176
1286
  break;
1177
1287
  case "nw":
1178
- w = pl1;
1179
- h = pl2;
1288
+ wLine = { p1: currentVertex[3], p2: currentVertex[1] };
1289
+ hLine = { p1: currentVertex[2], p2: currentVertex[3] };
1290
+ w = limitWH(newX, newY, wLine, w, minWidth);
1291
+ h = limitWH(newX, newY, hLine, h, minHeight);
1180
1292
  x = newX;
1181
1293
  y = newY;
1182
- if (matrixInfo.angle === 180) {
1183
- w = newX - currentVertex[3].x;
1184
- h = newY - currentVertex[3].y;
1294
+ let cv2x = currentVertex[2].x;
1295
+ let cv2y = currentVertex[2].y;
1296
+ let cv1x = currentVertex[1].x;
1297
+ let cv1y = currentVertex[1].y;
1298
+ let v32n = normalizeVector(cv2x - currentVertex[3].x, cv2y - currentVertex[3].y);
1299
+ v32n.x *= minWidth;
1300
+ v32n.y *= minWidth;
1301
+ let v10n = normalizeVector(currentVertex[0].x - cv1x, currentVertex[0].y - cv1y);
1302
+ v10n.x *= minWidth;
1303
+ v10n.y *= minWidth;
1304
+ let wp1 = { x: wLine.p1.x + v32n.x, y: wLine.p1.y + v32n.y };
1305
+ let wp2 = { x: wLine.p2.x + v10n.x, y: wLine.p2.y + v10n.y };
1306
+ let invalid = (wp2.x - wp1.x) * (newY - wp1.y) -
1307
+ (wp2.y - wp1.y) * (newX - wp1.x) >
1308
+ 0;
1309
+ if (invalid) {
1310
+ let v20n = normalizeVector(currentVertex[0].x - cv2x, currentVertex[0].y - cv2y);
1311
+ v20n.x *= h;
1312
+ v20n.y *= h;
1313
+ x = wp1.x + v20n.x;
1314
+ y = wp1.y + v20n.y;
1315
+ }
1316
+ let v31n = normalizeVector(cv1x - currentVertex[3].x, cv1y - currentVertex[3].y);
1317
+ v31n.x *= minHeight;
1318
+ v31n.y *= minHeight;
1319
+ let v20n = normalizeVector(currentVertex[0].x - cv2x, currentVertex[0].y - cv2y);
1320
+ v20n.x *= minHeight;
1321
+ v20n.y *= minHeight;
1322
+ let hp1 = { x: hLine.p1.x + v31n.x, y: hLine.p1.y + v31n.y };
1323
+ let hp2 = { x: hLine.p2.x + v20n.x, y: hLine.p2.y + v20n.y };
1324
+ invalid =
1325
+ (hp2.x - hp1.x) * (newY - hp1.y) -
1326
+ (hp2.y - hp1.y) * (newX - hp1.x) >
1327
+ 0;
1328
+ if (invalid) {
1329
+ let v10n = normalizeVector(currentVertex[0].x - cv1x, currentVertex[0].y - cv1y);
1330
+ v10n.x *= w;
1331
+ v10n.y *= w;
1332
+ x = hp2.x + v10n.x;
1333
+ y = hp2.y + v10n.y;
1185
1334
  }
1186
1335
  break;
1187
1336
  case "sw":
1188
- w = pl1;
1189
- h = pl2;
1190
- angl =
1191
- Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1337
+ wLine = { p1: currentVertex[3], p2: currentVertex[1] };
1338
+ hLine = { p1: currentVertex[1], p2: currentVertex[0] };
1339
+ w = limitWH(newX, newY, wLine, w, minWidth);
1340
+ h = limitWH(newX, newY, hLine, h, minHeight);
1192
1341
  let plw1;
1193
1342
  if (angl === 0) {
1194
1343
  x = newX;
@@ -1206,10 +1355,10 @@ class Resizable extends Uii {
1206
1355
  }
1207
1356
  break;
1208
1357
  case "ne":
1209
- w = pl1;
1210
- h = pl2;
1211
- angl =
1212
- Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1358
+ wLine = { p1: currentVertex[0], p2: currentVertex[2] };
1359
+ hLine = { p1: currentVertex[2], p2: currentVertex[3] };
1360
+ w = limitWH(newX, newY, wLine, w, minWidth);
1361
+ h = limitWH(newX, newY, hLine, h, minHeight);
1213
1362
  let plne;
1214
1363
  if (angl === 0) {
1215
1364
  x = newX;
@@ -1227,18 +1376,6 @@ class Resizable extends Uii {
1227
1376
  }
1228
1377
  break;
1229
1378
  }
1230
- if (changeW) {
1231
- if (minWidth && w < minWidth)
1232
- w = minWidth;
1233
- if (maxWidth && w > maxWidth)
1234
- w = maxWidth;
1235
- }
1236
- if (changeH) {
1237
- if (minHeight && h < minHeight)
1238
- h = minHeight;
1239
- if (maxHeight && h > maxHeight)
1240
- h = maxHeight;
1241
- }
1242
1379
  if (aspectRatio) {
1243
1380
  if (changeW) {
1244
1381
  style.width = w + "px";
@@ -1263,19 +1400,22 @@ class Resizable extends Uii {
1263
1400
  }
1264
1401
  }
1265
1402
  if (changeY) {
1266
- transform.moveToY(y + sY);
1403
+ transform.moveTo(x, y + sY);
1267
1404
  }
1268
1405
  if (changeX) {
1269
- transform.moveToX(x + sX);
1406
+ transform.moveTo(x + sX, y);
1270
1407
  }
1271
1408
  lastX = x;
1272
1409
  lastY = y;
1273
1410
  currentW = w;
1274
1411
  currentH = h;
1275
1412
  if (onResize && onResize.call) {
1276
- const { x, y, sx, sy } = panel instanceof SVGGraphicsElement
1277
- ? getCenterXySVG(panel, startOx, startOy)
1278
- : getCenterXy(panel);
1413
+ onResize.call;
1414
+ const panelRect = getRectInContainer(panel, panel.parentElement, matrixInfo);
1415
+ let centerX = Math.round(panelRect.x + panelRect.w / 2);
1416
+ let centerY = Math.round(panelRect.y + panelRect.h / 2);
1417
+ let sx = Math.round(centerX - originW / 2);
1418
+ let sy = Math.round(centerY - originH / 2);
1279
1419
  onResize.call(uiik, {
1280
1420
  w,
1281
1421
  h,
@@ -1287,7 +1427,7 @@ class Resizable extends Uii {
1287
1427
  sx: sx,
1288
1428
  sy: sy,
1289
1429
  deg: matrixInfo.angle,
1290
- transform
1430
+ transform,
1291
1431
  }, ev);
1292
1432
  }
1293
1433
  });
@@ -1302,37 +1442,31 @@ class Resizable extends Uii {
1302
1442
  moveTo(panel, lastX / matrixInfo.scale, lastY / matrixInfo.scale);
1303
1443
  resize(transform, panelStyle, parseFloat(ghostNode.style.width), parseFloat(ghostNode.style.height));
1304
1444
  }
1305
- panel.style.transformOrigin = originalTransformOrigin;
1306
- const { x, y, sx, sy, ox, oy } = panel instanceof SVGGraphicsElement
1307
- ? getCenterXySVG(panel, startOx, startOy)
1308
- : getCenterXy(panel);
1309
- let centerX = x, centerY = y;
1445
+ if (setOrigin)
1446
+ panel.style.transformOrigin = originalTransformOrigin;
1447
+ let { x: centerX, y: centerY } = getRectCenter(panel, matrixInfo);
1448
+ let sx = Math.round(centerX - currentW / 2);
1449
+ let sy = Math.round(centerY - currentH / 2);
1310
1450
  const deg = matrixInfo.angle * ONE_ANG;
1311
1451
  const currentVertex = calcVertex(currentW, currentH, centerX, centerY, sx, sy, deg);
1312
- if (panel instanceof SVGGraphicsElement) {
1313
- if (matrixInfo.angle != 0) {
1314
- const oxy = parseOxy(opts.ox, opts.oy, currentW, currentH);
1315
- rotateTo(transform.el, matrixInfo.angle, oxy.originX, originY);
1316
- let { x, y, sx, sy } = getCenterXySVG(panel, oxy.originX, originY);
1317
- let currentVertex2 = calcVertex(currentW, currentH, x, y, sx, sy, deg);
1318
- transform.moveTo(transform.x - (currentVertex2[0].x - currentVertex[0].x), transform.y - (currentVertex2[0].y - currentVertex[0].y));
1319
- }
1320
- }
1321
- else {
1322
- if (changeX || changeY) {
1323
- transform.moveTo(transform.x - (currentVertex[0].x - lastX), transform.y - (currentVertex[0].y - lastY));
1324
- }
1325
- else {
1326
- transform.moveTo(transform.x -
1327
- (currentVertex[0].x - vertexBeforeTransform[0].x), transform.y -
1328
- (currentVertex[0].y - vertexBeforeTransform[0].y));
1452
+ if (setOrigin) {
1453
+ if (panel instanceof HTMLElement) {
1454
+ if (changeX || changeY) {
1455
+ transform.moveTo(transform.x - (currentVertex[0].x - lastX), transform.y - (currentVertex[0].y - lastY));
1456
+ }
1457
+ else {
1458
+ transform.moveTo(transform.x -
1459
+ (currentVertex[0].x - vertexBeforeTransform[0].x), transform.y -
1460
+ (currentVertex[0].y - vertexBeforeTransform[0].y));
1461
+ }
1329
1462
  }
1330
1463
  }
1331
1464
  handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1332
- onEnd && onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
1465
+ onEnd &&
1466
+ onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
1333
1467
  });
1334
1468
  }, {
1335
- threshold: THRESHOLD$3,
1469
+ threshold: THRESHOLD,
1336
1470
  lockPage: true,
1337
1471
  });
1338
1472
  }
@@ -1366,6 +1500,15 @@ class Resizable extends Uii {
1366
1500
  });
1367
1501
  }
1368
1502
  }
1503
+ function limitWH(newX, newY, line, value, minValue) {
1504
+ let p1 = line.p1;
1505
+ let p2 = line.p2;
1506
+ let invalid = (p2.x - p1.x) * (newY - p1.y) - (p2.y - p1.y) * (newX - p1.x) > 0;
1507
+ if (invalid) {
1508
+ return minValue;
1509
+ }
1510
+ return value;
1511
+ }
1369
1512
  function resize(transform, style, w, h) {
1370
1513
  if (transform.el instanceof SVGGraphicsElement) {
1371
1514
  if (isDefined(w))
@@ -1395,14 +1538,15 @@ class Draggable extends Uii {
1395
1538
  super(els, assign({
1396
1539
  containment: false,
1397
1540
  watch: true,
1398
- threshold: 0,
1541
+ threshold: THRESHOLD,
1399
1542
  ghost: false,
1400
1543
  direction: "",
1401
1544
  scroll: true,
1545
+ useTransform: true,
1402
1546
  snapOptions: {
1403
1547
  tolerance: 10,
1404
1548
  },
1405
- self: false
1549
+ self: false,
1406
1550
  }, opts));
1407
1551
  _Draggable_instances.add(this);
1408
1552
  _Draggable_handleMap.set(this, new WeakMap());
@@ -1457,7 +1601,7 @@ class Draggable extends Uii {
1457
1601
  let draggableList = this.ele;
1458
1602
  const eleString = this.eleString;
1459
1603
  const initStyle = __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initStyle).bind(this);
1460
- this.addPointerDown(bindTarget, ({ ev, currentTarget, currentStyle, currentCStyle, pointX, pointY, onPointerStart, onPointerMove, onPointerEnd }) => {
1604
+ this.addPointerDown(bindTarget, ({ ev, currentCStyle, onPointerStart, onPointerMove, onPointerEnd, }) => {
1461
1605
  var _a;
1462
1606
  let t = ev.target;
1463
1607
  if (!t)
@@ -1466,7 +1610,7 @@ class Draggable extends Uii {
1466
1610
  draggableList = bindTarget.querySelectorAll(eleString);
1467
1611
  initStyle(draggableList);
1468
1612
  }
1469
- let findRs = closest(t, node => includes(draggableList, node), 'parentNode');
1613
+ let findRs = closest(t, (node) => includes(draggableList, node), "parentNode");
1470
1614
  if (!findRs)
1471
1615
  return true;
1472
1616
  const dragDom = findRs;
@@ -1477,28 +1621,23 @@ class Draggable extends Uii {
1477
1621
  if (opts.self && dragDom !== t)
1478
1622
  return true;
1479
1623
  const onPointerDown = opts.onPointerDown;
1480
- if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
1624
+ if (onPointerDown &&
1625
+ onPointerDown({ draggable: dragDom }, ev) === false)
1481
1626
  return true;
1482
1627
  const filter = opts.filter;
1483
1628
  if (filter) {
1484
- if (some(dragDom.querySelectorAll(filter), ele => ele.contains(t)))
1629
+ if (some(dragDom.querySelectorAll(filter), (ele) => ele.contains(t)))
1485
1630
  return true;
1486
1631
  }
1487
- const offsetParent = dragDom instanceof HTMLElement ? dragDom.offsetParent || document.body : dragDom.ownerSVGElement;
1488
- const offsetParentRect = offsetParent.getBoundingClientRect();
1489
- const offsetParentCStyle = window.getComputedStyle(offsetParent);
1490
- const offsetXy = getPointInContainer(ev, dragDom);
1491
- let offsetPointX = offsetXy.x;
1492
- let offsetPointY = offsetXy.y;
1493
- const matrixInfo = getMatrixInfo(dragDom, true);
1494
- const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1495
- if (matrixInfo.angle != 0) {
1496
- offsetPointX = currentXy.x - matrixInfo.x;
1497
- offsetPointY = currentXy.y - matrixInfo.y;
1498
- }
1632
+ let offsetParent;
1633
+ let offsetParentRect;
1634
+ let offsetParentCStyle;
1635
+ let offsetPointX = 0;
1636
+ let offsetPointY = 0;
1499
1637
  const inContainer = !!container;
1500
1638
  const ghost = opts.ghost;
1501
1639
  const ghostClass = opts.ghostClass;
1640
+ const ghostTo = opts.ghostTo;
1502
1641
  const direction = opts.direction;
1503
1642
  const onStart = opts.onStart;
1504
1643
  const onDrag = opts.onDrag;
@@ -1506,64 +1645,25 @@ class Draggable extends Uii {
1506
1645
  const onClone = opts.onClone;
1507
1646
  const originalZIndex = currentCStyle.zIndex;
1508
1647
  let zIndex = opts.zIndex || originalZIndex;
1509
- const classes = opts.classes || '';
1648
+ const classes = opts.classes || "";
1510
1649
  const group = opts.group;
1511
- if (group) {
1512
- let i = -1;
1513
- each(DRAGGER_GROUPS[group], el => {
1514
- const z = parseInt(currentCStyle.zIndex) || 0;
1515
- if (z > i)
1516
- i = z;
1517
- });
1518
- zIndex = i + 1;
1519
- }
1520
1650
  const scroll = opts.scroll;
1521
1651
  const scrollSpeed = opts.scrollSpeed || 10;
1522
1652
  let gridX, gridY;
1523
- const grid = opts.grid;
1524
- if (isArray(grid)) {
1525
- gridX = grid[0];
1526
- gridY = grid[1];
1527
- }
1528
- else if (isNumber(grid)) {
1529
- gridX = gridY = grid;
1530
- }
1531
1653
  const snapOn = opts.snap;
1532
1654
  let snappable;
1533
1655
  const snapTolerance = ((_a = opts.snapOptions) === null || _a === void 0 ? void 0 : _a.tolerance) || 10;
1534
1656
  const onSnap = opts.onSnap;
1535
1657
  let lastSnapDirY = "", lastSnapDirX = "";
1536
1658
  let lastSnapping = "";
1537
- if (snapOn) {
1538
- snappable = map((container || document).querySelectorAll(snapOn), (el) => {
1539
- const { x, y, w, h } = getRectInContainer(el, offsetParent);
1540
- return {
1541
- x1: x,
1542
- y1: y,
1543
- x2: x + w,
1544
- y2: y + h,
1545
- el: el,
1546
- };
1547
- });
1548
- }
1549
1659
  const dragDomRect = dragDom.getBoundingClientRect();
1550
- const originW = dragDomRect.width + parseFloat(currentCStyle.borderLeftWidth) + parseFloat(currentCStyle.borderRightWidth);
1551
- const originH = dragDomRect.height + parseFloat(currentCStyle.borderTopWidth) + parseFloat(currentCStyle.borderBottomWidth);
1660
+ let originW;
1661
+ let originH;
1552
1662
  let minX = 0;
1553
1663
  let minY = 0;
1554
1664
  let maxX = 0;
1555
1665
  let maxY = 0;
1556
- let originOffX = 0;
1557
- let originOffY = 0;
1558
- if (inContainer) {
1559
- maxX = container.scrollWidth - originW;
1560
- maxY = container.scrollHeight - originH;
1561
- }
1562
- if (maxX < 0)
1563
- maxX = 0;
1564
- if (maxY < 0)
1565
- maxY = 0;
1566
- let copyNode;
1666
+ let ghostNode;
1567
1667
  let transform;
1568
1668
  let timer = null;
1569
1669
  let toLeft = false;
@@ -1571,45 +1671,114 @@ class Draggable extends Uii {
1571
1671
  let toRight = false;
1572
1672
  let toBottom = false;
1573
1673
  let endX = 0, endY = 0;
1674
+ let startMatrixInfo;
1675
+ let startPointXy;
1574
1676
  onPointerStart(function (args) {
1575
- var _a;
1576
1677
  const { ev } = args;
1678
+ offsetParent =
1679
+ dragDom instanceof HTMLElement
1680
+ ? dragDom.offsetParent || document.body
1681
+ : dragDom.ownerSVGElement;
1682
+ offsetParentRect = offsetParent.getBoundingClientRect();
1683
+ offsetParentCStyle = window.getComputedStyle(offsetParent);
1684
+ startMatrixInfo = getMatrixInfo(dragDom, true);
1685
+ const offsetXy = getPointInContainer(ev, dragDom, undefined, undefined, startMatrixInfo);
1686
+ offsetPointX = offsetXy.x;
1687
+ offsetPointY = offsetXy.y;
1688
+ startPointXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle, startMatrixInfo);
1689
+ originW =
1690
+ dragDomRect.width;
1691
+ originH =
1692
+ dragDomRect.height;
1693
+ if (dragDom instanceof SVGGElement || dragDom instanceof SVGSVGElement) {
1694
+ let bbox = dragDom.getBBox();
1695
+ offsetPointX += bbox.x;
1696
+ offsetPointY += bbox.y;
1697
+ }
1698
+ if (startMatrixInfo.angle != 0) {
1699
+ let { sx, sy } = getCenterXy(dragDom);
1700
+ offsetPointX = startPointXy.x - sx;
1701
+ offsetPointY = startPointXy.y - sy;
1702
+ }
1703
+ if (group) {
1704
+ let i = -1;
1705
+ each(DRAGGER_GROUPS[group], (el) => {
1706
+ const z = parseInt(currentCStyle.zIndex) || 0;
1707
+ if (z > i)
1708
+ i = z;
1709
+ });
1710
+ zIndex = i + 1;
1711
+ }
1712
+ const grid = opts.grid;
1713
+ if (isArray(grid)) {
1714
+ gridX = grid[0];
1715
+ gridY = grid[1];
1716
+ }
1717
+ else if (isNumber(grid)) {
1718
+ gridX = gridY = grid;
1719
+ }
1720
+ if (snapOn) {
1721
+ snappable = map((container || document).querySelectorAll(snapOn), (el) => {
1722
+ const { x, y, w, h } = getRectInContainer(el, offsetParent);
1723
+ return {
1724
+ x1: x,
1725
+ y1: y,
1726
+ x2: x + w,
1727
+ y2: y + h,
1728
+ el: el,
1729
+ };
1730
+ });
1731
+ }
1732
+ if (inContainer) {
1733
+ maxX =
1734
+ container.scrollWidth - originW / startMatrixInfo.scale;
1735
+ maxY =
1736
+ container.scrollHeight - originH / startMatrixInfo.scale;
1737
+ }
1738
+ if (maxX < 0)
1739
+ maxX = 0;
1740
+ if (maxY < 0)
1741
+ maxY = 0;
1577
1742
  if (ghost) {
1578
1743
  if (isFunction(ghost)) {
1579
- copyNode = ghost(dragDom);
1744
+ ghostNode = ghost(dragDom);
1580
1745
  }
1581
1746
  else {
1582
- copyNode = dragDom.cloneNode(true);
1583
- copyNode.style.opacity = "0.3";
1584
- copyNode.style.pointerEvents = "none";
1585
- copyNode.style.position = "absolute";
1747
+ ghostNode = dragDom.cloneNode(true);
1748
+ ghostNode.style.opacity = "0.3";
1749
+ ghostNode.style.pointerEvents = "none";
1750
+ ghostNode.style.position = "absolute";
1586
1751
  }
1587
- copyNode.style.zIndex = zIndex + '';
1752
+ ghostNode.style.zIndex = zIndex + "";
1588
1753
  if (ghostClass) {
1589
- copyNode.classList.add(...compact(split(ghostClass, ' ')));
1754
+ ghostNode.classList.add(...compact(split(ghostClass, " ")));
1590
1755
  }
1591
- copyNode.classList.add(...compact(split(classes, ' ')));
1592
- copyNode.classList.toggle(CLASS_DRAGGABLE_GHOST, true);
1593
- (_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(copyNode);
1594
- transform = wrapper(copyNode);
1595
- onClone && onClone({ clone: copyNode }, ev);
1756
+ ghostNode.classList.add(...compact(split(classes, " ")));
1757
+ ghostNode.classList.toggle(CLASS_DRAGGABLE_GHOST, true);
1758
+ let ghostParent = ghostTo ? (isString(ghostTo) ? document.querySelector(ghostTo) : ghostTo) : dragDom.parentNode;
1759
+ ghostParent === null || ghostParent === void 0 ? void 0 : ghostParent.appendChild(ghostNode);
1760
+ transform = wrapper(ghostNode, opts.useTransform);
1761
+ onClone && onClone({ clone: ghostNode }, ev);
1596
1762
  }
1597
1763
  else {
1598
- transform = wrapper(dragDom);
1764
+ transform = wrapper(dragDom, opts.useTransform);
1599
1765
  }
1600
- dragDom.classList.add(...compact(split(classes, ' ')));
1601
- if (!copyNode)
1602
- dragDom.style.zIndex = zIndex + '';
1766
+ dragDom.classList.add(...compact(split(classes, " ")));
1767
+ if (!ghostNode)
1768
+ dragDom.style.zIndex = zIndex + "";
1603
1769
  dragDom.classList.toggle(CLASS_DRAGGABLE_ACTIVE, true);
1604
- onStart && onStart({ draggable: dragDom, x: currentXy.x, y: currentXy.y, transform }, ev);
1605
- const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
1770
+ onStart &&
1771
+ onStart({ draggable: dragDom, x: startPointXy.x, y: startPointXy.y, transform }, ev);
1772
+ const customEv = new Event("uii-dragactive", {
1773
+ bubbles: true,
1774
+ cancelable: false,
1775
+ });
1606
1776
  dragDom.dispatchEvent(customEv);
1607
1777
  });
1608
1778
  onPointerMove((args) => {
1609
1779
  const { ev, pointX, pointY, offX, offY } = args;
1610
- const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1611
- let newX = currentXy.x;
1612
- let newY = currentXy.y;
1780
+ let newX = startPointXy.x + offX;
1781
+ let newY = startPointXy.y + offY;
1613
1782
  if (scroll) {
1614
1783
  const lX = pointX - offsetParentRect.x;
1615
1784
  const lY = pointY - offsetParentRect.y;
@@ -1619,9 +1788,7 @@ class Draggable extends Uii {
1619
1788
  toTop = lY < EDGE_THRESHOLD;
1620
1789
  toRight = rX < EDGE_THRESHOLD;
1621
1790
  toBottom = rY < EDGE_THRESHOLD;
1622
- if (toLeft || toTop
1623
- ||
1624
- toRight || toBottom) {
1791
+ if (toLeft || toTop || toRight || toBottom) {
1625
1792
  if (!timer) {
1626
1793
  timer = setInterval(() => {
1627
1794
  if (toLeft) {
@@ -1653,17 +1820,17 @@ class Draggable extends Uii {
1653
1820
  y = ((y / gridY) >> 0) * gridY;
1654
1821
  }
1655
1822
  if (inContainer) {
1656
- if (originOffX + x < minX) {
1657
- x = -0;
1823
+ if (x < minX) {
1824
+ x = 0;
1658
1825
  }
1659
- if (originOffY + y < minY) {
1660
- y = -0;
1826
+ if (y < minY) {
1827
+ y = 0;
1661
1828
  }
1662
- if (originOffX + x > maxX) {
1663
- x = maxX - originOffX;
1829
+ if (x > maxX) {
1830
+ x = maxX;
1664
1831
  }
1665
- if (originOffY + y > maxY) {
1666
- y = maxY - originOffY;
1832
+ if (y > maxY) {
1833
+ y = maxY;
1667
1834
  }
1668
1835
  }
1669
1836
  let canDrag = true;
@@ -1736,7 +1903,7 @@ class Draggable extends Uii {
1736
1903
  if (onSnap && lastSnapping !== lastSnapDirX + "" + lastSnapDirY) {
1737
1904
  setTimeout(() => {
1738
1905
  onSnap({
1739
- el: copyNode || dragDom,
1906
+ el: ghostNode || dragDom,
1740
1907
  targetH: targetX,
1741
1908
  targetV: targetY,
1742
1909
  dirH: snapDirX,
@@ -1758,7 +1925,7 @@ class Draggable extends Uii {
1758
1925
  oy: offY,
1759
1926
  x: x,
1760
1927
  y: y,
1761
- transform
1928
+ transform,
1762
1929
  }, ev) === false) {
1763
1930
  canDrag = false;
1764
1931
  endX = x;
@@ -1780,7 +1947,7 @@ class Draggable extends Uii {
1780
1947
  }
1781
1948
  });
1782
1949
  onPointerEnd((args) => {
1783
- var _a, _b;
1950
+ var _a;
1784
1951
  const { ev, currentStyle } = args;
1785
1952
  if (scroll) {
1786
1953
  if (timer) {
@@ -1788,25 +1955,32 @@ class Draggable extends Uii {
1788
1955
  timer = null;
1789
1956
  }
1790
1957
  }
1791
- dragDom.classList.remove(...compact(split(classes, ' ')));
1958
+ dragDom.classList.remove(...compact(split(classes, " ")));
1792
1959
  currentStyle.zIndex = originalZIndex;
1793
1960
  dragDom.classList.remove(CLASS_DRAGGABLE_ACTIVE);
1794
1961
  let moveToGhost = true;
1795
1962
  if (onEnd) {
1796
- moveToGhost = onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) === false ? false : true;
1963
+ moveToGhost =
1964
+ onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) ===
1965
+ false
1966
+ ? false
1967
+ : true;
1797
1968
  }
1798
- const customEv = new Event("uii-dragdeactive", { "bubbles": true, "cancelable": false });
1969
+ const customEv = new Event("uii-dragdeactive", {
1970
+ bubbles: true,
1971
+ cancelable: false,
1972
+ });
1799
1973
  dragDom.dispatchEvent(customEv);
1800
1974
  if (ghost) {
1801
- ((_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.contains(copyNode)) && ((_b = dragDom.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(copyNode));
1975
+ (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
1802
1976
  if (moveToGhost !== false) {
1803
- wrapper(dragDom).moveTo(transform.x, transform.y);
1977
+ wrapper(dragDom, opts.useTransform).moveTo(transform.x, transform.y);
1804
1978
  }
1805
1979
  }
1806
1980
  });
1807
1981
  }, {
1808
1982
  threshold: this.opts.threshold || 0,
1809
- lockPage: true
1983
+ lockPage: true,
1810
1984
  });
1811
1985
  }
1812
1986
  onOptionChanged(opts) {
@@ -1835,10 +2009,10 @@ _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Dra
1835
2009
  const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
1836
2010
  ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
1837
2011
  if (!isUndefined(this.opts.cursor)) {
1838
- el.style.cursor = this.opts.cursor.default || 'move';
2012
+ el.style.cursor = this.opts.cursor.default || "move";
1839
2013
  if (isDefined(this.opts.cursor.over)) {
1840
2014
  el.dataset.cursorOver = this.opts.cursor.over;
1841
- el.dataset.cursorActive = this.opts.cursor.active || 'move';
2015
+ el.dataset.cursorActive = this.opts.cursor.active || "move";
1842
2016
  }
1843
2017
  }
1844
2018
  });
@@ -1970,7 +2144,6 @@ function newDroppable(els, opts) {
1970
2144
  return new Droppable(els, opts);
1971
2145
  }
1972
2146
 
1973
- const THRESHOLD$2 = 2;
1974
2147
  const CLASS_ROTATABLE = "uii-rotatable";
1975
2148
  const CLASS_ROTATABLE_HANDLE = "uii-rotatable-handle";
1976
2149
  const CLASS_ROTATABLE_ACTIVE = "uii-rotatable-active";
@@ -2022,23 +2195,20 @@ function bindHandle(uiik, handle, el, opts) {
2022
2195
  let startOy = 0;
2023
2196
  let startDeg = 0;
2024
2197
  let container;
2198
+ let startPointXy;
2025
2199
  onPointerStart(function (args) {
2026
2200
  const { ev } = args;
2027
2201
  const { w, h } = getStyleSize(el);
2028
- const { originX, originY } = parseOxy(opts.ox, opts.oy, w, h);
2202
+ const { originX, originY } = parseOxy(opts.ox, opts.oy, w, h, el);
2029
2203
  startOx = originX;
2030
2204
  startOy = originY;
2031
- const { x, y, ox, oy } = el instanceof SVGGraphicsElement
2032
- ? getCenterXySVG(el, startOx, startOy)
2033
- : getCenterXy(el, startOx, startOy);
2034
- (centerX = x), (centerY = y);
2035
- (startOx = ox), (startOy = oy);
2036
- container =
2037
- el instanceof SVGGraphicsElement
2038
- ? el.ownerSVGElement : el.parentElement;
2039
- const currentXy = getPointInContainer(ev, container);
2205
+ let centerXy = getRectCenter(el);
2206
+ centerX = centerXy.x;
2207
+ centerY = centerXy.y;
2208
+ container = el.parentElement;
2209
+ startPointXy = getPointInContainer(ev, container);
2040
2210
  startDeg =
2041
- Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD +
2211
+ Math.atan2(startPointXy.y - centerY, startPointXy.x - centerX) * ONE_RAD +
2042
2212
  90;
2043
2213
  if (startDeg < 0)
2044
2214
  startDeg = 360 + startDeg;
@@ -2048,10 +2218,11 @@ function bindHandle(uiik, handle, el, opts) {
2048
2218
  onStart && onStart({ deg, cx: centerX, cy: centerY }, ev);
2049
2219
  });
2050
2220
  onPointerMove((args) => {
2051
- const { ev } = args;
2052
- const currentXy = getPointInContainer(ev, container);
2221
+ const { ev, offX, offY } = args;
2222
+ let newX = startPointXy.x + offX;
2223
+ let newY = startPointXy.y + offY;
2053
2224
  deg =
2054
- Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD +
2225
+ Math.atan2(newY - centerY, newX - centerX) * ONE_RAD +
2055
2226
  90 -
2056
2227
  startDeg;
2057
2228
  onRotate &&
@@ -2071,7 +2242,7 @@ function bindHandle(uiik, handle, el, opts) {
2071
2242
  onEnd && onEnd({ deg }, ev);
2072
2243
  });
2073
2244
  }, {
2074
- threshold: THRESHOLD$2,
2245
+ threshold: THRESHOLD,
2075
2246
  lockPage: true,
2076
2247
  });
2077
2248
  }
@@ -2177,7 +2348,6 @@ var _Selectable_instances, _Selectable__detector, _Selectable__lastSelected, _Se
2177
2348
  const CLASS_SELECTOR = "uii-selector";
2178
2349
  const CLASS_SELECTING = "uii-selecting";
2179
2350
  const CLASS_SELECTED = "uii-selected";
2180
- const THRESHOLD$1 = 2;
2181
2351
  class Selectable extends Uii {
2182
2352
  constructor(container, opts) {
2183
2353
  super(container, assign({
@@ -2242,10 +2412,9 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
2242
2412
  if (onPointerDown && onPointerDown(ev) === false)
2243
2413
  return true;
2244
2414
  let originPos = "";
2245
- let matrixInfo = getMatrixInfo(currentTarget);
2246
- const startxy = getPointInContainer(ev, con, currentRect, currentCStyle, matrixInfo);
2247
- let hitPosX = startxy.x;
2248
- let hitPosY = startxy.y;
2415
+ let startPointXy = getPointInContainer(ev, con, currentRect, currentCStyle);
2416
+ let hitPosX = startPointXy.x;
2417
+ let hitPosY = startPointXy.y;
2249
2418
  const style = selector.style;
2250
2419
  let selection = [];
2251
2420
  let lastSelection = [];
@@ -2269,13 +2438,9 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
2269
2438
  style.display = 'block';
2270
2439
  onStart && onStart({ selection: __classPrivateFieldGet(that, _Selectable__lastSelected, "f"), selectable: con }, ev);
2271
2440
  });
2272
- onPointerMove((args) => {
2273
- const { ev } = args;
2274
- const currentXy = getPointInContainer(ev, currentTarget, currentRect, currentCStyle, matrixInfo);
2275
- let pointX = currentXy.x;
2276
- let pointY = currentXy.y;
2277
- let offX = pointX - hitPosX;
2278
- let offY = pointY - hitPosY;
2441
+ onPointerMove(({ ev, offX, offY }) => {
2442
+ let pointX = startPointXy.x + offX;
2443
+ let pointY = startPointXy.y + offY;
2279
2444
  if (scroll) {
2280
2445
  const ltX = ev.clientX - currentRect.x;
2281
2446
  const ltY = ev.clientY - currentRect.y;
@@ -2380,7 +2545,7 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
2380
2545
  onEnd({ selection, selectable: con }, ev);
2381
2546
  });
2382
2547
  }, {
2383
- threshold: THRESHOLD$1,
2548
+ threshold: THRESHOLD,
2384
2549
  lockPage: true
2385
2550
  });
2386
2551
  };
@@ -2394,7 +2559,6 @@ const CLASS_SORTABLE_CONTAINER = "uii-sortable-container";
2394
2559
  const CLASS_SORTABLE_GHOST = "uii-sortable-ghost";
2395
2560
  const CLASS_SORTABLE_ACTIVE = "uii-sortable-active";
2396
2561
  const ATTR_SORTABLE_ACTIVE = "uii-sortable-active";
2397
- const THRESHOLD = 2;
2398
2562
  class Sortable extends Uii {
2399
2563
  constructor(container, opts) {
2400
2564
  super(container, merge({
@@ -2770,7 +2934,7 @@ function newSortable(container, opts) {
2770
2934
  return new Sortable(container, opts);
2771
2935
  }
2772
2936
 
2773
- var version = "1.3.0-beta.4";
2937
+ var version = "1.3.2";
2774
2938
  var repository = {
2775
2939
  type: "git",
2776
2940
  url: "https://github.com/holyhigh2/uiik"
@@ -2803,4 +2967,4 @@ var index = {
2803
2967
  newSortable
2804
2968
  };
2805
2969
 
2806
- export { CollisionDetector, DRAGGING_RULE, Draggable, Droppable, EDGE_THRESHOLD, ONE_ANG, ONE_RAD, Resizable, Rotatable, Selectable, Sortable, Splittable, Uii, UiiTransform, VERSION, calcVertex, index as default, getBox, getCenterXy, getCenterXySVG, getMatrixInfo, getPointInContainer, getPointOffset, getRectInContainer, getStyleSize, getStyleXy, getTranslate, getVertex, isSVGEl, lockPage, moveBy, moveTo, newCollisionDetector, newDraggable, newDroppable, newResizable, newRotatable, newSelectable, newSortable, newSplittable, parseOxy, restoreCursor, rotateTo, saveCursor, setCursor, unlockPage, wrapper };
2970
+ export { CollisionDetector, DRAGGING_RULE, Draggable, Droppable, EDGE_THRESHOLD, ONE_ANG, ONE_RAD, Resizable, Rotatable, Selectable, Sortable, Splittable, THRESHOLD, Uii, UiiTransform, VERSION, calcVertex, index as default, getBox, getCenterXy, getCenterXySVG, getMatrixInfo, getPointInContainer, getPointOffset, getRectCenter, getRectInContainer, getStyleSize, getStyleXy, getTranslate, getVertex, isSVGEl, lockPage, moveBy, moveTo, newCollisionDetector, newDraggable, newDroppable, newResizable, newRotatable, newSelectable, newSortable, newSplittable, normalizeVector, parseOxy, restoreCursor, rotateTo, saveCursor, setCursor, transformMoveTo, unlockPage, wrapper };