@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.
- package/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +70 -2
- package/README.zh-CN.md +71 -0
- package/dist/AssetLease.d.ts +23 -0
- package/dist/AssetLease.js +69 -0
- package/dist/AssetManager.d.ts +56 -0
- package/dist/AssetManager.js +451 -0
- package/dist/AssetRef.d.ts +20 -0
- package/dist/AssetRef.js +32 -0
- package/dist/Bitmap.d.ts +40 -0
- package/dist/Bitmap.js +545 -0
- package/dist/ByteReader.d.ts +30 -0
- package/dist/ByteReader.js +177 -0
- package/dist/ByteWriter.d.ts +29 -0
- package/dist/ByteWriter.js +180 -0
- package/dist/CancellationController.d.ts +10 -0
- package/dist/CancellationController.js +66 -0
- package/dist/DisplayObject.d.ts +89 -0
- package/dist/DisplayObject.js +340 -0
- package/dist/DisplayObjectContainer.d.ts +28 -0
- package/dist/DisplayObjectContainer.js +226 -0
- package/dist/EgretError.d.ts +11 -0
- package/dist/EgretError.js +36 -0
- package/dist/Event.d.ts +45 -0
- package/dist/Event.js +84 -0
- package/dist/EventDispatcher.d.ts +24 -0
- package/dist/EventDispatcher.js +178 -0
- package/dist/Graphics.d.ts +106 -0
- package/dist/Graphics.js +504 -0
- package/dist/Mesh2D.d.ts +27 -0
- package/dist/Mesh2D.js +200 -0
- package/dist/NineSliceBitmap.d.ts +24 -0
- package/dist/NineSliceBitmap.js +164 -0
- package/dist/NineSliceGeometry2D.d.ts +18 -0
- package/dist/NineSliceGeometry2D.js +126 -0
- package/dist/Scope.d.ts +18 -0
- package/dist/Scope.js +133 -0
- package/dist/SequencePlayer.d.ts +12 -0
- package/dist/SequencePlayer.js +69 -0
- package/dist/Sprite.d.ts +8 -0
- package/dist/Sprite.js +12 -0
- package/dist/Stage.d.ts +14 -0
- package/dist/Stage.js +31 -0
- package/dist/Texture.d.ts +29 -0
- package/dist/Texture.js +177 -0
- package/dist/assetManagerOwnerState.d.ts +36 -0
- package/dist/assetManagerOwnerState.js +115 -0
- package/dist/assetState.d.ts +44 -0
- package/dist/assetState.js +2 -0
- package/dist/atlasFrameLayout.d.ts +21 -0
- package/dist/atlasFrameLayout.js +48 -0
- package/dist/bitmapDisplayState.d.ts +24 -0
- package/dist/bitmapDisplayState.js +22 -0
- package/dist/coordinateInverse.d.ts +4 -0
- package/dist/coordinateInverse.js +107 -0
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.js +13 -0
- package/dist/displayBounds.d.ts +9 -0
- package/dist/displayBounds.js +181 -0
- package/dist/displayCoordinates.d.ts +8 -0
- package/dist/displayCoordinates.js +81 -0
- package/dist/displayHitState.d.ts +18 -0
- package/dist/displayHitState.js +97 -0
- package/dist/displayHitTest.d.ts +8 -0
- package/dist/displayHitTest.js +219 -0
- package/dist/displayInputOperations.d.ts +12 -0
- package/dist/displayInputOperations.js +71 -0
- package/dist/displayTransform.d.ts +5 -0
- package/dist/displayTransform.js +38 -0
- package/dist/displayTreeState.d.ts +90 -0
- package/dist/displayTreeState.js +450 -0
- package/dist/displayVisualState.d.ts +74 -0
- package/dist/displayVisualState.js +140 -0
- package/dist/errorHelp.d.ts +14 -0
- package/dist/errorHelp.js +432 -0
- package/dist/errorHelpZh.d.ts +5 -0
- package/dist/errorHelpZh.js +340 -0
- package/dist/graphicsFill.d.ts +37 -0
- package/dist/graphicsFill.js +302 -0
- package/dist/graphicsShape.d.ts +144 -0
- package/dist/graphicsShape.js +755 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +28 -0
- package/dist/input/PointerRouter.d.ts +4 -0
- package/dist/input/PointerRouter.js +453 -0
- package/dist/input/index.d.ts +3 -0
- package/dist/input/index.js +3 -0
- package/dist/input/types.d.ts +58 -0
- package/dist/input/types.js +3 -0
- package/dist/meshCaptureSnapshot.d.ts +5 -0
- package/dist/meshCaptureSnapshot.js +13 -0
- package/dist/meshDisplayState.d.ts +18 -0
- package/dist/meshDisplayState.js +21 -0
- package/dist/ownership.d.ts +75 -0
- package/dist/ownership.js +157 -0
- package/dist/paragraph/Paragraph.d.ts +13 -0
- package/dist/paragraph/Paragraph.js +193 -0
- package/dist/paragraph/ParagraphCache.d.ts +5 -0
- package/dist/paragraph/ParagraphCache.js +354 -0
- package/dist/paragraph/geometry.d.ts +4 -0
- package/dist/paragraph/geometry.js +180 -0
- package/dist/paragraph/index.d.ts +3 -0
- package/dist/paragraph/index.js +3 -0
- package/dist/paragraph/request.d.ts +6 -0
- package/dist/paragraph/request.js +191 -0
- package/dist/paragraph/types.d.ts +183 -0
- package/dist/paragraph/types.js +2 -0
- package/dist/preparedDisplaySubtree.d.ts +7 -0
- package/dist/preparedDisplaySubtree.js +205 -0
- package/dist/renderEffect.d.ts +47 -0
- package/dist/renderEffect.js +87 -0
- package/dist/sequenceClip.d.ts +42 -0
- package/dist/sequenceClip.js +196 -0
- package/dist/sharedFrameCapture.d.ts +24 -0
- package/dist/sharedFrameCapture.js +1069 -0
- package/dist/spriteSheet.d.ts +34 -0
- package/dist/spriteSheet.js +321 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/text/TextField.d.ts +13 -0
- package/dist/text/TextField.js +261 -0
- package/dist/text/TextRasterCache.d.ts +5 -0
- package/dist/text/TextRasterCache.js +1191 -0
- package/dist/text/budget.d.ts +51 -0
- package/dist/text/budget.js +116 -0
- package/dist/text/index.d.ts +4 -0
- package/dist/text/index.js +3 -0
- package/dist/text/plan.d.ts +16 -0
- package/dist/text/plan.js +238 -0
- package/dist/text/request.d.ts +44 -0
- package/dist/text/request.js +303 -0
- package/dist/text/types.d.ts +179 -0
- package/dist/text/types.js +2 -0
- package/dist/textDisplayState.d.ts +21 -0
- package/dist/textDisplayState.js +27 -0
- package/dist/ui/displayCommit.d.ts +43 -0
- package/dist/ui/displayCommit.js +376 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/heightIndex.d.ts +35 -0
- package/dist/ui/heightIndex.js +295 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +6 -0
- package/dist/ui/layout.d.ts +9 -0
- package/dist/ui/layout.js +349 -0
- package/dist/ui/managedState.d.ts +12 -0
- package/dist/ui/managedState.js +44 -0
- package/dist/ui/textEditState.d.ts +4 -0
- package/dist/ui/textEditState.js +206 -0
- package/dist/ui/textEditTypes.d.ts +48 -0
- package/dist/ui/textEditTypes.js +2 -0
- package/dist/ui/types.d.ts +99 -0
- package/dist/ui/types.js +2 -0
- package/package.json +44 -4
package/dist/Mesh2D.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { isTexturedGeometry2D, isSharedGeometry2D } from "@egret/contracts";
|
|
2
|
+
import { isAssetLease, readAssetLeaseValue } from "./AssetLease.js";
|
|
3
|
+
import { DisplayObject } from "./DisplayObject.js";
|
|
4
|
+
import { assertLive, isTerminated, terminateNode } from "./displayTreeState.js";
|
|
5
|
+
import { EgretError } from "./EgretError.js";
|
|
6
|
+
import { readMeshState, writeMeshState } from "./meshDisplayState.js";
|
|
7
|
+
import { claimOwner, commitBinding, engineOf } from "./ownership.js";
|
|
8
|
+
import { isTexture, readTextureSnapshot } from "./Texture.js";
|
|
9
|
+
const mutations = new WeakSet();
|
|
10
|
+
const identities = new WeakSet();
|
|
11
|
+
const hasIdentity = identities.has.bind(identities);
|
|
12
|
+
const registerIdentity = identities.add.bind(identities);
|
|
13
|
+
/** Class identity survives clear/dispose; another textured leaf gains no Mesh methods. */
|
|
14
|
+
function assertMesh(value) {
|
|
15
|
+
if (!hasIdentity(value))
|
|
16
|
+
throw new EgretError("MESH_INVALID");
|
|
17
|
+
}
|
|
18
|
+
function contentState(lease, geometry, sourceRect, viewRegion) {
|
|
19
|
+
return Object.freeze({ lease, geometry, sourceRect, viewRegion, regionOnly: false });
|
|
20
|
+
}
|
|
21
|
+
/** Entitlement and live Texture authority never use public resource getters. */
|
|
22
|
+
function readMeshTexture(lease) {
|
|
23
|
+
const value = readAssetLeaseValue(lease);
|
|
24
|
+
if (!isTexture(value))
|
|
25
|
+
throw new EgretError("MESH_TEXTURE_INVALID");
|
|
26
|
+
return readTextureSnapshot(value);
|
|
27
|
+
}
|
|
28
|
+
/** Identity, display lifetime and Engine lifetime precede the mutation guard. */
|
|
29
|
+
function beginMutation(node) {
|
|
30
|
+
assertMesh(node);
|
|
31
|
+
assertLive(node);
|
|
32
|
+
const engine = engineOf(node);
|
|
33
|
+
engine.assertOpen();
|
|
34
|
+
if (mutations.has(node))
|
|
35
|
+
throw new EgretError("MESH_MUTATION_REENTRANT");
|
|
36
|
+
mutations.add(node);
|
|
37
|
+
return engine;
|
|
38
|
+
}
|
|
39
|
+
/** Reentry or terminal cleanup cannot resurrect a previously observed slot. */
|
|
40
|
+
function revalidateMutation(node, engine, previous) {
|
|
41
|
+
assertLive(node);
|
|
42
|
+
engine.assertOpen();
|
|
43
|
+
if (readMeshState(node) !== previous)
|
|
44
|
+
throw new EgretError("MESH_MUTATION_REENTRANT");
|
|
45
|
+
}
|
|
46
|
+
/** A display leaf borrowing an exact lease and an immutable owned geometry. */
|
|
47
|
+
export class Mesh2D extends DisplayObject {
|
|
48
|
+
/** Opaque producer binding: scene traversal exposes neither its borrowed lease nor a content writer. */
|
|
49
|
+
static createBinding(textureLease, geometry) {
|
|
50
|
+
if (!isTexturedGeometry2D(geometry) && !isSharedGeometry2D(geometry))
|
|
51
|
+
throw new EgretError("MESH_GEOMETRY_INVALID");
|
|
52
|
+
if (!isAssetLease(textureLease))
|
|
53
|
+
throw new EgretError("MESH_LEASE_INVALID");
|
|
54
|
+
const initial = readMeshTexture(textureLease), engine = engineOf(textureLease);
|
|
55
|
+
engine.assertOpen();
|
|
56
|
+
let disposed = false, cleaned = false, finishListeners = () => { };
|
|
57
|
+
const creation = {};
|
|
58
|
+
class OpaqueMesh extends DisplayObject {
|
|
59
|
+
constructor(token) {
|
|
60
|
+
if (token !== creation)
|
|
61
|
+
throw new EgretError("MESH_BINDING_FACTORY_REQUIRED");
|
|
62
|
+
super();
|
|
63
|
+
const cleanup = this.clearListeners;
|
|
64
|
+
finishListeners = () => {
|
|
65
|
+
Reflect.apply(cleanup, this, []);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
dispose() {
|
|
69
|
+
dispose();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const node = new OpaqueMesh(creation);
|
|
73
|
+
function finish() {
|
|
74
|
+
if (cleaned)
|
|
75
|
+
return;
|
|
76
|
+
cleaned = true;
|
|
77
|
+
const cleanup = finishListeners;
|
|
78
|
+
finishListeners = () => { };
|
|
79
|
+
cleanup();
|
|
80
|
+
}
|
|
81
|
+
// Retire all resources before any external cancellation-listener cleanup can reenter an owner.
|
|
82
|
+
function beginDispose() {
|
|
83
|
+
if (!disposed) {
|
|
84
|
+
disposed = true;
|
|
85
|
+
writeMeshState(node, undefined);
|
|
86
|
+
terminateNode(node);
|
|
87
|
+
}
|
|
88
|
+
return finish;
|
|
89
|
+
}
|
|
90
|
+
function dispose() {
|
|
91
|
+
beginDispose()();
|
|
92
|
+
}
|
|
93
|
+
function live() {
|
|
94
|
+
if (disposed)
|
|
95
|
+
throw new EgretError("MESH_BINDING_DISPOSED");
|
|
96
|
+
assertLive(node);
|
|
97
|
+
engine.assertOpen();
|
|
98
|
+
}
|
|
99
|
+
commitBinding([node], engine);
|
|
100
|
+
writeMeshState(node, contentState(textureLease, geometry, initial.sourceRect, initial.viewRegion));
|
|
101
|
+
const binding = Object.freeze({
|
|
102
|
+
node,
|
|
103
|
+
dispose,
|
|
104
|
+
beginDispose,
|
|
105
|
+
prepare(lease, geometry) {
|
|
106
|
+
live();
|
|
107
|
+
if (!isTexturedGeometry2D(geometry) && !isSharedGeometry2D(geometry))
|
|
108
|
+
throw new EgretError("MESH_GEOMETRY_INVALID");
|
|
109
|
+
if (!isAssetLease(lease))
|
|
110
|
+
throw new EgretError("MESH_LEASE_INVALID");
|
|
111
|
+
if (engineOf(lease) !== engine)
|
|
112
|
+
throw new EgretError("ENGINE_MISMATCH");
|
|
113
|
+
const snapshot = readMeshTexture(lease), previous = readMeshState(node);
|
|
114
|
+
const next = contentState(lease, geometry, snapshot.sourceRect, snapshot.viewRegion);
|
|
115
|
+
let settled = false;
|
|
116
|
+
return Object.freeze({
|
|
117
|
+
abort() {
|
|
118
|
+
settled = true;
|
|
119
|
+
},
|
|
120
|
+
commit() {
|
|
121
|
+
live();
|
|
122
|
+
if (settled || readMeshState(node) !== previous)
|
|
123
|
+
throw new EgretError("MESH_BINDING_STALE");
|
|
124
|
+
// These identity/entitlement reads and publication invoke no caller code.
|
|
125
|
+
readMeshTexture(lease);
|
|
126
|
+
settled = true;
|
|
127
|
+
writeMeshState(node, next);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
// A consumer Scope cannot adopt an adapter-owned child through display traversal.
|
|
133
|
+
commitBinding([binding], engine);
|
|
134
|
+
claimOwner(node, binding);
|
|
135
|
+
Object.freeze(node);
|
|
136
|
+
return binding;
|
|
137
|
+
}
|
|
138
|
+
constructor(textureLease, geometry) {
|
|
139
|
+
super();
|
|
140
|
+
// Geometry authentication outranks every lease identity or entitlement read.
|
|
141
|
+
if (!isTexturedGeometry2D(geometry) && !isSharedGeometry2D(geometry))
|
|
142
|
+
throw new EgretError("MESH_GEOMETRY_INVALID");
|
|
143
|
+
if (!isAssetLease(textureLease))
|
|
144
|
+
throw new EgretError("MESH_LEASE_INVALID");
|
|
145
|
+
const snapshot = readMeshTexture(textureLease);
|
|
146
|
+
const engine = engineOf(textureLease);
|
|
147
|
+
engine.assertOpen();
|
|
148
|
+
commitBinding([this], engine);
|
|
149
|
+
writeMeshState(this, contentState(textureLease, geometry, snapshot.sourceRect, snapshot.viewRegion));
|
|
150
|
+
registerIdentity(this);
|
|
151
|
+
}
|
|
152
|
+
/** Cached identity-only reads remain valid after clear or terminal disposal. */
|
|
153
|
+
get textureLease() {
|
|
154
|
+
assertMesh(this);
|
|
155
|
+
return readMeshState(this)?.lease;
|
|
156
|
+
}
|
|
157
|
+
get geometry() {
|
|
158
|
+
assertMesh(this);
|
|
159
|
+
return readMeshState(this)?.geometry;
|
|
160
|
+
}
|
|
161
|
+
setContent(textureLease, geometry) {
|
|
162
|
+
const engine = beginMutation(this);
|
|
163
|
+
try {
|
|
164
|
+
const previous = readMeshState(this);
|
|
165
|
+
if (!isTexturedGeometry2D(geometry) && !isSharedGeometry2D(geometry))
|
|
166
|
+
throw new EgretError("MESH_GEOMETRY_INVALID");
|
|
167
|
+
if (!isAssetLease(textureLease))
|
|
168
|
+
throw new EgretError("MESH_LEASE_INVALID");
|
|
169
|
+
// Foreign Engine affinity wins even when that lease or Texture is retired.
|
|
170
|
+
if (engineOf(textureLease) !== engine)
|
|
171
|
+
throw new EgretError("ENGINE_MISMATCH");
|
|
172
|
+
const snapshot = readMeshTexture(textureLease);
|
|
173
|
+
revalidateMutation(this, engine, previous);
|
|
174
|
+
// Publish all borrowed content together; no callbacks occur at commit.
|
|
175
|
+
writeMeshState(this, contentState(textureLease, geometry, snapshot.sourceRect, snapshot.viewRegion));
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
mutations.delete(this);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** Clearing drops only cached content; Engine affinity and caller borrows stay. */
|
|
182
|
+
clear() {
|
|
183
|
+
beginMutation(this);
|
|
184
|
+
try {
|
|
185
|
+
writeMeshState(this, undefined);
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
mutations.delete(this);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** Drop the slot before base cleanup; terminal callback reentry sees no content. */
|
|
192
|
+
dispose() {
|
|
193
|
+
assertMesh(this);
|
|
194
|
+
if (isTerminated(this))
|
|
195
|
+
return;
|
|
196
|
+
writeMeshState(this, undefined);
|
|
197
|
+
super.dispose();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=Mesh2D.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AssetLease } from "./AssetLease.js";
|
|
2
|
+
import { DisplayObject } from "./DisplayObject.js";
|
|
3
|
+
import type { NineSliceInsets2D } from "./NineSliceGeometry2D.js";
|
|
4
|
+
import type { Texture } from "./Texture.js";
|
|
5
|
+
/** Required local panel dimensions and fixed source-crop borders. */
|
|
6
|
+
export interface NineSliceBitmapOptions {
|
|
7
|
+
readonly width: number;
|
|
8
|
+
readonly height: number;
|
|
9
|
+
readonly insets: NineSliceInsets2D;
|
|
10
|
+
}
|
|
11
|
+
/** A resizable stretch-only leaf borrowing one exact, caller-owned Texture lease. */
|
|
12
|
+
export declare class NineSliceBitmap extends DisplayObject {
|
|
13
|
+
private readonly nineSliceBitmapBrand;
|
|
14
|
+
constructor(textureLease: AssetLease<Texture>, options: NineSliceBitmapOptions);
|
|
15
|
+
/** Identity-only borrow metadata conveys no live resource entitlement. */
|
|
16
|
+
get textureLease(): AssetLease<Texture> | undefined;
|
|
17
|
+
get targetWidth(): number;
|
|
18
|
+
get targetHeight(): number;
|
|
19
|
+
get insets(): NineSliceInsets2D;
|
|
20
|
+
resize(width: number, height: number): void;
|
|
21
|
+
/** Drop the borrow before base terminal cleanup; the caller still owns it. */
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=NineSliceBitmap.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { isAssetLease, readAssetLeaseValue } from "./AssetLease.js";
|
|
2
|
+
import { DisplayObject } from "./DisplayObject.js";
|
|
3
|
+
import { assertLive, isTerminated } from "./displayTreeState.js";
|
|
4
|
+
import { EgretError } from "./EgretError.js";
|
|
5
|
+
import { writeMeshState } from "./meshDisplayState.js";
|
|
6
|
+
import { createNineSliceGeometry2D } from "./NineSliceGeometry2D.js";
|
|
7
|
+
import { commitBinding, engineOf } from "./ownership.js";
|
|
8
|
+
import { isTexture, readTextureSnapshot } from "./Texture.js";
|
|
9
|
+
// Capture operations before a descriptor can replace public intrinsics or ports.
|
|
10
|
+
const isArray = Array.isArray;
|
|
11
|
+
const freeze = Object.freeze;
|
|
12
|
+
const TypeFault = TypeError;
|
|
13
|
+
const apply = Reflect.apply;
|
|
14
|
+
const originalDispose = DisplayObject.prototype.dispose;
|
|
15
|
+
const geometryFactory = createNineSliceGeometry2D;
|
|
16
|
+
const writeContent = writeMeshState;
|
|
17
|
+
const states = new WeakMap();
|
|
18
|
+
const lookup = states.get.bind(states);
|
|
19
|
+
const register = states.set.bind(states);
|
|
20
|
+
/** Class identity is separate from the shared textured-capture content slot. */
|
|
21
|
+
function stateOf(receiver) {
|
|
22
|
+
const state = lookup(receiver);
|
|
23
|
+
if (state === undefined)
|
|
24
|
+
throw new EgretError("NINE_SLICE_BITMAP_INVALID");
|
|
25
|
+
return state;
|
|
26
|
+
}
|
|
27
|
+
/** Exact lease entitlement precedes Texture brand and live-image authority. */
|
|
28
|
+
function textureOf(lease) {
|
|
29
|
+
const value = readAssetLeaseValue(lease);
|
|
30
|
+
if (!isTexture(value))
|
|
31
|
+
throw new EgretError("NINE_SLICE_BITMAP_TEXTURE_INVALID");
|
|
32
|
+
return readTextureSnapshot(value);
|
|
33
|
+
}
|
|
34
|
+
/** A successful external read observes Engine, then lease, then Texture lifetime. */
|
|
35
|
+
function checkpoint(engine, lease) {
|
|
36
|
+
engine.assertOpen();
|
|
37
|
+
return textureOf(lease);
|
|
38
|
+
}
|
|
39
|
+
function descriptor(value) {
|
|
40
|
+
if (typeof value !== "object" || value === null) {
|
|
41
|
+
throw new TypeFault("NineSliceBitmap descriptor must be a non-array object");
|
|
42
|
+
}
|
|
43
|
+
let array;
|
|
44
|
+
try {
|
|
45
|
+
array = isArray(value);
|
|
46
|
+
}
|
|
47
|
+
catch (cause) {
|
|
48
|
+
throw new TypeFault("NineSliceBitmap descriptor admission failed", { cause });
|
|
49
|
+
}
|
|
50
|
+
if (array)
|
|
51
|
+
throw new TypeFault("NineSliceBitmap descriptor must be a non-array object");
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
/** Throwing reads keep their original cause; only successful reads checkpoint. */
|
|
55
|
+
function read(source, key, engine, lease) {
|
|
56
|
+
let value;
|
|
57
|
+
try {
|
|
58
|
+
value = source[key];
|
|
59
|
+
}
|
|
60
|
+
catch (cause) {
|
|
61
|
+
throw new TypeFault("NineSliceBitmap descriptor read failed", { cause });
|
|
62
|
+
}
|
|
63
|
+
checkpoint(engine, lease);
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function primitiveNumber(value) {
|
|
67
|
+
if (typeof value !== "number")
|
|
68
|
+
throw new TypeFault("NineSliceBitmap dimensions and borders must be primitive numbers");
|
|
69
|
+
return value === 0 ? 0 : value;
|
|
70
|
+
}
|
|
71
|
+
function geometry(sourceRect, viewRegion, width, height, insets) {
|
|
72
|
+
// The existing NS1 factory owns all range, precision and grid admission.
|
|
73
|
+
return geometryFactory({
|
|
74
|
+
sourceWidth: viewRegion?.logicalWidth ?? sourceRect.width,
|
|
75
|
+
sourceHeight: viewRegion?.logicalHeight ?? sourceRect.height,
|
|
76
|
+
targetWidth: width,
|
|
77
|
+
targetHeight: height,
|
|
78
|
+
insets
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function content(lease, owned, sourceRect, viewRegion) {
|
|
82
|
+
return freeze({ lease, geometry: owned, sourceRect, viewRegion, regionOnly: true });
|
|
83
|
+
}
|
|
84
|
+
/** A resizable stretch-only leaf borrowing one exact, caller-owned Texture lease. */
|
|
85
|
+
export class NineSliceBitmap extends DisplayObject {
|
|
86
|
+
constructor(textureLease, options) {
|
|
87
|
+
super();
|
|
88
|
+
if (!isAssetLease(textureLease))
|
|
89
|
+
throw new EgretError("NINE_SLICE_BITMAP_LEASE_INVALID");
|
|
90
|
+
const initial = textureOf(textureLease);
|
|
91
|
+
const engine = engineOf(textureLease);
|
|
92
|
+
engine.assertOpen();
|
|
93
|
+
const outer = descriptor(options);
|
|
94
|
+
const widthInput = read(outer, "width", engine, textureLease);
|
|
95
|
+
const heightInput = read(outer, "height", engine, textureLease);
|
|
96
|
+
// The successful insets read checkpoints before admitting that object.
|
|
97
|
+
const inset = descriptor(read(outer, "insets", engine, textureLease));
|
|
98
|
+
const leftInput = read(inset, "left", engine, textureLease);
|
|
99
|
+
const topInput = read(inset, "top", engine, textureLease);
|
|
100
|
+
const rightInput = read(inset, "right", engine, textureLease);
|
|
101
|
+
const bottomInput = read(inset, "bottom", engine, textureLease);
|
|
102
|
+
// Finish every primitive check before NS1 performs any numeric range check.
|
|
103
|
+
const width = primitiveNumber(widthInput), height = primitiveNumber(heightInput);
|
|
104
|
+
const left = primitiveNumber(leftInput), top = primitiveNumber(topInput);
|
|
105
|
+
const right = primitiveNumber(rightInput), bottom = primitiveNumber(bottomInput);
|
|
106
|
+
const insets = { left, top, right, bottom };
|
|
107
|
+
const owned = geometry(initial.sourceRect, initial.viewRegion, width, height, insets);
|
|
108
|
+
const fixedInsets = freeze(insets);
|
|
109
|
+
const size = freeze({ width, height });
|
|
110
|
+
const slot = content(textureLease, owned, initial.sourceRect, initial.viewRegion);
|
|
111
|
+
const state = {
|
|
112
|
+
sourceRect: initial.sourceRect,
|
|
113
|
+
viewRegion: initial.viewRegion,
|
|
114
|
+
insets: fixedInsets,
|
|
115
|
+
lease: textureLease,
|
|
116
|
+
size
|
|
117
|
+
};
|
|
118
|
+
checkpoint(engine, textureLease);
|
|
119
|
+
// All allocations/admission precede the callback-free affinity/content commit.
|
|
120
|
+
commitBinding([this], engine);
|
|
121
|
+
writeContent(this, slot);
|
|
122
|
+
register(this, state);
|
|
123
|
+
}
|
|
124
|
+
/** Identity-only borrow metadata conveys no live resource entitlement. */
|
|
125
|
+
get textureLease() {
|
|
126
|
+
return stateOf(this).lease;
|
|
127
|
+
}
|
|
128
|
+
get targetWidth() {
|
|
129
|
+
return stateOf(this).size.width;
|
|
130
|
+
}
|
|
131
|
+
get targetHeight() {
|
|
132
|
+
return stateOf(this).size.height;
|
|
133
|
+
}
|
|
134
|
+
get insets() {
|
|
135
|
+
return stateOf(this).insets;
|
|
136
|
+
}
|
|
137
|
+
resize(width, height) {
|
|
138
|
+
const state = stateOf(this);
|
|
139
|
+
assertLive(this);
|
|
140
|
+
const engine = engineOf(this);
|
|
141
|
+
engine.assertOpen();
|
|
142
|
+
const lease = state.lease;
|
|
143
|
+
textureOf(lease);
|
|
144
|
+
const targetWidth = primitiveNumber(width), targetHeight = primitiveNumber(height);
|
|
145
|
+
const owned = geometry(state.sourceRect, state.viewRegion, targetWidth, targetHeight, state.insets);
|
|
146
|
+
const size = freeze({ width: targetWidth, height: targetHeight });
|
|
147
|
+
const slot = content(lease, owned, state.sourceRect, state.viewRegion);
|
|
148
|
+
assertLive(this);
|
|
149
|
+
checkpoint(engine, lease);
|
|
150
|
+
// Publish only prepared immutable values, without events or public setters.
|
|
151
|
+
writeContent(this, slot);
|
|
152
|
+
state.size = size;
|
|
153
|
+
}
|
|
154
|
+
/** Drop the borrow before base terminal cleanup; the caller still owns it. */
|
|
155
|
+
dispose() {
|
|
156
|
+
const state = stateOf(this);
|
|
157
|
+
writeContent(this, undefined);
|
|
158
|
+
state.lease = undefined;
|
|
159
|
+
if (isTerminated(this))
|
|
160
|
+
return;
|
|
161
|
+
apply(originalDispose, this, []);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=NineSliceBitmap.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TexturedGeometry2D } from "@egret/contracts";
|
|
2
|
+
/** Border widths in the same units as the unrotated source crop. */
|
|
3
|
+
export interface NineSliceInsets2D {
|
|
4
|
+
readonly left: number;
|
|
5
|
+
readonly top: number;
|
|
6
|
+
readonly right: number;
|
|
7
|
+
readonly bottom: number;
|
|
8
|
+
}
|
|
9
|
+
export interface NineSliceGeometry2DOptions {
|
|
10
|
+
readonly sourceWidth: number;
|
|
11
|
+
readonly sourceHeight: number;
|
|
12
|
+
readonly targetWidth: number;
|
|
13
|
+
readonly targetHeight: number;
|
|
14
|
+
readonly insets: NineSliceInsets2D;
|
|
15
|
+
}
|
|
16
|
+
/** Create an owned immutable stretch grid for an existing Mesh2D texture lease. */
|
|
17
|
+
export declare function createNineSliceGeometry2D(options: NineSliceGeometry2DOptions): TexturedGeometry2D;
|
|
18
|
+
//# sourceMappingURL=NineSliceGeometry2D.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createTexturedGeometry2D } from "@egret/contracts";
|
|
2
|
+
// Capture admission, error and payload intrinsics before descriptor callbacks.
|
|
3
|
+
// The factory owns geometry only; the caller supplies crop/texture agreement.
|
|
4
|
+
const isArray = Array.isArray;
|
|
5
|
+
const finite = Number.isFinite;
|
|
6
|
+
const TypeFault = TypeError;
|
|
7
|
+
const RangeFault = RangeError;
|
|
8
|
+
const Floats = Float64Array;
|
|
9
|
+
const Indices = Uint16Array;
|
|
10
|
+
function object(value) {
|
|
11
|
+
if (typeof value !== "object" || value === null || isArray(value)) {
|
|
12
|
+
throw new TypeFault("Nine-slice descriptor must be a non-array object");
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function read(source, key) {
|
|
17
|
+
try {
|
|
18
|
+
return source[key];
|
|
19
|
+
}
|
|
20
|
+
catch (cause) {
|
|
21
|
+
throw new TypeFault("Nine-slice descriptor read failed", { cause });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function number(value) {
|
|
25
|
+
if (typeof value !== "number")
|
|
26
|
+
throw new TypeFault("Nine-slice values must be primitive numbers");
|
|
27
|
+
return value === 0 ? 0 : value;
|
|
28
|
+
}
|
|
29
|
+
function range(value, dimension) {
|
|
30
|
+
if (!finite(value) || (dimension ? value <= 0 : value < 0)) {
|
|
31
|
+
throw new RangeFault("Nine-slice numeric range is invalid");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function axis(source, target, leading, trailing) {
|
|
35
|
+
const borders = leading + trailing;
|
|
36
|
+
if (!finite(borders) || borders >= source || borders > target) {
|
|
37
|
+
throw new RangeFault("Nine-slice borders must leave a source center and fit the target");
|
|
38
|
+
}
|
|
39
|
+
// Equality with the computed border sum intentionally removes the center.
|
|
40
|
+
// Subtracting the trailing edge in that case can create a phantom interval.
|
|
41
|
+
const far = target === borders ? leading : target - trailing;
|
|
42
|
+
const nearUv = leading / source;
|
|
43
|
+
const farUv = (source - trailing) / source;
|
|
44
|
+
// Computed Float64 cuts are authoritative. Positive intervals must survive;
|
|
45
|
+
// GPU Float32 conversion and raster capacity remain renderer obligations.
|
|
46
|
+
if (!finite(far) ||
|
|
47
|
+
!finite(nearUv) ||
|
|
48
|
+
!finite(farUv) ||
|
|
49
|
+
far < leading ||
|
|
50
|
+
far > target ||
|
|
51
|
+
nearUv < 0 ||
|
|
52
|
+
farUv > 1 ||
|
|
53
|
+
nearUv >= farUv ||
|
|
54
|
+
(trailing > 0 && (far === target || farUv === 1)) ||
|
|
55
|
+
(leading > 0 && nearUv === 0) ||
|
|
56
|
+
(target > borders && far === leading)) {
|
|
57
|
+
throw new RangeFault("Nine-slice precision collapsed a positive interval");
|
|
58
|
+
}
|
|
59
|
+
return { cuts: [0, leading, far, target], uvs: [0, nearUv, farUv, 1] };
|
|
60
|
+
}
|
|
61
|
+
/** Create an owned immutable stretch grid for an existing Mesh2D texture lease. */
|
|
62
|
+
export function createNineSliceGeometry2D(options) {
|
|
63
|
+
const descriptor = object(options);
|
|
64
|
+
// Successful outer reads precede inset admission and its ordered reads.
|
|
65
|
+
// Local staging isolates descriptor reentry without retaining caller data.
|
|
66
|
+
const sourceWidthInput = read(descriptor, "sourceWidth");
|
|
67
|
+
const sourceHeightInput = read(descriptor, "sourceHeight");
|
|
68
|
+
const targetWidthInput = read(descriptor, "targetWidth");
|
|
69
|
+
const targetHeightInput = read(descriptor, "targetHeight");
|
|
70
|
+
const insetDescriptor = object(read(descriptor, "insets"));
|
|
71
|
+
const leftInput = read(insetDescriptor, "left");
|
|
72
|
+
const topInput = read(insetDescriptor, "top");
|
|
73
|
+
const rightInput = read(insetDescriptor, "right");
|
|
74
|
+
const bottomInput = read(insetDescriptor, "bottom");
|
|
75
|
+
// Complete all eight primitive checks before examining any numeric range.
|
|
76
|
+
const sourceWidth = number(sourceWidthInput);
|
|
77
|
+
const sourceHeight = number(sourceHeightInput);
|
|
78
|
+
const targetWidth = number(targetWidthInput);
|
|
79
|
+
const targetHeight = number(targetHeightInput);
|
|
80
|
+
const left = number(leftInput);
|
|
81
|
+
const top = number(topInput);
|
|
82
|
+
const right = number(rightInput);
|
|
83
|
+
const bottom = number(bottomInput);
|
|
84
|
+
range(sourceWidth, true);
|
|
85
|
+
range(sourceHeight, true);
|
|
86
|
+
range(targetWidth, true);
|
|
87
|
+
range(targetHeight, true);
|
|
88
|
+
range(left, false);
|
|
89
|
+
range(top, false);
|
|
90
|
+
range(right, false);
|
|
91
|
+
range(bottom, false);
|
|
92
|
+
const x = axis(sourceWidth, targetWidth, left, right);
|
|
93
|
+
const y = axis(sourceHeight, targetHeight, top, bottom);
|
|
94
|
+
// Allocation begins after scalar and precision admission. Native allocation
|
|
95
|
+
// faults escape unchanged; no asset or display-tree mutation has occurred.
|
|
96
|
+
const positions = new Floats(32);
|
|
97
|
+
const uvs = new Floats(32);
|
|
98
|
+
const lightColors = new Floats(64);
|
|
99
|
+
const indices = new Indices(54);
|
|
100
|
+
for (let row = 0; row < 4; row++) {
|
|
101
|
+
for (let column = 0; column < 4; column++) {
|
|
102
|
+
const vertex = 4 * row + column;
|
|
103
|
+
positions[2 * vertex] = x.cuts[column];
|
|
104
|
+
positions[2 * vertex + 1] = y.cuts[row];
|
|
105
|
+
uvs[2 * vertex] = x.uvs[column];
|
|
106
|
+
uvs[2 * vertex + 1] = y.uvs[row];
|
|
107
|
+
for (let component = 0; component < 4; component++)
|
|
108
|
+
lightColors[4 * vertex + component] = 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (let row = 0; row < 3; row++) {
|
|
112
|
+
for (let column = 0; column < 3; column++) {
|
|
113
|
+
const vertex = 4 * row + column, index = 6 * (3 * row + column);
|
|
114
|
+
indices[index] = vertex;
|
|
115
|
+
indices[index + 1] = vertex + 1;
|
|
116
|
+
indices[index + 2] = vertex + 4;
|
|
117
|
+
indices[index + 3] = vertex + 1;
|
|
118
|
+
indices[index + 4] = vertex + 5;
|
|
119
|
+
indices[index + 5] = vertex + 4;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// The original contracts factory owns the authentic frozen number arrays.
|
|
123
|
+
// Intentional zero-width cells retain the canonical 16/54 grid topology.
|
|
124
|
+
return createTexturedGeometry2D({ positions, uvs, lightColors, indices });
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=NineSliceGeometry2D.js.map
|
package/dist/Scope.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CancellationSignal, ScopeValue } from "@egret/contracts";
|
|
2
|
+
import type { EngineContext } from "./ownership.js";
|
|
3
|
+
export type ScopeState = "open" | "closing" | "closed";
|
|
4
|
+
export declare let createScope: (engine: EngineContext, onClosed: (scope: Scope) => void) => Scope;
|
|
5
|
+
/** Runtime-private identity for owner-chain lifetime validation. */
|
|
6
|
+
export declare function isScope(value: object): value is Scope;
|
|
7
|
+
/** Synchronous ownership boundary. Use Engine.createScope() to obtain one. */
|
|
8
|
+
export declare class Scope {
|
|
9
|
+
#private;
|
|
10
|
+
readonly signal: CancellationSignal;
|
|
11
|
+
private constructor();
|
|
12
|
+
get state(): ScopeState;
|
|
13
|
+
/** Accept one cleanup owner after callback-free validation of the current tree. */
|
|
14
|
+
use<T extends ScopeValue>(value: T): T;
|
|
15
|
+
/** Cancel first, then clean up in reverse acquisition order despite failures. */
|
|
16
|
+
dispose(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Scope.d.ts.map
|
package/dist/Scope.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { cleanupManagedWrapper } from "./ui/managedState.js";
|
|
2
|
+
import { CancellationController } from "./CancellationController.js";
|
|
3
|
+
import { EgretError } from "./EgretError.js";
|
|
4
|
+
import { claimOwner, commitBinding, engineOf, ownerOf, preflightBinding, validateBinding } from "./ownership.js";
|
|
5
|
+
export let createScope;
|
|
6
|
+
const CREATION_TOKEN = Symbol("egret.scopeFactory");
|
|
7
|
+
const scopes = new WeakSet();
|
|
8
|
+
/** Runtime-private identity for owner-chain lifetime validation. */
|
|
9
|
+
export function isScope(value) {
|
|
10
|
+
return scopes.has(value);
|
|
11
|
+
}
|
|
12
|
+
const activeRegistrations = new WeakSet();
|
|
13
|
+
function cleanup(value) {
|
|
14
|
+
if (cleanupManagedWrapper(value))
|
|
15
|
+
return;
|
|
16
|
+
if ("dispose" in value)
|
|
17
|
+
value.dispose();
|
|
18
|
+
else
|
|
19
|
+
value.release();
|
|
20
|
+
}
|
|
21
|
+
/** Synchronous ownership boundary. Use Engine.createScope() to obtain one. */
|
|
22
|
+
export class Scope {
|
|
23
|
+
#currentState = "open";
|
|
24
|
+
// Runtime-private ownership paths ignore harmless public old-name shadows.
|
|
25
|
+
#values = [];
|
|
26
|
+
#controller;
|
|
27
|
+
#engine;
|
|
28
|
+
#onClosed;
|
|
29
|
+
signal;
|
|
30
|
+
constructor(engine, onClosed, token) {
|
|
31
|
+
if (token !== CREATION_TOKEN)
|
|
32
|
+
throw new EgretError("SCOPE_FACTORY_REQUIRED");
|
|
33
|
+
scopes.add(this);
|
|
34
|
+
this.#engine = engine;
|
|
35
|
+
this.#onClosed = onClosed;
|
|
36
|
+
this.#controller = new CancellationController(diagnostic => {
|
|
37
|
+
this.#engine.captureCleanup(diagnostic.cause);
|
|
38
|
+
this.#engine.report(diagnostic);
|
|
39
|
+
});
|
|
40
|
+
this.signal = this.#controller.signal;
|
|
41
|
+
}
|
|
42
|
+
static {
|
|
43
|
+
createScope = (engine, onClosed) => new Scope(engine, onClosed, CREATION_TOKEN);
|
|
44
|
+
}
|
|
45
|
+
get state() {
|
|
46
|
+
return this.#currentState;
|
|
47
|
+
}
|
|
48
|
+
/** Accept one cleanup owner after callback-free validation of the current tree. */
|
|
49
|
+
use(value) {
|
|
50
|
+
if (activeRegistrations.has(value))
|
|
51
|
+
throw new EgretError("SCOPE_REGISTRATION_ACTIVE");
|
|
52
|
+
activeRegistrations.add(value);
|
|
53
|
+
try {
|
|
54
|
+
const existingOwner = this.#validateAcceptance(value);
|
|
55
|
+
if (existingOwner === this)
|
|
56
|
+
return value;
|
|
57
|
+
preflightBinding(value, this.#engine);
|
|
58
|
+
// Subclass preflight may close a Scope/Engine or mutate the tree. Nothing
|
|
59
|
+
// can invoke user code between the checks below and the ownership commit.
|
|
60
|
+
this.#validateAcceptance(value);
|
|
61
|
+
const binding = validateBinding(value, this.#engine);
|
|
62
|
+
commitBinding(binding, this.#engine);
|
|
63
|
+
claimOwner(value, this);
|
|
64
|
+
this.#values.push(value);
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
activeRegistrations.delete(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
#validateAcceptance(value) {
|
|
72
|
+
const existingOwner = ownerOf(value);
|
|
73
|
+
if (existingOwner !== undefined && existingOwner !== this)
|
|
74
|
+
throw new EgretError("OWNERSHIP_CONFLICT");
|
|
75
|
+
const existingEngine = engineOf(value);
|
|
76
|
+
if (existingEngine !== undefined && existingEngine !== this.#engine)
|
|
77
|
+
throw new EgretError("ENGINE_MISMATCH");
|
|
78
|
+
let closedError;
|
|
79
|
+
if (this.#currentState !== "open")
|
|
80
|
+
closedError = new EgretError("SCOPE_CLOSED");
|
|
81
|
+
else {
|
|
82
|
+
try {
|
|
83
|
+
this.#engine.assertOpen();
|
|
84
|
+
}
|
|
85
|
+
catch (cause) {
|
|
86
|
+
closedError = cause instanceof EgretError ? cause : new EgretError("ENGINE_CLOSED", { cause });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (closedError !== undefined) {
|
|
90
|
+
const cleanupErrors = [];
|
|
91
|
+
// A late unowned value must be cleaned up; a foreign owner stays authoritative.
|
|
92
|
+
if (existingOwner === undefined) {
|
|
93
|
+
try {
|
|
94
|
+
cleanup(value);
|
|
95
|
+
}
|
|
96
|
+
catch (cause) {
|
|
97
|
+
cleanupErrors.push(cause);
|
|
98
|
+
this.#engine.captureCleanup(cause);
|
|
99
|
+
this.#engine.report({ code: "SCOPE_LATE_CLEANUP_FAILED", phase: "scope", severity: "error", cause });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw new EgretError(closedError.code, { cause: closedError.cause, cleanupErrors });
|
|
103
|
+
}
|
|
104
|
+
return existingOwner;
|
|
105
|
+
}
|
|
106
|
+
/** Cancel first, then clean up in reverse acquisition order despite failures. */
|
|
107
|
+
dispose() {
|
|
108
|
+
if (this.#currentState !== "open")
|
|
109
|
+
return;
|
|
110
|
+
this.#currentState = "closing";
|
|
111
|
+
try {
|
|
112
|
+
this.#controller.abort(new EgretError("SCOPE_CLOSED"));
|
|
113
|
+
for (let index = this.#values.length - 1; index >= 0; index--) {
|
|
114
|
+
const value = this.#values[index];
|
|
115
|
+
if (value === undefined)
|
|
116
|
+
continue;
|
|
117
|
+
try {
|
|
118
|
+
cleanup(value);
|
|
119
|
+
}
|
|
120
|
+
catch (cause) {
|
|
121
|
+
this.#engine.captureCleanup(cause);
|
|
122
|
+
this.#engine.report({ code: "SCOPE_CLEANUP_FAILED", phase: "scope", severity: "error", cause });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
this.#values.length = 0;
|
|
128
|
+
this.#currentState = "closed";
|
|
129
|
+
this.#onClosed(this);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=Scope.js.map
|