@antv/util 2.0.15 → 3.0.0-beta.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/LICENSE +21 -0
- package/README.md +15 -241
- package/dist/util.min.js +1 -0
- package/esm/color/arr2rgb.d.ts +12 -0
- package/esm/color/arr2rgb.js +18 -0
- package/esm/color/arr2rgb.js.map +1 -0
- package/esm/color/gradient.d.ts +6 -0
- package/esm/color/gradient.js +45 -0
- package/esm/color/gradient.js.map +1 -0
- package/esm/color/index.d.ts +4 -0
- package/esm/color/index.js +6 -0
- package/esm/color/index.js.map +1 -0
- package/esm/color/rgb2arr.d.ts +6 -0
- package/esm/color/rgb2arr.js +9 -0
- package/esm/color/rgb2arr.js.map +1 -0
- package/esm/color/tocssgradient.d.ts +1 -0
- package/esm/color/tocssgradient.js +37 -0
- package/esm/color/tocssgradient.js.map +1 -0
- package/esm/color/torgb.d.ts +6 -0
- package/esm/color/torgb.js +36 -0
- package/esm/color/torgb.js.map +1 -0
- package/esm/helper/index.d.ts +2 -0
- package/esm/helper/index.js +3 -0
- package/esm/helper/index.js.map +1 -0
- package/esm/helper/mod.d.ts +1 -0
- package/esm/helper/mod.js +4 -0
- package/esm/helper/mod.js.map +1 -0
- package/esm/helper/to-radian.d.ts +1 -0
- package/esm/helper/to-radian.js +5 -0
- package/esm/helper/to-radian.js.map +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -0
- package/esm/matrix/index.d.ts +27 -0
- package/esm/matrix/index.js +97 -0
- package/esm/matrix/index.js.map +1 -0
- package/esm/path/catmull-rom-2-bezier.d.ts +10 -0
- package/esm/path/catmull-rom-2-bezier.js +115 -0
- package/esm/path/catmull-rom-2-bezier.js.map +1 -0
- package/esm/path/fill-path-by-diff.d.ts +5 -0
- package/esm/path/fill-path-by-diff.js +110 -0
- package/esm/path/fill-path-by-diff.js.map +1 -0
- package/esm/path/fill-path.d.ts +1 -0
- package/esm/path/fill-path.js +129 -0
- package/esm/path/fill-path.js.map +1 -0
- package/esm/path/format-path.d.ts +1 -0
- package/esm/path/format-path.js +139 -0
- package/esm/path/format-path.js.map +1 -0
- package/esm/path/get-arc-params.d.ts +17 -0
- package/esm/path/get-arc-params.js +90 -0
- package/esm/path/get-arc-params.js.map +1 -0
- package/esm/path/get-line-intersect.d.ts +14 -0
- package/esm/path/get-line-intersect.js +33 -0
- package/esm/path/get-line-intersect.js.map +1 -0
- package/esm/path/index.d.ts +16 -0
- package/esm/path/index.js +17 -0
- package/esm/path/index.js.map +1 -0
- package/esm/path/is-polygons-intersect.d.ts +1 -0
- package/esm/path/is-polygons-intersect.js +81 -0
- package/esm/path/is-polygons-intersect.js.map +1 -0
- package/esm/path/parse-path-array.d.ts +1 -0
- package/esm/path/parse-path-array.js +5 -0
- package/esm/path/parse-path-array.js.map +1 -0
- package/esm/path/parse-path-string.d.ts +1 -0
- package/esm/path/parse-path-string.js +57 -0
- package/esm/path/parse-path-string.js.map +1 -0
- package/esm/path/parse-path.d.ts +1 -0
- package/esm/path/parse-path.js +33 -0
- package/esm/path/parse-path.js.map +1 -0
- package/esm/path/path-2-absolute.d.ts +1 -0
- package/esm/path/path-2-absolute.js +124 -0
- package/esm/path/path-2-absolute.js.map +1 -0
- package/esm/path/path-2-curve.d.ts +2 -0
- package/esm/path/path-2-curve.js +63 -0
- package/esm/path/path-2-curve.js.map +1 -0
- package/esm/path/path-2-segments.d.ts +1 -0
- package/esm/path/path-2-segments.js +138 -0
- package/esm/path/path-2-segments.js.map +1 -0
- package/esm/path/path-intersection.d.ts +9 -0
- package/esm/path/path-intersection.js +366 -0
- package/esm/path/path-intersection.js.map +1 -0
- package/esm/path/point-in-polygon.d.ts +5 -0
- package/esm/path/point-in-polygon.js +49 -0
- package/esm/path/point-in-polygon.js.map +1 -0
- package/esm/path/process/arc-2-cubic.d.ts +1 -0
- package/esm/path/process/arc-2-cubic.js +140 -0
- package/esm/path/process/arc-2-cubic.js.map +1 -0
- package/esm/path/process/line-2-cubic.d.ts +1 -0
- package/esm/path/process/line-2-cubic.js +35 -0
- package/esm/path/process/line-2-cubic.js.map +1 -0
- package/esm/path/process/quad-2-cubic.d.ts +1 -0
- package/esm/path/process/quad-2-cubic.js +13 -0
- package/esm/path/process/quad-2-cubic.js.map +1 -0
- package/esm/path/process/segment-2-cubic.d.ts +2 -0
- package/esm/path/process/segment-2-cubic.js +37 -0
- package/esm/path/process/segment-2-cubic.js.map +1 -0
- package/esm/path/rect-path.d.ts +4 -0
- package/esm/path/rect-path.js +19 -0
- package/esm/path/rect-path.js.map +1 -0
- package/esm/path/types.d.ts +25 -0
- package/esm/path/types.js +2 -0
- package/esm/path/types.js.map +1 -0
- package/lib/color/arr2rgb.d.ts +12 -0
- package/lib/color/arr2rgb.js +23 -0
- package/lib/color/arr2rgb.js.map +1 -0
- package/lib/color/gradient.d.ts +6 -0
- package/lib/color/gradient.js +49 -0
- package/lib/color/gradient.js.map +1 -0
- package/lib/color/index.d.ts +4 -0
- package/lib/color/index.js +13 -0
- package/lib/color/index.js.map +1 -0
- package/lib/color/rgb2arr.d.ts +6 -0
- package/lib/color/rgb2arr.js +13 -0
- package/lib/color/rgb2arr.js.map +1 -0
- package/lib/color/tocssgradient.d.ts +1 -0
- package/lib/color/tocssgradient.js +41 -0
- package/lib/color/tocssgradient.js.map +1 -0
- package/lib/color/torgb.d.ts +6 -0
- package/lib/color/torgb.js +40 -0
- package/lib/color/torgb.js.map +1 -0
- package/lib/helper/index.d.ts +2 -0
- package/lib/helper/index.js +8 -0
- package/lib/helper/index.js.map +1 -0
- package/lib/helper/mod.d.ts +1 -0
- package/lib/helper/mod.js +8 -0
- package/lib/helper/mod.js.map +1 -0
- package/lib/helper/to-radian.d.ts +1 -0
- package/lib/helper/to-radian.js +9 -0
- package/lib/helper/to-radian.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/matrix/index.d.ts +27 -0
- package/lib/matrix/index.js +104 -0
- package/lib/matrix/index.js.map +1 -0
- package/lib/path/catmull-rom-2-bezier.d.ts +10 -0
- package/lib/path/catmull-rom-2-bezier.js +119 -0
- package/lib/path/catmull-rom-2-bezier.js.map +1 -0
- package/lib/path/fill-path-by-diff.d.ts +5 -0
- package/lib/path/fill-path-by-diff.js +117 -0
- package/lib/path/fill-path-by-diff.js.map +1 -0
- package/lib/path/fill-path.d.ts +1 -0
- package/lib/path/fill-path.js +133 -0
- package/lib/path/fill-path.js.map +1 -0
- package/lib/path/format-path.d.ts +1 -0
- package/lib/path/format-path.js +143 -0
- package/lib/path/format-path.js.map +1 -0
- package/lib/path/get-arc-params.d.ts +17 -0
- package/lib/path/get-arc-params.js +95 -0
- package/lib/path/get-arc-params.js.map +1 -0
- package/lib/path/get-line-intersect.d.ts +14 -0
- package/lib/path/get-line-intersect.js +37 -0
- package/lib/path/get-line-intersect.js.map +1 -0
- package/lib/path/index.d.ts +16 -0
- package/lib/path/index.js +36 -0
- package/lib/path/index.js.map +1 -0
- package/lib/path/is-polygons-intersect.d.ts +1 -0
- package/lib/path/is-polygons-intersect.js +85 -0
- package/lib/path/is-polygons-intersect.js.map +1 -0
- package/lib/path/parse-path-array.d.ts +1 -0
- package/lib/path/parse-path-array.js +9 -0
- package/lib/path/parse-path-array.js.map +1 -0
- package/lib/path/parse-path-string.d.ts +1 -0
- package/lib/path/parse-path-string.js +61 -0
- package/lib/path/parse-path-string.js.map +1 -0
- package/lib/path/parse-path.d.ts +1 -0
- package/lib/path/parse-path.js +37 -0
- package/lib/path/parse-path.js.map +1 -0
- package/lib/path/path-2-absolute.d.ts +1 -0
- package/lib/path/path-2-absolute.js +128 -0
- package/lib/path/path-2-absolute.js.map +1 -0
- package/lib/path/path-2-curve.d.ts +2 -0
- package/lib/path/path-2-curve.js +67 -0
- package/lib/path/path-2-curve.js.map +1 -0
- package/lib/path/path-2-segments.d.ts +1 -0
- package/lib/path/path-2-segments.js +142 -0
- package/lib/path/path-2-segments.js.map +1 -0
- package/lib/path/path-intersection.d.ts +9 -0
- package/lib/path/path-intersection.js +370 -0
- package/lib/path/path-intersection.js.map +1 -0
- package/lib/path/point-in-polygon.d.ts +5 -0
- package/lib/path/point-in-polygon.js +53 -0
- package/lib/path/point-in-polygon.js.map +1 -0
- package/lib/path/process/arc-2-cubic.d.ts +1 -0
- package/lib/path/process/arc-2-cubic.js +144 -0
- package/lib/path/process/arc-2-cubic.js.map +1 -0
- package/lib/path/process/line-2-cubic.d.ts +1 -0
- package/lib/path/process/line-2-cubic.js +39 -0
- package/lib/path/process/line-2-cubic.js.map +1 -0
- package/lib/path/process/quad-2-cubic.d.ts +1 -0
- package/lib/path/process/quad-2-cubic.js +17 -0
- package/lib/path/process/quad-2-cubic.js.map +1 -0
- package/lib/path/process/segment-2-cubic.d.ts +2 -0
- package/lib/path/process/segment-2-cubic.js +41 -0
- package/lib/path/process/segment-2-cubic.js.map +1 -0
- package/lib/path/rect-path.d.ts +4 -0
- package/lib/path/rect-path.js +23 -0
- package/lib/path/rect-path.js.map +1 -0
- package/lib/path/types.d.ts +25 -0
- package/lib/path/types.js +3 -0
- package/lib/path/types.js.map +1 -0
- package/package.json +77 -36
- package/src/color/arr2rgb.ts +19 -0
- package/src/color/gradient.ts +55 -0
- package/src/color/index.ts +5 -0
- package/src/color/rgb2arr.ts +8 -0
- package/src/color/tocssgradient.ts +43 -0
- package/src/color/torgb.ts +45 -0
- package/src/helper/index.ts +2 -0
- package/src/helper/mod.ts +3 -0
- package/src/helper/to-radian.ts +5 -0
- package/src/index.ts +3 -130
- package/src/matrix/index.ts +108 -0
- package/src/path/catmull-rom-2-bezier.ts +141 -0
- package/src/path/fill-path-by-diff.ts +116 -0
- package/src/path/fill-path.ts +129 -0
- package/src/path/format-path.ts +142 -0
- package/src/path/get-arc-params.ts +102 -0
- package/src/path/get-line-intersect.ts +46 -0
- package/src/path/index.ts +16 -0
- package/src/path/is-polygons-intersect.ts +95 -0
- package/src/path/parse-path-array.ts +5 -0
- package/src/path/parse-path-string.ts +63 -0
- package/src/path/parse-path.ts +34 -0
- package/src/path/path-2-absolute.ts +132 -0
- package/src/path/path-2-curve.ts +69 -0
- package/src/path/path-2-segments.ts +142 -0
- package/src/path/path-intersection.ts +419 -0
- package/src/path/point-in-polygon.ts +56 -0
- package/src/path/process/arc-2-cubic.ts +221 -0
- package/src/path/process/line-2-cubic.ts +37 -0
- package/src/path/process/quad-2-cubic.ts +12 -0
- package/src/path/process/segment-2-cubic.ts +44 -0
- package/src/path/rect-path.ts +22 -0
- package/src/path/types.ts +25 -0
- package/src/augment.ts +0 -16
- package/src/cache.ts +0 -31
- package/src/clamp.ts +0 -10
- package/src/clear-animation-frame.ts +0 -11
- package/src/clone.ts +0 -31
- package/src/contains.ts +0 -10
- package/src/debounce.ts +0 -22
- package/src/deep-mix.ts +0 -39
- package/src/difference.ts +0 -17
- package/src/each.ts +0 -28
- package/src/ends-with.ts +0 -10
- package/src/every.ts +0 -14
- package/src/extend.ts +0 -36
- package/src/filter.ts +0 -18
- package/src/find-index.ts +0 -12
- package/src/find.ts +0 -29
- package/src/first-value.ts +0 -21
- package/src/fixed-base.ts +0 -14
- package/src/flatten-deep.ts +0 -24
- package/src/flatten.ts +0 -23
- package/src/for-in.ts +0 -3
- package/src/get-ellipsis-text.ts +0 -75
- package/src/get-range.ts +0 -35
- package/src/get-type.ts +0 -7
- package/src/get-wrap-behavior.ts +0 -13
- package/src/get.ts +0 -18
- package/src/group-by.ts +0 -35
- package/src/group-to-map.ts +0 -30
- package/src/group.ts +0 -14
- package/src/has-key.ts +0 -2
- package/src/has-value.ts +0 -4
- package/src/has.ts +0 -1
- package/src/head.ts +0 -8
- package/src/identity.ts +0 -1
- package/src/index-of.ts +0 -22
- package/src/is-arguments.ts +0 -13
- package/src/is-array-like.ts +0 -11
- package/src/is-array.ts +0 -7
- package/src/is-boolean.ts +0 -13
- package/src/is-date.ts +0 -7
- package/src/is-decimal.ts +0 -7
- package/src/is-element.ts +0 -8
- package/src/is-empty.ts +0 -39
- package/src/is-equal-with.ts +0 -31
- package/src/is-equal.ts +0 -46
- package/src/is-error.ts +0 -13
- package/src/is-even.ts +0 -7
- package/src/is-finite.ts +0 -11
- package/src/is-function.ts +0 -10
- package/src/is-integer.ts +0 -7
- package/src/is-match.ts +0 -17
- package/src/is-negative.ts +0 -7
- package/src/is-nil.ts +0 -10
- package/src/is-null.ts +0 -5
- package/src/is-number-equal.ts +0 -5
- package/src/is-number.ts +0 -10
- package/src/is-object-like.ts +0 -11
- package/src/is-object.ts +0 -10
- package/src/is-odd.ts +0 -7
- package/src/is-plain-object.ts +0 -24
- package/src/is-positive.ts +0 -7
- package/src/is-prototype.ts +0 -9
- package/src/is-reg-exp.ts +0 -7
- package/src/is-segment-equal.ts +0 -15
- package/src/is-string.ts +0 -5
- package/src/is-type.ts +0 -5
- package/src/is-undefined.ts +0 -5
- package/src/keys.ts +0 -14
- package/src/last.ts +0 -9
- package/src/lower-case.ts +0 -7
- package/src/lower-first.ts +0 -8
- package/src/map-values.ts +0 -19
- package/src/map.ts +0 -17
- package/src/max-by.ts +0 -37
- package/src/max.ts +0 -28
- package/src/measure-text-width.ts +0 -25
- package/src/memoize.ts +0 -31
- package/src/merge.ts +0 -12
- package/src/min-by.ts +0 -38
- package/src/min.ts +0 -28
- package/src/mix.ts +0 -15
- package/src/mod.ts +0 -5
- package/src/noop.ts +0 -1
- package/src/number2color.ts +0 -17
- package/src/omit.ts +0 -15
- package/src/parse-radius.ts +0 -45
- package/src/pick.ts +0 -32
- package/src/pull-at.ts +0 -23
- package/src/pull.ts +0 -16
- package/src/reduce.ts +0 -17
- package/src/remove.ts +0 -30
- package/src/request-animation-frame.ts +0 -13
- package/src/set.ts +0 -29
- package/src/size.ts +0 -12
- package/src/some.ts +0 -14
- package/src/sort-by.ts +0 -42
- package/src/starts-with.ts +0 -10
- package/src/substitute.ts +0 -17
- package/src/throttle.ts +0 -48
- package/src/to-array.ts +0 -5
- package/src/to-degree.ts +0 -7
- package/src/to-integer.ts +0 -1
- package/src/to-radian.ts +0 -7
- package/src/to-string.ts +0 -6
- package/src/types/index.ts +0 -3
- package/src/union.ts +0 -7
- package/src/uniq.ts +0 -15
- package/src/unique-id.ts +0 -11
- package/src/upper-case.ts +0 -7
- package/src/upper-first.ts +0 -8
- package/src/values-of-key.ts +0 -29
- package/src/values.ts +0 -15
- package/src/wrap-behavior.ts +0 -20
package/src/keys.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isFunction from './is-function';
|
|
3
|
-
|
|
4
|
-
const keys = Object.keys ? obj => Object.keys(obj) : obj => {
|
|
5
|
-
const result = [];
|
|
6
|
-
each(obj, (value, key) => {
|
|
7
|
-
if (!(isFunction(obj) && key === 'prototype')) {
|
|
8
|
-
result.push(key);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default keys;
|
package/src/last.ts
DELETED
package/src/lower-case.ts
DELETED
package/src/lower-first.ts
DELETED
package/src/map-values.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import isNil from './is-nil';
|
|
2
|
-
import isObject from './is-object'
|
|
3
|
-
|
|
4
|
-
const identity = <T>(v: T): T => v;
|
|
5
|
-
|
|
6
|
-
interface _Type<T> {
|
|
7
|
-
[key: string]: T;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default <T>(object: { [key: string]: T }, func: (value: T, key: string) => any = identity): { [key: string]: any } => {
|
|
11
|
-
const r: _Type<T> = {};
|
|
12
|
-
if (isObject(object) && !isNil(object)) {
|
|
13
|
-
Object.keys(object).forEach(key => {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
r[key] = func(object[key], key);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return r;
|
|
19
|
-
}
|
package/src/map.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import isArrayLike from './is-array-like';
|
|
2
|
-
|
|
3
|
-
const map = <T, G> (arr: T[], func: (v: T, idx: number) => G): G[] => {
|
|
4
|
-
if (!isArrayLike(arr)) {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
return arr;
|
|
7
|
-
}
|
|
8
|
-
const result: G[] = [];
|
|
9
|
-
|
|
10
|
-
for (let index = 0; index < arr.length; index++) {
|
|
11
|
-
const value = arr[index];
|
|
12
|
-
result.push(func(value, index));
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default map;
|
package/src/max-by.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isArray from './is-array';
|
|
3
|
-
import isFunction from './is-function';
|
|
4
|
-
/**
|
|
5
|
-
* @param {Array} arr The array to iterate over.
|
|
6
|
-
* @param {Function} [fn] The iteratee invoked per element.
|
|
7
|
-
* @return {*} Returns the maximum value.
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* var objects = [{ 'n': 1 }, { 'n': 2 }];
|
|
11
|
-
*
|
|
12
|
-
* maxBy(objects, function(o) { return o.n; });
|
|
13
|
-
* // => { 'n': 2 }
|
|
14
|
-
*
|
|
15
|
-
* maxBy(objects, 'n');
|
|
16
|
-
* // => { 'n': 2 }
|
|
17
|
-
*/
|
|
18
|
-
export default <T>(arr: T[], fn: ((v: T) => number) | string): T | undefined => {
|
|
19
|
-
if (!isArray(arr)) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let maxItem;
|
|
24
|
-
let max = -Infinity;
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < arr.length; i++) {
|
|
27
|
-
const item = arr[i];
|
|
28
|
-
const v = isFunction(fn) ? fn(item) : item[fn];
|
|
29
|
-
|
|
30
|
-
if (v > max) {
|
|
31
|
-
maxItem = item;
|
|
32
|
-
max = v;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return maxItem;
|
|
37
|
-
};
|
package/src/max.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isArray from './is-array';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Array} arr The array to iterate over.
|
|
6
|
-
* @return {*} Returns the maximum value.
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* max([1, 2]);
|
|
10
|
-
* // => 2
|
|
11
|
-
*
|
|
12
|
-
* max([]);
|
|
13
|
-
* // => undefined
|
|
14
|
-
*
|
|
15
|
-
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
16
|
-
*
|
|
17
|
-
* max(data);
|
|
18
|
-
* // => 1250010
|
|
19
|
-
* // Math.max(...data) will encounter "Maximum call stack size exceeded" error
|
|
20
|
-
*/
|
|
21
|
-
export default (arr: number[]): number | undefined => {
|
|
22
|
-
if (!isArray(arr)) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
return arr.reduce((prev, curr) => {
|
|
26
|
-
return Math.max(prev, curr)
|
|
27
|
-
}, arr[0]);
|
|
28
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import values from './values';
|
|
2
|
-
import memoize from './memoize';
|
|
3
|
-
import isString from './is-string';
|
|
4
|
-
import type { Properties } from 'csstype';
|
|
5
|
-
|
|
6
|
-
export type Font = Pick<Properties, 'fontFamily' | 'fontWeight' | 'fontStyle' | 'fontVariant'> & {
|
|
7
|
-
fontSize?: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
let ctx: CanvasRenderingContext2D;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 计算文本的宽度
|
|
14
|
-
*/
|
|
15
|
-
export default memoize(
|
|
16
|
-
(text: any, font: Font = {}): number => {
|
|
17
|
-
const { fontSize, fontFamily, fontWeight, fontStyle, fontVariant } = font;
|
|
18
|
-
if (!ctx) {
|
|
19
|
-
ctx = document.createElement('canvas').getContext('2d') as CanvasRenderingContext2D;
|
|
20
|
-
}
|
|
21
|
-
ctx!.font = [fontStyle, fontVariant, fontWeight, `${fontSize}px`, fontFamily].join(' ');
|
|
22
|
-
return ctx!.measureText(isString(text) ? text : '').width;
|
|
23
|
-
},
|
|
24
|
-
(text: any, font: Font = {}) => [text, ...values(font)].join('')
|
|
25
|
-
);
|
package/src/memoize.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import isFunction from './is-function';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* _.memoize(calColor);
|
|
5
|
-
* _.memoize(calColor, (...args) => args[0]);
|
|
6
|
-
* @param f
|
|
7
|
-
* @param resolver
|
|
8
|
-
*/
|
|
9
|
-
export default (f: Function, resolver?: (...args: any[]) => string) => {
|
|
10
|
-
if (!isFunction(f)) {
|
|
11
|
-
throw new TypeError('Expected a function')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const memoized = function(...args) {
|
|
15
|
-
// 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
|
|
16
|
-
const key = resolver ? resolver.apply(this, args) : args[0];
|
|
17
|
-
const cache = memoized.cache;
|
|
18
|
-
|
|
19
|
-
if (cache.has(key)) {
|
|
20
|
-
return cache.get(key)
|
|
21
|
-
}
|
|
22
|
-
const result = f.apply(this, args);
|
|
23
|
-
// 缓存起来
|
|
24
|
-
cache.set(key, result);
|
|
25
|
-
return result
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
memoized.cache = new Map();
|
|
29
|
-
|
|
30
|
-
return memoized
|
|
31
|
-
}
|
package/src/merge.ts
DELETED
package/src/min-by.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isArray from './is-array';
|
|
3
|
-
import isFunction from './is-function';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {Array} arr The array to iterate over.
|
|
7
|
-
* @param {Function} [fn] The iteratee invoked per element.
|
|
8
|
-
* @return {*} Returns the minimum value.
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* var objects = [{ 'n': 1 }, { 'n': 2 }];
|
|
12
|
-
*
|
|
13
|
-
* minBy(objects, function(o) { return o.n; });
|
|
14
|
-
* // => { 'n': 1 }
|
|
15
|
-
*
|
|
16
|
-
* minBy(objects, 'n');
|
|
17
|
-
* // => { 'n': 1 }
|
|
18
|
-
*/
|
|
19
|
-
export default <T>(arr: T[], fn: ((v: T) => number) | string): T | undefined => {
|
|
20
|
-
if (!isArray(arr)) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let minItem;
|
|
25
|
-
let min = Infinity;
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < arr.length; i++) {
|
|
28
|
-
const item = arr[i];
|
|
29
|
-
const v = isFunction(fn) ? fn(item) : item[fn];
|
|
30
|
-
|
|
31
|
-
if (v < min) {
|
|
32
|
-
minItem = item;
|
|
33
|
-
min = v;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return minItem;
|
|
38
|
-
};
|
package/src/min.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isArray from './is-array';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Array} arr The array to iterate over.
|
|
6
|
-
* @return {*} Returns the minimum value.
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* min([1, 2]);
|
|
10
|
-
* // => 1
|
|
11
|
-
*
|
|
12
|
-
* min([]);
|
|
13
|
-
* // => undefined
|
|
14
|
-
*
|
|
15
|
-
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
16
|
-
*
|
|
17
|
-
* min(data);
|
|
18
|
-
* // => 1250010
|
|
19
|
-
* // Math.min(...data) will encounter "Maximum call stack size exceeded" error
|
|
20
|
-
*/
|
|
21
|
-
export default (arr: number[]): number | undefined => {
|
|
22
|
-
if (!isArray(arr)) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
return arr.reduce((prev, curr) => {
|
|
26
|
-
return Math.min(prev, curr)
|
|
27
|
-
}, arr[0]);
|
|
28
|
-
};
|
package/src/mix.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// FIXME: Mutable param should be forbidden in static lang.
|
|
2
|
-
function _mix<Base, Source>(dist: Base & Source, obj: Source): void {
|
|
3
|
-
for (const key in obj) {
|
|
4
|
-
if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
|
|
5
|
-
(<any>dist)[key] = obj[key];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default function mix<Base, A, B, C>(dist: Base & A & B & C, src1?: A, src2?: B, src3?: C): Base & A & B & C {
|
|
11
|
-
if (src1) _mix(dist, src1);
|
|
12
|
-
if (src2) _mix(dist, src2);
|
|
13
|
-
if (src3) _mix(dist, src3);
|
|
14
|
-
return dist;
|
|
15
|
-
}
|
package/src/mod.ts
DELETED
package/src/noop.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default () => {};
|
package/src/number2color.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const numColorCache = {};
|
|
2
|
-
|
|
3
|
-
function numberToColor(num: number): string {
|
|
4
|
-
// 增加缓存
|
|
5
|
-
let color = numColorCache[num];
|
|
6
|
-
if (!color) {
|
|
7
|
-
let str = num.toString(16);
|
|
8
|
-
for (let i = str.length; i < 6; i++) {
|
|
9
|
-
str = '0' + str;
|
|
10
|
-
}
|
|
11
|
-
color = '#' + str;
|
|
12
|
-
numColorCache[num] = color;
|
|
13
|
-
}
|
|
14
|
-
return color;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default numberToColor;
|
package/src/omit.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import reduce from './reduce';
|
|
2
|
-
import { ObjectType } from './types';
|
|
3
|
-
|
|
4
|
-
export default <T>(obj: ObjectType<T>, keys: string[]): ObjectType<T> => {
|
|
5
|
-
return reduce(
|
|
6
|
-
obj,
|
|
7
|
-
(r: ObjectType<T>, curr: T, key: string) => {
|
|
8
|
-
if (!keys.includes(key)) {
|
|
9
|
-
r[key] = curr;
|
|
10
|
-
}
|
|
11
|
-
return r;
|
|
12
|
-
},
|
|
13
|
-
{}
|
|
14
|
-
);
|
|
15
|
-
}
|
package/src/parse-radius.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
|
|
3
|
-
export interface RadiusType {
|
|
4
|
-
r1: number;
|
|
5
|
-
r2: number;
|
|
6
|
-
r3: number;
|
|
7
|
-
r4: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function parseRadius(radius: number): RadiusType;
|
|
11
|
-
function parseRadius(radius: number[]): RadiusType;
|
|
12
|
-
|
|
13
|
-
function parseRadius(radius: number | number[]): RadiusType {
|
|
14
|
-
let r1 = 0,
|
|
15
|
-
r2 = 0,
|
|
16
|
-
r3 = 0,
|
|
17
|
-
r4 = 0;
|
|
18
|
-
if (isArray(radius)) {
|
|
19
|
-
if (radius.length === 1) {
|
|
20
|
-
r1 = r2 = r3 = r4 = radius[0];
|
|
21
|
-
} else if (radius.length === 2) {
|
|
22
|
-
r1 = r3 = radius[0];
|
|
23
|
-
r2 = r4 = radius[1];
|
|
24
|
-
} else if (radius.length === 3) {
|
|
25
|
-
r1 = radius[0];
|
|
26
|
-
r2 = r4 = radius[1];
|
|
27
|
-
r3 = radius[2];
|
|
28
|
-
} else {
|
|
29
|
-
r1 = radius[0];
|
|
30
|
-
r2 = radius[1];
|
|
31
|
-
r3 = radius[2];
|
|
32
|
-
r4 = radius[3];
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
r1 = r2 = r3 = r4 = radius;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
r1,
|
|
39
|
-
r2,
|
|
40
|
-
r3,
|
|
41
|
-
r4
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default parseRadius;
|
package/src/pick.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isPlainObject from './is-plain-object';
|
|
3
|
-
|
|
4
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
5
|
-
/**
|
|
6
|
-
* Creates an object composed of the picked `object` properties.
|
|
7
|
-
*
|
|
8
|
-
* @param {Object} object The source object.
|
|
9
|
-
* @param {...(string[])} [paths] The property paths to pick.
|
|
10
|
-
* @returns {Object} Returns the new object.
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* var object = { 'a': 1, 'b': '2', 'c': 3 };
|
|
14
|
-
* pick(object, ['a', 'c']); // => { 'a': 1, 'c': 3 }
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export interface ObjectType<T> {
|
|
18
|
-
[key: string]: T;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default <T>(object: ObjectType<T>, keys: string[]): ObjectType<T> => {
|
|
22
|
-
if (object === null || !isPlainObject(object)) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
const result: ObjectType<T> = {};
|
|
26
|
-
each(keys, key => {
|
|
27
|
-
if (hasOwnProperty.call(object, key)) {
|
|
28
|
-
result[key] = object[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return result;
|
|
32
|
-
};
|
package/src/pull-at.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import isArrayLike from './is-array-like';
|
|
2
|
-
|
|
3
|
-
const splice = Array.prototype.splice;
|
|
4
|
-
|
|
5
|
-
const pullAt = function pullAt <T>(arr: T[], indexes: number[]): T[] {
|
|
6
|
-
if (!isArrayLike(arr)) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
let length = arr ? indexes.length : 0;
|
|
10
|
-
const last = length - 1;
|
|
11
|
-
|
|
12
|
-
while (length--) {
|
|
13
|
-
let previous;
|
|
14
|
-
const index = indexes[length];
|
|
15
|
-
if (length === last || index !== previous) {
|
|
16
|
-
previous = index;
|
|
17
|
-
splice.call(arr, index, 1);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return arr;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default pullAt;
|
package/src/pull.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const arrPrototype = Array.prototype;
|
|
2
|
-
const splice = arrPrototype.splice;
|
|
3
|
-
const indexOf = arrPrototype.indexOf;
|
|
4
|
-
|
|
5
|
-
const pull = function<T>(arr: T[], ...values: any[]): T[] {
|
|
6
|
-
for (let i = 0; i < values.length; i++) {
|
|
7
|
-
const value = values[i];
|
|
8
|
-
let fromIndex = -1;
|
|
9
|
-
while ((fromIndex = indexOf.call(arr, value)) > -1) {
|
|
10
|
-
splice.call(arr, fromIndex, 1);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return arr;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default pull;
|
package/src/reduce.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import each from './each';
|
|
2
|
-
import isArray from './is-array';
|
|
3
|
-
import isPlainObject from './is-plain-object';
|
|
4
|
-
import { ObjectType } from './types';
|
|
5
|
-
|
|
6
|
-
const reduce = function<T, G>(arr: G[]|ObjectType<T>, fn: (result: T, data: G, idx: string | number) => T, init: T) {
|
|
7
|
-
if (!isArray(arr) && !isPlainObject(arr)) {
|
|
8
|
-
return arr;
|
|
9
|
-
}
|
|
10
|
-
let result = init;
|
|
11
|
-
each(arr, (data, i) => {
|
|
12
|
-
result = fn(result, data, i);
|
|
13
|
-
});
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default reduce;
|
package/src/remove.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import isArrayLike from './is-array-like';
|
|
2
|
-
import pullAt from './pull-at';
|
|
3
|
-
|
|
4
|
-
const remove = function<T>(arr: T[], predicate: (value: T, idx: number, arr?: T[]) => boolean): T[] {
|
|
5
|
-
/**
|
|
6
|
-
* const arr = [1, 2, 3, 4]
|
|
7
|
-
* const evens = remove(arr, n => n % 2 == 0)
|
|
8
|
-
* console.log(arr) // => [1, 3]
|
|
9
|
-
* console.log(evens) // => [2, 4]
|
|
10
|
-
*/
|
|
11
|
-
const result = [];
|
|
12
|
-
if (!isArrayLike(arr)) {
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
let i = -1;
|
|
16
|
-
const indexes = [];
|
|
17
|
-
const length = arr.length;
|
|
18
|
-
|
|
19
|
-
while (++i < length) {
|
|
20
|
-
const value = arr[i];
|
|
21
|
-
if (predicate(value, i, arr)) {
|
|
22
|
-
result.push(value);
|
|
23
|
-
indexes.push(i);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
pullAt(arr, indexes);
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default remove;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export default function requestAnimationFrame(fn: FrameRequestCallback) {
|
|
2
|
-
const method = window.requestAnimationFrame ||
|
|
3
|
-
window.webkitRequestAnimationFrame ||
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
window.mozRequestAnimationFrame ||
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
window.msRequestAnimationFrame ||
|
|
8
|
-
function(f) {
|
|
9
|
-
return setTimeout(f, 16);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
return method(fn);
|
|
13
|
-
};
|
package/src/set.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import isObject from './is-object';
|
|
2
|
-
import isString from './is-string';
|
|
3
|
-
import isNumber from './is-number';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* https://github.com/developit/dlv/blob/master/index.js
|
|
7
|
-
* @param obj
|
|
8
|
-
* @param path
|
|
9
|
-
* @param value
|
|
10
|
-
*/
|
|
11
|
-
export default (obj: any, path: string | any[], value: any): any => {
|
|
12
|
-
let o = obj;
|
|
13
|
-
|
|
14
|
-
const keyArr = isString(path) ? path.split('.') : path;
|
|
15
|
-
|
|
16
|
-
keyArr.forEach((key: string | number, idx: number) => {
|
|
17
|
-
// 不是最后一个
|
|
18
|
-
if (idx < keyArr.length - 1) {
|
|
19
|
-
if (!isObject(o[key])) {
|
|
20
|
-
o[key] = isNumber(keyArr[idx + 1]) ? [] : {};
|
|
21
|
-
}
|
|
22
|
-
o = o[key]
|
|
23
|
-
} else {
|
|
24
|
-
o[key] = value;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return obj;
|
|
29
|
-
}
|
package/src/size.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import isNil from './is-nil';
|
|
2
|
-
import isArraylike from './is-array-like';
|
|
3
|
-
|
|
4
|
-
export default function size(o: unknown) {
|
|
5
|
-
if (isNil(o)) {
|
|
6
|
-
return 0;
|
|
7
|
-
}
|
|
8
|
-
if (isArraylike(o)) {
|
|
9
|
-
return (<ArrayLike<any>>o).length;
|
|
10
|
-
}
|
|
11
|
-
return Object.keys(<object>o).length;
|
|
12
|
-
}
|
package/src/some.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 只要有一个满足条件就返回 true
|
|
3
|
-
* @param arr
|
|
4
|
-
* @param func
|
|
5
|
-
*/
|
|
6
|
-
const some = function <T>(arr: T[], func: (v: T, idx?: number) => any): boolean {
|
|
7
|
-
for (let i = 0; i < arr.length; i ++) {
|
|
8
|
-
if (func(arr[i], i)) return true;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return false;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default some;
|
package/src/sort-by.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
import isString from './is-string';
|
|
3
|
-
import isFunction from './is-function';
|
|
4
|
-
|
|
5
|
-
export interface ObjectType<T> {
|
|
6
|
-
[key: string]: T;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function sortBy<T> (arr: ObjectType<T>[], key: Function): ObjectType<T>[];
|
|
10
|
-
function sortBy<T> (arr: ObjectType<T>[], key: string): ObjectType<T>[];
|
|
11
|
-
function sortBy<T> (arr: ObjectType<T>[], key: string[]): ObjectType<T>[];
|
|
12
|
-
|
|
13
|
-
function sortBy<T> (arr: ObjectType<T>[], key: Function | string | string[]): ObjectType<T>[] {
|
|
14
|
-
let comparer;
|
|
15
|
-
if (isFunction(key)) {
|
|
16
|
-
comparer = (a, b) => key(a) - key(b);
|
|
17
|
-
} else {
|
|
18
|
-
let keys = [];
|
|
19
|
-
if (isString(key)) {
|
|
20
|
-
keys.push(key);
|
|
21
|
-
} else if (isArray(key)) {
|
|
22
|
-
keys = key;
|
|
23
|
-
}
|
|
24
|
-
comparer = (a, b) => {
|
|
25
|
-
for (let i = 0; i < keys.length; i += 1) {
|
|
26
|
-
const prop = keys[i];
|
|
27
|
-
if (a[prop] > b[prop]) {
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
if (a[prop] < b[prop]) {
|
|
31
|
-
return -1;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return 0;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
arr.sort(comparer);
|
|
39
|
-
return arr;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default sortBy;
|
package/src/starts-with.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
import isString from './is-string';
|
|
3
|
-
|
|
4
|
-
function startsWith(arr: string, e: string): boolean;
|
|
5
|
-
function startsWith<T>(arr: T[], e: T): boolean;
|
|
6
|
-
function startsWith<T>(arr: string | T[], e: string | T): boolean {
|
|
7
|
-
return (isArray(arr) || isString(arr)) ? arr[0] === e : false;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default startsWith;
|
package/src/substitute.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface ObjectType<T> {
|
|
2
|
-
[key: string]: T;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function substitute <T>(str: string, o: ObjectType<T>) {
|
|
6
|
-
if (!str || !o) {
|
|
7
|
-
return str;
|
|
8
|
-
}
|
|
9
|
-
return str.replace(/\\?\{([^{}]+)\}/g, (match, name): any => {
|
|
10
|
-
if (match.charAt(0) === '\\') {
|
|
11
|
-
return match.slice(1);
|
|
12
|
-
}
|
|
13
|
-
return (o[name] === undefined) ? '' : o[name];
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default substitute;
|