@egret/runtime 7.0.1-rc.3 → 7.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.
@@ -0,0 +1,173 @@
1
+ /** A place: `x` and `y`. */
2
+ export declare class Point {
3
+ x: number;
4
+ y: number;
5
+ constructor(x?: number, y?: number);
6
+ /** The distance from the origin. */
7
+ get length(): number;
8
+ setTo(x: number, y: number): this;
9
+ clone(): Point;
10
+ copyFrom(source: {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ }): void;
14
+ equals(other: {
15
+ readonly x: number;
16
+ readonly y: number;
17
+ }): boolean;
18
+ /** A new point that is this one moved by another. */
19
+ add(other: {
20
+ readonly x: number;
21
+ readonly y: number;
22
+ }): Point;
23
+ /** A new point that is this one less another. */
24
+ subtract(other: {
25
+ readonly x: number;
26
+ readonly y: number;
27
+ }): Point;
28
+ /** Moves it by an amount. */
29
+ offset(dx: number, dy: number): void;
30
+ /** Scales it to a length, keeping its direction. A point at the origin stays there. */
31
+ normalize(thickness: number): void;
32
+ toString(): string;
33
+ static distance(a: {
34
+ readonly x: number;
35
+ readonly y: number;
36
+ }, b: {
37
+ readonly x: number;
38
+ readonly y: number;
39
+ }): number;
40
+ /** The point a fraction `f` of the way from `b` to `a`: `a` at 1, `b` at 0, as Egret's. */
41
+ static interpolate(a: {
42
+ readonly x: number;
43
+ readonly y: number;
44
+ }, b: {
45
+ readonly x: number;
46
+ readonly y: number;
47
+ }, f: number): Point;
48
+ /** The point at a length and an angle in radians from the origin. */
49
+ static polar(length: number, angle: number): Point;
50
+ }
51
+ /** A rectangle: its top left corner `x`, `y`, and its `width` and `height`. */
52
+ export declare class Rectangle {
53
+ x: number;
54
+ y: number;
55
+ width: number;
56
+ height: number;
57
+ constructor(x?: number, y?: number, width?: number, height?: number);
58
+ get left(): number;
59
+ /** Moves the left side, keeping the right side where it is. */
60
+ set left(value: number);
61
+ get right(): number;
62
+ set right(value: number);
63
+ get top(): number;
64
+ /** Moves the top side, keeping the bottom side where it is. */
65
+ set top(value: number);
66
+ get bottom(): number;
67
+ set bottom(value: number);
68
+ get topLeft(): Point;
69
+ set topLeft(value: {
70
+ readonly x: number;
71
+ readonly y: number;
72
+ });
73
+ get bottomRight(): Point;
74
+ set bottomRight(value: {
75
+ readonly x: number;
76
+ readonly y: number;
77
+ });
78
+ setTo(x: number, y: number, width: number, height: number): this;
79
+ clone(): Rectangle;
80
+ copyFrom(source: RectangleLike): void;
81
+ equals(other: RectangleLike): boolean;
82
+ /** Whether it has no area. */
83
+ isEmpty(): boolean;
84
+ setEmpty(): void;
85
+ /** Whether a point is inside it: its left and top sides count, its right and bottom do not. */
86
+ contains(x: number, y: number): boolean;
87
+ containsPoint(point: {
88
+ readonly x: number;
89
+ readonly y: number;
90
+ }): boolean;
91
+ /** Whether another rectangle lies wholly inside it. An empty one lies nowhere. */
92
+ containsRect(other: RectangleLike): boolean;
93
+ /** Whether the two share some area. */
94
+ intersects(other: RectangleLike): boolean;
95
+ /** The area the two share, or an empty rectangle. */
96
+ intersection(other: RectangleLike): Rectangle;
97
+ /** The least rectangle holding both. An empty one adds nothing. */
98
+ union(other: RectangleLike): Rectangle;
99
+ /** Grows it by `dx` on the left and on the right, and `dy` at the top and at the bottom. */
100
+ inflate(dx: number, dy: number): void;
101
+ inflatePoint(point: {
102
+ readonly x: number;
103
+ readonly y: number;
104
+ }): void;
105
+ offset(dx: number, dy: number): void;
106
+ offsetPoint(point: {
107
+ readonly x: number;
108
+ readonly y: number;
109
+ }): void;
110
+ toString(): string;
111
+ }
112
+ /** Anything with a rectangle's x, y, width and height. */
113
+ export interface RectangleLike {
114
+ readonly x: number;
115
+ readonly y: number;
116
+ readonly width: number;
117
+ readonly height: number;
118
+ }
119
+ /**
120
+ * A matrix of the plane, as Egret's and a canvas's: a point (x, y) goes to (a·x + c·y + tx, b·x + d·y + ty).
121
+ * `concat`, `rotate`, `scale` and `translate` add a change after the ones it has; `prepend` adds one before them.
122
+ */
123
+ export declare class Matrix {
124
+ a: number;
125
+ b: number;
126
+ c: number;
127
+ d: number;
128
+ tx: number;
129
+ ty: number;
130
+ constructor(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number);
131
+ setTo(a: number, b: number, c: number, d: number, tx: number, ty: number): this;
132
+ clone(): Matrix;
133
+ copyFrom(source: MatrixLike): this;
134
+ equals(other: MatrixLike): boolean;
135
+ identity(): void;
136
+ /** Adds another matrix's change after this one's. */
137
+ concat(other: MatrixLike): void;
138
+ /** The same as `concat`. */
139
+ append(a: number, b: number, c: number, d: number, tx: number, ty: number): this;
140
+ /** Adds a change before this one's. */
141
+ prepend(a: number, b: number, c: number, d: number, tx: number, ty: number): this;
142
+ /** Turns it into its inverse. One with no inverse becomes what Egret made of it: no scale, and its move reversed. */
143
+ invert(): void;
144
+ /** Adds a turn by an angle in radians. */
145
+ rotate(angle: number): void;
146
+ scale(sx: number, sy: number): void;
147
+ translate(dx: number, dy: number): void;
148
+ /** Where a point goes. */
149
+ transformPoint(x: number, y: number, result?: Point): Point;
150
+ /** Where a direction goes: the change without its move. */
151
+ deltaTransformPoint(point: {
152
+ readonly x: number;
153
+ readonly y: number;
154
+ }): Point;
155
+ /** Sets it to scale, then turn by an angle in radians, then move. */
156
+ createBox(scaleX: number, scaleY: number, rotation?: number, tx?: number, ty?: number): void;
157
+ /**
158
+ * Sets it to the matrix `beginGradientFill` takes for a box of a width and height at `tx`, `ty`, turned by an
159
+ * angle in radians: the gradient's own square of 1638.4 units fitted to the box.
160
+ */
161
+ createGradientBox(width: number, height: number, rotation?: number, tx?: number, ty?: number): void;
162
+ toString(): string;
163
+ }
164
+ /** Anything with a 2D matrix's six numbers. */
165
+ export interface MatrixLike {
166
+ readonly a: number;
167
+ readonly b: number;
168
+ readonly c: number;
169
+ readonly d: number;
170
+ readonly tx: number;
171
+ readonly ty: number;
172
+ }
173
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1,311 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Egret 5's Point, Rectangle and Matrix, for code that is moved over with them. Each is also a plain object of the
3
+ // shape the engine takes, `{ x, y }`, `{ x, y, width, height }` and `{ a, b, c, d, tx, ty }`, so one can be passed
4
+ // wherever such an object is asked for. Angles are in radians, as they were there.
5
+ /** A place: `x` and `y`. */
6
+ export class Point {
7
+ x;
8
+ y;
9
+ constructor(x = 0, y = 0) {
10
+ this.x = x;
11
+ this.y = y;
12
+ }
13
+ /** The distance from the origin. */
14
+ get length() {
15
+ return Math.hypot(this.x, this.y);
16
+ }
17
+ setTo(x, y) {
18
+ this.x = x;
19
+ this.y = y;
20
+ return this;
21
+ }
22
+ clone() {
23
+ return new Point(this.x, this.y);
24
+ }
25
+ copyFrom(source) {
26
+ this.x = source.x;
27
+ this.y = source.y;
28
+ }
29
+ equals(other) {
30
+ return this.x === other.x && this.y === other.y;
31
+ }
32
+ /** A new point that is this one moved by another. */
33
+ add(other) {
34
+ return new Point(this.x + other.x, this.y + other.y);
35
+ }
36
+ /** A new point that is this one less another. */
37
+ subtract(other) {
38
+ return new Point(this.x - other.x, this.y - other.y);
39
+ }
40
+ /** Moves it by an amount. */
41
+ offset(dx, dy) {
42
+ this.x += dx;
43
+ this.y += dy;
44
+ }
45
+ /** Scales it to a length, keeping its direction. A point at the origin stays there. */
46
+ normalize(thickness) {
47
+ const length = this.length;
48
+ if (length > 0) {
49
+ this.x *= thickness / length;
50
+ this.y *= thickness / length;
51
+ }
52
+ }
53
+ toString() {
54
+ return `(x=${this.x}, y=${this.y})`;
55
+ }
56
+ static distance(a, b) {
57
+ return Math.hypot(a.x - b.x, a.y - b.y);
58
+ }
59
+ /** The point a fraction `f` of the way from `b` to `a`: `a` at 1, `b` at 0, as Egret's. */
60
+ static interpolate(a, b, f) {
61
+ return new Point(b.x + (a.x - b.x) * f, b.y + (a.y - b.y) * f);
62
+ }
63
+ /** The point at a length and an angle in radians from the origin. */
64
+ static polar(length, angle) {
65
+ return new Point(length * Math.cos(angle), length * Math.sin(angle));
66
+ }
67
+ }
68
+ /** A rectangle: its top left corner `x`, `y`, and its `width` and `height`. */
69
+ export class Rectangle {
70
+ x;
71
+ y;
72
+ width;
73
+ height;
74
+ constructor(x = 0, y = 0, width = 0, height = 0) {
75
+ this.x = x;
76
+ this.y = y;
77
+ this.width = width;
78
+ this.height = height;
79
+ }
80
+ get left() {
81
+ return this.x;
82
+ }
83
+ /** Moves the left side, keeping the right side where it is. */
84
+ set left(value) {
85
+ this.width += this.x - value;
86
+ this.x = value;
87
+ }
88
+ get right() {
89
+ return this.x + this.width;
90
+ }
91
+ set right(value) {
92
+ this.width = value - this.x;
93
+ }
94
+ get top() {
95
+ return this.y;
96
+ }
97
+ /** Moves the top side, keeping the bottom side where it is. */
98
+ set top(value) {
99
+ this.height += this.y - value;
100
+ this.y = value;
101
+ }
102
+ get bottom() {
103
+ return this.y + this.height;
104
+ }
105
+ set bottom(value) {
106
+ this.height = value - this.y;
107
+ }
108
+ get topLeft() {
109
+ return new Point(this.left, this.top);
110
+ }
111
+ set topLeft(value) {
112
+ this.top = value.y;
113
+ this.left = value.x;
114
+ }
115
+ get bottomRight() {
116
+ return new Point(this.right, this.bottom);
117
+ }
118
+ set bottomRight(value) {
119
+ this.bottom = value.y;
120
+ this.right = value.x;
121
+ }
122
+ setTo(x, y, width, height) {
123
+ this.x = x;
124
+ this.y = y;
125
+ this.width = width;
126
+ this.height = height;
127
+ return this;
128
+ }
129
+ clone() {
130
+ return new Rectangle(this.x, this.y, this.width, this.height);
131
+ }
132
+ copyFrom(source) {
133
+ this.setTo(source.x, source.y, source.width, source.height);
134
+ }
135
+ equals(other) {
136
+ return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
137
+ }
138
+ /** Whether it has no area. */
139
+ isEmpty() {
140
+ return this.width <= 0 || this.height <= 0;
141
+ }
142
+ setEmpty() {
143
+ this.setTo(0, 0, 0, 0);
144
+ }
145
+ /** Whether a point is inside it: its left and top sides count, its right and bottom do not. */
146
+ contains(x, y) {
147
+ return x >= this.x && x < this.x + this.width && y >= this.y && y < this.y + this.height;
148
+ }
149
+ containsPoint(point) {
150
+ return this.contains(point.x, point.y);
151
+ }
152
+ /** Whether another rectangle lies wholly inside it. An empty one lies nowhere. */
153
+ containsRect(other) {
154
+ if (other.width <= 0 || other.height <= 0)
155
+ return false;
156
+ return (other.x >= this.x &&
157
+ other.y >= this.y &&
158
+ other.x + other.width <= this.x + this.width &&
159
+ other.y + other.height <= this.y + this.height);
160
+ }
161
+ /** Whether the two share some area. */
162
+ intersects(other) {
163
+ return !this.intersection(other).isEmpty();
164
+ }
165
+ /** The area the two share, or an empty rectangle. */
166
+ intersection(other) {
167
+ const left = Math.max(this.x, other.x), top = Math.max(this.y, other.y), right = Math.min(this.x + this.width, other.x + other.width), bottom = Math.min(this.y + this.height, other.y + other.height);
168
+ return right <= left || bottom <= top ? new Rectangle() : new Rectangle(left, top, right - left, bottom - top);
169
+ }
170
+ /** The least rectangle holding both. An empty one adds nothing. */
171
+ union(other) {
172
+ if (this.isEmpty())
173
+ return new Rectangle(other.x, other.y, other.width, other.height);
174
+ if (other.width <= 0 || other.height <= 0)
175
+ return this.clone();
176
+ const left = Math.min(this.x, other.x), top = Math.min(this.y, other.y);
177
+ return new Rectangle(left, top, Math.max(this.x + this.width, other.x + other.width) - left, Math.max(this.y + this.height, other.y + other.height) - top);
178
+ }
179
+ /** Grows it by `dx` on the left and on the right, and `dy` at the top and at the bottom. */
180
+ inflate(dx, dy) {
181
+ this.x -= dx;
182
+ this.width += 2 * dx;
183
+ this.y -= dy;
184
+ this.height += 2 * dy;
185
+ }
186
+ inflatePoint(point) {
187
+ this.inflate(point.x, point.y);
188
+ }
189
+ offset(dx, dy) {
190
+ this.x += dx;
191
+ this.y += dy;
192
+ }
193
+ offsetPoint(point) {
194
+ this.offset(point.x, point.y);
195
+ }
196
+ toString() {
197
+ return `(x=${this.x}, y=${this.y}, width=${this.width}, height=${this.height})`;
198
+ }
199
+ }
200
+ /**
201
+ * A matrix of the plane, as Egret's and a canvas's: a point (x, y) goes to (a·x + c·y + tx, b·x + d·y + ty).
202
+ * `concat`, `rotate`, `scale` and `translate` add a change after the ones it has; `prepend` adds one before them.
203
+ */
204
+ export class Matrix {
205
+ a;
206
+ b;
207
+ c;
208
+ d;
209
+ tx;
210
+ ty;
211
+ constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
212
+ this.a = a;
213
+ this.b = b;
214
+ this.c = c;
215
+ this.d = d;
216
+ this.tx = tx;
217
+ this.ty = ty;
218
+ }
219
+ setTo(a, b, c, d, tx, ty) {
220
+ this.a = a;
221
+ this.b = b;
222
+ this.c = c;
223
+ this.d = d;
224
+ this.tx = tx;
225
+ this.ty = ty;
226
+ return this;
227
+ }
228
+ clone() {
229
+ return new Matrix(this.a, this.b, this.c, this.d, this.tx, this.ty);
230
+ }
231
+ copyFrom(source) {
232
+ return this.setTo(source.a, source.b, source.c, source.d, source.tx, source.ty);
233
+ }
234
+ equals(other) {
235
+ return (this.a === other.a &&
236
+ this.b === other.b &&
237
+ this.c === other.c &&
238
+ this.d === other.d &&
239
+ this.tx === other.tx &&
240
+ this.ty === other.ty);
241
+ }
242
+ identity() {
243
+ this.setTo(1, 0, 0, 1, 0, 0);
244
+ }
245
+ /** Adds another matrix's change after this one's. */
246
+ concat(other) {
247
+ this.setTo(this.a * other.a + this.b * other.c, this.a * other.b + this.b * other.d, this.c * other.a + this.d * other.c, this.c * other.b + this.d * other.d, this.tx * other.a + this.ty * other.c + other.tx, this.tx * other.b + this.ty * other.d + other.ty);
248
+ }
249
+ /** The same as `concat`. */
250
+ append(a, b, c, d, tx, ty) {
251
+ this.concat({ a, b, c, d, tx, ty });
252
+ return this;
253
+ }
254
+ /** Adds a change before this one's. */
255
+ prepend(a, b, c, d, tx, ty) {
256
+ const m = { a: this.a, b: this.b, c: this.c, d: this.d, tx: this.tx, ty: this.ty };
257
+ this.setTo(a, b, c, d, tx, ty);
258
+ this.concat(m);
259
+ return this;
260
+ }
261
+ /** Turns it into its inverse. One with no inverse becomes what Egret made of it: no scale, and its move reversed. */
262
+ invert() {
263
+ const det = this.a * this.d - this.b * this.c;
264
+ if (det === 0 || !Number.isFinite(det)) {
265
+ this.setTo(0, 0, 0, 0, -this.tx, -this.ty);
266
+ return;
267
+ }
268
+ const { a, b, c, d, tx, ty } = this;
269
+ this.setTo(d / det, -b / det, -c / det, a / det, (c * ty - d * tx) / det, (b * tx - a * ty) / det);
270
+ }
271
+ /** Adds a turn by an angle in radians. */
272
+ rotate(angle) {
273
+ if (angle === 0)
274
+ return;
275
+ const cos = Math.cos(angle), sin = Math.sin(angle);
276
+ this.concat({ a: cos, b: sin, c: -sin, d: cos, tx: 0, ty: 0 });
277
+ }
278
+ scale(sx, sy) {
279
+ this.concat({ a: sx, b: 0, c: 0, d: sy, tx: 0, ty: 0 });
280
+ }
281
+ translate(dx, dy) {
282
+ this.tx += dx;
283
+ this.ty += dy;
284
+ }
285
+ /** Where a point goes. */
286
+ transformPoint(x, y, result) {
287
+ const out = result ?? new Point();
288
+ return out.setTo(this.a * x + this.c * y + this.tx, this.b * x + this.d * y + this.ty);
289
+ }
290
+ /** Where a direction goes: the change without its move. */
291
+ deltaTransformPoint(point) {
292
+ return new Point(this.a * point.x + this.c * point.y, this.b * point.x + this.d * point.y);
293
+ }
294
+ /** Sets it to scale, then turn by an angle in radians, then move. */
295
+ createBox(scaleX, scaleY, rotation = 0, tx = 0, ty = 0) {
296
+ const cos = Math.cos(rotation), sin = Math.sin(rotation);
297
+ // Adding 0 makes a zero that came out negative an ordinary one.
298
+ this.setTo(scaleX * cos + 0, scaleX * sin + 0, -scaleY * sin + 0, scaleY * cos + 0, tx, ty);
299
+ }
300
+ /**
301
+ * Sets it to the matrix `beginGradientFill` takes for a box of a width and height at `tx`, `ty`, turned by an
302
+ * angle in radians: the gradient's own square of 1638.4 units fitted to the box.
303
+ */
304
+ createGradientBox(width, height, rotation = 0, tx = 0, ty = 0) {
305
+ this.createBox(width / 1638.4, height / 1638.4, rotation, tx + width / 2, ty + height / 2);
306
+ }
307
+ toString() {
308
+ return `(a=${this.a}, b=${this.b}, c=${this.c}, d=${this.d}, tx=${this.tx}, ty=${this.ty})`;
309
+ }
310
+ }
311
+ //# sourceMappingURL=geometry.js.map
@@ -1,4 +1,4 @@
1
- import type { ImageData2D, Rectangle2D, SharedGeometry2D } from '@egret/contracts';
1
+ import type { ImageData2D, Matrix2D, Rectangle2D, SharedGeometry2D } from '@egret/contracts';
2
2
  import type { ShapeGradient } from './graphicsFill.js';
3
3
  import type { AssetLease } from './AssetLease.js';
4
4
  import type { Texture } from './Texture.js';
@@ -140,5 +140,31 @@ export declare function shapeFits(vertices: number, indices: number): boolean;
140
140
  export declare function drawingFits(drawing: ShapeDrawing): boolean;
141
141
  /** The geometries and bounds of a node's shapes, or undefined while they hold no triangle. */
142
142
  export declare function resolveShape(shape: ShapeState): ResolvedShape | undefined;
143
+ /** The image of a mask, the region of it that is whole, and where it lies in the masked node's units. */
144
+ export interface ShapeMaskImage {
145
+ readonly image: ImageData2D;
146
+ readonly region: {
147
+ readonly packed: Rectangle2D;
148
+ readonly logicalWidth: number;
149
+ readonly logicalHeight: number;
150
+ readonly trimX: 0;
151
+ readonly trimY: 0;
152
+ readonly quarterTurn: 0;
153
+ };
154
+ readonly rect: Rectangle2D;
155
+ }
156
+ /** The most pixels a side of a mask's image has, and how many samples a pixel takes on each side. */
157
+ export declare const SHAPE_MASK_LIMITS: Readonly<{
158
+ maxEdge: 2048;
159
+ samples: 4;
160
+ }>;
161
+ /**
162
+ * The image of what a mask draws, its filled rectangles and its drawing placed by `matrix` in the masked node's units,
163
+ * at `scale` pixels to a unit of that node. `mask` is what the image is kept for.
164
+ */
165
+ export declare function shapeMaskImage(mask: object, primitives: readonly {
166
+ readonly rect: Rectangle2D;
167
+ readonly alpha: number;
168
+ }[], shape: ResolvedShape | undefined, matrix: Matrix2D, scale: number): ShapeMaskImage;
143
169
  export {};
144
170
  //# sourceMappingURL=graphicsShape.d.ts.map