uiik 1.1.0 → 1.3.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/droppable.js DELETED
@@ -1,160 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _Droppable_active;
13
- /* eslint-disable require-jsdoc */
14
- /* eslint-disable max-len */
15
- /**
16
- * 拖动器
17
- * @author holyhigh2
18
- */
19
- import { each } from "myfx/collection";
20
- import { assign } from 'myfx/object';
21
- import { split, test } from 'myfx/string';
22
- import { isString, isFunction } from "myfx/is";
23
- import { Uii } from "./types";
24
- import { setCursor } from "./utils";
25
- const Droppables = [];
26
- const CLASS_DROPPABLE = "uii-droppable";
27
- /**
28
- * 用于表示一个或多个可响应拖动元素的定义
29
- * > 可用CSS接口
30
- * - .uii-droppable
31
- * @public
32
- */
33
- export class Droppable extends Uii {
34
- constructor(el, opts) {
35
- super(el, assign({}, opts));
36
- _Droppable_active.set(this, void 0);
37
- Droppables.push(this);
38
- }
39
- /**
40
- * @internal
41
- */
42
- bindEvent(droppable, opts) {
43
- //dragenter
44
- this.registerEvent(droppable, "mouseenter", (e) => {
45
- if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
46
- return;
47
- if (opts.hoverClass) {
48
- each(split(opts.hoverClass, ' '), cls => {
49
- droppable.classList.toggle(cls, true);
50
- });
51
- }
52
- if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
53
- setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver);
54
- }
55
- opts.onEnter && opts.onEnter({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
56
- });
57
- //dragleave
58
- this.registerEvent(droppable, "mouseleave", (e) => {
59
- if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
60
- return;
61
- if (opts.hoverClass) {
62
- each(split(opts.hoverClass, ' '), cls => {
63
- droppable.classList.toggle(cls, false);
64
- });
65
- }
66
- if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
67
- setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '');
68
- }
69
- opts.onLeave && opts.onLeave({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
70
- });
71
- //dragover
72
- this.registerEvent(droppable, "mousemove", (e) => {
73
- if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
74
- return;
75
- opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
76
- });
77
- //drop
78
- this.registerEvent(droppable, "mouseup", (e) => {
79
- if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
80
- return;
81
- if (opts.hoverClass) {
82
- each(split(opts.hoverClass, ' '), cls => {
83
- droppable.classList.toggle(cls, false);
84
- });
85
- }
86
- opts.onDrop && opts.onDrop({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
87
- });
88
- }
89
- /**
90
- * @internal
91
- */
92
- active(target) {
93
- let valid = true;
94
- const opts = this.opts;
95
- //check accepts
96
- if (isString(opts.accepts)) {
97
- valid = !!target.dataset.dropType && test(opts.accepts, target.dataset.dropType);
98
- }
99
- else if (isFunction(opts.accepts)) {
100
- valid = opts.accepts(this.ele, target);
101
- }
102
- if (!valid)
103
- return;
104
- __classPrivateFieldSet(this, _Droppable_active, target, "f");
105
- if (opts.activeClass) {
106
- each(this.ele, el => {
107
- each(split(opts.activeClass || '', ' '), cls => {
108
- el.classList.toggle(cls, true);
109
- });
110
- });
111
- }
112
- opts.onActive && opts.onActive({ draggable: target, droppables: this.ele });
113
- //bind events
114
- each(this.ele, (el) => {
115
- el.classList.toggle(CLASS_DROPPABLE, true);
116
- el.style.pointerEvents = 'initial';
117
- this.bindEvent(el, opts);
118
- });
119
- }
120
- /**
121
- * @internal
122
- */
123
- deactive(target) {
124
- if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
125
- return;
126
- __classPrivateFieldSet(this, _Droppable_active, null, "f");
127
- const opts = this.opts;
128
- if (opts.activeClass) {
129
- each(this.ele, el => {
130
- each(split(opts.activeClass || '', ' '), cls => {
131
- el.classList.toggle(cls, false);
132
- });
133
- });
134
- }
135
- opts.onDeactive && opts.onDeactive({ draggable: target, droppables: this.ele });
136
- //unbind events
137
- this.destroy();
138
- }
139
- }
140
- _Droppable_active = new WeakMap();
141
- //uii-drag active
142
- document.addEventListener("uii-dragactive", (e) => {
143
- each(Droppables, dpb => {
144
- dpb.active(e.target);
145
- });
146
- });
147
- document.addEventListener("uii-dragdeactive", (e) => {
148
- each(Droppables, dpb => {
149
- dpb.deactive(e.target);
150
- });
151
- });
152
- /**
153
- * Enable els to response to draggable objects
154
- * @param els selector string / html element
155
- * @param opts
156
- * @returns
157
- */
158
- export function newDroppable(els, opts) {
159
- return new Droppable(els, opts);
160
- }
package/resizable.js DELETED
@@ -1,308 +0,0 @@
1
- /* eslint-disable max-len */
2
- /**
3
- * dom resizer
4
- * @author holyhigh2
5
- */
6
- import { each, } from "myfx/collection";
7
- import { assign } from 'myfx/object';
8
- import { isArray, isFunction, isNumber } from 'myfx/is';
9
- import { Uii } from './types';
10
- import { lockPage, restoreCursor, saveCursor, setCursor, unlockPage } from './utils';
11
- const THRESHOLD = 2;
12
- const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
13
- const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
14
- const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
15
- /**
16
- * 用于表示一个或多个可改变尺寸元素的定义
17
- * > 可用CSS接口
18
- * - .uii-resizable-handle
19
- * - .uii-resizable-handle-[n/s/e/w/ne/nw/se/sw]
20
- * - .uii-resizable-handle-active
21
- * @public
22
- */
23
- export class Resizable extends Uii {
24
- constructor(els, opts) {
25
- super(els, assign({
26
- handleSize: 8,
27
- minSize: 50,
28
- dir: ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'],
29
- ghost: false,
30
- offset: 0
31
- }, opts));
32
- each(this.ele, (el) => {
33
- initHandle(el, this.opts);
34
- });
35
- }
36
- }
37
- function bindHandle(handle, dir, panel, opts) {
38
- const onStart = opts.onStart;
39
- const onResize = opts.onResize;
40
- const onEnd = opts.onEnd;
41
- const onClone = opts.onClone;
42
- handle.onmousedown = function (e) {
43
- // 获取panel当前信息
44
- const originW = panel.offsetWidth;
45
- const originH = panel.offsetHeight;
46
- const originX = panel.offsetLeft;
47
- const originY = panel.offsetTop;
48
- let changeW = false;
49
- let changeH = false;
50
- let changeX = false;
51
- let changeY = false;
52
- switch (dir) {
53
- case 's':
54
- changeH = true;
55
- break;
56
- case 'e':
57
- changeW = true;
58
- break;
59
- case 'n':
60
- changeY = true;
61
- changeH = true;
62
- break;
63
- case 'w':
64
- changeX = true;
65
- changeW = true;
66
- break;
67
- case 'se':
68
- changeW = true;
69
- changeH = true;
70
- break;
71
- case 'sw':
72
- changeX = true;
73
- changeW = true;
74
- changeH = true;
75
- break;
76
- case 'ne':
77
- changeY = true;
78
- changeW = true;
79
- changeH = true;
80
- break;
81
- case 'nw':
82
- changeX = true;
83
- changeY = true;
84
- changeW = true;
85
- changeH = true;
86
- break;
87
- }
88
- const originPosX = e.clientX;
89
- const originPosY = e.clientY;
90
- // boundary
91
- let minWidth;
92
- let minHeight;
93
- let maxWidth;
94
- let maxHeight;
95
- if (isArray(opts.minSize)) {
96
- minWidth = opts.minSize[0];
97
- minHeight = opts.minSize[1];
98
- }
99
- else if (isNumber(opts.minSize)) {
100
- minWidth = opts.minSize;
101
- minHeight = opts.minSize;
102
- }
103
- if (isArray(opts.maxSize)) {
104
- maxWidth = opts.maxSize[0];
105
- maxHeight = opts.maxSize[1];
106
- }
107
- else if (isNumber(opts.maxSize)) {
108
- maxWidth = opts.maxSize;
109
- maxHeight = opts.maxSize;
110
- }
111
- const minX = maxWidth ? originX - maxWidth + originW : null;
112
- const minY = maxHeight ? originY - maxHeight + originH : null;
113
- const maxX = minWidth ? originX + originW - minWidth : null;
114
- const maxY = minHeight ? originY + originH - minHeight : null;
115
- //ghost
116
- const ghost = opts.ghost;
117
- const ghostClass = opts.ghostClass;
118
- let ghostNode = null;
119
- //aspectRatio
120
- const aspectRatio = opts.aspectRatio;
121
- const panelStyle = panel.style;
122
- let style = panelStyle;
123
- let currentW = originW;
124
- let currentH = originH;
125
- let dragging = false;
126
- saveCursor();
127
- const dragListener = (ev) => {
128
- var _a;
129
- const offsetx = ev.clientX - originPosX;
130
- const offsety = ev.clientY - originPosY;
131
- if (!dragging) {
132
- if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
133
- dragging = true;
134
- handle.classList.add(CLASS_RESIZABLE_HANDLE_ACTIVE);
135
- if (ghost) {
136
- if (isFunction(ghost)) {
137
- ghostNode = ghost();
138
- }
139
- else {
140
- ghostNode = panel.cloneNode(true);
141
- ghostNode.style.opacity = '0.3';
142
- ghostNode.style.pointerEvents = 'none';
143
- }
144
- if (ghostNode) {
145
- if (ghostClass) {
146
- ghostNode.className =
147
- ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
148
- }
149
- (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
150
- onClone && onClone({ clone: ghostNode }, ev);
151
- }
152
- style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
153
- }
154
- lockPage();
155
- setCursor(handle.dataset.cursor || '');
156
- onStart && onStart({ w: originW, h: originH }, ev);
157
- }
158
- else {
159
- ev.preventDefault();
160
- return false;
161
- }
162
- }
163
- let w = originW;
164
- let h = originH;
165
- let y = originY;
166
- let x = originX;
167
- if (changeW) {
168
- w = originW + offsetx * (changeX ? -1 : 1);
169
- if (minWidth && w < minWidth)
170
- w = minWidth;
171
- if (maxWidth && w > maxWidth)
172
- w = maxWidth;
173
- }
174
- if (changeH) {
175
- h = originH + offsety * (changeY ? -1 : 1);
176
- if (minHeight && h < minHeight)
177
- h = minHeight;
178
- if (maxHeight && h > maxHeight)
179
- h = maxHeight;
180
- }
181
- if (changeY) {
182
- y = originY + offsety;
183
- if (minY && y < minY)
184
- y = minY;
185
- if (maxY && y > maxY)
186
- y = maxY;
187
- }
188
- if (changeX) {
189
- x = originX + offsetx;
190
- if (minX && x < minX)
191
- x = minX;
192
- if (maxX && x > maxX)
193
- x = maxX;
194
- }
195
- if (aspectRatio) {
196
- if (changeW) {
197
- style.width = w + 'px';
198
- style.height = w / aspectRatio + 'px';
199
- }
200
- if (changeH && dir !== 'sw') {
201
- if (dir === 'nw') {
202
- y = originY - w / aspectRatio + originH;
203
- }
204
- else {
205
- style.width = h * aspectRatio + 'px';
206
- style.height = h + 'px';
207
- }
208
- }
209
- }
210
- else {
211
- if (changeW) {
212
- style.width = w + 'px';
213
- }
214
- if (changeH) {
215
- style.height = h + 'px';
216
- }
217
- }
218
- if (changeY) {
219
- style.top = y + 'px';
220
- }
221
- if (changeX) {
222
- style.left = x + 'px';
223
- }
224
- currentW = w;
225
- currentH = h;
226
- onResize && onResize({ w, h }, ev);
227
- ev.preventDefault();
228
- return false;
229
- };
230
- const dragEndListener = (ev) => {
231
- var _a, _b;
232
- document.removeEventListener('mousemove', dragListener, false);
233
- document.removeEventListener('mouseup', dragEndListener, false);
234
- window.removeEventListener('blur', dragEndListener, false);
235
- if (ghost && ghostNode) {
236
- ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
237
- panelStyle.left = ghostNode.style.left;
238
- panelStyle.top = ghostNode.style.top;
239
- panelStyle.width = ghostNode.style.width;
240
- panelStyle.height = ghostNode.style.height;
241
- }
242
- if (dragging) {
243
- handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
244
- unlockPage();
245
- restoreCursor();
246
- onEnd && onEnd({ w: currentW, h: currentH }, ev);
247
- }
248
- };
249
- document.addEventListener('mousemove', dragListener, false);
250
- document.addEventListener('mouseup', dragEndListener, false);
251
- window.addEventListener('blur', dragEndListener, false);
252
- e.preventDefault();
253
- return false;
254
- };
255
- }
256
- function initHandle(panel, opts) {
257
- // create handles
258
- const handleSize = opts.handleSize;
259
- const offset = opts.offset || 0;
260
- each(opts.dir || ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'], (dir) => {
261
- const handle = document.createElement('div');
262
- handle.classList.add(CLASS_RESIZABLE_HANDLE, CLASS_RESIZABLE_HANDLE_DIR + dir);
263
- handle.setAttribute('name', 'handle');
264
- let css = '';
265
- switch (dir) {
266
- case 'n':
267
- css = `left:0px;top:${-offset}px;width:100%;height:${handleSize}px;`;
268
- break;
269
- case 's':
270
- css = `left:0px;bottom:${-offset}px;width:100%;height:${handleSize}px;`;
271
- break;
272
- case 'w':
273
- css = `top:0px;left:${-offset}px;width:${handleSize}px;height:100%;`;
274
- break;
275
- case 'e':
276
- css = `top:0px;right:${-offset}px;width:${handleSize}px;height:100%;`;
277
- break;
278
- default:
279
- css = `width:${handleSize}px;height:${handleSize}px;z-index:9;`;
280
- switch (dir) {
281
- case 'ne':
282
- css += `top:${-offset}px;right:${-offset}px;`;
283
- break;
284
- case 'nw':
285
- css += `top:${-offset}px;left:${-offset}px;`;
286
- break;
287
- case 'se':
288
- css += `bottom:${-offset}px;right:${-offset}px;`;
289
- break;
290
- case 'sw':
291
- css += `bottom:${-offset}px;left:${-offset}px;`;
292
- }
293
- }
294
- bindHandle(handle, dir, panel, opts);
295
- handle.style.cssText = `position: absolute;cursor: ${dir}-resize;` + css;
296
- handle.dataset.cursor = `${dir}-resize`;
297
- panel.appendChild(handle);
298
- });
299
- }
300
- /**
301
- * Make els resizable
302
- * @param els selector string / html element
303
- * @param opts
304
- * @returns
305
- */
306
- export function newResizable(els, opts) {
307
- return new Resizable(els, opts);
308
- }
package/rotatable.js DELETED
@@ -1,137 +0,0 @@
1
- /* eslint-disable max-len */
2
- /**
3
- * dom rotator
4
- * @author holyhigh2
5
- */
6
- import { isDefined } from 'myfx/is';
7
- import { each } from 'myfx/collection';
8
- import { Uii } from './types';
9
- import { lockPage, restoreCursor, saveCursor, setCursor, unlockPage } from './utils';
10
- const ONE_DEG = 180 / Math.PI;
11
- const THRESHOLD = 2;
12
- const CLASS_ROTATABLE = "uii-rotatable";
13
- const CLASS_ROTATABLE_HANDLE = "uii-rotatable-handle";
14
- const CLASS_ROTATABLE_ACTIVE = "uii-rotatable-active";
15
- /**
16
- * 用于表示一个或多个可旋转元素的定义
17
- * > 可用CSS接口
18
- * - .uii-rotatable
19
- * - .uii-rotatable-handle
20
- * - .uii-rotatable-active
21
- * @public
22
- */
23
- export class Rotatable extends Uii {
24
- constructor(els, opts) {
25
- super(els, opts);
26
- each(this.ele, (el) => {
27
- initHandle(el, this.opts);
28
- });
29
- }
30
- }
31
- function initHandle(el, opts) {
32
- var _a;
33
- const handle = document.createElement('div');
34
- handle.className = CLASS_ROTATABLE_HANDLE;
35
- handle.style.cssText = `
36
- position:absolute;
37
- width:12px;
38
- height:12px;
39
- border-radius:50%;
40
- left: calc(50% - 6px);
41
- top: -24px;
42
- `;
43
- handle.style.cursor = ((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.default) || 'crosshair';
44
- bindHandle(handle, el, opts);
45
- el.classList.toggle(CLASS_ROTATABLE, true);
46
- el.appendChild(handle);
47
- }
48
- function bindHandle(handle, el, opts) {
49
- const onStart = opts.onStart;
50
- const onRotate = opts.onRotate;
51
- const onEnd = opts.onEnd;
52
- handle.onmousedown = function (e) {
53
- var _a, _b;
54
- // calc center
55
- const center = window.getComputedStyle(el).transformOrigin || '';
56
- const centerPair = center.split(' ');
57
- const shadowDom = el.cloneNode();
58
- shadowDom.style.cssText = 'transform:rotate(0);z-index:-999;position:absolute;';
59
- (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.appendChild(shadowDom);
60
- const offsetXY = shadowDom.getBoundingClientRect();
61
- (_b = el.parentElement) === null || _b === void 0 ? void 0 : _b.removeChild(shadowDom);
62
- let centerX = parseFloat(centerPair[0]) + offsetXY.x;
63
- let centerY = parseFloat(centerPair[1]) + offsetXY.y;
64
- let a = 0, b = 0;
65
- const matrix = window.getComputedStyle(el).transform;
66
- if (matrix.indexOf('matrix') > -1) {
67
- const abcd = matrix.replace(/^matrix\(|\)$/mg, '').split(',');
68
- a = parseFloat(abcd[0]);
69
- b = parseFloat(abcd[1]);
70
- }
71
- let deg = Math.atan2(b, a) * ONE_DEG;
72
- if (deg < 0)
73
- deg = 360 - deg;
74
- if (deg > 360)
75
- deg = 360 - deg % 360;
76
- const style = el.style;
77
- let startDeg = Math.atan2(e.clientY - centerY, e.clientX - centerX) * ONE_DEG + 90;
78
- if (startDeg < 0)
79
- startDeg = 360 + startDeg;
80
- const offsetDeg = startDeg - deg;
81
- let dragging = false;
82
- saveCursor();
83
- const dragListener = (ev) => {
84
- var _a;
85
- const offsetx = ev.clientX - centerX;
86
- const offsety = ev.clientY - centerY;
87
- if (!dragging) {
88
- if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
89
- dragging = true;
90
- //apply classes
91
- el.classList.toggle(CLASS_ROTATABLE_ACTIVE, true);
92
- onStart && onStart({ deg }, ev);
93
- lockPage();
94
- if (isDefined(opts.cursor)) {
95
- setCursor(((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.active) || 'crosshair');
96
- }
97
- }
98
- else {
99
- ev.preventDefault();
100
- return false;
101
- }
102
- }
103
- deg = Math.atan2(offsety, offsetx) * ONE_DEG + 90 - offsetDeg;
104
- if (deg < 0)
105
- deg = 360 + deg;
106
- onRotate && onRotate({ deg }, ev);
107
- style.transform = style.transform.replace(/rotateZ\(.*?\)/, '') + ' rotateZ(' + deg + 'deg)';
108
- ev.preventDefault();
109
- return false;
110
- };
111
- const dragEndListener = (ev) => {
112
- document.removeEventListener('mousemove', dragListener, false);
113
- document.removeEventListener('mouseup', dragEndListener, false);
114
- window.removeEventListener('blur', dragEndListener, false);
115
- if (dragging) {
116
- unlockPage();
117
- restoreCursor();
118
- el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
119
- onEnd && onEnd({ deg }, ev);
120
- }
121
- };
122
- document.addEventListener('mousemove', dragListener, false);
123
- document.addEventListener('mouseup', dragEndListener, false);
124
- window.addEventListener('blur', dragEndListener, false);
125
- e.preventDefault();
126
- return false;
127
- };
128
- }
129
- /**
130
- * Make els rotatable
131
- * @param els selector string / html element
132
- * @param opts
133
- * @returns
134
- */
135
- export function newRotatable(els, opts) {
136
- return new Rotatable(els, opts);
137
- }