@egret/runtime 0.0.0-stage → 7.0.1-rc.3

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.
Files changed (155) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +70 -2
  4. package/README.zh-CN.md +71 -0
  5. package/dist/AssetLease.d.ts +23 -0
  6. package/dist/AssetLease.js +69 -0
  7. package/dist/AssetManager.d.ts +56 -0
  8. package/dist/AssetManager.js +451 -0
  9. package/dist/AssetRef.d.ts +20 -0
  10. package/dist/AssetRef.js +32 -0
  11. package/dist/Bitmap.d.ts +40 -0
  12. package/dist/Bitmap.js +545 -0
  13. package/dist/ByteReader.d.ts +30 -0
  14. package/dist/ByteReader.js +177 -0
  15. package/dist/ByteWriter.d.ts +29 -0
  16. package/dist/ByteWriter.js +180 -0
  17. package/dist/CancellationController.d.ts +10 -0
  18. package/dist/CancellationController.js +66 -0
  19. package/dist/DisplayObject.d.ts +89 -0
  20. package/dist/DisplayObject.js +340 -0
  21. package/dist/DisplayObjectContainer.d.ts +28 -0
  22. package/dist/DisplayObjectContainer.js +226 -0
  23. package/dist/EgretError.d.ts +11 -0
  24. package/dist/EgretError.js +36 -0
  25. package/dist/Event.d.ts +45 -0
  26. package/dist/Event.js +84 -0
  27. package/dist/EventDispatcher.d.ts +24 -0
  28. package/dist/EventDispatcher.js +178 -0
  29. package/dist/Graphics.d.ts +106 -0
  30. package/dist/Graphics.js +504 -0
  31. package/dist/Mesh2D.d.ts +27 -0
  32. package/dist/Mesh2D.js +200 -0
  33. package/dist/NineSliceBitmap.d.ts +24 -0
  34. package/dist/NineSliceBitmap.js +164 -0
  35. package/dist/NineSliceGeometry2D.d.ts +18 -0
  36. package/dist/NineSliceGeometry2D.js +126 -0
  37. package/dist/Scope.d.ts +18 -0
  38. package/dist/Scope.js +133 -0
  39. package/dist/SequencePlayer.d.ts +12 -0
  40. package/dist/SequencePlayer.js +69 -0
  41. package/dist/Sprite.d.ts +8 -0
  42. package/dist/Sprite.js +12 -0
  43. package/dist/Stage.d.ts +14 -0
  44. package/dist/Stage.js +31 -0
  45. package/dist/Texture.d.ts +29 -0
  46. package/dist/Texture.js +177 -0
  47. package/dist/assetManagerOwnerState.d.ts +36 -0
  48. package/dist/assetManagerOwnerState.js +115 -0
  49. package/dist/assetState.d.ts +44 -0
  50. package/dist/assetState.js +2 -0
  51. package/dist/atlasFrameLayout.d.ts +21 -0
  52. package/dist/atlasFrameLayout.js +48 -0
  53. package/dist/bitmapDisplayState.d.ts +24 -0
  54. package/dist/bitmapDisplayState.js +22 -0
  55. package/dist/coordinateInverse.d.ts +4 -0
  56. package/dist/coordinateInverse.js +107 -0
  57. package/dist/diagnostics.d.ts +4 -0
  58. package/dist/diagnostics.js +13 -0
  59. package/dist/displayBounds.d.ts +9 -0
  60. package/dist/displayBounds.js +181 -0
  61. package/dist/displayCoordinates.d.ts +8 -0
  62. package/dist/displayCoordinates.js +81 -0
  63. package/dist/displayHitState.d.ts +18 -0
  64. package/dist/displayHitState.js +97 -0
  65. package/dist/displayHitTest.d.ts +8 -0
  66. package/dist/displayHitTest.js +219 -0
  67. package/dist/displayInputOperations.d.ts +12 -0
  68. package/dist/displayInputOperations.js +71 -0
  69. package/dist/displayTransform.d.ts +5 -0
  70. package/dist/displayTransform.js +38 -0
  71. package/dist/displayTreeState.d.ts +90 -0
  72. package/dist/displayTreeState.js +450 -0
  73. package/dist/displayVisualState.d.ts +74 -0
  74. package/dist/displayVisualState.js +140 -0
  75. package/dist/errorHelp.d.ts +14 -0
  76. package/dist/errorHelp.js +432 -0
  77. package/dist/errorHelpZh.d.ts +5 -0
  78. package/dist/errorHelpZh.js +340 -0
  79. package/dist/graphicsFill.d.ts +37 -0
  80. package/dist/graphicsFill.js +302 -0
  81. package/dist/graphicsShape.d.ts +144 -0
  82. package/dist/graphicsShape.js +755 -0
  83. package/dist/index.d.ts +50 -0
  84. package/dist/index.js +28 -0
  85. package/dist/input/PointerRouter.d.ts +4 -0
  86. package/dist/input/PointerRouter.js +453 -0
  87. package/dist/input/index.d.ts +3 -0
  88. package/dist/input/index.js +3 -0
  89. package/dist/input/types.d.ts +58 -0
  90. package/dist/input/types.js +3 -0
  91. package/dist/meshCaptureSnapshot.d.ts +5 -0
  92. package/dist/meshCaptureSnapshot.js +13 -0
  93. package/dist/meshDisplayState.d.ts +18 -0
  94. package/dist/meshDisplayState.js +21 -0
  95. package/dist/ownership.d.ts +75 -0
  96. package/dist/ownership.js +157 -0
  97. package/dist/paragraph/Paragraph.d.ts +13 -0
  98. package/dist/paragraph/Paragraph.js +193 -0
  99. package/dist/paragraph/ParagraphCache.d.ts +5 -0
  100. package/dist/paragraph/ParagraphCache.js +354 -0
  101. package/dist/paragraph/geometry.d.ts +4 -0
  102. package/dist/paragraph/geometry.js +180 -0
  103. package/dist/paragraph/index.d.ts +3 -0
  104. package/dist/paragraph/index.js +3 -0
  105. package/dist/paragraph/request.d.ts +6 -0
  106. package/dist/paragraph/request.js +191 -0
  107. package/dist/paragraph/types.d.ts +183 -0
  108. package/dist/paragraph/types.js +2 -0
  109. package/dist/preparedDisplaySubtree.d.ts +7 -0
  110. package/dist/preparedDisplaySubtree.js +205 -0
  111. package/dist/renderEffect.d.ts +47 -0
  112. package/dist/renderEffect.js +87 -0
  113. package/dist/sequenceClip.d.ts +42 -0
  114. package/dist/sequenceClip.js +196 -0
  115. package/dist/sharedFrameCapture.d.ts +24 -0
  116. package/dist/sharedFrameCapture.js +1069 -0
  117. package/dist/spriteSheet.d.ts +34 -0
  118. package/dist/spriteSheet.js +321 -0
  119. package/dist/srgbBytes.d.ts +3 -0
  120. package/dist/srgbBytes.js +64 -0
  121. package/dist/text/TextField.d.ts +13 -0
  122. package/dist/text/TextField.js +261 -0
  123. package/dist/text/TextRasterCache.d.ts +5 -0
  124. package/dist/text/TextRasterCache.js +1191 -0
  125. package/dist/text/budget.d.ts +51 -0
  126. package/dist/text/budget.js +116 -0
  127. package/dist/text/index.d.ts +4 -0
  128. package/dist/text/index.js +3 -0
  129. package/dist/text/plan.d.ts +16 -0
  130. package/dist/text/plan.js +238 -0
  131. package/dist/text/request.d.ts +44 -0
  132. package/dist/text/request.js +303 -0
  133. package/dist/text/types.d.ts +179 -0
  134. package/dist/text/types.js +2 -0
  135. package/dist/textDisplayState.d.ts +21 -0
  136. package/dist/textDisplayState.js +27 -0
  137. package/dist/ui/displayCommit.d.ts +43 -0
  138. package/dist/ui/displayCommit.js +376 -0
  139. package/dist/ui/editing.d.ts +3 -0
  140. package/dist/ui/editing.js +3 -0
  141. package/dist/ui/heightIndex.d.ts +35 -0
  142. package/dist/ui/heightIndex.js +295 -0
  143. package/dist/ui/index.d.ts +6 -0
  144. package/dist/ui/index.js +6 -0
  145. package/dist/ui/layout.d.ts +9 -0
  146. package/dist/ui/layout.js +349 -0
  147. package/dist/ui/managedState.d.ts +12 -0
  148. package/dist/ui/managedState.js +44 -0
  149. package/dist/ui/textEditState.d.ts +4 -0
  150. package/dist/ui/textEditState.js +206 -0
  151. package/dist/ui/textEditTypes.d.ts +48 -0
  152. package/dist/ui/textEditTypes.js +2 -0
  153. package/dist/ui/types.d.ts +99 -0
  154. package/dist/ui/types.js +2 -0
  155. package/package.json +44 -4
@@ -0,0 +1,302 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Filling for Graphics beyond one simple outline: the non-zero rule over any number of outlines, so that holes and
3
+ // outlines that cross themselves are filled as a canvas fills them, and gradients, which are given as vertex colours.
4
+ import { decodeSRGBByte } from './srgbBytes.js';
5
+ /**
6
+ * The linear-light value of an sRGB value from 0 to 255 that need not be whole: between the two bytes it lies between,
7
+ * read from the written table. A power here would differ in its last bit from one engine of JavaScript to another.
8
+ */
9
+ function toLinear(value) {
10
+ const low = Math.floor(value);
11
+ if (low >= 255)
12
+ return decodeSRGBByte(255);
13
+ if (low < 0)
14
+ return decodeSRGBByte(0);
15
+ const from = decodeSRGBByte(low);
16
+ return from + (decodeSRGBByte(low + 1) - from) * (value - low);
17
+ }
18
+ /** The linear-light red, green and blue and the alpha of a gradient at a point. Stops are mixed as sRGB values, as a canvas mixes them. */
19
+ export function gradientColor(gradient, x, y, out, at = 0) {
20
+ const u = gradient.a * x + gradient.c * y + gradient.tx;
21
+ let t = gradient.radial ? Math.hypot(u, gradient.b * x + gradient.d * y + gradient.ty) : u;
22
+ const stops = gradient.stops, last = stops.length - 1;
23
+ if (!(t > 0))
24
+ t = 0;
25
+ else if (t > 1)
26
+ t = 1;
27
+ let i = 0;
28
+ while (i < last && stops[i + 1].offset <= t)
29
+ i++;
30
+ const from = stops[i];
31
+ let color = from.color, alpha = from.alpha, r = (color >> 16) & 255, g = (color >> 8) & 255, b = color & 255;
32
+ if (i < last && t > from.offset) {
33
+ const to = stops[i + 1], f = (t - from.offset) / (to.offset - from.offset);
34
+ color = to.color;
35
+ r += (((color >> 16) & 255) - r) * f;
36
+ g += (((color >> 8) & 255) - g) * f;
37
+ b += ((color & 255) - b) * f;
38
+ alpha += (to.alpha - alpha) * f;
39
+ }
40
+ out[at] = toLinear(r);
41
+ out[at + 1] = toLinear(g);
42
+ out[at + 2] = toLinear(b);
43
+ out[at + 3] = alpha;
44
+ }
45
+ /** Whether an outline, taken as closed, has two sides that cross. */
46
+ export function outlineCrosses(points) {
47
+ const count = points.length / 2;
48
+ for (let i = 0; i < count; i++) {
49
+ const ax = points[2 * i], ay = points[2 * i + 1], bx = points[2 * ((i + 1) % count)], by = points[2 * ((i + 1) % count) + 1];
50
+ const left = Math.min(ax, bx), right = Math.max(ax, bx), top = Math.min(ay, by), bottom = Math.max(ay, by);
51
+ for (let j = i + 2; j < count; j++) {
52
+ if (i === 0 && j === count - 1)
53
+ continue;
54
+ const cx = points[2 * j], cy = points[2 * j + 1], dx = points[2 * ((j + 1) % count)], dy = points[2 * ((j + 1) % count) + 1];
55
+ if (Math.max(cx, dx) < left || Math.min(cx, dx) > right || Math.max(cy, dy) < top || Math.min(cy, dy) > bottom)
56
+ continue;
57
+ const d1 = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax), d2 = (bx - ax) * (dy - ay) - (by - ay) * (dx - ax);
58
+ const d3 = (dx - cx) * (ay - cy) - (dy - cy) * (ax - cx), d4 = (dx - cx) * (by - cy) - (dy - cy) * (bx - cx);
59
+ if (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0)))
60
+ return true;
61
+ // A corner that lies on another side, or sides that run along each other, is left to the non-zero fill too.
62
+ if (d1 === 0 || d2 === 0 || d3 === 0 || d4 === 0)
63
+ return true;
64
+ }
65
+ }
66
+ return false;
67
+ }
68
+ /**
69
+ * The triangles of what closed outlines cover by the non-zero rule, as x, y of each corner, three corners to a
70
+ * triangle; undefined when there would be more than `maxTriangles`. The plane is cut into bands at every corner and
71
+ * crossing; in a band no two sides cross, so what is inside lies between pairs of sides. Triangles that meet along a
72
+ * band's edge share every corner on it, so no seam opens between bands under any transform.
73
+ */
74
+ export function fillNonZero(outlines, maxTriangles) {
75
+ const x0 = [], y0 = [], x1 = [], y1 = [], turn = [];
76
+ for (const points of outlines) {
77
+ const count = points.length / 2;
78
+ if (count < 3)
79
+ continue;
80
+ for (let i = 0; i < count; i++) {
81
+ const ax = points[2 * i], ay = points[2 * i + 1], j = (i + 1) % count, bx = points[2 * j], by = points[2 * j + 1];
82
+ if (ay === by)
83
+ continue;
84
+ if (ay < by) {
85
+ x0.push(ax);
86
+ y0.push(ay);
87
+ x1.push(bx);
88
+ y1.push(by);
89
+ turn.push(1);
90
+ }
91
+ else {
92
+ x0.push(bx);
93
+ y0.push(by);
94
+ x1.push(ax);
95
+ y1.push(ay);
96
+ turn.push(-1);
97
+ }
98
+ }
99
+ }
100
+ const edges = x0.length;
101
+ if (edges === 0)
102
+ return [];
103
+ const order = [];
104
+ for (let i = 0; i < edges; i++)
105
+ order.push(i);
106
+ order.sort((p, q) => y0[p] - y0[q]);
107
+ const levels = new Set();
108
+ for (let i = 0; i < edges; i++) {
109
+ levels.add(y0[i]);
110
+ levels.add(y1[i]);
111
+ }
112
+ for (let p = 0; p < edges; p++) {
113
+ const i = order[p], bottom = y1[i], si = (x1[i] - x0[i]) / (bottom - y0[i]), li = Math.min(x0[i], x1[i]), ri = Math.max(x0[i], x1[i]);
114
+ for (let q = p + 1; q < edges; q++) {
115
+ const j = order[q];
116
+ if (y0[j] >= bottom)
117
+ break;
118
+ if (Math.max(x0[j], x1[j]) < li || Math.min(x0[j], x1[j]) > ri)
119
+ continue;
120
+ const sj = (x1[j] - x0[j]) / (y1[j] - y0[j]);
121
+ if (si === sj)
122
+ continue;
123
+ const y = (x0[j] - x0[i] + y0[i] * si - y0[j] * sj) / (si - sj);
124
+ if (y > y0[j] && y < bottom && y < y1[j])
125
+ levels.add(y);
126
+ }
127
+ }
128
+ // Levels closer than stored coordinates can tell apart are one level, and every side ends on a level, so that no
129
+ // band is thinner than a stored coordinate can say.
130
+ let reach = 1;
131
+ for (let i = 0; i < edges; i++)
132
+ reach = Math.max(reach, Math.abs(y0[i]), Math.abs(y1[i]), Math.abs(x0[i]), Math.abs(x1[i]));
133
+ const ys = [];
134
+ for (const y of [...levels].sort((p, q) => p - q))
135
+ if (ys.length === 0 || y - ys[ys.length - 1] > reach * 1e-6)
136
+ ys.push(y);
137
+ const level = (y) => {
138
+ let low = 0, high = ys.length - 1;
139
+ while (low < high) {
140
+ const middle = (low + high + 1) >> 1;
141
+ if (ys[middle] <= y)
142
+ low = middle;
143
+ else
144
+ high = middle - 1;
145
+ }
146
+ return ys[low];
147
+ };
148
+ for (let i = 0; i < edges; i++) {
149
+ y0[i] = level(y0[i]);
150
+ y1[i] = level(y1[i]);
151
+ }
152
+ const bands = ys.length - 1;
153
+ const at = (edge, y) => y === y0[edge]
154
+ ? x0[edge]
155
+ : y === y1[edge]
156
+ ? x1[edge]
157
+ : x0[edge] + ((y - y0[edge]) * (x1[edge] - x0[edge])) / (y1[edge] - y0[edge]);
158
+ // For each band, the spans inside it: left and right at its top, then left and right at its bottom.
159
+ const spans = [], corners = [];
160
+ for (let k = 0; k <= bands; k++)
161
+ corners.push([]);
162
+ let active = [], next = 0, total = 0;
163
+ for (let k = 0; k < bands; k++) {
164
+ const top = ys[k], bottom = ys[k + 1];
165
+ active = active.filter(edge => y1[edge] > top);
166
+ while (next < edges && y0[order[next]] <= top) {
167
+ if (y1[order[next]] > top)
168
+ active.push(order[next]);
169
+ next++;
170
+ }
171
+ const here = active
172
+ .map(edge => {
173
+ const xt = at(edge, top), xb = at(edge, bottom);
174
+ return { edge, xt, xb, middle: (xt + xb) / 2 };
175
+ })
176
+ .sort((p, q) => p.middle - q.middle || p.xb - q.xb);
177
+ const band = [];
178
+ let winding = 0, left = here[0];
179
+ for (const side of here) {
180
+ const before = winding;
181
+ winding += turn[side.edge];
182
+ if (before === 0 && winding !== 0)
183
+ left = side;
184
+ else if (before !== 0 && winding === 0 && (left.xt !== side.xt || left.xb !== side.xb)) {
185
+ band.push(left.xt, side.xt, left.xb, side.xb);
186
+ corners[k].push(left.xt, side.xt);
187
+ corners[k + 1].push(left.xb, side.xb);
188
+ }
189
+ }
190
+ spans.push(band);
191
+ total += band.length / 2;
192
+ }
193
+ if (total > 2 * maxTriangles)
194
+ return undefined;
195
+ for (const line of corners)
196
+ line.sort((p, q) => p - q);
197
+ const out = [], topRow = [], bottomRow = [];
198
+ const row = (line, from, to, into) => {
199
+ into.length = 0;
200
+ into.push(from);
201
+ for (const x of line)
202
+ if (x > from && x < to && x !== into[into.length - 1])
203
+ into.push(x);
204
+ if (to !== from)
205
+ into.push(to);
206
+ };
207
+ for (let k = 0; k < bands; k++) {
208
+ const band = spans[k], top = ys[k], bottom = ys[k + 1];
209
+ for (let s = 0; s < band.length; s += 4) {
210
+ row(corners[k], band[s], band[s + 1], topRow);
211
+ row(corners[k + 1], band[s + 2], band[s + 3], bottomRow);
212
+ // The two rows are joined like a zip, always from the row whose next corner comes first.
213
+ for (let i = 0, j = 0; i + 1 < topRow.length || j + 1 < bottomRow.length;) {
214
+ if (i + 1 < topRow.length && (j + 1 === bottomRow.length || topRow[i + 1] <= bottomRow[j + 1])) {
215
+ out.push(topRow[i], top, topRow[i + 1], top, bottomRow[j], bottom);
216
+ i++;
217
+ }
218
+ else {
219
+ out.push(topRow[i], top, bottomRow[j + 1], bottom, bottomRow[j], bottom);
220
+ j++;
221
+ }
222
+ }
223
+ if (out.length > 6 * maxTriangles)
224
+ return undefined;
225
+ }
226
+ }
227
+ return out;
228
+ }
229
+ /** How far a colour may be from its gradient, in a measure close to what an eye tells apart: two parts in 255. */
230
+ const TOLERANCE = 2 / 255;
231
+ /**
232
+ * Cuts triangles until the colours of their corners, mixed across each side, stay within the tolerance of the gradient.
233
+ * A side's test depends on its endpoints. The triangle budget can still stop adjacent subdivisions at different depths.
234
+ * When supplied, boundary masks are replaced in the output order. Only the children of an original boundary inherit it.
235
+ */
236
+ export function refineForGradient(triangles, gradient, maxTriangles, boundary) {
237
+ const ca = [0, 0, 0, 0], cb = [0, 0, 0, 0], cm = [0, 0, 0, 0];
238
+ const cut = (ax, ay, bx, by) => {
239
+ if (ax > bx || (ax === bx && ay > by)) {
240
+ const x = ax, y = ay;
241
+ ax = bx;
242
+ ay = by;
243
+ bx = x;
244
+ by = y;
245
+ }
246
+ const dx = bx - ax, dy = by - ay;
247
+ if (dx * dx + dy * dy < 0.25)
248
+ return false;
249
+ gradientColor(gradient, ax, ay, ca);
250
+ gradientColor(gradient, bx, by, cb);
251
+ for (let step = 1; step < 4; step++) {
252
+ const f = step / 4;
253
+ gradientColor(gradient, ax + dx * f, ay + dy * f, cm);
254
+ for (let i = 0; i < 3; i++)
255
+ if (Math.abs(Math.sqrt(cm[i]) - Math.sqrt(ca[i] + (cb[i] - ca[i]) * f)) > TOLERANCE)
256
+ return true;
257
+ if (Math.abs(cm[3] - (ca[3] + (cb[3] - ca[3]) * f)) > TOLERANCE)
258
+ return true;
259
+ }
260
+ return false;
261
+ };
262
+ const stack = triangles.slice(), out = [];
263
+ const boundaries = boundary?.slice();
264
+ if (boundary !== undefined)
265
+ boundary.length = 0;
266
+ let count = triangles.length / 6;
267
+ while (stack.length !== 0) {
268
+ const p = stack.splice(stack.length - 6, 6);
269
+ const mask = boundaries?.pop() ?? 0;
270
+ const flags = count < maxTriangles
271
+ ? [cut(p[0], p[1], p[2], p[3]), cut(p[2], p[3], p[4], p[5]), cut(p[4], p[5], p[0], p[1])]
272
+ : [false, false, false];
273
+ const cuts = (flags[0] ? 1 : 0) + (flags[1] ? 1 : 0) + (flags[2] ? 1 : 0);
274
+ if (cuts === 0) {
275
+ out.push(...p);
276
+ boundary?.push(mask);
277
+ continue;
278
+ }
279
+ // Turned so that with one cut it is the first side, and with two the uncut side is the last.
280
+ const turnBy = cuts === 3 ? 0 : cuts === 1 ? flags.indexOf(true) : (flags.indexOf(false) + 1) % 3;
281
+ const ax = p[2 * turnBy], ay = p[2 * turnBy + 1], bx = p[2 * ((turnBy + 1) % 3)], by = p[2 * ((turnBy + 1) % 3) + 1], cx = p[2 * ((turnBy + 2) % 3)], cy = p[2 * ((turnBy + 2) % 3) + 1];
282
+ const abx = (ax + bx) / 2, aby = (ay + by) / 2, bcx = (bx + cx) / 2, bcy = (by + cy) / 2, cax = (cx + ax) / 2, cay = (cy + ay) / 2;
283
+ // Rotate the three bits with the corners. New interior sides never carry a boundary bit.
284
+ const turned = (mask >>> turnBy) | ((mask << (3 - turnBy)) & 7);
285
+ const ab = turned & 1, bc = turned & 2, ca = turned & 4;
286
+ if (cuts === 1) {
287
+ stack.push(ax, ay, abx, aby, cx, cy, abx, aby, bx, by, cx, cy);
288
+ boundaries?.push(ab | ca, ab | bc);
289
+ }
290
+ else if (cuts === 2) {
291
+ stack.push(abx, aby, bx, by, bcx, bcy, ax, ay, abx, aby, bcx, bcy, ax, ay, bcx, bcy, cx, cy);
292
+ boundaries?.push(ab | bc, ab, bc | ca);
293
+ }
294
+ else {
295
+ stack.push(ax, ay, abx, aby, cax, cay, abx, aby, bx, by, bcx, bcy, cax, cay, bcx, bcy, cx, cy, abx, aby, bcx, bcy, cax, cay);
296
+ boundaries?.push(ab | ca, ab | bc, bc | ca, 0);
297
+ }
298
+ count += cuts;
299
+ }
300
+ return out;
301
+ }
302
+ //# sourceMappingURL=graphicsFill.js.map
@@ -0,0 +1,144 @@
1
+ import type { ImageData2D, Rectangle2D, SharedGeometry2D } from '@egret/contracts';
2
+ import type { ShapeGradient } from './graphicsFill.js';
3
+ import type { AssetLease } from './AssetLease.js';
4
+ import type { Texture } from './Texture.js';
5
+ /**
6
+ * An image as a fill: the lease of its texture, whether it repeats, and the map from a node's units to the image, in
7
+ * which 0 to 1 is once across it: `u = a·x + c·y + tx` and `v = b·x + d·y + ty`.
8
+ */
9
+ export interface ShapeBitmap {
10
+ readonly lease: AssetLease<Texture>;
11
+ readonly repeat: boolean;
12
+ readonly width: number;
13
+ readonly height: number;
14
+ readonly a: number;
15
+ readonly b: number;
16
+ readonly c: number;
17
+ readonly d: number;
18
+ readonly tx: number;
19
+ readonly ty: number;
20
+ }
21
+ /** `feather` is how far, in the node's units, the edge of what is painted fades to nothing; none when it is not there. */
22
+ export interface ShapePaint {
23
+ readonly color: number;
24
+ readonly alpha: number;
25
+ readonly gradient?: ShapeGradient | undefined;
26
+ readonly bitmap?: ShapeBitmap | undefined;
27
+ readonly feather?: number | undefined;
28
+ }
29
+ export type LineCaps = 'none' | 'round' | 'square';
30
+ export type LineJoints = 'miter' | 'round' | 'bevel';
31
+ /** A line: its width, how its ends and corners are drawn, and the lengths of its dashes and gaps in turn, if it is dashed. */
32
+ export interface ShapeLine extends ShapePaint {
33
+ readonly width: number;
34
+ readonly caps: LineCaps;
35
+ readonly joints: LineJoints;
36
+ readonly miterLimit: number;
37
+ readonly dash: readonly number[] | undefined;
38
+ }
39
+ /** A path being drawn with moveTo and lineTo: its paints, and each subpath as x, y pairs. */
40
+ export interface ShapePath {
41
+ readonly fill: ShapePaint | undefined;
42
+ readonly line: ShapeLine | undefined;
43
+ readonly subpaths: number[][];
44
+ }
45
+ /**
46
+ * Triangles that are drawn together: x, y of each vertex; linear-light r, g, b and alpha of each vertex; where each
47
+ * vertex is in its image; three vertex numbers for each triangle. They are over one white pixel, or over an image.
48
+ */
49
+ export interface ShapeBatch {
50
+ positions: number[];
51
+ colors: number[];
52
+ uvs: number[];
53
+ indices: number[];
54
+ bitmap: ShapeBitmap | undefined;
55
+ }
56
+ /** A drawing in order: the batches that are finished, and the one being added to. A fill of another image begins a batch. */
57
+ export interface ShapeDrawing extends ShapeBatch {
58
+ done: ShapeBatch[];
59
+ }
60
+ export interface ShapeState extends ShapeDrawing {
61
+ path: ShapePath | undefined;
62
+ /** What the lists and the path give, made when capture or bounds first ask after a change. */
63
+ resolved: ResolvedShape | undefined;
64
+ }
65
+ /** One geometry for each batch that has a triangle, in drawing order, with the image it is drawn over if it has one. */
66
+ export interface ResolvedPart {
67
+ readonly geometry: SharedGeometry2D;
68
+ readonly bitmap: ShapeBitmap | undefined;
69
+ }
70
+ export interface ResolvedShape {
71
+ readonly parts: readonly ResolvedPart[];
72
+ readonly bounds: Rectangle2D;
73
+ }
74
+ /** The most one node's shapes may hold: what one shared geometry takes. */
75
+ export declare const GRAPHICS_SHAPE_LIMITS: Readonly<{
76
+ maxVertices: 65536;
77
+ maxIndices: 196608;
78
+ maxLogicalBytes: 4980736;
79
+ maxPathPoints: 8192;
80
+ maxLineWidth: 1024;
81
+ maxDashes: 16384;
82
+ maxGradientStops: 16;
83
+ maxFillTriangles: 16384;
84
+ maxBatches: 16;
85
+ maxRepeatPixels: 8192;
86
+ }>;
87
+ /** The one white pixel every shape samples: its colour is the colour of its vertices. */
88
+ export declare const SHAPE_PAGE: ImageData2D;
89
+ export declare const SHAPE_REGION: Readonly<{
90
+ packed: Readonly<{
91
+ x: 0;
92
+ y: 0;
93
+ width: 1;
94
+ height: 1;
95
+ }>;
96
+ logicalWidth: 1;
97
+ logicalHeight: 1;
98
+ trimX: 0;
99
+ trimY: 0;
100
+ quarterTurn: 0;
101
+ }>;
102
+ export declare function createShapeState(): ShapeState;
103
+ /** A copy that can be drawn on without changing the drawing it was made from. */
104
+ export declare function copyDrawing(from: ShapeDrawing): ShapeDrawing;
105
+ type Target = ShapeDrawing;
106
+ /** A convex outline as a fan from its first corner. */
107
+ export declare function fillConvex(target: Target, outline: readonly number[], color: ShapePaint): void;
108
+ /** Any simple outline, by cutting ears. An outline that crosses itself is filled without a promise about where. */
109
+ export declare function fillPolygon(target: Target, outline: readonly number[], color: ShapePaint): void;
110
+ /**
111
+ * What closed outlines cover, filled. One outline that does not cross itself is cut into ears; several, or one that
112
+ * crosses itself, are filled by the non-zero rule, so an outline drawn the other way round inside another is a hole.
113
+ * A gradient is given as the colours of the corners, with triangles cut until that is close enough.
114
+ * False when the fill would take more triangles than one fill may.
115
+ */
116
+ export declare function fillOutlines(target: Target, outlines: readonly (readonly number[])[], convex: boolean, color: ShapePaint, edge?: boolean): boolean;
117
+ /**
118
+ * A line of a width along points. Two pieces meet at a corner in one point on its inside, so a translucent line is not
119
+ * darker there; its outside is a mitre, cut to a bevel when longer than `miterLimit` half-widths, a bevel or an arc.
120
+ * An open line ends flat, in a half square or in a half circle. False when its dashes are more than a line may have.
121
+ */
122
+ export declare function strokeLine(target: Target, line: readonly number[], closed: boolean, style: ShapeLine): boolean;
123
+ /** How many straight pieces a curve of this radius is drawn with: each is within a quarter unit of the curve. */
124
+ export declare function curveSegments(radius: number): number;
125
+ /** An ellipse as an outline, starting at its right and going on through its bottom. */
126
+ export declare function ellipseOutline(cx: number, cy: number, rx: number, ry: number): number[];
127
+ /** A rectangle whose corners are quarter ellipses of the two radii. */
128
+ export declare function roundRectOutline(x: number, y: number, width: number, height: number, rx: number, ry: number): number[];
129
+ /** The points of an arc after its first, which the caller has already placed. */
130
+ export declare function arcPoints(cx: number, cy: number, radius: number, start: number, end: number, anticlockwise: boolean): number[];
131
+ /** The points of a curve of two or three control points after its first, which is `from`. */
132
+ export declare function bezierPoints(from: readonly [number, number], controls: readonly number[], to: readonly [number, number]): number[];
133
+ /** A shape drawn at once: its fill under its line. False when it is more than a fill or a line may be. */
134
+ export declare function addOutline(target: Target, outline: readonly number[], convex: boolean, fill: ShapePaint | undefined, line: ShapeLine | undefined): boolean;
135
+ /** The triangles of a path: its parts filled together as closed outlines, then each lined, closed only where its ends meet. */
136
+ export declare function addPath(target: Target, path: ShapePath): boolean;
137
+ /** Whether a drawing of this many vertices and indices is one a node may hold. */
138
+ export declare function shapeFits(vertices: number, indices: number): boolean;
139
+ /** Whether a drawing is one a node may hold: every batch within what one geometry takes, and no more batches than a node has. */
140
+ export declare function drawingFits(drawing: ShapeDrawing): boolean;
141
+ /** The geometries and bounds of a node's shapes, or undefined while they hold no triangle. */
142
+ export declare function resolveShape(shape: ShapeState): ResolvedShape | undefined;
143
+ export {};
144
+ //# sourceMappingURL=graphicsShape.d.ts.map