@fulate/share 1.0.19 → 2.0.11

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/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": "1.0.19",
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": "2.0.11",
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
+ }