@formily-design/shared 1.0.5 → 1.0.6

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/esm/array.d.ts CHANGED
@@ -33,5 +33,5 @@ export declare function includes<T extends string>(val: T, searchElement: string
33
33
  export declare function includes<T>(val: T[], searchElement: T, revert?: boolean): boolean;
34
34
  export declare function includesWith<T extends string>(val: T, search: (item: string) => boolean): boolean;
35
35
  export declare function includesWith<T>(val: T[], search: (item: T) => boolean): boolean;
36
- export declare const flat: <T>(array: Array<T | T[]>) => T[];
36
+ export declare const flat: <T>(array: (T | T[])[]) => T[];
37
37
  export {};
package/esm/scroller.d.ts CHANGED
@@ -5,6 +5,6 @@ export interface IAutoScrollBasicInfo {
5
5
  speedFactor: number;
6
6
  speed: number;
7
7
  }
8
- export declare const calcAutoScrollBasicInfo: (point: IPoint, axis: "x" | "y", viewport: DOMRect, maxSpeed?: number) => IAutoScrollBasicInfo | null;
9
- export declare const updateScrollValue: (element: HTMLElement | Window, axis: "x" | "y", value: number, callback?: (scrollValue: number) => void) => void;
10
- export declare const scrollAnimate: (element: HTMLElement | Window, axis: "x" | "y", direction: "begin" | "end", speed: number, callback?: (scrollValue: number) => void) => () => void;
8
+ export declare const calcAutoScrollBasicInfo: (point: IPoint, axis: 'x' | 'y', viewport: DOMRect, maxSpeed?: number) => IAutoScrollBasicInfo | null;
9
+ export declare const updateScrollValue: (element: HTMLElement | Window, axis: 'x' | 'y', value: number, callback?: (scrollValue: number) => void) => void;
10
+ export declare const scrollAnimate: (element: HTMLElement | Window, axis: 'x' | 'y', direction: 'begin' | 'end', speed: number, callback?: (scrollValue: number) => void) => () => void;
package/lib/array.d.ts CHANGED
@@ -33,5 +33,5 @@ export declare function includes<T extends string>(val: T, searchElement: string
33
33
  export declare function includes<T>(val: T[], searchElement: T, revert?: boolean): boolean;
34
34
  export declare function includesWith<T extends string>(val: T, search: (item: string) => boolean): boolean;
35
35
  export declare function includesWith<T>(val: T[], search: (item: T) => boolean): boolean;
36
- export declare const flat: <T>(array: Array<T | T[]>) => T[];
36
+ export declare const flat: <T>(array: (T | T[])[]) => T[];
37
37
  export {};
package/lib/array.js CHANGED
@@ -1,15 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flat = exports.toArr = void 0;
4
- exports.each = each;
5
- exports.map = map;
6
- exports.reduce = reduce;
7
- exports.every = every;
8
- exports.some = some;
9
- exports.findIndex = findIndex;
10
- exports.find = find;
11
- exports.includes = includes;
12
- exports.includesWith = includesWith;
3
+ exports.flat = exports.includesWith = exports.includes = exports.find = exports.findIndex = exports.some = exports.every = exports.reduce = exports.map = exports.each = exports.toArr = void 0;
13
4
  const types_1 = require("./types");
14
5
  const toArr = (val) => ((0, types_1.isArr)(val) ? val : val ? [val] : []);
15
6
  exports.toArr = toArr;
@@ -41,6 +32,7 @@ function each(val, iterator, revert) {
41
32
  }
42
33
  }
43
34
  }
35
+ exports.each = each;
44
36
  function map(val, iterator, revert) {
45
37
  const res = (0, types_1.isArr)(val) || (0, types_1.isStr)(val) ? [] : {};
46
38
  each(val, (item, key) => {
@@ -55,6 +47,7 @@ function map(val, iterator, revert) {
55
47
  }, revert);
56
48
  return res;
57
49
  }
50
+ exports.map = map;
58
51
  function reduce(val, iterator, accumulator, revert) {
59
52
  let result = accumulator;
60
53
  each(val, (item, key) => {
@@ -62,6 +55,7 @@ function reduce(val, iterator, accumulator, revert) {
62
55
  }, revert);
63
56
  return result;
64
57
  }
58
+ exports.reduce = reduce;
65
59
  function every(val, iterator, revert) {
66
60
  let res = true;
67
61
  each(val, (item, key) => {
@@ -72,6 +66,7 @@ function every(val, iterator, revert) {
72
66
  }, revert);
73
67
  return res;
74
68
  }
69
+ exports.every = every;
75
70
  function some(val, iterator, revert) {
76
71
  let res = false;
77
72
  each(val, (item, key) => {
@@ -82,6 +77,7 @@ function some(val, iterator, revert) {
82
77
  }, revert);
83
78
  return res;
84
79
  }
80
+ exports.some = some;
85
81
  function findIndex(val, iterator, revert) {
86
82
  let res = -1;
87
83
  each(val, (item, key) => {
@@ -92,6 +88,7 @@ function findIndex(val, iterator, revert) {
92
88
  }, revert);
93
89
  return res;
94
90
  }
91
+ exports.findIndex = findIndex;
95
92
  function find(val, iterator, revert) {
96
93
  let res;
97
94
  each(val, (item, key) => {
@@ -102,11 +99,13 @@ function find(val, iterator, revert) {
102
99
  }, revert);
103
100
  return res;
104
101
  }
102
+ exports.find = find;
105
103
  function includes(val, searchElement, revert) {
106
104
  if ((0, types_1.isStr)(val))
107
105
  return val.includes(searchElement);
108
106
  return some(val, (item) => item === searchElement, revert);
109
107
  }
108
+ exports.includes = includes;
110
109
  function includesWith(val, search) {
111
110
  if ((0, types_1.isArr)(val)) {
112
111
  return val.some((item) => search(item));
@@ -115,6 +114,7 @@ function includesWith(val, search) {
115
114
  return false;
116
115
  }
117
116
  }
117
+ exports.includesWith = includesWith;
118
118
  const flat = (array) => {
119
119
  return (0, exports.toArr)(array).reduce((buf, item) => {
120
120
  if ((0, types_1.isArr)(item))
package/lib/coordinate.js CHANGED
@@ -1,39 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RectQuadrant = exports.LineSegment = exports.Rect = exports.Point = void 0;
4
- exports.isRect = isRect;
5
- exports.isPoint = isPoint;
6
- exports.isLineSegment = isLineSegment;
7
- exports.isPointInRect = isPointInRect;
8
- exports.isEqualRect = isEqualRect;
9
- exports.getRectPoints = getRectPoints;
10
- exports.isRectInRect = isRectInRect;
11
- exports.isCrossRectInRect = isCrossRectInRect;
12
- exports.calcQuadrantOfPointToRect = calcQuadrantOfPointToRect;
13
- exports.calcDistanceOfPointToRect = calcDistanceOfPointToRect;
14
- exports.calcDistancePointToEdge = calcDistancePointToEdge;
15
- exports.isNearAfter = isNearAfter;
16
- exports.calcRelativeOfPointToRect = calcRelativeOfPointToRect;
17
- exports.calcBoundingRect = calcBoundingRect;
18
- exports.calcRectByStartEndPoint = calcRectByStartEndPoint;
19
- exports.calcEdgeLinesOfRect = calcEdgeLinesOfRect;
20
- exports.calcRectOfAxisLineSegment = calcRectOfAxisLineSegment;
21
- exports.calcSpaceBlockOfRect = calcSpaceBlockOfRect;
22
- exports.calcExtendsLineSegmentOfRect = calcExtendsLineSegmentOfRect;
23
- exports.calcOffsetOfSnapLineSegmentToEdge = calcOffsetOfSnapLineSegmentToEdge;
24
- exports.calcDistanceOfSnapLineToEdges = calcDistanceOfSnapLineToEdges;
25
- exports.calcCombineSnapLineSegment = calcCombineSnapLineSegment;
26
- exports.calcClosestEdges = calcClosestEdges;
3
+ exports.calcClosestEdges = exports.calcCombineSnapLineSegment = exports.calcDistanceOfSnapLineToEdges = exports.calcOffsetOfSnapLineSegmentToEdge = exports.calcExtendsLineSegmentOfRect = exports.calcSpaceBlockOfRect = exports.calcRectOfAxisLineSegment = exports.calcEdgeLinesOfRect = exports.calcRectByStartEndPoint = exports.calcBoundingRect = exports.calcRelativeOfPointToRect = exports.isNearAfter = exports.calcDistancePointToEdge = exports.calcDistanceOfPointToRect = exports.calcQuadrantOfPointToRect = exports.isCrossRectInRect = exports.isRectInRect = exports.getRectPoints = exports.isEqualRect = exports.isPointInRect = exports.RectQuadrant = exports.LineSegment = exports.Rect = exports.Point = exports.isLineSegment = exports.isPoint = exports.isRect = void 0;
27
4
  const types_1 = require("./types");
28
5
  function isRect(rect) {
29
6
  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);
30
7
  }
8
+ exports.isRect = isRect;
31
9
  function isPoint(val) {
32
10
  return (0, types_1.isValidNumber)(val === null || val === void 0 ? void 0 : val.x) && (0, types_1.isValidNumber)(val === null || val === void 0 ? void 0 : val.y);
33
11
  }
12
+ exports.isPoint = isPoint;
34
13
  function isLineSegment(val) {
35
14
  return isPoint(val === null || val === void 0 ? void 0 : val.start) && isPoint(val === null || val === void 0 ? void 0 : val.end);
36
15
  }
16
+ exports.isLineSegment = isLineSegment;
37
17
  class Point {
38
18
  constructor(x, y) {
39
19
  this.x = x;
@@ -100,12 +80,14 @@ function isPointInRect(point, rect, sensitive = true) {
100
80
  point.y >= rect.y + boundSensor(rect.height) &&
101
81
  point.y <= rect.y + rect.height - boundSensor(rect.height));
102
82
  }
83
+ exports.isPointInRect = isPointInRect;
103
84
  function isEqualRect(target, source) {
104
85
  return ((target === null || target === void 0 ? void 0 : target.x) === (source === null || source === void 0 ? void 0 : source.x) &&
105
86
  target.y === source.y &&
106
87
  target.width === source.width &&
107
88
  target.height === source.height);
108
89
  }
90
+ exports.isEqualRect = isEqualRect;
109
91
  function getRectPoints(source) {
110
92
  const p1 = new Point(source.x, source.y);
111
93
  const p2 = new Point(source.x + source.width, source.y);
@@ -113,6 +95,7 @@ function getRectPoints(source) {
113
95
  const p4 = new Point(source.x, source.y + source.height);
114
96
  return [p1, p2, p3, p4];
115
97
  }
98
+ exports.getRectPoints = getRectPoints;
116
99
  function isRectInRect(target, source) {
117
100
  const [p1, p2, p3, p4] = getRectPoints(target);
118
101
  return (isPointInRect(p1, source, false) &&
@@ -120,6 +103,7 @@ function isRectInRect(target, source) {
120
103
  isPointInRect(p3, source, false) &&
121
104
  isPointInRect(p4, source, false));
122
105
  }
106
+ exports.isRectInRect = isRectInRect;
123
107
  function isCrossRectInRect(target, source) {
124
108
  const targetCenterPoint = new Point(target.x + target.width / 2, target.y + target.height / 2);
125
109
  const sourceCenterPoint = new Point(source.x + source.width / 2, source.y + source.height / 2);
@@ -128,6 +112,7 @@ function isCrossRectInRect(target, source) {
128
112
  Math.abs(targetCenterPoint.y - sourceCenterPoint.y) <=
129
113
  target.height / 2 + source.height / 2);
130
114
  }
115
+ exports.isCrossRectInRect = isCrossRectInRect;
131
116
  /**
132
117
  * 计算点在矩形的哪个象限
133
118
  * @param point
@@ -172,6 +157,7 @@ function calcQuadrantOfPointToRect(point, rect) {
172
157
  }
173
158
  }
174
159
  }
160
+ exports.calcQuadrantOfPointToRect = calcQuadrantOfPointToRect;
175
161
  function calcDistanceOfPointToRect(point, rect) {
176
162
  let minX = Math.min(Math.abs(point.x - rect.x), Math.abs(point.x - (rect.x + rect.width)));
177
163
  let minY = Math.min(Math.abs(point.y - rect.y), Math.abs(point.y - (rect.y + rect.height)));
@@ -183,6 +169,7 @@ function calcDistanceOfPointToRect(point, rect) {
183
169
  }
184
170
  return Math.sqrt(minX ** 2 + minY ** 2);
185
171
  }
172
+ exports.calcDistanceOfPointToRect = calcDistanceOfPointToRect;
186
173
  function calcDistancePointToEdge(point, rect) {
187
174
  const distanceTop = Math.abs(point.y - rect.y);
188
175
  const distanceBottom = Math.abs(point.y - (rect.y + rect.height));
@@ -190,6 +177,7 @@ function calcDistancePointToEdge(point, rect) {
190
177
  const distanceRight = Math.abs(point.x - (rect.x + rect.width));
191
178
  return Math.min(distanceTop, distanceBottom, distanceLeft, distanceRight);
192
179
  }
180
+ exports.calcDistancePointToEdge = calcDistancePointToEdge;
193
181
  function isNearAfter(point, rect, inline = false) {
194
182
  if (inline) {
195
183
  return (Math.abs(point.x - rect.x) + Math.abs(point.y - rect.y) >
@@ -198,6 +186,7 @@ function isNearAfter(point, rect, inline = false) {
198
186
  }
199
187
  return Math.abs(point.y - rect.y) > Math.abs(point.y - (rect.y + rect.height));
200
188
  }
189
+ exports.isNearAfter = isNearAfter;
201
190
  /**
202
191
  * 计算点鱼矩形的相对位置信息
203
192
  * @param point
@@ -211,6 +200,7 @@ function calcRelativeOfPointToRect(point, rect) {
211
200
  distance,
212
201
  };
213
202
  }
203
+ exports.calcRelativeOfPointToRect = calcRelativeOfPointToRect;
214
204
  function calcBoundingRect(rects) {
215
205
  if (!(rects === null || rects === void 0 ? void 0 : rects.length))
216
206
  return;
@@ -237,6 +227,7 @@ function calcBoundingRect(rects) {
237
227
  });
238
228
  return new Rect(minLeft, minTop, maxRight - minLeft, maxBottom - minTop);
239
229
  }
230
+ exports.calcBoundingRect = calcBoundingRect;
240
231
  function calcRectByStartEndPoint(startPoint, endPoint, scrollX = 0, scrollY = 0) {
241
232
  let drawStartX = 0, drawStartY = 0;
242
233
  if (endPoint.x + scrollX >= startPoint.x &&
@@ -267,6 +258,7 @@ function calcRectByStartEndPoint(startPoint, endPoint, scrollX = 0, scrollY = 0)
267
258
  return new Rect(drawStartX, drawStartY, Math.abs(endPoint.x - startPoint.x + scrollX), Math.abs(endPoint.y - startPoint.y + scrollY));
268
259
  }
269
260
  }
261
+ exports.calcRectByStartEndPoint = calcRectByStartEndPoint;
270
262
  function calcEdgeLinesOfRect(rect) {
271
263
  return {
272
264
  v: [
@@ -281,12 +273,14 @@ function calcEdgeLinesOfRect(rect) {
281
273
  ],
282
274
  };
283
275
  }
276
+ exports.calcEdgeLinesOfRect = calcEdgeLinesOfRect;
284
277
  function calcRectOfAxisLineSegment(line) {
285
278
  if (!isLineSegment(line))
286
279
  return;
287
280
  const isXAxis = line.start.x === line.end.x;
288
281
  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);
289
282
  }
283
+ exports.calcRectOfAxisLineSegment = calcRectOfAxisLineSegment;
290
284
  function calcSpaceBlockOfRect(target, source, type) {
291
285
  const targetRect = new Rect(target.x, target.y, target.width, target.height);
292
286
  const sourceRect = new Rect(source.x, source.y, source.width, source.height);
@@ -347,6 +341,7 @@ function calcSpaceBlockOfRect(target, source, type) {
347
341
  };
348
342
  }
349
343
  }
344
+ exports.calcSpaceBlockOfRect = calcSpaceBlockOfRect;
350
345
  function calcExtendsLineSegmentOfRect(targetRect, referRect) {
351
346
  if (referRect.right < targetRect.right &&
352
347
  targetRect.left <= referRect.right) {
@@ -420,6 +415,7 @@ function calcExtendsLineSegmentOfRect(targetRect, referRect) {
420
415
  }
421
416
  }
422
417
  }
418
+ exports.calcExtendsLineSegmentOfRect = calcExtendsLineSegmentOfRect;
423
419
  function calcOffsetOfSnapLineSegmentToEdge(line, current) {
424
420
  const edges = calcEdgeLinesOfRect(current);
425
421
  const isVerticalLine = line.start.x === line.end.x;
@@ -445,6 +441,7 @@ function calcOffsetOfSnapLineSegmentToEdge(line, current) {
445
441
  }
446
442
  return { x: 0, y: calcMinDistanceValue(edges.y, line.start.y) - current.y };
447
443
  }
444
+ exports.calcOffsetOfSnapLineSegmentToEdge = calcOffsetOfSnapLineSegmentToEdge;
448
445
  function calcDistanceOfSnapLineToEdges(line, edges) {
449
446
  var _a, _b, _c, _d;
450
447
  let distance = Infinity;
@@ -469,12 +466,14 @@ function calcDistanceOfSnapLineToEdges(line, edges) {
469
466
  }
470
467
  return distance;
471
468
  }
469
+ exports.calcDistanceOfSnapLineToEdges = calcDistanceOfSnapLineToEdges;
472
470
  function calcCombineSnapLineSegment(target, source) {
473
471
  if (target.start.x === target.end.x) {
474
472
  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));
475
473
  }
476
474
  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));
477
475
  }
476
+ exports.calcCombineSnapLineSegment = calcCombineSnapLineSegment;
478
477
  function calcClosestEdges(line, edges) {
479
478
  var _a, _b, _c, _d;
480
479
  let result;
@@ -502,3 +501,4 @@ function calcClosestEdges(line, edges) {
502
501
  }
503
502
  return [distance, result];
504
503
  }
504
+ exports.calcClosestEdges = calcClosestEdges;
package/lib/scroller.d.ts CHANGED
@@ -5,6 +5,6 @@ export interface IAutoScrollBasicInfo {
5
5
  speedFactor: number;
6
6
  speed: number;
7
7
  }
8
- export declare const calcAutoScrollBasicInfo: (point: IPoint, axis: "x" | "y", viewport: DOMRect, maxSpeed?: number) => IAutoScrollBasicInfo | null;
9
- export declare const updateScrollValue: (element: HTMLElement | Window, axis: "x" | "y", value: number, callback?: (scrollValue: number) => void) => void;
10
- export declare const scrollAnimate: (element: HTMLElement | Window, axis: "x" | "y", direction: "begin" | "end", speed: number, callback?: (scrollValue: number) => void) => () => void;
8
+ export declare const calcAutoScrollBasicInfo: (point: IPoint, axis: 'x' | 'y', viewport: DOMRect, maxSpeed?: number) => IAutoScrollBasicInfo | null;
9
+ export declare const updateScrollValue: (element: HTMLElement | Window, axis: 'x' | 'y', value: number, callback?: (scrollValue: number) => void) => void;
10
+ export declare const scrollAnimate: (element: HTMLElement | Window, axis: 'x' | 'y', direction: 'begin' | 'end', speed: number, callback?: (scrollValue: number) => void) => () => void;
package/lib/uid.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uid = uid;
3
+ exports.uid = void 0;
4
4
  let IDX = 36, HEX = '';
5
5
  while (IDX--)
6
6
  HEX += IDX.toString(36);
@@ -10,3 +10,4 @@ function uid(len) {
10
10
  str += HEX[(Math.random() * 36) | 0];
11
11
  return str;
12
12
  }
13
+ exports.uid = uid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formily-design/shared",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "license": "MIT",
5
5
  "main": "lib",
6
6
  "types": "lib/index.d.ts",
@@ -28,5 +28,5 @@
28
28
  "dependencies": {
29
29
  "requestidlecallback": "^0.3.0"
30
30
  },
31
- "gitHead": "a4bdfa62e815f7284aa96e95e981afbab9d08db0"
31
+ "gitHead": "e5564cc16c767903c2509f925b95b21580d25865"
32
32
  }