uiik 1.3.7 → 1.4.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/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * uiik v1.3.7
2
+ * uiik v1.4.0
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2025 @holyhigh2 may be freely distributed under the MIT license
@@ -7,11 +7,11 @@
7
7
  import { find, map, toArray, each, reject, includes, some, flatMap, size } from 'myfx/collection';
8
8
  import { isDefined, isNumber, isNaN, isString, isArrayLike, isElement, isEmpty, isBlank, isArray, isFunction, isBoolean, isUndefined } from 'myfx/is';
9
9
  import { get, assign, merge } from 'myfx/object';
10
+ import { isElement as isElement$1, filter, last } from 'myfx';
10
11
  import { compact, findIndex } from 'myfx/array';
11
12
  import { split, test } from 'myfx/string';
12
13
  import { closest } from 'myfx/tree';
13
14
  import { alphaId } from 'myfx/utils';
14
- import { filter, last } from 'myfx';
15
15
 
16
16
  /******************************************************************************
17
17
  Copyright (c) Microsoft Corporation.
@@ -978,6 +978,7 @@ function newSplittable(container, opts) {
978
978
  const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
979
979
  const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
980
980
  const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
981
+ const CLASS_RESIZABLE_GHOST = "uii-resizable-ghost";
981
982
  const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
982
983
  class Resizable extends Uii {
983
984
  constructor(els, opts) {
@@ -1110,11 +1111,9 @@ class Resizable extends Uii {
1110
1111
  }
1111
1112
  if (ghostNode) {
1112
1113
  if (ghostClass) {
1113
- ghostNode.className =
1114
- ghostNode.className.replace(ghostClass, "") +
1115
- " " +
1116
- ghostClass;
1114
+ ghostNode.classList.add(ghostClass);
1117
1115
  }
1116
+ ghostNode.classList.toggle(CLASS_RESIZABLE_GHOST, true);
1118
1117
  (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
1119
1118
  transform = wrapper(ghostNode);
1120
1119
  onClone && onClone({ clone: ghostNode }, ev);
@@ -1176,7 +1175,7 @@ class Resizable extends Uii {
1176
1175
  }
1177
1176
  startPointXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle, matrixInfo);
1178
1177
  onStart &&
1179
- onStart.call(uiik, { w: originW, h: originH, transform }, ev);
1178
+ onStart.call(uiik, { w: originW, h: originH, transform, handle, ghost: ghostNode }, ev);
1180
1179
  });
1181
1180
  onPointerMove((args) => {
1182
1181
  const { ev, offX, offY } = args;
@@ -1397,39 +1396,13 @@ class Resizable extends Uii {
1397
1396
  break;
1398
1397
  }
1399
1398
  if (aspectRatio) {
1400
- if (changeW) {
1401
- style.width = w + "px";
1402
- style.height = w / aspectRatio + "px";
1403
- }
1404
1399
  if (changeH && dir !== "sw") {
1405
1400
  if (dir === "nw") {
1406
1401
  y = originY - w / aspectRatio + originH;
1407
1402
  }
1408
- else {
1409
- style.width = h * aspectRatio + "px";
1410
- style.height = h + "px";
1411
- }
1412
1403
  }
1413
1404
  }
1414
- else {
1415
- if (changeW) {
1416
- resize(transform, style, w);
1417
- }
1418
- if (changeH) {
1419
- resize(transform, style, undefined, h);
1420
- }
1421
- }
1422
- if (changeY) {
1423
- transform.moveTo(x, y + sY);
1424
- }
1425
- if (changeX) {
1426
- transform.moveTo(x + sX, y);
1427
- }
1428
- lastX = x;
1429
- lastY = y;
1430
- console.log(lastX, lastY);
1431
- currentW = w;
1432
- currentH = h;
1405
+ let canResize = true;
1433
1406
  if (onResize && onResize.call) {
1434
1407
  onResize.call;
1435
1408
  const panelRect = getRectInContainer(panel, panel.parentElement, matrixInfo);
@@ -1437,7 +1410,7 @@ class Resizable extends Uii {
1437
1410
  let centerY = Math.round(panelRect.y + panelRect.h / 2);
1438
1411
  let sx = Math.round(centerX - originW / 2);
1439
1412
  let sy = Math.round(centerY - originH / 2);
1440
- onResize.call(uiik, {
1413
+ canResize = onResize.call(uiik, {
1441
1414
  w,
1442
1415
  h,
1443
1416
  ow: w - originW,
@@ -1449,20 +1422,68 @@ class Resizable extends Uii {
1449
1422
  sy: sy,
1450
1423
  deg: matrixInfo.angle,
1451
1424
  transform,
1425
+ handle
1452
1426
  }, ev);
1453
1427
  }
1428
+ if (canResize !== false) {
1429
+ if (aspectRatio) {
1430
+ if (changeW) {
1431
+ style.width = w + "px";
1432
+ style.height = w / aspectRatio + "px";
1433
+ }
1434
+ if (changeH && dir !== "sw" && dir !== "nw") {
1435
+ style.width = h * aspectRatio + "px";
1436
+ style.height = h + "px";
1437
+ }
1438
+ }
1439
+ else {
1440
+ if (changeW) {
1441
+ resize(transform, style, w);
1442
+ }
1443
+ if (changeH) {
1444
+ resize(transform, style, undefined, h);
1445
+ }
1446
+ }
1447
+ if (changeY) {
1448
+ transform.moveTo(x, y + sY);
1449
+ }
1450
+ if (changeX) {
1451
+ transform.moveTo(x + sX, y);
1452
+ }
1453
+ }
1454
+ lastX = x;
1455
+ lastY = y;
1456
+ currentW = w;
1457
+ currentH = h;
1454
1458
  });
1455
1459
  onPointerEnd((args) => {
1456
1460
  var _a, _b;
1457
1461
  const { ev } = args;
1462
+ let doDefault = true;
1463
+ handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1464
+ let ghostLeft = '0';
1465
+ let ghostTop = '0';
1466
+ let ghostWidth = '0';
1467
+ let ghostHeight = '0';
1458
1468
  if (ghost && ghostNode) {
1459
- panelStyle.left = ghostNode.style.left;
1460
- panelStyle.top = ghostNode.style.top;
1461
- transform = wrapper(panel);
1462
- transform.moveTo((lastX + sX), (lastY + sY));
1469
+ ghostLeft = ghostNode.style.left;
1470
+ ghostTop = ghostNode.style.top;
1471
+ ghostWidth = ghostNode.style.width;
1472
+ ghostHeight = ghostNode.style.height;
1463
1473
  ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) &&
1464
1474
  ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
1465
- resize(transform, panelStyle, parseFloat(ghostNode.style.width), parseFloat(ghostNode.style.height));
1475
+ }
1476
+ if (onEnd) {
1477
+ doDefault = onEnd.call(uiik, { w: currentW, h: currentH, transform, handle, ghost: ghostNode }, ev);
1478
+ }
1479
+ if (doDefault === false)
1480
+ return;
1481
+ if (ghost && ghostNode) {
1482
+ panelStyle.left = ghostLeft;
1483
+ panelStyle.top = ghostTop;
1484
+ transform = wrapper(panel);
1485
+ transform.moveTo((lastX + sX), (lastY + sY));
1486
+ resize(transform, panelStyle, parseFloat(ghostWidth), parseFloat(ghostHeight));
1466
1487
  }
1467
1488
  if (setOrigin)
1468
1489
  panel.style.transformOrigin = originalTransformOrigin;
@@ -1483,9 +1504,6 @@ class Resizable extends Uii {
1483
1504
  }
1484
1505
  }
1485
1506
  }
1486
- handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1487
- onEnd &&
1488
- onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
1489
1507
  });
1490
1508
  }, {
1491
1509
  threshold: THRESHOLD,
@@ -1502,6 +1520,15 @@ class Resizable extends Uii {
1502
1520
  else if (isFunction(handleStr)) {
1503
1521
  handles = handleStr(panel);
1504
1522
  }
1523
+ else if (isElement$1(handleStr)) {
1524
+ handles = [handleStr];
1525
+ }
1526
+ else if (isArrayLike(handleStr)) {
1527
+ let eles = filter(handleStr, h => isElement$1(h));
1528
+ if (eles.length > 0) {
1529
+ handles = eles;
1530
+ }
1531
+ }
1505
1532
  if (!handles) {
1506
1533
  console.error('Can not find handles in "' + panel.outerHTML + '"');
1507
1534
  return;
@@ -2973,7 +3000,7 @@ function newSortable(container, opts) {
2973
3000
  return new Sortable(container, opts);
2974
3001
  }
2975
3002
 
2976
- var version = "1.3.7";
3003
+ var version = "1.4.0";
2977
3004
  var repository = {
2978
3005
  type: "git",
2979
3006
  url: "https://github.com/holyhigh2/uiik"
package/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * uiik v1.3.7
2
+ * uiik v1.4.0
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2025 @holyhigh2 may be freely distributed under the MIT license
6
6
  */
7
7
  (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/collection'), require('myfx/is'), require('myfx/object'), require('myfx/array'), require('myfx/string'), require('myfx/tree'), require('myfx/utils'), require('myfx')) :
9
- typeof define === 'function' && define.amd ? define(['exports', 'myfx/collection', 'myfx/is', 'myfx/object', 'myfx/array', 'myfx/string', 'myfx/tree', 'myfx/utils', 'myfx'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.collection, global.is, global.object, global.array, global.string, global.tree, global.utils, global.myfx));
11
- })(this, (function (exports, collection, is, object, array, string, tree, utils, myfx) { 'use strict';
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/collection'), require('myfx/is'), require('myfx/object'), require('myfx'), require('myfx/array'), require('myfx/string'), require('myfx/tree'), require('myfx/utils')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', 'myfx/collection', 'myfx/is', 'myfx/object', 'myfx', 'myfx/array', 'myfx/string', 'myfx/tree', 'myfx/utils'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.collection, global.is, global.object, global.myfx, global.array, global.string, global.tree, global.utils));
11
+ })(this, (function (exports, collection, is, object, myfx, array, string, tree, utils) { 'use strict';
12
12
 
13
13
  /******************************************************************************
14
14
  Copyright (c) Microsoft Corporation.
@@ -975,6 +975,7 @@
975
975
  const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
976
976
  const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
977
977
  const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
978
+ const CLASS_RESIZABLE_GHOST = "uii-resizable-ghost";
978
979
  const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
979
980
  class Resizable extends Uii {
980
981
  constructor(els, opts) {
@@ -1107,11 +1108,9 @@
1107
1108
  }
1108
1109
  if (ghostNode) {
1109
1110
  if (ghostClass) {
1110
- ghostNode.className =
1111
- ghostNode.className.replace(ghostClass, "") +
1112
- " " +
1113
- ghostClass;
1111
+ ghostNode.classList.add(ghostClass);
1114
1112
  }
1113
+ ghostNode.classList.toggle(CLASS_RESIZABLE_GHOST, true);
1115
1114
  (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
1116
1115
  transform = wrapper(ghostNode);
1117
1116
  onClone && onClone({ clone: ghostNode }, ev);
@@ -1173,7 +1172,7 @@
1173
1172
  }
1174
1173
  startPointXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle, matrixInfo);
1175
1174
  onStart &&
1176
- onStart.call(uiik, { w: originW, h: originH, transform }, ev);
1175
+ onStart.call(uiik, { w: originW, h: originH, transform, handle, ghost: ghostNode }, ev);
1177
1176
  });
1178
1177
  onPointerMove((args) => {
1179
1178
  const { ev, offX, offY } = args;
@@ -1394,39 +1393,13 @@
1394
1393
  break;
1395
1394
  }
1396
1395
  if (aspectRatio) {
1397
- if (changeW) {
1398
- style.width = w + "px";
1399
- style.height = w / aspectRatio + "px";
1400
- }
1401
1396
  if (changeH && dir !== "sw") {
1402
1397
  if (dir === "nw") {
1403
1398
  y = originY - w / aspectRatio + originH;
1404
1399
  }
1405
- else {
1406
- style.width = h * aspectRatio + "px";
1407
- style.height = h + "px";
1408
- }
1409
1400
  }
1410
1401
  }
1411
- else {
1412
- if (changeW) {
1413
- resize(transform, style, w);
1414
- }
1415
- if (changeH) {
1416
- resize(transform, style, undefined, h);
1417
- }
1418
- }
1419
- if (changeY) {
1420
- transform.moveTo(x, y + sY);
1421
- }
1422
- if (changeX) {
1423
- transform.moveTo(x + sX, y);
1424
- }
1425
- lastX = x;
1426
- lastY = y;
1427
- console.log(lastX, lastY);
1428
- currentW = w;
1429
- currentH = h;
1402
+ let canResize = true;
1430
1403
  if (onResize && onResize.call) {
1431
1404
  onResize.call;
1432
1405
  const panelRect = getRectInContainer(panel, panel.parentElement, matrixInfo);
@@ -1434,7 +1407,7 @@
1434
1407
  let centerY = Math.round(panelRect.y + panelRect.h / 2);
1435
1408
  let sx = Math.round(centerX - originW / 2);
1436
1409
  let sy = Math.round(centerY - originH / 2);
1437
- onResize.call(uiik, {
1410
+ canResize = onResize.call(uiik, {
1438
1411
  w,
1439
1412
  h,
1440
1413
  ow: w - originW,
@@ -1446,20 +1419,68 @@
1446
1419
  sy: sy,
1447
1420
  deg: matrixInfo.angle,
1448
1421
  transform,
1422
+ handle
1449
1423
  }, ev);
1450
1424
  }
1425
+ if (canResize !== false) {
1426
+ if (aspectRatio) {
1427
+ if (changeW) {
1428
+ style.width = w + "px";
1429
+ style.height = w / aspectRatio + "px";
1430
+ }
1431
+ if (changeH && dir !== "sw" && dir !== "nw") {
1432
+ style.width = h * aspectRatio + "px";
1433
+ style.height = h + "px";
1434
+ }
1435
+ }
1436
+ else {
1437
+ if (changeW) {
1438
+ resize(transform, style, w);
1439
+ }
1440
+ if (changeH) {
1441
+ resize(transform, style, undefined, h);
1442
+ }
1443
+ }
1444
+ if (changeY) {
1445
+ transform.moveTo(x, y + sY);
1446
+ }
1447
+ if (changeX) {
1448
+ transform.moveTo(x + sX, y);
1449
+ }
1450
+ }
1451
+ lastX = x;
1452
+ lastY = y;
1453
+ currentW = w;
1454
+ currentH = h;
1451
1455
  });
1452
1456
  onPointerEnd((args) => {
1453
1457
  var _a, _b;
1454
1458
  const { ev } = args;
1459
+ let doDefault = true;
1460
+ handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1461
+ let ghostLeft = '0';
1462
+ let ghostTop = '0';
1463
+ let ghostWidth = '0';
1464
+ let ghostHeight = '0';
1455
1465
  if (ghost && ghostNode) {
1456
- panelStyle.left = ghostNode.style.left;
1457
- panelStyle.top = ghostNode.style.top;
1458
- transform = wrapper(panel);
1459
- transform.moveTo((lastX + sX), (lastY + sY));
1466
+ ghostLeft = ghostNode.style.left;
1467
+ ghostTop = ghostNode.style.top;
1468
+ ghostWidth = ghostNode.style.width;
1469
+ ghostHeight = ghostNode.style.height;
1460
1470
  ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) &&
1461
1471
  ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
1462
- resize(transform, panelStyle, parseFloat(ghostNode.style.width), parseFloat(ghostNode.style.height));
1472
+ }
1473
+ if (onEnd) {
1474
+ doDefault = onEnd.call(uiik, { w: currentW, h: currentH, transform, handle, ghost: ghostNode }, ev);
1475
+ }
1476
+ if (doDefault === false)
1477
+ return;
1478
+ if (ghost && ghostNode) {
1479
+ panelStyle.left = ghostLeft;
1480
+ panelStyle.top = ghostTop;
1481
+ transform = wrapper(panel);
1482
+ transform.moveTo((lastX + sX), (lastY + sY));
1483
+ resize(transform, panelStyle, parseFloat(ghostWidth), parseFloat(ghostHeight));
1463
1484
  }
1464
1485
  if (setOrigin)
1465
1486
  panel.style.transformOrigin = originalTransformOrigin;
@@ -1480,9 +1501,6 @@
1480
1501
  }
1481
1502
  }
1482
1503
  }
1483
- handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1484
- onEnd &&
1485
- onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
1486
1504
  });
1487
1505
  }, {
1488
1506
  threshold: THRESHOLD,
@@ -1499,6 +1517,15 @@
1499
1517
  else if (is.isFunction(handleStr)) {
1500
1518
  handles = handleStr(panel);
1501
1519
  }
1520
+ else if (myfx.isElement(handleStr)) {
1521
+ handles = [handleStr];
1522
+ }
1523
+ else if (is.isArrayLike(handleStr)) {
1524
+ let eles = myfx.filter(handleStr, h => myfx.isElement(h));
1525
+ if (eles.length > 0) {
1526
+ handles = eles;
1527
+ }
1528
+ }
1502
1529
  if (!handles) {
1503
1530
  console.error('Can not find handles in "' + panel.outerHTML + '"');
1504
1531
  return;
@@ -2970,7 +2997,7 @@
2970
2997
  return new Sortable(container, opts);
2971
2998
  }
2972
2999
 
2973
- var version = "1.3.7";
3000
+ var version = "1.4.0";
2974
3001
  var repository = {
2975
3002
  type: "git",
2976
3003
  url: "https://github.com/holyhigh2/uiik"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uiik",
3
- "version": "1.3.7",
3
+ "version": "1.4.0",
4
4
  "description": "A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
package/types.d.ts CHANGED
@@ -25,7 +25,7 @@ export type ResizableOptions = {
25
25
  minSize?: number | Array<number>;
26
26
  maxSize?: number | Array<number>;
27
27
  aspectRatio?: number;
28
- ghost?: boolean | Function;
28
+ ghost?: ((panel: HTMLElement | SVGGraphicsElement) => HTMLElement | SVGGraphicsElement) | boolean;
29
29
  ghostClass?: string;
30
30
  ox?: number | string;
31
31
  oy?: number | string;
@@ -34,6 +34,8 @@ export type ResizableOptions = {
34
34
  w: number;
35
35
  h: number;
36
36
  transform: UiiTransform;
37
+ handle: HTMLElement | SVGGraphicsElement;
38
+ ghost: HTMLElement | SVGGraphicsElement;
37
39
  }, event: MouseEvent) => void;
38
40
  onResize?: (data: {
39
41
  w: number;
@@ -46,14 +48,17 @@ export type ResizableOptions = {
46
48
  y: number;
47
49
  }>;
48
50
  transform: UiiTransform;
49
- }, event: MouseEvent) => void;
51
+ handle: HTMLElement | SVGGraphicsElement;
52
+ }, event: MouseEvent) => boolean | void;
50
53
  onEnd?: (data: {
51
54
  w: number;
52
55
  h: number;
53
56
  transform: UiiTransform;
54
- }, event: MouseEvent) => void;
57
+ handle: HTMLElement | SVGGraphicsElement;
58
+ ghost: HTMLElement | SVGGraphicsElement;
59
+ }, event: MouseEvent) => boolean | void;
55
60
  onClone?: (data: {
56
- clone: HTMLElement;
61
+ clone: HTMLElement | SVGGraphicsElement;
57
62
  }, event: MouseEvent) => void;
58
63
  };
59
64
  export type SplittableOptions = {
@@ -97,7 +102,7 @@ export type DraggableOptions = {
97
102
  handle?: string;
98
103
  filter?: string;
99
104
  droppable?: (() => NodeList | HTMLCollection | HTMLElement[]) | string | HTMLElement | HTMLElement[];
100
- ghost?: ((el: HTMLElement) => HTMLElement) | boolean;
105
+ ghost?: ((panel: HTMLElement | SVGGraphicsElement) => HTMLElement | SVGGraphicsElement) | boolean;
101
106
  ghostClass?: string;
102
107
  ghostTo?: string | HTMLElement;
103
108
  direction?: "v" | "h";