uiik 1.0.9 → 1.3.0-alpha

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.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * uiik v1.0.9
2
+ * uiik v1.3.0-alpha
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
7
  (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@holyhigh/func.js')) :
9
- typeof define === 'function' && define.amd ? define(['exports', '@holyhigh/func.js'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.func_js));
11
- })(this, (function (exports, func_js) { 'use strict';
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/is'), require('myfx/collection'), require('myfx/object'), require('myfx/string'), require('myfx/array'), require('myfx'), require('myfx/utils')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', 'myfx/is', 'myfx/collection', 'myfx/object', 'myfx/string', 'myfx/array', 'myfx', 'myfx/utils'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.is, global.collection, global.object, global.string, global.array, null, global.utils));
11
+ })(this, (function (exports, is, collection, object, string, array, myfx, utils) { 'use strict';
12
12
 
13
13
  /******************************************************************************
14
14
  Copyright (c) Microsoft Corporation.
@@ -36,21 +36,346 @@
36
36
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
37
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
38
38
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
39
+ }
40
+
41
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
42
+ var e = new Error(message);
43
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
44
+ };
45
+
46
+ const UtMap = new WeakMap();
47
+ const EXP_MATRIX$1 = /matrix\((?<a>[\d-.]+)\s*,\s*(?<b>[\d-.]+)\s*,\s*(?<c>[\d-.]+)\s*,\s*(?<d>[\d-.]+)\s*,\s*(?<x>[\d-.]+)\s*,\s*(?<y>[\d-.]+)\)/gim;
48
+ class UiiTransformer {
49
+ constructor(el) {
50
+ this.angle = 0;
51
+ this.el = el;
52
+ this.normalize(el);
53
+ UtMap.set(el, this);
54
+ }
55
+ normalize(el) {
56
+ let { x, y } = normalize(el);
57
+ this.x = x;
58
+ this.y = y;
59
+ return this;
60
+ }
61
+ moveTo(x, y) {
62
+ this.x = x;
63
+ this.y = y;
64
+ moveTo(this.el, this.x, this.y);
65
+ }
66
+ moveToX(x) {
67
+ this.x = x;
68
+ moveTo(this.el, this.x, this.y);
69
+ }
70
+ moveToY(y) {
71
+ this.y = y;
72
+ moveTo(this.el, this.x, this.y);
73
+ }
74
+ }
75
+ function normalize(el) {
76
+ const style = window.getComputedStyle(el);
77
+ let x = 0, y = 0;
78
+ if (el instanceof HTMLElement) {
79
+ x = (parseFloat(style.left) || 0) + (parseFloat(style.marginLeft) || 0);
80
+ y = (parseFloat(style.top) || 0) + (parseFloat(style.marginTop) || 0);
81
+ el.style.setProperty("left", "0", "important");
82
+ el.style.setProperty("top", "0", "important");
83
+ el.style.setProperty("margin", "0", "important");
84
+ }
85
+ else {
86
+ x = parseFloat(style.x || style.cx) || 0;
87
+ y = parseFloat(style.y || style.cy) || 0;
88
+ el.removeAttribute("x");
89
+ el.removeAttribute("y");
90
+ el.removeAttribute("cx");
91
+ el.removeAttribute("cy");
92
+ }
93
+ EXP_MATRIX$1.lastIndex = 0;
94
+ const rs = EXP_MATRIX$1.exec(window.getComputedStyle(el).transform);
95
+ if (rs && rs.groups) {
96
+ x += parseFloat(rs.groups.x) || 0;
97
+ y += parseFloat(rs.groups.y) || 0;
98
+ }
99
+ moveTo(el, x, y);
100
+ return { x, y };
101
+ }
102
+ function wrapper(el) {
103
+ let ut = UtMap.get(el);
104
+ if (ut)
105
+ return ut.normalize(el);
106
+ return new UiiTransformer(el);
107
+ }
108
+ function transformMove(transofrmStr, x, y, unit = false) {
109
+ return (`translate(${x}${unit ? "px" : ""},${y}${unit ? "px" : ""})` +
110
+ transofrmStr.replace(/translate\([^)]+?\)/, ""));
111
+ }
112
+ function getTranslate(el) {
113
+ let xVal = NaN, yVal = NaN;
114
+ let transformStr = "";
115
+ if (el instanceof SVGGraphicsElement) {
116
+ transformStr = el.getAttribute("transform") || "";
117
+ }
118
+ else {
119
+ let style = el.style;
120
+ transformStr = style.transform || "";
121
+ }
122
+ EXP_GET_TRANSLATE.lastIndex = 0;
123
+ const xy = EXP_GET_TRANSLATE.exec(transformStr);
124
+ if (xy && xy.groups) {
125
+ xVal = parseFloat(xy.groups.x);
126
+ yVal = parseFloat(xy.groups.y);
127
+ }
128
+ else {
129
+ EXP_GET_TRANSLATE_XY.lastIndex = 0;
130
+ const xy = EXP_GET_TRANSLATE_XY.exec(transformStr);
131
+ if (xy && xy.groups) {
132
+ if (xy.groups.dir == "X") {
133
+ xVal = parseFloat(xy.groups.v);
134
+ }
135
+ else {
136
+ yVal = parseFloat(xy.groups.v);
137
+ }
138
+ }
139
+ }
140
+ return { x: xVal, y: yVal };
141
+ }
142
+ function moveTo(el, x, y) {
143
+ if (el instanceof SVGGraphicsElement) {
144
+ el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", x, y));
145
+ }
146
+ else {
147
+ let style = el.style;
148
+ style.transform = transformMove(style.transform || "", x, y, true);
149
+ }
150
+ }
151
+ const EXP_GET_TRANSLATE = /translate\(\s*(?<x>[\d.-]+)\D*,\s*(?<y>[\d.-]+)\D*\)/gim;
152
+ const EXP_GET_TRANSLATE_XY = /translate(?<dir>X|Y)\(\s*(?<v>[\d.-]+)\D*\)/gim;
153
+ function moveBy(el, x, y) {
154
+ const xy = getTranslate(el);
155
+ if (el instanceof SVGGraphicsElement) {
156
+ el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", xy.x + x, xy.y + y));
157
+ }
158
+ else {
159
+ let style = el.style;
160
+ style.transform = transformMove(style.transform || "", xy.x + x, xy.y + y, true);
161
+ }
162
+ }
163
+ function rotateTo(el, deg, cx, cy) {
164
+ if (el instanceof SVGGraphicsElement) {
165
+ let transformStr = el.getAttribute("transform") || "";
166
+ let originPos = is.isDefined(cx) && is.isDefined(cy);
167
+ let origin = "";
168
+ if (originPos) {
169
+ if (el.x instanceof SVGAnimatedLength) {
170
+ cx += el.x.animVal.value;
171
+ cy += el.y.animVal.value;
172
+ }
173
+ else if (el.cx instanceof SVGAnimatedLength) {
174
+ cx += el.cx.animVal.value;
175
+ cy += el.cy.animVal.value;
176
+ }
177
+ origin = `,${cx},${cy}`;
178
+ }
179
+ transformStr =
180
+ transformStr.replace(/rotate\([^)]+?\)/, "") + ` rotate(${deg}${origin})`;
181
+ el.setAttribute("transform", transformStr);
182
+ }
183
+ else {
184
+ let style = el.style;
185
+ style.transform =
186
+ style.transform.replace(/rotate\([^)]+?\)/, "").replace(/rotateZ\([^)]+?\)/, "") +
187
+ " rotateZ(" +
188
+ deg +
189
+ "deg)";
190
+ }
191
+ }
192
+
193
+ const ONE_ANG = Math.PI / 180;
194
+ const ONE_RAD = 180 / Math.PI;
195
+ function getBox(child, parent) {
196
+ const rect = child.getBoundingClientRect();
197
+ const rs = { x: 0, y: 0, w: rect.width, h: rect.height };
198
+ parent =
199
+ parent ||
200
+ child.offsetParent ||
201
+ child.ownerSVGElement ||
202
+ child.parentElement ||
203
+ document.body;
204
+ const parentRect = parent.getBoundingClientRect();
205
+ const parentStyle = window.getComputedStyle(parent);
206
+ const parentBorderLeft = parseFloat(parentStyle.borderLeftWidth);
207
+ const parentBorderTop = parseFloat(parentStyle.borderTopWidth);
208
+ rs.x = rect.x - parentRect.x + parent.scrollLeft;
209
+ rs.y = rect.y - parentRect.y + parent.scrollTop;
210
+ if (child instanceof SVGElement) ;
211
+ else {
212
+ rs.x -= parentBorderLeft;
213
+ rs.y -= parentBorderTop;
214
+ }
215
+ return rs;
216
+ }
217
+ function getPointOffset(e, pos) {
218
+ let ox = e.offsetX || 0, oy = e.offsetY || 0;
219
+ if (e.target instanceof SVGElement) {
220
+ ox -= pos.x;
221
+ oy -= pos.y;
222
+ }
223
+ return [ox, oy];
224
+ }
225
+ function isSVGEl(el) {
226
+ return el instanceof SVGElement;
227
+ }
228
+ const EDGE_THRESHOLD = 5;
229
+ const DRAGGING_RULE = "body * { pointer-events: none; }";
230
+ let lockSheet;
231
+ function lockPage() {
232
+ lockSheet = getFirstSS();
233
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.insertRule(DRAGGING_RULE, 0);
234
+ }
235
+ function unlockPage() {
236
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.deleteRule(0);
237
+ }
238
+ function getFirstSS() {
239
+ if (document.styleSheets.length < 1) {
240
+ document.head.appendChild(document.createElement("style"));
241
+ }
242
+ const sheet = collection.find(document.styleSheets, (ss) => !ss.href);
243
+ if (!sheet) {
244
+ document.head.appendChild(document.createElement("style"));
245
+ }
246
+ return sheet || collection.find(document.styleSheets, (ss) => !ss.href);
247
+ }
248
+ let cursor = { html: "", body: "" };
249
+ function saveCursor() {
250
+ cursor.body = document.body.style.cursor;
251
+ cursor.html = document.documentElement.style.cursor;
252
+ }
253
+ function setCursor(cursor) {
254
+ document.body.style.cursor = document.documentElement.style.cursor = cursor;
255
+ }
256
+ function restoreCursor() {
257
+ document.body.style.cursor = cursor.body;
258
+ document.documentElement.style.cursor = cursor.html;
259
+ }
260
+ function getStyleXy(el) {
261
+ const style = window.getComputedStyle(el);
262
+ let x = 0, y = 0;
263
+ if (el instanceof SVGGraphicsElement) {
264
+ x = parseFloat(style.x || style.cx) || 0;
265
+ y = parseFloat(style.y || style.cy) || 0;
266
+ }
267
+ else {
268
+ x = parseFloat(style.left) || 0;
269
+ y = parseFloat(style.top) || 0;
270
+ }
271
+ return { x, y };
272
+ }
273
+ const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<x>[\d.-]+)\s*,\s*(?<y>[\d.-]+)\s*\)/;
274
+ function getMatrixInfo(elCStyle) {
275
+ let a = 1, b = 0, x = 0, y = 0;
276
+ let e = undefined, f = undefined;
277
+ if (elCStyle instanceof SVGGraphicsElement) {
278
+ const transMatrix = elCStyle.transform.animVal[0];
279
+ if (transMatrix) {
280
+ e = transMatrix.matrix.e;
281
+ f = transMatrix.matrix.f;
282
+ }
283
+ elCStyle = window.getComputedStyle(elCStyle);
284
+ }
285
+ else {
286
+ if (elCStyle instanceof HTMLElement) {
287
+ elCStyle = window.getComputedStyle(elCStyle);
288
+ }
289
+ }
290
+ const matched = elCStyle.transform.match(EXP_MATRIX);
291
+ if (matched && matched.groups) {
292
+ a = parseFloat(matched.groups.a);
293
+ b = parseFloat(matched.groups.b);
294
+ parseFloat(matched.groups.c);
295
+ parseFloat(matched.groups.d);
296
+ x = parseFloat(matched.groups.x);
297
+ y = parseFloat(matched.groups.y);
298
+ }
299
+ if (e && f) {
300
+ x = e;
301
+ y = f;
302
+ }
303
+ const rs = { scale: 1, angle: 0, x, y };
304
+ rs.scale = Math.sqrt(a * a + b * b);
305
+ rs.angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
306
+ return rs;
307
+ }
308
+ function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
309
+ if (!elRect) {
310
+ elRect = el.getBoundingClientRect();
311
+ }
312
+ if (!elCStyle) {
313
+ elCStyle = window.getComputedStyle(el);
314
+ }
315
+ if (!matrixInfo) {
316
+ matrixInfo = getMatrixInfo(elCStyle);
317
+ }
318
+ const scale = matrixInfo.scale;
319
+ let x = event.clientX -
320
+ elRect.x -
321
+ (parseFloat(elCStyle.borderLeftWidth) || 0) * scale +
322
+ el.scrollLeft * scale;
323
+ let y = event.clientY -
324
+ elRect.y -
325
+ (parseFloat(elCStyle.borderTopWidth) || 0) * scale +
326
+ el.scrollTop * scale;
327
+ return { x: x / scale, y: y / scale };
328
+ }
329
+ function getRectInContainer(el, container) {
330
+ const elRect = el.getBoundingClientRect();
331
+ const containerRect = container.getBoundingClientRect();
332
+ const elCStyle = window.getComputedStyle(container);
333
+ const matrixInfo = getMatrixInfo(elCStyle);
334
+ const scale = matrixInfo.scale;
335
+ let x = elRect.x -
336
+ containerRect.x -
337
+ (parseFloat(elCStyle.borderLeftWidth) || 0) * scale +
338
+ container.scrollLeft * scale;
339
+ let y = elRect.y -
340
+ containerRect.y -
341
+ (parseFloat(elCStyle.borderTopWidth) || 0) * scale +
342
+ container.scrollTop * scale;
343
+ return {
344
+ x: x / scale,
345
+ y: y / scale,
346
+ w: elRect.width / scale,
347
+ h: elRect.height / scale,
348
+ };
349
+ }
350
+ function getCenterXy(el) {
351
+ const cStyle = window.getComputedStyle(el);
352
+ const center = cStyle.transformOrigin;
353
+ const centerPair = center.split(" ");
354
+ const ox = parseFloat(centerPair[0]);
355
+ const oy = parseFloat(centerPair[1]);
356
+ const shadowDom = el.cloneNode();
357
+ rotateTo(shadowDom, 0);
358
+ const parentEl = el.parentElement;
359
+ let startX = 0, startY = 0;
360
+ if (parentEl) {
361
+ parentEl.appendChild(shadowDom);
362
+ const offsetXY = getRectInContainer(shadowDom, parentEl);
363
+ (startX = offsetXY.x), (startY = offsetXY.y);
364
+ parentEl.removeChild(shadowDom);
365
+ }
366
+ return { sx: startX, sy: startY, x: startX + ox, y: startY + oy, ox, oy };
39
367
  }
40
368
 
41
369
  var _Uii_listeners;
42
- /**
43
- * A Base class for all Uii classes
44
- */
45
370
  class Uii {
46
371
  constructor(ele, opts) {
47
372
  this.enabled = true;
48
373
  _Uii_listeners.set(this, []);
49
374
  this.opts = opts || {};
50
- if (func_js.isArrayLike(ele) && !func_js.isString(ele)) {
51
- this.ele = func_js.map(ele, (el) => {
52
- let e = func_js.isString(el) ? document.querySelector(el) : el;
53
- if (!func_js.isElement(e)) {
375
+ if (is.isArrayLike(ele) && !is.isString(ele)) {
376
+ this.ele = collection.map(ele, (el) => {
377
+ let e = is.isString(el) ? document.querySelector(el) : el;
378
+ if (!is.isElement(e)) {
54
379
  console.error('Invalid element "' + el + '"');
55
380
  return false;
56
381
  }
@@ -58,30 +383,95 @@
58
383
  });
59
384
  }
60
385
  else {
61
- const el = func_js.isString(ele) ? document.querySelectorAll(ele) : ele;
62
- if (!func_js.isElement(el) && !func_js.isArrayLike(el)) {
386
+ if (is.isString(ele)) {
387
+ this.eleString = ele;
388
+ }
389
+ const el = is.isString(ele) ? document.querySelectorAll(ele) : ele;
390
+ if (!is.isElement(el) && !is.isArrayLike(el)) {
63
391
  console.error('Invalid element "' + ele + '"');
64
392
  return;
65
393
  }
66
- this.ele = func_js.isArrayLike(el) ? func_js.toArray(el) : [el];
394
+ this.ele = is.isArrayLike(el) ? collection.toArray(el) : [el];
67
395
  }
68
396
  }
69
- /**
70
- * 销毁uii对象,包括卸载事件、清空元素等
71
- */
72
397
  destroy() {
73
- func_js.each(__classPrivateFieldGet(this, _Uii_listeners, "f"), ev => {
398
+ collection.each(__classPrivateFieldGet(this, _Uii_listeners, "f"), (ev) => {
74
399
  ev[0].removeEventListener(ev[1], ev[2], ev[3]);
75
400
  });
76
401
  __classPrivateFieldSet(this, _Uii_listeners, [], "f");
77
402
  }
78
- /**
79
- * 注册事件,以便在{@link destroy}方法中卸载
80
- * @param el dom元素
81
- * @param event 事件名
82
- * @param hook 回调函数
83
- * @param useCapture 默认false
84
- */
403
+ addPointerDown(el, pointerDown, opts) {
404
+ const onPointerDown = pointerDown;
405
+ const threshold = opts.threshold || 0;
406
+ const toLockPage = opts.lockPage || false;
407
+ const uiiOptions = this.opts;
408
+ this.registerEvent(el, 'mousedown', (e) => {
409
+ let t = e.target;
410
+ if (!t)
411
+ return;
412
+ const hasCursor = !is.isEmpty(object.get(uiiOptions, 'cursor.active'));
413
+ const currentStyle = el.style;
414
+ const currentCStyle = window.getComputedStyle(el);
415
+ const currentRect = el.getBoundingClientRect();
416
+ let dragging = false;
417
+ const originPosX = e.clientX;
418
+ const originPosY = e.clientY;
419
+ if (hasCursor) {
420
+ saveCursor();
421
+ }
422
+ let onPointerStart;
423
+ let onPointerMove;
424
+ let onPointerEnd;
425
+ onPointerDown({
426
+ onPointerMove: (pm) => { onPointerMove = pm; },
427
+ onPointerStart: (ps) => { onPointerStart = ps; },
428
+ onPointerEnd: (pe) => { onPointerEnd = pe; },
429
+ ev: e,
430
+ pointX: e.clientX, pointY: e.clientY, target: t,
431
+ currentTarget: el, currentStyle, currentCStyle, currentRect
432
+ });
433
+ const pointerMove = (ev) => {
434
+ const offX = ev.clientX - originPosX;
435
+ const offY = ev.clientY - originPosY;
436
+ if (!dragging) {
437
+ if (Math.abs(offX) > threshold || Math.abs(offY) > threshold) {
438
+ dragging = true;
439
+ if (toLockPage) {
440
+ lockPage();
441
+ }
442
+ if (hasCursor) {
443
+ setCursor(uiiOptions.cursor.active);
444
+ }
445
+ onPointerMove && onPointerStart({ ev });
446
+ }
447
+ else {
448
+ ev.preventDefault();
449
+ return false;
450
+ }
451
+ }
452
+ onPointerMove && onPointerMove({ ev, pointX: ev.clientX, pointY: ev.clientY, offX, offY, currentStyle, currentCStyle });
453
+ };
454
+ const pointerEnd = (ev) => {
455
+ document.removeEventListener('mousemove', pointerMove, false);
456
+ document.removeEventListener('mouseup', pointerEnd, false);
457
+ window.removeEventListener('blur', pointerEnd, false);
458
+ if (dragging) {
459
+ if (toLockPage) {
460
+ unlockPage();
461
+ }
462
+ if (hasCursor) {
463
+ restoreCursor();
464
+ }
465
+ onPointerEnd && onPointerEnd({ ev, currentStyle });
466
+ }
467
+ };
468
+ document.addEventListener("mousemove", pointerMove);
469
+ document.addEventListener("mouseup", pointerEnd);
470
+ window.addEventListener("blur", pointerEnd);
471
+ e.preventDefault();
472
+ return false;
473
+ }, true);
474
+ }
85
475
  registerEvent(el, event, hook, useCapture = false) {
86
476
  const wrapper = ((ev) => {
87
477
  if (!this.enabled)
@@ -91,107 +481,32 @@
91
481
  el.addEventListener(event, wrapper, useCapture);
92
482
  __classPrivateFieldGet(this, _Uii_listeners, "f").push([el, event, wrapper, useCapture]);
93
483
  }
94
- /**
95
- * 禁用uii实例,禁用后的dom不会响应事件
96
- */
97
484
  disable() {
98
485
  this.enabled = false;
99
486
  }
100
- /**
101
- * 启用uii实例
102
- */
103
487
  enable() {
104
488
  this.enabled = true;
105
489
  }
106
- /**
107
- * 获取指定名称的选项值
108
- * @param name
109
- * @returns
110
- */
490
+ getOptions() {
491
+ return this.opts;
492
+ }
111
493
  getOption(name) {
112
- return name ? this.opts[name] : this.opts;
494
+ return this.opts[name];
113
495
  }
114
- /**
115
- * 一次设置多个选项值。触发`onOptionChanged`
116
- * @param options
117
- */
118
496
  setOptions(options) {
119
- func_js.assign(this.opts, options);
497
+ object.assign(this.opts, options);
120
498
  this.onOptionChanged(this.opts);
121
499
  }
122
- /**
123
- * 设置指定name的选项值。触发`onOptionChanged`
124
- * @param name
125
- * @param value
126
- */
127
500
  setOption(name, value) {
128
501
  this.opts[name] = value;
129
502
  this.onOptionChanged(this.opts);
130
503
  }
131
- /**
132
- * @internal
133
- */
134
- onOptionChanged(opts) {
135
- }
504
+ onOptionChanged(opts) { }
136
505
  }
137
506
  _Uii_listeners = new WeakMap();
138
507
 
139
- /* eslint-disable max-len */
140
- /**
141
- * 获取child相对于parent的offset信息。含border宽度
142
- * @returns
143
- */
144
- function getOffset(child, parent) {
145
- const rs = { x: 0, y: 0 };
146
- let op = child.offsetParent;
147
- while (op && parent && op !== parent) {
148
- const style = window.getComputedStyle(op);
149
- rs.x += op.offsetLeft + parseFloat(style.borderLeftWidth);
150
- rs.y += op.offsetTop + parseFloat(style.borderTopWidth);
151
- op = op.offsetParent;
152
- }
153
- rs.x += child.offsetLeft;
154
- rs.y += child.offsetTop;
155
- return rs;
156
- }
157
- /**
158
- * 边缘检测最小内部边距
159
- */
160
- const EDGE_THRESHOLD = 5;
161
- const DRAGGING_RULE = "body * { pointer-events: none; }";
162
- let lockSheet;
163
- function lockPage() {
164
- lockSheet = getFirstSS();
165
- lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.insertRule(DRAGGING_RULE, 0);
166
- }
167
- function unlockPage() {
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;
191
- }
192
-
193
508
  var _Splittable_instances, _Splittable_checkDirection, _Splittable_bindHandle;
194
- const THRESHOLD$3 = 1;
509
+ const THRESHOLD$4 = 1;
195
510
  const CLASS_SPLITTABLE = "uii-splittable";
196
511
  const CLASS_SPLITTABLE_HANDLE = "uii-splittable-handle";
197
512
  const CLASS_SPLITTABLE_HANDLE_GHOST = "uii-splittable-handle-ghost";
@@ -205,20 +520,9 @@
205
520
  }
206
521
  return rs;
207
522
  }
208
- /**
209
- * 用于表示一个或多个分割器的定义
210
- * > 可用CSS接口
211
- * - .uii-splittable
212
- * - .uii-splittable-handle
213
- * - .uii-splittable-handle-ghost
214
- * - .uii-splittable-handle-active
215
- * - .uii-splittable-v
216
- * - .uii-splittable-h
217
- * @public
218
- */
219
523
  class Splittable extends Uii {
220
524
  constructor(container, opts) {
221
- super(container, func_js.assign({
525
+ super(container, object.assign({
222
526
  handleSize: 10,
223
527
  minSize: 0,
224
528
  sticky: false,
@@ -226,65 +530,65 @@
226
530
  ghost: false
227
531
  }, opts));
228
532
  _Splittable_instances.add(this);
229
- const con = this.ele[0];
230
- //detect container position
231
- const pos = window.getComputedStyle(con).position;
232
- if (pos === "static") {
233
- con.style.position = "relative";
234
- }
235
- con.classList.toggle(CLASS_SPLITTABLE, true);
236
- const handleDoms = con.querySelectorAll(this.opts.handle);
237
- const children = func_js.reject(con.children, c => {
238
- if (func_js.includes(handleDoms, c))
239
- return true;
240
- return false;
241
- });
242
- const dir = __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_checkDirection).call(this, con);
243
- con.classList.toggle(dir === 'v' ? CLASS_SPLITTABLE_V : CLASS_SPLITTABLE_H, true);
244
- const minSizeAry = func_js.map(children, (c, i) => {
245
- if (func_js.isArray(this.opts.minSize)) {
246
- return this.opts.minSize[i] || 0;
247
- }
248
- else {
249
- return this.opts.minSize;
250
- }
251
- });
252
- const stickyAry = func_js.map(children, (c, i) => {
253
- if (func_js.isArray(this.opts.sticky)) {
254
- return this.opts.sticky[i] || false;
255
- }
256
- else {
257
- return this.opts.sticky;
258
- }
259
- });
260
- if (func_js.isEmpty(handleDoms)) {
261
- const len = children.length - 1;
262
- for (let i = 0; i < len; i++) {
263
- __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, children[i], children[i + 1]);
264
- }
265
- }
266
- else {
267
- func_js.each(handleDoms, (h, i) => {
268
- const isRoot = h.parentNode.classList.contains(CLASS_SPLITTABLE);
269
- let dom1, dom2;
270
- if (isRoot) {
271
- dom1 = h.previousElementSibling;
272
- dom2 = h.nextElementSibling;
533
+ collection.each(this.ele, con => {
534
+ const pos = window.getComputedStyle(con).position;
535
+ if (pos === "static") {
536
+ con.style.position = "relative";
537
+ }
538
+ con.classList.toggle(CLASS_SPLITTABLE, true);
539
+ const handleDoms = con.querySelectorAll(this.opts.handle);
540
+ const children = collection.reject(con.children, c => {
541
+ if (collection.includes(handleDoms, c))
542
+ return true;
543
+ return false;
544
+ });
545
+ const dir = __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_checkDirection).call(this, con);
546
+ con.classList.toggle(dir === 'v' ? CLASS_SPLITTABLE_V : CLASS_SPLITTABLE_H, true);
547
+ const minSizeAry = collection.map(children, (c, i) => {
548
+ if (is.isArray(this.opts.minSize)) {
549
+ return this.opts.minSize[i] || 0;
273
550
  }
274
551
  else {
275
- dom2 = getRootEl(h, con);
276
- dom1 = dom2.previousElementSibling;
552
+ return this.opts.minSize;
277
553
  }
278
- __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);
279
554
  });
280
- }
555
+ const stickyAry = collection.map(children, (c, i) => {
556
+ if (is.isArray(this.opts.sticky)) {
557
+ return this.opts.sticky[i] || false;
558
+ }
559
+ else {
560
+ return this.opts.sticky;
561
+ }
562
+ });
563
+ if (is.isEmpty(handleDoms)) {
564
+ const len = children.length - 1;
565
+ for (let i = 0; i < len; i++) {
566
+ __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, children[i], children[i + 1]);
567
+ }
568
+ }
569
+ else {
570
+ collection.each(handleDoms, (h, i) => {
571
+ const isRoot = h.parentNode.classList.contains(CLASS_SPLITTABLE);
572
+ let dom1, dom2;
573
+ if (isRoot) {
574
+ dom1 = h.previousElementSibling;
575
+ dom2 = h.nextElementSibling;
576
+ }
577
+ else {
578
+ dom2 = getRootEl(h, con);
579
+ dom1 = dom2.previousElementSibling;
580
+ }
581
+ __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);
582
+ });
583
+ }
584
+ });
281
585
  }
282
586
  }
283
587
  _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Splittable_checkDirection(container) {
284
588
  let dir = 'h';
285
589
  const child = container.children[0];
286
590
  let lastY = child.offsetTop;
287
- func_js.each(container.children, c => {
591
+ collection.each(container.children, c => {
288
592
  if (c.offsetTop != lastY) {
289
593
  dir = 'v';
290
594
  return false;
@@ -324,34 +628,29 @@
324
628
  const oneSideMode = opts.oneSideMode;
325
629
  const updateStart = !oneSideMode || oneSideMode === 'start';
326
630
  const updateEnd = !oneSideMode || oneSideMode === 'end';
327
- handle.onmousedown = function (e) {
328
- // 1. 获取原始高度/宽度;设置宽度/高度
631
+ this.addPointerDown(handle, ({ currentTarget, onPointerStart, onPointerMove, onPointerEnd }) => {
329
632
  let originSize = 0;
330
633
  let originSize1 = 0;
331
- const originPosX = e.clientX;
332
- const originPosY = e.clientY;
333
634
  let splitterSize = 1;
334
- let blockSize = 0; // 分割区size
635
+ let blockSize = 0;
335
636
  switch (dir) {
336
637
  case 'v':
337
638
  originSize = dom1.offsetHeight;
338
639
  originSize1 = dom2.offsetHeight;
339
- splitterSize = handle.offsetHeight;
640
+ splitterSize = currentTarget.offsetHeight;
340
641
  break;
341
642
  case 'h':
342
643
  originSize = dom1.offsetWidth;
343
644
  originSize1 = dom2.offsetWidth;
344
- splitterSize = handle.offsetWidth;
645
+ splitterSize = currentTarget.offsetWidth;
345
646
  break;
346
647
  }
347
648
  blockSize = splitterSize + originSize + originSize1;
348
649
  const dom1Style = dom1.style;
349
650
  const dom2Style = dom2.style;
350
- //ghost
351
651
  const ghost = opts.ghost;
352
652
  const ghostClass = opts.ghostClass;
353
653
  let ghostNode = null;
354
- // 初始化sticked位置
355
654
  let sticked = 'none';
356
655
  if (originSize < minSize1 / 2) {
357
656
  sticked = 'start';
@@ -359,43 +658,31 @@
359
658
  else if (blockSize - originSize - splitterSize < minSize2 / 2) {
360
659
  sticked = 'end';
361
660
  }
362
- let dragging = false;
363
- saveCursor();
364
661
  let startPos = dir === 'v' ? dom1.offsetTop : dom1.offsetLeft;
365
662
  let ds1, anotherSize;
366
- const dragListener = (ev) => {
367
- var _a;
368
- const offsetx = ev.clientX - originPosX;
369
- const offsety = ev.clientY - originPosY;
370
- if (!dragging) {
371
- if (Math.abs(offsetx) > THRESHOLD$3 || Math.abs(offsety) > THRESHOLD$3) {
372
- dragging = true;
373
- handle === null || handle === void 0 ? void 0 : handle.classList.add(CLASS_SPLITTABLE_HANDLE_ACTIVE);
374
- if (ghost) {
375
- ghostNode = handle.cloneNode(true);
376
- ghostNode.style.opacity = '0.3';
377
- ghostNode.style.pointerEvents = 'none';
378
- ghostNode.classList.add(CLASS_SPLITTABLE_HANDLE_GHOST);
379
- if (ghostNode) {
380
- if (ghostClass) {
381
- ghostNode.className =
382
- ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
383
- }
384
- (_a = handle === null || handle === void 0 ? void 0 : handle.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
385
- func_js.call(onClone, ghostNode, e);
386
- }
663
+ onPointerStart(function (args) {
664
+ const { ev } = args;
665
+ currentTarget.classList.add(CLASS_SPLITTABLE_HANDLE_ACTIVE);
666
+ if (ghost) {
667
+ ghostNode = currentTarget.cloneNode(true);
668
+ ghostNode.style.opacity = '0.3';
669
+ ghostNode.style.pointerEvents = 'none';
670
+ ghostNode.classList.add(CLASS_SPLITTABLE_HANDLE_GHOST);
671
+ if (ghostNode) {
672
+ if (ghostClass) {
673
+ ghostNode.className =
674
+ ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
387
675
  }
388
- lockPage();
389
- setCursor((handle === null || handle === void 0 ? void 0 : handle.dataset.cursor) || '');
390
- func_js.call(onStart, originSize, originSize1);
391
- }
392
- else {
393
- ev.preventDefault();
394
- return false;
676
+ currentTarget.parentNode.appendChild(ghostNode);
677
+ onClone && onClone({ clone: ghostNode }, ev);
395
678
  }
396
679
  }
680
+ onStart && onStart({ size1: originSize, size2: originSize1 }, ev);
681
+ });
682
+ onPointerMove((args) => {
683
+ const { ev, offX, offY, currentStyle } = args;
397
684
  let doSticky = false;
398
- ds1 = dir === 'v' ? originSize + offsety : originSize + offsetx;
685
+ ds1 = dir === 'v' ? originSize + offY : originSize + offX;
399
686
  if (ds1 < minSize1 / 2 && sticky1 && minSize1 > 0) {
400
687
  if (sticked == 'none') {
401
688
  doSticky = true;
@@ -406,7 +693,6 @@
406
693
  else if (ds1 < minSize1) {
407
694
  ds1 = minSize1;
408
695
  if (sticked == 'start' && sticky1) {
409
- // 重置状态
410
696
  doSticky = true;
411
697
  sticked = 'none';
412
698
  }
@@ -422,7 +708,6 @@
422
708
  else if (blockSize - ds1 - splitterSize < minSize2) {
423
709
  ds1 = blockSize - minSize2 - splitterSize;
424
710
  if (sticked == 'end' && sticky2) {
425
- // 重置状态
426
711
  doSticky = true;
427
712
  sticked = 'none';
428
713
  }
@@ -434,6 +719,7 @@
434
719
  }
435
720
  else {
436
721
  ghostNode.style.left = startPos + ds1 - handleSize / 2 + 'px';
722
+ console.log(ghostNode.style.left);
437
723
  }
438
724
  }
439
725
  else {
@@ -445,395 +731,499 @@
445
731
  dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
446
732
  }
447
733
  if (doSticky) {
448
- func_js.call(onSticky, ds1, anotherSize, sticked);
734
+ onSticky && onSticky({ size1: ds1, size2: anotherSize, position: sticked }, ev);
449
735
  }
450
- //update handle
451
736
  if (dir === 'v') {
452
- handle.style.top = dom2.offsetTop - handleSize / 2 + 'px';
737
+ currentStyle.top = dom2.offsetTop - handleSize / 2 + 'px';
453
738
  }
454
739
  else {
455
- handle.style.left = dom2.offsetLeft - handleSize / 2 + 'px';
740
+ currentStyle.left = dom2.offsetLeft - handleSize / 2 + 'px';
456
741
  }
457
742
  }
458
- func_js.call(onSplit, ds1, anotherSize);
459
- ev.preventDefault();
460
- return false;
461
- };
462
- const dragEndListener = (ev) => {
743
+ onSplit && onSplit({ size1: ds1, size2: anotherSize }, ev);
744
+ });
745
+ onPointerEnd((args) => {
463
746
  var _a, _b;
464
- document.removeEventListener('mousemove', dragListener, false);
465
- document.removeEventListener('mouseup', dragEndListener, false);
466
- window.removeEventListener('blur', dragEndListener, false);
467
- if (dragging) {
468
- switch (dir) {
469
- case 'v':
470
- originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetHeight) || -1;
471
- originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetHeight) || -1;
472
- break;
473
- case 'h':
474
- originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetWidth) || -1;
475
- originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetWidth) || -1;
476
- break;
747
+ const { ev, currentStyle } = args;
748
+ switch (dir) {
749
+ case 'v':
750
+ originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetHeight) || -1;
751
+ originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetHeight) || -1;
752
+ break;
753
+ case 'h':
754
+ originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetWidth) || -1;
755
+ originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetWidth) || -1;
756
+ break;
757
+ }
758
+ handle === null || handle === void 0 ? void 0 : handle.classList.remove(CLASS_SPLITTABLE_HANDLE_ACTIVE);
759
+ if (ghostNode) {
760
+ const updateProp = dir === 'v' ? 'height' : 'width';
761
+ if (updateStart) {
762
+ dom1Style.setProperty(updateProp, ds1 + 'px', 'important');
477
763
  }
478
- handle === null || handle === void 0 ? void 0 : handle.classList.remove(CLASS_SPLITTABLE_HANDLE_ACTIVE);
479
- if (ghostNode) {
480
- const updateProp = dir === 'v' ? 'height' : 'width';
481
- if (updateStart) {
482
- dom1Style.setProperty(updateProp, ds1 + 'px', 'important');
483
- }
484
- if (updateEnd) {
485
- dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
486
- }
487
- //update handle
488
- if (dir === 'v') {
489
- handle.style.top = startPos + ds1 - handleSize / 2 + 'px';
490
- }
491
- else {
492
- handle.style.left = startPos + ds1 - handleSize / 2 + 'px';
493
- }
494
- ((_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = ghostNode.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
764
+ if (updateEnd) {
765
+ dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
495
766
  }
496
- unlockPage();
497
- restoreCursor();
498
- func_js.call(onEnd, originSize, originSize1);
767
+ if (dir === 'v') {
768
+ currentStyle.top = startPos + ds1 - handleSize / 2 + 'px';
769
+ }
770
+ else {
771
+ currentStyle.left = startPos + ds1 - handleSize / 2 + 'px';
772
+ }
773
+ ((_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = ghostNode.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
499
774
  }
500
- };
501
- document.addEventListener('mousemove', dragListener, false);
502
- document.addEventListener('mouseup', dragEndListener, false);
503
- window.addEventListener('blur', dragEndListener, false);
504
- e.preventDefault();
505
- return false;
506
- };
775
+ onEnd && onEnd({ size1: originSize, size2: originSize1 }, ev);
776
+ });
777
+ }, {
778
+ threshold: THRESHOLD$4,
779
+ lockPage: true
780
+ });
507
781
  };
508
- /**
509
- * Add one or more splittors into the container
510
- * @param container css selector or html element
511
- * @param opts SplittableOptions
512
- * @returns
513
- */
514
782
  function newSplittable(container, opts) {
515
783
  return new Splittable(container, opts);
516
784
  }
517
785
 
518
- /* eslint-disable max-len */
519
- const THRESHOLD$2 = 2;
786
+ const THRESHOLD$3 = 2;
520
787
  const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
521
788
  const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
522
789
  const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
523
- /**
524
- * 用于表示一个或多个可改变尺寸元素的定义
525
- * > 可用CSS接口
526
- * - .uii-resizable-handle
527
- * - .uii-resizable-handle-[n/s/e/w/ne/nw/se/sw]
528
- * - .uii-resizable-handle-active
529
- * @public
530
- */
790
+ const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
531
791
  class Resizable extends Uii {
532
792
  constructor(els, opts) {
533
- super(els, func_js.assign({
793
+ super(els, object.assign({
534
794
  handleSize: 8,
535
795
  minSize: 50,
536
- dir: ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'],
796
+ dir: ["n", "s", "e", "w", "ne", "nw", "se", "sw"],
537
797
  ghost: false,
538
- offset: 0
798
+ offset: 0,
539
799
  }, opts));
540
- func_js.each(this.ele, (el) => {
541
- initHandle$1(el, this.opts);
800
+ collection.each(this.ele, (el) => {
801
+ this.initHandle(el);
542
802
  });
543
803
  }
544
- }
545
- function bindHandle$1(handle, dir, panel, opts) {
546
- const onStart = opts.onStart;
547
- const onResize = opts.onResize;
548
- const onEnd = opts.onEnd;
549
- const onClone = opts.onClone;
550
- handle.onmousedown = function (e) {
551
- // 获取panel当前信息
552
- const originW = panel.offsetWidth;
553
- const originH = panel.offsetHeight;
554
- const originX = panel.offsetLeft;
555
- const originY = panel.offsetTop;
556
- let changeW = false;
557
- let changeH = false;
558
- let changeX = false;
559
- let changeY = false;
560
- switch (dir) {
561
- case 's':
562
- changeH = true;
563
- break;
564
- case 'e':
565
- changeW = true;
566
- break;
567
- case 'n':
568
- changeY = true;
569
- changeH = true;
570
- break;
571
- case 'w':
572
- changeX = true;
573
- changeW = true;
574
- break;
575
- case 'se':
576
- changeW = true;
577
- changeH = true;
578
- break;
579
- case 'sw':
580
- changeX = true;
581
- changeW = true;
582
- changeH = true;
583
- break;
584
- case 'ne':
585
- changeY = true;
586
- changeW = true;
587
- changeH = true;
588
- break;
589
- case 'nw':
590
- changeX = true;
591
- changeY = true;
592
- changeW = true;
593
- changeH = true;
594
- break;
595
- }
596
- const originPosX = e.clientX;
597
- const originPosY = e.clientY;
598
- // boundary
599
- let minWidth;
600
- let minHeight;
601
- let maxWidth;
602
- let maxHeight;
603
- if (func_js.isArray(opts.minSize)) {
604
- minWidth = opts.minSize[0];
605
- minHeight = opts.minSize[1];
606
- }
607
- else if (func_js.isNumber(opts.minSize)) {
608
- minWidth = opts.minSize;
609
- minHeight = opts.minSize;
610
- }
611
- if (func_js.isArray(opts.maxSize)) {
612
- maxWidth = opts.maxSize[0];
613
- maxHeight = opts.maxSize[1];
614
- }
615
- else if (func_js.isNumber(opts.maxSize)) {
616
- maxWidth = opts.maxSize;
617
- maxHeight = opts.maxSize;
618
- }
619
- const minX = maxWidth ? originX - maxWidth + originW : null;
620
- const minY = maxHeight ? originY - maxHeight + originH : null;
621
- const maxX = minWidth ? originX + originW - minWidth : null;
622
- const maxY = minHeight ? originY + originH - minHeight : null;
623
- //ghost
624
- const ghost = opts.ghost;
625
- const ghostClass = opts.ghostClass;
626
- let ghostNode = null;
627
- //aspectRatio
628
- const aspectRatio = opts.aspectRatio;
629
- const panelStyle = panel.style;
630
- let style = panelStyle;
631
- let currentW = originW;
632
- let currentH = originH;
633
- let dragging = false;
634
- saveCursor();
635
- const dragListener = (ev) => {
636
- var _a;
637
- const offsetx = ev.clientX - originPosX;
638
- const offsety = ev.clientY - originPosY;
639
- if (!dragging) {
640
- if (Math.abs(offsetx) > THRESHOLD$2 || Math.abs(offsety) > THRESHOLD$2) {
641
- dragging = true;
642
- handle.classList.add(CLASS_RESIZABLE_HANDLE_ACTIVE);
643
- if (ghost) {
644
- if (func_js.isFunction(ghost)) {
645
- ghostNode = ghost();
646
- }
647
- else {
648
- ghostNode = panel.cloneNode(true);
649
- ghostNode.style.opacity = '0.3';
650
- ghostNode.style.pointerEvents = 'none';
651
- }
652
- if (ghostNode) {
653
- if (ghostClass) {
654
- ghostNode.className =
655
- ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
656
- }
657
- (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
658
- func_js.call(onClone, ghostNode, e);
804
+ bindHandle(handle, dir, panel, opts) {
805
+ const onStart = opts.onStart;
806
+ const onResize = opts.onResize;
807
+ const onEnd = opts.onEnd;
808
+ const onClone = opts.onClone;
809
+ const uiik = this;
810
+ this.addPointerDown(handle, ({ ev, onPointerStart, onPointerMove, onPointerEnd }) => {
811
+ const onPointerDown = opts.onPointerDown;
812
+ if (onPointerDown && onPointerDown(ev) === false)
813
+ return;
814
+ let matrixInfo = getMatrixInfo(panel);
815
+ const offset = getRectInContainer(panel, panel.parentElement);
816
+ const offsetParentRect = panel.parentElement.getBoundingClientRect();
817
+ const offsetParentCStyle = window.getComputedStyle(panel.parentElement);
818
+ const panelCStyle = window.getComputedStyle(panel);
819
+ const originW = parseFloat(panelCStyle.width);
820
+ const originH = parseFloat(panelCStyle.height);
821
+ const originX = offset.x;
822
+ const originY = offset.y;
823
+ let changeW = false;
824
+ let changeH = false;
825
+ let changeX = false;
826
+ let changeY = false;
827
+ let toTransformOrigin = "";
828
+ switch (dir) {
829
+ case "s":
830
+ changeH = true;
831
+ break;
832
+ case "e":
833
+ changeW = true;
834
+ break;
835
+ case "se":
836
+ changeW = true;
837
+ changeH = true;
838
+ break;
839
+ case "n":
840
+ changeX = true;
841
+ changeY = true;
842
+ changeH = true;
843
+ toTransformOrigin = "0 0";
844
+ break;
845
+ case "w":
846
+ changeX = true;
847
+ changeY = true;
848
+ changeW = true;
849
+ toTransformOrigin = "0 0";
850
+ break;
851
+ case "sw":
852
+ case "ne":
853
+ case "nw":
854
+ changeX = true;
855
+ changeY = true;
856
+ changeW = true;
857
+ changeH = true;
858
+ toTransformOrigin = "0 0";
859
+ break;
860
+ }
861
+ let minWidth;
862
+ let minHeight;
863
+ let maxWidth;
864
+ let maxHeight;
865
+ if (is.isArray(opts.minSize)) {
866
+ minWidth = opts.minSize[0];
867
+ minHeight = opts.minSize[1];
868
+ }
869
+ else if (is.isNumber(opts.minSize)) {
870
+ minWidth = opts.minSize;
871
+ minHeight = opts.minSize;
872
+ }
873
+ if (is.isArray(opts.maxSize)) {
874
+ maxWidth = opts.maxSize[0];
875
+ maxHeight = opts.maxSize[1];
876
+ }
877
+ else if (is.isNumber(opts.maxSize)) {
878
+ maxWidth = opts.maxSize;
879
+ maxHeight = opts.maxSize;
880
+ }
881
+ const ghost = opts.ghost;
882
+ const ghostClass = opts.ghostClass;
883
+ let ghostNode = null;
884
+ const aspectRatio = opts.aspectRatio;
885
+ const panelStyle = panel.style;
886
+ let style = panelStyle;
887
+ let currentW = originW;
888
+ let currentH = originH;
889
+ let transformer;
890
+ let lastX = 0, lastY = 0;
891
+ let originalTransformOrigin = "";
892
+ let originVertex;
893
+ let vertexBeforeTransform;
894
+ let currentVertex;
895
+ let refPoint;
896
+ let k1;
897
+ onPointerStart(function (args) {
898
+ var _a;
899
+ const { ev } = args;
900
+ handle.classList.add(CLASS_RESIZABLE_HANDLE_ACTIVE);
901
+ if (ghost) {
902
+ if (is.isFunction(ghost)) {
903
+ ghostNode = ghost(panel);
904
+ }
905
+ else {
906
+ ghostNode = panel.cloneNode(true);
907
+ ghostNode.style.opacity = "0.3";
908
+ ghostNode.style.pointerEvents = "none";
909
+ }
910
+ if (ghostNode) {
911
+ if (ghostClass) {
912
+ ghostNode.className =
913
+ ghostNode.className.replace(ghostClass, "") +
914
+ " " +
915
+ ghostClass;
659
916
  }
660
- style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
917
+ (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
918
+ transformer = wrapper(ghostNode);
919
+ onClone && onClone({ clone: ghostNode }, ev);
661
920
  }
662
- lockPage();
663
- setCursor(handle.dataset.cursor || '');
664
- func_js.call(onStart, originW, originH);
921
+ style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
665
922
  }
666
923
  else {
667
- ev.preventDefault();
668
- return false;
924
+ transformer = wrapper(panel);
669
925
  }
670
- }
671
- let w = originW;
672
- let h = originH;
673
- let y = originY;
674
- let x = originX;
675
- if (changeW) {
676
- w = originW + offsetx * (changeX ? -1 : 1);
677
- if (minWidth && w < minWidth)
678
- w = minWidth;
679
- if (maxWidth && w > maxWidth)
680
- w = maxWidth;
681
- }
682
- if (changeH) {
683
- h = originH + offsety * (changeY ? -1 : 1);
684
- if (minHeight && h < minHeight)
685
- h = minHeight;
686
- if (maxHeight && h > maxHeight)
687
- h = maxHeight;
688
- }
689
- if (changeY) {
690
- y = originY + offsety;
691
- if (minY && y < minY)
692
- y = minY;
693
- if (maxY && y > maxY)
694
- y = maxY;
695
- }
696
- if (changeX) {
697
- x = originX + offsetx;
698
- if (minX && x < minX)
699
- x = minX;
700
- if (maxX && x > maxX)
701
- x = maxX;
702
- }
703
- if (aspectRatio) {
704
- if (changeW) {
705
- style.width = w + 'px';
706
- style.height = w / aspectRatio + 'px';
707
- }
708
- if (changeH && dir !== 'sw') {
709
- if (dir === 'nw') {
710
- y = originY - w / aspectRatio + originH;
711
- }
712
- else {
713
- style.width = h * aspectRatio + 'px';
714
- style.height = h + 'px';
715
- }
926
+ const { x, y, sx, sy } = getCenterXy(panel);
927
+ let centerX = x, centerY = y;
928
+ const deg = matrixInfo.angle * ONE_ANG;
929
+ originVertex = [
930
+ { x: 0, y: 0 },
931
+ { x: originW, y: 0 },
932
+ { x: 0, y: originH },
933
+ { x: originW, y: originH },
934
+ ];
935
+ currentVertex = vertexBeforeTransform = collection.map(originVertex, ({ x, y }) => {
936
+ const nx = (x - centerX + sx) * Math.cos(deg) -
937
+ (y - centerY + sy) * Math.sin(deg);
938
+ const ny = (x - centerX + sx) * Math.sin(deg) +
939
+ (y - centerY + sy) * Math.cos(deg);
940
+ return { x: centerX + nx, y: centerY + ny };
941
+ });
942
+ switch (dir) {
943
+ case "s":
944
+ case "e":
945
+ case "se":
946
+ refPoint = currentVertex[0];
947
+ break;
948
+ case "n":
949
+ case "w":
950
+ case "nw":
951
+ refPoint = currentVertex[3];
952
+ break;
953
+ case "sw":
954
+ refPoint = currentVertex[1];
955
+ break;
956
+ case "ne":
957
+ refPoint = currentVertex[2];
958
+ break;
716
959
  }
717
- }
718
- else {
719
- if (changeW) {
720
- style.width = w + 'px';
960
+ k1 =
961
+ (currentVertex[1].y - refPoint.y) /
962
+ (currentVertex[1].x - refPoint.x);
963
+ style.transition = "none";
964
+ originalTransformOrigin = style.transformOrigin;
965
+ if (toTransformOrigin) {
966
+ style.transformOrigin = toTransformOrigin;
721
967
  }
722
- if (changeH) {
723
- style.height = h + 'px';
968
+ else {
969
+ style.transformOrigin = `${centerX - transformer.x}px ${centerY - transformer.y}px`;
724
970
  }
725
- }
726
- if (changeY) {
727
- style.top = y + 'px';
728
- }
729
- if (changeX) {
730
- style.left = x + 'px';
731
- }
732
- currentW = w;
733
- currentH = h;
734
- func_js.call(onResize, w, h);
735
- ev.preventDefault();
736
- return false;
737
- };
738
- const dragEndListener = (ev) => {
739
- var _a, _b;
740
- document.removeEventListener('mousemove', dragListener, false);
741
- document.removeEventListener('mouseup', dragEndListener, false);
742
- window.removeEventListener('blur', dragEndListener, false);
743
- if (ghost && ghostNode) {
744
- ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
745
- panelStyle.left = ghostNode.style.left;
746
- panelStyle.top = ghostNode.style.top;
747
- panelStyle.width = ghostNode.style.width;
748
- panelStyle.height = ghostNode.style.height;
749
- }
750
- if (dragging) {
751
- handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
752
- unlockPage();
753
- restoreCursor();
754
- func_js.call(onEnd, currentW, currentH);
755
- }
756
- };
757
- document.addEventListener('mousemove', dragListener, false);
758
- document.addEventListener('mouseup', dragEndListener, false);
759
- window.addEventListener('blur', dragEndListener, false);
760
- e.preventDefault();
761
- return false;
762
- };
763
- }
764
- function initHandle$1(panel, opts) {
765
- // create handles
766
- const handleSize = opts.handleSize;
767
- const offset = opts.offset || 0;
768
- func_js.each(opts.dir || ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'], (dir) => {
769
- const handle = document.createElement('div');
770
- handle.classList.add(CLASS_RESIZABLE_HANDLE, CLASS_RESIZABLE_HANDLE_DIR + dir);
771
- handle.setAttribute('name', 'handle');
772
- let css = '';
773
- switch (dir) {
774
- case 'n':
775
- css = `left:0px;top:${-offset}px;width:100%;height:${handleSize}px;`;
776
- break;
777
- case 's':
778
- css = `left:0px;bottom:${-offset}px;width:100%;height:${handleSize}px;`;
779
- break;
780
- case 'w':
781
- css = `top:0px;left:${-offset}px;width:${handleSize}px;height:100%;`;
782
- break;
783
- case 'e':
784
- css = `top:0px;right:${-offset}px;width:${handleSize}px;height:100%;`;
785
- break;
786
- default:
787
- css = `width:${handleSize}px;height:${handleSize}px;z-index:9;`;
971
+ onStart && onStart.call(uiik, { w: originW, h: originH }, ev);
972
+ });
973
+ onPointerMove((args) => {
974
+ const { ev } = args;
975
+ const currentXy = getPointInContainer(ev, panel.parentElement, offsetParentRect, offsetParentCStyle);
976
+ let newX = currentXy.x;
977
+ let newY = currentXy.y;
978
+ let angle = Math.atan2(newY - refPoint.y, newX - refPoint.x) * ONE_RAD -
979
+ matrixInfo.angle;
980
+ let hyLen = Math.sqrt((newX - refPoint.x) * (newX - refPoint.x) +
981
+ (newY - refPoint.y) * (newY - refPoint.y));
982
+ let pl1 = Math.abs(k1 === Infinity
983
+ ? newY - refPoint.y
984
+ : hyLen * Math.cos(angle * ONE_ANG));
985
+ let pl2 = Math.sqrt(hyLen * hyLen - pl1 * pl1);
986
+ let w = originW;
987
+ let h = originH;
988
+ let y = originY;
989
+ let x = originX;
990
+ let angl = 0;
788
991
  switch (dir) {
789
- case 'ne':
790
- css += `top:${-offset}px;right:${-offset}px;`;
992
+ case "s":
993
+ h = pl2;
994
+ break;
995
+ case "e":
996
+ w = pl1;
997
+ break;
998
+ case "se":
999
+ w = pl1;
1000
+ h = pl2;
1001
+ break;
1002
+ case "n":
1003
+ h = pl2;
1004
+ angl =
1005
+ Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1006
+ let plh;
1007
+ if (angl === 90) {
1008
+ h = newY - currentVertex[2].y;
1009
+ x = currentVertex[2].x;
1010
+ y = newY;
1011
+ }
1012
+ else if (currentVertex[2].y > currentVertex[0].y) {
1013
+ plh = h * Math.cos(angl * ONE_ANG);
1014
+ x = currentVertex[2].x + plh;
1015
+ y = currentVertex[2].y - Math.sqrt(h * h - plh * plh);
1016
+ }
1017
+ else {
1018
+ plh = h * Math.cos((180 - angl) * ONE_ANG);
1019
+ x = currentVertex[2].x - plh;
1020
+ y = currentVertex[2].y + Math.sqrt(h * h - plh * plh);
1021
+ }
1022
+ break;
1023
+ case "w":
1024
+ w = pl1;
1025
+ angl =
1026
+ Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1027
+ let plw;
1028
+ if (angl === 0) {
1029
+ w = newX - currentVertex[1].x;
1030
+ x = newX;
1031
+ y = currentVertex[1].y;
1032
+ }
1033
+ else if (currentVertex[1].y > currentVertex[0].y) {
1034
+ plw = w * Math.cos((180 - angl) * ONE_ANG);
1035
+ x = currentVertex[1].x - plw;
1036
+ y = currentVertex[1].y - Math.sqrt(w * w - plw * plw);
1037
+ }
1038
+ else {
1039
+ plw = w * Math.cos(angl * ONE_ANG);
1040
+ x = currentVertex[1].x + plw;
1041
+ y = currentVertex[1].y + Math.sqrt(w * w - plw * plw);
1042
+ }
791
1043
  break;
792
- case 'nw':
793
- css += `top:${-offset}px;left:${-offset}px;`;
1044
+ case "nw":
1045
+ w = pl1;
1046
+ h = pl2;
1047
+ x = newX;
1048
+ y = newY;
1049
+ if (matrixInfo.angle === 180) {
1050
+ w = newX - currentVertex[3].x;
1051
+ h = newY - currentVertex[3].y;
1052
+ }
1053
+ break;
1054
+ case "sw":
1055
+ w = pl1;
1056
+ h = pl2;
1057
+ angl =
1058
+ Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1059
+ let plw1;
1060
+ if (angl === 0) {
1061
+ x = newX;
1062
+ y = currentVertex[0].y;
1063
+ }
1064
+ else if (currentVertex[1].y > currentVertex[0].y) {
1065
+ plw1 = w * Math.cos((180 - angl) * ONE_ANG);
1066
+ x = currentVertex[1].x - plw1;
1067
+ y = currentVertex[1].y - Math.sqrt(w * w - plw1 * plw1);
1068
+ }
1069
+ else {
1070
+ plw1 = w * Math.cos((180 - angl) * ONE_ANG);
1071
+ x = currentVertex[1].x - plw1;
1072
+ y = currentVertex[1].y + Math.sqrt(w * w - plw1 * plw1);
1073
+ }
794
1074
  break;
795
- case 'se':
796
- css += `bottom:${-offset}px;right:${-offset}px;`;
1075
+ case "ne":
1076
+ w = pl1;
1077
+ h = pl2;
1078
+ angl =
1079
+ Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1080
+ let plne;
1081
+ if (angl === 0) {
1082
+ x = newX;
1083
+ y = currentVertex[0].y;
1084
+ }
1085
+ else if (currentVertex[1].x > currentVertex[0].x) {
1086
+ plne = h * Math.cos((180 - angl) * ONE_ANG);
1087
+ x = currentVertex[2].x - plne;
1088
+ y = currentVertex[2].y - Math.sqrt(h * h - plne * plne);
1089
+ }
1090
+ else {
1091
+ plne = h * Math.cos(angl * ONE_ANG);
1092
+ x = currentVertex[2].x + plne;
1093
+ y = currentVertex[2].y + Math.sqrt(h * h - plne * plne);
1094
+ }
797
1095
  break;
798
- case 'sw':
799
- css += `bottom:${-offset}px;left:${-offset}px;`;
800
1096
  }
1097
+ if (changeW) {
1098
+ if (minWidth && w < minWidth)
1099
+ w = minWidth;
1100
+ if (maxWidth && w > maxWidth)
1101
+ w = maxWidth;
1102
+ }
1103
+ if (changeH) {
1104
+ if (minHeight && h < minHeight)
1105
+ h = minHeight;
1106
+ if (maxHeight && h > maxHeight)
1107
+ h = maxHeight;
1108
+ }
1109
+ if (aspectRatio) {
1110
+ if (changeW) {
1111
+ style.width = w + "px";
1112
+ style.height = w / aspectRatio + "px";
1113
+ }
1114
+ if (changeH && dir !== "sw") {
1115
+ if (dir === "nw") {
1116
+ y = originY - w / aspectRatio + originH;
1117
+ }
1118
+ else {
1119
+ style.width = h * aspectRatio + "px";
1120
+ style.height = h + "px";
1121
+ }
1122
+ }
1123
+ }
1124
+ else {
1125
+ if (changeW) {
1126
+ style.width = w + "px";
1127
+ }
1128
+ if (changeH) {
1129
+ style.height = h + "px";
1130
+ }
1131
+ }
1132
+ if (changeY) {
1133
+ transformer.moveToY(y);
1134
+ }
1135
+ if (changeX) {
1136
+ transformer.moveToX(x);
1137
+ }
1138
+ lastX = x;
1139
+ lastY = y;
1140
+ currentW = w;
1141
+ currentH = h;
1142
+ onResize &&
1143
+ onResize.call(uiik, { w, h, ow: w - originW, oh: h - originH }, ev);
1144
+ });
1145
+ onPointerEnd((args) => {
1146
+ var _a, _b;
1147
+ const { ev } = args;
1148
+ if (ghost && ghostNode) {
1149
+ ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) &&
1150
+ ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
1151
+ panelStyle.left = ghostNode.style.left;
1152
+ panelStyle.top = ghostNode.style.top;
1153
+ moveTo(panel, lastX / matrixInfo.scale, lastY / matrixInfo.scale);
1154
+ panelStyle.width = ghostNode.style.width;
1155
+ panelStyle.height = ghostNode.style.height;
1156
+ }
1157
+ panel.style.transformOrigin = originalTransformOrigin;
1158
+ const { x, y, sx, sy } = getCenterXy(panel);
1159
+ let centerX = x, centerY = y;
1160
+ const deg = matrixInfo.angle * ONE_ANG;
1161
+ const currentVertex = collection.map(originVertex, ({ x, y }) => {
1162
+ const nx = (x - centerX + sx) * Math.cos(deg) -
1163
+ (y - centerY + sy) * Math.sin(deg);
1164
+ const ny = (x - centerX + sx) * Math.sin(deg) +
1165
+ (y - centerY + sy) * Math.cos(deg);
1166
+ return { x: centerX + nx, y: centerY + ny };
1167
+ });
1168
+ if (changeX || changeY) {
1169
+ transformer.moveTo(transformer.x - (currentVertex[0].x - lastX), transformer.y - (currentVertex[0].y - lastY));
1170
+ }
1171
+ else {
1172
+ transformer.moveTo(transformer.x - (currentVertex[0].x - vertexBeforeTransform[0].x), transformer.y - (currentVertex[0].y - vertexBeforeTransform[0].y));
1173
+ }
1174
+ handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1175
+ onEnd && onEnd.call(uiik, { w: currentW, h: currentH }, ev);
1176
+ });
1177
+ }, {
1178
+ threshold: THRESHOLD$3,
1179
+ lockPage: true,
1180
+ });
1181
+ }
1182
+ initHandle(panel) {
1183
+ const opts = this.opts;
1184
+ let handleStr = opts.handle;
1185
+ let handles;
1186
+ if (is.isString(handleStr)) {
1187
+ handles = document.querySelectorAll(handleStr);
801
1188
  }
802
- bindHandle$1(handle, dir, panel, opts);
803
- handle.style.cssText = `position: absolute;cursor: ${dir}-resize;` + css;
804
- handle.dataset.cursor = `${dir}-resize`;
805
- panel.appendChild(handle);
806
- });
1189
+ else if (is.isFunction(handleStr)) {
1190
+ handles = handleStr(panel);
1191
+ }
1192
+ if (!handles) {
1193
+ console.error('Can not find handles with "' + panel.outerHTML + '"');
1194
+ return;
1195
+ }
1196
+ handles = is.isArrayLike(handles) ? handles : [handles];
1197
+ collection.each(handles, (h) => {
1198
+ const className = h.getAttribute("class") || "";
1199
+ const matchRs = className.match(EXP_DIR);
1200
+ let dir = "se";
1201
+ if (matchRs) {
1202
+ dir = matchRs.groups.dir;
1203
+ }
1204
+ h.classList.add(CLASS_RESIZABLE_HANDLE);
1205
+ this.bindHandle(h, dir, panel, opts);
1206
+ h.style.cursor = `${dir}-resize`;
1207
+ h.dataset.cursor = `${dir}-resize`;
1208
+ h.setAttribute("name", "handle");
1209
+ });
1210
+ }
807
1211
  }
808
- /**
809
- * Make els resizable
810
- * @param els selector string / html element
811
- * @param opts
812
- * @returns
813
- */
814
1212
  function newResizable(els, opts) {
815
1213
  return new Resizable(els, opts);
816
1214
  }
817
1215
 
818
- var _Draggable_handleMap;
1216
+ var _Draggable_instances, _Draggable_handleMap, _Draggable_container, _Draggable_initStyle;
819
1217
  const DRAGGER_GROUPS = {};
820
1218
  const CLASS_DRAGGABLE = "uii-draggable";
821
1219
  const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
822
1220
  const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
823
1221
  const CLASS_DRAGGABLE_GHOST = "uii-draggable-ghost";
824
- /**
825
- * 用于表示一个或多个可拖动元素的定义
826
- * > 可用CSS接口
827
- * - .uii-draggable
828
- * - .uii-draggable-handle
829
- * - .uii-draggable-active
830
- * - .uii-draggable-ghost
831
- * @public
832
- */
833
1222
  class Draggable extends Uii {
834
1223
  constructor(els, opts) {
835
- super(els, func_js.assign({
836
- container: false,
1224
+ super(els, object.assign({
1225
+ containment: false,
1226
+ watch: true,
837
1227
  threshold: 0,
838
1228
  ghost: false,
839
1229
  direction: "",
@@ -842,9 +1232,11 @@
842
1232
  tolerance: 10,
843
1233
  }
844
1234
  }, opts));
1235
+ _Draggable_instances.add(this);
845
1236
  _Draggable_handleMap.set(this, new WeakMap());
1237
+ _Draggable_container.set(this, null);
846
1238
  if (this.opts.handle) {
847
- func_js.each(this.ele, (el) => {
1239
+ collection.each(this.ele, (el) => {
848
1240
  const h = el.querySelector(this.opts.handle);
849
1241
  if (!h) {
850
1242
  console.error('No handle found "' + this.opts.handle + '"');
@@ -854,465 +1246,428 @@
854
1246
  });
855
1247
  }
856
1248
  this.onOptionChanged(this.opts);
857
- //put into group
858
1249
  if (this.opts.group) {
859
1250
  if (!DRAGGER_GROUPS[this.opts.group]) {
860
1251
  DRAGGER_GROUPS[this.opts.group] = [];
861
1252
  }
862
1253
  DRAGGER_GROUPS[this.opts.group].push(...this.ele);
863
1254
  }
864
- func_js.each(this.ele, (el) => {
865
- bindEvent(this.registerEvent.bind(this), el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
866
- if (func_js.isDefined(this.opts.type))
867
- el.dataset.dropType = this.opts.type;
868
- el.classList.toggle(CLASS_DRAGGABLE, true);
869
- const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
870
- ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
871
- if (func_js.isDefined(this.opts.cursor)) {
872
- el.style.cursor = this.opts.cursor.default || 'move';
873
- if (func_js.isDefined(this.opts.cursor.over)) {
874
- el.dataset.cursorOver = this.opts.cursor.over;
875
- el.dataset.cursorActive = this.opts.cursor.active || 'move';
876
- }
1255
+ __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initStyle).call(this, this.ele);
1256
+ if (this.opts.containment) {
1257
+ if (is.isBoolean(this.opts.containment)) {
1258
+ __classPrivateFieldSet(this, _Draggable_container, is.isEmpty(this.ele) ? null : this.ele[0].parentElement, "f");
877
1259
  }
878
- });
879
- }
880
- /**
881
- * @internal
882
- */
883
- onOptionChanged(opts) {
884
- const droppable = opts.droppable;
885
- if (!func_js.isFunction(droppable)) {
886
- if (func_js.isUndefined(droppable)) {
887
- opts.droppable = () => { };
1260
+ else if (is.isString(this.opts.containment)) {
1261
+ __classPrivateFieldSet(this, _Draggable_container, document.querySelector(this.opts.containment), "f");
888
1262
  }
889
- else if (func_js.isString(droppable)) {
890
- opts.droppable = () => document.querySelectorAll(droppable);
1263
+ else if (is.isElement(this.opts.containment)) {
1264
+ __classPrivateFieldSet(this, _Draggable_container, this.opts.containment, "f");
891
1265
  }
892
- else if (func_js.isArrayLike(droppable)) {
893
- opts.droppable = () => droppable;
1266
+ }
1267
+ if (this.opts.watch && this.eleString) {
1268
+ let con;
1269
+ if (is.isString(this.opts.watch)) {
1270
+ con = document.querySelector(this.opts.watch);
894
1271
  }
895
- else if (func_js.isElement(droppable)) {
896
- opts.droppable = () => [droppable];
1272
+ else {
1273
+ con = is.isEmpty(this.ele) ? null : this.ele[0].parentElement;
897
1274
  }
1275
+ this.bindEvent(con || document.body, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
898
1276
  }
899
- }
900
- }
901
- _Draggable_handleMap = new WeakMap();
902
- function bindEvent(registerEvent, el, opts, handleMap) {
903
- registerEvent(el, "mousedown", (e) => {
904
- var _a;
905
- // get options
906
- let dragDom = e.currentTarget;
907
- let t = e.target;
908
- if (!t)
909
- return;
910
- let handle = handleMap.get(dragDom);
911
- if (handle && !handle.contains(t)) {
912
- return;
913
- }
914
- const filter = opts.filter;
915
- //check filter
916
- if (filter) {
917
- if (func_js.some(el.querySelectorAll(filter), ele => ele.contains(t)))
918
- return;
919
- }
920
- const computedStyle = window.getComputedStyle(dragDom);
921
- const container = dragDom.offsetParent || document.body;
922
- const inContainer = opts.container;
923
- const threshold = opts.threshold || 0;
924
- const ghost = opts.ghost;
925
- const ghostClass = opts.ghostClass;
926
- const direction = opts.direction;
927
- const onStart = opts.onStart;
928
- const onDrag = opts.onDrag;
929
- const onEnd = opts.onEnd;
930
- const onClone = opts.onClone;
931
- const originalZIndex = computedStyle.zIndex;
932
- let zIndex = opts.zIndex || originalZIndex;
933
- const classes = opts.classes || '';
934
- const group = opts.group;
935
- if (group) {
936
- let i = -1;
937
- func_js.each(DRAGGER_GROUPS[group], el => {
938
- const z = parseInt(window.getComputedStyle(el).zIndex) || 0;
939
- if (z > i)
940
- i = z;
941
- });
942
- zIndex = i + 1;
943
- }
944
- const scroll = opts.scroll;
945
- const scrollSpeed = opts.scrollSpeed || 10;
946
- let gridX, gridY;
947
- const grid = opts.grid;
948
- if (func_js.isArray(grid)) {
949
- gridX = grid[0];
950
- gridY = grid[1];
951
- }
952
- else if (func_js.isNumber(grid)) {
953
- gridX = gridY = grid;
954
- }
955
- const snapOn = opts.snap;
956
- let snappable;
957
- const snapTolerance = ((_a = opts.snapOptions) === null || _a === void 0 ? void 0 : _a.tolerance) || 10;
958
- const onSnap = opts.onSnap;
959
- let lastSnapDirY = "", lastSnapDirX = "";
960
- let lastSnapping = "";
961
- let parentOffsetX = 0, parentOffsetY = 0;
962
- if (snapOn) {
963
- snappable = func_js.map(document.querySelectorAll(snapOn), (el) => {
964
- let offX = 0, offY = 0;
965
- func_js.closest(el, (el) => {
966
- offX += el.offsetLeft;
967
- offY += el.offsetTop;
968
- return false;
969
- }, "offsetParent");
970
- return {
971
- x1: offX,
972
- y1: offY,
973
- x2: offX + el.offsetWidth,
974
- y2: offY + el.offsetHeight,
975
- el: el,
976
- };
1277
+ else {
1278
+ collection.each(this.ele, (el) => {
1279
+ this.bindEvent(el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
977
1280
  });
978
- func_js.closest(dragDom, (el, times) => {
979
- if (times > 0) {
980
- parentOffsetX += el.offsetLeft;
981
- parentOffsetY += el.offsetTop;
982
- }
983
- return false;
984
- }, "offsetParent");
985
- }
986
- const originW = dragDom.offsetWidth + parseFloat(computedStyle.borderLeftWidth) + parseFloat(computedStyle.borderRightWidth);
987
- const originH = dragDom.offsetHeight + parseFloat(computedStyle.borderTopWidth) + parseFloat(computedStyle.borderBottomWidth);
988
- // boundary
989
- let minX = 0;
990
- let minY = 0;
991
- let maxX = 0;
992
- let maxY = 0;
993
- if (inContainer) {
994
- maxX = container.scrollWidth - originW;
995
- maxY = container.scrollHeight - originH;
996
- }
997
- if (maxX < 0)
998
- maxX = 0;
999
- if (maxY < 0)
1000
- maxY = 0;
1001
- //start point
1002
- const rect = container.getBoundingClientRect();
1003
- const offset = getOffset(t, container);
1004
- const ox = e.offsetX || 0;
1005
- const oy = e.offsetY || 0;
1006
- let hitPosX = offset.x + ox + container.scrollLeft;
1007
- let hitPosY = offset.y + oy + container.scrollTop;
1008
- let cursorX = ox, cursorY = e.offsetY;
1009
- if (e.target !== dragDom) {
1010
- const offset = getOffset(t, dragDom);
1011
- const style = window.getComputedStyle(t);
1012
- cursorX = offset.x + ox + parseFloat(style.borderLeftWidth);
1013
- cursorY = offset.y + oy + parseFloat(style.borderTopWidth);
1014
1281
  }
1015
- const cursorAt = opts.cursorAt;
1016
- if (cursorAt) {
1017
- const l = cursorAt.left;
1018
- const t = cursorAt.top;
1019
- if (func_js.isString(l)) {
1020
- cursorX = parseFloat(l) / 100 * dragDom.offsetWidth;
1282
+ }
1283
+ bindEvent(bindTarget, opts, handleMap) {
1284
+ const container = __classPrivateFieldGet(this, _Draggable_container, "f");
1285
+ let draggableList = this.ele;
1286
+ const eleString = this.eleString;
1287
+ const initStyle = __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initStyle).bind(this);
1288
+ this.addPointerDown(bindTarget, ({ ev, currentTarget, currentStyle, currentCStyle, pointX, pointY, onPointerStart, onPointerMove, onPointerEnd }) => {
1289
+ var _a;
1290
+ let t = ev.target;
1291
+ if (!t)
1292
+ return;
1293
+ if (opts.watch && eleString) {
1294
+ draggableList = bindTarget.querySelectorAll(eleString);
1295
+ initStyle(draggableList);
1021
1296
  }
1022
- else {
1023
- cursorX = l;
1297
+ let findRs = collection.find(draggableList, el => el.contains(t));
1298
+ if (!findRs)
1299
+ return;
1300
+ const dragDom = findRs;
1301
+ let handle = handleMap.get(dragDom);
1302
+ if (handle && !handle.contains(t)) {
1303
+ return;
1024
1304
  }
1025
- if (func_js.isString(t)) {
1026
- cursorY = parseFloat(t) / 100 * dragDom.offsetWidth;
1305
+ const onPointerDown = opts.onPointerDown;
1306
+ if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
1307
+ return;
1308
+ const filter = opts.filter;
1309
+ if (filter) {
1310
+ if (collection.some(dragDom.querySelectorAll(filter), ele => ele.contains(t)))
1311
+ return;
1027
1312
  }
1028
- else {
1029
- cursorY = t;
1313
+ const offsetParent = dragDom instanceof HTMLElement ? dragDom.offsetParent || document.body : dragDom.ownerSVGElement;
1314
+ const offsetParentRect = offsetParent.getBoundingClientRect();
1315
+ const offsetParentCStyle = window.getComputedStyle(offsetParent);
1316
+ const offsetXy = getPointInContainer(ev, dragDom);
1317
+ let offsetPointX = offsetXy.x;
1318
+ let offsetPointY = offsetXy.y;
1319
+ const matrixInfo = getMatrixInfo(dragDom);
1320
+ const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1321
+ if (matrixInfo.angle != 0) {
1322
+ offsetPointX = currentXy.x - matrixInfo.x;
1323
+ offsetPointY = currentXy.y - matrixInfo.y;
1324
+ }
1325
+ const inContainer = !!container;
1326
+ const ghost = opts.ghost;
1327
+ const ghostClass = opts.ghostClass;
1328
+ const direction = opts.direction;
1329
+ const onStart = opts.onStart;
1330
+ const onDrag = opts.onDrag;
1331
+ const onEnd = opts.onEnd;
1332
+ const onClone = opts.onClone;
1333
+ const originalZIndex = currentCStyle.zIndex;
1334
+ let zIndex = opts.zIndex || originalZIndex;
1335
+ const classes = opts.classes || '';
1336
+ const group = opts.group;
1337
+ if (group) {
1338
+ let i = -1;
1339
+ collection.each(DRAGGER_GROUPS[group], el => {
1340
+ const z = parseInt(currentCStyle.zIndex) || 0;
1341
+ if (z > i)
1342
+ i = z;
1343
+ });
1344
+ zIndex = i + 1;
1345
+ }
1346
+ const scroll = opts.scroll;
1347
+ const scrollSpeed = opts.scrollSpeed || 10;
1348
+ let gridX, gridY;
1349
+ const grid = opts.grid;
1350
+ if (is.isArray(grid)) {
1351
+ gridX = grid[0];
1352
+ gridY = grid[1];
1353
+ }
1354
+ else if (is.isNumber(grid)) {
1355
+ gridX = gridY = grid;
1356
+ }
1357
+ const snapOn = opts.snap;
1358
+ let snappable;
1359
+ const snapTolerance = ((_a = opts.snapOptions) === null || _a === void 0 ? void 0 : _a.tolerance) || 10;
1360
+ const onSnap = opts.onSnap;
1361
+ let lastSnapDirY = "", lastSnapDirX = "";
1362
+ let lastSnapping = "";
1363
+ if (snapOn) {
1364
+ snappable = collection.map((container || document).querySelectorAll(snapOn), (el) => {
1365
+ const { x, y, w, h } = getRectInContainer(el, offsetParent);
1366
+ return {
1367
+ x1: x,
1368
+ y1: y,
1369
+ x2: x + w,
1370
+ y2: y + h,
1371
+ el: el,
1372
+ };
1373
+ });
1030
1374
  }
1031
- }
1032
- const style = dragDom.style;
1033
- let dragging = false;
1034
- let copyNode;
1035
- let timer = null;
1036
- let toLeft = false;
1037
- let toTop = false;
1038
- let toRight = false;
1039
- let toBottom = false;
1040
- saveCursor();
1041
- const dragListener = (ev) => {
1042
- var _a;
1043
- const newX = ev.clientX - rect.x + container.scrollLeft;
1044
- const newY = ev.clientY - rect.y + container.scrollTop;
1045
- let offsetx = newX - hitPosX;
1046
- let offsety = newY - hitPosY;
1047
- if (!dragging) {
1048
- if (Math.abs(offsetx) > threshold || Math.abs(offsety) > threshold) {
1049
- dragging = true;
1050
- if (ghost) {
1051
- if (func_js.isFunction(ghost)) {
1052
- copyNode = ghost(dragDom);
1053
- }
1054
- else {
1055
- copyNode = dragDom.cloneNode(true);
1056
- copyNode.style.opacity = "0.3";
1057
- copyNode.style.pointerEvents = "none";
1058
- copyNode.style.position = "absolute";
1059
- }
1060
- copyNode.style.left = dragDom.style.left;
1061
- copyNode.style.top = dragDom.style.top;
1062
- copyNode.style.zIndex = zIndex + '';
1063
- if (ghostClass) {
1064
- copyNode.classList.add(...func_js.compact(func_js.split(ghostClass, ' ')));
1065
- }
1066
- copyNode.classList.add(...func_js.compact(func_js.split(classes, ' ')));
1067
- copyNode.classList.toggle(CLASS_DRAGGABLE_GHOST, true);
1068
- (_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(copyNode);
1069
- if (onClone) {
1070
- onClone(copyNode, ev);
1071
- }
1375
+ const dragDomRect = dragDom.getBoundingClientRect();
1376
+ const originW = dragDomRect.width + parseFloat(currentCStyle.borderLeftWidth) + parseFloat(currentCStyle.borderRightWidth);
1377
+ const originH = dragDomRect.height + parseFloat(currentCStyle.borderTopWidth) + parseFloat(currentCStyle.borderBottomWidth);
1378
+ let minX = 0;
1379
+ let minY = 0;
1380
+ let maxX = 0;
1381
+ let maxY = 0;
1382
+ let originOffX = 0;
1383
+ let originOffY = 0;
1384
+ if (inContainer) {
1385
+ maxX = container.scrollWidth - originW;
1386
+ maxY = container.scrollHeight - originH;
1387
+ }
1388
+ if (maxX < 0)
1389
+ maxX = 0;
1390
+ if (maxY < 0)
1391
+ maxY = 0;
1392
+ let copyNode;
1393
+ let transformer;
1394
+ let timer = null;
1395
+ let toLeft = false;
1396
+ let toTop = false;
1397
+ let toRight = false;
1398
+ let toBottom = false;
1399
+ let endX = 0, endY = 0;
1400
+ onPointerStart(function (args) {
1401
+ var _a;
1402
+ const { ev } = args;
1403
+ if (ghost) {
1404
+ if (is.isFunction(ghost)) {
1405
+ copyNode = ghost(dragDom);
1072
1406
  }
1073
- //apply classes
1074
- dragDom.classList.add(...func_js.compact(func_js.split(classes, ' ')));
1075
- if (!copyNode)
1076
- dragDom.style.zIndex = zIndex + '';
1077
- dragDom.classList.toggle(CLASS_DRAGGABLE_ACTIVE, true);
1078
- func_js.call(onStart, dragDom, ev);
1079
- lockPage();
1080
- if (opts.cursor) {
1081
- setCursor(opts.cursor.active || 'move');
1407
+ else {
1408
+ copyNode = dragDom.cloneNode(true);
1409
+ copyNode.style.opacity = "0.3";
1410
+ copyNode.style.pointerEvents = "none";
1411
+ copyNode.style.position = "absolute";
1082
1412
  }
1083
- //notify
1084
- const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
1085
- dragDom.dispatchEvent(customEv);
1086
- }
1087
- else {
1088
- ev.preventDefault();
1089
- return false;
1090
- }
1091
- }
1092
- //edge detect
1093
- if (scroll) {
1094
- const ltX = ev.clientX - rect.x;
1095
- const ltY = ev.clientY - rect.y;
1096
- const rbX = rect.x + rect.width - ev.clientX;
1097
- const rbY = rect.y + rect.height - ev.clientY;
1098
- toLeft = ltX < EDGE_THRESHOLD;
1099
- toTop = ltY < EDGE_THRESHOLD;
1100
- toRight = rbX < EDGE_THRESHOLD;
1101
- toBottom = rbY < EDGE_THRESHOLD;
1102
- if (toLeft || toTop
1103
- ||
1104
- toRight || toBottom) {
1105
- if (!timer) {
1106
- timer = setInterval(() => {
1107
- if (toLeft) {
1108
- container.scrollLeft -= scrollSpeed;
1109
- }
1110
- else if (toRight) {
1111
- container.scrollLeft += scrollSpeed;
1112
- }
1113
- if (toTop) {
1114
- container.scrollTop -= scrollSpeed;
1115
- }
1116
- else if (toBottom) {
1117
- container.scrollTop += scrollSpeed;
1118
- }
1119
- }, 20);
1413
+ copyNode.style.zIndex = zIndex + '';
1414
+ if (ghostClass) {
1415
+ copyNode.classList.add(...array.compact(string.split(ghostClass, ' ')));
1120
1416
  }
1417
+ copyNode.classList.add(...array.compact(string.split(classes, ' ')));
1418
+ copyNode.classList.toggle(CLASS_DRAGGABLE_GHOST, true);
1419
+ (_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(copyNode);
1420
+ transformer = wrapper(copyNode);
1421
+ onClone && onClone({ clone: copyNode }, ev);
1121
1422
  }
1122
1423
  else {
1123
- if (timer) {
1124
- clearInterval(timer);
1125
- timer = null;
1126
- }
1424
+ transformer = wrapper(dragDom);
1127
1425
  }
1128
- }
1129
- let x = newX - cursorX;
1130
- let y = newY - cursorY;
1131
- //grid
1132
- if (func_js.isNumber(gridX) && func_js.isNumber(gridY)) {
1133
- x = ((x / gridX) >> 0) * gridX;
1134
- y = ((y / gridY) >> 0) * gridY;
1135
- }
1136
- if (inContainer) {
1137
- if (x < minX)
1138
- x = minX;
1139
- if (y < minY)
1140
- y = minY;
1141
- if (x > maxX)
1142
- x = maxX;
1143
- if (y > maxY)
1144
- y = maxY;
1145
- }
1146
- let canDrag = true;
1147
- let emitSnap = false;
1148
- if (snapOn) {
1149
- const currPageX1 = parentOffsetX + x;
1150
- const currPageY1 = parentOffsetY + y;
1151
- const currPageX2 = currPageX1 + originW;
1152
- const currPageY2 = currPageY1 + originH;
1153
- //check snappable
1154
- let snapX = NaN, snapY = NaN;
1155
- let targetX, targetY;
1156
- let snapDirX, snapDirY;
1157
- if (!direction || direction === "v") {
1158
- func_js.each(snappable, (data) => {
1159
- if (Math.abs(data.y1 - currPageY1) <= snapTolerance) {
1160
- //top parallel
1161
- snapY = data.y1;
1162
- snapDirY = "t2t";
1163
- }
1164
- else if (Math.abs(data.y2 - currPageY1) <= snapTolerance) {
1165
- //b2t
1166
- snapY = data.y2;
1167
- snapDirY = "t2b";
1168
- }
1169
- else if (Math.abs(data.y1 - currPageY2) <= snapTolerance) {
1170
- //t2b
1171
- snapY = data.y1 - originH;
1172
- snapDirY = "b2t";
1173
- }
1174
- else if (Math.abs(data.y2 - currPageY2) <= snapTolerance) {
1175
- //bottom parallel
1176
- snapY = data.y2 - originH;
1177
- snapDirY = "b2b";
1426
+ dragDom.classList.add(...array.compact(string.split(classes, ' ')));
1427
+ if (!copyNode)
1428
+ dragDom.style.zIndex = zIndex + '';
1429
+ dragDom.classList.toggle(CLASS_DRAGGABLE_ACTIVE, true);
1430
+ onStart && onStart({ draggable: dragDom, x: currentXy.x, y: currentXy.y }, ev);
1431
+ const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
1432
+ dragDom.dispatchEvent(customEv);
1433
+ });
1434
+ onPointerMove((args) => {
1435
+ const { ev, pointX, pointY, offX, offY } = args;
1436
+ const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1437
+ let newX = currentXy.x;
1438
+ let newY = currentXy.y;
1439
+ if (scroll) {
1440
+ const lX = pointX - offsetParentRect.x;
1441
+ const lY = pointY - offsetParentRect.y;
1442
+ const rX = offsetParentRect.x + offsetParentRect.width - pointX;
1443
+ const rY = offsetParentRect.y + offsetParentRect.height - pointY;
1444
+ toLeft = lX < EDGE_THRESHOLD;
1445
+ toTop = lY < EDGE_THRESHOLD;
1446
+ toRight = rX < EDGE_THRESHOLD;
1447
+ toBottom = rY < EDGE_THRESHOLD;
1448
+ if (toLeft || toTop
1449
+ ||
1450
+ toRight || toBottom) {
1451
+ if (!timer) {
1452
+ timer = setInterval(() => {
1453
+ if (toLeft) {
1454
+ offsetParent.scrollLeft -= scrollSpeed;
1455
+ }
1456
+ else if (toRight) {
1457
+ offsetParent.scrollLeft += scrollSpeed;
1458
+ }
1459
+ if (toTop) {
1460
+ offsetParent.scrollTop -= scrollSpeed;
1461
+ }
1462
+ else if (toBottom) {
1463
+ offsetParent.scrollTop += scrollSpeed;
1464
+ }
1465
+ }, 20);
1178
1466
  }
1179
- if (snapY) {
1180
- lastSnapDirY = snapDirY;
1181
- targetY = data.el;
1182
- return false;
1467
+ }
1468
+ else {
1469
+ if (timer) {
1470
+ clearInterval(timer);
1471
+ timer = null;
1183
1472
  }
1184
- });
1473
+ }
1185
1474
  }
1186
- if (!direction || direction === "h") {
1187
- func_js.each(snappable, (data) => {
1188
- if (Math.abs(data.x1 - currPageX1) <= snapTolerance) {
1189
- //left parallel
1190
- snapX = data.x1;
1191
- snapDirX = "l2l";
1192
- }
1193
- else if (Math.abs(data.x2 - currPageX1) <= snapTolerance) {
1194
- //r2l
1195
- snapX = data.x2;
1196
- snapDirX = "l2r";
1197
- }
1198
- else if (Math.abs(data.x1 - currPageX2) <= snapTolerance) {
1199
- //l2r
1200
- snapX = data.x1 - originW;
1201
- snapDirX = "r2l";
1202
- }
1203
- else if (Math.abs(data.x2 - currPageX2) <= snapTolerance) {
1204
- //right parallel
1205
- snapX = data.x2 - originW;
1206
- snapDirX = "r2r";
1207
- }
1208
- if (snapX) {
1209
- lastSnapDirX = snapDirX;
1210
- targetX = data.el;
1211
- return false;
1212
- }
1213
- });
1475
+ let x = newX - offsetPointX + 0;
1476
+ let y = newY - offsetPointY + 0;
1477
+ if (is.isNumber(gridX) && is.isNumber(gridY)) {
1478
+ x = ((x / gridX) >> 0) * gridX;
1479
+ y = ((y / gridY) >> 0) * gridY;
1214
1480
  }
1215
- if (snapX || snapY) {
1216
- if (snapX) {
1217
- x = snapX - parentOffsetX;
1481
+ if (inContainer) {
1482
+ if (originOffX + x < minX) {
1483
+ x = -0;
1218
1484
  }
1219
- if (snapY) {
1220
- y = snapY - parentOffsetY;
1485
+ if (originOffY + y < minY) {
1486
+ y = -0;
1221
1487
  }
1222
- if (onSnap && lastSnapping !== lastSnapDirX + "" + lastSnapDirY) {
1223
- setTimeout(() => {
1224
- //emit after relocate
1225
- onSnap(copyNode || dragDom, targetX, targetY, snapDirX, snapDirY);
1226
- }, 0);
1227
- lastSnapping = lastSnapDirX + "" + lastSnapDirY;
1488
+ if (originOffX + x > maxX) {
1489
+ x = maxX - originOffX;
1490
+ }
1491
+ if (originOffY + y > maxY) {
1492
+ y = maxY - originOffY;
1228
1493
  }
1229
- emitSnap = true;
1230
- }
1231
- else {
1232
- lastSnapDirX = lastSnapDirY = lastSnapping = "";
1233
- }
1234
- }
1235
- if (onDrag && !emitSnap) {
1236
- if (onDrag(dragDom, ev, offsetx, offsety, x, y) === false) {
1237
- canDrag = false;
1238
1494
  }
1239
- }
1240
- if (canDrag) {
1241
- if (copyNode) {
1242
- if (direction === "v") {
1243
- copyNode.style.top = `${y}px`;
1495
+ let canDrag = true;
1496
+ let emitSnap = false;
1497
+ if (snapOn) {
1498
+ const currPageX1 = x;
1499
+ const currPageY1 = y;
1500
+ const currPageX2 = currPageX1 + originW;
1501
+ const currPageY2 = currPageY1 + originH;
1502
+ let snapX = NaN, snapY = NaN;
1503
+ let targetX, targetY;
1504
+ let snapDirX, snapDirY;
1505
+ if (!direction || direction === "v") {
1506
+ collection.each(snappable, (data) => {
1507
+ if (Math.abs(data.y1 - currPageY1) <= snapTolerance) {
1508
+ snapY = data.y1;
1509
+ snapDirY = "t2t";
1510
+ }
1511
+ else if (Math.abs(data.y2 - currPageY1) <= snapTolerance) {
1512
+ snapY = data.y2;
1513
+ snapDirY = "t2b";
1514
+ }
1515
+ else if (Math.abs(data.y1 - currPageY2) <= snapTolerance) {
1516
+ snapY = data.y1 - originH;
1517
+ snapDirY = "b2t";
1518
+ }
1519
+ else if (Math.abs(data.y2 - currPageY2) <= snapTolerance) {
1520
+ snapY = data.y2 - originH;
1521
+ snapDirY = "b2b";
1522
+ }
1523
+ if (snapY) {
1524
+ lastSnapDirY = snapDirY;
1525
+ targetY = data.el;
1526
+ return false;
1527
+ }
1528
+ });
1244
1529
  }
1245
- else if (direction === "h") {
1246
- copyNode.style.left = `${x}px`;
1530
+ if (!direction || direction === "h") {
1531
+ collection.each(snappable, (data) => {
1532
+ if (Math.abs(data.x1 - currPageX1) <= snapTolerance) {
1533
+ snapX = data.x1;
1534
+ snapDirX = "l2l";
1535
+ }
1536
+ else if (Math.abs(data.x2 - currPageX1) <= snapTolerance) {
1537
+ snapX = data.x2;
1538
+ snapDirX = "l2r";
1539
+ }
1540
+ else if (Math.abs(data.x1 - currPageX2) <= snapTolerance) {
1541
+ snapX = data.x1 - originW;
1542
+ snapDirX = "r2l";
1543
+ }
1544
+ else if (Math.abs(data.x2 - currPageX2) <= snapTolerance) {
1545
+ snapX = data.x2 - originW;
1546
+ snapDirX = "r2r";
1547
+ }
1548
+ if (snapX) {
1549
+ lastSnapDirX = snapDirX;
1550
+ targetX = data.el;
1551
+ return false;
1552
+ }
1553
+ });
1554
+ }
1555
+ if (snapX || snapY) {
1556
+ if (snapX) {
1557
+ x = snapX;
1558
+ }
1559
+ if (snapY) {
1560
+ y = snapY;
1561
+ }
1562
+ if (onSnap && lastSnapping !== lastSnapDirX + "" + lastSnapDirY) {
1563
+ setTimeout(() => {
1564
+ onSnap({
1565
+ el: copyNode || dragDom,
1566
+ targetH: targetX,
1567
+ targetV: targetY,
1568
+ dirH: snapDirX,
1569
+ dirV: snapDirY,
1570
+ }, ev);
1571
+ }, 0);
1572
+ lastSnapping = lastSnapDirX + "" + lastSnapDirY;
1573
+ }
1574
+ emitSnap = true;
1247
1575
  }
1248
1576
  else {
1249
- copyNode.style.left = `${x}px`;
1250
- copyNode.style.top = `${y}px`;
1577
+ lastSnapDirX = lastSnapDirY = lastSnapping = "";
1251
1578
  }
1252
1579
  }
1253
- else {
1580
+ if (onDrag && !emitSnap) {
1581
+ if (onDrag({
1582
+ draggable: dragDom,
1583
+ ox: offX,
1584
+ oy: offY,
1585
+ x: x,
1586
+ y: y
1587
+ }, ev) === false) {
1588
+ canDrag = false;
1589
+ endX = x;
1590
+ endY = y;
1591
+ }
1592
+ }
1593
+ if (canDrag) {
1254
1594
  if (direction === "v") {
1255
- style.top = `${y}px`;
1595
+ transformer.moveToY(y);
1256
1596
  }
1257
1597
  else if (direction === "h") {
1258
- style.left = `${x}px`;
1598
+ transformer.moveToX(x);
1259
1599
  }
1260
1600
  else {
1261
- style.left = `${x}px`;
1262
- style.top = `${y}px`;
1601
+ transformer.moveTo(x, y);
1263
1602
  }
1603
+ endX = x;
1604
+ endY = y;
1264
1605
  }
1265
- }
1266
- ev.preventDefault();
1267
- return false;
1268
- };
1269
- const dragEndListener = (ev) => {
1270
- var _a, _b;
1271
- document.removeEventListener("mousemove", dragListener);
1272
- document.removeEventListener("mouseup", dragEndListener);
1273
- window.removeEventListener("blur", dragEndListener);
1274
- if (scroll) {
1275
- if (timer) {
1276
- clearInterval(timer);
1277
- timer = null;
1606
+ });
1607
+ onPointerEnd((args) => {
1608
+ var _a, _b;
1609
+ const { ev, currentStyle } = args;
1610
+ if (scroll) {
1611
+ if (timer) {
1612
+ clearInterval(timer);
1613
+ timer = null;
1614
+ }
1278
1615
  }
1279
- }
1280
- //restore classes
1281
- dragDom.classList.remove(...func_js.compact(func_js.split(classes, ' ')));
1282
- dragDom.style.zIndex = originalZIndex;
1283
- dragDom.classList.remove(CLASS_DRAGGABLE_ACTIVE);
1284
- let moveToGhost = true;
1285
- if (dragging) {
1286
- moveToGhost = func_js.call(onEnd, dragDom, ev);
1287
- }
1288
- //notify
1289
- const customEv = new Event("uii-dragdeactive", { "bubbles": true, "cancelable": false });
1290
- dragDom.dispatchEvent(customEv);
1291
- if (dragging) {
1292
- unlockPage();
1293
- restoreCursor();
1616
+ dragDom.classList.remove(...array.compact(string.split(classes, ' ')));
1617
+ currentStyle.zIndex = originalZIndex;
1618
+ dragDom.classList.remove(CLASS_DRAGGABLE_ACTIVE);
1619
+ let moveToGhost = true;
1620
+ if (onEnd) {
1621
+ moveToGhost = onEnd({ draggable: dragDom, x: endX, y: endY }, ev) === false ? false : true;
1622
+ }
1623
+ const customEv = new Event("uii-dragdeactive", { "bubbles": true, "cancelable": false });
1624
+ dragDom.dispatchEvent(customEv);
1294
1625
  if (ghost) {
1295
1626
  ((_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.contains(copyNode)) && ((_b = dragDom.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(copyNode));
1296
1627
  if (moveToGhost !== false) {
1297
- style.left = copyNode.style.left;
1298
- style.top = copyNode.style.top;
1628
+ wrapper(dragDom).moveTo(transformer.x, transformer.y);
1299
1629
  }
1300
1630
  }
1631
+ });
1632
+ }, {
1633
+ threshold: this.opts.threshold || 0,
1634
+ lockPage: true
1635
+ });
1636
+ }
1637
+ onOptionChanged(opts) {
1638
+ const droppable = opts.droppable;
1639
+ if (!is.isFunction(droppable)) {
1640
+ if (is.isUndefined(droppable)) {
1641
+ opts.droppable = () => { };
1301
1642
  }
1302
- };
1303
- document.addEventListener("mousemove", dragListener);
1304
- document.addEventListener("mouseup", dragEndListener);
1305
- window.addEventListener("blur", dragEndListener);
1306
- e.preventDefault();
1307
- return false;
1308
- });
1643
+ else if (is.isString(droppable)) {
1644
+ opts.droppable = () => document.querySelectorAll(droppable);
1645
+ }
1646
+ else if (is.isArrayLike(droppable)) {
1647
+ opts.droppable = () => droppable;
1648
+ }
1649
+ else if (is.isElement(droppable)) {
1650
+ opts.droppable = () => [droppable];
1651
+ }
1652
+ }
1653
+ }
1309
1654
  }
1310
- /**
1311
- * create a draggable pattern for one or more elements with opts
1312
- * @param els selector string / html element
1313
- * @param opts
1314
- * @returns Draggable instance
1315
- */
1655
+ _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Draggable_instances = new WeakSet(), _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
1656
+ collection.each(draggableList, (el) => {
1657
+ if (is.isDefined(this.opts.type))
1658
+ el.dataset.dropType = this.opts.type;
1659
+ el.classList.toggle(CLASS_DRAGGABLE, true);
1660
+ const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
1661
+ ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
1662
+ if (is.isDefined(this.opts.cursor)) {
1663
+ el.style.cursor = this.opts.cursor.default || 'move';
1664
+ if (is.isDefined(this.opts.cursor.over)) {
1665
+ el.dataset.cursorOver = this.opts.cursor.over;
1666
+ el.dataset.cursorActive = this.opts.cursor.active || 'move';
1667
+ }
1668
+ }
1669
+ });
1670
+ };
1316
1671
  function newDraggable(els, opts) {
1317
1672
  return new Draggable(els, opts);
1318
1673
  }
@@ -1320,267 +1675,185 @@
1320
1675
  var _Droppable_active;
1321
1676
  const Droppables = [];
1322
1677
  const CLASS_DROPPABLE = "uii-droppable";
1323
- /**
1324
- * 用于表示一个或多个可响应拖动元素的定义
1325
- * > 可用CSS接口
1326
- * - .uii-droppable
1327
- * @public
1328
- */
1329
1678
  class Droppable extends Uii {
1330
1679
  constructor(el, opts) {
1331
- super(el, func_js.assign({}, opts));
1680
+ super(el, object.assign({}, opts));
1332
1681
  _Droppable_active.set(this, void 0);
1333
1682
  Droppables.push(this);
1334
1683
  }
1335
- /**
1336
- * @internal
1337
- */
1338
- bindEvent(el, opts) {
1339
- //dragenter
1340
- this.registerEvent(el, "mouseenter", (e) => {
1684
+ bindEvent(droppable, opts) {
1685
+ this.registerEvent(droppable, "mouseenter", (e) => {
1341
1686
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1342
1687
  return;
1343
1688
  if (opts.hoverClass) {
1344
- func_js.each(func_js.split(opts.hoverClass, ' '), cls => {
1345
- el.classList.toggle(cls, true);
1689
+ collection.each(string.split(opts.hoverClass, ' '), cls => {
1690
+ droppable.classList.toggle(cls, true);
1346
1691
  });
1347
1692
  }
1348
1693
  if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1349
1694
  setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver);
1350
1695
  }
1351
- func_js.call(opts.onEnter, el, e);
1696
+ opts.onEnter && opts.onEnter({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1352
1697
  });
1353
- //dragleave
1354
- this.registerEvent(el, "mouseleave", (e) => {
1698
+ this.registerEvent(droppable, "mouseleave", (e) => {
1355
1699
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1356
1700
  return;
1357
1701
  if (opts.hoverClass) {
1358
- func_js.each(func_js.split(opts.hoverClass, ' '), cls => {
1359
- el.classList.toggle(cls, false);
1702
+ collection.each(string.split(opts.hoverClass, ' '), cls => {
1703
+ droppable.classList.toggle(cls, false);
1360
1704
  });
1361
1705
  }
1362
1706
  if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1363
1707
  setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '');
1364
1708
  }
1365
- func_js.call(opts.onLeave, el, e);
1709
+ opts.onLeave && opts.onLeave({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1366
1710
  });
1367
- //dragover
1368
- this.registerEvent(el, "mousemove", (e) => {
1711
+ this.registerEvent(droppable, "mousemove", (e) => {
1369
1712
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1370
1713
  return;
1371
- if (opts.onDragOver) {
1372
- opts.onDragOver(el, e);
1373
- }
1714
+ opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1374
1715
  });
1375
- //drop
1376
- this.registerEvent(el, "mouseup", (e) => {
1716
+ this.registerEvent(droppable, "mouseup", (e) => {
1377
1717
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1378
1718
  return;
1379
1719
  if (opts.hoverClass) {
1380
- func_js.each(func_js.split(opts.hoverClass, ' '), cls => {
1381
- el.classList.toggle(cls, false);
1720
+ collection.each(string.split(opts.hoverClass, ' '), cls => {
1721
+ droppable.classList.toggle(cls, false);
1382
1722
  });
1383
1723
  }
1384
- func_js.call(opts.onDrop, el, e);
1724
+ opts.onDrop && opts.onDrop({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1385
1725
  });
1386
1726
  }
1387
- /**
1388
- * @internal
1389
- */
1390
1727
  active(target) {
1391
1728
  let valid = true;
1392
- //check accepts
1393
- if (func_js.isString(this.opts.accepts)) {
1394
- valid = !!target.dataset.dropType && func_js.test(this.opts.accepts, target.dataset.dropType);
1729
+ const opts = this.opts;
1730
+ if (is.isString(opts.accepts)) {
1731
+ valid = !!target.dataset.dropType && string.test(opts.accepts, target.dataset.dropType);
1395
1732
  }
1396
- else if (func_js.isFunction(this.opts.accepts)) {
1397
- valid = this.opts.accepts(this.ele, target);
1733
+ else if (is.isFunction(opts.accepts)) {
1734
+ valid = opts.accepts(this.ele, target);
1398
1735
  }
1399
1736
  if (!valid)
1400
1737
  return;
1401
1738
  __classPrivateFieldSet(this, _Droppable_active, target, "f");
1402
- if (this.opts.activeClass) {
1403
- func_js.each(this.ele, el => {
1404
- func_js.each(func_js.split(this.opts.activeClass, ' '), cls => {
1739
+ if (opts.activeClass) {
1740
+ collection.each(this.ele, el => {
1741
+ collection.each(string.split(opts.activeClass || '', ' '), cls => {
1405
1742
  el.classList.toggle(cls, true);
1406
1743
  });
1407
1744
  });
1408
1745
  }
1409
- func_js.call(this.opts.onActive, target, this.ele);
1410
- //bind events
1411
- func_js.each(this.ele, (el) => {
1746
+ opts.onActive && opts.onActive({ draggable: target, droppables: this.ele });
1747
+ collection.each(this.ele, (el) => {
1412
1748
  el.classList.toggle(CLASS_DROPPABLE, true);
1413
1749
  el.style.pointerEvents = 'initial';
1414
- this.bindEvent(el, this.opts);
1750
+ this.bindEvent(el, opts);
1415
1751
  });
1416
1752
  }
1417
- /**
1418
- * @internal
1419
- */
1420
1753
  deactive(target) {
1421
1754
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1422
1755
  return;
1423
1756
  __classPrivateFieldSet(this, _Droppable_active, null, "f");
1424
- if (this.opts.activeClass) {
1425
- func_js.each(this.ele, el => {
1426
- func_js.each(func_js.split(this.opts.activeClass, ' '), cls => {
1757
+ const opts = this.opts;
1758
+ if (opts.activeClass) {
1759
+ collection.each(this.ele, el => {
1760
+ collection.each(string.split(opts.activeClass || '', ' '), cls => {
1427
1761
  el.classList.toggle(cls, false);
1428
1762
  });
1429
1763
  });
1430
1764
  }
1431
- func_js.call(this.opts.onDeactive, target, this.ele);
1432
- //unbind events
1765
+ opts.onDeactive && opts.onDeactive({ draggable: target, droppables: this.ele });
1433
1766
  this.destroy();
1434
1767
  }
1435
1768
  }
1436
1769
  _Droppable_active = new WeakMap();
1437
- //uii-drag active
1438
1770
  document.addEventListener("uii-dragactive", (e) => {
1439
- func_js.each(Droppables, dpb => {
1771
+ collection.each(Droppables, dpb => {
1440
1772
  dpb.active(e.target);
1441
1773
  });
1442
1774
  });
1443
1775
  document.addEventListener("uii-dragdeactive", (e) => {
1444
- func_js.each(Droppables, dpb => {
1776
+ collection.each(Droppables, dpb => {
1445
1777
  dpb.deactive(e.target);
1446
1778
  });
1447
1779
  });
1448
- /**
1449
- * Enable els to response to draggable objects
1450
- * @param els selector string / html element
1451
- * @param opts
1452
- * @returns
1453
- */
1454
1780
  function newDroppable(els, opts) {
1455
1781
  return new Droppable(els, opts);
1456
1782
  }
1457
1783
 
1458
- /* eslint-disable max-len */
1459
- const ONE_DEG = 180 / Math.PI;
1460
- const THRESHOLD$1 = 2;
1784
+ const THRESHOLD$2 = 2;
1461
1785
  const CLASS_ROTATABLE = "uii-rotatable";
1462
1786
  const CLASS_ROTATABLE_HANDLE = "uii-rotatable-handle";
1463
1787
  const CLASS_ROTATABLE_ACTIVE = "uii-rotatable-active";
1464
- /**
1465
- * 用于表示一个或多个可旋转元素的定义
1466
- * > 可用CSS接口
1467
- * - .uii-rotatable
1468
- * - .uii-rotatable-handle
1469
- * - .uii-rotatable-active
1470
- * @public
1471
- */
1472
1788
  class Rotatable extends Uii {
1473
1789
  constructor(els, opts) {
1474
1790
  super(els, opts);
1475
- func_js.each(this.ele, (el) => {
1476
- initHandle(el, this.opts);
1791
+ collection.each(this.ele, (el) => {
1792
+ initHandle(this, el, this.opts);
1477
1793
  });
1478
1794
  }
1479
1795
  }
1480
- function initHandle(el, opts) {
1481
- var _a;
1482
- const handle = document.createElement('div');
1483
- handle.className = CLASS_ROTATABLE_HANDLE;
1484
- handle.style.cssText = `
1485
- position:absolute;
1486
- width:12px;
1487
- height:12px;
1488
- border-radius:50%;
1489
- left: calc(50% - 6px);
1490
- top: -24px;
1491
- `;
1492
- handle.style.cursor = ((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.default) || 'crosshair';
1493
- bindHandle(handle, el, opts);
1796
+ function initHandle(uiik, el, opts) {
1797
+ let handleStr = opts.handle;
1798
+ let handles;
1799
+ if (is.isString(handleStr)) {
1800
+ handles = document.querySelectorAll(handleStr);
1801
+ }
1802
+ else if (is.isFunction(handleStr)) {
1803
+ handles = handleStr(el);
1804
+ }
1805
+ if (!handles) {
1806
+ console.error('Can not find handles with "' + el.outerHTML + '"');
1807
+ return;
1808
+ }
1809
+ collection.each(handles, (h) => {
1810
+ var _a;
1811
+ h.classList.add(CLASS_ROTATABLE_HANDLE);
1812
+ h.style.cursor = ((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.default) || "crosshair";
1813
+ bindHandle(uiik, h, el, opts);
1814
+ });
1494
1815
  el.classList.toggle(CLASS_ROTATABLE, true);
1495
- el.appendChild(handle);
1496
1816
  }
1497
- function bindHandle(handle, el, opts) {
1817
+ function bindHandle(uiik, handle, el, opts) {
1498
1818
  const onStart = opts.onStart;
1499
1819
  const onRotate = opts.onRotate;
1500
1820
  const onEnd = opts.onEnd;
1501
- handle.onmousedown = function (e) {
1502
- var _a, _b;
1503
- // calc center
1504
- const center = window.getComputedStyle(el).transformOrigin || '';
1505
- const centerPair = center.split(' ');
1506
- const shadowDom = el.cloneNode();
1507
- shadowDom.style.cssText = 'transform:rotate(0);z-index:-999;position:absolute;';
1508
- (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.appendChild(shadowDom);
1509
- const offsetXY = shadowDom.getBoundingClientRect();
1510
- (_b = el.parentElement) === null || _b === void 0 ? void 0 : _b.removeChild(shadowDom);
1511
- let centerX = parseFloat(centerPair[0]) + offsetXY.x;
1512
- let centerY = parseFloat(centerPair[1]) + offsetXY.y;
1513
- let a = 0, b = 0;
1514
- const matrix = window.getComputedStyle(el).transform;
1515
- if (matrix.indexOf('matrix') > -1) {
1516
- const abcd = matrix.replace(/^matrix\(|\)$/mg, '').split(',');
1517
- a = parseFloat(abcd[0]);
1518
- b = parseFloat(abcd[1]);
1519
- }
1520
- let deg = Math.atan2(b, a) * ONE_DEG;
1521
- if (deg < 0)
1522
- deg = 360 - deg;
1523
- if (deg > 360)
1524
- deg = 360 - deg % 360;
1525
- const style = el.style;
1526
- let startDeg = Math.atan2(e.clientY - centerY, e.clientX - centerX) * ONE_DEG + 90;
1527
- if (startDeg < 0)
1528
- startDeg = 360 + startDeg;
1529
- const offsetDeg = startDeg - deg;
1530
- let dragging = false;
1531
- saveCursor();
1532
- const dragListener = (ev) => {
1533
- var _a;
1534
- const offsetx = ev.clientX - centerX;
1535
- const offsety = ev.clientY - centerY;
1536
- if (!dragging) {
1537
- if (Math.abs(offsetx) > THRESHOLD$1 || Math.abs(offsety) > THRESHOLD$1) {
1538
- dragging = true;
1539
- //apply classes
1540
- el.classList.toggle(CLASS_ROTATABLE_ACTIVE, true);
1541
- func_js.call(onStart, deg);
1542
- lockPage();
1543
- if (func_js.isDefined(opts.cursor)) {
1544
- setCursor(((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.active) || 'crosshair');
1545
- }
1546
- }
1547
- else {
1548
- ev.preventDefault();
1549
- return false;
1550
- }
1551
- }
1552
- deg = Math.atan2(offsety, offsetx) * ONE_DEG + 90 - offsetDeg;
1553
- if (deg < 0)
1554
- deg = 360 + deg;
1555
- func_js.call(onRotate, deg);
1556
- style.transform = style.transform.replace(/rotateZ\(.*?\)/, '') + ' rotateZ(' + deg + 'deg)';
1557
- ev.preventDefault();
1558
- return false;
1559
- };
1560
- const dragEndListener = (ev) => {
1561
- document.removeEventListener('mousemove', dragListener, false);
1562
- document.removeEventListener('mouseup', dragEndListener, false);
1563
- window.removeEventListener('blur', dragEndListener, false);
1564
- if (dragging) {
1565
- unlockPage();
1566
- restoreCursor();
1567
- el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
1568
- func_js.call(onEnd, deg);
1569
- }
1570
- };
1571
- document.addEventListener('mousemove', dragListener, false);
1572
- document.addEventListener('mouseup', dragEndListener, false);
1573
- window.addEventListener('blur', dragEndListener, false);
1574
- e.preventDefault();
1575
- return false;
1576
- };
1821
+ let deg = 0;
1822
+ uiik.addPointerDown(handle, ({ onPointerStart, onPointerMove, onPointerEnd }) => {
1823
+ const { x, y, ox, oy } = getCenterXy(el);
1824
+ let centerX = x, centerY = y;
1825
+ let startDeg = 0;
1826
+ onPointerStart(function (args) {
1827
+ const { ev } = args;
1828
+ const currentXy = getPointInContainer(ev, el.parentElement);
1829
+ startDeg =
1830
+ Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD + 90;
1831
+ if (startDeg < 0)
1832
+ startDeg = 360 + startDeg;
1833
+ let matrixInfo = getMatrixInfo(el);
1834
+ startDeg -= matrixInfo.angle;
1835
+ el.classList.toggle(CLASS_ROTATABLE_ACTIVE, true);
1836
+ onStart && onStart({ deg, cx: centerX, cy: centerY }, ev);
1837
+ });
1838
+ onPointerMove((args) => {
1839
+ const { ev } = args;
1840
+ const currentXy = getPointInContainer(ev, el.parentElement);
1841
+ deg =
1842
+ Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD +
1843
+ 90 - startDeg;
1844
+ onRotate && onRotate({ deg, cx: centerX, cy: centerY }, ev);
1845
+ rotateTo(el, deg, ox, oy);
1846
+ });
1847
+ onPointerEnd((args) => {
1848
+ const { ev } = args;
1849
+ el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
1850
+ onEnd && onEnd({ deg }, ev);
1851
+ });
1852
+ }, {
1853
+ threshold: THRESHOLD$2,
1854
+ lockPage: true,
1855
+ });
1577
1856
  }
1578
- /**
1579
- * Make els rotatable
1580
- * @param els selector string / html element
1581
- * @param opts
1582
- * @returns
1583
- */
1584
1857
  function newRotatable(els, opts) {
1585
1858
  return new Rotatable(els, opts);
1586
1859
  }
@@ -1593,16 +1866,15 @@
1593
1866
  this.opts = {
1594
1867
  container: document.body
1595
1868
  };
1596
- this.opts = func_js.assign(this.opts, opts);
1597
- const domEl = func_js.isString(el) ? document.querySelector(el) : el;
1869
+ this.opts = object.assign(this.opts, opts);
1870
+ const domEl = is.isString(el) ? document.querySelector(el) : el;
1598
1871
  if (!domEl) {
1599
1872
  console.error('Invalid selector "' + el + '"');
1600
1873
  return;
1601
1874
  }
1602
1875
  const ele = domEl;
1603
1876
  this.el = domEl;
1604
- //el data
1605
- const offset = getOffset(ele, this.opts.container);
1877
+ const offset = getBox(ele, this.opts.container);
1606
1878
  const rect = { x: offset.x, y: offset.y, width: ele.offsetWidth, height: ele.offsetHeight };
1607
1879
  this.elData = {
1608
1880
  x1: rect.x,
@@ -1610,38 +1882,32 @@
1610
1882
  x2: rect.x + rect.width,
1611
1883
  y2: rect.y + rect.height,
1612
1884
  };
1613
- //targets data
1614
1885
  this.update();
1615
1886
  }
1616
- /**
1617
- * update targets data if them changed
1618
- */
1619
1887
  update() {
1620
1888
  let targets;
1621
- if (func_js.isFunction(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1889
+ if (is.isFunction(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1622
1890
  targets = __classPrivateFieldGet(this, _CollisionDetector__targets, "f").call(this);
1623
1891
  }
1624
- else if (func_js.isString(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1892
+ else if (is.isString(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1625
1893
  targets = this.opts.container.querySelectorAll(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"));
1894
+ targets = collection.reject(targets, t => t === this.el);
1626
1895
  }
1627
- else if (func_js.isElement(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1896
+ else if (is.isElement(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1628
1897
  targets = [__classPrivateFieldGet(this, _CollisionDetector__targets, "f")];
1629
1898
  }
1630
1899
  else {
1631
1900
  targets = __classPrivateFieldGet(this, _CollisionDetector__targets, "f");
1632
1901
  }
1633
- this.targetsData = func_js.flatMap(targets, t => {
1902
+ this.targetsData = collection.flatMap(targets, t => {
1634
1903
  if (!t)
1635
1904
  return [];
1636
- if (!func_js.isElement(t))
1637
- return [];
1638
- const offset = getOffset(t, this.opts.container);
1639
- const rect = { x: offset.x, y: offset.y, width: t.offsetWidth, height: t.offsetHeight };
1905
+ const rect = getRectInContainer(t, this.opts.container);
1640
1906
  return {
1641
1907
  x1: rect.x,
1642
1908
  y1: rect.y,
1643
- x2: rect.x + rect.width,
1644
- y2: rect.y + rect.height,
1909
+ x2: rect.x + rect.w,
1910
+ y2: rect.y + rect.h,
1645
1911
  el: t
1646
1912
  };
1647
1913
  });
@@ -1656,7 +1922,7 @@
1656
1922
  y2,
1657
1923
  };
1658
1924
  }
1659
- let overlaps = func_js.flatMap(this.targetsData, (td, i) => {
1925
+ let overlaps = collection.flatMap(this.targetsData, (td, i) => {
1660
1926
  if (elData.x2 < td.x1 || elData.x1 > td.x2 || elData.y2 < td.y1 || elData.y1 > td.y2)
1661
1927
  return [];
1662
1928
  return td.el;
@@ -1673,7 +1939,7 @@
1673
1939
  y2,
1674
1940
  };
1675
1941
  }
1676
- let contains = func_js.flatMap(this.targetsData, (td, i) => {
1942
+ let contains = collection.flatMap(this.targetsData, (td, i) => {
1677
1943
  if (elData.x2 >= td.x2 && elData.x1 <= td.x1 && elData.y2 >= td.y2 && elData.y1 <= td.y1)
1678
1944
  return td.el;
1679
1945
  return [];
@@ -1682,39 +1948,18 @@
1682
1948
  }
1683
1949
  }
1684
1950
  _CollisionDetector__targets = new WeakMap();
1685
- /**
1686
- * create a detector for the el and return
1687
- * @param el element to be detected
1688
- * @param targets
1689
- * @param opts CollisionDetectorOptions
1690
- * @param opts.container a root element of targets
1691
- * @returns
1692
- */
1693
1951
  function newCollisionDetector(el, targets, opts) {
1694
1952
  return new CollisionDetector(el, targets, opts);
1695
1953
  }
1696
1954
 
1697
- /* eslint-disable max-len */
1698
- /**
1699
- * selector
1700
- * @author holyhigh2
1701
- */
1702
1955
  var _Selectable_instances, _Selectable__detector, _Selectable__lastSelected, _Selectable_bindEvent;
1703
1956
  const CLASS_SELECTOR = "uii-selector";
1704
1957
  const CLASS_SELECTING = "uii-selecting";
1705
1958
  const CLASS_SELECTED = "uii-selected";
1706
- const THRESHOLD = 2;
1707
- /**
1708
- * 用于表示一个元素选择器的定义
1709
- * > 可用CSS接口
1710
- * - .uii-selector
1711
- * - .uii-selecting
1712
- * - .uii-selected
1713
- * @public
1714
- */
1959
+ const THRESHOLD$1 = 2;
1715
1960
  class Selectable extends Uii {
1716
1961
  constructor(container, opts) {
1717
- super(container, func_js.assign({
1962
+ super(container, object.assign({
1718
1963
  targets: [],
1719
1964
  scroll: true,
1720
1965
  }, opts));
@@ -1722,117 +1967,99 @@
1722
1967
  _Selectable__detector.set(this, void 0);
1723
1968
  _Selectable__lastSelected.set(this, void 0);
1724
1969
  const domEl = this.ele[0];
1725
- //create selector
1726
- const selector = document.createElement("div");
1727
- selector.className = CLASS_SELECTOR;
1970
+ let selector = document.createElement("div");
1971
+ if (domEl instanceof SVGElement) {
1972
+ selector = document.createElementNS('http://www.w3.org/2000/svg', "rect");
1973
+ }
1974
+ selector.setAttribute('class', CLASS_SELECTOR);
1728
1975
  selector.style.cssText = `
1729
1976
  position:absolute;
1730
- left:-9999px;
1977
+ left:0;top:0;
1731
1978
  `;
1732
1979
  if (this.opts.class) {
1733
- selector.className += " " + this.opts.class;
1980
+ selector.setAttribute('class', selector.getAttribute('class') + " " + this.opts.class);
1734
1981
  }
1735
1982
  else {
1736
- selector.style.cssText += "border:1px dashed #000;";
1983
+ selector.style.cssText += "border:1px dashed #000;stroke:#000;";
1737
1984
  }
1985
+ selector.style.display = 'none';
1738
1986
  domEl.appendChild(selector);
1739
- //create detector
1740
1987
  __classPrivateFieldSet(this, _Selectable__detector, newCollisionDetector(selector, this.opts.targets, {
1741
1988
  container: domEl,
1742
1989
  }), "f");
1743
1990
  __classPrivateFieldGet(this, _Selectable_instances, "m", _Selectable_bindEvent).call(this, selector, domEl);
1744
1991
  }
1745
- /**
1746
- * 更新targets
1747
- */
1748
1992
  updateTargets() {
1749
1993
  __classPrivateFieldGet(this, _Selectable__detector, "f").update();
1750
1994
  }
1751
- /**
1752
- * @internal
1753
- */
1754
1995
  onOptionChanged() {
1755
1996
  this.updateTargets();
1756
1997
  }
1757
1998
  }
1758
1999
  _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap(), _Selectable_instances = new WeakSet(), _Selectable_bindEvent = function _Selectable_bindEvent(selector, con) {
1759
2000
  const that = this;
1760
- this.registerEvent(con, "mousedown", (e) => {
1761
- const t = e.target;
1762
- const onStart = that.opts.onStart;
1763
- const onSelect = that.opts.onSelect;
1764
- const onEnd = that.opts.onEnd;
1765
- const mode = that.opts.mode || "overlap";
1766
- const scroll = that.opts.scroll;
1767
- const scrollSpeed = that.opts.scrollSpeed || 10;
1768
- const filter = that.opts.filter;
1769
- const selectingClassAry = func_js.compact(func_js.split(that.opts.selectingClass, " "));
1770
- const selectedClassAry = func_js.compact(func_js.split(that.opts.selectedClass, " "));
1771
- //check filter
2001
+ const opts = this.opts;
2002
+ this.addPointerDown(con, ({ ev, target, currentRect, currentCStyle, currentTarget, onPointerStart, onPointerMove, onPointerEnd }) => {
2003
+ const onStart = opts.onStart;
2004
+ const onSelect = opts.onSelect;
2005
+ const onEnd = opts.onEnd;
2006
+ const mode = opts.mode || "overlap";
2007
+ const scroll = opts.scroll;
2008
+ const scrollSpeed = opts.scrollSpeed || 10;
2009
+ const filter = opts.filter;
2010
+ const selectingClassAry = array.compact(string.split(opts.selectingClass, " "));
2011
+ const selectedClassAry = array.compact(string.split(opts.selectedClass, " "));
1772
2012
  if (filter) {
1773
- if (func_js.isFunction(filter)) {
1774
- if (filter(t))
2013
+ if (is.isFunction(filter)) {
2014
+ if (filter(target))
1775
2015
  return;
1776
2016
  }
1777
- else if (func_js.some(con.querySelectorAll(filter), (el) => el.contains(t)))
2017
+ else if (collection.some(con.querySelectorAll(filter), (el) => el.contains(target)))
1778
2018
  return;
1779
2019
  }
2020
+ const onPointerDown = opts.onPointerDown;
2021
+ if (onPointerDown && onPointerDown(ev) === false)
2022
+ return;
1780
2023
  let originPos = "";
1781
- //offset
1782
- const rect = con.getBoundingClientRect();
1783
- const conStyle = window.getComputedStyle(con);
1784
- const blw = parseFloat(conStyle.borderLeftWidth);
1785
- const btw = parseFloat(conStyle.borderTopWidth);
1786
- let hitPosX = e.offsetX + con.scrollLeft, hitPosY = e.offsetY + con.scrollTop;
1787
- if (t !== con) {
1788
- const offset = getOffset(t, con);
1789
- const style = window.getComputedStyle(t);
1790
- hitPosX = offset.x + e.offsetX + parseFloat(style.borderLeftWidth);
1791
- hitPosY = offset.y + e.offsetY + parseFloat(style.borderTopWidth);
1792
- }
2024
+ let matrixInfo = getMatrixInfo(currentCStyle);
2025
+ const startxy = getPointInContainer(ev, con, currentRect, currentCStyle, matrixInfo);
2026
+ let hitPosX = startxy.x;
2027
+ let hitPosY = startxy.y;
1793
2028
  const style = selector.style;
1794
2029
  let selection = [];
1795
2030
  let lastSelection = [];
1796
2031
  let x1 = hitPosX, y1 = hitPosY;
1797
- let dragging = false;
1798
2032
  let timer = null;
1799
2033
  let toLeft = false;
1800
2034
  let toTop = false;
1801
2035
  let toRight = false;
1802
2036
  let toBottom = false;
1803
- const dragListener = (ev) => {
1804
- const newX = ev.clientX - rect.x + con.scrollLeft - blw;
1805
- const newY = ev.clientY - rect.y + con.scrollTop - btw;
1806
- const offsetx = newX - hitPosX;
1807
- const offsety = newY - hitPosY;
1808
- if (!dragging) {
1809
- if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
1810
- dragging = true;
1811
- //update targets count & positions
1812
- __classPrivateFieldGet(this, _Selectable__detector, "f").update();
1813
- //detect container position
1814
- const pos = window.getComputedStyle(con).position;
1815
- if (pos === "static") {
1816
- originPos = con.style.position;
1817
- con.style.position = "relative";
1818
- }
1819
- //clear _lastSelected
1820
- func_js.each(__classPrivateFieldGet(this, _Selectable__lastSelected, "f"), t => {
1821
- t.classList.toggle(CLASS_SELECTED, false);
1822
- });
1823
- func_js.call(onStart, t);
1824
- }
1825
- else {
1826
- ev.preventDefault();
1827
- return false;
1828
- }
1829
- }
1830
- //edge detect
2037
+ onPointerStart(function (args) {
2038
+ const { ev } = args;
2039
+ __classPrivateFieldGet(that, _Selectable__detector, "f").update();
2040
+ const pos = currentCStyle.position;
2041
+ if (pos === "static") {
2042
+ originPos = con.style.position;
2043
+ con.style.position = "relative";
2044
+ }
2045
+ collection.each(__classPrivateFieldGet(that, _Selectable__lastSelected, "f"), t => {
2046
+ target.classList.toggle(CLASS_SELECTED, false);
2047
+ });
2048
+ style.display = 'block';
2049
+ onStart && onStart({ selection: __classPrivateFieldGet(that, _Selectable__lastSelected, "f"), selectable: con }, ev);
2050
+ });
2051
+ onPointerMove((args) => {
2052
+ const { ev } = args;
2053
+ const currentXy = getPointInContainer(ev, currentTarget, currentRect, currentCStyle, matrixInfo);
2054
+ let pointX = currentXy.x;
2055
+ let pointY = currentXy.y;
2056
+ let offX = pointX - hitPosX;
2057
+ let offY = pointY - hitPosY;
1831
2058
  if (scroll) {
1832
- const ltX = ev.clientX - rect.x;
1833
- const ltY = ev.clientY - rect.y;
1834
- const rbX = rect.x + rect.width - ev.clientX;
1835
- const rbY = rect.y + rect.height - ev.clientY;
2059
+ const ltX = ev.clientX - currentRect.x;
2060
+ const ltY = ev.clientY - currentRect.y;
2061
+ const rbX = currentRect.x + currentRect.width - ev.clientX;
2062
+ const rbY = currentRect.y + currentRect.height - ev.clientY;
1836
2063
  toLeft = ltX < EDGE_THRESHOLD;
1837
2064
  toTop = ltY < EDGE_THRESHOLD;
1838
2065
  toRight = rbX < EDGE_THRESHOLD;
@@ -1862,107 +2089,472 @@
1862
2089
  }
1863
2090
  }
1864
2091
  }
1865
- let x = hitPosX, y = hitPosY, w = Math.abs(offsetx), h = Math.abs(offsety);
1866
- if (offsetx > 0 && offsety > 0) {
2092
+ let x = hitPosX, y = hitPosY, w = Math.abs(offX), h = Math.abs(offY);
2093
+ if (offX > 0 && offY > 0) {
1867
2094
  x1 = hitPosX;
1868
2095
  y1 = hitPosY;
1869
2096
  }
1870
- else if (offsetx < 0 && offsety < 0) {
1871
- x = x1 = newX;
1872
- y = y1 = newY;
2097
+ else if (offX < 0 && offY < 0) {
2098
+ x = x1 = pointX;
2099
+ y = y1 = pointY;
1873
2100
  }
1874
- else if (offsetx < 0) {
1875
- x = x1 = newX;
2101
+ else if (offX < 0) {
2102
+ x = x1 = pointX;
1876
2103
  }
1877
- else if (offsety < 0) {
1878
- y = y1 = newY;
2104
+ else if (offY < 0) {
2105
+ y = y1 = pointY;
1879
2106
  }
1880
- style.left = x + "px";
1881
- style.top = y + "px";
1882
2107
  style.width = w + "px";
1883
2108
  style.height = h + "px";
1884
- //detect collision
2109
+ style.transform = `translate3d(${x}px,${y}px,0)`;
1885
2110
  if (mode === "overlap") {
1886
2111
  selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getOverlaps(x1, y1, x1 + w, y1 + h);
1887
2112
  }
1888
2113
  else if (mode === "inclusion") {
1889
2114
  selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getInclusions(x1, y1, x1 + w, y1 + h);
1890
2115
  }
1891
- func_js.each(lastSelection, (t) => {
1892
- if (!func_js.includes(selection, t)) {
2116
+ collection.each(lastSelection, (t) => {
2117
+ if (!collection.includes(selection, t)) {
1893
2118
  t.classList.toggle(CLASS_SELECTING, false);
1894
- func_js.each(selectingClassAry, (cls) => {
2119
+ collection.each(selectingClassAry, (cls) => {
1895
2120
  t.classList.toggle(cls, false);
1896
2121
  });
1897
2122
  }
1898
2123
  });
1899
- func_js.each(selection, (t) => {
2124
+ collection.each(selection, (t) => {
1900
2125
  t.classList.toggle(CLASS_SELECTING, true);
1901
- func_js.each(selectingClassAry, (cls) => {
2126
+ collection.each(selectingClassAry, (cls) => {
1902
2127
  t.classList.toggle(cls, true);
1903
2128
  });
1904
2129
  });
1905
2130
  const changed = lastSelection.length != selection.length;
1906
2131
  lastSelection = selection;
1907
- if (changed)
1908
- func_js.call(onSelect, selection);
1909
- ev.preventDefault();
1910
- return false;
1911
- };
1912
- const dragEndListener = (ev) => {
1913
- style.left = "-9999px";
1914
- style.width = style.height = "0px";
1915
- document.removeEventListener("mousemove", dragListener, false);
1916
- document.removeEventListener("mouseup", dragEndListener, false);
1917
- window.removeEventListener("blur", dragEndListener, false);
2132
+ if (changed && onSelect)
2133
+ onSelect({ selection, selectable: con }, ev);
2134
+ });
2135
+ onPointerEnd((args) => {
2136
+ const { ev, currentStyle } = args;
2137
+ style.display = 'none';
1918
2138
  if (scroll) {
1919
2139
  if (timer) {
1920
2140
  clearInterval(timer);
1921
2141
  timer = null;
1922
2142
  }
1923
2143
  }
1924
- //restore container position
1925
2144
  if (originPos) {
1926
2145
  con.style.position = originPos;
1927
2146
  }
1928
- func_js.each(selection, (t) => {
1929
- func_js.each(selectingClassAry, (cls) => {
2147
+ collection.each(selection, (t) => {
2148
+ collection.each(selectingClassAry, (cls) => {
1930
2149
  t.classList.toggle(cls, false);
1931
2150
  });
1932
- func_js.each(selectedClassAry, (cls) => {
2151
+ collection.each(selectedClassAry, (cls) => {
1933
2152
  t.classList.toggle(cls, true);
1934
2153
  });
1935
2154
  t.classList.toggle(CLASS_SELECTING, false);
1936
2155
  t.classList.toggle(CLASS_SELECTED, true);
1937
2156
  });
1938
- __classPrivateFieldSet(this, _Selectable__lastSelected, selection, "f");
1939
- if (dragging)
1940
- func_js.call(onEnd, selection);
1941
- };
1942
- document.addEventListener("mousemove", dragListener, false);
1943
- document.addEventListener("mouseup", dragEndListener, false);
1944
- window.addEventListener("blur", dragEndListener, false);
1945
- e.preventDefault();
1946
- return false;
2157
+ __classPrivateFieldSet(that, _Selectable__lastSelected, selection, "f");
2158
+ if (onEnd)
2159
+ onEnd({ selection, selectable: con }, ev);
2160
+ });
2161
+ }, {
2162
+ threshold: THRESHOLD$1,
2163
+ lockPage: true
1947
2164
  });
1948
2165
  };
1949
- /**
1950
- * Add a selector into the container
1951
- * @param container css selector or html element
1952
- * @param opts
1953
- * @returns
1954
- */
1955
2166
  function newSelectable(container, opts) {
1956
2167
  return new Selectable(container, opts);
1957
2168
  }
1958
2169
 
1959
- var version = "1.0.9";
2170
+ var _Sortable_removeListenItems;
2171
+ const SORTABLE_GROUPS = {};
2172
+ const CLASS_SORTABLE_CONTAINER = "uii-sortable-container";
2173
+ const CLASS_SORTABLE_GHOST = "uii-sortable-ghost";
2174
+ const CLASS_SORTABLE_ACTIVE = "uii-sortable-active";
2175
+ const ATTR_SORTABLE_ACTIVE = "uii-sortable-active";
2176
+ const THRESHOLD = 2;
2177
+ class Sortable extends Uii {
2178
+ constructor(container, opts) {
2179
+ super(container, object.merge({
2180
+ move: {
2181
+ from: true,
2182
+ to: true,
2183
+ },
2184
+ scroll: true,
2185
+ sort: true
2186
+ }, opts));
2187
+ _Sortable_removeListenItems.set(this, void 0);
2188
+ if (collection.size(this.ele) > 1 && !this.opts.group) {
2189
+ this.opts.group = "uii_sortable_" + utils.alphaId();
2190
+ }
2191
+ collection.each(this.ele, (el) => {
2192
+ el.classList.add(CLASS_SORTABLE_CONTAINER);
2193
+ el.style.position = "relative";
2194
+ el.style.pointerEvents = "initial";
2195
+ bindContainer(this.registerEvent.bind(this), el, this.opts);
2196
+ });
2197
+ if (this.opts.group) {
2198
+ if (!SORTABLE_GROUPS[this.opts.group]) {
2199
+ SORTABLE_GROUPS[this.opts.group] = [];
2200
+ }
2201
+ SORTABLE_GROUPS[this.opts.group].push([this, this.ele]);
2202
+ }
2203
+ }
2204
+ active(draggingItem, fromContainer, toContainers, toOpts) {
2205
+ var _a;
2206
+ const moveFrom = (_a = toOpts.move) === null || _a === void 0 ? void 0 : _a.from;
2207
+ const acceptFn = is.isFunction(moveFrom) ? moveFrom : () => !!moveFrom;
2208
+ const activableContainers = collection.flatMap(toContainers, (el) => {
2209
+ const valid = acceptFn(draggingItem, fromContainer, el);
2210
+ return valid ? el : [];
2211
+ });
2212
+ collection.each(activableContainers, (el) => {
2213
+ el.setAttribute(ATTR_SORTABLE_ACTIVE, "1");
2214
+ if (toOpts.activeClass) {
2215
+ collection.each(string.split(toOpts.activeClass || "", " "), (cls) => {
2216
+ el.classList.toggle(cls, true);
2217
+ });
2218
+ }
2219
+ });
2220
+ __classPrivateFieldSet(this, _Sortable_removeListenItems, collection.map(activableContainers, (con) => {
2221
+ const filteredItems = con.querySelectorAll(":scope > *");
2222
+ return listenItems(toOpts, con, draggingItem, filteredItems);
2223
+ }), "f");
2224
+ toOpts.onActive &&
2225
+ toOpts.onActive({ item: draggingItem, from: fromContainer });
2226
+ }
2227
+ deactive(draggingItem, fromContainer, toContainers, opts) {
2228
+ collection.each(toContainers, (el) => {
2229
+ el.removeAttribute(ATTR_SORTABLE_ACTIVE);
2230
+ if (opts.activeClass) {
2231
+ collection.each(string.split(opts.activeClass || "", " "), (cls) => {
2232
+ el.classList.toggle(cls, false);
2233
+ });
2234
+ }
2235
+ });
2236
+ collection.each(__classPrivateFieldGet(this, _Sortable_removeListenItems, "f"), (fn) => {
2237
+ fn();
2238
+ });
2239
+ opts.onDeactive &&
2240
+ opts.onDeactive({ item: draggingItem, from: fromContainer });
2241
+ }
2242
+ onOptionChanged() { }
2243
+ }
2244
+ _Sortable_removeListenItems = new WeakMap();
2245
+ let DraggingData = null;
2246
+ function bindContainer(registerEvent, container, opts) {
2247
+ registerEvent(container, "mousedown", (e) => {
2248
+ var _a;
2249
+ let con = e.currentTarget;
2250
+ let t = e.target;
2251
+ if (t === con)
2252
+ return;
2253
+ const filterStr = opts.filter ? `:not(${opts.filter})` : "";
2254
+ const filteredItems = con.querySelectorAll(":scope > *" + filterStr);
2255
+ const handles = opts.handle
2256
+ ? collection.map(filteredItems, (el) => el.querySelector(opts.handle || ""))
2257
+ : collection.toArray(filteredItems);
2258
+ const i = array.findIndex(handles, (handle) => handle.contains(t));
2259
+ if (i < 0)
2260
+ return;
2261
+ const draggingItem = filteredItems[i];
2262
+ const ghostContainer = opts.ghostContainer || con;
2263
+ const onStart = opts.onStart;
2264
+ const onEnd = opts.onEnd;
2265
+ const ghostClass = opts.ghostClass;
2266
+ const group = opts.group;
2267
+ let moveTo = (_a = opts.move) === null || _a === void 0 ? void 0 : _a.to;
2268
+ const toCopy = moveTo === "copy";
2269
+ const toOutFn = is.isFunction(moveTo) ? moveTo : () => !!moveTo;
2270
+ const moveMode = toOutFn(draggingItem, con);
2271
+ const sort = opts.sort;
2272
+ opts.scroll;
2273
+ opts.scrollSpeed || 10;
2274
+ let hitPosX = e.offsetX + con.scrollLeft, hitPosY = e.offsetY + con.scrollTop;
2275
+ saveCursor();
2276
+ let dragging = false;
2277
+ let ghostNode = null;
2278
+ let removeListenItems = null;
2279
+ const dragListener = (ev) => {
2280
+ const newX = ev.clientX;
2281
+ const newY = ev.clientY;
2282
+ let offsetx = newX - hitPosX;
2283
+ let offsety = newY - hitPosY;
2284
+ if (!dragging) {
2285
+ if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
2286
+ dragging = true;
2287
+ ghostNode = draggingItem.cloneNode(true);
2288
+ ghostNode.style.opacity = "0.3";
2289
+ ghostNode.style.pointerEvents = "none";
2290
+ ghostNode.style.position = "fixed";
2291
+ ghostNode.style.zIndex = "999";
2292
+ ghostNode.style.left = draggingItem.style.left;
2293
+ ghostNode.style.top = draggingItem.style.top;
2294
+ if (ghostClass) {
2295
+ ghostNode.classList.add(...array.compact(string.split(ghostClass, " ")));
2296
+ }
2297
+ ghostNode.classList.toggle(CLASS_SORTABLE_GHOST, true);
2298
+ ghostContainer.appendChild(ghostNode);
2299
+ if (!toCopy)
2300
+ draggingItem.classList.toggle(CLASS_SORTABLE_ACTIVE, true);
2301
+ let copy = undefined;
2302
+ if (toCopy) {
2303
+ copy = draggingItem.cloneNode(true);
2304
+ copy.classList.toggle(CLASS_SORTABLE_ACTIVE, true);
2305
+ }
2306
+ DraggingData = {
2307
+ item: draggingItem,
2308
+ fromIndex: i,
2309
+ fromContainer: con,
2310
+ toContainer: con,
2311
+ moveTo: toCopy ? "copy" : moveMode,
2312
+ spill: opts.spill,
2313
+ copy
2314
+ };
2315
+ onStart && onStart({ item: draggingItem, from: con, index: i }, ev);
2316
+ lockPage();
2317
+ if (sort) {
2318
+ removeListenItems = listenItems(opts, con, toCopy ? draggingItem : copy, filteredItems, i);
2319
+ }
2320
+ if (moveMode && group && SORTABLE_GROUPS[group]) {
2321
+ collection.each(SORTABLE_GROUPS[group], ([sortable, ele]) => {
2322
+ const filtered = collection.reject(ele, (el) => el === container);
2323
+ if (is.isEmpty(filtered))
2324
+ return;
2325
+ sortable.active(toCopy ? draggingItem : copy, container, filtered, sortable.getOptions());
2326
+ });
2327
+ }
2328
+ }
2329
+ else {
2330
+ ev.preventDefault();
2331
+ return false;
2332
+ }
2333
+ }
2334
+ ghostNode.style.left = newX + "px";
2335
+ ghostNode.style.top = newY + "px";
2336
+ ev.preventDefault();
2337
+ return false;
2338
+ };
2339
+ const dragEndListener = (ev) => {
2340
+ var _a;
2341
+ document.removeEventListener("mousemove", dragListener);
2342
+ document.removeEventListener("mouseup", dragEndListener);
2343
+ window.removeEventListener("blur", dragEndListener);
2344
+ if (dragging) {
2345
+ unlockPage();
2346
+ restoreCursor();
2347
+ if (ghostNode)
2348
+ ghostContainer.removeChild(ghostNode);
2349
+ const toContainer = DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.toContainer;
2350
+ DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.item.classList.remove(CLASS_SORTABLE_ACTIVE);
2351
+ (_a = DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.copy) === null || _a === void 0 ? void 0 : _a.classList.remove(CLASS_SORTABLE_ACTIVE);
2352
+ DraggingData = null;
2353
+ if (removeListenItems)
2354
+ removeListenItems();
2355
+ if (group && SORTABLE_GROUPS[group]) {
2356
+ collection.each(SORTABLE_GROUPS[group], ([sortable, ele]) => {
2357
+ const filtered = collection.reject(ele, (el) => el === container);
2358
+ if (is.isEmpty(filtered))
2359
+ return;
2360
+ sortable.deactive(draggingItem, container, filtered, sortable.getOptions());
2361
+ });
2362
+ }
2363
+ onEnd && onEnd({ item: draggingItem, from: container, to: toContainer }, e);
2364
+ }
2365
+ };
2366
+ document.addEventListener("mousemove", dragListener);
2367
+ document.addEventListener("mouseup", dragEndListener);
2368
+ window.addEventListener("blur", dragEndListener);
2369
+ e.preventDefault();
2370
+ return false;
2371
+ });
2372
+ registerEvent(container, "mouseleave", (e) => {
2373
+ var _a, _b;
2374
+ if (!DraggingData)
2375
+ return;
2376
+ opts.onLeave &&
2377
+ opts.onLeave({
2378
+ item: DraggingData.item,
2379
+ from: DraggingData.fromContainer,
2380
+ to: container,
2381
+ }, e);
2382
+ if (DraggingData.moveTo !== 'copy') {
2383
+ if (DraggingData.spill === 'remove') {
2384
+ (_a = DraggingData.item.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(DraggingData.item);
2385
+ }
2386
+ else if (DraggingData.spill === 'revert') {
2387
+ (_b = DraggingData.item.parentElement) === null || _b === void 0 ? void 0 : _b.removeChild(DraggingData.item);
2388
+ const nextSibling = DraggingData.fromContainer.children[DraggingData.fromIndex];
2389
+ DraggingData.fromContainer.insertBefore(DraggingData.item, nextSibling);
2390
+ }
2391
+ }
2392
+ });
2393
+ registerEvent(container, "mouseenter", (e) => {
2394
+ var _a;
2395
+ if (!DraggingData)
2396
+ return;
2397
+ let draggingItem = DraggingData.item;
2398
+ draggingItem.parentElement;
2399
+ const cx = e.clientX;
2400
+ const cy = e.clientY;
2401
+ const rect = container.getBoundingClientRect();
2402
+ const centerX = rect.width / 2;
2403
+ const centerY = rect.height / 2;
2404
+ const offsetX = cx - rect.x;
2405
+ const offsetY = cy - rect.y;
2406
+ let dir = "";
2407
+ if (offsetX < centerX && offsetY < centerY) {
2408
+ dir = "tl";
2409
+ }
2410
+ else if (offsetX > centerX && offsetY > centerY) {
2411
+ dir = "br";
2412
+ }
2413
+ else if (offsetX < centerX && offsetY > centerY) {
2414
+ dir = "bl";
2415
+ }
2416
+ else if (offsetX > centerX && offsetY < centerY) {
2417
+ dir = "tr";
2418
+ }
2419
+ opts.onEnter &&
2420
+ opts.onEnter({
2421
+ item: DraggingData.item,
2422
+ from: DraggingData.fromContainer,
2423
+ to: container,
2424
+ dir,
2425
+ }, e);
2426
+ DraggingData.toContainer = container;
2427
+ if (container.getAttribute(ATTR_SORTABLE_ACTIVE)) {
2428
+ let valid = true;
2429
+ const moveFrom = (_a = opts.move) === null || _a === void 0 ? void 0 : _a.from;
2430
+ const acceptFn = is.isFunction(moveFrom) ? moveFrom : () => !!moveFrom;
2431
+ valid = acceptFn(DraggingData.item, DraggingData.fromContainer, container);
2432
+ if (!valid)
2433
+ return;
2434
+ if (container.contains(draggingItem)) {
2435
+ return;
2436
+ }
2437
+ const moveTo = DraggingData.moveTo;
2438
+ if (moveTo === "copy") {
2439
+ draggingItem = DraggingData.copy;
2440
+ }
2441
+ if (draggingItem.parentElement)
2442
+ draggingItem.parentElement.removeChild(draggingItem);
2443
+ let toIndex = 0;
2444
+ if (dir[0] === "t") {
2445
+ container.insertBefore(draggingItem, container.children[0]);
2446
+ }
2447
+ else {
2448
+ container.appendChild(draggingItem);
2449
+ toIndex = container.children.length - 1;
2450
+ }
2451
+ opts.onAdd &&
2452
+ opts.onAdd({
2453
+ item: draggingItem,
2454
+ from: DraggingData.fromContainer,
2455
+ to: container,
2456
+ index: toIndex,
2457
+ }, e);
2458
+ }
2459
+ else if (container === DraggingData.fromContainer) {
2460
+ if (DraggingData.copy) {
2461
+ let parent = DraggingData.copy.parentElement;
2462
+ if (parent)
2463
+ parent.removeChild(DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.copy);
2464
+ }
2465
+ else {
2466
+ if (draggingItem.parentElement)
2467
+ draggingItem.parentElement.removeChild(draggingItem);
2468
+ if (dir[0] === "t") {
2469
+ container.insertBefore(draggingItem, container.children[0]);
2470
+ }
2471
+ else {
2472
+ container.appendChild(draggingItem);
2473
+ container.children.length - 1;
2474
+ }
2475
+ }
2476
+ }
2477
+ });
2478
+ }
2479
+ function listenItems(opts, toContainer, draggingItem, items, fromIndex = 0) {
2480
+ const listener = (e) => {
2481
+ const ct = e.currentTarget;
2482
+ if (ct.style.transform) {
2483
+ return;
2484
+ }
2485
+ const toIndex = ct._uiik_i;
2486
+ let draggingItem = (DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.copy) || (DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.item);
2487
+ if (toContainer === (DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.fromContainer)) {
2488
+ draggingItem = DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.item;
2489
+ }
2490
+ let parent = draggingItem.parentElement;
2491
+ parent === null || parent === void 0 ? void 0 : parent.removeChild(draggingItem);
2492
+ const sameContainer = parent === ct.parentElement;
2493
+ if (!sameContainer) {
2494
+ parent = ct.parentElement;
2495
+ }
2496
+ const oldIndex = fromIndex;
2497
+ if (toIndex > fromIndex) {
2498
+ fromIndex = toIndex;
2499
+ parent === null || parent === void 0 ? void 0 : parent.insertBefore(draggingItem, ct.nextElementSibling);
2500
+ }
2501
+ else {
2502
+ fromIndex = toIndex - 1;
2503
+ parent === null || parent === void 0 ? void 0 : parent.insertBefore(draggingItem, ct);
2504
+ }
2505
+ opts.onChange &&
2506
+ opts.onChange({
2507
+ item: draggingItem,
2508
+ from: DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.fromContainer,
2509
+ to: toContainer,
2510
+ fromIndex: oldIndex,
2511
+ toIndex: fromIndex,
2512
+ }, e);
2513
+ const toPos = { x: ct.offsetLeft, y: ct.offsetTop };
2514
+ const fromPos = { x: draggingItem.offsetLeft, y: draggingItem.offsetTop };
2515
+ ct.style.transform = `translate3d(${fromPos.x - toPos.x}px,${fromPos.y - toPos.y}px,0)`;
2516
+ draggingItem.style.transform = `translate3d(${toPos.x - fromPos.x}px,${toPos.y - fromPos.y}px,0)`;
2517
+ draggingItem.offsetHeight;
2518
+ ct.offsetHeight;
2519
+ draggingItem.style.transition = "transform .15s";
2520
+ draggingItem.style.transform = `translate3d(0px,0px,0)`;
2521
+ ct.style.transition = "transform .15s";
2522
+ ct.style.transform = `translate3d(0px,0px,0)`;
2523
+ setTimeout(() => {
2524
+ ct.style.transition = "";
2525
+ ct.style.transform = ``;
2526
+ draggingItem.style.transition = "";
2527
+ draggingItem.style.transform = ``;
2528
+ }, 150);
2529
+ e.stopPropagation();
2530
+ e.preventDefault();
2531
+ };
2532
+ collection.each(items, (item, i) => {
2533
+ item.style.position = "relative";
2534
+ if (item === draggingItem)
2535
+ return;
2536
+ item.style.pointerEvents = "initial";
2537
+ item._uiik_i = i;
2538
+ item.addEventListener("mouseenter", listener);
2539
+ });
2540
+ return () => {
2541
+ collection.each(items, (item, i) => {
2542
+ if (item === draggingItem)
2543
+ return;
2544
+ item.removeEventListener("mouseenter", listener);
2545
+ });
2546
+ };
2547
+ }
2548
+ function newSortable(container, opts) {
2549
+ return new Sortable(container, opts);
2550
+ }
2551
+
2552
+ var version = "1.3.0-alpha";
1960
2553
  var repository = {
1961
2554
  type: "git",
1962
2555
  url: "https://github.com/holyhigh2/uiik"
1963
2556
  };
1964
2557
 
1965
- // welcome info
1966
2558
  const welcome = globalThis.welcome;
1967
2559
  if (!welcome) {
1968
2560
  const ssAry = [];
@@ -1986,26 +2578,52 @@
1986
2578
  newDraggable,
1987
2579
  newDroppable,
1988
2580
  newRotatable,
1989
- newSelectable
2581
+ newSelectable,
2582
+ newSortable
1990
2583
  };
1991
2584
 
1992
2585
  exports.CollisionDetector = CollisionDetector;
2586
+ exports.DRAGGING_RULE = DRAGGING_RULE;
1993
2587
  exports.Draggable = Draggable;
1994
2588
  exports.Droppable = Droppable;
2589
+ exports.EDGE_THRESHOLD = EDGE_THRESHOLD;
2590
+ exports.ONE_ANG = ONE_ANG;
2591
+ exports.ONE_RAD = ONE_RAD;
1995
2592
  exports.Resizable = Resizable;
1996
2593
  exports.Rotatable = Rotatable;
1997
2594
  exports.Selectable = Selectable;
2595
+ exports.Sortable = Sortable;
1998
2596
  exports.Splittable = Splittable;
1999
2597
  exports.Uii = Uii;
2598
+ exports.UiiTransformer = UiiTransformer;
2000
2599
  exports.VERSION = VERSION;
2001
2600
  exports["default"] = index;
2601
+ exports.getBox = getBox;
2602
+ exports.getCenterXy = getCenterXy;
2603
+ exports.getMatrixInfo = getMatrixInfo;
2604
+ exports.getPointInContainer = getPointInContainer;
2605
+ exports.getPointOffset = getPointOffset;
2606
+ exports.getRectInContainer = getRectInContainer;
2607
+ exports.getStyleXy = getStyleXy;
2608
+ exports.getTranslate = getTranslate;
2609
+ exports.isSVGEl = isSVGEl;
2610
+ exports.lockPage = lockPage;
2611
+ exports.moveBy = moveBy;
2612
+ exports.moveTo = moveTo;
2002
2613
  exports.newCollisionDetector = newCollisionDetector;
2003
2614
  exports.newDraggable = newDraggable;
2004
2615
  exports.newDroppable = newDroppable;
2005
2616
  exports.newResizable = newResizable;
2006
2617
  exports.newRotatable = newRotatable;
2007
2618
  exports.newSelectable = newSelectable;
2619
+ exports.newSortable = newSortable;
2008
2620
  exports.newSplittable = newSplittable;
2621
+ exports.restoreCursor = restoreCursor;
2622
+ exports.rotateTo = rotateTo;
2623
+ exports.saveCursor = saveCursor;
2624
+ exports.setCursor = setCursor;
2625
+ exports.unlockPage = unlockPage;
2626
+ exports.wrapper = wrapper;
2009
2627
 
2010
2628
  Object.defineProperty(exports, '__esModule', { value: true });
2011
2629