@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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { AssetLease } from './AssetLease.js';
|
|
2
|
+
import type { Texture } from './Texture.js';
|
|
3
|
+
import type { Bitmap } from './Bitmap.js';
|
|
4
|
+
import type { Stage } from './Stage.js';
|
|
5
|
+
import type { CapturedSharedContent2D } from './sharedFrameCapture.js';
|
|
6
|
+
import type { Diagnostic } from '@egret/contracts';
|
|
7
|
+
import type { CapturedInsertionNode, PreparedInsertionTree } from './displayTreeState.js';
|
|
8
|
+
import type { DisplayObjectContainer } from './DisplayObjectContainer.js';
|
|
9
|
+
import type { Scope } from './Scope.js';
|
|
10
|
+
import type { DisplayObject } from './DisplayObject.js';
|
|
11
|
+
import type { AssetGroupOperations } from './assetManagerOwnerState.js';
|
|
12
|
+
/** Internal instance port; runtime never imports the Engine implementation. */
|
|
13
|
+
export interface EngineContext {
|
|
14
|
+
/** @internal Registered once by the genuine Stage; never a caller scene callback. */
|
|
15
|
+
readonly registerPreparedDisplayOperations?: (operations: Readonly<{
|
|
16
|
+
prepare(target: DisplayObjectContainer, candidate: DisplayObject): object;
|
|
17
|
+
validate(token: object): void;
|
|
18
|
+
capture(token: object): CapturedSharedContent2D;
|
|
19
|
+
commit(token: object): void;
|
|
20
|
+
dispose(token: object): void;
|
|
21
|
+
}>) => void;
|
|
22
|
+
/** @internal Genuine Bitmap assembly; no runtime root forwards these operations. */
|
|
23
|
+
readonly registerBitmapResourceTarget?: (bitmap: Bitmap, operations: Readonly<{
|
|
24
|
+
capture(bitmap: Bitmap, expected?: object): object;
|
|
25
|
+
prepare(bitmap: Bitmap, lease: AssetLease<Texture>): object;
|
|
26
|
+
commit(bitmap: Bitmap, expected: object, prepared: object): void;
|
|
27
|
+
claim(bitmap: Bitmap, lease: AssetLease<Texture>, owner: object): void;
|
|
28
|
+
release(lease: AssetLease<Texture>): void;
|
|
29
|
+
clearIfCurrent(bitmap: Bitmap, expected: object): boolean;
|
|
30
|
+
captureBatch(targets: readonly Bitmap[]): object;
|
|
31
|
+
prepareBatch(captured: object, members: readonly AssetLease<Texture>[]): object;
|
|
32
|
+
commitBatch(captured: object, prepared: object): object;
|
|
33
|
+
capturePreparedSharedContent(stage: Stage, captured: object, prepared: object): CapturedSharedContent2D;
|
|
34
|
+
clearBatchIfCurrent(publication: object): void;
|
|
35
|
+
}>) => void;
|
|
36
|
+
assertOpen(): void;
|
|
37
|
+
report(diagnostic: Diagnostic): void;
|
|
38
|
+
captureCleanup(cause: unknown): void;
|
|
39
|
+
/** @internal Optional explicit-text assembly; ordinary runtime contexts need not supply it. */
|
|
40
|
+
readonly registerTextFieldCache?: (cache: object, construct: (scope: Scope) => DisplayObject, kind?: 'explicit-lines' | 'paragraph') => void;
|
|
41
|
+
/** @internal Optional group assembly; ordinary runtime contexts remain unchanged. */
|
|
42
|
+
readonly registerAssetGroupOperations?: (operations: AssetGroupOperations) => void;
|
|
43
|
+
}
|
|
44
|
+
export declare const OWNERSHIP_CHILDREN: unique symbol;
|
|
45
|
+
export declare const ASSERT_BINDABLE: unique symbol;
|
|
46
|
+
export declare const ASSERT_ATTACHABLE: unique symbol;
|
|
47
|
+
export declare function ownerOf(value: object): object | undefined;
|
|
48
|
+
export declare function engineOf(value: object): EngineContext | undefined;
|
|
49
|
+
export declare function claimOwner(value: object, owner: object): void;
|
|
50
|
+
export declare function engineInSubtree(value: object): EngineContext | undefined;
|
|
51
|
+
/** Validate every descendant before touching any owner, binding, or parent. */
|
|
52
|
+
export declare function preflightBinding(value: object, engine: EngineContext): readonly object[];
|
|
53
|
+
/** Callback-free final validation uses the current tree and binding authority. */
|
|
54
|
+
export declare function validateBinding(value: object, engine: EngineContext): readonly object[];
|
|
55
|
+
/** Commit only values returned by callback-free validation, without intervening hooks. */
|
|
56
|
+
export declare function commitBinding(values: readonly object[], engine: EngineContext): void;
|
|
57
|
+
export declare function bind(value: object, engine: EngineContext): void;
|
|
58
|
+
interface CapturedInsertionAffinity {
|
|
59
|
+
readonly record: CapturedInsertionNode;
|
|
60
|
+
readonly engine: EngineContext | undefined;
|
|
61
|
+
}
|
|
62
|
+
/** This plan stays inside runtime-private modules and is consumed once by addChildAt. */
|
|
63
|
+
export interface PreparedChildInsertion {
|
|
64
|
+
readonly tree: PreparedInsertionTree;
|
|
65
|
+
readonly receiverAffinities: readonly CapturedInsertionAffinity[];
|
|
66
|
+
readonly incomingAffinities: readonly CapturedInsertionAffinity[];
|
|
67
|
+
readonly engine: EngineContext | undefined;
|
|
68
|
+
readonly stagedBindings: readonly DisplayObject[];
|
|
69
|
+
}
|
|
70
|
+
/** One post-last-hook capture supplies Engine selection, validation and all preparation. */
|
|
71
|
+
export declare function prepareChildInsertion(receiver: DisplayObjectContainer, child: DisplayObject, index: number): PreparedChildInsertion;
|
|
72
|
+
/** Straight-line commit has no hook, validation, explicit allocation or ownership write. */
|
|
73
|
+
export declare function publishPreparedChildInsertion(plan: PreparedChildInsertion): void;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=ownership.d.ts.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { EgretError } from './EgretError.js';
|
|
2
|
+
import { recordVisualChange, VISUAL_BINDING } from './displayVisualState.js';
|
|
3
|
+
import { assertLive, captureChildInsertion, childrenOf, isDisplayNode, prepareCapturedInsertionTree, publishCapturedInsertionTree, validateCapturedInsertionNode, validateCapturedInsertionRoots, validateCapturedInsertionSource } from './displayTreeState.js';
|
|
4
|
+
export const OWNERSHIP_CHILDREN = Symbol('egret.ownershipChildren');
|
|
5
|
+
export const ASSERT_BINDABLE = Symbol('egret.assertBindable');
|
|
6
|
+
export const ASSERT_ATTACHABLE = Symbol('egret.assertAttachable');
|
|
7
|
+
// Cleanup ownership and engine affinity are separate lifetime identities.
|
|
8
|
+
const owners = new WeakMap();
|
|
9
|
+
const engines = new WeakMap();
|
|
10
|
+
export function ownerOf(value) {
|
|
11
|
+
return owners.get(value);
|
|
12
|
+
}
|
|
13
|
+
export function engineOf(value) {
|
|
14
|
+
return engines.get(value);
|
|
15
|
+
}
|
|
16
|
+
export function claimOwner(value, owner) {
|
|
17
|
+
owners.set(value, owner);
|
|
18
|
+
}
|
|
19
|
+
export function engineInSubtree(value) {
|
|
20
|
+
const pending = [value];
|
|
21
|
+
while (pending.length !== 0) {
|
|
22
|
+
const current = pending.pop();
|
|
23
|
+
if (current === undefined)
|
|
24
|
+
break;
|
|
25
|
+
const engine = engineOf(current);
|
|
26
|
+
if (engine !== undefined)
|
|
27
|
+
return engine;
|
|
28
|
+
if (isDisplayNode(current))
|
|
29
|
+
pending.push(...childrenOf(current));
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
/** Validate every descendant before touching any owner, binding, or parent. */
|
|
34
|
+
export function preflightBinding(value, engine) {
|
|
35
|
+
engine.assertOpen();
|
|
36
|
+
const pending = [value];
|
|
37
|
+
const values = [];
|
|
38
|
+
while (pending.length !== 0) {
|
|
39
|
+
const current = pending.pop();
|
|
40
|
+
if (current === undefined)
|
|
41
|
+
break;
|
|
42
|
+
const existing = engineOf(current);
|
|
43
|
+
if (existing !== undefined && existing !== engine)
|
|
44
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
45
|
+
if (isDisplayNode(current)) {
|
|
46
|
+
current[ASSERT_BINDABLE]();
|
|
47
|
+
pending.push(...childrenOf(current));
|
|
48
|
+
}
|
|
49
|
+
values.push(current);
|
|
50
|
+
}
|
|
51
|
+
return values;
|
|
52
|
+
}
|
|
53
|
+
/** Callback-free final validation uses the current tree and binding authority. */
|
|
54
|
+
export function validateBinding(value, engine) {
|
|
55
|
+
engine.assertOpen();
|
|
56
|
+
const pending = [value];
|
|
57
|
+
const values = [];
|
|
58
|
+
while (pending.length !== 0) {
|
|
59
|
+
const current = pending.pop();
|
|
60
|
+
if (current === undefined)
|
|
61
|
+
break;
|
|
62
|
+
const existing = engineOf(current);
|
|
63
|
+
if (existing !== undefined && existing !== engine)
|
|
64
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
65
|
+
if (isDisplayNode(current)) {
|
|
66
|
+
assertLive(current);
|
|
67
|
+
pending.push(...childrenOf(current));
|
|
68
|
+
}
|
|
69
|
+
values.push(current);
|
|
70
|
+
}
|
|
71
|
+
return values;
|
|
72
|
+
}
|
|
73
|
+
/** Commit only values returned by callback-free validation, without intervening hooks. */
|
|
74
|
+
export function commitBinding(values, engine) {
|
|
75
|
+
for (const value of values) {
|
|
76
|
+
const changed = readInsertionEngine(value) !== engine;
|
|
77
|
+
engines.set(value, engine);
|
|
78
|
+
if (changed)
|
|
79
|
+
recordVisualChange(value, VISUAL_BINDING);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function bind(value, engine) {
|
|
83
|
+
preflightBinding(value, engine);
|
|
84
|
+
commitBinding(validateBinding(value, engine), engine);
|
|
85
|
+
}
|
|
86
|
+
// The new finite coordinator owns captured affinity reads/writes, separate from legacy bind.
|
|
87
|
+
const readInsertionEngine = engines.get.bind(engines);
|
|
88
|
+
const writeInsertionEngine = engines.set.bind(engines);
|
|
89
|
+
const InsertionBindingSet = Set;
|
|
90
|
+
const insertionBindingHas = Set.prototype.has.call.bind(Set.prototype.has);
|
|
91
|
+
const insertionBindingAdd = Set.prototype.add.call.bind(Set.prototype.add);
|
|
92
|
+
function captureInsertionAffinities(records) {
|
|
93
|
+
const affinities = [];
|
|
94
|
+
for (let index = 0; index < records.length; index++) {
|
|
95
|
+
const record = records[index];
|
|
96
|
+
affinities[index] = { record, engine: readInsertionEngine(record.node) };
|
|
97
|
+
}
|
|
98
|
+
return affinities;
|
|
99
|
+
}
|
|
100
|
+
function firstInsertionEngine(records) {
|
|
101
|
+
for (let index = 0; index < records.length; index++) {
|
|
102
|
+
const engine = records[index].engine;
|
|
103
|
+
if (engine !== undefined)
|
|
104
|
+
return engine;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
function validateInsertionAffinities(records, engine) {
|
|
109
|
+
for (let index = 0; index < records.length; index++) {
|
|
110
|
+
const current = records[index];
|
|
111
|
+
validateCapturedInsertionNode(current.record);
|
|
112
|
+
if (current.engine !== undefined && current.engine !== engine)
|
|
113
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** One post-last-hook capture supplies Engine selection, validation and all preparation. */
|
|
117
|
+
export function prepareChildInsertion(receiver, child, index) {
|
|
118
|
+
const capture = captureChildInsertion(receiver, child);
|
|
119
|
+
const receiverAffinities = captureInsertionAffinities(capture.receiverTree);
|
|
120
|
+
const incomingAffinities = captureInsertionAffinities(capture.incomingTree);
|
|
121
|
+
const engine = firstInsertionEngine(receiverAffinities) ?? firstInsertionEngine(incomingAffinities);
|
|
122
|
+
engine?.assertOpen();
|
|
123
|
+
validateCapturedInsertionRoots(capture, index);
|
|
124
|
+
// Both complete trees are always validated, including a wholly Engine-free capture.
|
|
125
|
+
validateInsertionAffinities(receiverAffinities, engine);
|
|
126
|
+
validateInsertionAffinities(incomingAffinities, engine);
|
|
127
|
+
validateCapturedInsertionSource(capture);
|
|
128
|
+
const tree = prepareCapturedInsertionTree(capture, index);
|
|
129
|
+
const stagedBindings = [];
|
|
130
|
+
const seen = new InsertionBindingSet();
|
|
131
|
+
if (engine !== undefined) {
|
|
132
|
+
for (let treeIndex = 0; treeIndex < 2; treeIndex++) {
|
|
133
|
+
const records = treeIndex === 0 ? receiverAffinities : incomingAffinities;
|
|
134
|
+
for (let position = 0; position < records.length; position++) {
|
|
135
|
+
const current = records[position], node = current.record.node;
|
|
136
|
+
if (current.engine === undefined && node !== undefined && !insertionBindingHas(seen, node)) {
|
|
137
|
+
insertionBindingAdd(seen, node);
|
|
138
|
+
stagedBindings[stagedBindings.length] = node;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Every explicit list, value and plan allocation finishes before the first outer write.
|
|
144
|
+
return { tree, receiverAffinities, incomingAffinities, engine, stagedBindings };
|
|
145
|
+
}
|
|
146
|
+
/** Straight-line commit has no hook, validation, explicit allocation or ownership write. */
|
|
147
|
+
export function publishPreparedChildInsertion(plan) {
|
|
148
|
+
if (plan.engine !== undefined) {
|
|
149
|
+
for (let index = 0; index < plan.stagedBindings.length; index++) {
|
|
150
|
+
const node = plan.stagedBindings[index];
|
|
151
|
+
writeInsertionEngine(node, plan.engine);
|
|
152
|
+
recordVisualChange(node, VISUAL_BINDING);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
publishCapturedInsertionTree(plan.tree);
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=ownership.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CancellationSignal } from '@egret/contracts';
|
|
2
|
+
import { DisplayObjectContainer } from '../DisplayObjectContainer.js';
|
|
3
|
+
import { Scope } from '../Scope.js';
|
|
4
|
+
import type { EngineContext } from '../ownership.js';
|
|
5
|
+
import type { ParagraphRequestInput, PreparedParagraph } from './types.js';
|
|
6
|
+
export interface ParagraphCachePort {
|
|
7
|
+
readonly context: EngineContext;
|
|
8
|
+
assertOpen(): void;
|
|
9
|
+
generation(): number;
|
|
10
|
+
acquire(request: ParagraphRequestInput, signal: CancellationSignal): Promise<PreparedParagraph>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createParagraphNode(scope: Scope, cache: ParagraphCachePort): DisplayObjectContainer;
|
|
13
|
+
//# sourceMappingURL=Paragraph.d.ts.map
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Bitmap } from '../Bitmap.js';
|
|
2
|
+
import { DisplayObjectContainer } from '../DisplayObjectContainer.js';
|
|
3
|
+
import { CancellationController } from '../CancellationController.js';
|
|
4
|
+
import { EgretError } from '../EgretError.js';
|
|
5
|
+
import { Scope } from '../Scope.js';
|
|
6
|
+
import { assertTextFieldScope } from '../textDisplayState.js';
|
|
7
|
+
import { claimOwner, prepareChildInsertion, publishPreparedChildInsertion } from '../ownership.js';
|
|
8
|
+
import { childCountOf, parentOf, removeNode } from '../displayTreeState.js';
|
|
9
|
+
import { assertManagedEdgeMutable } from '../ui/managedState.js';
|
|
10
|
+
import { snapshotParagraphRequest } from './request.js';
|
|
11
|
+
const states = new WeakMap();
|
|
12
|
+
const useScope = Scope.prototype.use, disposeContainer = DisplayObjectContainer.prototype.dispose;
|
|
13
|
+
const creationToken = Symbol('egret.paragraph.factory');
|
|
14
|
+
function stateOf(node) {
|
|
15
|
+
const s = states.get(node);
|
|
16
|
+
if (!s)
|
|
17
|
+
throw new EgretError('PARAGRAPH_INVALID');
|
|
18
|
+
return s;
|
|
19
|
+
}
|
|
20
|
+
function live(s) {
|
|
21
|
+
if (s.disposed)
|
|
22
|
+
throw new EgretError('PARAGRAPH_DISPOSED');
|
|
23
|
+
s.cache.assertOpen();
|
|
24
|
+
assertTextFieldScope(s.scope);
|
|
25
|
+
}
|
|
26
|
+
function cancel(s, code) {
|
|
27
|
+
const demand = s.pending;
|
|
28
|
+
s.pending = undefined;
|
|
29
|
+
if (demand) {
|
|
30
|
+
const error = new EgretError(code);
|
|
31
|
+
demand.reject(error);
|
|
32
|
+
demand.controller.abort(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class ParagraphNode extends DisplayObjectContainer {
|
|
36
|
+
constructor(scope, cache, token) {
|
|
37
|
+
super();
|
|
38
|
+
if (token !== creationToken)
|
|
39
|
+
throw new EgretError('PARAGRAPH_FACTORY_REQUIRED');
|
|
40
|
+
const s = {
|
|
41
|
+
scope,
|
|
42
|
+
cache,
|
|
43
|
+
disposed: false,
|
|
44
|
+
revision: 0,
|
|
45
|
+
request: undefined,
|
|
46
|
+
committedRevision: undefined,
|
|
47
|
+
committedGeneration: undefined,
|
|
48
|
+
metrics: undefined,
|
|
49
|
+
image: undefined,
|
|
50
|
+
committed: undefined,
|
|
51
|
+
pending: undefined
|
|
52
|
+
};
|
|
53
|
+
states.set(this, s);
|
|
54
|
+
live(s);
|
|
55
|
+
Reflect.apply(useScope, scope, [this]);
|
|
56
|
+
}
|
|
57
|
+
setRequest(input) {
|
|
58
|
+
const s = stateOf(this);
|
|
59
|
+
live(s);
|
|
60
|
+
const request = snapshotParagraphRequest(input);
|
|
61
|
+
live(s);
|
|
62
|
+
if (s.request !== undefined && JSON.stringify(s.request) === JSON.stringify(request))
|
|
63
|
+
return;
|
|
64
|
+
if (!Number.isSafeInteger(s.revision + 1))
|
|
65
|
+
throw new EgretError('PARAGRAPH_REVISION_EXHAUSTED');
|
|
66
|
+
s.revision++;
|
|
67
|
+
s.request = request;
|
|
68
|
+
cancel(s, 'PARAGRAPH_STALE');
|
|
69
|
+
}
|
|
70
|
+
prepare() {
|
|
71
|
+
const s = stateOf(this);
|
|
72
|
+
try {
|
|
73
|
+
live(s);
|
|
74
|
+
const request = s.request;
|
|
75
|
+
if (!request)
|
|
76
|
+
throw new EgretError('PARAGRAPH_REQUEST_REQUIRED');
|
|
77
|
+
const revision = s.revision, generation = s.cache.generation();
|
|
78
|
+
if (s.pending?.revision === revision && s.pending.generation === generation)
|
|
79
|
+
return s.pending.promise;
|
|
80
|
+
if (s.committedRevision === revision && s.committedGeneration === generation && s.metrics)
|
|
81
|
+
return Promise.resolve(s.metrics);
|
|
82
|
+
cancel(s, 'PARAGRAPH_STALE');
|
|
83
|
+
const controller = new CancellationController();
|
|
84
|
+
let fulfill, reject;
|
|
85
|
+
const promise = new Promise((resolve, fail) => {
|
|
86
|
+
fulfill = resolve;
|
|
87
|
+
reject = fail;
|
|
88
|
+
});
|
|
89
|
+
// Demand authority exists before an injected provider can synchronously reenter.
|
|
90
|
+
s.pending = { revision, generation, controller, promise, reject };
|
|
91
|
+
const work = s.cache
|
|
92
|
+
.acquire(request, controller.signal)
|
|
93
|
+
.then(prepared => {
|
|
94
|
+
let image, published = false;
|
|
95
|
+
try {
|
|
96
|
+
live(s);
|
|
97
|
+
if (s.revision !== revision || s.cache.generation() !== generation || controller.signal.aborted)
|
|
98
|
+
throw new EgretError('PARAGRAPH_STALE');
|
|
99
|
+
image = new Bitmap(prepared.lease);
|
|
100
|
+
// The paragraph retires its internal bitmap; share Scope identity without
|
|
101
|
+
// appending a retained Scope registration for every text replacement.
|
|
102
|
+
claimOwner(image, s.scope);
|
|
103
|
+
image.x = prepared.offsetX;
|
|
104
|
+
image.y = prepared.offsetY;
|
|
105
|
+
image.scaleX = 1 / prepared.density;
|
|
106
|
+
image.scaleY = 1 / prepared.density;
|
|
107
|
+
const previousImage = s.image, previous = s.committed;
|
|
108
|
+
// Capture and validate the private insertion without invoking public subclass hooks.
|
|
109
|
+
assertManagedEdgeMutable(this, image);
|
|
110
|
+
const insertion = prepareChildInsertion(this, image, childCountOf(this));
|
|
111
|
+
live(s);
|
|
112
|
+
if (s.revision !== revision || s.cache.generation() !== generation || controller.signal.aborted)
|
|
113
|
+
throw new EgretError('PARAGRAPH_STALE');
|
|
114
|
+
assertManagedEdgeMutable(this, image);
|
|
115
|
+
if (previousImage && parentOf(previousImage) === this)
|
|
116
|
+
assertManagedEdgeMutable(this, previousImage);
|
|
117
|
+
// Private publication and removal contain no overridable hooks or external callbacks.
|
|
118
|
+
publishPreparedChildInsertion(insertion);
|
|
119
|
+
if (previousImage && parentOf(previousImage) === this)
|
|
120
|
+
removeNode(this, previousImage);
|
|
121
|
+
s.image = image;
|
|
122
|
+
s.committed = prepared;
|
|
123
|
+
s.metrics = prepared.metrics;
|
|
124
|
+
s.committedRevision = revision;
|
|
125
|
+
s.committedGeneration = generation;
|
|
126
|
+
published = true;
|
|
127
|
+
if (s.pending?.controller === controller)
|
|
128
|
+
s.pending = undefined;
|
|
129
|
+
try {
|
|
130
|
+
previousImage?.dispose();
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
previous?.lease.release();
|
|
134
|
+
}
|
|
135
|
+
return prepared.metrics;
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
if (!published) {
|
|
139
|
+
image?.dispose();
|
|
140
|
+
prepared.lease.release();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
.catch(cause => {
|
|
145
|
+
if (s.pending?.controller === controller)
|
|
146
|
+
s.pending = undefined;
|
|
147
|
+
throw cause;
|
|
148
|
+
});
|
|
149
|
+
void work.then(fulfill, reject);
|
|
150
|
+
return promise;
|
|
151
|
+
}
|
|
152
|
+
catch (cause) {
|
|
153
|
+
return Promise.reject(cause);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
getStatus() {
|
|
157
|
+
const s = stateOf(this);
|
|
158
|
+
return Object.freeze({
|
|
159
|
+
state: s.disposed ? 'disposed' : s.metrics ? 'ready' : 'unprepared',
|
|
160
|
+
desiredRevision: s.revision,
|
|
161
|
+
committedRevision: s.committedRevision,
|
|
162
|
+
pending: s.pending !== undefined,
|
|
163
|
+
metrics: s.metrics,
|
|
164
|
+
...(s.committed?.geometry ? { geometry: s.committed.geometry } : {})
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
dispose() {
|
|
168
|
+
const s = stateOf(this);
|
|
169
|
+
if (s.disposed)
|
|
170
|
+
return;
|
|
171
|
+
s.disposed = true;
|
|
172
|
+
const committed = s.committed;
|
|
173
|
+
s.committed = undefined;
|
|
174
|
+
s.image = undefined;
|
|
175
|
+
s.request = undefined;
|
|
176
|
+
// Scope closure cancels pending demand before native work can publish a late result.
|
|
177
|
+
try {
|
|
178
|
+
cancel(s, 'PARAGRAPH_DISPOSED');
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
try {
|
|
182
|
+
Reflect.apply(disposeContainer, this, []);
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
committed?.lease.release();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function createParagraphNode(scope, cache) {
|
|
191
|
+
return new ParagraphNode(scope, cache, creationToken);
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=Paragraph.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AssetManager } from '../AssetManager.js';
|
|
2
|
+
import type { ParagraphCache, ParagraphCacheOptions } from './types.js';
|
|
3
|
+
/** A fixed optional profile shares Engine/AssetManager leases and their shutdown authority. */
|
|
4
|
+
export declare function createParagraphCache(assets: AssetManager, options: ParagraphCacheOptions): ParagraphCache;
|
|
5
|
+
//# sourceMappingURL=ParagraphCache.d.ts.map
|