@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
|
|
2
|
+
const regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
|
|
3
|
+
const regexColorStop = /[\d.]+:(#[^\s]+|[^)]+\))/gi;
|
|
4
|
+
|
|
5
|
+
function isGradientColor(val) {
|
|
6
|
+
return /^[r,R,L,l]{1}[\s]*\(/.test(val);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function toCSSGradient(gradientColor) {
|
|
10
|
+
if (isGradientColor(gradientColor)) {
|
|
11
|
+
let cssColor;
|
|
12
|
+
let steps;
|
|
13
|
+
if (gradientColor[0] === 'l') {
|
|
14
|
+
// 线性渐变
|
|
15
|
+
const arr = regexLG.exec(gradientColor);
|
|
16
|
+
const angle = +arr[1] + 90; // css 和 g 的渐变起始角度不同
|
|
17
|
+
steps = arr[2];
|
|
18
|
+
|
|
19
|
+
cssColor = `linear-gradient(${angle}deg, `;
|
|
20
|
+
} else if (gradientColor[0] === 'r') {
|
|
21
|
+
// 径向渐变
|
|
22
|
+
cssColor = 'radial-gradient(';
|
|
23
|
+
const arr = regexRG.exec(gradientColor);
|
|
24
|
+
steps = arr[4];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const colorStops: string[] = steps.match(regexColorStop);
|
|
28
|
+
|
|
29
|
+
colorStops.forEach((item: string, index: number) => {
|
|
30
|
+
const itemArr = item.split(':');
|
|
31
|
+
cssColor += `${itemArr[1]} ${Number(itemArr[0]) * 100}%`;
|
|
32
|
+
if (index !== colorStops.length - 1) {
|
|
33
|
+
cssColor += ', ';
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
cssColor += ')';
|
|
38
|
+
|
|
39
|
+
return cssColor;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return gradientColor;
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { arr2rgb } from './arr2rgb';
|
|
2
|
+
|
|
3
|
+
const RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 创建辅助 tag 取颜色
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
function createTmp(): HTMLElement {
|
|
10
|
+
const i = document.createElement('i');
|
|
11
|
+
i.title = 'Web Colour Picker';
|
|
12
|
+
i.style.display = 'none';
|
|
13
|
+
document.body.appendChild(i);
|
|
14
|
+
return i;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let iEl: HTMLElement;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 将颜色转换到 rgb 的格式
|
|
21
|
+
* @param {color} color 颜色
|
|
22
|
+
* @return 将颜色转换到 '#ffffff' 的格式
|
|
23
|
+
*/
|
|
24
|
+
export function toRGB(color: string): string {
|
|
25
|
+
// 如果已经是 rgb的格式
|
|
26
|
+
if (color[0] === '#' && color.length === 7) {
|
|
27
|
+
return color;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!iEl) {
|
|
31
|
+
// 防止防止在页头报错
|
|
32
|
+
iEl = createTmp();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
iEl.style.color = color;
|
|
36
|
+
|
|
37
|
+
let rst = document.defaultView.getComputedStyle(iEl, '').getPropertyValue('color');
|
|
38
|
+
|
|
39
|
+
const matches = RGB_REG.exec(rst) as string[];
|
|
40
|
+
const cArray: number[] = matches[1].split(/\s*,\s*/).map((s) => Number(s));
|
|
41
|
+
|
|
42
|
+
rst = arr2rgb(cArray);
|
|
43
|
+
|
|
44
|
+
return rst;
|
|
45
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,130 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export { default as find } from './find';
|
|
5
|
-
export { default as findIndex } from './find-index';
|
|
6
|
-
export { default as firstValue } from './first-value';
|
|
7
|
-
export { default as flatten } from './flatten';
|
|
8
|
-
export { default as flattenDeep } from './flatten-deep';
|
|
9
|
-
export { default as getRange } from './get-range';
|
|
10
|
-
export { default as pull } from './pull';
|
|
11
|
-
export { default as pullAt } from './pull-at';
|
|
12
|
-
export { default as reduce } from './reduce';
|
|
13
|
-
export { default as remove } from './remove';
|
|
14
|
-
export { default as sortBy } from './sort-by';
|
|
15
|
-
export { default as union } from './union';
|
|
16
|
-
export { default as uniq } from './uniq';
|
|
17
|
-
export { default as valuesOfKey } from './values-of-key';
|
|
18
|
-
export { default as head } from './head';
|
|
19
|
-
export { default as last } from './last';
|
|
20
|
-
export { default as startsWith } from './starts-with';
|
|
21
|
-
export { default as endsWith } from './ends-with';
|
|
22
|
-
export { default as filter } from './filter';
|
|
23
|
-
export { default as every } from './every';
|
|
24
|
-
export { default as some } from './some';
|
|
25
|
-
export { default as group } from './group';
|
|
26
|
-
export { default as groupBy } from './group-by';
|
|
27
|
-
export { default as groupToMap } from './group-to-map';
|
|
28
|
-
|
|
29
|
-
// event
|
|
30
|
-
export { default as getWrapBehavior } from './get-wrap-behavior';
|
|
31
|
-
export { default as wrapBehavior } from './wrap-behavior';
|
|
32
|
-
|
|
33
|
-
// format
|
|
34
|
-
export { default as number2color } from './number2color';
|
|
35
|
-
export { default as parseRadius } from './parse-radius';
|
|
36
|
-
|
|
37
|
-
// math
|
|
38
|
-
export { default as clamp } from './clamp';
|
|
39
|
-
export { default as fixedBase } from './fixed-base';
|
|
40
|
-
export { default as isDecimal } from './is-decimal';
|
|
41
|
-
export { default as isEven } from './is-even';
|
|
42
|
-
export { default as isInteger } from './is-integer';
|
|
43
|
-
export { default as isNegative } from './is-negative';
|
|
44
|
-
export { default as isNumberEqual } from './is-number-equal';
|
|
45
|
-
export { default as isOdd } from './is-odd';
|
|
46
|
-
export { default as isPositive } from './is-positive';
|
|
47
|
-
export { default as max } from './max';
|
|
48
|
-
export { default as maxBy } from './max-by';
|
|
49
|
-
export { default as min } from './min';
|
|
50
|
-
export { default as minBy } from './min-by';
|
|
51
|
-
export { default as mod } from './mod';
|
|
52
|
-
export { default as toDegree } from './to-degree';
|
|
53
|
-
export { default as toInteger } from './to-integer';
|
|
54
|
-
export { default as toRadian } from './to-radian';
|
|
55
|
-
|
|
56
|
-
// object
|
|
57
|
-
export { default as forIn } from './for-in';
|
|
58
|
-
export { default as has } from './has';
|
|
59
|
-
export { default as hasKey } from './has-key';
|
|
60
|
-
export { default as hasValue } from './has-value';
|
|
61
|
-
export { default as keys } from './keys';
|
|
62
|
-
export { default as isMatch } from './is-match';
|
|
63
|
-
export { default as values } from './values';
|
|
64
|
-
|
|
65
|
-
// string
|
|
66
|
-
export { default as lowerCase } from './lower-case';
|
|
67
|
-
export { default as lowerFirst } from './lower-first';
|
|
68
|
-
export { default as substitute } from './substitute';
|
|
69
|
-
export { default as upperCase } from './upper-case';
|
|
70
|
-
export { default as upperFirst } from './upper-first';
|
|
71
|
-
|
|
72
|
-
// type
|
|
73
|
-
export { default as getType } from './get-type';
|
|
74
|
-
export { default as isArguments } from './is-arguments';
|
|
75
|
-
export { default as isArray } from './is-array';
|
|
76
|
-
export { default as isArrayLike } from './is-array-like';
|
|
77
|
-
export { default as isBoolean } from './is-boolean';
|
|
78
|
-
export { default as isDate } from './is-date';
|
|
79
|
-
export { default as isError } from './is-error';
|
|
80
|
-
export { default as isFunction } from './is-function';
|
|
81
|
-
export { default as isFinite } from './is-finite';
|
|
82
|
-
export { default as isNil } from './is-nil';
|
|
83
|
-
export { default as isNull } from './is-null';
|
|
84
|
-
export { default as isNumber } from './is-number';
|
|
85
|
-
export { default as isObject } from './is-object';
|
|
86
|
-
export { default as isObjectLike } from './is-object-like';
|
|
87
|
-
export { default as isPlainObject } from './is-plain-object';
|
|
88
|
-
export { default as isPrototype } from './is-prototype';
|
|
89
|
-
export { default as isRegExp } from './is-reg-exp';
|
|
90
|
-
export { default as isString } from './is-string';
|
|
91
|
-
export { default as isType } from './is-type';
|
|
92
|
-
export { default as isUndefined } from './is-undefined';
|
|
93
|
-
export { default as isElement } from './is-element';
|
|
94
|
-
|
|
95
|
-
export { default as requestAnimationFrame } from './request-animation-frame';
|
|
96
|
-
export { default as clearAnimationFrame } from './clear-animation-frame';
|
|
97
|
-
|
|
98
|
-
// other
|
|
99
|
-
export { default as augment } from './augment';
|
|
100
|
-
export { default as clone } from './clone';
|
|
101
|
-
export { default as debounce } from './debounce';
|
|
102
|
-
export { default as memoize } from './memoize';
|
|
103
|
-
export { default as deepMix } from './deep-mix';
|
|
104
|
-
export { default as each } from './each';
|
|
105
|
-
export { default as extend } from './extend';
|
|
106
|
-
export { default as indexOf } from './index-of';
|
|
107
|
-
export { default as isEmpty } from './is-empty';
|
|
108
|
-
export { default as isEqual } from './is-equal';
|
|
109
|
-
export { default as isEqualWith } from './is-equal-with';
|
|
110
|
-
export { default as map } from './map';
|
|
111
|
-
export { default as mapValues } from './map-values';
|
|
112
|
-
export { default as mix, default as assign } from './mix';
|
|
113
|
-
export { default as get } from './get';
|
|
114
|
-
export { default as set } from './set';
|
|
115
|
-
export { default as pick } from './pick';
|
|
116
|
-
export { default as omit } from './omit';
|
|
117
|
-
export { default as throttle } from './throttle';
|
|
118
|
-
export { default as toArray } from './to-array';
|
|
119
|
-
export { default as toString } from './to-string';
|
|
120
|
-
export { default as uniqueId } from './unique-id';
|
|
121
|
-
export { default as noop } from './noop';
|
|
122
|
-
export { default as identity } from './identity';
|
|
123
|
-
export { default as size } from './size';
|
|
124
|
-
|
|
125
|
-
// text
|
|
126
|
-
export { default as measureTextWidth } from './measure-text-width';
|
|
127
|
-
export { default as getEllipsisText } from './get-ellipsis-text';
|
|
128
|
-
|
|
129
|
-
// 不知道为什么,需要把这个 export,不然 ts 会报类型错误
|
|
130
|
-
export { default as Cache } from './cache';
|
|
1
|
+
export * from './color';
|
|
2
|
+
export * from './matrix';
|
|
3
|
+
export * from './path';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 扩展方法,提供 gl-matrix 为提供的方法
|
|
3
|
+
* */
|
|
4
|
+
import { mat3, vec2 } from 'gl-matrix';
|
|
5
|
+
|
|
6
|
+
type mat3Type = [number, number, number, number, number, number, number, number, number];
|
|
7
|
+
|
|
8
|
+
function leftTranslate(out, a, v) {
|
|
9
|
+
const transMat: mat3Type = [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
10
|
+
mat3.fromTranslation(transMat, v);
|
|
11
|
+
return mat3.multiply(out, transMat, a);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function leftRotate(out, a, rad) {
|
|
15
|
+
const rotateMat: mat3Type = [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
16
|
+
mat3.fromRotation(rotateMat, rad);
|
|
17
|
+
return mat3.multiply(out, rotateMat, a);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function leftScale(out, a, v) {
|
|
21
|
+
const scaleMat: mat3Type = [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
22
|
+
mat3.fromScaling(scaleMat, v);
|
|
23
|
+
return mat3.multiply(out, scaleMat, a);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function leftMultiply(out, a, a1) {
|
|
27
|
+
return mat3.multiply(out, a1, a);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 根据 actions 来做 transform
|
|
31
|
+
* @param m
|
|
32
|
+
* @param actions
|
|
33
|
+
*/
|
|
34
|
+
export function transform(m: number[], actions: any[][]) {
|
|
35
|
+
const matrix = m ? [].concat(m) : [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
36
|
+
|
|
37
|
+
for (let i = 0, len = actions.length; i < len; i++) {
|
|
38
|
+
const action = actions[i];
|
|
39
|
+
switch (action[0]) {
|
|
40
|
+
case 't':
|
|
41
|
+
leftTranslate(matrix, matrix, [action[1], action[2]]);
|
|
42
|
+
break;
|
|
43
|
+
case 's':
|
|
44
|
+
leftScale(matrix, matrix, [action[1], action[2]]);
|
|
45
|
+
break;
|
|
46
|
+
case 'r':
|
|
47
|
+
leftRotate(matrix, matrix, action[1]);
|
|
48
|
+
break;
|
|
49
|
+
case 'm':
|
|
50
|
+
leftMultiply(matrix, matrix, action[1]);
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return matrix;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 向量 v1 到 向量 v2 夹角的方向
|
|
62
|
+
* @param {Array} v1 向量
|
|
63
|
+
* @param {Array} v2 向量
|
|
64
|
+
* @return {Boolean} >= 0 顺时针 < 0 逆时针
|
|
65
|
+
*/
|
|
66
|
+
export function direction(v1: number[], v2: number[]): number {
|
|
67
|
+
return v1[0] * v2[1] - v2[0] * v1[1];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 二维向量 v1 到 v2 的夹角
|
|
72
|
+
* @param v1
|
|
73
|
+
* @param v2
|
|
74
|
+
* @param direct
|
|
75
|
+
*/
|
|
76
|
+
export function angleTo(v1: [number, number], v2: [number, number], direct?: boolean): number {
|
|
77
|
+
const ang = vec2.angle(v1, v2);
|
|
78
|
+
const angleLargeThanPI = direction(v1, v2) >= 0;
|
|
79
|
+
if (direct) {
|
|
80
|
+
if (angleLargeThanPI) {
|
|
81
|
+
return Math.PI * 2 - ang;
|
|
82
|
+
}
|
|
83
|
+
return ang;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (angleLargeThanPI) {
|
|
87
|
+
return ang;
|
|
88
|
+
}
|
|
89
|
+
return Math.PI * 2 - ang;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 计算二维向量的垂直向量
|
|
94
|
+
* @param out
|
|
95
|
+
* @param v
|
|
96
|
+
* @param flag
|
|
97
|
+
*/
|
|
98
|
+
export function vertical(out: number[], v: number[], flag: boolean): number[] {
|
|
99
|
+
if (flag) {
|
|
100
|
+
out[0] = v[1];
|
|
101
|
+
out[1] = -1 * v[0];
|
|
102
|
+
} else {
|
|
103
|
+
out[0] = -1 * v[1];
|
|
104
|
+
out[1] = v[0];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { vec2 } from 'gl-matrix';
|
|
2
|
+
import type { PathCommand } from './types';
|
|
3
|
+
|
|
4
|
+
type Pos = [number, number];
|
|
5
|
+
|
|
6
|
+
function smoothBezier(points: Pos[], smooth: number, isLoop: boolean, constraint: Pos[]) {
|
|
7
|
+
const cps: vec2[] = [];
|
|
8
|
+
const hasConstraint = !!constraint;
|
|
9
|
+
|
|
10
|
+
let prevPoint: Pos;
|
|
11
|
+
let nextPoint: Pos;
|
|
12
|
+
let min: vec2;
|
|
13
|
+
let max: vec2;
|
|
14
|
+
let nextCp0: vec2;
|
|
15
|
+
let cp1: vec2;
|
|
16
|
+
let cp0: vec2;
|
|
17
|
+
|
|
18
|
+
if (hasConstraint) {
|
|
19
|
+
[min, max] = constraint;
|
|
20
|
+
for (let i = 0, l = points.length; i < l; i += 1) {
|
|
21
|
+
const point = points[i];
|
|
22
|
+
min = vec2.min([0, 0], min, point);
|
|
23
|
+
max = vec2.max([0, 0], max, point);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (let i = 0, len = points.length; i < len; i += 1) {
|
|
28
|
+
const point = points[i];
|
|
29
|
+
if (i === 0 && !isLoop) {
|
|
30
|
+
cp0 = point;
|
|
31
|
+
} else if (i === len - 1 && !isLoop) {
|
|
32
|
+
cp1 = point;
|
|
33
|
+
cps.push(cp0);
|
|
34
|
+
cps.push(cp1);
|
|
35
|
+
} else {
|
|
36
|
+
const prevIdx = [i ? i - 1 : len - 1, i - 1][isLoop ? 0 : 1];
|
|
37
|
+
prevPoint = points[prevIdx];
|
|
38
|
+
nextPoint = points[isLoop ? (i + 1) % len : i + 1];
|
|
39
|
+
|
|
40
|
+
let v: vec2 = [0, 0];
|
|
41
|
+
v = vec2.sub(v, nextPoint, prevPoint);
|
|
42
|
+
v = vec2.scale(v, v, smooth);
|
|
43
|
+
|
|
44
|
+
let d0 = vec2.distance(point, prevPoint);
|
|
45
|
+
let d1 = vec2.distance(point, nextPoint);
|
|
46
|
+
|
|
47
|
+
const sum = d0 + d1;
|
|
48
|
+
if (sum !== 0) {
|
|
49
|
+
d0 /= sum;
|
|
50
|
+
d1 /= sum;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let v1 = vec2.scale([0, 0], v, -d0);
|
|
54
|
+
let v2 = vec2.scale([0, 0], v, d1);
|
|
55
|
+
|
|
56
|
+
cp1 = vec2.add([0, 0], point, v1);
|
|
57
|
+
nextCp0 = vec2.add([0, 0], point, v2);
|
|
58
|
+
|
|
59
|
+
// 下一个控制点必须在这个点和下一个点之间
|
|
60
|
+
nextCp0 = vec2.min([0, 0], nextCp0, vec2.max([0, 0], nextPoint, point));
|
|
61
|
+
nextCp0 = vec2.max([0, 0], nextCp0, vec2.min([0, 0], nextPoint, point));
|
|
62
|
+
|
|
63
|
+
// 重新计算 cp1 的值
|
|
64
|
+
v1 = vec2.sub([0, 0], nextCp0, point);
|
|
65
|
+
v1 = vec2.scale([0, 0], v1, -d0 / d1);
|
|
66
|
+
cp1 = vec2.add([0, 0], point, v1);
|
|
67
|
+
|
|
68
|
+
// 上一个控制点必须要在上一个点和这一个点之间
|
|
69
|
+
cp1 = vec2.min([0, 0], cp1, vec2.max([0, 0], prevPoint, point));
|
|
70
|
+
cp1 = vec2.max([0, 0], cp1, vec2.min([0, 0], prevPoint, point));
|
|
71
|
+
|
|
72
|
+
// 重新计算 nextCp0 的值
|
|
73
|
+
v2 = vec2.sub([0, 0], point, cp1);
|
|
74
|
+
v2 = vec2.scale([0, 0], v2, d1 / d0);
|
|
75
|
+
nextCp0 = vec2.add([0, 0], point, v2);
|
|
76
|
+
|
|
77
|
+
if (hasConstraint) {
|
|
78
|
+
cp1 = vec2.max([0, 0], cp1, min);
|
|
79
|
+
cp1 = vec2.min([0, 0], cp1, max);
|
|
80
|
+
nextCp0 = vec2.max([0, 0], nextCp0, min);
|
|
81
|
+
nextCp0 = vec2.min([0, 0], nextCp0, max);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
cps.push(cp0);
|
|
85
|
+
cps.push(cp1);
|
|
86
|
+
cp0 = nextCp0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (isLoop) {
|
|
91
|
+
cps.push(cps.shift());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return cps;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* create bezier spline from catmull rom spline
|
|
99
|
+
* @param {Array} crp Catmull Rom Points
|
|
100
|
+
* @param {boolean} z Spline is loop
|
|
101
|
+
* @param {Array} constraint Constraint
|
|
102
|
+
*/
|
|
103
|
+
export function catmullRom2Bezier(
|
|
104
|
+
crp: number[],
|
|
105
|
+
z = false,
|
|
106
|
+
constraint: Pos[] = [
|
|
107
|
+
[0, 0],
|
|
108
|
+
[1, 1],
|
|
109
|
+
],
|
|
110
|
+
): PathCommand[] {
|
|
111
|
+
const isLoop = !!z;
|
|
112
|
+
const pointList: Pos[] = [];
|
|
113
|
+
for (let i = 0, l = crp.length; i < l; i += 2) {
|
|
114
|
+
pointList.push([crp[i], crp[i + 1]]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
|
|
118
|
+
const len = pointList.length;
|
|
119
|
+
const d1: PathCommand[] = [];
|
|
120
|
+
|
|
121
|
+
let cp1: vec2;
|
|
122
|
+
let cp2: vec2;
|
|
123
|
+
let p: Pos;
|
|
124
|
+
|
|
125
|
+
for (let i = 0; i < len - 1; i += 1) {
|
|
126
|
+
cp1 = controlPointList[i * 2];
|
|
127
|
+
cp2 = controlPointList[i * 2 + 1];
|
|
128
|
+
p = pointList[i + 1];
|
|
129
|
+
|
|
130
|
+
d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isLoop) {
|
|
134
|
+
cp1 = controlPointList[len];
|
|
135
|
+
cp2 = controlPointList[len + 1];
|
|
136
|
+
[p] = pointList;
|
|
137
|
+
|
|
138
|
+
d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]]);
|
|
139
|
+
}
|
|
140
|
+
return d1;
|
|
141
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import isEqual from 'fast-deep-equal';
|
|
2
|
+
|
|
3
|
+
export interface DiffType {
|
|
4
|
+
type: string;
|
|
5
|
+
min: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getMinDiff(del: number, add: number, modify: number): DiffType {
|
|
9
|
+
let type = null;
|
|
10
|
+
let min = modify;
|
|
11
|
+
if (add < min) {
|
|
12
|
+
min = add;
|
|
13
|
+
type = 'add';
|
|
14
|
+
}
|
|
15
|
+
if (del < min) {
|
|
16
|
+
min = del;
|
|
17
|
+
type = 'del';
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
type,
|
|
21
|
+
min,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* https://en.wikipedia.org/wiki/Levenshtein_distance
|
|
27
|
+
* 计算两条path的编辑距离
|
|
28
|
+
*/
|
|
29
|
+
const levenshteinDistance = function (source: string, target: string): DiffType[][] {
|
|
30
|
+
const sourceLen = source.length;
|
|
31
|
+
const targetLen = target.length;
|
|
32
|
+
let sourceSegment, targetSegment;
|
|
33
|
+
let temp = 0;
|
|
34
|
+
if (sourceLen === 0 || targetLen === 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const dist = [];
|
|
38
|
+
for (let i = 0; i <= sourceLen; i++) {
|
|
39
|
+
dist[i] = [];
|
|
40
|
+
dist[i][0] = { min: i };
|
|
41
|
+
}
|
|
42
|
+
for (let j = 0; j <= targetLen; j++) {
|
|
43
|
+
dist[0][j] = { min: j };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (let i = 1; i <= sourceLen; i++) {
|
|
47
|
+
sourceSegment = source[i - 1];
|
|
48
|
+
for (let j = 1; j <= targetLen; j++) {
|
|
49
|
+
targetSegment = target[j - 1];
|
|
50
|
+
if (isEqual(sourceSegment, targetSegment)) {
|
|
51
|
+
temp = 0;
|
|
52
|
+
} else {
|
|
53
|
+
temp = 1;
|
|
54
|
+
}
|
|
55
|
+
const del = dist[i - 1][j].min + 1;
|
|
56
|
+
const add = dist[i][j - 1].min + 1;
|
|
57
|
+
const modify = dist[i - 1][j - 1].min + temp;
|
|
58
|
+
dist[i][j] = getMinDiff(del, add, modify);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return dist;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function fillPathByDiff(source: string, target: string) {
|
|
65
|
+
const diffMatrix = levenshteinDistance(source, target);
|
|
66
|
+
let sourceLen = source.length;
|
|
67
|
+
const targetLen = target.length;
|
|
68
|
+
const changes = [];
|
|
69
|
+
let index = 1;
|
|
70
|
+
let minPos = 1;
|
|
71
|
+
// 如果source和target不是完全不相等
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
if (diffMatrix[sourceLen][targetLen] !== sourceLen) {
|
|
74
|
+
// 获取从source到target所需改动
|
|
75
|
+
for (let i = 1; i <= sourceLen; i++) {
|
|
76
|
+
let min = diffMatrix[i][i].min;
|
|
77
|
+
minPos = i;
|
|
78
|
+
for (let j = index; j <= targetLen; j++) {
|
|
79
|
+
if (diffMatrix[i][j].min < min) {
|
|
80
|
+
min = diffMatrix[i][j].min;
|
|
81
|
+
minPos = j;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
index = minPos;
|
|
85
|
+
if (diffMatrix[i][index].type) {
|
|
86
|
+
changes.push({ index: i - 1, type: diffMatrix[i][index].type });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// 对source进行增删path
|
|
90
|
+
for (let i = changes.length - 1; i >= 0; i--) {
|
|
91
|
+
index = changes[i].index;
|
|
92
|
+
if (changes[i].type === 'add') {
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
source.splice(index, 0, [].concat(source[index]));
|
|
95
|
+
} else {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
source.splice(index, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// source尾部补齐
|
|
103
|
+
sourceLen = source.length;
|
|
104
|
+
if (sourceLen < targetLen) {
|
|
105
|
+
for (let i = 0; i < targetLen - sourceLen; i++) {
|
|
106
|
+
if (source[sourceLen - 1][0] === 'z' || source[sourceLen - 1][0] === 'Z') {
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
source.splice(sourceLen - 2, 0, source[sourceLen - 2]);
|
|
109
|
+
} else {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
source.push(source[sourceLen - 1]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return source;
|
|
116
|
+
}
|