@formily-design/shared 1.0.0 → 1.0.1
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/package.json +2 -2
- package/dist/designable.shared.umd.production.js +0 -1
- package/dist/designable.shared.umd.production.min.js +0 -2051
- package/rollup.config.js +0 -3
- package/src/animation.ts +0 -38
- package/src/array.ts +0 -301
- package/src/clone.ts +0 -96
- package/src/compose.ts +0 -7
- package/src/coordinate.ts +0 -633
- package/src/element.ts +0 -144
- package/src/event.ts +0 -379
- package/src/globalThisPolyfill.ts +0 -19
- package/src/index.ts +0 -17
- package/src/instanceof.ts +0 -10
- package/src/keycode.ts +0 -150
- package/src/lru.ts +0 -322
- package/src/observer.ts +0 -38
- package/src/request-idle.ts +0 -22
- package/src/scroller.ts +0 -113
- package/src/subscribable.ts +0 -60
- package/src/types.ts +0 -27
- package/src/uid.ts +0 -10
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -5
|
@@ -1,2051 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Designable = global.Designable || {}, global.Designable.Shared = {})));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
const isType = (type) => (obj) => obj != null &&
|
|
8
|
-
(Array.isArray(type) ? type : [type]).some((t) => getType(obj) === `[object ${t}]`);
|
|
9
|
-
const getType = (obj) => Object.prototype.toString.call(obj);
|
|
10
|
-
const isFn = isType([
|
|
11
|
-
'Function',
|
|
12
|
-
'AsyncFunction',
|
|
13
|
-
'GeneratorFunction',
|
|
14
|
-
]);
|
|
15
|
-
const isWindow = isType('Window');
|
|
16
|
-
const isHTMLElement = (obj) => {
|
|
17
|
-
return (obj === null || obj === void 0 ? void 0 : obj['nodeName']) || (obj === null || obj === void 0 ? void 0 : obj['tagName']);
|
|
18
|
-
};
|
|
19
|
-
const isArr = Array.isArray;
|
|
20
|
-
const isPlainObj = isType('Object');
|
|
21
|
-
const isStr = isType('String');
|
|
22
|
-
const isBool = isType('Boolean');
|
|
23
|
-
const isNum = isType('Number');
|
|
24
|
-
const isObj = (val) => typeof val === 'object';
|
|
25
|
-
const isRegExp = isType('RegExp');
|
|
26
|
-
const isValid = (val) => val !== null && val !== undefined;
|
|
27
|
-
const isValidNumber = (val) => !isNaN(val) && isNum(val);
|
|
28
|
-
|
|
29
|
-
const UNSUBSCRIBE_ID_SYMBOL = Symbol('UNSUBSCRIBE_ID_SYMBOL');
|
|
30
|
-
class Subscribable {
|
|
31
|
-
constructor() {
|
|
32
|
-
this.subscribers = {
|
|
33
|
-
index: 0,
|
|
34
|
-
};
|
|
35
|
-
this.unsubscribe = (id) => {
|
|
36
|
-
if (id === undefined || id === null) {
|
|
37
|
-
for (const key in this.subscribers) {
|
|
38
|
-
this.unsubscribe(key);
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!isFn(id)) {
|
|
43
|
-
delete this.subscribers[id];
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
delete this.subscribers[id[UNSUBSCRIBE_ID_SYMBOL]];
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
dispatch(event, context) {
|
|
51
|
-
let interrupted = false;
|
|
52
|
-
for (const key in this.subscribers) {
|
|
53
|
-
if (isFn(this.subscribers[key])) {
|
|
54
|
-
event['context'] = context;
|
|
55
|
-
if (this.subscribers[key](event) === false) {
|
|
56
|
-
interrupted = true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return interrupted ? false : true;
|
|
61
|
-
}
|
|
62
|
-
subscribe(subscriber) {
|
|
63
|
-
let id;
|
|
64
|
-
if (isFn(subscriber)) {
|
|
65
|
-
id = this.subscribers.index + 1;
|
|
66
|
-
this.subscribers[id] = subscriber;
|
|
67
|
-
this.subscribers.index++;
|
|
68
|
-
}
|
|
69
|
-
const unsubscribe = () => {
|
|
70
|
-
this.unsubscribe(id);
|
|
71
|
-
};
|
|
72
|
-
unsubscribe[UNSUBSCRIBE_ID_SYMBOL] = id;
|
|
73
|
-
return unsubscribe;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getGlobalThis() {
|
|
78
|
-
try {
|
|
79
|
-
if (typeof self !== 'undefined') {
|
|
80
|
-
return self;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (e) { }
|
|
84
|
-
try {
|
|
85
|
-
if (typeof globalThisPolyfill !== 'undefined') {
|
|
86
|
-
return globalThisPolyfill;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch (e) { }
|
|
90
|
-
try {
|
|
91
|
-
if (typeof global !== 'undefined') {
|
|
92
|
-
return global;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (e) { }
|
|
96
|
-
return Function('return this')();
|
|
97
|
-
}
|
|
98
|
-
const globalThisPolyfill = getGlobalThis();
|
|
99
|
-
|
|
100
|
-
const ATTACHED_SYMBOL = Symbol('ATTACHED_SYMBOL');
|
|
101
|
-
const EVENTS_SYMBOL = Symbol('__EVENTS_SYMBOL__');
|
|
102
|
-
const EVENTS_ONCE_SYMBOL = Symbol('EVENTS_ONCE_SYMBOL');
|
|
103
|
-
const EVENTS_BATCH_SYMBOL = Symbol('EVENTS_BATCH_SYMBOL');
|
|
104
|
-
const DRIVER_INSTANCES_SYMBOL = Symbol('DRIVER_INSTANCES_SYMBOL');
|
|
105
|
-
const isOnlyMode = (mode) => mode === 'onlyOne' || mode === 'onlyChild' || mode === 'onlyParent';
|
|
106
|
-
/**
|
|
107
|
-
* 事件驱动器基类
|
|
108
|
-
*/
|
|
109
|
-
class EventDriver {
|
|
110
|
-
constructor(engine, context) {
|
|
111
|
-
this.container = document;
|
|
112
|
-
this.contentWindow = globalThisPolyfill;
|
|
113
|
-
this.engine = engine;
|
|
114
|
-
this.context = context;
|
|
115
|
-
}
|
|
116
|
-
dispatch(event) {
|
|
117
|
-
return this.engine.dispatch(event, this.context);
|
|
118
|
-
}
|
|
119
|
-
subscribe(subscriber) {
|
|
120
|
-
return this.engine.subscribe(subscriber);
|
|
121
|
-
}
|
|
122
|
-
subscribeTo(type, subscriber) {
|
|
123
|
-
return this.engine.subscribeTo(type, subscriber);
|
|
124
|
-
}
|
|
125
|
-
subscribeWith(type, subscriber) {
|
|
126
|
-
return this.engine.subscribeWith(type, subscriber);
|
|
127
|
-
}
|
|
128
|
-
attach(container) {
|
|
129
|
-
console.error('attach must implement.');
|
|
130
|
-
}
|
|
131
|
-
detach(container) {
|
|
132
|
-
console.error('attach must implement.');
|
|
133
|
-
}
|
|
134
|
-
eventTarget(type) {
|
|
135
|
-
var _a;
|
|
136
|
-
if (type === 'resize' || type === 'scroll') {
|
|
137
|
-
if (this.container === ((_a = this.contentWindow) === null || _a === void 0 ? void 0 : _a.document)) {
|
|
138
|
-
return this.contentWindow;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return this.container;
|
|
142
|
-
}
|
|
143
|
-
addEventListener(type, listener, options) {
|
|
144
|
-
var _a, _b, _c, _d;
|
|
145
|
-
const target = this.eventTarget(type);
|
|
146
|
-
if (isOnlyMode(options === null || options === void 0 ? void 0 : options.mode)) {
|
|
147
|
-
target[EVENTS_ONCE_SYMBOL] = target[EVENTS_ONCE_SYMBOL] || {};
|
|
148
|
-
const constructor = this['constructor'];
|
|
149
|
-
constructor[EVENTS_ONCE_SYMBOL] = constructor[EVENTS_ONCE_SYMBOL] || {};
|
|
150
|
-
const handler = target[EVENTS_ONCE_SYMBOL][type];
|
|
151
|
-
const container = constructor[EVENTS_ONCE_SYMBOL][type];
|
|
152
|
-
if (!handler) {
|
|
153
|
-
if (container) {
|
|
154
|
-
if (options.mode === 'onlyChild') {
|
|
155
|
-
if (container.contains(target)) {
|
|
156
|
-
container.removeEventListener(type, container[EVENTS_ONCE_SYMBOL][type], options);
|
|
157
|
-
delete container[EVENTS_ONCE_SYMBOL][type];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else if (options.mode === 'onlyParent') {
|
|
161
|
-
if (container.contains(target))
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
target.addEventListener(type, listener, options);
|
|
166
|
-
target[EVENTS_ONCE_SYMBOL][type] = listener;
|
|
167
|
-
constructor[EVENTS_ONCE_SYMBOL][type] = target;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
target[EVENTS_SYMBOL] = target[EVENTS_SYMBOL] || {};
|
|
172
|
-
target[EVENTS_SYMBOL][type] = target[EVENTS_SYMBOL][type] || new Map();
|
|
173
|
-
if (!((_b = (_a = target[EVENTS_SYMBOL][type]) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, listener))) {
|
|
174
|
-
target.addEventListener(type, listener, options);
|
|
175
|
-
(_d = (_c = target[EVENTS_SYMBOL][type]) === null || _c === void 0 ? void 0 : _c.set) === null || _d === void 0 ? void 0 : _d.call(_c, listener, true);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
removeEventListener(type, listener, options) {
|
|
180
|
-
var _a, _b;
|
|
181
|
-
const target = this.eventTarget(type);
|
|
182
|
-
if (isOnlyMode(options === null || options === void 0 ? void 0 : options.mode)) {
|
|
183
|
-
const constructor = this['constructor'];
|
|
184
|
-
constructor[EVENTS_ONCE_SYMBOL] = constructor[EVENTS_ONCE_SYMBOL] || {};
|
|
185
|
-
target[EVENTS_ONCE_SYMBOL] = target[EVENTS_ONCE_SYMBOL] || {};
|
|
186
|
-
delete constructor[EVENTS_ONCE_SYMBOL][type];
|
|
187
|
-
delete target[EVENTS_ONCE_SYMBOL][type];
|
|
188
|
-
target.removeEventListener(type, listener, options);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
target[EVENTS_SYMBOL] = target[EVENTS_SYMBOL] || {};
|
|
192
|
-
target[EVENTS_SYMBOL][type] = target[EVENTS_SYMBOL][type] || new Map();
|
|
193
|
-
(_b = (_a = target[EVENTS_SYMBOL][type]) === null || _a === void 0 ? void 0 : _a.delete) === null || _b === void 0 ? void 0 : _b.call(_a, listener);
|
|
194
|
-
target.removeEventListener(type, listener, options);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
batchAddEventListener(type, listener, options) {
|
|
198
|
-
this.engine[DRIVER_INSTANCES_SYMBOL] =
|
|
199
|
-
this.engine[DRIVER_INSTANCES_SYMBOL] || [];
|
|
200
|
-
if (!this.engine[DRIVER_INSTANCES_SYMBOL].includes(this)) {
|
|
201
|
-
this.engine[DRIVER_INSTANCES_SYMBOL].push(this);
|
|
202
|
-
}
|
|
203
|
-
this.engine[DRIVER_INSTANCES_SYMBOL].forEach((driver) => {
|
|
204
|
-
const target = driver.eventTarget(type);
|
|
205
|
-
target[EVENTS_BATCH_SYMBOL] = target[EVENTS_BATCH_SYMBOL] || {};
|
|
206
|
-
if (!target[EVENTS_BATCH_SYMBOL][type]) {
|
|
207
|
-
target.addEventListener(type, listener, options);
|
|
208
|
-
target[EVENTS_BATCH_SYMBOL][type] = listener;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
batchRemoveEventListener(type, listener, options) {
|
|
213
|
-
this.engine[DRIVER_INSTANCES_SYMBOL] =
|
|
214
|
-
this.engine[DRIVER_INSTANCES_SYMBOL] || [];
|
|
215
|
-
this.engine[DRIVER_INSTANCES_SYMBOL].forEach((driver) => {
|
|
216
|
-
const target = driver.eventTarget(type);
|
|
217
|
-
target[EVENTS_BATCH_SYMBOL] = target[EVENTS_BATCH_SYMBOL] || {};
|
|
218
|
-
target.removeEventListener(type, listener, options);
|
|
219
|
-
delete target[EVENTS_BATCH_SYMBOL][type];
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* 事件引擎
|
|
225
|
-
*/
|
|
226
|
-
class Event extends Subscribable {
|
|
227
|
-
constructor(props) {
|
|
228
|
-
super();
|
|
229
|
-
this.drivers = [];
|
|
230
|
-
this.containers = [];
|
|
231
|
-
if (isArr(props === null || props === void 0 ? void 0 : props.effects)) {
|
|
232
|
-
props.effects.forEach((plugin) => {
|
|
233
|
-
plugin(this);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
if (isArr(props === null || props === void 0 ? void 0 : props.drivers)) {
|
|
237
|
-
this.drivers = props.drivers;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
subscribeTo(type, subscriber) {
|
|
241
|
-
return this.subscribe((event) => {
|
|
242
|
-
if (type && event instanceof type) {
|
|
243
|
-
return subscriber(event);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
subscribeWith(type, subscriber) {
|
|
248
|
-
return this.subscribe((event) => {
|
|
249
|
-
if (isArr(type)) {
|
|
250
|
-
if (type.includes(event === null || event === void 0 ? void 0 : event.type)) {
|
|
251
|
-
return subscriber(event);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
if (type && (event === null || event === void 0 ? void 0 : event.type) === type) {
|
|
256
|
-
return subscriber(event);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
attachEvents(container, contentWindow = globalThisPolyfill, context) {
|
|
262
|
-
if (!container)
|
|
263
|
-
return;
|
|
264
|
-
if (isWindow(container)) {
|
|
265
|
-
return this.attachEvents(container.document, container, context);
|
|
266
|
-
}
|
|
267
|
-
if (container[ATTACHED_SYMBOL])
|
|
268
|
-
return;
|
|
269
|
-
container[ATTACHED_SYMBOL] = this.drivers.map((EventDriver) => {
|
|
270
|
-
const driver = new EventDriver(this, context);
|
|
271
|
-
driver.contentWindow = contentWindow;
|
|
272
|
-
driver.container = container;
|
|
273
|
-
driver.attach(container);
|
|
274
|
-
return driver;
|
|
275
|
-
});
|
|
276
|
-
if (!this.containers.includes(container)) {
|
|
277
|
-
this.containers.push(container);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
detachEvents(container) {
|
|
281
|
-
if (!container) {
|
|
282
|
-
this.containers.forEach((container) => {
|
|
283
|
-
this.detachEvents(container);
|
|
284
|
-
});
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
if (isWindow(container)) {
|
|
288
|
-
return this.detachEvents(container.document);
|
|
289
|
-
}
|
|
290
|
-
if (!container[ATTACHED_SYMBOL])
|
|
291
|
-
return;
|
|
292
|
-
container[ATTACHED_SYMBOL].forEach((driver) => {
|
|
293
|
-
driver.detach(container);
|
|
294
|
-
});
|
|
295
|
-
this[DRIVER_INSTANCES_SYMBOL] = this[DRIVER_INSTANCES_SYMBOL] || [];
|
|
296
|
-
this[DRIVER_INSTANCES_SYMBOL] = this[DRIVER_INSTANCES_SYMBOL].reduce((drivers, driver) => {
|
|
297
|
-
if (driver.container === container) {
|
|
298
|
-
driver.detach(container);
|
|
299
|
-
return drivers;
|
|
300
|
-
}
|
|
301
|
-
return drivers.concat(driver);
|
|
302
|
-
}, []);
|
|
303
|
-
this.containers = this.containers.filter((item) => item !== container);
|
|
304
|
-
delete container[ATTACHED_SYMBOL];
|
|
305
|
-
delete container[EVENTS_SYMBOL];
|
|
306
|
-
delete container[EVENTS_ONCE_SYMBOL];
|
|
307
|
-
delete container[EVENTS_BATCH_SYMBOL];
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const createUniformSpeedAnimation = (speed = 10, callback) => {
|
|
312
|
-
let request = null;
|
|
313
|
-
let startTime = null;
|
|
314
|
-
const start = () => {
|
|
315
|
-
if (request)
|
|
316
|
-
return;
|
|
317
|
-
request = requestAnimationFrame((timestamp) => {
|
|
318
|
-
if (startTime === null) {
|
|
319
|
-
startTime = timestamp;
|
|
320
|
-
}
|
|
321
|
-
const deltaTime = timestamp - startTime;
|
|
322
|
-
const delta = (deltaTime / 1000) * speed;
|
|
323
|
-
callback(delta);
|
|
324
|
-
request = null;
|
|
325
|
-
start();
|
|
326
|
-
});
|
|
327
|
-
};
|
|
328
|
-
start();
|
|
329
|
-
return () => {
|
|
330
|
-
if (request) {
|
|
331
|
-
cancelAnimationFrame(request);
|
|
332
|
-
request = null;
|
|
333
|
-
}
|
|
334
|
-
startTime = null;
|
|
335
|
-
};
|
|
336
|
-
};
|
|
337
|
-
//越接近阈值,速度越小,越远离阈值,速度越大
|
|
338
|
-
const calcSpeedFactor = (delta = 0, threshold = Infinity) => {
|
|
339
|
-
if (threshold >= delta) {
|
|
340
|
-
return (threshold - delta) / threshold;
|
|
341
|
-
}
|
|
342
|
-
return 0;
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const MAX_SPEED = 80; // px/s
|
|
346
|
-
const calcAutoScrollBasicInfo = (point, axis, viewport, maxSpeed = MAX_SPEED) => {
|
|
347
|
-
const { left, right, top, bottom } = viewport;
|
|
348
|
-
const { x, y } = point;
|
|
349
|
-
let begin;
|
|
350
|
-
let end;
|
|
351
|
-
let pos;
|
|
352
|
-
let speedFactor;
|
|
353
|
-
if (axis === 'x') {
|
|
354
|
-
begin = left;
|
|
355
|
-
end = right;
|
|
356
|
-
pos = x;
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
begin = top;
|
|
360
|
-
end = bottom;
|
|
361
|
-
pos = y;
|
|
362
|
-
}
|
|
363
|
-
const scrollerSize = end - begin;
|
|
364
|
-
const moveDistance = scrollerSize > 400 ? 100 : scrollerSize / 3;
|
|
365
|
-
if (end - pos < moveDistance) {
|
|
366
|
-
return {
|
|
367
|
-
direction: 'end',
|
|
368
|
-
speedFactor,
|
|
369
|
-
speed: maxSpeed * calcSpeedFactor(end - pos, moveDistance),
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
else if (pos - begin < moveDistance) {
|
|
373
|
-
return {
|
|
374
|
-
direction: 'begin',
|
|
375
|
-
speedFactor,
|
|
376
|
-
speed: maxSpeed * calcSpeedFactor(pos - begin, moveDistance),
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return null;
|
|
380
|
-
};
|
|
381
|
-
const updateScrollValue = (element, axis, value, callback) => {
|
|
382
|
-
if (element) {
|
|
383
|
-
if (!isWindow(element)) {
|
|
384
|
-
if (axis === 'x') {
|
|
385
|
-
if (element.scrollLeft + value > element.scrollWidth)
|
|
386
|
-
return;
|
|
387
|
-
element.scrollLeft += value;
|
|
388
|
-
if (isFn(callback)) {
|
|
389
|
-
callback(element.scrollLeft);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
if (element.scrollTop + value > element.scrollHeight)
|
|
394
|
-
return;
|
|
395
|
-
element.scrollTop += value;
|
|
396
|
-
if (isFn(callback)) {
|
|
397
|
-
callback(element.scrollTop);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
if (axis === 'x') {
|
|
403
|
-
element.scrollBy({
|
|
404
|
-
left: value,
|
|
405
|
-
behavior: 'smooth',
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
element.scrollBy({
|
|
410
|
-
top: value,
|
|
411
|
-
behavior: 'smooth',
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
if (isFn(callback)) {
|
|
415
|
-
callback(value);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
const scrollAnimate = (element, axis, direction, speed, callback) => {
|
|
421
|
-
return createUniformSpeedAnimation(speed, (delta) => {
|
|
422
|
-
updateScrollValue(element, axis, direction === 'begin' ? 0 - delta : delta, callback);
|
|
423
|
-
});
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
function isRect(rect) {
|
|
427
|
-
return (rect === null || rect === void 0 ? void 0 : rect.x) && (rect === null || rect === void 0 ? void 0 : rect.y) && (rect === null || rect === void 0 ? void 0 : rect.width) && (rect === null || rect === void 0 ? void 0 : rect.height);
|
|
428
|
-
}
|
|
429
|
-
function isPoint(val) {
|
|
430
|
-
return isValidNumber(val === null || val === void 0 ? void 0 : val.x) && isValidNumber(val === null || val === void 0 ? void 0 : val.y);
|
|
431
|
-
}
|
|
432
|
-
function isLineSegment(val) {
|
|
433
|
-
return isPoint(val === null || val === void 0 ? void 0 : val.start) && isPoint(val === null || val === void 0 ? void 0 : val.end);
|
|
434
|
-
}
|
|
435
|
-
class Point {
|
|
436
|
-
constructor(x, y) {
|
|
437
|
-
this.x = x;
|
|
438
|
-
this.y = y;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
class Rect {
|
|
442
|
-
constructor(x, y, width, height) {
|
|
443
|
-
this.x = 0;
|
|
444
|
-
this.y = 0;
|
|
445
|
-
this.width = 0;
|
|
446
|
-
this.height = 0;
|
|
447
|
-
this.x = x;
|
|
448
|
-
this.y = y;
|
|
449
|
-
this.width = width;
|
|
450
|
-
this.height = height;
|
|
451
|
-
}
|
|
452
|
-
get left() {
|
|
453
|
-
return this.x;
|
|
454
|
-
}
|
|
455
|
-
get right() {
|
|
456
|
-
return this.x + this.width;
|
|
457
|
-
}
|
|
458
|
-
get top() {
|
|
459
|
-
return this.y;
|
|
460
|
-
}
|
|
461
|
-
get bottom() {
|
|
462
|
-
return this.y + this.height;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
class LineSegment {
|
|
466
|
-
constructor(start, end) {
|
|
467
|
-
this.start = { ...start };
|
|
468
|
-
this.end = { ...end };
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
exports.RectQuadrant = void 0;
|
|
472
|
-
(function (RectQuadrant) {
|
|
473
|
-
RectQuadrant["Inner1"] = "I1";
|
|
474
|
-
RectQuadrant["Inner2"] = "I2";
|
|
475
|
-
RectQuadrant["Inner3"] = "I3";
|
|
476
|
-
RectQuadrant["Inner4"] = "I4";
|
|
477
|
-
RectQuadrant["Outer1"] = "O1";
|
|
478
|
-
RectQuadrant["Outer2"] = "O2";
|
|
479
|
-
RectQuadrant["Outer3"] = "O3";
|
|
480
|
-
RectQuadrant["Outer4"] = "O4";
|
|
481
|
-
})(exports.RectQuadrant || (exports.RectQuadrant = {}));
|
|
482
|
-
function isPointInRect(point, rect, sensitive = true) {
|
|
483
|
-
const boundSensor = (value) => {
|
|
484
|
-
if (!sensitive)
|
|
485
|
-
return 0;
|
|
486
|
-
const sensor = value * 0.1;
|
|
487
|
-
if (sensor > 20)
|
|
488
|
-
return 20;
|
|
489
|
-
if (sensor < 10)
|
|
490
|
-
return 10;
|
|
491
|
-
return sensor;
|
|
492
|
-
};
|
|
493
|
-
return (point.x >= rect.x + boundSensor(rect.width) &&
|
|
494
|
-
point.x <= rect.x + rect.width - boundSensor(rect.width) &&
|
|
495
|
-
point.y >= rect.y + boundSensor(rect.height) &&
|
|
496
|
-
point.y <= rect.y + rect.height - boundSensor(rect.height));
|
|
497
|
-
}
|
|
498
|
-
function isEqualRect(target, source) {
|
|
499
|
-
return ((target === null || target === void 0 ? void 0 : target.x) === (source === null || source === void 0 ? void 0 : source.x) &&
|
|
500
|
-
target.y === source.y &&
|
|
501
|
-
target.width === source.width &&
|
|
502
|
-
target.height === source.height);
|
|
503
|
-
}
|
|
504
|
-
function getRectPoints(source) {
|
|
505
|
-
const p1 = new Point(source.x, source.y);
|
|
506
|
-
const p2 = new Point(source.x + source.width, source.y);
|
|
507
|
-
const p3 = new Point(source.x + source.width, source.y + source.height);
|
|
508
|
-
const p4 = new Point(source.x, source.y + source.height);
|
|
509
|
-
return [p1, p2, p3, p4];
|
|
510
|
-
}
|
|
511
|
-
function isRectInRect(target, source) {
|
|
512
|
-
const [p1, p2, p3, p4] = getRectPoints(target);
|
|
513
|
-
return (isPointInRect(p1, source, false) &&
|
|
514
|
-
isPointInRect(p2, source, false) &&
|
|
515
|
-
isPointInRect(p3, source, false) &&
|
|
516
|
-
isPointInRect(p4, source, false));
|
|
517
|
-
}
|
|
518
|
-
function isCrossRectInRect(target, source) {
|
|
519
|
-
const targetCenterPoint = new Point(target.x + target.width / 2, target.y + target.height / 2);
|
|
520
|
-
const sourceCenterPoint = new Point(source.x + source.width / 2, source.y + source.height / 2);
|
|
521
|
-
return (Math.abs(targetCenterPoint.x - sourceCenterPoint.x) <=
|
|
522
|
-
target.width / 2 + source.width / 2 &&
|
|
523
|
-
Math.abs(targetCenterPoint.y - sourceCenterPoint.y) <=
|
|
524
|
-
target.height / 2 + source.height / 2);
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* 计算点在矩形的哪个象限
|
|
528
|
-
* @param point
|
|
529
|
-
* @param rect
|
|
530
|
-
*/
|
|
531
|
-
function calcQuadrantOfPointToRect(point, rect) {
|
|
532
|
-
const isInner = isPointInRect(point, rect);
|
|
533
|
-
if (point.x <= rect.x + rect.width / 2) {
|
|
534
|
-
if (point.y <= rect.y + rect.height / 2) {
|
|
535
|
-
if (isInner) {
|
|
536
|
-
return exports.RectQuadrant.Inner1;
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
return exports.RectQuadrant.Outer1;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
543
|
-
if (isInner) {
|
|
544
|
-
return exports.RectQuadrant.Inner4;
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
return exports.RectQuadrant.Outer4;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
else {
|
|
552
|
-
if (point.y <= rect.y + rect.height / 2) {
|
|
553
|
-
if (isInner) {
|
|
554
|
-
return exports.RectQuadrant.Inner2;
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
return exports.RectQuadrant.Outer2;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
if (isInner) {
|
|
562
|
-
return exports.RectQuadrant.Inner3;
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
return exports.RectQuadrant.Outer3;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
function calcDistanceOfPointToRect(point, rect) {
|
|
571
|
-
let minX = Math.min(Math.abs(point.x - rect.x), Math.abs(point.x - (rect.x + rect.width)));
|
|
572
|
-
let minY = Math.min(Math.abs(point.y - rect.y), Math.abs(point.y - (rect.y + rect.height)));
|
|
573
|
-
if (point.x >= rect.x && point.x <= rect.x + rect.width) {
|
|
574
|
-
minX = 0;
|
|
575
|
-
}
|
|
576
|
-
if (point.y >= rect.y && point.y <= rect.y + rect.height) {
|
|
577
|
-
minY = 0;
|
|
578
|
-
}
|
|
579
|
-
return Math.sqrt(minX ** 2 + minY ** 2);
|
|
580
|
-
}
|
|
581
|
-
function calcDistancePointToEdge(point, rect) {
|
|
582
|
-
const distanceTop = Math.abs(point.y - rect.y);
|
|
583
|
-
const distanceBottom = Math.abs(point.y - (rect.y + rect.height));
|
|
584
|
-
const distanceLeft = Math.abs(point.x - rect.x);
|
|
585
|
-
const distanceRight = Math.abs(point.x - (rect.x + rect.width));
|
|
586
|
-
return Math.min(distanceTop, distanceBottom, distanceLeft, distanceRight);
|
|
587
|
-
}
|
|
588
|
-
function isNearAfter(point, rect, inline = false) {
|
|
589
|
-
if (inline) {
|
|
590
|
-
return (Math.abs(point.x - rect.x) + Math.abs(point.y - rect.y) >
|
|
591
|
-
Math.abs(point.x - (rect.x + rect.width)) +
|
|
592
|
-
Math.abs(point.y - (rect.y + rect.height)));
|
|
593
|
-
}
|
|
594
|
-
return Math.abs(point.y - rect.y) > Math.abs(point.y - (rect.y + rect.height));
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* 计算点鱼矩形的相对位置信息
|
|
598
|
-
* @param point
|
|
599
|
-
* @param rect
|
|
600
|
-
*/
|
|
601
|
-
function calcRelativeOfPointToRect(point, rect) {
|
|
602
|
-
const distance = calcDistanceOfPointToRect(point, rect);
|
|
603
|
-
const quadrant = calcQuadrantOfPointToRect(point, rect);
|
|
604
|
-
return {
|
|
605
|
-
quadrant,
|
|
606
|
-
distance,
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
function calcBoundingRect(rects) {
|
|
610
|
-
if (!(rects === null || rects === void 0 ? void 0 : rects.length))
|
|
611
|
-
return;
|
|
612
|
-
if ((rects === null || rects === void 0 ? void 0 : rects.length) === 1 && !rects[0])
|
|
613
|
-
return;
|
|
614
|
-
let minTop = Infinity;
|
|
615
|
-
let maxBottom = -Infinity;
|
|
616
|
-
let minLeft = Infinity;
|
|
617
|
-
let maxRight = -Infinity;
|
|
618
|
-
rects.forEach((item) => {
|
|
619
|
-
const rect = new Rect(item.x, item.y, item.width, item.height);
|
|
620
|
-
if (rect.top <= minTop) {
|
|
621
|
-
minTop = rect.top;
|
|
622
|
-
}
|
|
623
|
-
if (rect.bottom >= maxBottom) {
|
|
624
|
-
maxBottom = rect.bottom;
|
|
625
|
-
}
|
|
626
|
-
if (rect.left <= minLeft) {
|
|
627
|
-
minLeft = rect.left;
|
|
628
|
-
}
|
|
629
|
-
if (rect.right >= maxRight) {
|
|
630
|
-
maxRight = rect.right;
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
return new Rect(minLeft, minTop, maxRight - minLeft, maxBottom - minTop);
|
|
634
|
-
}
|
|
635
|
-
function calcRectByStartEndPoint(startPoint, endPoint, scrollX = 0, scrollY = 0) {
|
|
636
|
-
let drawStartX = 0, drawStartY = 0;
|
|
637
|
-
if (endPoint.x + scrollX >= startPoint.x &&
|
|
638
|
-
endPoint.y + scrollY >= startPoint.y) {
|
|
639
|
-
//4象限
|
|
640
|
-
drawStartX = startPoint.x;
|
|
641
|
-
drawStartY = startPoint.y;
|
|
642
|
-
return new Rect(drawStartX - scrollX, drawStartY - scrollY, Math.abs(endPoint.x - startPoint.x + scrollX), Math.abs(endPoint.y - startPoint.y + scrollY));
|
|
643
|
-
}
|
|
644
|
-
else if (endPoint.x + scrollX < startPoint.x &&
|
|
645
|
-
endPoint.y + scrollY < startPoint.y) {
|
|
646
|
-
//1象限
|
|
647
|
-
drawStartX = endPoint.x;
|
|
648
|
-
drawStartY = endPoint.y;
|
|
649
|
-
return new Rect(drawStartX, drawStartY, Math.abs(endPoint.x - startPoint.x + scrollX), Math.abs(endPoint.y - startPoint.y + scrollY));
|
|
650
|
-
}
|
|
651
|
-
else if (endPoint.x + scrollX < startPoint.x &&
|
|
652
|
-
endPoint.y + scrollY >= startPoint.y) {
|
|
653
|
-
//3象限
|
|
654
|
-
drawStartX = endPoint.x;
|
|
655
|
-
drawStartY = startPoint.y;
|
|
656
|
-
return new Rect(drawStartX - scrollX, drawStartY - scrollY, Math.abs(endPoint.x - startPoint.x + scrollX), Math.abs(endPoint.y - startPoint.y + scrollY));
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
659
|
-
//2象限
|
|
660
|
-
drawStartX = startPoint.x;
|
|
661
|
-
drawStartY = endPoint.y;
|
|
662
|
-
return new Rect(drawStartX, drawStartY, Math.abs(endPoint.x - startPoint.x + scrollX), Math.abs(endPoint.y - startPoint.y + scrollY));
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function calcEdgeLinesOfRect(rect) {
|
|
666
|
-
return {
|
|
667
|
-
v: [
|
|
668
|
-
new LineSegment(new Point(rect.x, rect.y), new Point(rect.x, rect.y + rect.height)),
|
|
669
|
-
new LineSegment(new Point(rect.x + rect.width / 2, rect.y), new Point(rect.x + rect.width / 2, rect.y + rect.height)),
|
|
670
|
-
new LineSegment(new Point(rect.x + rect.width, rect.y), new Point(rect.x + rect.width, rect.y + rect.height)),
|
|
671
|
-
],
|
|
672
|
-
h: [
|
|
673
|
-
new LineSegment(new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y)),
|
|
674
|
-
new LineSegment(new Point(rect.x, rect.y + rect.height / 2), new Point(rect.x + rect.width, rect.y + rect.height / 2)),
|
|
675
|
-
new LineSegment(new Point(rect.x, rect.y + rect.height), new Point(rect.x + rect.width, rect.y + rect.height)),
|
|
676
|
-
],
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
function calcRectOfAxisLineSegment(line) {
|
|
680
|
-
if (!isLineSegment(line))
|
|
681
|
-
return;
|
|
682
|
-
const isXAxis = line.start.x === line.end.x;
|
|
683
|
-
return new Rect(line.start.x, line.start.y, isXAxis ? 0 : line.end.x - line.start.x, isXAxis ? line.end.y - line.start.y : 0);
|
|
684
|
-
}
|
|
685
|
-
function calcSpaceBlockOfRect(target, source, type) {
|
|
686
|
-
const targetRect = new Rect(target.x, target.y, target.width, target.height);
|
|
687
|
-
const sourceRect = new Rect(source.x, source.y, source.width, source.height);
|
|
688
|
-
if (sourceRect.bottom < targetRect.top && sourceRect.left > targetRect.right)
|
|
689
|
-
return;
|
|
690
|
-
if (sourceRect.top > targetRect.bottom && sourceRect.left > targetRect.right)
|
|
691
|
-
return;
|
|
692
|
-
if (sourceRect.bottom < targetRect.top && sourceRect.right < targetRect.left)
|
|
693
|
-
return;
|
|
694
|
-
if (sourceRect.top > targetRect.bottom && sourceRect.right < targetRect.left)
|
|
695
|
-
return;
|
|
696
|
-
if (sourceRect.bottom < targetRect.top) {
|
|
697
|
-
const distance = targetRect.top - sourceRect.bottom;
|
|
698
|
-
const left = Math.min(sourceRect.left, targetRect.left);
|
|
699
|
-
const right = Math.max(sourceRect.right, targetRect.right);
|
|
700
|
-
if (type && type !== 'top')
|
|
701
|
-
return;
|
|
702
|
-
return {
|
|
703
|
-
type: 'top',
|
|
704
|
-
distance,
|
|
705
|
-
rect: new Rect(left, sourceRect.bottom, right - left, distance),
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
else if (sourceRect.top > targetRect.bottom) {
|
|
709
|
-
const distance = sourceRect.top - targetRect.bottom;
|
|
710
|
-
const left = Math.min(sourceRect.left, targetRect.left);
|
|
711
|
-
const right = Math.max(sourceRect.right, targetRect.right);
|
|
712
|
-
if (type && type !== 'bottom')
|
|
713
|
-
return;
|
|
714
|
-
return {
|
|
715
|
-
type: 'bottom',
|
|
716
|
-
distance,
|
|
717
|
-
rect: new Rect(left, targetRect.bottom, right - left, distance),
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
else if (sourceRect.right < targetRect.left) {
|
|
721
|
-
const distance = targetRect.left - sourceRect.right;
|
|
722
|
-
const top = Math.min(sourceRect.top, targetRect.top);
|
|
723
|
-
const bottom = Math.max(sourceRect.bottom, targetRect.bottom);
|
|
724
|
-
if (type && type !== 'left')
|
|
725
|
-
return;
|
|
726
|
-
return {
|
|
727
|
-
type: 'left',
|
|
728
|
-
distance,
|
|
729
|
-
rect: new Rect(sourceRect.right, top, distance, bottom - top),
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
else if (sourceRect.left > targetRect.right) {
|
|
733
|
-
const distance = sourceRect.left - targetRect.right;
|
|
734
|
-
const top = Math.min(sourceRect.top, targetRect.top);
|
|
735
|
-
const bottom = Math.max(sourceRect.bottom, targetRect.bottom);
|
|
736
|
-
if (type && type !== 'right')
|
|
737
|
-
return;
|
|
738
|
-
return {
|
|
739
|
-
type: 'right',
|
|
740
|
-
distance,
|
|
741
|
-
rect: new Rect(targetRect.right, top, distance, bottom - top),
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
function calcExtendsLineSegmentOfRect(targetRect, referRect) {
|
|
746
|
-
if (referRect.right < targetRect.right &&
|
|
747
|
-
targetRect.left <= referRect.right) {
|
|
748
|
-
//右侧
|
|
749
|
-
if (referRect.bottom < targetRect.top) {
|
|
750
|
-
//上方
|
|
751
|
-
return {
|
|
752
|
-
start: { x: referRect.right, y: referRect.bottom },
|
|
753
|
-
end: { x: targetRect.right, y: referRect.bottom },
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
else if (referRect.top > targetRect.bottom) {
|
|
757
|
-
//下方
|
|
758
|
-
return {
|
|
759
|
-
start: { x: referRect.right, y: referRect.top },
|
|
760
|
-
end: { x: targetRect.right, y: referRect.top },
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
else if (referRect.left > targetRect.left &&
|
|
765
|
-
targetRect.right >= referRect.left) {
|
|
766
|
-
//左侧
|
|
767
|
-
if (referRect.bottom < targetRect.top) {
|
|
768
|
-
//上方
|
|
769
|
-
return {
|
|
770
|
-
start: { x: targetRect.left, y: referRect.bottom },
|
|
771
|
-
end: { x: referRect.left, y: referRect.bottom },
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
else if (referRect.top > targetRect.bottom) {
|
|
775
|
-
//下方
|
|
776
|
-
return {
|
|
777
|
-
start: { x: targetRect.left, y: referRect.top },
|
|
778
|
-
end: { x: referRect.left, y: referRect.top },
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (referRect.top < targetRect.top && targetRect.bottom >= referRect.top) {
|
|
783
|
-
//refer在上方
|
|
784
|
-
if (referRect.right < targetRect.left) {
|
|
785
|
-
//右侧
|
|
786
|
-
return {
|
|
787
|
-
start: { x: referRect.right, y: referRect.bottom },
|
|
788
|
-
end: { x: referRect.right, y: targetRect.bottom },
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
else if (referRect.left > targetRect.right) {
|
|
792
|
-
//左侧
|
|
793
|
-
return {
|
|
794
|
-
start: { x: referRect.left, y: referRect.bottom },
|
|
795
|
-
end: { x: referRect.left, y: targetRect.bottom },
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
else if (referRect.bottom > targetRect.bottom &&
|
|
800
|
-
referRect.top <= targetRect.bottom) {
|
|
801
|
-
//refer下方
|
|
802
|
-
if (referRect.right < targetRect.left) {
|
|
803
|
-
//右侧
|
|
804
|
-
return {
|
|
805
|
-
start: { x: referRect.right, y: targetRect.top },
|
|
806
|
-
end: { x: referRect.right, y: referRect.top },
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
else if (referRect.left > targetRect.right) {
|
|
810
|
-
//左侧
|
|
811
|
-
return {
|
|
812
|
-
start: { x: referRect.left, y: targetRect.top },
|
|
813
|
-
end: { x: referRect.left, y: referRect.top },
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
function calcOffsetOfSnapLineSegmentToEdge(line, current) {
|
|
819
|
-
const edges = calcEdgeLinesOfRect(current);
|
|
820
|
-
const isVerticalLine = line.start.x === line.end.x;
|
|
821
|
-
if (isVerticalLine) {
|
|
822
|
-
return { x: calcMinDistanceValue(edges.x, line.start.x) - current.x, y: 0 };
|
|
823
|
-
}
|
|
824
|
-
function calcEdgeLinesOfRect(rect) {
|
|
825
|
-
return {
|
|
826
|
-
x: [rect.x, rect.x + rect.width / 2, rect.x + rect.width],
|
|
827
|
-
y: [rect.y, rect.y + rect.height / 2, rect.y + rect.height],
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
function calcMinDistanceValue(edges, targetValue) {
|
|
831
|
-
let minDistance = Infinity, minDistanceIndex = -1;
|
|
832
|
-
for (let i = 0; i < edges.length; i++) {
|
|
833
|
-
const distance = Math.abs(edges[i] - targetValue);
|
|
834
|
-
if (minDistance > distance) {
|
|
835
|
-
minDistance = distance;
|
|
836
|
-
minDistanceIndex = i;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
return edges[minDistanceIndex];
|
|
840
|
-
}
|
|
841
|
-
return { x: 0, y: calcMinDistanceValue(edges.y, line.start.y) - current.y };
|
|
842
|
-
}
|
|
843
|
-
function calcDistanceOfSnapLineToEdges(line, edges) {
|
|
844
|
-
var _a, _b, _c, _d;
|
|
845
|
-
let distance = Infinity;
|
|
846
|
-
if (((_a = line === null || line === void 0 ? void 0 : line.start) === null || _a === void 0 ? void 0 : _a.y) === ((_b = line === null || line === void 0 ? void 0 : line.end) === null || _b === void 0 ? void 0 : _b.y)) {
|
|
847
|
-
edges.h.forEach((target) => {
|
|
848
|
-
const _distance = Math.abs(target.start.y - line.start.y);
|
|
849
|
-
if (_distance < distance) {
|
|
850
|
-
distance = _distance;
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
else if (((_c = line === null || line === void 0 ? void 0 : line.start) === null || _c === void 0 ? void 0 : _c.x) === ((_d = line === null || line === void 0 ? void 0 : line.end) === null || _d === void 0 ? void 0 : _d.x)) {
|
|
855
|
-
edges.v.forEach((target) => {
|
|
856
|
-
const _distance = Math.abs(target.start.x - line.start.x);
|
|
857
|
-
if (_distance < distance) {
|
|
858
|
-
distance = _distance;
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
else {
|
|
863
|
-
throw new Error('can not calculate slash distance');
|
|
864
|
-
}
|
|
865
|
-
return distance;
|
|
866
|
-
}
|
|
867
|
-
function calcCombineSnapLineSegment(target, source) {
|
|
868
|
-
if (target.start.x === target.end.x) {
|
|
869
|
-
return new LineSegment(new Point(target.start.x, target.start.y > source.start.y ? source.start.y : target.start.y), new Point(target.start.x, target.end.y > source.end.y ? target.end.y : source.end.y));
|
|
870
|
-
}
|
|
871
|
-
return new LineSegment(new Point(target.start.x > source.start.x ? source.start.x : target.start.x, target.start.y), new Point(target.end.x > source.end.x ? target.end.x : source.end.x, target.end.y));
|
|
872
|
-
}
|
|
873
|
-
function calcClosestEdges(line, edges) {
|
|
874
|
-
var _a, _b, _c, _d;
|
|
875
|
-
let result;
|
|
876
|
-
let distance = Infinity;
|
|
877
|
-
if (((_a = line === null || line === void 0 ? void 0 : line.start) === null || _a === void 0 ? void 0 : _a.y) === ((_b = line === null || line === void 0 ? void 0 : line.end) === null || _b === void 0 ? void 0 : _b.y)) {
|
|
878
|
-
edges.h.forEach((target) => {
|
|
879
|
-
const _distance = Math.abs(target.start.y - line.start.y);
|
|
880
|
-
if (_distance < distance) {
|
|
881
|
-
distance = _distance;
|
|
882
|
-
result = target;
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
else if (((_c = line === null || line === void 0 ? void 0 : line.start) === null || _c === void 0 ? void 0 : _c.x) === ((_d = line === null || line === void 0 ? void 0 : line.end) === null || _d === void 0 ? void 0 : _d.x)) {
|
|
887
|
-
edges.v.forEach((target) => {
|
|
888
|
-
const _distance = Math.abs(target.start.x - line.start.x);
|
|
889
|
-
if (_distance < distance) {
|
|
890
|
-
distance = _distance;
|
|
891
|
-
result = target;
|
|
892
|
-
}
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
throw new Error('can not calculate slash distance');
|
|
897
|
-
}
|
|
898
|
-
return [distance, result];
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
let IDX = 36, HEX = '';
|
|
902
|
-
while (IDX--)
|
|
903
|
-
HEX += IDX.toString(36);
|
|
904
|
-
function uid(len) {
|
|
905
|
-
let str = '', num = len || 11;
|
|
906
|
-
while (num--)
|
|
907
|
-
str += HEX[(Math.random() * 36) | 0];
|
|
908
|
-
return str;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
const instOf = (value, cls) => {
|
|
912
|
-
if (isFn(cls))
|
|
913
|
-
return value instanceof cls;
|
|
914
|
-
if (isStr(cls))
|
|
915
|
-
return globalThisPolyfill[cls]
|
|
916
|
-
? value instanceof globalThisPolyfill[cls]
|
|
917
|
-
: false;
|
|
918
|
-
return false;
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
const NATIVE_KEYS = [
|
|
922
|
-
['Map', (map) => new Map(map)],
|
|
923
|
-
['WeakMap', (map) => new WeakMap(map)],
|
|
924
|
-
['WeakSet', (set) => new WeakSet(set)],
|
|
925
|
-
['Set', (set) => new Set(set)],
|
|
926
|
-
['Date', (date) => new Date(date)],
|
|
927
|
-
'FileList',
|
|
928
|
-
'File',
|
|
929
|
-
'URL',
|
|
930
|
-
'RegExp',
|
|
931
|
-
[
|
|
932
|
-
'Promise',
|
|
933
|
-
(promise) => new Promise((resolve, reject) => promise.then(resolve, reject)),
|
|
934
|
-
],
|
|
935
|
-
];
|
|
936
|
-
const isNativeObject = (values) => {
|
|
937
|
-
for (let i = 0; i < NATIVE_KEYS.length; i++) {
|
|
938
|
-
const item = NATIVE_KEYS[i];
|
|
939
|
-
if (Array.isArray(item) && item[0]) {
|
|
940
|
-
if (instOf(values, item[0])) {
|
|
941
|
-
return item[1] ? item[1] : item[0];
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
if (instOf(values, item)) {
|
|
946
|
-
return item;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
const shallowClone = (values) => {
|
|
952
|
-
let nativeClone;
|
|
953
|
-
if (Array.isArray(values)) {
|
|
954
|
-
return values.slice(0);
|
|
955
|
-
}
|
|
956
|
-
else if (isNativeObject(values)) {
|
|
957
|
-
nativeClone = isNativeObject(values);
|
|
958
|
-
return isFn(nativeClone) ? nativeClone(values) : values;
|
|
959
|
-
}
|
|
960
|
-
else if (typeof values === 'object' && !!values) {
|
|
961
|
-
return {
|
|
962
|
-
...values,
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
const clone = (values, filter) => {
|
|
967
|
-
let nativeClone;
|
|
968
|
-
if (Array.isArray(values)) {
|
|
969
|
-
return values.map((item) => clone(item, filter));
|
|
970
|
-
}
|
|
971
|
-
else if (isNativeObject(values)) {
|
|
972
|
-
nativeClone = isNativeObject(values);
|
|
973
|
-
return isFn(nativeClone) ? nativeClone(values) : values;
|
|
974
|
-
}
|
|
975
|
-
else if (typeof values === 'object' && !!values) {
|
|
976
|
-
if ('$$typeof' in values && '_owner' in values) {
|
|
977
|
-
return values;
|
|
978
|
-
}
|
|
979
|
-
if (values._isAMomentObject) {
|
|
980
|
-
return values;
|
|
981
|
-
}
|
|
982
|
-
if (values._isJSONSchemaObject) {
|
|
983
|
-
return values;
|
|
984
|
-
}
|
|
985
|
-
if (isFn(values.toJS)) {
|
|
986
|
-
return values;
|
|
987
|
-
}
|
|
988
|
-
if (isFn(values.toJSON)) {
|
|
989
|
-
return values;
|
|
990
|
-
}
|
|
991
|
-
if (Object.getOwnPropertySymbols(values || {}).length) {
|
|
992
|
-
return values;
|
|
993
|
-
}
|
|
994
|
-
const res = {};
|
|
995
|
-
for (const key in values) {
|
|
996
|
-
if (Object.hasOwnProperty.call(values, key)) {
|
|
997
|
-
if (isFn(filter)) {
|
|
998
|
-
if (filter(values[key], key)) {
|
|
999
|
-
res[key] = clone(values[key], filter);
|
|
1000
|
-
}
|
|
1001
|
-
else {
|
|
1002
|
-
res[key] = values[key];
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
res[key] = clone(values[key], filter);
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
return res;
|
|
1011
|
-
}
|
|
1012
|
-
else {
|
|
1013
|
-
return values;
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
|
|
1017
|
-
/**
|
|
1018
|
-
* A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
|
|
1019
|
-
* recently used items while discarding least recently used items when its limit
|
|
1020
|
-
* is reached.
|
|
1021
|
-
*
|
|
1022
|
-
* Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
|
|
1023
|
-
* See README.md for details.
|
|
1024
|
-
*
|
|
1025
|
-
* Illustration of the design:
|
|
1026
|
-
*
|
|
1027
|
-
* entry entry entry entry
|
|
1028
|
-
* ______ ______ ______ ______
|
|
1029
|
-
* | head |.newer => | |.newer => | |.newer => | tail |
|
|
1030
|
-
* | A | | B | | C | | D |
|
|
1031
|
-
* |______| <= older.|______| <= older.|______| <= older.|______|
|
|
1032
|
-
*
|
|
1033
|
-
* removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
|
|
1034
|
-
*/
|
|
1035
|
-
/* eslint-disable */
|
|
1036
|
-
const NEWER = Symbol('newer');
|
|
1037
|
-
const OLDER = Symbol('older');
|
|
1038
|
-
function Entry(key, value) {
|
|
1039
|
-
this.key = key;
|
|
1040
|
-
this.value = value;
|
|
1041
|
-
this[NEWER] = undefined;
|
|
1042
|
-
this[OLDER] = undefined;
|
|
1043
|
-
}
|
|
1044
|
-
class LRUMap {
|
|
1045
|
-
constructor(limit, entries) {
|
|
1046
|
-
if (typeof limit !== 'number') {
|
|
1047
|
-
// called as (entries)
|
|
1048
|
-
entries = limit;
|
|
1049
|
-
limit = 0;
|
|
1050
|
-
}
|
|
1051
|
-
this.size = 0;
|
|
1052
|
-
this.limit = limit;
|
|
1053
|
-
this.oldest = this.newest = undefined;
|
|
1054
|
-
this._keymap = new Map();
|
|
1055
|
-
if (entries) {
|
|
1056
|
-
this.assign(entries);
|
|
1057
|
-
if (limit < 1) {
|
|
1058
|
-
this.limit = this.size;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
_markEntryAsUsed(entry) {
|
|
1063
|
-
if (entry === this.newest) {
|
|
1064
|
-
// Already the most recenlty used entry, so no need to update the list
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
// HEAD--------------TAIL
|
|
1068
|
-
// <.older .newer>
|
|
1069
|
-
// <--- add direction --
|
|
1070
|
-
// A B C <D> E
|
|
1071
|
-
if (entry[NEWER]) {
|
|
1072
|
-
if (entry === this.oldest) {
|
|
1073
|
-
this.oldest = entry[NEWER];
|
|
1074
|
-
}
|
|
1075
|
-
entry[NEWER][OLDER] = entry[OLDER]; // C <-- E.
|
|
1076
|
-
}
|
|
1077
|
-
if (entry[OLDER]) {
|
|
1078
|
-
entry[OLDER][NEWER] = entry[NEWER]; // C. --> E
|
|
1079
|
-
}
|
|
1080
|
-
entry[NEWER] = undefined; // D --x
|
|
1081
|
-
entry[OLDER] = this.newest; // D. --> E
|
|
1082
|
-
if (this.newest) {
|
|
1083
|
-
this.newest[NEWER] = entry; // E. <-- D
|
|
1084
|
-
}
|
|
1085
|
-
this.newest = entry;
|
|
1086
|
-
}
|
|
1087
|
-
assign(entries) {
|
|
1088
|
-
let entry;
|
|
1089
|
-
let limit = this.limit || Number.MAX_VALUE;
|
|
1090
|
-
this._keymap.clear();
|
|
1091
|
-
const it = entries[Symbol.iterator]();
|
|
1092
|
-
for (let itv = it.next(); !itv.done; itv = it.next()) {
|
|
1093
|
-
const e = new Entry(itv.value[0], itv.value[1]);
|
|
1094
|
-
this._keymap.set(e.key, e);
|
|
1095
|
-
if (!entry) {
|
|
1096
|
-
this.oldest = e;
|
|
1097
|
-
}
|
|
1098
|
-
else {
|
|
1099
|
-
entry[NEWER] = e;
|
|
1100
|
-
e[OLDER] = entry;
|
|
1101
|
-
}
|
|
1102
|
-
entry = e;
|
|
1103
|
-
if (limit-- === 0) {
|
|
1104
|
-
throw new Error('overflow');
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
this.newest = entry;
|
|
1108
|
-
this.size = this._keymap.size;
|
|
1109
|
-
}
|
|
1110
|
-
get(key) {
|
|
1111
|
-
// First, find our cache entry
|
|
1112
|
-
const entry = this._keymap.get(key);
|
|
1113
|
-
if (!entry) {
|
|
1114
|
-
return;
|
|
1115
|
-
} // Not cached. Sorry.
|
|
1116
|
-
// As <key> was found in the cache, register it as being requested recently
|
|
1117
|
-
this._markEntryAsUsed(entry);
|
|
1118
|
-
return entry.value;
|
|
1119
|
-
}
|
|
1120
|
-
set(key, value) {
|
|
1121
|
-
let entry = this._keymap.get(key);
|
|
1122
|
-
if (entry) {
|
|
1123
|
-
// update existing
|
|
1124
|
-
entry.value = value;
|
|
1125
|
-
this._markEntryAsUsed(entry);
|
|
1126
|
-
return this;
|
|
1127
|
-
}
|
|
1128
|
-
// new entry
|
|
1129
|
-
this._keymap.set(key, (entry = new Entry(key, value)));
|
|
1130
|
-
if (this.newest) {
|
|
1131
|
-
// link previous tail to the new tail (entry)
|
|
1132
|
-
this.newest[NEWER] = entry;
|
|
1133
|
-
entry[OLDER] = this.newest;
|
|
1134
|
-
}
|
|
1135
|
-
else {
|
|
1136
|
-
// we're first in -- yay
|
|
1137
|
-
this.oldest = entry;
|
|
1138
|
-
}
|
|
1139
|
-
// add new entry to the end of the linked list -- it's now the freshest entry.
|
|
1140
|
-
this.newest = entry;
|
|
1141
|
-
++this.size;
|
|
1142
|
-
if (this.size > this.limit) {
|
|
1143
|
-
// we hit the limit -- remove the head
|
|
1144
|
-
this.shift();
|
|
1145
|
-
}
|
|
1146
|
-
return this;
|
|
1147
|
-
}
|
|
1148
|
-
shift() {
|
|
1149
|
-
// todo: handle special case when limit == 1
|
|
1150
|
-
const entry = this.oldest;
|
|
1151
|
-
if (entry) {
|
|
1152
|
-
if (this.oldest[NEWER]) {
|
|
1153
|
-
// advance the list
|
|
1154
|
-
this.oldest = this.oldest[NEWER];
|
|
1155
|
-
this.oldest[OLDER] = undefined;
|
|
1156
|
-
}
|
|
1157
|
-
else {
|
|
1158
|
-
// the cache is exhausted
|
|
1159
|
-
this.oldest = undefined;
|
|
1160
|
-
this.newest = undefined;
|
|
1161
|
-
}
|
|
1162
|
-
// Remove last strong reference to <entry> and remove links from the purged
|
|
1163
|
-
// entry being returned:
|
|
1164
|
-
entry[NEWER] = entry[OLDER] = undefined;
|
|
1165
|
-
this._keymap.delete(entry.key);
|
|
1166
|
-
--this.size;
|
|
1167
|
-
return [entry.key, entry.value];
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
find(key) {
|
|
1171
|
-
const e = this._keymap.get(key);
|
|
1172
|
-
return e ? e.value : undefined;
|
|
1173
|
-
}
|
|
1174
|
-
has(key) {
|
|
1175
|
-
return this._keymap.has(key);
|
|
1176
|
-
}
|
|
1177
|
-
delete(key) {
|
|
1178
|
-
const entry = this._keymap.get(key);
|
|
1179
|
-
if (!entry) {
|
|
1180
|
-
return;
|
|
1181
|
-
}
|
|
1182
|
-
this._keymap.delete(entry.key);
|
|
1183
|
-
if (entry[NEWER] && entry[OLDER]) {
|
|
1184
|
-
// relink the older entry with the newer entry
|
|
1185
|
-
entry[OLDER][NEWER] = entry[NEWER];
|
|
1186
|
-
entry[NEWER][OLDER] = entry[OLDER];
|
|
1187
|
-
}
|
|
1188
|
-
else if (entry[NEWER]) {
|
|
1189
|
-
// remove the link to us
|
|
1190
|
-
entry[NEWER][OLDER] = undefined;
|
|
1191
|
-
// link the newer entry to head
|
|
1192
|
-
this.oldest = entry[NEWER];
|
|
1193
|
-
}
|
|
1194
|
-
else if (entry[OLDER]) {
|
|
1195
|
-
// remove the link to us
|
|
1196
|
-
entry[OLDER][NEWER] = undefined;
|
|
1197
|
-
// link the newer entry to head
|
|
1198
|
-
this.newest = entry[OLDER];
|
|
1199
|
-
}
|
|
1200
|
-
else {
|
|
1201
|
-
// if(entry[OLDER] === undefined && entry.newer === undefined) {
|
|
1202
|
-
this.oldest = this.newest = undefined;
|
|
1203
|
-
}
|
|
1204
|
-
this.size--;
|
|
1205
|
-
return entry.value;
|
|
1206
|
-
}
|
|
1207
|
-
clear() {
|
|
1208
|
-
// Not clearing links should be safe, as we don't expose live links to user
|
|
1209
|
-
this.oldest = this.newest = undefined;
|
|
1210
|
-
this.size = 0;
|
|
1211
|
-
this._keymap.clear();
|
|
1212
|
-
}
|
|
1213
|
-
keys() {
|
|
1214
|
-
return new KeyIterator(this.oldest);
|
|
1215
|
-
}
|
|
1216
|
-
values() {
|
|
1217
|
-
return new ValueIterator(this.oldest);
|
|
1218
|
-
}
|
|
1219
|
-
entries() { }
|
|
1220
|
-
forEach(fun, thisObj) {
|
|
1221
|
-
if (typeof thisObj !== 'object') {
|
|
1222
|
-
thisObj = this;
|
|
1223
|
-
}
|
|
1224
|
-
let entry = this.oldest;
|
|
1225
|
-
while (entry) {
|
|
1226
|
-
fun.call(thisObj, entry.value, entry.key, this);
|
|
1227
|
-
entry = entry[NEWER];
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
toJSON() {
|
|
1231
|
-
const s = new Array(this.size);
|
|
1232
|
-
let i = 0;
|
|
1233
|
-
let entry = this.oldest;
|
|
1234
|
-
while (entry) {
|
|
1235
|
-
s[i++] = { key: entry.key, value: entry.value };
|
|
1236
|
-
entry = entry[NEWER];
|
|
1237
|
-
}
|
|
1238
|
-
return s;
|
|
1239
|
-
}
|
|
1240
|
-
toString() {
|
|
1241
|
-
let s = '';
|
|
1242
|
-
let entry = this.oldest;
|
|
1243
|
-
while (entry) {
|
|
1244
|
-
s += String(entry.key) + ':' + entry.value;
|
|
1245
|
-
entry = entry[NEWER];
|
|
1246
|
-
if (entry) {
|
|
1247
|
-
s += ' < ';
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
return s;
|
|
1251
|
-
}
|
|
1252
|
-
[Symbol.iterator]() {
|
|
1253
|
-
return new EntryIterator(this.oldest);
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
class EntryIterator {
|
|
1257
|
-
constructor(oldestEntry) {
|
|
1258
|
-
this.entry = oldestEntry;
|
|
1259
|
-
}
|
|
1260
|
-
[Symbol.iterator]() {
|
|
1261
|
-
return this;
|
|
1262
|
-
}
|
|
1263
|
-
next() {
|
|
1264
|
-
const ent = this.entry;
|
|
1265
|
-
if (ent) {
|
|
1266
|
-
this.entry = ent[NEWER];
|
|
1267
|
-
return { done: false, value: [ent.key, ent.value] };
|
|
1268
|
-
}
|
|
1269
|
-
else {
|
|
1270
|
-
return { done: true, value: undefined };
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
class KeyIterator {
|
|
1275
|
-
constructor(oldestEntry) {
|
|
1276
|
-
this.entry = oldestEntry;
|
|
1277
|
-
}
|
|
1278
|
-
[Symbol.iterator]() {
|
|
1279
|
-
return this;
|
|
1280
|
-
}
|
|
1281
|
-
next() {
|
|
1282
|
-
const ent = this.entry;
|
|
1283
|
-
if (ent) {
|
|
1284
|
-
this.entry = ent[NEWER];
|
|
1285
|
-
return { done: false, value: ent.key };
|
|
1286
|
-
}
|
|
1287
|
-
else {
|
|
1288
|
-
return { done: true, value: undefined };
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
class ValueIterator {
|
|
1293
|
-
constructor(oldestEntry) {
|
|
1294
|
-
this.entry = oldestEntry;
|
|
1295
|
-
}
|
|
1296
|
-
[Symbol.iterator]() {
|
|
1297
|
-
return this;
|
|
1298
|
-
}
|
|
1299
|
-
next() {
|
|
1300
|
-
const ent = this.entry;
|
|
1301
|
-
if (ent) {
|
|
1302
|
-
this.entry = ent[NEWER];
|
|
1303
|
-
return { done: false, value: ent.value };
|
|
1304
|
-
}
|
|
1305
|
-
else {
|
|
1306
|
-
return { done: true, value: undefined };
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
const compose = (...fns) => {
|
|
1312
|
-
return (payload) => {
|
|
1313
|
-
return fns.reduce((buf, fn) => {
|
|
1314
|
-
return fn(buf);
|
|
1315
|
-
}, payload);
|
|
1316
|
-
};
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
|
-
const toArr = (val) => (isArr(val) ? val : val ? [val] : []);
|
|
1320
|
-
function each(val, iterator, revert) {
|
|
1321
|
-
if (isArr(val) || isStr(val)) {
|
|
1322
|
-
if (revert) {
|
|
1323
|
-
for (let i = val.length - 1; i >= 0; i--) {
|
|
1324
|
-
if (iterator(val[i], i) === false) {
|
|
1325
|
-
return;
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
else {
|
|
1330
|
-
for (let i = 0; i < val.length; i++) {
|
|
1331
|
-
if (iterator(val[i], i) === false) {
|
|
1332
|
-
return;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
else if (isObj(val)) {
|
|
1338
|
-
let key;
|
|
1339
|
-
for (key in val) {
|
|
1340
|
-
if (Object.hasOwnProperty.call(val, key)) {
|
|
1341
|
-
if (iterator(val[key], key) === false) {
|
|
1342
|
-
return;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
function map(val, iterator, revert) {
|
|
1349
|
-
const res = isArr(val) || isStr(val) ? [] : {};
|
|
1350
|
-
each(val, (item, key) => {
|
|
1351
|
-
const value = iterator(item, key);
|
|
1352
|
-
if (isArr(res)) {
|
|
1353
|
-
res.push(value);
|
|
1354
|
-
}
|
|
1355
|
-
else {
|
|
1356
|
-
res[key] = value;
|
|
1357
|
-
}
|
|
1358
|
-
}, revert);
|
|
1359
|
-
return res;
|
|
1360
|
-
}
|
|
1361
|
-
function reduce(val, iterator, accumulator, revert) {
|
|
1362
|
-
let result = accumulator;
|
|
1363
|
-
each(val, (item, key) => {
|
|
1364
|
-
result = iterator(result, item, key);
|
|
1365
|
-
}, revert);
|
|
1366
|
-
return result;
|
|
1367
|
-
}
|
|
1368
|
-
function every(val, iterator, revert) {
|
|
1369
|
-
let res = true;
|
|
1370
|
-
each(val, (item, key) => {
|
|
1371
|
-
if (!iterator(item, key)) {
|
|
1372
|
-
res = false;
|
|
1373
|
-
return false;
|
|
1374
|
-
}
|
|
1375
|
-
}, revert);
|
|
1376
|
-
return res;
|
|
1377
|
-
}
|
|
1378
|
-
function some(val, iterator, revert) {
|
|
1379
|
-
let res = false;
|
|
1380
|
-
each(val, (item, key) => {
|
|
1381
|
-
if (iterator(item, key)) {
|
|
1382
|
-
res = true;
|
|
1383
|
-
return false;
|
|
1384
|
-
}
|
|
1385
|
-
}, revert);
|
|
1386
|
-
return res;
|
|
1387
|
-
}
|
|
1388
|
-
function findIndex(val, iterator, revert) {
|
|
1389
|
-
let res = -1;
|
|
1390
|
-
each(val, (item, key) => {
|
|
1391
|
-
if (iterator(item, key)) {
|
|
1392
|
-
res = key;
|
|
1393
|
-
return false;
|
|
1394
|
-
}
|
|
1395
|
-
}, revert);
|
|
1396
|
-
return res;
|
|
1397
|
-
}
|
|
1398
|
-
function find(val, iterator, revert) {
|
|
1399
|
-
let res;
|
|
1400
|
-
each(val, (item, key) => {
|
|
1401
|
-
if (iterator(item, key)) {
|
|
1402
|
-
res = item;
|
|
1403
|
-
return false;
|
|
1404
|
-
}
|
|
1405
|
-
}, revert);
|
|
1406
|
-
return res;
|
|
1407
|
-
}
|
|
1408
|
-
function includes(val, searchElement, revert) {
|
|
1409
|
-
if (isStr(val))
|
|
1410
|
-
return val.includes(searchElement);
|
|
1411
|
-
return some(val, (item) => item === searchElement, revert);
|
|
1412
|
-
}
|
|
1413
|
-
function includesWith(val, search) {
|
|
1414
|
-
if (isArr(val)) {
|
|
1415
|
-
return val.some((item) => search(item));
|
|
1416
|
-
}
|
|
1417
|
-
else {
|
|
1418
|
-
return false;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
const flat = (array) => {
|
|
1422
|
-
return toArr(array).reduce((buf, item) => {
|
|
1423
|
-
if (isArr(item))
|
|
1424
|
-
return buf.concat(flat(item));
|
|
1425
|
-
return buf.concat(item);
|
|
1426
|
-
}, []);
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
|
-
exports.KeyCode = void 0;
|
|
1430
|
-
(function (KeyCode) {
|
|
1431
|
-
KeyCode["Backspace"] = "Backspace";
|
|
1432
|
-
KeyCode["Tab"] = "Tab";
|
|
1433
|
-
KeyCode["Enter"] = "Enter";
|
|
1434
|
-
KeyCode["Shift"] = "Shift";
|
|
1435
|
-
KeyCode["Control"] = "Control";
|
|
1436
|
-
KeyCode["Alt"] = "Alt";
|
|
1437
|
-
KeyCode["CapsLock"] = "CapsLock";
|
|
1438
|
-
KeyCode["Escape"] = "Escape";
|
|
1439
|
-
KeyCode["Space"] = " ";
|
|
1440
|
-
KeyCode["PageUp"] = "PageUp";
|
|
1441
|
-
KeyCode["PageDown"] = "PageDown";
|
|
1442
|
-
KeyCode["End"] = "End";
|
|
1443
|
-
KeyCode["Home"] = "Home";
|
|
1444
|
-
KeyCode["ArrowLeft"] = "ArrowLeft";
|
|
1445
|
-
KeyCode["ArrowUp"] = "ArrowUp";
|
|
1446
|
-
KeyCode["ArrowRight"] = "ArrowRight";
|
|
1447
|
-
KeyCode["ArrowDown"] = "ArrowDown";
|
|
1448
|
-
KeyCode["Left"] = "Left";
|
|
1449
|
-
KeyCode["Up"] = "Up";
|
|
1450
|
-
KeyCode["Right"] = "Right";
|
|
1451
|
-
KeyCode["Down"] = "Down";
|
|
1452
|
-
KeyCode["Insert"] = "Insert";
|
|
1453
|
-
KeyCode["Delete"] = "Delete";
|
|
1454
|
-
KeyCode["Zero"] = "0";
|
|
1455
|
-
KeyCode["ClosedParen"] = ")";
|
|
1456
|
-
KeyCode["One"] = "1";
|
|
1457
|
-
KeyCode["ExclamationMark"] = "!";
|
|
1458
|
-
KeyCode["Two"] = "2";
|
|
1459
|
-
KeyCode["AtSign"] = "@";
|
|
1460
|
-
KeyCode["Three"] = "3";
|
|
1461
|
-
KeyCode["PoundSign"] = "\u00A3";
|
|
1462
|
-
KeyCode["Hash"] = "#";
|
|
1463
|
-
KeyCode["Four"] = "4";
|
|
1464
|
-
KeyCode["DollarSign"] = "$";
|
|
1465
|
-
KeyCode["Five"] = "5";
|
|
1466
|
-
KeyCode["PercentSign"] = "%";
|
|
1467
|
-
KeyCode["Six"] = "6";
|
|
1468
|
-
KeyCode["Caret"] = "^";
|
|
1469
|
-
KeyCode["Hat"] = "^";
|
|
1470
|
-
KeyCode["Seven"] = "7";
|
|
1471
|
-
KeyCode["Ampersand"] = "&";
|
|
1472
|
-
KeyCode["Eight"] = "8";
|
|
1473
|
-
KeyCode["Star"] = "*";
|
|
1474
|
-
KeyCode["Asterisk"] = "*";
|
|
1475
|
-
KeyCode["Nine"] = "9";
|
|
1476
|
-
KeyCode["OpenParen"] = "(";
|
|
1477
|
-
KeyCode["a"] = "a";
|
|
1478
|
-
KeyCode["b"] = "b";
|
|
1479
|
-
KeyCode["c"] = "c";
|
|
1480
|
-
KeyCode["d"] = "d";
|
|
1481
|
-
KeyCode["e"] = "e";
|
|
1482
|
-
KeyCode["f"] = "f";
|
|
1483
|
-
KeyCode["g"] = "g";
|
|
1484
|
-
KeyCode["h"] = "h";
|
|
1485
|
-
KeyCode["i"] = "i";
|
|
1486
|
-
KeyCode["j"] = "j";
|
|
1487
|
-
KeyCode["k"] = "k";
|
|
1488
|
-
KeyCode["l"] = "l";
|
|
1489
|
-
KeyCode["m"] = "m";
|
|
1490
|
-
KeyCode["n"] = "n";
|
|
1491
|
-
KeyCode["o"] = "o";
|
|
1492
|
-
KeyCode["p"] = "p";
|
|
1493
|
-
KeyCode["q"] = "q";
|
|
1494
|
-
KeyCode["r"] = "r";
|
|
1495
|
-
KeyCode["s"] = "s";
|
|
1496
|
-
KeyCode["t"] = "t";
|
|
1497
|
-
KeyCode["u"] = "u";
|
|
1498
|
-
KeyCode["v"] = "v";
|
|
1499
|
-
KeyCode["w"] = "w";
|
|
1500
|
-
KeyCode["x"] = "x";
|
|
1501
|
-
KeyCode["y"] = "y";
|
|
1502
|
-
KeyCode["z"] = "z";
|
|
1503
|
-
KeyCode["A"] = "A";
|
|
1504
|
-
KeyCode["B"] = "B";
|
|
1505
|
-
KeyCode["C"] = "C";
|
|
1506
|
-
KeyCode["D"] = "D";
|
|
1507
|
-
KeyCode["E"] = "E";
|
|
1508
|
-
KeyCode["F"] = "F";
|
|
1509
|
-
KeyCode["G"] = "G";
|
|
1510
|
-
KeyCode["H"] = "H";
|
|
1511
|
-
KeyCode["I"] = "I";
|
|
1512
|
-
KeyCode["J"] = "J";
|
|
1513
|
-
KeyCode["K"] = "K";
|
|
1514
|
-
KeyCode["L"] = "L";
|
|
1515
|
-
KeyCode["M"] = "M";
|
|
1516
|
-
KeyCode["N"] = "N";
|
|
1517
|
-
KeyCode["O"] = "O";
|
|
1518
|
-
KeyCode["P"] = "P";
|
|
1519
|
-
KeyCode["Q"] = "Q";
|
|
1520
|
-
KeyCode["R"] = "R";
|
|
1521
|
-
KeyCode["S"] = "S";
|
|
1522
|
-
KeyCode["T"] = "T";
|
|
1523
|
-
KeyCode["U"] = "U";
|
|
1524
|
-
KeyCode["V"] = "V";
|
|
1525
|
-
KeyCode["W"] = "W";
|
|
1526
|
-
KeyCode["X"] = "X";
|
|
1527
|
-
KeyCode["Y"] = "Y";
|
|
1528
|
-
KeyCode["Z"] = "Z";
|
|
1529
|
-
KeyCode["Meta"] = "Meta";
|
|
1530
|
-
KeyCode["LeftWindowKey"] = "Meta";
|
|
1531
|
-
KeyCode["RightWindowKey"] = "Meta";
|
|
1532
|
-
KeyCode["Numpad0"] = "0";
|
|
1533
|
-
KeyCode["Numpad1"] = "1";
|
|
1534
|
-
KeyCode["Numpad2"] = "2";
|
|
1535
|
-
KeyCode["Numpad3"] = "3";
|
|
1536
|
-
KeyCode["Numpad4"] = "4";
|
|
1537
|
-
KeyCode["Numpad5"] = "5";
|
|
1538
|
-
KeyCode["Numpad6"] = "6";
|
|
1539
|
-
KeyCode["Numpad7"] = "7";
|
|
1540
|
-
KeyCode["Numpad8"] = "8";
|
|
1541
|
-
KeyCode["Numpad9"] = "9";
|
|
1542
|
-
KeyCode["Multiply"] = "*";
|
|
1543
|
-
KeyCode["Add"] = "+";
|
|
1544
|
-
KeyCode["Subtract"] = "-";
|
|
1545
|
-
KeyCode["DecimalPoint"] = ".";
|
|
1546
|
-
KeyCode["MSDecimalPoint"] = "Decimal";
|
|
1547
|
-
KeyCode["Divide"] = "/";
|
|
1548
|
-
KeyCode["F1"] = "F1";
|
|
1549
|
-
KeyCode["F2"] = "F2";
|
|
1550
|
-
KeyCode["F3"] = "F3";
|
|
1551
|
-
KeyCode["F4"] = "F4";
|
|
1552
|
-
KeyCode["F5"] = "F5";
|
|
1553
|
-
KeyCode["F6"] = "F6";
|
|
1554
|
-
KeyCode["F7"] = "F7";
|
|
1555
|
-
KeyCode["F8"] = "F8";
|
|
1556
|
-
KeyCode["F9"] = "F9";
|
|
1557
|
-
KeyCode["F10"] = "F10";
|
|
1558
|
-
KeyCode["F11"] = "F11";
|
|
1559
|
-
KeyCode["F12"] = "F12";
|
|
1560
|
-
KeyCode["NumLock"] = "NumLock";
|
|
1561
|
-
KeyCode["ScrollLock"] = "ScrollLock";
|
|
1562
|
-
KeyCode["SemiColon"] = ";";
|
|
1563
|
-
KeyCode["Equals"] = "=";
|
|
1564
|
-
KeyCode["Comma"] = ",";
|
|
1565
|
-
KeyCode["Dash"] = "-";
|
|
1566
|
-
KeyCode["Period"] = ".";
|
|
1567
|
-
KeyCode["UnderScore"] = "_";
|
|
1568
|
-
KeyCode["PlusSign"] = "+";
|
|
1569
|
-
KeyCode["ForwardSlash"] = "/";
|
|
1570
|
-
KeyCode["Tilde"] = "~";
|
|
1571
|
-
KeyCode["GraveAccent"] = "`";
|
|
1572
|
-
KeyCode["OpenBracket"] = "[";
|
|
1573
|
-
KeyCode["ClosedBracket"] = "]";
|
|
1574
|
-
KeyCode["Quote"] = "'";
|
|
1575
|
-
})(exports.KeyCode || (exports.KeyCode = {}));
|
|
1576
|
-
const getKeyCodeFromEvent = (event) => {
|
|
1577
|
-
return event.key;
|
|
1578
|
-
};
|
|
1579
|
-
|
|
1580
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
1581
|
-
|
|
1582
|
-
function createCommonjsModule(fn) {
|
|
1583
|
-
var module = { exports: {} };
|
|
1584
|
-
return fn(module, module.exports), module.exports;
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
createCommonjsModule(function (module) {
|
|
1588
|
-
(function (factory) {
|
|
1589
|
-
if (module.exports) {
|
|
1590
|
-
module.exports = factory();
|
|
1591
|
-
} else {
|
|
1592
|
-
window.idleCallbackShim = factory();
|
|
1593
|
-
}
|
|
1594
|
-
}(function(){
|
|
1595
|
-
var scheduleStart, throttleDelay, lazytimer, lazyraf;
|
|
1596
|
-
var root = typeof window != 'undefined' ?
|
|
1597
|
-
window :
|
|
1598
|
-
typeof commonjsGlobal != undefined ?
|
|
1599
|
-
commonjsGlobal :
|
|
1600
|
-
this || {};
|
|
1601
|
-
var requestAnimationFrame = root.cancelRequestAnimationFrame && root.requestAnimationFrame || setTimeout;
|
|
1602
|
-
var cancelRequestAnimationFrame = root.cancelRequestAnimationFrame || clearTimeout;
|
|
1603
|
-
var tasks = [];
|
|
1604
|
-
var runAttempts = 0;
|
|
1605
|
-
var isRunning = false;
|
|
1606
|
-
var remainingTime = 7;
|
|
1607
|
-
var minThrottle = 35;
|
|
1608
|
-
var throttle = 125;
|
|
1609
|
-
var index = 0;
|
|
1610
|
-
var taskStart = 0;
|
|
1611
|
-
var tasklength = 0;
|
|
1612
|
-
var IdleDeadline = {
|
|
1613
|
-
get didTimeout(){
|
|
1614
|
-
return false;
|
|
1615
|
-
},
|
|
1616
|
-
timeRemaining: function(){
|
|
1617
|
-
var timeRemaining = remainingTime - (Date.now() - taskStart);
|
|
1618
|
-
return timeRemaining < 0 ? 0 : timeRemaining;
|
|
1619
|
-
},
|
|
1620
|
-
};
|
|
1621
|
-
var setInactive = debounce(function(){
|
|
1622
|
-
remainingTime = 22;
|
|
1623
|
-
throttle = 66;
|
|
1624
|
-
minThrottle = 0;
|
|
1625
|
-
});
|
|
1626
|
-
|
|
1627
|
-
function debounce(fn){
|
|
1628
|
-
var id, timestamp;
|
|
1629
|
-
var wait = 99;
|
|
1630
|
-
var check = function(){
|
|
1631
|
-
var last = (Date.now()) - timestamp;
|
|
1632
|
-
|
|
1633
|
-
if (last < wait) {
|
|
1634
|
-
id = setTimeout(check, wait - last);
|
|
1635
|
-
} else {
|
|
1636
|
-
id = null;
|
|
1637
|
-
fn();
|
|
1638
|
-
}
|
|
1639
|
-
};
|
|
1640
|
-
return function(){
|
|
1641
|
-
timestamp = Date.now();
|
|
1642
|
-
if(!id){
|
|
1643
|
-
id = setTimeout(check, wait);
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
function abortRunning(){
|
|
1649
|
-
if(isRunning){
|
|
1650
|
-
if(lazyraf){
|
|
1651
|
-
cancelRequestAnimationFrame(lazyraf);
|
|
1652
|
-
}
|
|
1653
|
-
if(lazytimer){
|
|
1654
|
-
clearTimeout(lazytimer);
|
|
1655
|
-
}
|
|
1656
|
-
isRunning = false;
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
function onInputorMutation(){
|
|
1661
|
-
if(throttle != 125){
|
|
1662
|
-
remainingTime = 7;
|
|
1663
|
-
throttle = 125;
|
|
1664
|
-
minThrottle = 35;
|
|
1665
|
-
|
|
1666
|
-
if(isRunning) {
|
|
1667
|
-
abortRunning();
|
|
1668
|
-
scheduleLazy();
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
setInactive();
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
function scheduleAfterRaf() {
|
|
1675
|
-
lazyraf = null;
|
|
1676
|
-
lazytimer = setTimeout(runTasks, 0);
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
function scheduleRaf(){
|
|
1680
|
-
lazytimer = null;
|
|
1681
|
-
requestAnimationFrame(scheduleAfterRaf);
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
function scheduleLazy(){
|
|
1685
|
-
|
|
1686
|
-
if(isRunning){return;}
|
|
1687
|
-
throttleDelay = throttle - (Date.now() - taskStart);
|
|
1688
|
-
|
|
1689
|
-
scheduleStart = Date.now();
|
|
1690
|
-
|
|
1691
|
-
isRunning = true;
|
|
1692
|
-
|
|
1693
|
-
if(minThrottle && throttleDelay < minThrottle){
|
|
1694
|
-
throttleDelay = minThrottle;
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
if(throttleDelay > 9){
|
|
1698
|
-
lazytimer = setTimeout(scheduleRaf, throttleDelay);
|
|
1699
|
-
} else {
|
|
1700
|
-
throttleDelay = 0;
|
|
1701
|
-
scheduleRaf();
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
function runTasks(){
|
|
1706
|
-
var task, i, len;
|
|
1707
|
-
var timeThreshold = remainingTime > 9 ?
|
|
1708
|
-
9 :
|
|
1709
|
-
1
|
|
1710
|
-
;
|
|
1711
|
-
|
|
1712
|
-
taskStart = Date.now();
|
|
1713
|
-
isRunning = false;
|
|
1714
|
-
|
|
1715
|
-
lazytimer = null;
|
|
1716
|
-
|
|
1717
|
-
if(runAttempts > 2 || taskStart - throttleDelay - 50 < scheduleStart){
|
|
1718
|
-
for(i = 0, len = tasks.length; i < len && IdleDeadline.timeRemaining() > timeThreshold; i++){
|
|
1719
|
-
task = tasks.shift();
|
|
1720
|
-
tasklength++;
|
|
1721
|
-
if(task){
|
|
1722
|
-
task(IdleDeadline);
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
if(tasks.length){
|
|
1728
|
-
scheduleLazy();
|
|
1729
|
-
} else {
|
|
1730
|
-
runAttempts = 0;
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
function requestIdleCallbackShim(task){
|
|
1735
|
-
index++;
|
|
1736
|
-
tasks.push(task);
|
|
1737
|
-
scheduleLazy();
|
|
1738
|
-
return index;
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
function cancelIdleCallbackShim(id){
|
|
1742
|
-
var index = id - 1 - tasklength;
|
|
1743
|
-
if(tasks[index]){
|
|
1744
|
-
tasks[index] = null;
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
if(!root.requestIdleCallback || !root.cancelIdleCallback){
|
|
1749
|
-
root.requestIdleCallback = requestIdleCallbackShim;
|
|
1750
|
-
root.cancelIdleCallback = cancelIdleCallbackShim;
|
|
1751
|
-
|
|
1752
|
-
if(root.document && document.addEventListener){
|
|
1753
|
-
root.addEventListener('scroll', onInputorMutation, true);
|
|
1754
|
-
root.addEventListener('resize', onInputorMutation);
|
|
1755
|
-
|
|
1756
|
-
document.addEventListener('focus', onInputorMutation, true);
|
|
1757
|
-
document.addEventListener('mouseover', onInputorMutation, true);
|
|
1758
|
-
['click', 'keypress', 'touchstart', 'mousedown'].forEach(function(name){
|
|
1759
|
-
document.addEventListener(name, onInputorMutation, {capture: true, passive: true});
|
|
1760
|
-
});
|
|
1761
|
-
|
|
1762
|
-
if(root.MutationObserver){
|
|
1763
|
-
new MutationObserver( onInputorMutation ).observe( document.documentElement, {childList: true, subtree: true, attributes: true} );
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
} else {
|
|
1767
|
-
try{
|
|
1768
|
-
root.requestIdleCallback(function(){}, {timeout: 0});
|
|
1769
|
-
} catch(e){
|
|
1770
|
-
(function(rIC){
|
|
1771
|
-
var timeRemainingProto, timeRemaining;
|
|
1772
|
-
root.requestIdleCallback = function(fn, timeout){
|
|
1773
|
-
if(timeout && typeof timeout.timeout == 'number'){
|
|
1774
|
-
return rIC(fn, timeout.timeout);
|
|
1775
|
-
}
|
|
1776
|
-
return rIC(fn);
|
|
1777
|
-
};
|
|
1778
|
-
if(root.IdleCallbackDeadline && (timeRemainingProto = IdleCallbackDeadline.prototype)){
|
|
1779
|
-
timeRemaining = Object.getOwnPropertyDescriptor(timeRemainingProto, 'timeRemaining');
|
|
1780
|
-
if(!timeRemaining || !timeRemaining.configurable || !timeRemaining.get){return;}
|
|
1781
|
-
Object.defineProperty(timeRemainingProto, 'timeRemaining', {
|
|
1782
|
-
value: function(){
|
|
1783
|
-
return timeRemaining.get.call(this);
|
|
1784
|
-
},
|
|
1785
|
-
enumerable: true,
|
|
1786
|
-
configurable: true,
|
|
1787
|
-
});
|
|
1788
|
-
}
|
|
1789
|
-
})(root.requestIdleCallback);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
return {
|
|
1794
|
-
request: requestIdleCallbackShim,
|
|
1795
|
-
cancel: cancelIdleCallbackShim,
|
|
1796
|
-
};
|
|
1797
|
-
}));
|
|
1798
|
-
});
|
|
1799
|
-
|
|
1800
|
-
const requestIdle = (callback, options) => {
|
|
1801
|
-
return globalThisPolyfill['requestIdleCallback'](callback, options);
|
|
1802
|
-
};
|
|
1803
|
-
const cancelIdle = (id) => {
|
|
1804
|
-
globalThisPolyfill['cancelIdleCallback'](id);
|
|
1805
|
-
};
|
|
1806
|
-
|
|
1807
|
-
const InlineLayoutTagNames = new Set([
|
|
1808
|
-
'A',
|
|
1809
|
-
'ABBR',
|
|
1810
|
-
'ACRONYM',
|
|
1811
|
-
'AUDIO',
|
|
1812
|
-
'B',
|
|
1813
|
-
'BDI',
|
|
1814
|
-
'BDO',
|
|
1815
|
-
'BIG',
|
|
1816
|
-
'BR',
|
|
1817
|
-
'BUTTON',
|
|
1818
|
-
'CANVAS',
|
|
1819
|
-
'CITE',
|
|
1820
|
-
'CODE',
|
|
1821
|
-
'DATA',
|
|
1822
|
-
'DATALIST',
|
|
1823
|
-
'DEL',
|
|
1824
|
-
'DFN',
|
|
1825
|
-
'EM',
|
|
1826
|
-
'EMBED',
|
|
1827
|
-
'I',
|
|
1828
|
-
'IFRAME',
|
|
1829
|
-
'IMG',
|
|
1830
|
-
'INS',
|
|
1831
|
-
'KBD',
|
|
1832
|
-
'LABEL',
|
|
1833
|
-
'MAP',
|
|
1834
|
-
'MARK',
|
|
1835
|
-
'METER',
|
|
1836
|
-
'NOSCRIPT',
|
|
1837
|
-
'OBJECT',
|
|
1838
|
-
'OUTPUT',
|
|
1839
|
-
'PICTURE',
|
|
1840
|
-
'PROGRESS',
|
|
1841
|
-
'Q',
|
|
1842
|
-
'RUBY',
|
|
1843
|
-
'S',
|
|
1844
|
-
'SAMP',
|
|
1845
|
-
'SELECT',
|
|
1846
|
-
'SLOT',
|
|
1847
|
-
'SMALL',
|
|
1848
|
-
'STRONG',
|
|
1849
|
-
'SUB',
|
|
1850
|
-
'SUP',
|
|
1851
|
-
'SVG',
|
|
1852
|
-
'TEMPLATE',
|
|
1853
|
-
'TEXTAREA',
|
|
1854
|
-
'TIME',
|
|
1855
|
-
'U',
|
|
1856
|
-
'TT',
|
|
1857
|
-
'VAR',
|
|
1858
|
-
'VIDEO',
|
|
1859
|
-
'WBR',
|
|
1860
|
-
'INPUT',
|
|
1861
|
-
'SPAN',
|
|
1862
|
-
]);
|
|
1863
|
-
const calcElementOuterWidth = (innerWidth, style) => {
|
|
1864
|
-
return (innerWidth +
|
|
1865
|
-
parseFloat(style.marginLeft) +
|
|
1866
|
-
parseFloat(style.marginRight) +
|
|
1867
|
-
parseFloat(style.paddingLeft) +
|
|
1868
|
-
parseFloat(style.paddingRight) +
|
|
1869
|
-
parseFloat(style.borderLeftWidth) +
|
|
1870
|
-
parseFloat(style.borderRightWidth));
|
|
1871
|
-
};
|
|
1872
|
-
const calcElementLayout = (element) => {
|
|
1873
|
-
if (!element)
|
|
1874
|
-
return 'vertical';
|
|
1875
|
-
const parent = element.parentElement;
|
|
1876
|
-
if (!parent)
|
|
1877
|
-
return 'vertical';
|
|
1878
|
-
const tagName = element.tagName;
|
|
1879
|
-
const parentTagName = parent.tagName;
|
|
1880
|
-
const style = getComputedStyle(element);
|
|
1881
|
-
const parentStyle = getComputedStyle(parent);
|
|
1882
|
-
const isNotFullWidth = () => {
|
|
1883
|
-
const innerWidth = element.getBoundingClientRect().width;
|
|
1884
|
-
const outerWidth = calcElementOuterWidth(innerWidth, style);
|
|
1885
|
-
const parentInnerWidth = parent.getBoundingClientRect().width;
|
|
1886
|
-
return outerWidth.toFixed(0) < parentInnerWidth.toFixed(0);
|
|
1887
|
-
};
|
|
1888
|
-
if (tagName === 'TH' || tagName === 'TD') {
|
|
1889
|
-
if (parentTagName === 'TR')
|
|
1890
|
-
return 'horizontal';
|
|
1891
|
-
}
|
|
1892
|
-
if (parentStyle.display === 'flex' && parentStyle.flexDirection === 'row')
|
|
1893
|
-
return 'horizontal';
|
|
1894
|
-
if (parentStyle.display === 'grid') {
|
|
1895
|
-
if (isNotFullWidth()) {
|
|
1896
|
-
return 'horizontal';
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
if (InlineLayoutTagNames.has(tagName)) {
|
|
1900
|
-
if (style.display === 'block') {
|
|
1901
|
-
if (style.float === 'left' || style.float === 'right') {
|
|
1902
|
-
if (isNotFullWidth()) {
|
|
1903
|
-
return 'horizontal';
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
return 'vertical';
|
|
1907
|
-
}
|
|
1908
|
-
return 'horizontal';
|
|
1909
|
-
}
|
|
1910
|
-
};
|
|
1911
|
-
const calcElementTranslate = (element) => {
|
|
1912
|
-
var _a, _b, _c;
|
|
1913
|
-
const transform = (_a = element === null || element === void 0 ? void 0 : element.style) === null || _a === void 0 ? void 0 : _a.transform;
|
|
1914
|
-
if (transform) {
|
|
1915
|
-
const [x, y] = (_c = (_b = transform
|
|
1916
|
-
.match(/translate(?:3d)?\(\s*([-\d.]+)[a-z]+?[\s,]+([-\d.]+)[a-z]+?(?:[\s,]+([-\d.]+))?[a-z]+?\s*\)/)) === null || _b === void 0 ? void 0 : _b.slice(1, 3)) !== null && _c !== void 0 ? _c : [0, 0];
|
|
1917
|
-
return new Point(Number(x), Number(y));
|
|
1918
|
-
}
|
|
1919
|
-
else {
|
|
1920
|
-
return new Point(Number(element.offsetLeft), Number(element.offsetTop));
|
|
1921
|
-
}
|
|
1922
|
-
};
|
|
1923
|
-
const calcElementRotate = (element) => {
|
|
1924
|
-
var _a, _b, _c;
|
|
1925
|
-
const transform = (_a = element === null || element === void 0 ? void 0 : element.style) === null || _a === void 0 ? void 0 : _a.transform;
|
|
1926
|
-
if (transform) {
|
|
1927
|
-
return Number((_c = (_b = transform.match(/rotate\(\s*([-\d.]+)/)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : 0);
|
|
1928
|
-
}
|
|
1929
|
-
else {
|
|
1930
|
-
return 0;
|
|
1931
|
-
}
|
|
1932
|
-
};
|
|
1933
|
-
const calcElementScale = (element) => {
|
|
1934
|
-
var _a, _b, _c;
|
|
1935
|
-
const transform = (_a = element === null || element === void 0 ? void 0 : element.style) === null || _a === void 0 ? void 0 : _a.transform;
|
|
1936
|
-
if (transform) {
|
|
1937
|
-
return Number((_c = (_b = transform.match(/scale\(\s*([-\d.]+)/)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : 0);
|
|
1938
|
-
}
|
|
1939
|
-
else {
|
|
1940
|
-
return 0;
|
|
1941
|
-
}
|
|
1942
|
-
};
|
|
1943
|
-
|
|
1944
|
-
class LayoutObserver {
|
|
1945
|
-
constructor(observer = () => { }) {
|
|
1946
|
-
this.connected = false;
|
|
1947
|
-
this.observe = (target) => {
|
|
1948
|
-
this.resizeObserver.observe(target);
|
|
1949
|
-
this.performanceObserver.observe({
|
|
1950
|
-
entryTypes: ['paint', 'element', 'layout-shift', 'event'],
|
|
1951
|
-
});
|
|
1952
|
-
this.mutationObserver.observe(target, {
|
|
1953
|
-
attributeFilter: ['style'],
|
|
1954
|
-
attributes: true,
|
|
1955
|
-
});
|
|
1956
|
-
this.connected = true;
|
|
1957
|
-
};
|
|
1958
|
-
this.disconnect = () => {
|
|
1959
|
-
if (this.connected) {
|
|
1960
|
-
this.resizeObserver.disconnect();
|
|
1961
|
-
this.performanceObserver.disconnect();
|
|
1962
|
-
this.mutationObserver.disconnect();
|
|
1963
|
-
}
|
|
1964
|
-
this.connected = false;
|
|
1965
|
-
};
|
|
1966
|
-
this.resizeObserver = new ResizeObserver(() => observer());
|
|
1967
|
-
this.performanceObserver = new PerformanceObserver(() => {
|
|
1968
|
-
observer();
|
|
1969
|
-
});
|
|
1970
|
-
this.mutationObserver = new MutationObserver(() => observer());
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
exports.Event = Event;
|
|
1975
|
-
exports.EventDriver = EventDriver;
|
|
1976
|
-
exports.LRUMap = LRUMap;
|
|
1977
|
-
exports.LayoutObserver = LayoutObserver;
|
|
1978
|
-
exports.LineSegment = LineSegment;
|
|
1979
|
-
exports.Point = Point;
|
|
1980
|
-
exports.Rect = Rect;
|
|
1981
|
-
exports.Subscribable = Subscribable;
|
|
1982
|
-
exports.calcAutoScrollBasicInfo = calcAutoScrollBasicInfo;
|
|
1983
|
-
exports.calcBoundingRect = calcBoundingRect;
|
|
1984
|
-
exports.calcClosestEdges = calcClosestEdges;
|
|
1985
|
-
exports.calcCombineSnapLineSegment = calcCombineSnapLineSegment;
|
|
1986
|
-
exports.calcDistanceOfPointToRect = calcDistanceOfPointToRect;
|
|
1987
|
-
exports.calcDistanceOfSnapLineToEdges = calcDistanceOfSnapLineToEdges;
|
|
1988
|
-
exports.calcDistancePointToEdge = calcDistancePointToEdge;
|
|
1989
|
-
exports.calcEdgeLinesOfRect = calcEdgeLinesOfRect;
|
|
1990
|
-
exports.calcElementLayout = calcElementLayout;
|
|
1991
|
-
exports.calcElementOuterWidth = calcElementOuterWidth;
|
|
1992
|
-
exports.calcElementRotate = calcElementRotate;
|
|
1993
|
-
exports.calcElementScale = calcElementScale;
|
|
1994
|
-
exports.calcElementTranslate = calcElementTranslate;
|
|
1995
|
-
exports.calcExtendsLineSegmentOfRect = calcExtendsLineSegmentOfRect;
|
|
1996
|
-
exports.calcOffsetOfSnapLineSegmentToEdge = calcOffsetOfSnapLineSegmentToEdge;
|
|
1997
|
-
exports.calcQuadrantOfPointToRect = calcQuadrantOfPointToRect;
|
|
1998
|
-
exports.calcRectByStartEndPoint = calcRectByStartEndPoint;
|
|
1999
|
-
exports.calcRectOfAxisLineSegment = calcRectOfAxisLineSegment;
|
|
2000
|
-
exports.calcRelativeOfPointToRect = calcRelativeOfPointToRect;
|
|
2001
|
-
exports.calcSpaceBlockOfRect = calcSpaceBlockOfRect;
|
|
2002
|
-
exports.calcSpeedFactor = calcSpeedFactor;
|
|
2003
|
-
exports.cancelIdle = cancelIdle;
|
|
2004
|
-
exports.clone = clone;
|
|
2005
|
-
exports.compose = compose;
|
|
2006
|
-
exports.createUniformSpeedAnimation = createUniformSpeedAnimation;
|
|
2007
|
-
exports.each = each;
|
|
2008
|
-
exports.every = every;
|
|
2009
|
-
exports.find = find;
|
|
2010
|
-
exports.findIndex = findIndex;
|
|
2011
|
-
exports.flat = flat;
|
|
2012
|
-
exports.getKeyCodeFromEvent = getKeyCodeFromEvent;
|
|
2013
|
-
exports.getRectPoints = getRectPoints;
|
|
2014
|
-
exports.getType = getType;
|
|
2015
|
-
exports.globalThisPolyfill = globalThisPolyfill;
|
|
2016
|
-
exports.includes = includes;
|
|
2017
|
-
exports.includesWith = includesWith;
|
|
2018
|
-
exports.instOf = instOf;
|
|
2019
|
-
exports.isArr = isArr;
|
|
2020
|
-
exports.isBool = isBool;
|
|
2021
|
-
exports.isCrossRectInRect = isCrossRectInRect;
|
|
2022
|
-
exports.isEqualRect = isEqualRect;
|
|
2023
|
-
exports.isFn = isFn;
|
|
2024
|
-
exports.isHTMLElement = isHTMLElement;
|
|
2025
|
-
exports.isLineSegment = isLineSegment;
|
|
2026
|
-
exports.isNearAfter = isNearAfter;
|
|
2027
|
-
exports.isNum = isNum;
|
|
2028
|
-
exports.isObj = isObj;
|
|
2029
|
-
exports.isPlainObj = isPlainObj;
|
|
2030
|
-
exports.isPoint = isPoint;
|
|
2031
|
-
exports.isPointInRect = isPointInRect;
|
|
2032
|
-
exports.isRect = isRect;
|
|
2033
|
-
exports.isRectInRect = isRectInRect;
|
|
2034
|
-
exports.isRegExp = isRegExp;
|
|
2035
|
-
exports.isStr = isStr;
|
|
2036
|
-
exports.isValid = isValid;
|
|
2037
|
-
exports.isValidNumber = isValidNumber;
|
|
2038
|
-
exports.isWindow = isWindow;
|
|
2039
|
-
exports.map = map;
|
|
2040
|
-
exports.reduce = reduce;
|
|
2041
|
-
exports.requestIdle = requestIdle;
|
|
2042
|
-
exports.scrollAnimate = scrollAnimate;
|
|
2043
|
-
exports.shallowClone = shallowClone;
|
|
2044
|
-
exports.some = some;
|
|
2045
|
-
exports.toArr = toArr;
|
|
2046
|
-
exports.uid = uid;
|
|
2047
|
-
exports.updateScrollValue = updateScrollValue;
|
|
2048
|
-
|
|
2049
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2050
|
-
|
|
2051
|
-
}));
|