uiik 1.0.2 → 1.0.4

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.0.2
2
+ * uiik v1.0.4
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2023 @holyhigh2 may be freely distributed under the MIT license
6
6
  */
7
- import { isArrayLike, isString, map, isElement, toArray, each, assign, reject, includes, isArray, isEmpty, call, isNumber, isFunction, isDefined, isUndefined, closest, some, compact, split, test, flatMap } from '@holyhigh/func.js';
7
+ import { isArrayLike, isString, map, isElement, toArray, each, assign, find, reject, includes, isArray, isEmpty, call, isNumber, isFunction, isDefined, isUndefined, closest, some, compact, split, test, flatMap } from '@holyhigh/func.js';
8
8
 
9
9
  /******************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
@@ -133,10 +133,6 @@ class Uii {
133
133
  _Uii_listeners = new WeakMap();
134
134
 
135
135
  /* eslint-disable max-len */
136
- /**
137
- * 工具包
138
- * @author holyhigh2
139
- */
140
136
  /**
141
137
  * 获取child相对于parent的offset信息。含border宽度
142
138
  * @returns
@@ -159,11 +155,35 @@ function getOffset(child, parent) {
159
155
  */
160
156
  const EDGE_THRESHOLD = 5;
161
157
  const DRAGGING_RULE = "body * { pointer-events: none; }";
158
+ let lockSheet;
162
159
  function lockPage() {
163
- document.styleSheets[0].insertRule(DRAGGING_RULE, 0);
160
+ lockSheet = getFirstSS();
161
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.insertRule(DRAGGING_RULE, 0);
164
162
  }
165
163
  function unlockPage() {
166
- document.styleSheets[0].deleteRule(0);
164
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.deleteRule(0);
165
+ }
166
+ function getFirstSS() {
167
+ if (document.styleSheets.length < 1) {
168
+ document.head.appendChild(document.createElement('style'));
169
+ }
170
+ const sheet = find(document.styleSheets, ss => !ss.href);
171
+ if (!sheet) {
172
+ document.head.appendChild(document.createElement('style'));
173
+ }
174
+ return sheet || find(document.styleSheets, ss => !ss.href);
175
+ }
176
+ let cursor = { html: '', body: '' };
177
+ function saveCursor() {
178
+ cursor.body = document.body.style.cursor;
179
+ cursor.html = document.documentElement.style.cursor;
180
+ }
181
+ function setCursor(cursor) {
182
+ document.body.style.cursor = document.documentElement.style.cursor = cursor;
183
+ }
184
+ function restoreCursor() {
185
+ document.body.style.cursor = cursor.body;
186
+ document.documentElement.style.cursor = cursor.html;
167
187
  }
168
188
 
169
189
  var _Splittable_instances, _Splittable_checkDirection, _Splittable_bindHandle;
@@ -336,7 +356,7 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
336
356
  sticked = 'end';
337
357
  }
338
358
  let dragging = false;
339
- let bodyCursor = document.body.style.cursor;
359
+ saveCursor();
340
360
  let startPos = dir === 'v' ? dom1.offsetTop : dom1.offsetLeft;
341
361
  let ds1, anotherSize;
342
362
  const dragListener = (ev) => {
@@ -362,7 +382,7 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
362
382
  }
363
383
  }
364
384
  lockPage();
365
- document.body.style.cursor = (handle === null || handle === void 0 ? void 0 : handle.dataset.cursor) || '';
385
+ setCursor((handle === null || handle === void 0 ? void 0 : handle.dataset.cursor) || '');
366
386
  call(onStart, originSize, originSize1);
367
387
  }
368
388
  else {
@@ -470,7 +490,7 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
470
490
  (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
471
491
  }
472
492
  unlockPage();
473
- document.body.style.cursor = bodyCursor;
493
+ restoreCursor();
474
494
  call(onEnd, originSize, originSize1);
475
495
  }
476
496
  };
@@ -607,7 +627,7 @@ function bindHandle$1(handle, dir, panel, opts) {
607
627
  let currentW = originW;
608
628
  let currentH = originH;
609
629
  let dragging = false;
610
- let bodyCursor = document.body.style.cursor;
630
+ saveCursor();
611
631
  const dragListener = (ev) => {
612
632
  var _a;
613
633
  const offsetx = ev.clientX - originPosX;
@@ -636,7 +656,7 @@ function bindHandle$1(handle, dir, panel, opts) {
636
656
  style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
637
657
  }
638
658
  lockPage();
639
- document.body.style.cursor = handle.dataset.cursor || '';
659
+ setCursor(handle.dataset.cursor || '');
640
660
  call(onStart, originW, originH);
641
661
  }
642
662
  else {
@@ -725,7 +745,7 @@ function bindHandle$1(handle, dir, panel, opts) {
725
745
  }
726
746
  handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
727
747
  unlockPage();
728
- document.body.style.cursor = bodyCursor;
748
+ restoreCursor();
729
749
  call(onEnd, currentW, currentH);
730
750
  };
731
751
  document.addEventListener('mousemove', dragListener, false);
@@ -1010,7 +1030,7 @@ function bindEvent(registerEvent, el, opts, handleMap) {
1010
1030
  let toTop = false;
1011
1031
  let toRight = false;
1012
1032
  let toBottom = false;
1013
- let bodyCursor = document.body.style.cursor;
1033
+ saveCursor();
1014
1034
  const dragListener = (ev) => {
1015
1035
  var _a;
1016
1036
  const newX = ev.clientX - rect.x + container.scrollLeft;
@@ -1050,7 +1070,7 @@ function bindEvent(registerEvent, el, opts, handleMap) {
1050
1070
  call(onStart, dragDom, ev);
1051
1071
  lockPage();
1052
1072
  if (isDefined(opts.cursor)) {
1053
- document.body.style.cursor = opts.cursor.active || 'move';
1073
+ setCursor(opts.cursor.active || 'move');
1054
1074
  }
1055
1075
  //notify
1056
1076
  const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
@@ -1262,7 +1282,7 @@ function bindEvent(registerEvent, el, opts, handleMap) {
1262
1282
  dragDom.dispatchEvent(customEv);
1263
1283
  if (dragging) {
1264
1284
  unlockPage();
1265
- document.body.style.cursor = bodyCursor;
1285
+ restoreCursor();
1266
1286
  if (ghost) {
1267
1287
  (_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(copyNode);
1268
1288
  if (moveToGhost !== false) {
@@ -1318,7 +1338,7 @@ class Droppable extends Uii {
1318
1338
  });
1319
1339
  }
1320
1340
  if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1321
- document.body.style.cursor = __classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver;
1341
+ setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver);
1322
1342
  }
1323
1343
  call(opts.onEnter, el, e);
1324
1344
  });
@@ -1332,7 +1352,7 @@ class Droppable extends Uii {
1332
1352
  });
1333
1353
  }
1334
1354
  if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1335
- document.body.style.cursor = __classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '';
1355
+ setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '');
1336
1356
  }
1337
1357
  call(opts.onLeave, el, e);
1338
1358
  });
@@ -1500,7 +1520,7 @@ function bindHandle(handle, el, opts) {
1500
1520
  startDeg = 360 + startDeg;
1501
1521
  const offsetDeg = startDeg - deg;
1502
1522
  let dragging = false;
1503
- let bodyCursor = document.body.style.cursor;
1523
+ saveCursor();
1504
1524
  const dragListener = (ev) => {
1505
1525
  var _a;
1506
1526
  const offsetx = ev.clientX - centerX;
@@ -1513,7 +1533,7 @@ function bindHandle(handle, el, opts) {
1513
1533
  call(onStart, deg);
1514
1534
  lockPage();
1515
1535
  if (isDefined(opts.cursor)) {
1516
- document.body.style.cursor = ((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.active) || 'crosshair';
1536
+ setCursor(((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.active) || 'crosshair');
1517
1537
  }
1518
1538
  }
1519
1539
  else {
@@ -1535,7 +1555,7 @@ function bindHandle(handle, el, opts) {
1535
1555
  window.removeEventListener('blur', dragEndListener, false);
1536
1556
  if (dragging) {
1537
1557
  unlockPage();
1538
- document.body.style.cursor = bodyCursor;
1558
+ restoreCursor();
1539
1559
  el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
1540
1560
  call(onEnd, deg);
1541
1561
  }
@@ -1928,7 +1948,7 @@ function newSelectable(container, opts) {
1928
1948
  return new Selectable(container, opts);
1929
1949
  }
1930
1950
 
1931
- var version = "1.0.2";
1951
+ var version = "1.0.4";
1932
1952
  var repository = {
1933
1953
  type: "git",
1934
1954
  url: "https://github.com/holyhigh2/uiik"
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * uiik v1.0.2
2
+ * uiik v1.0.4
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2023 @holyhigh2 may be freely distributed under the MIT license
@@ -137,10 +137,6 @@
137
137
  _Uii_listeners = new WeakMap();
138
138
 
139
139
  /* eslint-disable max-len */
140
- /**
141
- * 工具包
142
- * @author holyhigh2
143
- */
144
140
  /**
145
141
  * 获取child相对于parent的offset信息。含border宽度
146
142
  * @returns
@@ -163,11 +159,35 @@
163
159
  */
164
160
  const EDGE_THRESHOLD = 5;
165
161
  const DRAGGING_RULE = "body * { pointer-events: none; }";
162
+ let lockSheet;
166
163
  function lockPage() {
167
- document.styleSheets[0].insertRule(DRAGGING_RULE, 0);
164
+ lockSheet = getFirstSS();
165
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.insertRule(DRAGGING_RULE, 0);
168
166
  }
169
167
  function unlockPage() {
170
- document.styleSheets[0].deleteRule(0);
168
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.deleteRule(0);
169
+ }
170
+ function getFirstSS() {
171
+ if (document.styleSheets.length < 1) {
172
+ document.head.appendChild(document.createElement('style'));
173
+ }
174
+ const sheet = func_js.find(document.styleSheets, ss => !ss.href);
175
+ if (!sheet) {
176
+ document.head.appendChild(document.createElement('style'));
177
+ }
178
+ return sheet || func_js.find(document.styleSheets, ss => !ss.href);
179
+ }
180
+ let cursor = { html: '', body: '' };
181
+ function saveCursor() {
182
+ cursor.body = document.body.style.cursor;
183
+ cursor.html = document.documentElement.style.cursor;
184
+ }
185
+ function setCursor(cursor) {
186
+ document.body.style.cursor = document.documentElement.style.cursor = cursor;
187
+ }
188
+ function restoreCursor() {
189
+ document.body.style.cursor = cursor.body;
190
+ document.documentElement.style.cursor = cursor.html;
171
191
  }
172
192
 
173
193
  var _Splittable_instances, _Splittable_checkDirection, _Splittable_bindHandle;
@@ -340,7 +360,7 @@
340
360
  sticked = 'end';
341
361
  }
342
362
  let dragging = false;
343
- let bodyCursor = document.body.style.cursor;
363
+ saveCursor();
344
364
  let startPos = dir === 'v' ? dom1.offsetTop : dom1.offsetLeft;
345
365
  let ds1, anotherSize;
346
366
  const dragListener = (ev) => {
@@ -366,7 +386,7 @@
366
386
  }
367
387
  }
368
388
  lockPage();
369
- document.body.style.cursor = (handle === null || handle === void 0 ? void 0 : handle.dataset.cursor) || '';
389
+ setCursor((handle === null || handle === void 0 ? void 0 : handle.dataset.cursor) || '');
370
390
  func_js.call(onStart, originSize, originSize1);
371
391
  }
372
392
  else {
@@ -474,7 +494,7 @@
474
494
  (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
475
495
  }
476
496
  unlockPage();
477
- document.body.style.cursor = bodyCursor;
497
+ restoreCursor();
478
498
  func_js.call(onEnd, originSize, originSize1);
479
499
  }
480
500
  };
@@ -611,7 +631,7 @@
611
631
  let currentW = originW;
612
632
  let currentH = originH;
613
633
  let dragging = false;
614
- let bodyCursor = document.body.style.cursor;
634
+ saveCursor();
615
635
  const dragListener = (ev) => {
616
636
  var _a;
617
637
  const offsetx = ev.clientX - originPosX;
@@ -640,7 +660,7 @@
640
660
  style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
641
661
  }
642
662
  lockPage();
643
- document.body.style.cursor = handle.dataset.cursor || '';
663
+ setCursor(handle.dataset.cursor || '');
644
664
  func_js.call(onStart, originW, originH);
645
665
  }
646
666
  else {
@@ -729,7 +749,7 @@
729
749
  }
730
750
  handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
731
751
  unlockPage();
732
- document.body.style.cursor = bodyCursor;
752
+ restoreCursor();
733
753
  func_js.call(onEnd, currentW, currentH);
734
754
  };
735
755
  document.addEventListener('mousemove', dragListener, false);
@@ -1014,7 +1034,7 @@
1014
1034
  let toTop = false;
1015
1035
  let toRight = false;
1016
1036
  let toBottom = false;
1017
- let bodyCursor = document.body.style.cursor;
1037
+ saveCursor();
1018
1038
  const dragListener = (ev) => {
1019
1039
  var _a;
1020
1040
  const newX = ev.clientX - rect.x + container.scrollLeft;
@@ -1054,7 +1074,7 @@
1054
1074
  func_js.call(onStart, dragDom, ev);
1055
1075
  lockPage();
1056
1076
  if (func_js.isDefined(opts.cursor)) {
1057
- document.body.style.cursor = opts.cursor.active || 'move';
1077
+ setCursor(opts.cursor.active || 'move');
1058
1078
  }
1059
1079
  //notify
1060
1080
  const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
@@ -1266,7 +1286,7 @@
1266
1286
  dragDom.dispatchEvent(customEv);
1267
1287
  if (dragging) {
1268
1288
  unlockPage();
1269
- document.body.style.cursor = bodyCursor;
1289
+ restoreCursor();
1270
1290
  if (ghost) {
1271
1291
  (_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(copyNode);
1272
1292
  if (moveToGhost !== false) {
@@ -1322,7 +1342,7 @@
1322
1342
  });
1323
1343
  }
1324
1344
  if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1325
- document.body.style.cursor = __classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver;
1345
+ setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver);
1326
1346
  }
1327
1347
  func_js.call(opts.onEnter, el, e);
1328
1348
  });
@@ -1336,7 +1356,7 @@
1336
1356
  });
1337
1357
  }
1338
1358
  if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1339
- document.body.style.cursor = __classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '';
1359
+ setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '');
1340
1360
  }
1341
1361
  func_js.call(opts.onLeave, el, e);
1342
1362
  });
@@ -1504,7 +1524,7 @@
1504
1524
  startDeg = 360 + startDeg;
1505
1525
  const offsetDeg = startDeg - deg;
1506
1526
  let dragging = false;
1507
- let bodyCursor = document.body.style.cursor;
1527
+ saveCursor();
1508
1528
  const dragListener = (ev) => {
1509
1529
  var _a;
1510
1530
  const offsetx = ev.clientX - centerX;
@@ -1517,7 +1537,7 @@
1517
1537
  func_js.call(onStart, deg);
1518
1538
  lockPage();
1519
1539
  if (func_js.isDefined(opts.cursor)) {
1520
- document.body.style.cursor = ((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.active) || 'crosshair';
1540
+ setCursor(((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.active) || 'crosshair');
1521
1541
  }
1522
1542
  }
1523
1543
  else {
@@ -1539,7 +1559,7 @@
1539
1559
  window.removeEventListener('blur', dragEndListener, false);
1540
1560
  if (dragging) {
1541
1561
  unlockPage();
1542
- document.body.style.cursor = bodyCursor;
1562
+ restoreCursor();
1543
1563
  el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
1544
1564
  func_js.call(onEnd, deg);
1545
1565
  }
@@ -1932,7 +1952,7 @@
1932
1952
  return new Selectable(container, opts);
1933
1953
  }
1934
1954
 
1935
- var version = "1.0.2";
1955
+ var version = "1.0.4";
1936
1956
  var repository = {
1937
1957
  type: "git",
1938
1958
  url: "https://github.com/holyhigh2/uiik"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uiik",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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/utils.d.ts CHANGED
@@ -17,3 +17,6 @@ export declare const EDGE_THRESHOLD = 5;
17
17
  export declare const DRAGGING_RULE = "body * { pointer-events: none; }";
18
18
  export declare function lockPage(): void;
19
19
  export declare function unlockPage(): void;
20
+ export declare function saveCursor(): void;
21
+ export declare function setCursor(cursor: string): void;
22
+ export declare function restoreCursor(): void;