@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,451 @@
1
+ import { AssetLease, createAssetLease, isAssetLease, readAssetLeaseValue, revokeAssetLease } from "./AssetLease.js";
2
+ import { assertAssetRef, assertAssetType } from "./AssetRef.js";
3
+ import { CancellationController } from "./CancellationController.js";
4
+ import { EgretError } from "./EgretError.js";
5
+ import { closeOwnedTextCache, markAssetManagerOwnerClosed, registerAssetManagerOwner } from "./assetManagerOwnerState.js";
6
+ import { claimOwner, engineOf, ownerOf } from "./ownership.js";
7
+ const CREATION_TOKEN = Symbol("egret.assetManagerFactory");
8
+ const APPLY = Reflect.apply;
9
+ const FREEZE = Object.freeze;
10
+ let bindAssetManagerOwner;
11
+ export let createAssetManager;
12
+ function nextIdentity(value) {
13
+ const next = value + 1;
14
+ if (!Number.isSafeInteger(next))
15
+ throw new EgretError("ASSET_ID_EXHAUSTED");
16
+ return next;
17
+ }
18
+ /** CPU acquisition only: demand retains values; completed unused values are evicted. */
19
+ export class AssetManager {
20
+ closed = false;
21
+ taskId = 0;
22
+ leaseId = 0;
23
+ #engine;
24
+ providers = new Map();
25
+ identities = new Map();
26
+ current = new Map();
27
+ entries = new Set();
28
+ constructor(engine, token) {
29
+ if (token !== CREATION_TOKEN)
30
+ throw new EgretError("ASSET_MANAGER_FACTORY_REQUIRED");
31
+ this.#engine = engine;
32
+ bindAssetManagerOwner(this, engine);
33
+ }
34
+ static {
35
+ // Capture original operations before any manager or later explicit entry is exposed.
36
+ const assertOpen = this.prototype.assertOpen;
37
+ const register = this.prototype.register;
38
+ const acquire = this.prototype.acquire;
39
+ const invalidate = this.prototype.invalidate;
40
+ const admitGroupRefs = this.prototype.admitGroupRefs;
41
+ const claimGroupLease = this.prototype.claimGroupLease;
42
+ const releaseGroupLease = AssetLease.prototype.release;
43
+ bindAssetManagerOwner = (manager, context) => {
44
+ registerAssetManagerOwner(manager, FREEZE({
45
+ context,
46
+ assertOpen: () => {
47
+ APPLY(assertOpen, manager, []);
48
+ },
49
+ register: (type, provider) => {
50
+ APPLY(register, manager, [type, provider]);
51
+ },
52
+ acquire: (ref, options) => APPLY(acquire, manager, [ref, options]),
53
+ invalidate: (ref) => {
54
+ APPLY(invalidate, manager, [ref]);
55
+ }
56
+ }));
57
+ // Genuine construction alone supplies the captured, frozen narrow bridge.
58
+ // Text-cache owner state and contexts without this callback are unchanged.
59
+ const registerGroupOperations = context.registerAssetGroupOperations;
60
+ if (registerGroupOperations !== undefined) {
61
+ const operations = FREEZE({
62
+ admitGroupRefs: (refs) => {
63
+ APPLY(admitGroupRefs, manager, [refs]);
64
+ },
65
+ acquire: (ref, options) => APPLY(acquire, manager, [ref, options]),
66
+ claimGroupLease: (lease, group) => {
67
+ APPLY(claimGroupLease, manager, [lease, group]);
68
+ },
69
+ releaseGroupLease: (lease) => {
70
+ APPLY(releaseGroupLease, lease, []);
71
+ }
72
+ });
73
+ APPLY(registerGroupOperations, context, [operations]);
74
+ }
75
+ };
76
+ createAssetManager = (engine) => new AssetManager(engine, CREATION_TOKEN);
77
+ }
78
+ assertOpen() {
79
+ if (this.closed)
80
+ throw new EgretError("ASSET_MANAGER_CLOSED");
81
+ try {
82
+ this.#engine.assertOpen();
83
+ }
84
+ catch (cause) {
85
+ throw new EgretError("ASSET_MANAGER_CLOSED", { cause });
86
+ }
87
+ }
88
+ /** Snapshot method identity and receiver once, including getter reentry checks. */
89
+ register(type, provider) {
90
+ this.assertOpen();
91
+ assertAssetType(type);
92
+ if (this.providers.has(type))
93
+ throw new EgretError("ASSET_PROVIDER_REGISTERED");
94
+ const load = provider?.load;
95
+ const dispose = provider?.dispose;
96
+ if (typeof load !== "function" || typeof dispose !== "function")
97
+ throw new EgretError("ASSET_PROVIDER_INVALID");
98
+ this.assertOpen();
99
+ if (this.providers.has(type))
100
+ throw new EgretError("ASSET_PROVIDER_REGISTERED");
101
+ this.providers.set(type, {
102
+ // Intrinsic invocation ignores mutable own .call properties on callbacks.
103
+ load: (ref, context) => Reflect.apply(load, provider, [ref, context]),
104
+ dispose: value => {
105
+ Reflect.apply(dispose, provider, [value]);
106
+ }
107
+ });
108
+ }
109
+ /** The executor commits an entry and its first waiter before any loader callback. */
110
+ acquire(ref, options = {}) {
111
+ return new Promise((resolve, reject) => {
112
+ try {
113
+ this.assertOpen();
114
+ assertAssetRef(ref);
115
+ const provider = this.providers.get(ref.type);
116
+ if (provider === undefined)
117
+ throw new EgretError("ASSET_PROVIDER_MISSING");
118
+ let signal;
119
+ let alreadyAborted = false;
120
+ let cancellationReason;
121
+ try {
122
+ signal = options.signal;
123
+ alreadyAborted = signal?.aborted ?? false;
124
+ if (alreadyAborted)
125
+ cancellationReason = signal?.reason;
126
+ }
127
+ catch (cause) {
128
+ this.diagnose("ASSET_SIGNAL_FAILED", cause);
129
+ throw new EgretError("ASSET_SIGNAL_FAILED", { cause });
130
+ }
131
+ if (alreadyAborted)
132
+ throw new EgretError("ASSET_ACQUIRE_CANCELLED", { cause: cancellationReason });
133
+ this.assertOpen();
134
+ const identity = this.identityFor(ref);
135
+ let entry = this.current.get(ref.id);
136
+ if (entry === undefined) {
137
+ const generation = nextIdentity(identity.generation);
138
+ const taskId = nextIdentity(this.taskId);
139
+ identity.generation = generation;
140
+ this.taskId = taskId;
141
+ entry = {
142
+ ref,
143
+ provider,
144
+ generation,
145
+ taskId,
146
+ controller: new CancellationController(diagnostic => this.diagnose(diagnostic.code, diagnostic.cause)),
147
+ waiters: new Set(),
148
+ leases: new Set(),
149
+ state: "loading",
150
+ started: false,
151
+ hasValue: false,
152
+ cleanupAttempted: false,
153
+ value: undefined
154
+ };
155
+ this.current.set(ref.id, entry);
156
+ this.entries.add(entry);
157
+ }
158
+ const waiter = {
159
+ entry,
160
+ signal,
161
+ pending: true,
162
+ installing: false,
163
+ listening: false,
164
+ resolve: lease => resolve(lease),
165
+ reject,
166
+ listener: () => {
167
+ if (!waiter.pending)
168
+ return;
169
+ let reason;
170
+ try {
171
+ reason = signal?.reason;
172
+ }
173
+ catch (cause) {
174
+ this.failWaiter(waiter, new EgretError("ASSET_SIGNAL_FAILED", { cause }));
175
+ this.diagnose("ASSET_SIGNAL_FAILED", cause);
176
+ return;
177
+ }
178
+ this.failWaiter(waiter, new EgretError("ASSET_ACQUIRE_CANCELLED", { cause: reason }));
179
+ }
180
+ };
181
+ entry.waiters.add(waiter);
182
+ this.installSignal(waiter);
183
+ if (!waiter.pending)
184
+ return;
185
+ if (entry.state === "ready")
186
+ this.deliver(waiter);
187
+ else if (entry.state === "loading" && !entry.started)
188
+ this.start(entry);
189
+ }
190
+ catch (cause) {
191
+ reject(cause instanceof EgretError ? cause : new EgretError("ASSET_ACQUIRE_FAILED", { cause }));
192
+ }
193
+ });
194
+ }
195
+ identityFor(ref) {
196
+ let identity = this.identities.get(ref.id);
197
+ if (identity !== undefined && identity.type !== ref.type)
198
+ throw new EgretError("ASSET_TYPE_MISMATCH");
199
+ if (identity === undefined) {
200
+ identity = { type: ref.type, generation: 0 };
201
+ this.identities.set(ref.id, identity);
202
+ }
203
+ return identity;
204
+ }
205
+ /** Authenticate all positions without reserving identity or creating demand. */
206
+ admitGroupRefs(refs) {
207
+ this.assertOpen();
208
+ const admitted = new Map();
209
+ for (const ref of refs) {
210
+ assertAssetRef(ref);
211
+ if (!this.providers.has(ref.type))
212
+ throw new EgretError("ASSET_PROVIDER_MISSING");
213
+ const existing = this.identities.get(ref.id);
214
+ const inputType = admitted.get(ref.id);
215
+ if ((existing !== undefined && existing.type !== ref.type) || (inputType !== undefined && inputType !== ref.type))
216
+ throw new EgretError("ASSET_TYPE_MISMATCH");
217
+ admitted.set(ref.id, ref.type);
218
+ }
219
+ }
220
+ /** Lease identity, affinity and one cleanup owner are checked before publication. */
221
+ claimGroupLease(lease, group) {
222
+ this.assertOpen();
223
+ if (!isAssetLease(lease) || engineOf(lease) !== this.#engine || ownerOf(lease) !== undefined)
224
+ throw new EgretError("ASSET_GROUP_MEMBER_INVALID");
225
+ try {
226
+ readAssetLeaseValue(lease);
227
+ }
228
+ catch (cause) {
229
+ throw new EgretError("ASSET_GROUP_MEMBER_INVALID", { cause });
230
+ }
231
+ claimOwner(lease, group);
232
+ }
233
+ /** Invalidation changes future routing, while old demand keeps its own entry. */
234
+ invalidate(ref) {
235
+ this.assertOpen();
236
+ assertAssetRef(ref);
237
+ this.identityFor(ref);
238
+ this.current.delete(ref.id);
239
+ }
240
+ installSignal(waiter) {
241
+ if (waiter.signal === undefined)
242
+ return;
243
+ waiter.installing = true;
244
+ waiter.listening = true;
245
+ let failure;
246
+ let failed = false;
247
+ try {
248
+ waiter.signal.addEventListener("abort", waiter.listener, { once: true });
249
+ // Adapters may abort without dispatching, or close the manager during add.
250
+ if (waiter.pending && waiter.signal.aborted)
251
+ waiter.listener();
252
+ }
253
+ catch (cause) {
254
+ failure = cause;
255
+ failed = true;
256
+ this.failWaiter(waiter, new EgretError("ASSET_SIGNAL_FAILED", { cause }));
257
+ }
258
+ finally {
259
+ waiter.installing = false;
260
+ }
261
+ if (!waiter.pending) {
262
+ const removal = this.detach(waiter);
263
+ if (removal.failed)
264
+ this.diagnose("ASSET_SIGNAL_FAILED", removal.cause);
265
+ }
266
+ if (failed)
267
+ this.diagnose("ASSET_SIGNAL_FAILED", failure);
268
+ }
269
+ /** Mark local subscription inert before adapter removal; throws retain diagnostics. */
270
+ detach(waiter) {
271
+ if (waiter.installing || !waiter.listening || waiter.signal === undefined)
272
+ return { failed: false };
273
+ waiter.listening = false;
274
+ try {
275
+ waiter.signal.removeEventListener("abort", waiter.listener);
276
+ return { failed: false };
277
+ }
278
+ catch (cause) {
279
+ return { failed: true, cause };
280
+ }
281
+ }
282
+ start(entry) {
283
+ entry.started = true;
284
+ let promise;
285
+ try {
286
+ promise = entry.provider.load(entry.ref, Object.freeze({ signal: entry.controller.signal, resourceGeneration: entry.generation, taskId: entry.taskId }));
287
+ }
288
+ catch (cause) {
289
+ this.failEntry(entry, new EgretError("ASSET_LOAD_FAILED", { cause }));
290
+ return;
291
+ }
292
+ // Resolve thenables through Promise machinery; every internal rejection is observed.
293
+ void Promise.resolve(promise)
294
+ .then(value => this.receive(entry, value), cause => this.failEntry(entry, new EgretError("ASSET_LOAD_FAILED", { cause })))
295
+ .catch(cause => {
296
+ this.failEntry(entry, new EgretError("ASSET_LOAD_FAILED", { cause }));
297
+ });
298
+ }
299
+ receive(entry, value) {
300
+ entry.hasValue = true;
301
+ entry.value = value;
302
+ if (this.isTerminal(entry)) {
303
+ this.cleanup(entry);
304
+ return;
305
+ }
306
+ let valid;
307
+ try {
308
+ valid = entry.ref.type.is(value);
309
+ }
310
+ catch (cause) {
311
+ this.failEntry(entry, new EgretError("ASSET_VALUE_INVALID", { cause }));
312
+ return;
313
+ }
314
+ // Validator callbacks can cancel demand or close the manager synchronously.
315
+ if (this.isTerminal(entry)) {
316
+ this.cleanup(entry);
317
+ return;
318
+ }
319
+ if (!valid) {
320
+ this.failEntry(entry, new EgretError("ASSET_VALUE_INVALID"));
321
+ return;
322
+ }
323
+ entry.state = "ready";
324
+ for (const waiter of [...entry.waiters])
325
+ this.deliver(waiter);
326
+ this.retireUnused(entry);
327
+ }
328
+ deliver(waiter) {
329
+ const entry = waiter.entry;
330
+ if (!waiter.pending || entry.state !== "ready")
331
+ return;
332
+ let lease;
333
+ try {
334
+ this.leaseId = nextIdentity(this.leaseId);
335
+ lease = createAssetLease(this.#engine, this.leaseId, entry.generation, () => entry.value, () => {
336
+ entry.leases.delete(lease);
337
+ this.retireUnused(entry);
338
+ });
339
+ }
340
+ catch (cause) {
341
+ this.failWaiter(waiter, cause instanceof EgretError ? cause : new EgretError("ASSET_ACQUIRE_FAILED", { cause }));
342
+ return;
343
+ }
344
+ // Successful delivery wins against later abort, including removal callback reentry.
345
+ waiter.pending = false;
346
+ entry.waiters.delete(waiter);
347
+ entry.leases.add(lease);
348
+ const removal = this.detach(waiter);
349
+ if (removal.failed) {
350
+ lease.release();
351
+ waiter.reject(new EgretError("ASSET_SIGNAL_FAILED", { cause: removal.cause }));
352
+ this.diagnose("ASSET_SIGNAL_FAILED", removal.cause);
353
+ }
354
+ else
355
+ waiter.resolve(lease);
356
+ }
357
+ failWaiter(waiter, error) {
358
+ if (!waiter.pending)
359
+ return;
360
+ waiter.pending = false;
361
+ waiter.entry.waiters.delete(waiter);
362
+ this.retireUnused(waiter.entry);
363
+ const removal = this.detach(waiter);
364
+ waiter.reject(error);
365
+ if (removal.failed)
366
+ this.diagnose("ASSET_SIGNAL_FAILED", removal.cause);
367
+ }
368
+ failEntry(entry, error) {
369
+ if (entry.state === "terminal")
370
+ return;
371
+ const waiters = [...entry.waiters];
372
+ this.markTerminal(entry);
373
+ for (const waiter of waiters)
374
+ waiter.pending = false;
375
+ for (const waiter of waiters) {
376
+ const removal = this.detach(waiter);
377
+ waiter.reject(error);
378
+ if (removal.failed)
379
+ this.diagnose("ASSET_SIGNAL_FAILED", removal.cause);
380
+ }
381
+ entry.controller.abort(error);
382
+ this.cleanup(entry);
383
+ }
384
+ /** Remove only this entry: old-generation cleanup cannot delete its replacement. */
385
+ markTerminal(entry) {
386
+ entry.state = "terminal";
387
+ if (this.current.get(entry.ref.id) === entry)
388
+ this.current.delete(entry.ref.id);
389
+ this.entries.delete(entry);
390
+ entry.waiters.clear();
391
+ for (const lease of entry.leases)
392
+ revokeAssetLease(lease);
393
+ entry.leases.clear();
394
+ }
395
+ isTerminal(entry) {
396
+ return entry.state === "terminal";
397
+ }
398
+ retireUnused(entry) {
399
+ if (entry.state === "terminal" || entry.waiters.size !== 0 || entry.leases.size !== 0)
400
+ return;
401
+ this.markTerminal(entry);
402
+ entry.controller.abort(new EgretError("ASSET_NO_DEMAND"));
403
+ this.cleanup(entry);
404
+ }
405
+ /** One attempted disposal per successful result, even if the disposer throws. */
406
+ cleanup(entry) {
407
+ if (!entry.hasValue || entry.cleanupAttempted)
408
+ return;
409
+ entry.cleanupAttempted = true;
410
+ entry.hasValue = false;
411
+ const value = entry.value;
412
+ entry.value = undefined;
413
+ try {
414
+ entry.provider.dispose(value);
415
+ }
416
+ catch (cause) {
417
+ this.diagnose("ASSET_CLEANUP_FAILED", cause);
418
+ }
419
+ }
420
+ diagnose(code, cause) {
421
+ this.#engine.captureCleanup(cause);
422
+ this.#engine.report({ code, phase: "assets", severity: "error", cause });
423
+ }
424
+ /** Close the gate and revoke every local demand before the first external hook. */
425
+ dispose() {
426
+ if (this.closed)
427
+ return;
428
+ this.closed = true;
429
+ markAssetManagerOwnerClosed(this);
430
+ const entries = [...this.entries];
431
+ const waiters = entries.flatMap(entry => [...entry.waiters]);
432
+ for (const entry of entries)
433
+ this.markTerminal(entry);
434
+ for (const waiter of waiters)
435
+ waiter.pending = false;
436
+ // All manager demand is inert before the trusted cache close or external hooks.
437
+ closeOwnedTextCache(this);
438
+ const error = new EgretError("ASSET_MANAGER_CLOSED");
439
+ for (const waiter of waiters) {
440
+ const removal = this.detach(waiter);
441
+ waiter.reject(error);
442
+ if (removal.failed)
443
+ this.diagnose("ASSET_SIGNAL_FAILED", removal.cause);
444
+ }
445
+ for (const entry of entries) {
446
+ entry.controller.abort(error);
447
+ this.cleanup(entry);
448
+ }
449
+ }
450
+ }
451
+ //# sourceMappingURL=AssetManager.js.map
@@ -0,0 +1,20 @@
1
+ declare const ASSET_VALUE: unique symbol;
2
+ /** Factory identity prevents equal names from aliasing; the phantom is invariant. */
3
+ export interface AssetType<T> {
4
+ readonly name: string;
5
+ readonly is: (value: unknown) => value is T;
6
+ readonly [ASSET_VALUE]?: (value: T) => T;
7
+ }
8
+ /** A stable manager-local identity paired with its invariant value descriptor. */
9
+ export interface AssetRef<T> {
10
+ readonly type: AssetType<T>;
11
+ readonly id: string;
12
+ }
13
+ export declare function createAssetType<T>(name: string, is: (value: unknown) => value is T): AssetType<T>;
14
+ /** Keep the caller's valid ID byte-for-byte; whitespace is not normalization. */
15
+ export declare function createAssetRef<T>(type: AssetType<T>, id: string): AssetRef<T>;
16
+ export declare function assertAssetType(type: unknown): asserts type is AssetType<never>;
17
+ /** Authentication checks happen before reading any structural lookalike getter. */
18
+ export declare function assertAssetRef(ref: unknown): asserts ref is AssetRef<never>;
19
+ export {};
20
+ //# sourceMappingURL=AssetRef.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { EgretError } from "./EgretError.js";
2
+ const types = new WeakSet();
3
+ const references = new WeakSet();
4
+ function validIdentity(value) {
5
+ return typeof value === "string" && value.trim().length !== 0;
6
+ }
7
+ export function createAssetType(name, is) {
8
+ if (!validIdentity(name) || typeof is !== "function")
9
+ throw new EgretError("ASSET_TYPE_INVALID");
10
+ const type = Object.freeze({ name, is });
11
+ types.add(type);
12
+ return type;
13
+ }
14
+ /** Keep the caller's valid ID byte-for-byte; whitespace is not normalization. */
15
+ export function createAssetRef(type, id) {
16
+ assertAssetType(type);
17
+ if (!validIdentity(id))
18
+ throw new EgretError("ASSET_REF_INVALID");
19
+ const ref = Object.freeze({ type, id });
20
+ references.add(ref);
21
+ return ref;
22
+ }
23
+ export function assertAssetType(type) {
24
+ if (typeof type !== "object" || type === null || !types.has(type))
25
+ throw new EgretError("ASSET_TYPE_INVALID");
26
+ }
27
+ /** Authentication checks happen before reading any structural lookalike getter. */
28
+ export function assertAssetRef(ref) {
29
+ if (typeof ref !== "object" || ref === null || !references.has(ref))
30
+ throw new EgretError("ASSET_REF_INVALID");
31
+ }
32
+ //# sourceMappingURL=AssetRef.js.map
@@ -0,0 +1,40 @@
1
+ import type { SequenceRegion } from "./sequenceClip.js";
2
+ import type { ImageData2D, TextureRegion2D } from "@egret/contracts";
3
+ import { AssetLease } from "./AssetLease.js";
4
+ import { DisplayObject } from "./DisplayObject.js";
5
+ import type { BitmapCaptureState } from "./bitmapDisplayState.js";
6
+ export type { BitmapCaptureState } from "./bitmapDisplayState.js";
7
+ import type { Texture, TextureSnapshot2D } from "./Texture.js";
8
+ /** Internal-only original Bitmap operations; neither public root forwards this port. */
9
+ export declare let spriteSheetBitmapOperations: Readonly<{
10
+ construct(lease: AssetLease<Texture>): Bitmap;
11
+ setCrop(bitmap: Bitmap, region: TextureRegion2D): void;
12
+ dispose(bitmap: Bitmap): void;
13
+ }>;
14
+ /** A leaf borrowing one exact lease; engine affinity outlives clearing its slot. */
15
+ export declare class Bitmap extends DisplayObject {
16
+ constructor(textureLease: AssetLease<Texture>);
17
+ get textureLease(): AssetLease<Texture> | undefined;
18
+ set textureLease(value: AssetLease<Texture> | undefined);
19
+ /** Cached metadata remains readable without granting live image entitlement. */
20
+ get sourceRect(): TextureRegion2D | undefined;
21
+ set sourceRect(value: TextureRegion2D | undefined);
22
+ get naturalWidth(): number;
23
+ get naturalHeight(): number;
24
+ /** Drop the borrow before base cleanup/reentry; the caller still owns the lease. */
25
+ dispose(): void;
26
+ }
27
+ /** Brand and slot only: geometry may be validated before any lease read. */
28
+ export declare function bitmapCaptureState(node: DisplayObject): BitmapCaptureState | undefined;
29
+ /** Internal binding authority; a cleared slot remains distinguishable from retirement. */
30
+ export declare function readBitmapBinding(node: Bitmap): BitmapCaptureState | undefined;
31
+ /** Exact entitlement precedes value/live checks; public value getters are not authority. */
32
+ export declare function readBitmapImage(lease: AssetLease<Texture>): TextureSnapshot2D;
33
+ /**
34
+ * The image of a lease that `readBitmapImage` has admitted before: the same entitlement, value and live
35
+ * checks with the same refusals, and no record made. A lease stays a lease, so that one check is not repeated.
36
+ */
37
+ export declare function readBitmapSource(lease: AssetLease<Texture>): ImageData2D;
38
+ /** Private complete-frame bridge; public crop setters deliberately ignore layout. */
39
+ export declare function applyBitmapAtlasFrame(bitmap: Bitmap, region: SequenceRegion): void;
40
+ //# sourceMappingURL=Bitmap.d.ts.map