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