@fulate/share 1.0.19 → 3.0.2
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/README.md +11 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -1
- package/dist/rect.d.ts +3 -0
- package/package.json +24 -24
package/README.md
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
# `@fulate/share`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
提供点、矩形、矩阵、颜色、渐变和相交计算。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
| 用途 | 常用 API |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| 点 | `PointView`、`createPointView()`、`transformPoint()` |
|
|
8
|
+
| 边界 | `Rect`、`BoundingBox`、`Bound` |
|
|
9
|
+
| 矩阵 | `Matrix2D`、`ReadonlyMatrix2D`、`qrDecompose()` |
|
|
10
|
+
| 几何 | `Intersection`、`clipPolygonToRect()` |
|
|
11
|
+
| 颜色 | 颜色解析、格式化、混色、alpha 合成和 Canvas gradient |
|
|
11
12
|
|
|
12
13
|
```ts
|
|
13
|
-
import {
|
|
14
|
-
Bound,
|
|
15
|
-
createPointView,
|
|
16
|
-
transformPoint,
|
|
17
|
-
colorWithAlpha
|
|
18
|
-
} from "@fulate/share";
|
|
14
|
+
import { Bound, Matrix2D, createPointView, transformPoint, colorWithAlpha } from "@fulate/share";
|
|
19
15
|
|
|
16
|
+
const matrix = new Matrix2D().translateSelf(20, 10);
|
|
20
17
|
const point = transformPoint(matrix, createPointView(10, 20));
|
|
21
18
|
const bounds = Bound.fromPoints([point]);
|
|
22
19
|
const overlay = colorWithAlpha("#6750a4", 0.12);
|
|
23
20
|
```
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
语义工作;调用方需要独立结果时使用明确的 `copy()` 或在自身 owner 内创建新值。
|
|
22
|
+
`Bound` 可修改;需要独立边界时调用 `copy()`。
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { transformPoint, createPointView, isPointWithinDistance } from "./point";
|
|
2
2
|
export type { MutablePointView, PointView } from "./point";
|
|
3
|
-
export { Bound, makeBoundingBoxFromRects } from "./rect";
|
|
3
|
+
export { Bound, projectBounds, makeBoundingBoxFromRects } from "./rect";
|
|
4
4
|
export type { Rect, RectWithCenter, BoundingBox } from "./rect";
|
|
5
5
|
export { Matrix2D, qrDecompose } from "./matrix";
|
|
6
6
|
export type { ReadonlyMatrix2D } from "./matrix";
|
package/dist/index.js
CHANGED
|
@@ -109,6 +109,30 @@ var Bound = class Bound {
|
|
|
109
109
|
return new Bound(minX, minY, maxX, maxY);
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
+
/** Project a local rectangle into a matrix space and return its AABB. */
|
|
113
|
+
function projectBounds(matrix, bounds) {
|
|
114
|
+
if (!bounds) return new Bound();
|
|
115
|
+
const left = bounds.left;
|
|
116
|
+
const top = bounds.top;
|
|
117
|
+
const right = left + bounds.width;
|
|
118
|
+
const bottom = top + bounds.height;
|
|
119
|
+
if (matrix.b === 0 && matrix.c === 0) {
|
|
120
|
+
const firstX = matrix.a * left + matrix.e;
|
|
121
|
+
const secondX = matrix.a * right + matrix.e;
|
|
122
|
+
const firstY = matrix.d * top + matrix.f;
|
|
123
|
+
const secondY = matrix.d * bottom + matrix.f;
|
|
124
|
+
return new Bound(Math.min(firstX, secondX), Math.min(firstY, secondY), Math.max(firstX, secondX), Math.max(firstY, secondY));
|
|
125
|
+
}
|
|
126
|
+
const x0 = matrix.a * left + matrix.c * top + matrix.e;
|
|
127
|
+
const x1 = matrix.a * right + matrix.c * top + matrix.e;
|
|
128
|
+
const x2 = matrix.a * right + matrix.c * bottom + matrix.e;
|
|
129
|
+
const x3 = matrix.a * left + matrix.c * bottom + matrix.e;
|
|
130
|
+
const y0 = matrix.b * left + matrix.d * top + matrix.f;
|
|
131
|
+
const y1 = matrix.b * right + matrix.d * top + matrix.f;
|
|
132
|
+
const y2 = matrix.b * right + matrix.d * bottom + matrix.f;
|
|
133
|
+
const y3 = matrix.b * left + matrix.d * bottom + matrix.f;
|
|
134
|
+
return new Bound(Math.min(x0, x1, x2, x3), Math.min(y0, y1, y2, y3), Math.max(x0, x1, x2, x3), Math.max(y0, y1, y2, y3));
|
|
135
|
+
}
|
|
112
136
|
function makeBoundingBoxFromRects(rects) {
|
|
113
137
|
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
114
138
|
for (let i = 0; i < rects.length; i++) {
|
|
@@ -534,4 +558,4 @@ function createCanvasGradient(ctx, gradient, width, height) {
|
|
|
534
558
|
return result;
|
|
535
559
|
}
|
|
536
560
|
//#endregion
|
|
537
|
-
export { Bound, Intersection, Matrix2D, blendColor, clipPolygonToRect, colorWithAlpha, createCanvasGradient, createPointView, degreesToRadians, formatColor, formatPremultipliedColor, isGradient, isPointWithinDistance, makeBoundingBoxFromRects, parseColor, parsePremultipliedColor, qrDecompose, radiansToDegrees, rectEdgePosition, transformPoint };
|
|
561
|
+
export { Bound, Intersection, Matrix2D, blendColor, clipPolygonToRect, colorWithAlpha, createCanvasGradient, createPointView, degreesToRadians, formatColor, formatPremultipliedColor, isGradient, isPointWithinDistance, makeBoundingBoxFromRects, parseColor, parsePremultipliedColor, projectBounds, qrDecompose, radiansToDegrees, rectEdgePosition, transformPoint };
|
package/dist/rect.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PointView } from "./point";
|
|
2
|
+
import type { ReadonlyMatrix2D } from "./matrix";
|
|
2
3
|
export interface Rect {
|
|
3
4
|
left: number;
|
|
4
5
|
top: number;
|
|
@@ -33,4 +34,6 @@ export declare class Bound implements RectWithCenter {
|
|
|
33
34
|
includePoint(x: number, y: number, padding?: number): this;
|
|
34
35
|
static fromPoints(points: readonly PointView[]): Bound;
|
|
35
36
|
}
|
|
37
|
+
/** Project a local rectangle into a matrix space and return its AABB. */
|
|
38
|
+
export declare function projectBounds(matrix: ReadonlyMatrix2D, bounds: Readonly<Rect> | null): Bound;
|
|
36
39
|
export declare function makeBoundingBoxFromRects(rects: readonly Rect[]): Rect;
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fulate/share",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"import": "./dist/index.js"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"dist"
|
|
15
|
-
],
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"scripts": {
|
|
18
|
-
"test": "vitest run --config vitest.config.ts"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"colord": "^2.9.3",
|
|
22
|
-
"lodash-es": "^4.17.22"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fulate/share",
|
|
3
|
+
"version": "3.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "vitest run --config vitest.config.ts"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"colord": "^2.9.3",
|
|
22
|
+
"lodash-es": "^4.17.22"
|
|
23
|
+
}
|
|
24
|
+
}
|