@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,37 @@
|
|
|
1
|
+
// export function getPointAtSegLength(p1x: number, p1y: number, c1x: number, c1y: number, c2x: number, c2y: number, p2x: number, p2y: number, t: number) {
|
|
2
|
+
// const t1 = 1 - t;
|
|
3
|
+
// return {
|
|
4
|
+
// x: (t1 ** 3) * p1x
|
|
5
|
+
// + t1 * t1 * 3 * t * c1x
|
|
6
|
+
// + t1 * 3 * t * t * c2x
|
|
7
|
+
// + (t ** 3) * p2x,
|
|
8
|
+
// y: (t1 ** 3) * p1y
|
|
9
|
+
// + t1 * t1 * 3 * t * c1y
|
|
10
|
+
// + t1 * 3 * t * t * c2y
|
|
11
|
+
// + (t ** 3) * p2y,
|
|
12
|
+
// };
|
|
13
|
+
// }
|
|
14
|
+
|
|
15
|
+
// export function midPoint(a: number[], b: number[], t: number) {
|
|
16
|
+
// const ax = a[0];
|
|
17
|
+
// const ay = a[1];
|
|
18
|
+
// const bx = b[0];
|
|
19
|
+
// const by = b[1];
|
|
20
|
+
// return [ax + (bx - ax) * t, ay + (by - ay) * t];
|
|
21
|
+
// }
|
|
22
|
+
|
|
23
|
+
export function lineToCubic(x1: number, y1: number, x2: number, y2: number) {
|
|
24
|
+
return [x1, y1, x2, y2, x2, y2];
|
|
25
|
+
// const t = 0.5;
|
|
26
|
+
// const p0 = [x1, y1];
|
|
27
|
+
// const p1 = [x2, y2];
|
|
28
|
+
// const p2 = midPoint(p0, p1, t);
|
|
29
|
+
// const p3 = midPoint(p1, p2, t);
|
|
30
|
+
// const p4 = midPoint(p2, p3, t);
|
|
31
|
+
// const p5 = midPoint(p3, p4, t);
|
|
32
|
+
// const p6 = midPoint(p4, p5, t);
|
|
33
|
+
// const cp1 = getPointAtSegLength.apply(0, p0.concat(p2, p4, p6, t));
|
|
34
|
+
// const cp2 = getPointAtSegLength.apply(0, p6.concat(p5, p3, p1, 0));
|
|
35
|
+
|
|
36
|
+
// return [cp1.x, cp1.y, cp2.x, cp2.y, x2, y2];
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function quadToCubic(x1: number, y1: number, qx: number, qy: number, x2: number, y2: number) {
|
|
2
|
+
const r13 = 1 / 3;
|
|
3
|
+
const r23 = 2 / 3;
|
|
4
|
+
return [
|
|
5
|
+
r13 * x1 + r23 * qx, // cpx1
|
|
6
|
+
r13 * y1 + r23 * qy, // cpy1
|
|
7
|
+
r13 * x2 + r23 * qx, // cpx2
|
|
8
|
+
r13 * y2 + r23 * qy, // cpy2
|
|
9
|
+
x2,
|
|
10
|
+
y2, // x,y
|
|
11
|
+
];
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PathCommand, ProcessParams } from '../types';
|
|
2
|
+
import { arcToCubic } from './arc-2-cubic';
|
|
3
|
+
import { quadToCubic } from './quad-2-cubic';
|
|
4
|
+
import { lineToCubic } from './line-2-cubic';
|
|
5
|
+
|
|
6
|
+
export function segmentToCubic(segment: PathCommand, params: ProcessParams): PathCommand {
|
|
7
|
+
if ('TQ'.indexOf(segment[0]) < 0) {
|
|
8
|
+
params.qx = null;
|
|
9
|
+
params.qy = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const [s1, s2] = segment.slice(1);
|
|
13
|
+
|
|
14
|
+
switch (segment[0]) {
|
|
15
|
+
case 'M':
|
|
16
|
+
params.x = s1 as number;
|
|
17
|
+
params.y = s2 as number;
|
|
18
|
+
return segment;
|
|
19
|
+
case 'A':
|
|
20
|
+
return ['C'].concat(
|
|
21
|
+
arcToCubic.apply(0, [params.x1, params.y1].concat(segment.slice(1) as number[])),
|
|
22
|
+
) as PathCommand;
|
|
23
|
+
case 'Q':
|
|
24
|
+
params.qx = s1 as number;
|
|
25
|
+
params.qy = s2 as number;
|
|
26
|
+
return ['C'].concat(
|
|
27
|
+
quadToCubic.apply(0, [params.x1, params.y1].concat(segment.slice(1) as number[])),
|
|
28
|
+
) as PathCommand;
|
|
29
|
+
case 'L':
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return ['C'].concat(lineToCubic(params.x1, params.y1, segment[1], segment[2])) as PathCommand;
|
|
32
|
+
case 'H':
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
return ['C'].concat(lineToCubic(params.x1, params.y1, segment[1], params.y1)) as PathCommand;
|
|
35
|
+
case 'V':
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return ['C'].concat(lineToCubic(params.x1, params.y1, params.x1, segment[1])) as PathCommand;
|
|
38
|
+
case 'Z':
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
return ['C'].concat(lineToCubic(params.x1, params.y1, params.x, params.y)) as PathCommand;
|
|
41
|
+
default:
|
|
42
|
+
}
|
|
43
|
+
return segment;
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Ele {
|
|
2
|
+
[idx: number]: number | string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function rectPath(x: number, y: number, w: number, h: number, r?: number): Ele[] {
|
|
6
|
+
if (r) {
|
|
7
|
+
return [
|
|
8
|
+
['M', +x + +r, y],
|
|
9
|
+
['l', w - r * 2, 0],
|
|
10
|
+
['a', r, r, 0, 0, 1, r, r],
|
|
11
|
+
['l', 0, h - r * 2],
|
|
12
|
+
['a', r, r, 0, 0, 1, -r, r],
|
|
13
|
+
['l', r * 2 - w, 0],
|
|
14
|
+
['a', r, r, 0, 0, 1, -r, -r],
|
|
15
|
+
['l', 0, r * 2 - h],
|
|
16
|
+
['a', r, r, 0, 0, 1, r, -r],
|
|
17
|
+
['z'],
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
return [['M', x, y], ['l', w, 0], ['l', 0, h], ['l', -w, 0], ['z']];
|
|
21
|
+
// res.parsePathArray = parsePathArray;
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type A = ['a' | 'A', number, number, number, number, number, number, number];
|
|
2
|
+
type C = ['c' | 'C', number, number, number, number, number, number];
|
|
3
|
+
type O = ['o' | 'O', number, number];
|
|
4
|
+
type H = ['h' | 'H', number];
|
|
5
|
+
type L = ['l' | 'L', number, number];
|
|
6
|
+
type M = ['m' | 'M', number, number];
|
|
7
|
+
type R = ['r' | 'R', number, number, number, number];
|
|
8
|
+
type Q = ['q' | 'Q', number, number, number, number];
|
|
9
|
+
type S = ['s' | 'S', number, number, number, number, number, number, number];
|
|
10
|
+
type T = ['t' | 'T', number, number];
|
|
11
|
+
type V = ['v' | 'V', number];
|
|
12
|
+
type U = ['u' | 'U', number, number, number];
|
|
13
|
+
type Z = ['z' | 'Z'];
|
|
14
|
+
export type PathCommand = A | C | O | H | L | M | R | Q | S | T | V | U | Z;
|
|
15
|
+
|
|
16
|
+
export type ProcessParams = {
|
|
17
|
+
x1: number;
|
|
18
|
+
y1: number;
|
|
19
|
+
x2: number;
|
|
20
|
+
y2: number;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
qx: number | null;
|
|
24
|
+
qy: number | null;
|
|
25
|
+
};
|
package/src/augment.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import mix from './mix';
|
|
2
|
-
import isFunction from './is-function';
|
|
3
|
-
import toArray from './to-array';
|
|
4
|
-
|
|
5
|
-
const augment = function(...args:any[]) {
|
|
6
|
-
const c = args[0];
|
|
7
|
-
for (let i = 1; i < args.length; i++) {
|
|
8
|
-
let obj = args[i];
|
|
9
|
-
if (isFunction(obj)) {
|
|
10
|
-
obj = obj.prototype;
|
|
11
|
-
}
|
|
12
|
-
mix(c.prototype, obj);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default augment;
|
package/src/cache.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* k-v 存储
|
|
3
|
-
*/
|
|
4
|
-
export default class <T> {
|
|
5
|
-
map: { [key: string]: T } = {};
|
|
6
|
-
|
|
7
|
-
has(key: string): boolean {
|
|
8
|
-
return this.map[key] !== undefined;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get(key: string, def?: T): T | undefined {
|
|
12
|
-
const v = this.map[key];
|
|
13
|
-
return v === undefined ? def : v;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
set(key: string, value: T): void {
|
|
17
|
-
this.map[key] = value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
clear() {
|
|
21
|
-
this.map = {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
delete(key: string) {
|
|
25
|
-
delete this.map[key];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
size(): number {
|
|
29
|
-
return Object.keys(this.map).length;
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/clamp.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default function cancelAnimationFrame(handler: number) {
|
|
2
|
-
const method = window.cancelAnimationFrame ||
|
|
3
|
-
window.webkitCancelAnimationFrame ||
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
window.mozCancelAnimationFrame ||
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
window.msCancelAnimationFrame ||
|
|
8
|
-
clearTimeout;
|
|
9
|
-
|
|
10
|
-
method(handler);
|
|
11
|
-
};
|
package/src/clone.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
|
|
3
|
-
const clone = function(obj) {
|
|
4
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
5
|
-
return obj;
|
|
6
|
-
}
|
|
7
|
-
let rst;
|
|
8
|
-
if (isArray(obj)) {
|
|
9
|
-
rst = [];
|
|
10
|
-
for (let i = 0, l = obj.length; i < l; i++) {
|
|
11
|
-
if (typeof obj[i] === 'object' && obj[i] != null) {
|
|
12
|
-
rst[i] = clone(obj[i]);
|
|
13
|
-
} else {
|
|
14
|
-
rst[i] = obj[i];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
} else {
|
|
18
|
-
rst = {};
|
|
19
|
-
for (const k in obj) {
|
|
20
|
-
if (typeof obj[k] === 'object' && obj[k] != null) {
|
|
21
|
-
rst[k] = clone(obj[k]);
|
|
22
|
-
} else {
|
|
23
|
-
rst[k] = obj[k];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return rst;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default clone;
|
package/src/contains.ts
DELETED
package/src/debounce.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function debounce(func: Function, wait?: number, immediate?: boolean) {
|
|
3
|
-
let timeout;
|
|
4
|
-
return function() {
|
|
5
|
-
const context = this,
|
|
6
|
-
args = arguments;
|
|
7
|
-
const later = function() {
|
|
8
|
-
timeout = null;
|
|
9
|
-
if (!immediate) {
|
|
10
|
-
func.apply(context, args);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const callNow = immediate && !timeout;
|
|
14
|
-
clearTimeout(timeout);
|
|
15
|
-
timeout = setTimeout(later, wait);
|
|
16
|
-
if (callNow) {
|
|
17
|
-
func.apply(context, args);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default debounce;
|
package/src/deep-mix.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
import isPlainObject from './is-plain-object';
|
|
3
|
-
|
|
4
|
-
const MAX_MIX_LEVEL = 5;
|
|
5
|
-
|
|
6
|
-
function _deepMix(dist, src, level?, maxLevel?) {
|
|
7
|
-
level = level || 0;
|
|
8
|
-
maxLevel = maxLevel || MAX_MIX_LEVEL;
|
|
9
|
-
for (const key in src) {
|
|
10
|
-
if (src.hasOwnProperty(key)) {
|
|
11
|
-
const value = src[key];
|
|
12
|
-
if (value !== null && isPlainObject(value)) {
|
|
13
|
-
if (!isPlainObject(dist[key])) {
|
|
14
|
-
dist[key] = {};
|
|
15
|
-
}
|
|
16
|
-
if (level < maxLevel) {
|
|
17
|
-
_deepMix(dist[key], value, level + 1, maxLevel);
|
|
18
|
-
} else {
|
|
19
|
-
dist[key] = src[key];
|
|
20
|
-
}
|
|
21
|
-
} else if (isArray(value)) {
|
|
22
|
-
dist[key] = [];
|
|
23
|
-
dist[key] = dist[key].concat(value);
|
|
24
|
-
} else if (value !== undefined) {
|
|
25
|
-
dist[key] = value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// todo 重写
|
|
32
|
-
const deepMix = function(rst:any, ...args:any[]) {
|
|
33
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
34
|
-
_deepMix(rst, args[i]);
|
|
35
|
-
}
|
|
36
|
-
return rst;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default deepMix;
|
package/src/difference.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import filter from './filter';
|
|
2
|
-
import contains from './contains';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Flattens `array` a single level deep.
|
|
6
|
-
*
|
|
7
|
-
* @param {Array} arr The array to inspect.
|
|
8
|
-
* @param {Array} values The values to exclude.
|
|
9
|
-
* @return {Array} Returns the new array of filtered values.
|
|
10
|
-
* @example
|
|
11
|
-
* difference([2, 1], [2, 3]); // => [1]
|
|
12
|
-
*/
|
|
13
|
-
const difference = function<T>(arr: T[], values: T[] = []): T[] {
|
|
14
|
-
return filter(arr, (value: any) => !contains(values, value));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default difference;
|
package/src/each.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
import isObject from './is-object';
|
|
3
|
-
|
|
4
|
-
function each (elements: any[] | object, func: (v: any, k: any) => any): void {
|
|
5
|
-
if (!elements) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
let rst;
|
|
9
|
-
if (isArray(elements)) {
|
|
10
|
-
for (let i = 0, len = elements.length; i < len; i++) {
|
|
11
|
-
rst = func(elements[i], i);
|
|
12
|
-
if (rst === false) {
|
|
13
|
-
break;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
} else if (isObject(elements)) {
|
|
17
|
-
for (const k in elements) {
|
|
18
|
-
if (elements.hasOwnProperty(k)) {
|
|
19
|
-
rst = func(elements[k], k);
|
|
20
|
-
if (rst === false) {
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default each;
|
package/src/ends-with.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
import isString from './is-string';
|
|
3
|
-
|
|
4
|
-
function endsWith(arr: string, e: string): boolean;
|
|
5
|
-
function endsWith<T>(arr: T[], e: T): boolean;
|
|
6
|
-
function endsWith<T>(arr: string | T[], e: string | T): boolean {
|
|
7
|
-
return (isArray(arr) || isString(arr)) ? arr[arr.length - 1] === e : false;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default endsWith;
|
package/src/every.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 只要有一个不满足条件就返回 false
|
|
3
|
-
* @param arr
|
|
4
|
-
* @param func
|
|
5
|
-
*/
|
|
6
|
-
const every = 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 false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return true;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default every;
|
package/src/extend.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import mix from './mix';
|
|
2
|
-
import isFunction from './is-function';
|
|
3
|
-
|
|
4
|
-
const extend = function(subclass, superclass, overrides?, staticOverrides?) {
|
|
5
|
-
// 如果只提供父类构造函数,则自动生成子类构造函数
|
|
6
|
-
if (!isFunction(superclass)) {
|
|
7
|
-
overrides = superclass;
|
|
8
|
-
superclass = subclass;
|
|
9
|
-
subclass = function() {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const create = Object.create ?
|
|
13
|
-
function(proto, c) {
|
|
14
|
-
return Object.create(proto, {
|
|
15
|
-
constructor: {
|
|
16
|
-
value: c
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
} :
|
|
20
|
-
function(proto, c) {
|
|
21
|
-
function Tmp() {}
|
|
22
|
-
Tmp.prototype = proto;
|
|
23
|
-
const o = new Tmp();
|
|
24
|
-
o.constructor = c;
|
|
25
|
-
return o;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const superObj = create(superclass.prototype, subclass); // new superclass(),//实例化父类作为子类的prototype
|
|
29
|
-
subclass.prototype = mix(superObj, subclass.prototype); // 指定子类的prototype
|
|
30
|
-
subclass.superclass = create(superclass.prototype, superclass);
|
|
31
|
-
mix(superObj, overrides);
|
|
32
|
-
mix(subclass, staticOverrides);
|
|
33
|
-
return subclass;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default extend;
|
package/src/filter.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import isArrayLike from './is-array-like';
|
|
2
|
-
|
|
3
|
-
const filter = function <T>(arr: T[], func: (v: T, idx: number) => boolean): T[] {
|
|
4
|
-
if (!isArrayLike(arr)) {
|
|
5
|
-
return arr;
|
|
6
|
-
}
|
|
7
|
-
const result: T[] = [];
|
|
8
|
-
for (let index = 0; index < arr.length; index++) {
|
|
9
|
-
const value = arr[index];
|
|
10
|
-
if (func(value, index)) {
|
|
11
|
-
result.push(value);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default filter;
|
package/src/find-index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function findIndex<T>(arr: T[], predicate: (item: T, idx?: number) => boolean, fromIndex: number = 0): number {
|
|
2
|
-
for (let i = fromIndex; i < arr.length; i ++) {
|
|
3
|
-
if (predicate(arr[i], i)) {
|
|
4
|
-
// 找到终止循环
|
|
5
|
-
return i;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return -1;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default findIndex;
|
package/src/find.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import isFunction from './is-function';
|
|
2
|
-
import isMatch from './is-match';
|
|
3
|
-
import isArray from './is-array';
|
|
4
|
-
import isPlainObject from './is-plain-object';
|
|
5
|
-
|
|
6
|
-
function find<T>(arr: T[], predicate: Function): T;
|
|
7
|
-
function find<T>(arr: T[], predicate: object): T;
|
|
8
|
-
|
|
9
|
-
function find<T>(arr: T[], predicate: Function | object): T {
|
|
10
|
-
if (!isArray(arr)) return null;
|
|
11
|
-
|
|
12
|
-
let _predicate;
|
|
13
|
-
if (isFunction(predicate)) {
|
|
14
|
-
_predicate = predicate;
|
|
15
|
-
}
|
|
16
|
-
if (isPlainObject(predicate)) {
|
|
17
|
-
_predicate = a => isMatch(a, predicate);
|
|
18
|
-
}
|
|
19
|
-
if (_predicate) {
|
|
20
|
-
for (let i = 0; i < arr.length; i += 1) {
|
|
21
|
-
if (_predicate(arr[i])) {
|
|
22
|
-
return arr[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default find;
|
package/src/first-value.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import isNil from './is-nil';
|
|
2
|
-
import isArray from './is-array';
|
|
3
|
-
|
|
4
|
-
const firstValue = function(data: object[], name: string): any {
|
|
5
|
-
let rst = null;
|
|
6
|
-
for (let i = 0; i < data.length; i++) {
|
|
7
|
-
const obj = data[i];
|
|
8
|
-
const value = obj[name];
|
|
9
|
-
if (!isNil(value)) {
|
|
10
|
-
if (isArray(value)) {
|
|
11
|
-
rst = value[0]; // todo 这里是否应该使用递归,调用 firstValue @绝云
|
|
12
|
-
} else {
|
|
13
|
-
rst = value;
|
|
14
|
-
}
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return rst;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default firstValue;
|
package/src/fixed-base.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const fixedBase = function(v: number, base: number | string): number {
|
|
2
|
-
const str = base.toString();
|
|
3
|
-
const index = str.indexOf('.');
|
|
4
|
-
if (index === -1) {
|
|
5
|
-
return Math.round(v);
|
|
6
|
-
}
|
|
7
|
-
let length = str.substr(index + 1).length;
|
|
8
|
-
if (length > 20) {
|
|
9
|
-
length = 20;
|
|
10
|
-
}
|
|
11
|
-
return parseFloat(v.toFixed(length));
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default fixedBase;
|
package/src/flatten-deep.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Flattens `array` a single level deep.
|
|
5
|
-
*
|
|
6
|
-
* @param {Array} arr The array to flatten.
|
|
7
|
-
* @param {Array} result The array to return.
|
|
8
|
-
* @return {Array} Returns the new flattened array.
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* flattenDeep([1, [2, [3, [4]], 5]]); // => [1, 2, 3, 4, 5]
|
|
12
|
-
*/
|
|
13
|
-
const flattenDeep = function(arr: any[], result: any[] = []): any[] {
|
|
14
|
-
if (!isArray(arr)) {
|
|
15
|
-
result.push(arr);
|
|
16
|
-
} else {
|
|
17
|
-
for (let i = 0; i < arr.length; i += 1) {
|
|
18
|
-
flattenDeep(arr[i], result);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default flattenDeep;
|
package/src/flatten.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import isArray from './is-array';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Flattens `array` a single level deep.
|
|
5
|
-
*
|
|
6
|
-
* @param {Array} arr The array to flatten.
|
|
7
|
-
* @return {Array} Returns the new flattened array.
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
|
|
11
|
-
*/
|
|
12
|
-
const flatten = function <T>(arr: T[]): T[] {
|
|
13
|
-
if (!isArray(arr)) {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
let rst: T[] = [];
|
|
17
|
-
for (let i = 0; i < arr.length; i++) {
|
|
18
|
-
rst = rst.concat(arr[i]);
|
|
19
|
-
}
|
|
20
|
-
return rst;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default flatten;
|
package/src/for-in.ts
DELETED
package/src/get-ellipsis-text.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import isString from './is-string';
|
|
2
|
-
import toString from './to-string';
|
|
3
|
-
import { Font, default as measureTextWidth } from './measure-text-width';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 获取文本的 ... 文本。
|
|
7
|
-
* 算法(减少每次 measureText 的长度,measureText 的性能跟字符串时间相关):
|
|
8
|
-
* 1. 先通过 STEP 逐步计算,找到最后一个小于 maxWidth 的字符串
|
|
9
|
-
* 2. 然后对最后这个字符串二分计算
|
|
10
|
-
* @param text 需要计算的文本, 由于历史原因 除了支持string,还支持空值,number和数组等
|
|
11
|
-
* @param maxWidth 最大宽度
|
|
12
|
-
* @param font 字体
|
|
13
|
-
* @param str 要替换的文本
|
|
14
|
-
*/
|
|
15
|
-
export default (text: string | number, maxWidth: number, font?: Font, str: string = '...') => {
|
|
16
|
-
const STEP = 16; // 每次 16,调参工程师
|
|
17
|
-
const PLACEHOLDER_WIDTH = measureTextWidth(str, font);
|
|
18
|
-
let leftText = !isString(text) ? toString(text) : text;
|
|
19
|
-
|
|
20
|
-
let leftWidth = maxWidth;
|
|
21
|
-
|
|
22
|
-
const r = []; // 最终的分段字符串
|
|
23
|
-
let currentText;
|
|
24
|
-
let currentWidth;
|
|
25
|
-
|
|
26
|
-
if (measureTextWidth(text, font) <= maxWidth) {
|
|
27
|
-
return text;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 首先通过 step 计算,找出最大的未超出长度的
|
|
31
|
-
// eslint-disable-next-line no-constant-condition
|
|
32
|
-
while (true) {
|
|
33
|
-
// 更新字符串
|
|
34
|
-
currentText = leftText.substr(0, STEP);
|
|
35
|
-
// 计算宽度
|
|
36
|
-
currentWidth = measureTextWidth(currentText, font);
|
|
37
|
-
// 超出剩余宽度,则停止
|
|
38
|
-
if (currentWidth + PLACEHOLDER_WIDTH > leftWidth) {
|
|
39
|
-
if (currentWidth > leftWidth) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
r.push(currentText);
|
|
45
|
-
// 没有超出,则计算剩余宽度
|
|
46
|
-
leftWidth -= currentWidth;
|
|
47
|
-
leftText = leftText.substr(STEP);
|
|
48
|
-
// 字符串整体没有超出
|
|
49
|
-
if (!leftText) {
|
|
50
|
-
return r.join('');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 最下的最后一个 STEP,使用 1 递增(用二分效果更高)
|
|
55
|
-
// eslint-disable-next-line no-constant-condition
|
|
56
|
-
while (true) {
|
|
57
|
-
// 更新字符串
|
|
58
|
-
currentText = leftText.substr(0, 1);
|
|
59
|
-
// 计算宽度
|
|
60
|
-
currentWidth = measureTextWidth(currentText, font);
|
|
61
|
-
// 超出剩余宽度,则停止
|
|
62
|
-
if (currentWidth + PLACEHOLDER_WIDTH > leftWidth) {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
r.push(currentText);
|
|
66
|
-
// 没有超出,则计算剩余宽度
|
|
67
|
-
leftWidth -= currentWidth;
|
|
68
|
-
leftText = leftText.substr(1);
|
|
69
|
-
|
|
70
|
-
if (!leftText) {
|
|
71
|
-
return r.join('');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return `${r.join('')}${str}`;
|
|
75
|
-
};
|