uiik 1.3.0-beta.1 → 1.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/detector.d.ts +0 -19
- package/draggable.d.ts +0 -20
- package/droppable.d.ts +0 -21
- package/index.esm.js +52 -449
- package/index.js +55 -451
- package/package.json +1 -1
- package/resizable.d.ts +0 -14
- package/rotatable.d.ts +0 -14
- package/selectable.d.ts +0 -20
- package/sortable.d.ts +0 -24
- package/splittable.d.ts +0 -17
- package/transform.d.ts +2 -28
- package/types.d.ts +7 -311
- package/utils.d.ts +0 -82
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* uiik v1.3.0-beta.
|
|
2
|
+
* uiik v1.3.0-beta.2
|
|
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
|
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
import { isDefined, isString, isNumber, isArrayLike, isElement, isEmpty, isArray, isFunction, isBoolean, isUndefined } from 'myfx/is';
|
|
8
8
|
import { find, map, toArray, each, reject, includes, some, flatMap, size } from 'myfx/collection';
|
|
9
9
|
import { get, assign, merge } from 'myfx/object';
|
|
10
|
-
import {
|
|
11
|
-
import { lowerCase, split, test } from 'myfx/string';
|
|
10
|
+
import { split, test } from 'myfx/string';
|
|
12
11
|
import { compact, findIndex } from 'myfx/array';
|
|
13
12
|
import { alphaId } from 'myfx/utils';
|
|
14
13
|
|
|
@@ -45,9 +44,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
45
44
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
/* eslint-disable max-len */
|
|
49
47
|
const UtMap = new WeakMap();
|
|
50
|
-
class
|
|
48
|
+
class UiiTransform {
|
|
51
49
|
constructor(el) {
|
|
52
50
|
this.angle = 0;
|
|
53
51
|
this.el = el;
|
|
@@ -78,14 +76,9 @@ class UiiTransformer {
|
|
|
78
76
|
rotateTo(this.el, deg, cx, cy);
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
/**
|
|
82
|
-
* 统一化处理,所有外边距都处理为translate
|
|
83
|
-
* @param el
|
|
84
|
-
*/
|
|
85
79
|
function normalize(el) {
|
|
86
80
|
const style = window.getComputedStyle(el);
|
|
87
81
|
let x = 0, y = 0;
|
|
88
|
-
//1. convert left/top (include margins)
|
|
89
82
|
if (el instanceof HTMLElement) {
|
|
90
83
|
x = (parseFloat(style.left) || 0) + (parseFloat(style.marginLeft) || 0);
|
|
91
84
|
y = (parseFloat(style.top) || 0) + (parseFloat(style.marginTop) || 0);
|
|
@@ -105,36 +98,25 @@ function normalize(el) {
|
|
|
105
98
|
el.removeAttribute("cx");
|
|
106
99
|
el.removeAttribute("cy");
|
|
107
100
|
}
|
|
108
|
-
//2. merge transform
|
|
109
101
|
const { x: tx, y: ty } = getTranslate(el);
|
|
110
102
|
x += tx || 0;
|
|
111
103
|
y += ty || 0;
|
|
112
104
|
moveTo(el, x, y);
|
|
113
105
|
return { x, y };
|
|
114
106
|
}
|
|
115
|
-
/**
|
|
116
|
-
* 返回一个包装后的变形对象,可执行变形操作
|
|
117
|
-
* @param el
|
|
118
|
-
*/
|
|
119
107
|
function wrapper(el) {
|
|
120
108
|
let ut = UtMap.get(el);
|
|
121
109
|
if (ut)
|
|
122
110
|
return ut.normalize(el);
|
|
123
|
-
return new
|
|
111
|
+
return new UiiTransform(el);
|
|
124
112
|
}
|
|
125
113
|
function transformMove(transofrmStr, x, y, unit = false) {
|
|
126
114
|
return (`translate(${x}${unit ? "px" : ""},${y}${unit ? "px" : ""}) ` +
|
|
127
115
|
transofrmStr.replace(/translate\([^)]+?\)/, "").trim());
|
|
128
116
|
}
|
|
129
|
-
/**
|
|
130
|
-
* 获取元素当前transform中的位移数据
|
|
131
|
-
* @param el HTMLElement|SVGGraphicsElement
|
|
132
|
-
* @returns {x,y}
|
|
133
|
-
*/
|
|
134
117
|
function getTranslate(el) {
|
|
135
118
|
let xVal = NaN, yVal = NaN;
|
|
136
119
|
let transformStr = "";
|
|
137
|
-
//svg
|
|
138
120
|
if (el instanceof SVGGraphicsElement) {
|
|
139
121
|
transformStr = el.getAttribute("transform") || "";
|
|
140
122
|
}
|
|
@@ -162,14 +144,7 @@ function getTranslate(el) {
|
|
|
162
144
|
}
|
|
163
145
|
return { x: xVal, y: yVal };
|
|
164
146
|
}
|
|
165
|
-
/**
|
|
166
|
-
* 自动检测HTML元素或SVG元素并设置对应移动属性
|
|
167
|
-
* @param el HTMLElement|SVGGraphicsElement
|
|
168
|
-
* @param x value of px
|
|
169
|
-
* @param y value of px
|
|
170
|
-
*/
|
|
171
147
|
function moveTo(el, x, y) {
|
|
172
|
-
//svg
|
|
173
148
|
if (el instanceof SVGGraphicsElement) {
|
|
174
149
|
el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", x, y));
|
|
175
150
|
}
|
|
@@ -180,15 +155,8 @@ function moveTo(el, x, y) {
|
|
|
180
155
|
}
|
|
181
156
|
const EXP_GET_TRANSLATE = /translate\(\s*(?<x>[\d.-]+)\D*,\s*(?<y>[\d.-]+)\D*\)/gim;
|
|
182
157
|
const EXP_GET_TRANSLATE_XY = /translate(?<dir>X|Y)\(\s*(?<v>[\d.-]+)\D*\)/gim;
|
|
183
|
-
/**
|
|
184
|
-
* 自动检测HTML元素或SVG元素并设置对应移动属性
|
|
185
|
-
* @param el HTMLElement|SVGGraphicsElement
|
|
186
|
-
* @param x value of px
|
|
187
|
-
* @param y value of px
|
|
188
|
-
*/
|
|
189
158
|
function moveBy(el, x, y) {
|
|
190
159
|
const xy = getTranslate(el);
|
|
191
|
-
//svg
|
|
192
160
|
if (el instanceof SVGGraphicsElement) {
|
|
193
161
|
el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", xy.x + x, xy.y + y));
|
|
194
162
|
}
|
|
@@ -198,13 +166,11 @@ function moveBy(el, x, y) {
|
|
|
198
166
|
}
|
|
199
167
|
}
|
|
200
168
|
function rotateTo(el, deg, cx, cy) {
|
|
201
|
-
//svg
|
|
202
169
|
if (el instanceof SVGGraphicsElement) {
|
|
203
170
|
let transformStr = el.getAttribute("transform") || "";
|
|
204
171
|
let originPos = isDefined(cx) && isDefined(cy);
|
|
205
172
|
let origin = "";
|
|
206
173
|
if (originPos) {
|
|
207
|
-
//origin offset
|
|
208
174
|
if (el.x instanceof SVGAnimatedLength) {
|
|
209
175
|
cx += el.x.animVal.value;
|
|
210
176
|
cy += el.y.animVal.value;
|
|
@@ -231,21 +197,8 @@ function rotateTo(el, deg, cx, cy) {
|
|
|
231
197
|
}
|
|
232
198
|
}
|
|
233
199
|
|
|
234
|
-
/* eslint-disable max-len */
|
|
235
|
-
/**
|
|
236
|
-
* 一角度对应的弧度
|
|
237
|
-
*/
|
|
238
200
|
const ONE_ANG = Math.PI / 180;
|
|
239
|
-
/**
|
|
240
|
-
* 一弧度对应的角度
|
|
241
|
-
*/
|
|
242
201
|
const ONE_RAD = 180 / Math.PI;
|
|
243
|
-
/**
|
|
244
|
-
* 获取child相对于parent的位置信息。含border宽度
|
|
245
|
-
*
|
|
246
|
-
* todo
|
|
247
|
-
* @returns {x,y,w,h}
|
|
248
|
-
*/
|
|
249
202
|
function getBox(child, parent) {
|
|
250
203
|
const rect = child.getBoundingClientRect();
|
|
251
204
|
const rs = { x: 0, y: 0, w: rect.width, h: rect.height };
|
|
@@ -255,7 +208,7 @@ function getBox(child, parent) {
|
|
|
255
208
|
child.ownerSVGElement ||
|
|
256
209
|
child.parentElement ||
|
|
257
210
|
document.body;
|
|
258
|
-
const parentRect = parent.getBoundingClientRect();
|
|
211
|
+
const parentRect = parent.getBoundingClientRect();
|
|
259
212
|
const parentStyle = window.getComputedStyle(parent);
|
|
260
213
|
const parentBorderLeft = parseFloat(parentStyle.borderLeftWidth);
|
|
261
214
|
const parentBorderTop = parseFloat(parentStyle.borderTopWidth);
|
|
@@ -268,11 +221,6 @@ function getBox(child, parent) {
|
|
|
268
221
|
}
|
|
269
222
|
return rs;
|
|
270
223
|
}
|
|
271
|
-
/**
|
|
272
|
-
* 获取事件目标与点击点之间的偏移
|
|
273
|
-
* @param e
|
|
274
|
-
* @returns [offx,offy]
|
|
275
|
-
*/
|
|
276
224
|
function getPointOffset(e, pos) {
|
|
277
225
|
let ox = e.offsetX || 0, oy = e.offsetY || 0;
|
|
278
226
|
if (e.target instanceof SVGElement) {
|
|
@@ -284,9 +232,6 @@ function getPointOffset(e, pos) {
|
|
|
284
232
|
function isSVGEl(el) {
|
|
285
233
|
return el instanceof SVGElement;
|
|
286
234
|
}
|
|
287
|
-
/**
|
|
288
|
-
* 边缘检测最小内部边距
|
|
289
|
-
*/
|
|
290
235
|
const EDGE_THRESHOLD = 5;
|
|
291
236
|
const DRAGGING_RULE = "body * { pointer-events: none; }";
|
|
292
237
|
let lockSheet;
|
|
@@ -319,10 +264,6 @@ function restoreCursor() {
|
|
|
319
264
|
document.body.style.cursor = cursor.body;
|
|
320
265
|
document.documentElement.style.cursor = cursor.html;
|
|
321
266
|
}
|
|
322
|
-
/**
|
|
323
|
-
* 获取元素样式/属性中的x/y
|
|
324
|
-
* @param el
|
|
325
|
-
*/
|
|
326
267
|
function getStyleXy(el) {
|
|
327
268
|
const style = window.getComputedStyle(el);
|
|
328
269
|
let x = 0, y = 0;
|
|
@@ -336,10 +277,6 @@ function getStyleXy(el) {
|
|
|
336
277
|
}
|
|
337
278
|
return { x, y };
|
|
338
279
|
}
|
|
339
|
-
/**
|
|
340
|
-
* 获取元素样式/属性中的w/h
|
|
341
|
-
* @param el
|
|
342
|
-
*/
|
|
343
280
|
function getStyleSize(el, cStyle) {
|
|
344
281
|
if (!cStyle)
|
|
345
282
|
cStyle = window.getComputedStyle(el);
|
|
@@ -348,11 +285,6 @@ function getStyleSize(el, cStyle) {
|
|
|
348
285
|
return { w, h };
|
|
349
286
|
}
|
|
350
287
|
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*\)/;
|
|
351
|
-
/**
|
|
352
|
-
* 获取matrix中的scale/angle
|
|
353
|
-
* @param elCStyle
|
|
354
|
-
* @returns
|
|
355
|
-
*/
|
|
356
288
|
function getMatrixInfo(elCStyle) {
|
|
357
289
|
let a = 1, b = 0, x = 0, y = 0;
|
|
358
290
|
let e = undefined, f = undefined;
|
|
@@ -387,14 +319,6 @@ function getMatrixInfo(elCStyle) {
|
|
|
387
319
|
rs.angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
|
|
388
320
|
return rs;
|
|
389
321
|
}
|
|
390
|
-
/**
|
|
391
|
-
* 获取当前鼠标相对于指定元素el的坐标
|
|
392
|
-
* @param event 点击事件
|
|
393
|
-
* @param el 元素
|
|
394
|
-
* @param elRect 元素的DOMRect
|
|
395
|
-
* @param elCStyle 元素的计算样式
|
|
396
|
-
* @returns
|
|
397
|
-
*/
|
|
398
322
|
function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
|
|
399
323
|
if (!elRect) {
|
|
400
324
|
elRect = el.getBoundingClientRect();
|
|
@@ -416,11 +340,6 @@ function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
|
|
|
416
340
|
el.scrollTop * scale;
|
|
417
341
|
return { x: x / scale, y: y / scale };
|
|
418
342
|
}
|
|
419
|
-
/**
|
|
420
|
-
* 获取元素el在容器container中的相对boundingBox
|
|
421
|
-
* @param el
|
|
422
|
-
* @param container
|
|
423
|
-
*/
|
|
424
343
|
function getRectInContainer(el, container) {
|
|
425
344
|
const elRect = el.getBoundingClientRect();
|
|
426
345
|
const containerRect = container.getBoundingClientRect();
|
|
@@ -442,21 +361,12 @@ function getRectInContainer(el, container) {
|
|
|
442
361
|
h: elRect.height / scale,
|
|
443
362
|
};
|
|
444
363
|
}
|
|
445
|
-
/**
|
|
446
|
-
* 获取指定元素的圆心坐标
|
|
447
|
-
* @param el
|
|
448
|
-
* @param left
|
|
449
|
-
* @param top
|
|
450
|
-
* @returns
|
|
451
|
-
*/
|
|
452
364
|
function getCenterXy(el, ox, oy) {
|
|
453
365
|
const cStyle = window.getComputedStyle(el);
|
|
454
|
-
//origin
|
|
455
366
|
const center = cStyle.transformOrigin;
|
|
456
367
|
const centerPair = center.split(" ");
|
|
457
368
|
ox = ox || parseFloat(centerPair[0]);
|
|
458
369
|
oy = oy || parseFloat(centerPair[1]);
|
|
459
|
-
//left & top
|
|
460
370
|
const shadowDom = el.cloneNode();
|
|
461
371
|
rotateTo(shadowDom, 0);
|
|
462
372
|
const parentEl = el.parentElement;
|
|
@@ -473,12 +383,6 @@ function getCenterXySVG(el, ox, oy) {
|
|
|
473
383
|
const { x, y } = getTranslate(el);
|
|
474
384
|
return { sx: x, sy: y, x: x + ox, y: y + oy, ox, oy };
|
|
475
385
|
}
|
|
476
|
-
/**
|
|
477
|
-
* 获取元素当前顶点
|
|
478
|
-
* @param el
|
|
479
|
-
* @param ox 相对于图形左上角的圆心偏移,支持数字/百分比,仅对SVG元素有效,对于非SVG元素使用transform-origin属性
|
|
480
|
-
* @param oy
|
|
481
|
-
*/
|
|
482
386
|
function getVertex(el, ox, oy) {
|
|
483
387
|
const cStyle = window.getComputedStyle(el);
|
|
484
388
|
const w = parseFloat(cStyle.width);
|
|
@@ -488,17 +392,6 @@ function getVertex(el, ox, oy) {
|
|
|
488
392
|
const { angle } = getMatrixInfo(cStyle);
|
|
489
393
|
return calcVertex(w, h, x, y, sx, sy, angle * ONE_ANG);
|
|
490
394
|
}
|
|
491
|
-
/**
|
|
492
|
-
* 计算指定矩形旋转后的顶点坐标
|
|
493
|
-
* @param w 宽
|
|
494
|
-
* @param h 高
|
|
495
|
-
* @param cx 圆心
|
|
496
|
-
* @param cy
|
|
497
|
-
* @param sx
|
|
498
|
-
* @param sy
|
|
499
|
-
* @param radian 旋转角 弧度值
|
|
500
|
-
* @returns
|
|
501
|
-
*/
|
|
502
395
|
function calcVertex(w, h, cx, cy, sx, sy, radian) {
|
|
503
396
|
let originVertex = [
|
|
504
397
|
{ x: 0, y: 0 },
|
|
@@ -514,25 +407,15 @@ function calcVertex(w, h, cx, cy, sx, sy, radian) {
|
|
|
514
407
|
return { x: cx + nx, y: cy + ny };
|
|
515
408
|
});
|
|
516
409
|
}
|
|
517
|
-
/**
|
|
518
|
-
* 解析ox/y
|
|
519
|
-
* @param ox 如果不是number或string,originX为0
|
|
520
|
-
* @param oy 如果不是number或string,originY为0
|
|
521
|
-
* @param w
|
|
522
|
-
* @param h
|
|
523
|
-
* @returns {originX,originY}
|
|
524
|
-
*/
|
|
525
410
|
function parseOxy(ox, oy, w, h) {
|
|
526
411
|
let originX = 0, originY = 0;
|
|
527
412
|
if (isString(ox)) {
|
|
528
|
-
//percent
|
|
529
413
|
originX = (parseFloat(ox) / 100) * w;
|
|
530
414
|
}
|
|
531
415
|
else if (isNumber(ox)) {
|
|
532
416
|
originX = ox;
|
|
533
417
|
}
|
|
534
418
|
if (isString(oy)) {
|
|
535
|
-
//percent
|
|
536
419
|
originY = (parseFloat(oy) / 100) * h;
|
|
537
420
|
}
|
|
538
421
|
else if (isNumber(oy)) {
|
|
@@ -542,9 +425,6 @@ function parseOxy(ox, oy, w, h) {
|
|
|
542
425
|
}
|
|
543
426
|
|
|
544
427
|
var _Uii_listeners;
|
|
545
|
-
/**
|
|
546
|
-
* A Base class for all Uii classes
|
|
547
|
-
*/
|
|
548
428
|
class Uii {
|
|
549
429
|
constructor(ele, opts) {
|
|
550
430
|
this.enabled = true;
|
|
@@ -572,16 +452,12 @@ class Uii {
|
|
|
572
452
|
this.ele = isArrayLike(el) ? toArray(el) : [el];
|
|
573
453
|
}
|
|
574
454
|
}
|
|
575
|
-
/**
|
|
576
|
-
* 销毁uii对象,包括卸载事件、清空元素等
|
|
577
|
-
*/
|
|
578
455
|
destroy() {
|
|
579
456
|
each(__classPrivateFieldGet(this, _Uii_listeners, "f"), (ev) => {
|
|
580
457
|
ev[0].removeEventListener(ev[1], ev[2], ev[3]);
|
|
581
458
|
});
|
|
582
459
|
__classPrivateFieldSet(this, _Uii_listeners, [], "f");
|
|
583
460
|
}
|
|
584
|
-
//通用指针事件处理接口
|
|
585
461
|
addPointerDown(el, pointerDown, opts) {
|
|
586
462
|
const onPointerDown = pointerDown;
|
|
587
463
|
const threshold = opts.threshold || 0;
|
|
@@ -591,9 +467,7 @@ class Uii {
|
|
|
591
467
|
let t = e.target;
|
|
592
468
|
if (!t)
|
|
593
469
|
return;
|
|
594
|
-
//uiik options
|
|
595
470
|
const hasCursor = !isEmpty(get(uiiOptions, 'cursor.active'));
|
|
596
|
-
//提取通用信息
|
|
597
471
|
const currentStyle = el.style;
|
|
598
472
|
const currentCStyle = window.getComputedStyle(el);
|
|
599
473
|
const currentRect = el.getBoundingClientRect();
|
|
@@ -618,7 +492,6 @@ class Uii {
|
|
|
618
492
|
e.preventDefault();
|
|
619
493
|
return false;
|
|
620
494
|
}
|
|
621
|
-
//函数
|
|
622
495
|
const pointerMove = (ev) => {
|
|
623
496
|
const offX = ev.clientX - originPosX;
|
|
624
497
|
const offY = ev.clientY - originPosY;
|
|
@@ -661,13 +534,6 @@ class Uii {
|
|
|
661
534
|
return false;
|
|
662
535
|
}, true);
|
|
663
536
|
}
|
|
664
|
-
/**
|
|
665
|
-
* 注册事件,以便在{@link destroy}方法中卸载
|
|
666
|
-
* @param el dom元素
|
|
667
|
-
* @param event 事件名
|
|
668
|
-
* @param hook 回调函数
|
|
669
|
-
* @param useCapture 默认false
|
|
670
|
-
*/
|
|
671
537
|
registerEvent(el, event, hook, useCapture = false) {
|
|
672
538
|
const wrapper = ((ev) => {
|
|
673
539
|
if (!this.enabled)
|
|
@@ -677,52 +543,26 @@ class Uii {
|
|
|
677
543
|
el.addEventListener(event, wrapper, useCapture);
|
|
678
544
|
__classPrivateFieldGet(this, _Uii_listeners, "f").push([el, event, wrapper, useCapture]);
|
|
679
545
|
}
|
|
680
|
-
/**
|
|
681
|
-
* 禁用uii实例,禁用后的dom不会响应事件
|
|
682
|
-
*/
|
|
683
546
|
disable() {
|
|
684
547
|
this.enabled = false;
|
|
685
548
|
}
|
|
686
|
-
/**
|
|
687
|
-
* 启用uii实例
|
|
688
|
-
*/
|
|
689
549
|
enable() {
|
|
690
550
|
this.enabled = true;
|
|
691
551
|
}
|
|
692
|
-
/**
|
|
693
|
-
* 获取uii实例选项对象
|
|
694
|
-
*/
|
|
695
552
|
getOptions() {
|
|
696
553
|
return this.opts;
|
|
697
554
|
}
|
|
698
|
-
/**
|
|
699
|
-
* 获取指定名称的选项值
|
|
700
|
-
* @param name
|
|
701
|
-
* @returns
|
|
702
|
-
*/
|
|
703
555
|
getOption(name) {
|
|
704
556
|
return this.opts[name];
|
|
705
557
|
}
|
|
706
|
-
/**
|
|
707
|
-
* 设置多个选项值。触发`onOptionChanged`
|
|
708
|
-
* @param options
|
|
709
|
-
*/
|
|
710
558
|
setOptions(options) {
|
|
711
559
|
assign(this.opts, options);
|
|
712
560
|
this.onOptionChanged(this.opts);
|
|
713
561
|
}
|
|
714
|
-
/**
|
|
715
|
-
* 设置指定name的选项值。触发`onOptionChanged`
|
|
716
|
-
* @param name
|
|
717
|
-
* @param value
|
|
718
|
-
*/
|
|
719
562
|
setOption(name, value) {
|
|
720
563
|
this.opts[name] = value;
|
|
721
564
|
this.onOptionChanged(this.opts);
|
|
722
565
|
}
|
|
723
|
-
/**
|
|
724
|
-
* @internal
|
|
725
|
-
*/
|
|
726
566
|
onOptionChanged(opts) { }
|
|
727
567
|
}
|
|
728
568
|
_Uii_listeners = new WeakMap();
|
|
@@ -742,17 +582,6 @@ function getRootEl(el, root) {
|
|
|
742
582
|
}
|
|
743
583
|
return rs;
|
|
744
584
|
}
|
|
745
|
-
/**
|
|
746
|
-
* 用于表示一个或多个分割器的定义
|
|
747
|
-
* > 可用CSS接口
|
|
748
|
-
* - .uii-splittable
|
|
749
|
-
* - .uii-splittable-handle
|
|
750
|
-
* - .uii-splittable-handle-ghost
|
|
751
|
-
* - .uii-splittable-handle-active
|
|
752
|
-
* - .uii-splittable-v
|
|
753
|
-
* - .uii-splittable-h
|
|
754
|
-
* @public
|
|
755
|
-
*/
|
|
756
585
|
class Splittable extends Uii {
|
|
757
586
|
constructor(container, opts) {
|
|
758
587
|
super(container, assign({
|
|
@@ -764,7 +593,6 @@ class Splittable extends Uii {
|
|
|
764
593
|
}, opts));
|
|
765
594
|
_Splittable_instances.add(this);
|
|
766
595
|
each(this.ele, con => {
|
|
767
|
-
//detect container position
|
|
768
596
|
const pos = window.getComputedStyle(con).position;
|
|
769
597
|
if (pos === "static") {
|
|
770
598
|
con.style.position = "relative";
|
|
@@ -863,11 +691,10 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
863
691
|
const updateStart = !oneSideMode || oneSideMode === 'start';
|
|
864
692
|
const updateEnd = !oneSideMode || oneSideMode === 'end';
|
|
865
693
|
this.addPointerDown(handle, ({ currentTarget, onPointerStart, onPointerMove, onPointerEnd }) => {
|
|
866
|
-
// 1. 获取原始高度/宽度;设置宽度/高度
|
|
867
694
|
let originSize = 0;
|
|
868
695
|
let originSize1 = 0;
|
|
869
696
|
let splitterSize = 1;
|
|
870
|
-
let blockSize = 0;
|
|
697
|
+
let blockSize = 0;
|
|
871
698
|
switch (dir) {
|
|
872
699
|
case 'v':
|
|
873
700
|
originSize = dom1.offsetHeight;
|
|
@@ -883,11 +710,9 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
883
710
|
blockSize = splitterSize + originSize + originSize1;
|
|
884
711
|
const dom1Style = dom1.style;
|
|
885
712
|
const dom2Style = dom2.style;
|
|
886
|
-
//ghost
|
|
887
713
|
const ghost = opts.ghost;
|
|
888
714
|
const ghostClass = opts.ghostClass;
|
|
889
715
|
let ghostNode = null;
|
|
890
|
-
// 初始化sticked位置
|
|
891
716
|
let sticked = 'none';
|
|
892
717
|
if (originSize < minSize1 / 2) {
|
|
893
718
|
sticked = 'start';
|
|
@@ -897,7 +722,6 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
897
722
|
}
|
|
898
723
|
let startPos = dir === 'v' ? dom1.offsetTop : dom1.offsetLeft;
|
|
899
724
|
let ds1, anotherSize;
|
|
900
|
-
//bind events
|
|
901
725
|
onPointerStart(function (args) {
|
|
902
726
|
const { ev } = args;
|
|
903
727
|
currentTarget.classList.add(CLASS_SPLITTABLE_HANDLE_ACTIVE);
|
|
@@ -931,7 +755,6 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
931
755
|
else if (ds1 < minSize1) {
|
|
932
756
|
ds1 = minSize1;
|
|
933
757
|
if (sticked == 'start' && sticky1) {
|
|
934
|
-
// 重置状态
|
|
935
758
|
doSticky = true;
|
|
936
759
|
sticked = 'none';
|
|
937
760
|
}
|
|
@@ -947,7 +770,6 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
947
770
|
else if (blockSize - ds1 - splitterSize < minSize2) {
|
|
948
771
|
ds1 = blockSize - minSize2 - splitterSize;
|
|
949
772
|
if (sticked == 'end' && sticky2) {
|
|
950
|
-
// 重置状态
|
|
951
773
|
doSticky = true;
|
|
952
774
|
sticked = 'none';
|
|
953
775
|
}
|
|
@@ -972,7 +794,6 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
972
794
|
if (doSticky) {
|
|
973
795
|
onSticky && onSticky({ size1: ds1, size2: anotherSize, position: sticked }, ev);
|
|
974
796
|
}
|
|
975
|
-
//update handle
|
|
976
797
|
if (dir === 'v') {
|
|
977
798
|
currentStyle.top = dom2.offsetTop - handleSize / 2 + 'px';
|
|
978
799
|
}
|
|
@@ -1004,7 +825,6 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
1004
825
|
if (updateEnd) {
|
|
1005
826
|
dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
|
|
1006
827
|
}
|
|
1007
|
-
//update handle
|
|
1008
828
|
if (dir === 'v') {
|
|
1009
829
|
currentStyle.top = startPos + ds1 - handleSize / 2 + 'px';
|
|
1010
830
|
}
|
|
@@ -1020,30 +840,15 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
|
|
|
1020
840
|
lockPage: true
|
|
1021
841
|
});
|
|
1022
842
|
};
|
|
1023
|
-
/**
|
|
1024
|
-
* Add one or more splittors into the container
|
|
1025
|
-
* @param container css selector or html element
|
|
1026
|
-
* @param opts SplittableOptions
|
|
1027
|
-
* @returns
|
|
1028
|
-
*/
|
|
1029
843
|
function newSplittable(container, opts) {
|
|
1030
844
|
return new Splittable(container, opts);
|
|
1031
845
|
}
|
|
1032
846
|
|
|
1033
|
-
/* eslint-disable max-len */
|
|
1034
847
|
const THRESHOLD$3 = 2;
|
|
1035
848
|
const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
|
|
1036
849
|
const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
|
|
1037
850
|
const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
|
|
1038
851
|
const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
|
|
1039
|
-
/**
|
|
1040
|
-
* 用于表示一个或多个可改变尺寸元素的定义
|
|
1041
|
-
* > 可用CSS接口
|
|
1042
|
-
* - .uii-resizable-handle
|
|
1043
|
-
* - .uii-resizable-handle-[n/s/e/w/ne/nw/se/sw]
|
|
1044
|
-
* - .uii-resizable-handle-active
|
|
1045
|
-
* @public
|
|
1046
|
-
*/
|
|
1047
852
|
class Resizable extends Uii {
|
|
1048
853
|
constructor(els, opts) {
|
|
1049
854
|
super(els, assign({
|
|
@@ -1072,15 +877,13 @@ class Resizable extends Uii {
|
|
|
1072
877
|
const onClone = opts.onClone;
|
|
1073
878
|
const uiik = this;
|
|
1074
879
|
this.addPointerDown(handle, ({ ev, onPointerStart, onPointerMove, onPointerEnd }) => {
|
|
1075
|
-
//检测
|
|
1076
880
|
const onPointerDown = opts.onPointerDown;
|
|
1077
881
|
if (onPointerDown && onPointerDown(ev) === false)
|
|
1078
882
|
return true;
|
|
1079
883
|
let container = panel instanceof SVGGraphicsElement
|
|
1080
|
-
?
|
|
884
|
+
? panel.ownerSVGElement
|
|
1081
885
|
: panel.parentElement;
|
|
1082
886
|
let setOrigin = !(panel instanceof SVGGraphicsElement);
|
|
1083
|
-
// 获取panel当前信息
|
|
1084
887
|
let matrixInfo = getMatrixInfo(panel);
|
|
1085
888
|
const offset = getRectInContainer(panel, container);
|
|
1086
889
|
const offsetParentRect = container.getBoundingClientRect();
|
|
@@ -1128,7 +931,6 @@ class Resizable extends Uii {
|
|
|
1128
931
|
toTransformOrigin = "0 0";
|
|
1129
932
|
break;
|
|
1130
933
|
}
|
|
1131
|
-
// boundary
|
|
1132
934
|
let minWidth;
|
|
1133
935
|
let minHeight;
|
|
1134
936
|
let maxWidth;
|
|
@@ -1149,28 +951,24 @@ class Resizable extends Uii {
|
|
|
1149
951
|
maxWidth = opts.maxSize;
|
|
1150
952
|
maxHeight = opts.maxSize;
|
|
1151
953
|
}
|
|
1152
|
-
//ghost
|
|
1153
954
|
const ghost = opts.ghost;
|
|
1154
955
|
const ghostClass = opts.ghostClass;
|
|
1155
956
|
let ghostNode = null;
|
|
1156
|
-
//aspectRatio
|
|
1157
957
|
const aspectRatio = opts.aspectRatio;
|
|
1158
958
|
const panelStyle = panel.style;
|
|
1159
959
|
let style = panelStyle;
|
|
1160
960
|
let currentW = originW;
|
|
1161
961
|
let currentH = originH;
|
|
1162
|
-
let
|
|
962
|
+
let transform;
|
|
1163
963
|
let lastX = 0, lastY = 0;
|
|
1164
964
|
let originalTransformOrigin = "";
|
|
1165
965
|
let vertexBeforeTransform;
|
|
1166
966
|
let currentVertex;
|
|
1167
967
|
let refPoint;
|
|
1168
|
-
//slope
|
|
1169
968
|
let k1;
|
|
1170
969
|
let startOx = 0;
|
|
1171
970
|
let startOy = 0;
|
|
1172
971
|
let sX = 0, sY = 0;
|
|
1173
|
-
//bind events
|
|
1174
972
|
onPointerStart(function (args) {
|
|
1175
973
|
var _a;
|
|
1176
974
|
const { ev } = args;
|
|
@@ -1192,20 +990,20 @@ class Resizable extends Uii {
|
|
|
1192
990
|
ghostClass;
|
|
1193
991
|
}
|
|
1194
992
|
(_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
|
|
1195
|
-
|
|
993
|
+
transform = wrapper(ghostNode);
|
|
1196
994
|
onClone && onClone({ clone: ghostNode }, ev);
|
|
1197
995
|
}
|
|
1198
996
|
style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
|
|
1199
997
|
}
|
|
1200
998
|
else {
|
|
1201
|
-
|
|
999
|
+
transform = wrapper(panel);
|
|
1202
1000
|
}
|
|
1203
1001
|
const cStyle = window.getComputedStyle(panel);
|
|
1204
1002
|
const w = parseFloat(cStyle.width);
|
|
1205
1003
|
const h = parseFloat(cStyle.height);
|
|
1206
|
-
const
|
|
1207
|
-
startOx = originX;
|
|
1208
|
-
startOy = originY;
|
|
1004
|
+
const oxy = parseOxy(opts.ox, opts.oy, w, h);
|
|
1005
|
+
startOx = oxy.originX;
|
|
1006
|
+
startOy = oxy.originY;
|
|
1209
1007
|
const { x, y, sx, sy } = panel instanceof SVGGraphicsElement
|
|
1210
1008
|
? getCenterXySVG(panel, startOx, startOy)
|
|
1211
1009
|
: getCenterXy(panel);
|
|
@@ -1214,7 +1012,6 @@ class Resizable extends Uii {
|
|
|
1214
1012
|
currentVertex =
|
|
1215
1013
|
vertexBeforeTransform =
|
|
1216
1014
|
calcVertex(originW, originH, centerX, centerY, sx, sy, deg);
|
|
1217
|
-
//计算参考点及斜率
|
|
1218
1015
|
switch (dir) {
|
|
1219
1016
|
case "s":
|
|
1220
1017
|
case "e":
|
|
@@ -1233,11 +1030,9 @@ class Resizable extends Uii {
|
|
|
1233
1030
|
refPoint = currentVertex[2];
|
|
1234
1031
|
break;
|
|
1235
1032
|
}
|
|
1236
|
-
//水平斜率
|
|
1237
1033
|
k1 =
|
|
1238
1034
|
(currentVertex[1].y - refPoint.y) /
|
|
1239
|
-
(currentVertex[1].x - refPoint.x);
|
|
1240
|
-
//change trans origin
|
|
1035
|
+
(currentVertex[1].x - refPoint.x);
|
|
1241
1036
|
style.transition = "none";
|
|
1242
1037
|
originalTransformOrigin = style.transformOrigin;
|
|
1243
1038
|
if (setOrigin) {
|
|
@@ -1245,29 +1040,24 @@ class Resizable extends Uii {
|
|
|
1245
1040
|
style.transformOrigin = toTransformOrigin;
|
|
1246
1041
|
}
|
|
1247
1042
|
else {
|
|
1248
|
-
style.transformOrigin = `${centerX -
|
|
1043
|
+
style.transformOrigin = `${centerX - transform.x}px ${centerY - transform.y}px`;
|
|
1249
1044
|
}
|
|
1250
1045
|
}
|
|
1251
1046
|
if (panel instanceof SVGGraphicsElement) {
|
|
1252
1047
|
sX = matrixInfo.x - currentVertex[0].x;
|
|
1253
1048
|
sY = matrixInfo.y - currentVertex[0].y;
|
|
1254
1049
|
}
|
|
1255
|
-
onStart && onStart.call(uiik, { w: originW, h: originH }, ev);
|
|
1050
|
+
onStart && onStart.call(uiik, { w: originW, h: originH, transform }, ev);
|
|
1256
1051
|
});
|
|
1257
1052
|
onPointerMove((args) => {
|
|
1258
1053
|
const { ev } = args;
|
|
1259
|
-
//获取当前位置坐标
|
|
1260
1054
|
const currentXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle);
|
|
1261
1055
|
let newX = currentXy.x;
|
|
1262
1056
|
let newY = currentXy.y;
|
|
1263
|
-
////////////////////////////////////////// 计算边长
|
|
1264
|
-
//1. calc angle
|
|
1265
1057
|
let angle = Math.atan2(newY - refPoint.y, newX - refPoint.x) * ONE_RAD -
|
|
1266
1058
|
matrixInfo.angle;
|
|
1267
|
-
//2. hypotenuse length
|
|
1268
1059
|
let hyLen = Math.sqrt((newX - refPoint.x) * (newX - refPoint.x) +
|
|
1269
1060
|
(newY - refPoint.y) * (newY - refPoint.y));
|
|
1270
|
-
//3. h&v projection length
|
|
1271
1061
|
let pl1 = Math.abs(k1 === Infinity
|
|
1272
1062
|
? newY - refPoint.y
|
|
1273
1063
|
: hyLen * Math.cos(angle * ONE_ANG));
|
|
@@ -1293,7 +1083,6 @@ class Resizable extends Uii {
|
|
|
1293
1083
|
angl =
|
|
1294
1084
|
Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
|
|
1295
1085
|
let plh;
|
|
1296
|
-
//1&2 quad
|
|
1297
1086
|
if (angl === 90) {
|
|
1298
1087
|
h = newY - currentVertex[2].y;
|
|
1299
1088
|
x = currentVertex[2].x;
|
|
@@ -1315,7 +1104,6 @@ class Resizable extends Uii {
|
|
|
1315
1104
|
angl =
|
|
1316
1105
|
Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
|
|
1317
1106
|
let plw;
|
|
1318
|
-
//1&4 quad
|
|
1319
1107
|
if (angl === 0) {
|
|
1320
1108
|
w = newX - currentVertex[1].x;
|
|
1321
1109
|
x = newX;
|
|
@@ -1335,7 +1123,6 @@ class Resizable extends Uii {
|
|
|
1335
1123
|
case "nw":
|
|
1336
1124
|
w = pl1;
|
|
1337
1125
|
h = pl2;
|
|
1338
|
-
//获取顺时针旋转后的直角坐标
|
|
1339
1126
|
x = newX;
|
|
1340
1127
|
y = newY;
|
|
1341
1128
|
if (matrixInfo.angle === 180) {
|
|
@@ -1349,7 +1136,6 @@ class Resizable extends Uii {
|
|
|
1349
1136
|
angl =
|
|
1350
1137
|
Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
|
|
1351
1138
|
let plw1;
|
|
1352
|
-
//1&4 quad
|
|
1353
1139
|
if (angl === 0) {
|
|
1354
1140
|
x = newX;
|
|
1355
1141
|
y = currentVertex[0].y;
|
|
@@ -1376,7 +1162,6 @@ class Resizable extends Uii {
|
|
|
1376
1162
|
y = currentVertex[0].y;
|
|
1377
1163
|
}
|
|
1378
1164
|
else if (currentVertex[1].x > currentVertex[0].x) {
|
|
1379
|
-
//1&2 quad
|
|
1380
1165
|
plne = h * Math.cos((180 - angl) * ONE_ANG);
|
|
1381
1166
|
x = currentVertex[2].x - plne;
|
|
1382
1167
|
y = currentVertex[2].y - Math.sqrt(h * h - plne * plne);
|
|
@@ -1389,6 +1174,7 @@ class Resizable extends Uii {
|
|
|
1389
1174
|
break;
|
|
1390
1175
|
}
|
|
1391
1176
|
if (changeW) {
|
|
1177
|
+
console.log(minWidth, 'xxxxxx', w);
|
|
1392
1178
|
if (minWidth && w < minWidth)
|
|
1393
1179
|
w = minWidth;
|
|
1394
1180
|
if (maxWidth && w > maxWidth)
|
|
@@ -1417,17 +1203,17 @@ class Resizable extends Uii {
|
|
|
1417
1203
|
}
|
|
1418
1204
|
else {
|
|
1419
1205
|
if (changeW) {
|
|
1420
|
-
resize(
|
|
1206
|
+
resize(transform, style, w);
|
|
1421
1207
|
}
|
|
1422
1208
|
if (changeH) {
|
|
1423
|
-
resize(
|
|
1209
|
+
resize(transform, style, undefined, h);
|
|
1424
1210
|
}
|
|
1425
1211
|
}
|
|
1426
1212
|
if (changeY) {
|
|
1427
|
-
|
|
1213
|
+
transform.moveToY(y + sY);
|
|
1428
1214
|
}
|
|
1429
1215
|
if (changeX) {
|
|
1430
|
-
|
|
1216
|
+
transform.moveToX(x + sX);
|
|
1431
1217
|
}
|
|
1432
1218
|
lastX = x;
|
|
1433
1219
|
lastY = y;
|
|
@@ -1448,6 +1234,7 @@ class Resizable extends Uii {
|
|
|
1448
1234
|
sx: sx,
|
|
1449
1235
|
sy: sy,
|
|
1450
1236
|
deg: matrixInfo.angle,
|
|
1237
|
+
transform
|
|
1451
1238
|
}, ev);
|
|
1452
1239
|
}
|
|
1453
1240
|
});
|
|
@@ -1460,9 +1247,7 @@ class Resizable extends Uii {
|
|
|
1460
1247
|
panelStyle.left = ghostNode.style.left;
|
|
1461
1248
|
panelStyle.top = ghostNode.style.top;
|
|
1462
1249
|
moveTo(panel, lastX / matrixInfo.scale, lastY / matrixInfo.scale);
|
|
1463
|
-
resize(
|
|
1464
|
-
// panelStyle.width = ghostNode.style.width;
|
|
1465
|
-
// panelStyle.height = ghostNode.style.height;
|
|
1250
|
+
resize(transform, panelStyle, parseFloat(ghostNode.style.width), parseFloat(ghostNode.style.height));
|
|
1466
1251
|
}
|
|
1467
1252
|
panel.style.transformOrigin = originalTransformOrigin;
|
|
1468
1253
|
const { x, y, sx, sy, ox, oy } = panel instanceof SVGGraphicsElement
|
|
@@ -1471,30 +1256,27 @@ class Resizable extends Uii {
|
|
|
1471
1256
|
let centerX = x, centerY = y;
|
|
1472
1257
|
const deg = matrixInfo.angle * ONE_ANG;
|
|
1473
1258
|
const currentVertex = calcVertex(currentW, currentH, centerX, centerY, sx, sy, deg);
|
|
1474
|
-
//修正偏移
|
|
1475
1259
|
if (panel instanceof SVGGraphicsElement) {
|
|
1476
|
-
//更新rotate圆心
|
|
1477
1260
|
if (matrixInfo.angle != 0) {
|
|
1478
|
-
const
|
|
1479
|
-
rotateTo(
|
|
1480
|
-
let { x, y, sx, sy } = getCenterXySVG(panel, originX, originY);
|
|
1261
|
+
const oxy = parseOxy(opts.ox, opts.oy, currentW, currentH);
|
|
1262
|
+
rotateTo(transform.el, matrixInfo.angle, oxy.originX, originY);
|
|
1263
|
+
let { x, y, sx, sy } = getCenterXySVG(panel, oxy.originX, originY);
|
|
1481
1264
|
let currentVertex2 = calcVertex(currentW, currentH, x, y, sx, sy, deg);
|
|
1482
|
-
|
|
1483
|
-
transformer.moveTo(transformer.x - (currentVertex2[0].x - currentVertex[0].x), transformer.y - (currentVertex2[0].y - currentVertex[0].y));
|
|
1265
|
+
transform.moveTo(transform.x - (currentVertex2[0].x - currentVertex[0].x), transform.y - (currentVertex2[0].y - currentVertex[0].y));
|
|
1484
1266
|
}
|
|
1485
1267
|
}
|
|
1486
1268
|
else {
|
|
1487
1269
|
if (changeX || changeY) {
|
|
1488
|
-
|
|
1270
|
+
transform.moveTo(transform.x - (currentVertex[0].x - lastX), transform.y - (currentVertex[0].y - lastY));
|
|
1489
1271
|
}
|
|
1490
1272
|
else {
|
|
1491
|
-
|
|
1492
|
-
(currentVertex[0].x - vertexBeforeTransform[0].x),
|
|
1273
|
+
transform.moveTo(transform.x -
|
|
1274
|
+
(currentVertex[0].x - vertexBeforeTransform[0].x), transform.y -
|
|
1493
1275
|
(currentVertex[0].y - vertexBeforeTransform[0].y));
|
|
1494
1276
|
}
|
|
1495
1277
|
}
|
|
1496
1278
|
handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
|
|
1497
|
-
onEnd && onEnd.call(uiik, { w: currentW, h: currentH }, ev);
|
|
1279
|
+
onEnd && onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
|
|
1498
1280
|
});
|
|
1499
1281
|
}, {
|
|
1500
1282
|
threshold: THRESHOLD$3,
|
|
@@ -1517,7 +1299,6 @@ class Resizable extends Uii {
|
|
|
1517
1299
|
}
|
|
1518
1300
|
handles = isArrayLike(handles) ? handles : [handles];
|
|
1519
1301
|
each(handles, (h) => {
|
|
1520
|
-
//get dir from handle
|
|
1521
1302
|
const className = h.getAttribute("class") || "";
|
|
1522
1303
|
const matchRs = className.match(EXP_DIR);
|
|
1523
1304
|
let dir = "se";
|
|
@@ -1532,13 +1313,12 @@ class Resizable extends Uii {
|
|
|
1532
1313
|
});
|
|
1533
1314
|
}
|
|
1534
1315
|
}
|
|
1535
|
-
function resize(
|
|
1536
|
-
|
|
1537
|
-
if (transformer.el instanceof SVGGraphicsElement) {
|
|
1316
|
+
function resize(transform, style, w, h) {
|
|
1317
|
+
if (transform.el instanceof SVGGraphicsElement) {
|
|
1538
1318
|
if (isDefined(w))
|
|
1539
|
-
|
|
1319
|
+
transform.el.setAttribute("width", w + "");
|
|
1540
1320
|
if (isDefined(h))
|
|
1541
|
-
|
|
1321
|
+
transform.el.setAttribute("height", h + "");
|
|
1542
1322
|
}
|
|
1543
1323
|
else {
|
|
1544
1324
|
if (isDefined(w))
|
|
@@ -1547,12 +1327,6 @@ function resize(transformer, style, w, h) {
|
|
|
1547
1327
|
style.height = h + "px";
|
|
1548
1328
|
}
|
|
1549
1329
|
}
|
|
1550
|
-
/**
|
|
1551
|
-
* Make els resizable
|
|
1552
|
-
* @param els selector string / html element
|
|
1553
|
-
* @param opts
|
|
1554
|
-
* @returns
|
|
1555
|
-
*/
|
|
1556
1330
|
function newResizable(els, opts) {
|
|
1557
1331
|
return new Resizable(els, opts);
|
|
1558
1332
|
}
|
|
@@ -1563,17 +1337,6 @@ const CLASS_DRAGGABLE = "uii-draggable";
|
|
|
1563
1337
|
const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
|
|
1564
1338
|
const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
|
|
1565
1339
|
const CLASS_DRAGGABLE_GHOST = "uii-draggable-ghost";
|
|
1566
|
-
/**
|
|
1567
|
-
* 用于表示一个或多个可拖动元素的定义
|
|
1568
|
-
* 每个拖动元素可以有独立handle,也可以公用一个handle
|
|
1569
|
-
* 可拖动元素拖动时自动剔除left/top/x/y/cx/cy属性,而使用transform:translate替代
|
|
1570
|
-
* > 可用CSS接口
|
|
1571
|
-
* - .uii-draggable
|
|
1572
|
-
* - .uii-draggable-handle
|
|
1573
|
-
* - .uii-draggable-active
|
|
1574
|
-
* - .uii-draggable-ghost
|
|
1575
|
-
* @public
|
|
1576
|
-
*/
|
|
1577
1340
|
class Draggable extends Uii {
|
|
1578
1341
|
constructor(els, opts) {
|
|
1579
1342
|
super(els, assign({
|
|
@@ -1601,7 +1364,6 @@ class Draggable extends Uii {
|
|
|
1601
1364
|
});
|
|
1602
1365
|
}
|
|
1603
1366
|
this.onOptionChanged(this.opts);
|
|
1604
|
-
//put into group
|
|
1605
1367
|
if (this.opts.group) {
|
|
1606
1368
|
if (!DRAGGER_GROUPS[this.opts.group]) {
|
|
1607
1369
|
DRAGGER_GROUPS[this.opts.group] = [];
|
|
@@ -1609,7 +1371,6 @@ class Draggable extends Uii {
|
|
|
1609
1371
|
DRAGGER_GROUPS[this.opts.group].push(...this.ele);
|
|
1610
1372
|
}
|
|
1611
1373
|
__classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initStyle).call(this, this.ele);
|
|
1612
|
-
//containment
|
|
1613
1374
|
if (this.opts.containment) {
|
|
1614
1375
|
if (isBoolean(this.opts.containment)) {
|
|
1615
1376
|
__classPrivateFieldSet(this, _Draggable_container, isEmpty(this.ele) ? null : this.ele[0].parentElement, "f");
|
|
@@ -1647,12 +1408,10 @@ class Draggable extends Uii {
|
|
|
1647
1408
|
let t = ev.target;
|
|
1648
1409
|
if (!t)
|
|
1649
1410
|
return true;
|
|
1650
|
-
//refresh draggableList
|
|
1651
1411
|
if (opts.watch && eleString) {
|
|
1652
1412
|
draggableList = bindTarget.querySelectorAll(eleString);
|
|
1653
1413
|
initStyle(draggableList);
|
|
1654
1414
|
}
|
|
1655
|
-
//find drag dom & handle
|
|
1656
1415
|
let findRs = find(draggableList, el => el.contains(t));
|
|
1657
1416
|
if (!findRs)
|
|
1658
1417
|
return true;
|
|
@@ -1661,17 +1420,14 @@ class Draggable extends Uii {
|
|
|
1661
1420
|
if (handle && !handle.contains(t)) {
|
|
1662
1421
|
return true;
|
|
1663
1422
|
}
|
|
1664
|
-
//检测
|
|
1665
1423
|
const onPointerDown = opts.onPointerDown;
|
|
1666
1424
|
if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
|
|
1667
1425
|
return true;
|
|
1668
1426
|
const filter = opts.filter;
|
|
1669
|
-
//check filter
|
|
1670
1427
|
if (filter) {
|
|
1671
1428
|
if (some(dragDom.querySelectorAll(filter), ele => ele.contains(t)))
|
|
1672
1429
|
return true;
|
|
1673
1430
|
}
|
|
1674
|
-
//用于计算鼠标移动时当前位置
|
|
1675
1431
|
const offsetParent = dragDom instanceof HTMLElement ? dragDom.offsetParent || document.body : dragDom.ownerSVGElement;
|
|
1676
1432
|
const offsetParentRect = offsetParent.getBoundingClientRect();
|
|
1677
1433
|
const offsetParentCStyle = window.getComputedStyle(offsetParent);
|
|
@@ -1680,6 +1436,9 @@ class Draggable extends Uii {
|
|
|
1680
1436
|
let offsetPointY = offsetXy.y;
|
|
1681
1437
|
const matrixInfo = getMatrixInfo(dragDom);
|
|
1682
1438
|
const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
|
|
1439
|
+
const matrixInfoParent = getMatrixInfo(offsetParent);
|
|
1440
|
+
offsetPointX = offsetPointX / (matrixInfo.scale * matrixInfoParent.scale);
|
|
1441
|
+
offsetPointY = offsetPointY / (matrixInfo.scale * matrixInfoParent.scale);
|
|
1683
1442
|
if (matrixInfo.angle != 0) {
|
|
1684
1443
|
offsetPointX = currentXy.x - matrixInfo.x;
|
|
1685
1444
|
offsetPointY = currentXy.y - matrixInfo.y;
|
|
@@ -1723,9 +1482,7 @@ class Draggable extends Uii {
|
|
|
1723
1482
|
let lastSnapDirY = "", lastSnapDirX = "";
|
|
1724
1483
|
let lastSnapping = "";
|
|
1725
1484
|
if (snapOn) {
|
|
1726
|
-
//获取拖动元素所在容器内的可吸附对象
|
|
1727
1485
|
snappable = map((container || document).querySelectorAll(snapOn), (el) => {
|
|
1728
|
-
//计算相对容器xy
|
|
1729
1486
|
const { x, y, w, h } = getRectInContainer(el, offsetParent);
|
|
1730
1487
|
return {
|
|
1731
1488
|
x1: x,
|
|
@@ -1739,7 +1496,6 @@ class Draggable extends Uii {
|
|
|
1739
1496
|
const dragDomRect = dragDom.getBoundingClientRect();
|
|
1740
1497
|
const originW = dragDomRect.width + parseFloat(currentCStyle.borderLeftWidth) + parseFloat(currentCStyle.borderRightWidth);
|
|
1741
1498
|
const originH = dragDomRect.height + parseFloat(currentCStyle.borderTopWidth) + parseFloat(currentCStyle.borderBottomWidth);
|
|
1742
|
-
// boundary
|
|
1743
1499
|
let minX = 0;
|
|
1744
1500
|
let minY = 0;
|
|
1745
1501
|
let maxX = 0;
|
|
@@ -1755,14 +1511,13 @@ class Draggable extends Uii {
|
|
|
1755
1511
|
if (maxY < 0)
|
|
1756
1512
|
maxY = 0;
|
|
1757
1513
|
let copyNode;
|
|
1758
|
-
let
|
|
1514
|
+
let transform;
|
|
1759
1515
|
let timer = null;
|
|
1760
1516
|
let toLeft = false;
|
|
1761
1517
|
let toTop = false;
|
|
1762
1518
|
let toRight = false;
|
|
1763
1519
|
let toBottom = false;
|
|
1764
1520
|
let endX = 0, endY = 0;
|
|
1765
|
-
//bind events
|
|
1766
1521
|
onPointerStart(function (args) {
|
|
1767
1522
|
var _a;
|
|
1768
1523
|
const { ev } = args;
|
|
@@ -1783,19 +1538,17 @@ class Draggable extends Uii {
|
|
|
1783
1538
|
copyNode.classList.add(...compact(split(classes, ' ')));
|
|
1784
1539
|
copyNode.classList.toggle(CLASS_DRAGGABLE_GHOST, true);
|
|
1785
1540
|
(_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(copyNode);
|
|
1786
|
-
|
|
1541
|
+
transform = wrapper(copyNode);
|
|
1787
1542
|
onClone && onClone({ clone: copyNode }, ev);
|
|
1788
1543
|
}
|
|
1789
1544
|
else {
|
|
1790
|
-
|
|
1545
|
+
transform = wrapper(dragDom);
|
|
1791
1546
|
}
|
|
1792
|
-
//apply classes
|
|
1793
1547
|
dragDom.classList.add(...compact(split(classes, ' ')));
|
|
1794
1548
|
if (!copyNode)
|
|
1795
1549
|
dragDom.style.zIndex = zIndex + '';
|
|
1796
1550
|
dragDom.classList.toggle(CLASS_DRAGGABLE_ACTIVE, true);
|
|
1797
|
-
onStart && onStart({ draggable: dragDom, x: currentXy.x, y: currentXy.y }, ev);
|
|
1798
|
-
//notify
|
|
1551
|
+
onStart && onStart({ draggable: dragDom, x: currentXy.x, y: currentXy.y, transform }, ev);
|
|
1799
1552
|
const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
|
|
1800
1553
|
dragDom.dispatchEvent(customEv);
|
|
1801
1554
|
});
|
|
@@ -1804,7 +1557,6 @@ class Draggable extends Uii {
|
|
|
1804
1557
|
const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
|
|
1805
1558
|
let newX = currentXy.x;
|
|
1806
1559
|
let newY = currentXy.y;
|
|
1807
|
-
//edge detect
|
|
1808
1560
|
if (scroll) {
|
|
1809
1561
|
const lX = pointX - offsetParentRect.x;
|
|
1810
1562
|
const lY = pointY - offsetParentRect.y;
|
|
@@ -1843,7 +1595,6 @@ class Draggable extends Uii {
|
|
|
1843
1595
|
}
|
|
1844
1596
|
let x = newX - offsetPointX;
|
|
1845
1597
|
let y = newY - offsetPointY;
|
|
1846
|
-
//grid
|
|
1847
1598
|
if (isNumber(gridX) && isNumber(gridY)) {
|
|
1848
1599
|
x = ((x / gridX) >> 0) * gridX;
|
|
1849
1600
|
y = ((y / gridY) >> 0) * gridY;
|
|
@@ -1869,29 +1620,24 @@ class Draggable extends Uii {
|
|
|
1869
1620
|
const currPageY1 = y;
|
|
1870
1621
|
const currPageX2 = currPageX1 + originW;
|
|
1871
1622
|
const currPageY2 = currPageY1 + originH;
|
|
1872
|
-
//check snappable
|
|
1873
1623
|
let snapX = NaN, snapY = NaN;
|
|
1874
1624
|
let targetX, targetY;
|
|
1875
1625
|
let snapDirX, snapDirY;
|
|
1876
1626
|
if (!direction || direction === "v") {
|
|
1877
1627
|
each(snappable, (data) => {
|
|
1878
1628
|
if (Math.abs(data.y1 - currPageY1) <= snapTolerance) {
|
|
1879
|
-
//top parallel
|
|
1880
1629
|
snapY = data.y1;
|
|
1881
1630
|
snapDirY = "t2t";
|
|
1882
1631
|
}
|
|
1883
1632
|
else if (Math.abs(data.y2 - currPageY1) <= snapTolerance) {
|
|
1884
|
-
//b2t
|
|
1885
1633
|
snapY = data.y2;
|
|
1886
1634
|
snapDirY = "t2b";
|
|
1887
1635
|
}
|
|
1888
1636
|
else if (Math.abs(data.y1 - currPageY2) <= snapTolerance) {
|
|
1889
|
-
//t2b
|
|
1890
1637
|
snapY = data.y1 - originH;
|
|
1891
1638
|
snapDirY = "b2t";
|
|
1892
1639
|
}
|
|
1893
1640
|
else if (Math.abs(data.y2 - currPageY2) <= snapTolerance) {
|
|
1894
|
-
//bottom parallel
|
|
1895
1641
|
snapY = data.y2 - originH;
|
|
1896
1642
|
snapDirY = "b2b";
|
|
1897
1643
|
}
|
|
@@ -1905,22 +1651,18 @@ class Draggable extends Uii {
|
|
|
1905
1651
|
if (!direction || direction === "h") {
|
|
1906
1652
|
each(snappable, (data) => {
|
|
1907
1653
|
if (Math.abs(data.x1 - currPageX1) <= snapTolerance) {
|
|
1908
|
-
//left parallel
|
|
1909
1654
|
snapX = data.x1;
|
|
1910
1655
|
snapDirX = "l2l";
|
|
1911
1656
|
}
|
|
1912
1657
|
else if (Math.abs(data.x2 - currPageX1) <= snapTolerance) {
|
|
1913
|
-
//r2l
|
|
1914
1658
|
snapX = data.x2;
|
|
1915
1659
|
snapDirX = "l2r";
|
|
1916
1660
|
}
|
|
1917
1661
|
else if (Math.abs(data.x1 - currPageX2) <= snapTolerance) {
|
|
1918
|
-
//l2r
|
|
1919
1662
|
snapX = data.x1 - originW;
|
|
1920
1663
|
snapDirX = "r2l";
|
|
1921
1664
|
}
|
|
1922
1665
|
else if (Math.abs(data.x2 - currPageX2) <= snapTolerance) {
|
|
1923
|
-
//right parallel
|
|
1924
1666
|
snapX = data.x2 - originW;
|
|
1925
1667
|
snapDirX = "r2r";
|
|
1926
1668
|
}
|
|
@@ -1940,7 +1682,6 @@ class Draggable extends Uii {
|
|
|
1940
1682
|
}
|
|
1941
1683
|
if (onSnap && lastSnapping !== lastSnapDirX + "" + lastSnapDirY) {
|
|
1942
1684
|
setTimeout(() => {
|
|
1943
|
-
//emit after relocate
|
|
1944
1685
|
onSnap({
|
|
1945
1686
|
el: copyNode || dragDom,
|
|
1946
1687
|
targetH: targetX,
|
|
@@ -1963,7 +1704,8 @@ class Draggable extends Uii {
|
|
|
1963
1704
|
ox: offX,
|
|
1964
1705
|
oy: offY,
|
|
1965
1706
|
x: x,
|
|
1966
|
-
y: y
|
|
1707
|
+
y: y,
|
|
1708
|
+
transform
|
|
1967
1709
|
}, ev) === false) {
|
|
1968
1710
|
canDrag = false;
|
|
1969
1711
|
endX = x;
|
|
@@ -1972,13 +1714,13 @@ class Draggable extends Uii {
|
|
|
1972
1714
|
}
|
|
1973
1715
|
if (canDrag) {
|
|
1974
1716
|
if (direction === "v") {
|
|
1975
|
-
|
|
1717
|
+
transform.moveToY(y);
|
|
1976
1718
|
}
|
|
1977
1719
|
else if (direction === "h") {
|
|
1978
|
-
|
|
1720
|
+
transform.moveToX(x);
|
|
1979
1721
|
}
|
|
1980
1722
|
else {
|
|
1981
|
-
|
|
1723
|
+
transform.moveTo(x, y);
|
|
1982
1724
|
}
|
|
1983
1725
|
endX = x;
|
|
1984
1726
|
endY = y;
|
|
@@ -1993,21 +1735,19 @@ class Draggable extends Uii {
|
|
|
1993
1735
|
timer = null;
|
|
1994
1736
|
}
|
|
1995
1737
|
}
|
|
1996
|
-
//restore classes
|
|
1997
1738
|
dragDom.classList.remove(...compact(split(classes, ' ')));
|
|
1998
1739
|
currentStyle.zIndex = originalZIndex;
|
|
1999
1740
|
dragDom.classList.remove(CLASS_DRAGGABLE_ACTIVE);
|
|
2000
1741
|
let moveToGhost = true;
|
|
2001
1742
|
if (onEnd) {
|
|
2002
|
-
moveToGhost = onEnd({ draggable: dragDom, x: endX, y: endY }, ev) === false ? false : true;
|
|
1743
|
+
moveToGhost = onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) === false ? false : true;
|
|
2003
1744
|
}
|
|
2004
|
-
//notify
|
|
2005
1745
|
const customEv = new Event("uii-dragdeactive", { "bubbles": true, "cancelable": false });
|
|
2006
1746
|
dragDom.dispatchEvent(customEv);
|
|
2007
1747
|
if (ghost) {
|
|
2008
1748
|
((_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.contains(copyNode)) && ((_b = dragDom.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(copyNode));
|
|
2009
1749
|
if (moveToGhost !== false) {
|
|
2010
|
-
wrapper(dragDom).moveTo(
|
|
1750
|
+
wrapper(dragDom).moveTo(transform.x, transform.y);
|
|
2011
1751
|
}
|
|
2012
1752
|
}
|
|
2013
1753
|
});
|
|
@@ -2016,9 +1756,6 @@ class Draggable extends Uii {
|
|
|
2016
1756
|
lockPage: true
|
|
2017
1757
|
});
|
|
2018
1758
|
}
|
|
2019
|
-
/**
|
|
2020
|
-
* @internal
|
|
2021
|
-
*/
|
|
2022
1759
|
onOptionChanged(opts) {
|
|
2023
1760
|
const droppable = opts.droppable;
|
|
2024
1761
|
if (!isFunction(droppable)) {
|
|
@@ -2053,12 +1790,6 @@ _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Dra
|
|
|
2053
1790
|
}
|
|
2054
1791
|
});
|
|
2055
1792
|
};
|
|
2056
|
-
/**
|
|
2057
|
-
* create a draggable pattern for one or more elements with opts
|
|
2058
|
-
* @param els selector string / html element
|
|
2059
|
-
* @param opts
|
|
2060
|
-
* @returns Draggable instance
|
|
2061
|
-
*/
|
|
2062
1793
|
function newDraggable(els, opts) {
|
|
2063
1794
|
return new Draggable(els, opts);
|
|
2064
1795
|
}
|
|
@@ -2066,23 +1797,13 @@ function newDraggable(els, opts) {
|
|
|
2066
1797
|
var _Droppable_active;
|
|
2067
1798
|
const Droppables = [];
|
|
2068
1799
|
const CLASS_DROPPABLE = "uii-droppable";
|
|
2069
|
-
/**
|
|
2070
|
-
* 用于表示一个或多个可响应拖动元素的定义
|
|
2071
|
-
* > 可用CSS接口
|
|
2072
|
-
* - .uii-droppable
|
|
2073
|
-
* @public
|
|
2074
|
-
*/
|
|
2075
1800
|
class Droppable extends Uii {
|
|
2076
1801
|
constructor(el, opts) {
|
|
2077
1802
|
super(el, assign({}, opts));
|
|
2078
1803
|
_Droppable_active.set(this, void 0);
|
|
2079
1804
|
Droppables.push(this);
|
|
2080
1805
|
}
|
|
2081
|
-
/**
|
|
2082
|
-
* @internal
|
|
2083
|
-
*/
|
|
2084
1806
|
bindEvent(droppable, opts) {
|
|
2085
|
-
//dragenter
|
|
2086
1807
|
this.registerEvent(droppable, "mouseenter", (e) => {
|
|
2087
1808
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
2088
1809
|
return;
|
|
@@ -2096,7 +1817,6 @@ class Droppable extends Uii {
|
|
|
2096
1817
|
}
|
|
2097
1818
|
opts.onEnter && opts.onEnter({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
|
|
2098
1819
|
});
|
|
2099
|
-
//dragleave
|
|
2100
1820
|
this.registerEvent(droppable, "mouseleave", (e) => {
|
|
2101
1821
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
2102
1822
|
return;
|
|
@@ -2110,13 +1830,11 @@ class Droppable extends Uii {
|
|
|
2110
1830
|
}
|
|
2111
1831
|
opts.onLeave && opts.onLeave({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
|
|
2112
1832
|
});
|
|
2113
|
-
//dragover
|
|
2114
1833
|
this.registerEvent(droppable, "mousemove", (e) => {
|
|
2115
1834
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
2116
1835
|
return;
|
|
2117
1836
|
opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
|
|
2118
1837
|
});
|
|
2119
|
-
//drop
|
|
2120
1838
|
this.registerEvent(droppable, "mouseup", (e) => {
|
|
2121
1839
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
2122
1840
|
return;
|
|
@@ -2128,13 +1846,9 @@ class Droppable extends Uii {
|
|
|
2128
1846
|
opts.onDrop && opts.onDrop({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
|
|
2129
1847
|
});
|
|
2130
1848
|
}
|
|
2131
|
-
/**
|
|
2132
|
-
* @internal
|
|
2133
|
-
*/
|
|
2134
1849
|
active(target) {
|
|
2135
1850
|
let valid = true;
|
|
2136
1851
|
const opts = this.opts;
|
|
2137
|
-
//check accepts
|
|
2138
1852
|
if (isString(opts.accepts)) {
|
|
2139
1853
|
valid = !!target.dataset.dropType && test(opts.accepts, target.dataset.dropType);
|
|
2140
1854
|
}
|
|
@@ -2152,16 +1866,12 @@ class Droppable extends Uii {
|
|
|
2152
1866
|
});
|
|
2153
1867
|
}
|
|
2154
1868
|
opts.onActive && opts.onActive({ draggable: target, droppables: this.ele });
|
|
2155
|
-
//bind events
|
|
2156
1869
|
each(this.ele, (el) => {
|
|
2157
1870
|
el.classList.toggle(CLASS_DROPPABLE, true);
|
|
2158
1871
|
el.style.pointerEvents = 'initial';
|
|
2159
1872
|
this.bindEvent(el, opts);
|
|
2160
1873
|
});
|
|
2161
1874
|
}
|
|
2162
|
-
/**
|
|
2163
|
-
* @internal
|
|
2164
|
-
*/
|
|
2165
1875
|
deactive(target) {
|
|
2166
1876
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
2167
1877
|
return;
|
|
@@ -2175,12 +1885,10 @@ class Droppable extends Uii {
|
|
|
2175
1885
|
});
|
|
2176
1886
|
}
|
|
2177
1887
|
opts.onDeactive && opts.onDeactive({ draggable: target, droppables: this.ele });
|
|
2178
|
-
//unbind events
|
|
2179
1888
|
this.destroy();
|
|
2180
1889
|
}
|
|
2181
1890
|
}
|
|
2182
1891
|
_Droppable_active = new WeakMap();
|
|
2183
|
-
//uii-drag active
|
|
2184
1892
|
document.addEventListener("uii-dragactive", (e) => {
|
|
2185
1893
|
each(Droppables, dpb => {
|
|
2186
1894
|
dpb.active(e.target);
|
|
@@ -2191,29 +1899,14 @@ document.addEventListener("uii-dragdeactive", (e) => {
|
|
|
2191
1899
|
dpb.deactive(e.target);
|
|
2192
1900
|
});
|
|
2193
1901
|
});
|
|
2194
|
-
/**
|
|
2195
|
-
* Enable els to response to draggable objects
|
|
2196
|
-
* @param els selector string / html element
|
|
2197
|
-
* @param opts
|
|
2198
|
-
* @returns
|
|
2199
|
-
*/
|
|
2200
1902
|
function newDroppable(els, opts) {
|
|
2201
1903
|
return new Droppable(els, opts);
|
|
2202
1904
|
}
|
|
2203
1905
|
|
|
2204
|
-
/* eslint-disable max-len */
|
|
2205
1906
|
const THRESHOLD$2 = 2;
|
|
2206
1907
|
const CLASS_ROTATABLE = "uii-rotatable";
|
|
2207
1908
|
const CLASS_ROTATABLE_HANDLE = "uii-rotatable-handle";
|
|
2208
1909
|
const CLASS_ROTATABLE_ACTIVE = "uii-rotatable-active";
|
|
2209
|
-
/**
|
|
2210
|
-
* 用于表示一个或多个可旋转元素的定义
|
|
2211
|
-
* > 可用CSS接口
|
|
2212
|
-
* - .uii-rotatable
|
|
2213
|
-
* - .uii-rotatable-handle
|
|
2214
|
-
* - .uii-rotatable-active
|
|
2215
|
-
* @public
|
|
2216
|
-
*/
|
|
2217
1910
|
class Rotatable extends Uii {
|
|
2218
1911
|
constructor(els, opts) {
|
|
2219
1912
|
super(els, opts);
|
|
@@ -2262,7 +1955,6 @@ function bindHandle(uiik, handle, el, opts) {
|
|
|
2262
1955
|
let startOy = 0;
|
|
2263
1956
|
let startDeg = 0;
|
|
2264
1957
|
let container;
|
|
2265
|
-
//bind events
|
|
2266
1958
|
onPointerStart(function (args) {
|
|
2267
1959
|
const { ev } = args;
|
|
2268
1960
|
const { w, h } = getStyleSize(el);
|
|
@@ -2276,8 +1968,7 @@ function bindHandle(uiik, handle, el, opts) {
|
|
|
2276
1968
|
(startOx = ox), (startOy = oy);
|
|
2277
1969
|
container =
|
|
2278
1970
|
el instanceof SVGGraphicsElement
|
|
2279
|
-
?
|
|
2280
|
-
: el.parentElement;
|
|
1971
|
+
? el.ownerSVGElement : el.parentElement;
|
|
2281
1972
|
const currentXy = getPointInContainer(ev, container);
|
|
2282
1973
|
startDeg =
|
|
2283
1974
|
Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD +
|
|
@@ -2286,7 +1977,6 @@ function bindHandle(uiik, handle, el, opts) {
|
|
|
2286
1977
|
startDeg = 360 + startDeg;
|
|
2287
1978
|
let matrixInfo = getMatrixInfo(el);
|
|
2288
1979
|
startDeg -= matrixInfo.angle;
|
|
2289
|
-
//apply classes
|
|
2290
1980
|
el.classList.toggle(CLASS_ROTATABLE_ACTIVE, true);
|
|
2291
1981
|
onStart && onStart({ deg, cx: centerX, cy: centerY }, ev);
|
|
2292
1982
|
});
|
|
@@ -2318,12 +2008,6 @@ function bindHandle(uiik, handle, el, opts) {
|
|
|
2318
2008
|
lockPage: true,
|
|
2319
2009
|
});
|
|
2320
2010
|
}
|
|
2321
|
-
/**
|
|
2322
|
-
* Make els rotatable
|
|
2323
|
-
* @param els selector string / html element
|
|
2324
|
-
* @param opts
|
|
2325
|
-
* @returns
|
|
2326
|
-
*/
|
|
2327
2011
|
function newRotatable(els, opts) {
|
|
2328
2012
|
return new Rotatable(els, opts);
|
|
2329
2013
|
}
|
|
@@ -2344,7 +2028,6 @@ class CollisionDetector {
|
|
|
2344
2028
|
}
|
|
2345
2029
|
const ele = domEl;
|
|
2346
2030
|
this.el = domEl;
|
|
2347
|
-
//el data
|
|
2348
2031
|
const offset = getBox(ele, this.opts.container);
|
|
2349
2032
|
const rect = { x: offset.x, y: offset.y, width: ele.offsetWidth, height: ele.offsetHeight };
|
|
2350
2033
|
this.elData = {
|
|
@@ -2353,12 +2036,8 @@ class CollisionDetector {
|
|
|
2353
2036
|
x2: rect.x + rect.width,
|
|
2354
2037
|
y2: rect.y + rect.height,
|
|
2355
2038
|
};
|
|
2356
|
-
//targets data
|
|
2357
2039
|
this.update();
|
|
2358
2040
|
}
|
|
2359
|
-
/**
|
|
2360
|
-
* update targets data if them changed
|
|
2361
|
-
*/
|
|
2362
2041
|
update() {
|
|
2363
2042
|
let targets;
|
|
2364
2043
|
if (isFunction(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
|
|
@@ -2423,14 +2102,6 @@ class CollisionDetector {
|
|
|
2423
2102
|
}
|
|
2424
2103
|
}
|
|
2425
2104
|
_CollisionDetector__targets = new WeakMap();
|
|
2426
|
-
/**
|
|
2427
|
-
* create a detector for the el and return
|
|
2428
|
-
* @param el element to be detected
|
|
2429
|
-
* @param targets
|
|
2430
|
-
* @param opts CollisionDetectorOptions
|
|
2431
|
-
* @param opts.container a root element of targets
|
|
2432
|
-
* @returns
|
|
2433
|
-
*/
|
|
2434
2105
|
function newCollisionDetector(el, targets, opts) {
|
|
2435
2106
|
return new CollisionDetector(el, targets, opts);
|
|
2436
2107
|
}
|
|
@@ -2440,14 +2111,6 @@ const CLASS_SELECTOR = "uii-selector";
|
|
|
2440
2111
|
const CLASS_SELECTING = "uii-selecting";
|
|
2441
2112
|
const CLASS_SELECTED = "uii-selected";
|
|
2442
2113
|
const THRESHOLD$1 = 2;
|
|
2443
|
-
/**
|
|
2444
|
-
* 用于表示一个元素选择器的定义
|
|
2445
|
-
* > 可用CSS接口
|
|
2446
|
-
* - .uii-selector
|
|
2447
|
-
* - .uii-selecting
|
|
2448
|
-
* - .uii-selected
|
|
2449
|
-
* @public
|
|
2450
|
-
*/
|
|
2451
2114
|
class Selectable extends Uii {
|
|
2452
2115
|
constructor(container, opts) {
|
|
2453
2116
|
super(container, assign({
|
|
@@ -2458,7 +2121,6 @@ class Selectable extends Uii {
|
|
|
2458
2121
|
_Selectable__detector.set(this, void 0);
|
|
2459
2122
|
_Selectable__lastSelected.set(this, void 0);
|
|
2460
2123
|
const domEl = this.ele[0];
|
|
2461
|
-
//create selector
|
|
2462
2124
|
let selector = document.createElement("div");
|
|
2463
2125
|
if (domEl instanceof SVGElement) {
|
|
2464
2126
|
selector = document.createElementNS('http://www.w3.org/2000/svg', "rect");
|
|
@@ -2476,21 +2138,14 @@ class Selectable extends Uii {
|
|
|
2476
2138
|
}
|
|
2477
2139
|
selector.style.display = 'none';
|
|
2478
2140
|
domEl.appendChild(selector);
|
|
2479
|
-
//create detector
|
|
2480
2141
|
__classPrivateFieldSet(this, _Selectable__detector, newCollisionDetector(selector, this.opts.targets, {
|
|
2481
2142
|
container: domEl,
|
|
2482
2143
|
}), "f");
|
|
2483
2144
|
__classPrivateFieldGet(this, _Selectable_instances, "m", _Selectable_bindEvent).call(this, selector, domEl);
|
|
2484
2145
|
}
|
|
2485
|
-
/**
|
|
2486
|
-
* 更新targets
|
|
2487
|
-
*/
|
|
2488
2146
|
updateTargets() {
|
|
2489
2147
|
__classPrivateFieldGet(this, _Selectable__detector, "f").update();
|
|
2490
2148
|
}
|
|
2491
|
-
/**
|
|
2492
|
-
* @internal
|
|
2493
|
-
*/
|
|
2494
2149
|
onOptionChanged() {
|
|
2495
2150
|
this.updateTargets();
|
|
2496
2151
|
}
|
|
@@ -2508,7 +2163,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2508
2163
|
const filter = opts.filter;
|
|
2509
2164
|
const selectingClassAry = compact(split(opts.selectingClass, " "));
|
|
2510
2165
|
const selectedClassAry = compact(split(opts.selectedClass, " "));
|
|
2511
|
-
//check filter
|
|
2512
2166
|
if (filter) {
|
|
2513
2167
|
if (isFunction(filter)) {
|
|
2514
2168
|
if (filter(target))
|
|
@@ -2517,7 +2171,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2517
2171
|
else if (some(con.querySelectorAll(filter), (el) => el.contains(target)))
|
|
2518
2172
|
return true;
|
|
2519
2173
|
}
|
|
2520
|
-
//检测
|
|
2521
2174
|
const onPointerDown = opts.onPointerDown;
|
|
2522
2175
|
if (onPointerDown && onPointerDown(ev) === false)
|
|
2523
2176
|
return true;
|
|
@@ -2535,18 +2188,14 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2535
2188
|
let toTop = false;
|
|
2536
2189
|
let toRight = false;
|
|
2537
2190
|
let toBottom = false;
|
|
2538
|
-
//bind events
|
|
2539
2191
|
onPointerStart(function (args) {
|
|
2540
2192
|
const { ev } = args;
|
|
2541
|
-
//update targets count & positions
|
|
2542
2193
|
__classPrivateFieldGet(that, _Selectable__detector, "f").update();
|
|
2543
|
-
//detect container position
|
|
2544
2194
|
const pos = currentCStyle.position;
|
|
2545
2195
|
if (pos === "static") {
|
|
2546
2196
|
originPos = con.style.position;
|
|
2547
2197
|
con.style.position = "relative";
|
|
2548
2198
|
}
|
|
2549
|
-
//clear _lastSelected
|
|
2550
2199
|
each(__classPrivateFieldGet(that, _Selectable__lastSelected, "f"), t => {
|
|
2551
2200
|
target.classList.toggle(CLASS_SELECTED, false);
|
|
2552
2201
|
});
|
|
@@ -2555,13 +2204,11 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2555
2204
|
});
|
|
2556
2205
|
onPointerMove((args) => {
|
|
2557
2206
|
const { ev } = args;
|
|
2558
|
-
//获取当前位置坐标
|
|
2559
2207
|
const currentXy = getPointInContainer(ev, currentTarget, currentRect, currentCStyle, matrixInfo);
|
|
2560
2208
|
let pointX = currentXy.x;
|
|
2561
2209
|
let pointY = currentXy.y;
|
|
2562
2210
|
let offX = pointX - hitPosX;
|
|
2563
2211
|
let offY = pointY - hitPosY;
|
|
2564
|
-
//edge detect
|
|
2565
2212
|
if (scroll) {
|
|
2566
2213
|
const ltX = ev.clientX - currentRect.x;
|
|
2567
2214
|
const ltY = ev.clientY - currentRect.y;
|
|
@@ -2614,7 +2261,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2614
2261
|
style.width = w + "px";
|
|
2615
2262
|
style.height = h + "px";
|
|
2616
2263
|
style.transform = `translate3d(${x}px,${y}px,0)`;
|
|
2617
|
-
//detect collision
|
|
2618
2264
|
if (mode === "overlap") {
|
|
2619
2265
|
selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getOverlaps(x1, y1, x1 + w, y1 + h);
|
|
2620
2266
|
}
|
|
@@ -2649,7 +2295,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2649
2295
|
timer = null;
|
|
2650
2296
|
}
|
|
2651
2297
|
}
|
|
2652
|
-
//restore container position
|
|
2653
2298
|
if (originPos) {
|
|
2654
2299
|
con.style.position = originPos;
|
|
2655
2300
|
}
|
|
@@ -2672,12 +2317,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
|
|
|
2672
2317
|
lockPage: true
|
|
2673
2318
|
});
|
|
2674
2319
|
};
|
|
2675
|
-
/**
|
|
2676
|
-
* Add a selector into the container
|
|
2677
|
-
* @param container css selector or html element
|
|
2678
|
-
* @param opts
|
|
2679
|
-
* @returns
|
|
2680
|
-
*/
|
|
2681
2320
|
function newSelectable(container, opts) {
|
|
2682
2321
|
return new Selectable(container, opts);
|
|
2683
2322
|
}
|
|
@@ -2689,14 +2328,6 @@ const CLASS_SORTABLE_GHOST = "uii-sortable-ghost";
|
|
|
2689
2328
|
const CLASS_SORTABLE_ACTIVE = "uii-sortable-active";
|
|
2690
2329
|
const ATTR_SORTABLE_ACTIVE = "uii-sortable-active";
|
|
2691
2330
|
const THRESHOLD = 2;
|
|
2692
|
-
/**
|
|
2693
|
-
* 用于表示一类排序容器的定义
|
|
2694
|
-
* > 可用CSS接口
|
|
2695
|
-
* - .uii-sortable-container
|
|
2696
|
-
* - .uii-sortable-ghost
|
|
2697
|
-
* - .uii-sortable-active
|
|
2698
|
-
* @public
|
|
2699
|
-
*/
|
|
2700
2331
|
class Sortable extends Uii {
|
|
2701
2332
|
constructor(container, opts) {
|
|
2702
2333
|
super(container, merge({
|
|
@@ -2717,7 +2348,6 @@ class Sortable extends Uii {
|
|
|
2717
2348
|
el.style.pointerEvents = "initial";
|
|
2718
2349
|
bindContainer(this.registerEvent.bind(this), el, this.opts);
|
|
2719
2350
|
});
|
|
2720
|
-
//put into group
|
|
2721
2351
|
if (this.opts.group) {
|
|
2722
2352
|
if (!SORTABLE_GROUPS[this.opts.group]) {
|
|
2723
2353
|
SORTABLE_GROUPS[this.opts.group] = [];
|
|
@@ -2725,16 +2355,10 @@ class Sortable extends Uii {
|
|
|
2725
2355
|
SORTABLE_GROUPS[this.opts.group].push([this, this.ele]);
|
|
2726
2356
|
}
|
|
2727
2357
|
}
|
|
2728
|
-
/**
|
|
2729
|
-
* 调用active表示移出策略肯定是true | 'copy'
|
|
2730
|
-
* @internal
|
|
2731
|
-
*/
|
|
2732
2358
|
active(draggingItem, fromContainer, toContainers, toOpts) {
|
|
2733
2359
|
var _a;
|
|
2734
|
-
//check move
|
|
2735
2360
|
const moveFrom = (_a = toOpts.move) === null || _a === void 0 ? void 0 : _a.from;
|
|
2736
2361
|
const acceptFn = isFunction(moveFrom) ? moveFrom : () => !!moveFrom;
|
|
2737
|
-
//验证移入策略
|
|
2738
2362
|
const activableContainers = flatMap(toContainers, (el) => {
|
|
2739
2363
|
const valid = acceptFn(draggingItem, fromContainer, el);
|
|
2740
2364
|
return valid ? el : [];
|
|
@@ -2754,9 +2378,6 @@ class Sortable extends Uii {
|
|
|
2754
2378
|
toOpts.onActive &&
|
|
2755
2379
|
toOpts.onActive({ item: draggingItem, from: fromContainer });
|
|
2756
2380
|
}
|
|
2757
|
-
/**
|
|
2758
|
-
* @internal
|
|
2759
|
-
*/
|
|
2760
2381
|
deactive(draggingItem, fromContainer, toContainers, opts) {
|
|
2761
2382
|
each(toContainers, (el) => {
|
|
2762
2383
|
el.removeAttribute(ATTR_SORTABLE_ACTIVE);
|
|
@@ -2772,9 +2393,6 @@ class Sortable extends Uii {
|
|
|
2772
2393
|
opts.onDeactive &&
|
|
2773
2394
|
opts.onDeactive({ item: draggingItem, from: fromContainer });
|
|
2774
2395
|
}
|
|
2775
|
-
/**
|
|
2776
|
-
* @internal
|
|
2777
|
-
*/
|
|
2778
2396
|
onOptionChanged() { }
|
|
2779
2397
|
}
|
|
2780
2398
|
_Sortable_removeListenItems = new WeakMap();
|
|
@@ -2786,7 +2404,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
2786
2404
|
let t = e.target;
|
|
2787
2405
|
if (t === con)
|
|
2788
2406
|
return;
|
|
2789
|
-
// filter & handle
|
|
2790
2407
|
const filterStr = opts.filter ? `:not(${opts.filter})` : "";
|
|
2791
2408
|
const filteredItems = con.querySelectorAll(":scope > *" + filterStr);
|
|
2792
2409
|
const handles = opts.handle
|
|
@@ -2854,7 +2471,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
2854
2471
|
if (sort) {
|
|
2855
2472
|
removeListenItems = listenItems(opts, con, toCopy ? draggingItem : copy, filteredItems, i);
|
|
2856
2473
|
}
|
|
2857
|
-
//active
|
|
2858
2474
|
if (moveMode && group && SORTABLE_GROUPS[group]) {
|
|
2859
2475
|
each(SORTABLE_GROUPS[group], ([sortable, ele]) => {
|
|
2860
2476
|
const filtered = reject(ele, (el) => el === container);
|
|
@@ -2890,7 +2506,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
2890
2506
|
DraggingData = null;
|
|
2891
2507
|
if (removeListenItems)
|
|
2892
2508
|
removeListenItems();
|
|
2893
|
-
//deactive
|
|
2894
2509
|
if (group && SORTABLE_GROUPS[group]) {
|
|
2895
2510
|
each(SORTABLE_GROUPS[group], ([sortable, ele]) => {
|
|
2896
2511
|
const filtered = reject(ele, (el) => el === container);
|
|
@@ -2929,7 +2544,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
2929
2544
|
}
|
|
2930
2545
|
}
|
|
2931
2546
|
});
|
|
2932
|
-
//总是先触发容器enter,之后才是itementer
|
|
2933
2547
|
registerEvent(container, "mouseenter", (e) => {
|
|
2934
2548
|
var _a;
|
|
2935
2549
|
if (!DraggingData)
|
|
@@ -2966,7 +2580,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
2966
2580
|
DraggingData.toContainer = container;
|
|
2967
2581
|
if (container.getAttribute(ATTR_SORTABLE_ACTIVE)) {
|
|
2968
2582
|
let valid = true;
|
|
2969
|
-
//check move
|
|
2970
2583
|
const moveFrom = (_a = opts.move) === null || _a === void 0 ? void 0 : _a.from;
|
|
2971
2584
|
const acceptFn = isFunction(moveFrom) ? moveFrom : () => !!moveFrom;
|
|
2972
2585
|
valid = acceptFn(DraggingData.item, DraggingData.fromContainer, container);
|
|
@@ -2975,7 +2588,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
2975
2588
|
if (container.contains(draggingItem)) {
|
|
2976
2589
|
return;
|
|
2977
2590
|
}
|
|
2978
|
-
//此处检测移出策略
|
|
2979
2591
|
const moveTo = DraggingData.moveTo;
|
|
2980
2592
|
if (moveTo === "copy") {
|
|
2981
2593
|
draggingItem = DraggingData.copy;
|
|
@@ -3019,7 +2631,6 @@ function bindContainer(registerEvent, container, opts) {
|
|
|
3019
2631
|
});
|
|
3020
2632
|
}
|
|
3021
2633
|
function listenItems(opts, toContainer, draggingItem, items, fromIndex = 0) {
|
|
3022
|
-
//sorting listener
|
|
3023
2634
|
const listener = (e) => {
|
|
3024
2635
|
const ct = e.currentTarget;
|
|
3025
2636
|
if (ct.style.transform) {
|
|
@@ -3081,7 +2692,6 @@ function listenItems(opts, toContainer, draggingItem, items, fromIndex = 0) {
|
|
|
3081
2692
|
item.addEventListener("mouseenter", listener);
|
|
3082
2693
|
});
|
|
3083
2694
|
return () => {
|
|
3084
|
-
//解绑enter事件
|
|
3085
2695
|
each(items, (item, i) => {
|
|
3086
2696
|
if (item === draggingItem)
|
|
3087
2697
|
return;
|
|
@@ -3089,23 +2699,16 @@ function listenItems(opts, toContainer, draggingItem, items, fromIndex = 0) {
|
|
|
3089
2699
|
});
|
|
3090
2700
|
};
|
|
3091
2701
|
}
|
|
3092
|
-
/**
|
|
3093
|
-
* make elements within the container sortable
|
|
3094
|
-
* @param container css selector or html element(array)
|
|
3095
|
-
* @param opts
|
|
3096
|
-
* @returns
|
|
3097
|
-
*/
|
|
3098
2702
|
function newSortable(container, opts) {
|
|
3099
2703
|
return new Sortable(container, opts);
|
|
3100
2704
|
}
|
|
3101
2705
|
|
|
3102
|
-
var version = "1.3.0-beta.
|
|
2706
|
+
var version = "1.3.0-beta.2";
|
|
3103
2707
|
var repository = {
|
|
3104
2708
|
type: "git",
|
|
3105
2709
|
url: "https://github.com/holyhigh2/uiik"
|
|
3106
2710
|
};
|
|
3107
2711
|
|
|
3108
|
-
// welcome info
|
|
3109
2712
|
const welcome = globalThis.welcome;
|
|
3110
2713
|
if (!welcome) {
|
|
3111
2714
|
const ssAry = [];
|
|
@@ -3133,4 +2736,4 @@ var index = {
|
|
|
3133
2736
|
newSortable
|
|
3134
2737
|
};
|
|
3135
2738
|
|
|
3136
|
-
export { CollisionDetector, DRAGGING_RULE, Draggable, Droppable, EDGE_THRESHOLD, ONE_ANG, ONE_RAD, Resizable, Rotatable, Selectable, Sortable, Splittable, Uii,
|
|
2739
|
+
export { CollisionDetector, DRAGGING_RULE, Draggable, Droppable, EDGE_THRESHOLD, ONE_ANG, ONE_RAD, Resizable, Rotatable, Selectable, Sortable, Splittable, Uii, UiiTransform, VERSION, calcVertex, index as default, getBox, getCenterXy, getCenterXySVG, getMatrixInfo, getPointInContainer, getPointOffset, getRectInContainer, getStyleSize, getStyleXy, getTranslate, getVertex, isSVGEl, lockPage, moveBy, moveTo, newCollisionDetector, newDraggable, newDroppable, newResizable, newRotatable, newSelectable, newSortable, newSplittable, parseOxy, restoreCursor, rotateTo, saveCursor, setCursor, unlockPage, wrapper };
|