@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,22 @@
1
+ import { recordVisualChange, VISUAL_CONTENT, VISUAL_BINDING } from './displayVisualState.js';
2
+ // One authoritative slot table, moved from Bitmap without duplicating geometry.
3
+ // Resource references remain type-only; revisions retain no resource ownership.
4
+ const states = new WeakMap();
5
+ const readPublishedState = states.get.bind(states);
6
+ /** A registered cleared slot remains different from an unregistered receiver. */
7
+ export function hasBitmapState(value) {
8
+ return states.has(value);
9
+ }
10
+ /** Read cached metadata only; this port grants no live image entitlement. */
11
+ export function readBitmapState(node) {
12
+ return states.get(node);
13
+ }
14
+ /** Bitmap alone writes its slot, preserving existing mutation/lifetime guards. */
15
+ export function writeBitmapState(node, value) {
16
+ const changed = readPublishedState(node) !== value;
17
+ states.set(node, value);
18
+ // Single writes, batch commits and conditional rollback share this publication.
19
+ if (changed)
20
+ recordVisualChange(node, VISUAL_CONTENT | VISUAL_BINDING);
21
+ }
22
+ //# sourceMappingURL=bitmapDisplayState.js.map
@@ -0,0 +1,4 @@
1
+ import type { Matrix2D, Point2D } from '@egret/contracts';
2
+ /** Exact rank belongs to the stored finite world matrix, not authored scales. */
3
+ export declare function invertCoordinatePoint(matrix: Matrix2D, x: number, y: number): Point2D;
4
+ //# sourceMappingURL=coordinateInverse.d.ts.map
@@ -0,0 +1,107 @@
1
+ import { EgretError } from './EgretError.js';
2
+ const FRACTION_MASK = (1n << 52n) - 1n;
3
+ const MAX_BITS = 8192;
4
+ function magnitude(n) {
5
+ return n < 0n ? -n : n;
6
+ }
7
+ function bits(n) {
8
+ return n === 0n ? 0 : magnitude(n).toString(2).length;
9
+ }
10
+ function bounded(n) {
11
+ if (bits(n) > MAX_BITS)
12
+ throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
13
+ return n;
14
+ }
15
+ /** Finite binary64 is decoded exactly; both DataView operations use big endian. */
16
+ function decodeFiniteDyadic(value, view) {
17
+ view.setFloat64(0, value, false);
18
+ const raw = view.getBigUint64(0, false);
19
+ const encodedExponent = Number((raw >> 52n) & 0x7ffn);
20
+ const fraction = raw & FRACTION_MASK;
21
+ const integer = encodedExponent === 0 ? fraction : (1n << 52n) | fraction;
22
+ return {
23
+ integer: raw >> 63n === 0n ? integer : -integer,
24
+ exponent: encodedExponent === 0 ? -1074 : encodedExponent - 1075
25
+ };
26
+ }
27
+ /** Only the fixed two/four inverse products are admitted, with no rounded sum. */
28
+ function sumDyadicProducts(terms) {
29
+ const products = terms.map(([left, right, sign]) => ({
30
+ integer: bounded(left.integer * right.integer * BigInt(sign)),
31
+ exponent: left.exponent + right.exponent
32
+ }));
33
+ const nonzero = products.filter(product => product.integer !== 0n);
34
+ if (nonzero.length === 0)
35
+ return { integer: 0n, exponent: 0 };
36
+ const exponent = Math.min(...nonzero.map(product => product.exponent));
37
+ let integer = 0n;
38
+ for (const product of nonzero) {
39
+ integer = bounded(integer + bounded(product.integer << BigInt(product.exponent - exponent)));
40
+ }
41
+ return { integer, exponent };
42
+ }
43
+ /** Round the exact rational once, including subnormal ties and overflow carry. */
44
+ function roundDyadicRatio(numerator, denominator) {
45
+ if (numerator.integer === 0n)
46
+ return 0;
47
+ const negative = numerator.integer < 0n !== denominator.integer < 0n;
48
+ let n = magnitude(numerator.integer);
49
+ let d = magnitude(denominator.integer);
50
+ let binaryExponent = bits(n) - bits(d);
51
+ if (binaryExponent >= 0) {
52
+ if (n < bounded(d << BigInt(binaryExponent)))
53
+ binaryExponent--;
54
+ }
55
+ else if (bounded(n << BigInt(-binaryExponent)) < d)
56
+ binaryExponent--;
57
+ const exponentDifference = numerator.exponent - denominator.exponent;
58
+ const k = binaryExponent + exponentDifference;
59
+ if (k > 1023)
60
+ throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
61
+ if (k < -1075)
62
+ return 0;
63
+ const quantum = k >= -1022 ? k - 52 : -1074;
64
+ const shift = exponentDifference - quantum;
65
+ if (shift >= 0)
66
+ n = bounded(n << BigInt(shift));
67
+ else
68
+ d = bounded(d << BigInt(-shift));
69
+ let significand = n / d;
70
+ const remainder = n % d;
71
+ const twiceRemainder = remainder << 1n;
72
+ if (twiceRemainder > d || (twiceRemainder === d && (significand & 1n) !== 0n))
73
+ significand++;
74
+ const result = Number(significand) * 2 ** quantum;
75
+ if (!Number.isFinite(result))
76
+ throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
77
+ return result === 0 ? 0 : negative ? -result : result;
78
+ }
79
+ /** Exact rank belongs to the stored finite world matrix, not authored scales. */
80
+ export function invertCoordinatePoint(matrix, x, y) {
81
+ const view = new DataView(new ArrayBuffer(8));
82
+ const a = decodeFiniteDyadic(matrix.a, view), b = decodeFiniteDyadic(matrix.b, view);
83
+ const c = decodeFiniteDyadic(matrix.c, view), d = decodeFiniteDyadic(matrix.d, view);
84
+ const tx = decodeFiniteDyadic(matrix.tx, view), ty = decodeFiniteDyadic(matrix.ty, view);
85
+ const gx = decodeFiniteDyadic(x, view), gy = decodeFiniteDyadic(y, view);
86
+ const determinant = sumDyadicProducts([
87
+ [a, d, 1],
88
+ [b, c, -1]
89
+ ]);
90
+ if (determinant.integer === 0n)
91
+ throw new EgretError('COORDINATE_TRANSFORM_SINGULAR');
92
+ const nx = sumDyadicProducts([
93
+ [d, gx, 1],
94
+ [d, tx, -1],
95
+ [c, gy, -1],
96
+ [c, ty, 1]
97
+ ]);
98
+ const ny = sumDyadicProducts([
99
+ [a, gy, 1],
100
+ [a, ty, -1],
101
+ [b, gx, -1],
102
+ [b, tx, 1]
103
+ ]);
104
+ // Both coordinates finish before the caller can publish an owned point.
105
+ return { x: roundDyadicRatio(nx, determinant), y: roundDyadicRatio(ny, determinant) };
106
+ }
107
+ //# sourceMappingURL=coordinateInverse.js.map
@@ -0,0 +1,4 @@
1
+ import type { Diagnostic, DiagnosticHandler } from "@egret/contracts";
2
+ /** Observer failures have no authority to interrupt cancellation or cleanup. */
3
+ export declare function reportDiagnostic(handler: DiagnosticHandler | undefined, diagnostic: Diagnostic): void;
4
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1,13 @@
1
+ /** Observer failures have no authority to interrupt cancellation or cleanup. */
2
+ export function reportDiagnostic(handler, diagnostic) {
3
+ try {
4
+ // Freeze the diagnostic envelope; application-owned cause objects stay borrowed.
5
+ handler?.(Object.freeze(diagnostic));
6
+ }
7
+ catch (cause) {
8
+ // The lifecycle failure remains in Diagnostic.cause / Engine's failure list.
9
+ // Do not call a failing observer recursively or replace the original failure.
10
+ void cause;
11
+ }
12
+ }
13
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1,9 @@
1
+ import type { Rectangle2D } from '@egret/contracts';
2
+ /** Receiver-inclusive node and content budgets for logical local measurement. */
3
+ export interface BoundsQueryOptions {
4
+ readonly maxNodes?: number;
5
+ readonly maxPrimitives?: number;
6
+ }
7
+ /** Private state only: no display-class value import, resource lookup or public hook. */
8
+ export declare function queryDisplayBounds(receiver: unknown, options: unknown): Rectangle2D;
9
+ //# sourceMappingURL=displayBounds.d.ts.map
@@ -0,0 +1,181 @@
1
+ import { resolveShape } from './graphicsShape.js';
2
+ import { readBitmapState } from './bitmapDisplayState.js';
3
+ import { readMeshState } from './meshDisplayState.js';
4
+ import { assertTextFieldScope, readTextFieldState } from './textDisplayState.js';
5
+ import { assertLive, childAtOf, childCountOf, isDisplayNode, parentOf } from './displayTreeState.js';
6
+ import { composeDisplayTransform } from './displayTransform.js';
7
+ import { finite, visualOf } from './displayVisualState.js';
8
+ import { engineOf } from './ownership.js';
9
+ import { EgretError } from './EgretError.js';
10
+ function live(node) {
11
+ assertLive(node);
12
+ engineOf(node)?.assertOpen();
13
+ }
14
+ function budgetsOf(node, options) {
15
+ let nodes, primitives;
16
+ if (options !== undefined) {
17
+ if (options === null || typeof options !== 'object')
18
+ throw new EgretError('BOUNDS_INPUT_INVALID');
19
+ let array;
20
+ // Revoked Proxy admission can throw. Array rejection is a semantic failure
21
+ // outside the source catch, and normal lookup retains inherited getters.
22
+ try {
23
+ array = Array.isArray(options);
24
+ }
25
+ catch (cause) {
26
+ throw new EgretError('BOUNDS_INPUT_INVALID', { cause });
27
+ }
28
+ if (array)
29
+ throw new EgretError('BOUNDS_INPUT_INVALID');
30
+ try {
31
+ nodes = options.maxNodes;
32
+ primitives = options.maxPrimitives;
33
+ }
34
+ catch (cause) {
35
+ throw new EgretError('BOUNDS_INPUT_INVALID', { cause });
36
+ }
37
+ }
38
+ // Finish both successful source reads before lifetime and numeric semantics.
39
+ // Throwing reads retain exact supplied causes, even after terminal side effects.
40
+ live(node);
41
+ const maxNodes = nodes === undefined ? 4096 : nodes;
42
+ const maxPrimitives = primitives === undefined ? 65536 : primitives;
43
+ if (!finite(maxNodes) || !Number.isInteger(maxNodes) || maxNodes < 1 || maxNodes > 65536) {
44
+ throw new EgretError('BOUNDS_INPUT_INVALID');
45
+ }
46
+ if (!finite(maxPrimitives) || !Number.isInteger(maxPrimitives) || maxPrimitives < 1 || maxPrimitives > 262144) {
47
+ throw new EgretError('BOUNDS_INPUT_INVALID');
48
+ }
49
+ return { maxNodes, maxPrimitives };
50
+ }
51
+ /** Private state only: no display-class value import, resource lookup or public hook. */
52
+ export function queryDisplayBounds(receiver, options) {
53
+ if (!isDisplayNode(receiver))
54
+ throw new EgretError('BOUNDS_RECEIVER_INVALID');
55
+ const node = receiver;
56
+ live(node);
57
+ const { maxNodes, maxPrimitives } = budgetsOf(node, options);
58
+ const seen = new Set(), visited = [], stack = [];
59
+ let items = 0, hasContent = false, minX = 0, minY = 0, maxX = 0, maxY = 0;
60
+ function admitItem() {
61
+ // Admission precedes indexing the next primitive's geometry or Bitmap size.
62
+ if (items >= maxPrimitives)
63
+ throw new EgretError('BOUNDS_CONTENT_LIMIT');
64
+ items++;
65
+ }
66
+ function point(matrix, x, y) {
67
+ const px = matrix.a * x + matrix.c * y + matrix.tx;
68
+ const py = matrix.b * x + matrix.d * y + matrix.ty;
69
+ if (!finite(px) || !finite(py))
70
+ throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
71
+ if (!hasContent) {
72
+ minX = maxX = px;
73
+ minY = maxY = py;
74
+ hasContent = true;
75
+ }
76
+ else {
77
+ minX = Math.min(minX, px);
78
+ minY = Math.min(minY, py);
79
+ maxX = Math.max(maxX, px);
80
+ maxY = Math.max(maxY, py);
81
+ }
82
+ }
83
+ function rectangle(matrix, x, y, width, height) {
84
+ // Authored zero extent consumes budget but does not evaluate endpoints.
85
+ // Positive content may still collapse to a point or line through rounding.
86
+ if (width === 0 || height === 0)
87
+ return;
88
+ const right = x + width, bottom = y + height;
89
+ if (!finite(right) || !finite(bottom))
90
+ throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
91
+ point(matrix, x, y);
92
+ point(matrix, right, y);
93
+ point(matrix, right, bottom);
94
+ point(matrix, x, bottom);
95
+ }
96
+ function enter(current, matrix) {
97
+ if (!isDisplayNode(current) || seen.has(current))
98
+ throw new EgretError('DISPLAY_TREE_INVARIANT');
99
+ live(current);
100
+ seen.add(current);
101
+ visited.push(current);
102
+ const primitives = visualOf(current).primitives;
103
+ for (let index = 0; index < primitives.length; index++) {
104
+ admitItem();
105
+ const rect = primitives[index].rect;
106
+ rectangle(matrix, rect.x, rect.y, rect.width, rect.height);
107
+ }
108
+ const shapeState = visualOf(current).shape, shape = shapeState === undefined ? undefined : resolveShape(shapeState);
109
+ if (shape !== undefined) {
110
+ admitItem();
111
+ rectangle(matrix, shape.bounds.x, shape.bounds.y, shape.bounds.width, shape.bounds.height);
112
+ }
113
+ const bitmap = readBitmapState(current);
114
+ if (bitmap !== undefined) {
115
+ admitItem();
116
+ rectangle(matrix, 0, 0, bitmap.width, bitmap.height);
117
+ }
118
+ const mesh = readMeshState(current);
119
+ if (mesh !== undefined) {
120
+ const geometry = mesh.geometry;
121
+ for (let triangle = 0; triangle < geometry.triangleCount; triangle++) {
122
+ // Debit before all three index reads; shared geometry still costs per use.
123
+ admitItem();
124
+ const offset = 3 * triangle;
125
+ const first = geometry.indices[offset], second = geometry.indices[offset + 1], third = geometry.indices[offset + 2];
126
+ // Logical bounds retain authored point/line triangles and skip unused XY.
127
+ point(matrix, geometry.positions[2 * first], geometry.positions[2 * first + 1]);
128
+ point(matrix, geometry.positions[2 * second], geometry.positions[2 * second + 1]);
129
+ point(matrix, geometry.positions[2 * third], geometry.positions[2 * third + 1]);
130
+ }
131
+ }
132
+ const text = readTextFieldState(current);
133
+ if (text !== undefined) {
134
+ assertTextFieldScope(text.scope);
135
+ if (text.committed !== undefined) {
136
+ admitItem();
137
+ const rect = text.committed.contentBounds;
138
+ rectangle(matrix, rect.x, rect.y, rect.width, rect.height);
139
+ }
140
+ }
141
+ stack.push({ node: current, matrix, children: childCountOf(current), nextChild: 0 });
142
+ }
143
+ // The receiver's frame is identity. Its own and all ancestor transforms are
144
+ // excluded, so no inverse or receiver/ancestor composition is evaluated.
145
+ enter(node, { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 });
146
+ while (stack.length !== 0) {
147
+ const frame = stack[stack.length - 1];
148
+ if (frame.nextChild === frame.children) {
149
+ stack.pop();
150
+ continue;
151
+ }
152
+ // Check before indexed retrieval: no eager child snapshot or sibling stack.
153
+ if (visited.length >= maxNodes)
154
+ throw new EgretError('BOUNDS_TREE_LIMIT');
155
+ const child = childAtOf(frame.node, frame.nextChild++);
156
+ if (child === undefined || !isDisplayNode(child) || seen.has(child) || parentOf(child) !== frame.node) {
157
+ throw new EgretError('DISPLAY_TREE_INVARIANT');
158
+ }
159
+ live(child);
160
+ const matrix = composeDisplayTransform(frame.matrix, visualOf(child));
161
+ // Completed descendant matrices are checked even for empty/zero-only nodes.
162
+ if (![matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty].every(finite)) {
163
+ throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
164
+ }
165
+ enter(child, matrix);
166
+ }
167
+ const width = hasContent ? maxX - minX : 0, height = hasContent ? maxY - minY : 0;
168
+ if (!finite(width) || !finite(height))
169
+ throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
170
+ for (const current of visited)
171
+ live(current);
172
+ // Ordinary binary64 subtraction is intentional, not an outward enclosure.
173
+ // Saved output retains no authority, options, primitive or resource reference.
174
+ return Object.freeze({
175
+ x: minX === 0 ? 0 : minX,
176
+ y: minY === 0 ? 0 : minY,
177
+ width: width === 0 ? 0 : width,
178
+ height: height === 0 ? 0 : height
179
+ });
180
+ }
181
+ //# sourceMappingURL=displayBounds.js.map
@@ -0,0 +1,8 @@
1
+ import type { Point2D } from '@egret/contracts';
2
+ /** Receiver-inclusive ancestor budget; omitted maxNodes defaults to 4096. */
3
+ export interface CoordinateQueryOptions {
4
+ readonly maxNodes?: number;
5
+ }
6
+ /** Private identity/state authority excludes getters and subclass hooks. */
7
+ export declare function queryDisplayPoint(receiver: unknown, x: unknown, y: unknown, options: unknown, inverse: boolean): Point2D;
8
+ //# sourceMappingURL=displayCoordinates.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { isDisplayNode, assertLive, parentOf } from './displayTreeState.js';
2
+ import { engineOf } from './ownership.js';
3
+ import { finite, visualOf } from './displayVisualState.js';
4
+ import { composeDisplayTransform } from './displayTransform.js';
5
+ import { invertCoordinatePoint } from './coordinateInverse.js';
6
+ import { EgretError } from './EgretError.js';
7
+ function live(node) {
8
+ assertLive(node);
9
+ engineOf(node)?.assertOpen();
10
+ }
11
+ function budgetOf(node, options) {
12
+ let requested;
13
+ if (options !== undefined) {
14
+ if (options === null || typeof options !== 'object')
15
+ throw new EgretError('COORDINATE_INPUT_INVALID');
16
+ let array;
17
+ // Admission can itself throw for a revoked Proxy; semantic rejection stays
18
+ // outside the source catch so it is never mistaken for an adapter failure.
19
+ try {
20
+ array = Array.isArray(options);
21
+ }
22
+ catch (cause) {
23
+ throw new EgretError('COORDINATE_INPUT_INVALID', { cause });
24
+ }
25
+ if (array)
26
+ throw new EgretError('COORDINATE_INPUT_INVALID');
27
+ try {
28
+ requested = options.maxNodes;
29
+ }
30
+ catch (cause) {
31
+ throw new EgretError('COORDINATE_INPUT_INVALID', { cause });
32
+ }
33
+ }
34
+ // A successful caller read may mutate, reparent, dispose or close the node.
35
+ // Throwing reads preserve their exact cause without this later recheck.
36
+ live(node);
37
+ const maxNodes = requested === undefined ? 4096 : requested;
38
+ if (!finite(maxNodes) || !Number.isInteger(maxNodes) || maxNodes < 1 || maxNodes > 65536) {
39
+ throw new EgretError('COORDINATE_INPUT_INVALID');
40
+ }
41
+ return maxNodes;
42
+ }
43
+ /** Private identity/state authority excludes getters and subclass hooks. */
44
+ export function queryDisplayPoint(receiver, x, y, options, inverse) {
45
+ if (!isDisplayNode(receiver))
46
+ throw new EgretError('COORDINATE_RECEIVER_INVALID');
47
+ const node = receiver;
48
+ live(node);
49
+ const px = x === undefined ? 0 : x, py = y === undefined ? 0 : y;
50
+ if (!finite(px) || !finite(py))
51
+ throw new EgretError('COORDINATE_INPUT_INVALID');
52
+ const maxNodes = budgetOf(node, options);
53
+ const path = [], seen = new Set();
54
+ for (let current = node; current !== undefined; current = parentOf(current)) {
55
+ if (path.length >= maxNodes)
56
+ throw new EgretError('COORDINATE_TREE_LIMIT');
57
+ if (seen.has(current))
58
+ throw new EgretError('DISPLAY_TREE_INVARIANT');
59
+ live(current);
60
+ seen.add(current);
61
+ path.push(current);
62
+ }
63
+ let world = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
64
+ for (let i = path.length - 1; i >= 0; i--) {
65
+ world = composeDisplayTransform(world, visualOf(path[i]));
66
+ if (!Object.values(world).every(finite))
67
+ throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
68
+ }
69
+ const result = inverse
70
+ ? invertCoordinatePoint(world, px, py)
71
+ : {
72
+ x: world.a * px + world.c * py + world.tx,
73
+ y: world.b * px + world.d * py + world.ty
74
+ };
75
+ if (!finite(result.x) || !finite(result.y))
76
+ throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
77
+ for (const current of path)
78
+ live(current);
79
+ return Object.freeze({ x: result.x === 0 ? 0 : result.x, y: result.y === 0 ? 0 : result.y });
80
+ }
81
+ //# sourceMappingURL=displayCoordinates.js.map
@@ -0,0 +1,18 @@
1
+ import type { Rectangle2D } from '@egret/contracts';
2
+ import type { DisplayObject } from './DisplayObject.js';
3
+ interface DisplayHitState {
4
+ touchEnabled: boolean;
5
+ hitArea: Rectangle2D | undefined;
6
+ touchChildren: boolean | undefined;
7
+ }
8
+ export declare function registerDisplayHitNode(node: DisplayObject): void;
9
+ export declare function registerDisplayHitContainer(node: DisplayObject): void;
10
+ /** Genuine identity is checked before any receiver property can be consulted. */
11
+ export declare function readDisplayHitState(receiver: unknown): DisplayHitState;
12
+ export declare function writeDisplayTouchEnabled(receiver: unknown, value: unknown): void;
13
+ export declare function readDisplayTouchChildren(receiver: unknown): boolean;
14
+ export declare function writeDisplayTouchChildren(receiver: unknown, value: unknown): void;
15
+ /** Read caller fields once in fixed order; source faults never become semantics. */
16
+ export declare function writeDisplayHitArea(receiver: unknown, source: unknown): void;
17
+ export {};
18
+ //# sourceMappingURL=displayHitState.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { assertManagedMutable } from './ui/managedState.js';
2
+ import { EgretError } from './EgretError.js';
3
+ import { assertLive, isDisplayNode } from './displayTreeState.js';
4
+ import { finite } from './displayVisualState.js';
5
+ import { engineOf } from './ownership.js';
6
+ // Interaction authority is independent of rendering content and public hooks.
7
+ const states = new WeakMap();
8
+ export function registerDisplayHitNode(node) {
9
+ states.set(node, { touchEnabled: false, hitArea: undefined, touchChildren: undefined });
10
+ }
11
+ export function registerDisplayHitContainer(node) {
12
+ readDisplayHitState(node).touchChildren = true;
13
+ }
14
+ /** Genuine identity is checked before any receiver property can be consulted. */
15
+ export function readDisplayHitState(receiver) {
16
+ if (!isDisplayNode(receiver))
17
+ throw new EgretError('HIT_TEST_RECEIVER_INVALID');
18
+ const state = states.get(receiver);
19
+ if (state === undefined)
20
+ throw new EgretError('HIT_TEST_RECEIVER_INVALID');
21
+ return state;
22
+ }
23
+ function live(node) {
24
+ assertManagedMutable(node);
25
+ assertLive(node);
26
+ engineOf(node)?.assertOpen();
27
+ }
28
+ export function writeDisplayTouchEnabled(receiver, value) {
29
+ const state = readDisplayHitState(receiver), node = receiver;
30
+ live(node);
31
+ if (typeof value !== 'boolean')
32
+ throw new EgretError('HIT_TEST_VALUE_INVALID');
33
+ state.touchEnabled = value;
34
+ }
35
+ export function readDisplayTouchChildren(receiver) {
36
+ const value = readDisplayHitState(receiver).touchChildren;
37
+ if (value === undefined)
38
+ throw new EgretError('HIT_TEST_RECEIVER_INVALID');
39
+ return value;
40
+ }
41
+ export function writeDisplayTouchChildren(receiver, value) {
42
+ const state = readDisplayHitState(receiver);
43
+ if (state.touchChildren === undefined)
44
+ throw new EgretError('HIT_TEST_RECEIVER_INVALID');
45
+ const node = receiver;
46
+ live(node);
47
+ if (typeof value !== 'boolean')
48
+ throw new EgretError('HIT_TEST_VALUE_INVALID');
49
+ state.touchChildren = value;
50
+ }
51
+ /** Read caller fields once in fixed order; source faults never become semantics. */
52
+ export function writeDisplayHitArea(receiver, source) {
53
+ const state = readDisplayHitState(receiver), node = receiver;
54
+ live(node);
55
+ if (source === undefined) {
56
+ state.hitArea = undefined;
57
+ return;
58
+ }
59
+ if (source === null || typeof source !== 'object')
60
+ throw new EgretError('HIT_TEST_AREA_INVALID');
61
+ let array;
62
+ try {
63
+ array = Array.isArray(source);
64
+ }
65
+ catch (cause) {
66
+ throw new EgretError('HIT_TEST_AREA_INVALID', { cause });
67
+ }
68
+ if (array)
69
+ throw new EgretError('HIT_TEST_AREA_INVALID');
70
+ let x, y, width, height;
71
+ try {
72
+ const area = source;
73
+ x = area.x;
74
+ y = area.y;
75
+ width = area.width;
76
+ height = area.height;
77
+ }
78
+ catch (cause) {
79
+ // Application EgretError and even undefined throws retain their exact cause.
80
+ throw new EgretError('HIT_TEST_AREA_INVALID', { cause });
81
+ }
82
+ // Successful source reads may terminate or rebind the current node. Their
83
+ // completed reentrant effects stand; this outer admission commits only here.
84
+ live(node);
85
+ if (!finite(x) ||
86
+ !finite(y) ||
87
+ !finite(width) ||
88
+ !finite(height) ||
89
+ width < 0 ||
90
+ height < 0 ||
91
+ !finite(x + width) ||
92
+ !finite(y + height)) {
93
+ throw new EgretError('HIT_TEST_AREA_INVALID');
94
+ }
95
+ state.hitArea = Object.freeze({ x, y, width, height });
96
+ }
97
+ //# sourceMappingURL=displayHitState.js.map
@@ -0,0 +1,8 @@
1
+ import type { DisplayObject } from './DisplayObject.js';
2
+ /** Receiver-inclusive whole-tree admission precedes all hit arithmetic. */
3
+ export interface HitTestOptions {
4
+ readonly maxNodes?: number;
5
+ }
6
+ /** Private state only; all active arithmetic completes before a borrowed result. */
7
+ export declare function queryDisplayHit(receiver: unknown, x: unknown, y: unknown, options: unknown): DisplayObject | undefined;
8
+ //# sourceMappingURL=displayHitTest.d.ts.map