@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,450 @@
|
|
|
1
|
+
import { EgretError } from "./EgretError.js";
|
|
2
|
+
import { recordVisualChange, VISUAL_STRUCTURE } from "./displayVisualState.js";
|
|
3
|
+
// Read at call time only; ownership imports this module for its own tree operations.
|
|
4
|
+
import { engineOf } from "./ownership.js";
|
|
5
|
+
// Internal state authority: validation/commit never uses overridable getters
|
|
6
|
+
// or public removeChild. Public subclass hooks run only during preflight.
|
|
7
|
+
const nodes = new WeakSet();
|
|
8
|
+
const terminated = new WeakSet();
|
|
9
|
+
const roots = new WeakSet();
|
|
10
|
+
const parents = new WeakMap();
|
|
11
|
+
const childLists = new WeakMap();
|
|
12
|
+
// The batch path uses captured original operations, never caller getters/hooks.
|
|
13
|
+
const readChildList = childLists.get.bind(childLists);
|
|
14
|
+
const readParent = parents.get.bind(parents);
|
|
15
|
+
const deleteParent = parents.delete.bind(parents);
|
|
16
|
+
const readStageRoot = roots.has.bind(roots);
|
|
17
|
+
export function registerNode(node) {
|
|
18
|
+
nodes.add(node);
|
|
19
|
+
}
|
|
20
|
+
export function registerContainer(node) {
|
|
21
|
+
childLists.set(node, []);
|
|
22
|
+
}
|
|
23
|
+
/** Authenticate an actual registered container without inspecting its shape. */
|
|
24
|
+
export function assertContainer(value) {
|
|
25
|
+
if (readChildList(value) === undefined)
|
|
26
|
+
throw new EgretError("INVALID_DISPLAY_CONTAINER");
|
|
27
|
+
}
|
|
28
|
+
export function markStageRoot(node) {
|
|
29
|
+
roots.add(node);
|
|
30
|
+
}
|
|
31
|
+
/** Identity-only authentication never reads a forged or proxied Stage. */
|
|
32
|
+
export function isStageRoot(value) {
|
|
33
|
+
return roots.has(value);
|
|
34
|
+
}
|
|
35
|
+
export function isDisplayNode(value) {
|
|
36
|
+
return nodes.has(value);
|
|
37
|
+
}
|
|
38
|
+
export function isTerminated(node) {
|
|
39
|
+
return terminated.has(node);
|
|
40
|
+
}
|
|
41
|
+
export function parentOf(node) {
|
|
42
|
+
return parents.get(node);
|
|
43
|
+
}
|
|
44
|
+
/** Return a snapshot so callers cannot mutate the authoritative child list. */
|
|
45
|
+
export function childrenOf(node) {
|
|
46
|
+
return [...(childLists.get(node) ?? [])];
|
|
47
|
+
}
|
|
48
|
+
/** Callback-free O(1) readers for budgeted traversal; never clone the list. */
|
|
49
|
+
export function childCountOf(node) {
|
|
50
|
+
return childLists.get(node)?.length ?? 0;
|
|
51
|
+
}
|
|
52
|
+
export function childAtOf(node, index) {
|
|
53
|
+
return childLists.get(node)?.[index];
|
|
54
|
+
}
|
|
55
|
+
/** Read the exact direct-child index in O(n), without a snapshot or callbacks. */
|
|
56
|
+
export function childIndexOf(parent, child) {
|
|
57
|
+
const list = readChildList(parent);
|
|
58
|
+
if (list === undefined)
|
|
59
|
+
throw new EgretError("INVALID_DISPLAY_CONTAINER");
|
|
60
|
+
if (readParent(child) !== parent)
|
|
61
|
+
throw new EgretError("NOT_A_CHILD");
|
|
62
|
+
// Scan authoritative identity directly; public getters and Array.indexOf are not authority.
|
|
63
|
+
for (let index = 0; index < list.length; index++) {
|
|
64
|
+
if (list[index] === child)
|
|
65
|
+
return index;
|
|
66
|
+
}
|
|
67
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
68
|
+
}
|
|
69
|
+
export function assertLive(node) {
|
|
70
|
+
if (terminated.has(node))
|
|
71
|
+
throw new EgretError("OBJECT_DISPOSED");
|
|
72
|
+
}
|
|
73
|
+
export function assertAttachable(node) {
|
|
74
|
+
assertLive(node);
|
|
75
|
+
if (roots.has(node))
|
|
76
|
+
throw new EgretError("STAGE_ROOT_ONLY");
|
|
77
|
+
}
|
|
78
|
+
export function assertNoCycle(parent, child) {
|
|
79
|
+
for (let current = parent; current !== undefined; current = parentOf(current)) {
|
|
80
|
+
if (current === child)
|
|
81
|
+
throw new EgretError("DISPLAY_CYCLE");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function listOf(parent) {
|
|
85
|
+
const list = childLists.get(parent);
|
|
86
|
+
if (list === undefined)
|
|
87
|
+
throw new EgretError("INVALID_DISPLAY_CONTAINER");
|
|
88
|
+
return list;
|
|
89
|
+
}
|
|
90
|
+
export function detachNode(child) {
|
|
91
|
+
const parent = parentOf(child);
|
|
92
|
+
if (parent === undefined)
|
|
93
|
+
return;
|
|
94
|
+
const list = listOf(parent);
|
|
95
|
+
// Reverse acquisition cleanup commonly removes the tail. Avoid a full
|
|
96
|
+
// search in that case; middle removals retain stable ordering and linear cost.
|
|
97
|
+
const index = list[list.length - 1] === child ? list.length - 1 : list.indexOf(child);
|
|
98
|
+
if (index < 0)
|
|
99
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
100
|
+
list.splice(index, 1);
|
|
101
|
+
parents.delete(child);
|
|
102
|
+
recordVisualChange(parent, VISUAL_STRUCTURE);
|
|
103
|
+
recordVisualChange(child, VISUAL_STRUCTURE);
|
|
104
|
+
}
|
|
105
|
+
/** Caller has completed validation; mutation has no subclass callbacks. */
|
|
106
|
+
export function attachNode(parent, child) {
|
|
107
|
+
detachNode(child);
|
|
108
|
+
listOf(parent).push(child);
|
|
109
|
+
parents.set(child, parent);
|
|
110
|
+
recordVisualChange(parent, VISUAL_STRUCTURE);
|
|
111
|
+
recordVisualChange(child, VISUAL_STRUCTURE);
|
|
112
|
+
}
|
|
113
|
+
export function removeNode(parent, child) {
|
|
114
|
+
if (parentOf(child) !== parent)
|
|
115
|
+
throw new EgretError("NOT_A_CHILD");
|
|
116
|
+
detachNode(child);
|
|
117
|
+
}
|
|
118
|
+
/** Preflight every direct edge, then detach the batch without user callbacks. */
|
|
119
|
+
export function detachChildren(parent) {
|
|
120
|
+
const list = readChildList(parent);
|
|
121
|
+
if (list === undefined)
|
|
122
|
+
throw new EgretError("INVALID_DISPLAY_CONTAINER");
|
|
123
|
+
// No edge changes until the entire private list agrees with parent authority.
|
|
124
|
+
for (let index = 0; index < list.length; index++) {
|
|
125
|
+
const child = list[index];
|
|
126
|
+
if (child === undefined || readParent(child) !== parent)
|
|
127
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
128
|
+
}
|
|
129
|
+
// Keep descendants, cleanup owners and permanent Engine affinity unchanged.
|
|
130
|
+
for (let index = 0; index < list.length; index++) {
|
|
131
|
+
const child = list[index];
|
|
132
|
+
if (child !== undefined) {
|
|
133
|
+
deleteParent(child);
|
|
134
|
+
recordVisualChange(child, VISUAL_STRUCTURE);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const changed = list.length !== 0;
|
|
138
|
+
list.length = 0;
|
|
139
|
+
if (changed)
|
|
140
|
+
recordVisualChange(parent, VISUAL_STRUCTURE);
|
|
141
|
+
}
|
|
142
|
+
export function setNodeIndex(parent, child, index) {
|
|
143
|
+
const list = listOf(parent);
|
|
144
|
+
if (parentOf(child) !== parent)
|
|
145
|
+
throw new EgretError("NOT_A_CHILD");
|
|
146
|
+
const previous = list.indexOf(child);
|
|
147
|
+
if (previous < 0)
|
|
148
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
149
|
+
list.splice(previous, 1);
|
|
150
|
+
list.splice(index, 0, child);
|
|
151
|
+
if (previous !== index) {
|
|
152
|
+
recordVisualChange(parent, VISUAL_STRUCTURE);
|
|
153
|
+
recordVisualChange(child, VISUAL_STRUCTURE);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export function terminateNode(node) {
|
|
157
|
+
terminated.add(node);
|
|
158
|
+
recordVisualChange(node, VISUAL_STRUCTURE);
|
|
159
|
+
detachNode(node);
|
|
160
|
+
}
|
|
161
|
+
// Indexed insertion has its own captured authority; legacy operations stay unchanged.
|
|
162
|
+
const insertionHasNode = nodes.has.bind(nodes);
|
|
163
|
+
const insertionIsTerminated = terminated.has.bind(terminated);
|
|
164
|
+
const insertionIsRoot = roots.has.bind(roots);
|
|
165
|
+
const insertionWriteChildren = childLists.set.bind(childLists);
|
|
166
|
+
const insertionWriteParent = parents.set.bind(parents);
|
|
167
|
+
const insertionInteger = Number.isInteger;
|
|
168
|
+
const InsertionSet = Set;
|
|
169
|
+
const insertionSeenHas = Set.prototype.has.call.bind(Set.prototype.has);
|
|
170
|
+
const insertionSeenAdd = Set.prototype.add.call.bind(Set.prototype.add);
|
|
171
|
+
// An indexed insertion that walked a receiver's whole tree and left every node in it bound to one
|
|
172
|
+
// Engine records that Engine here, so the next insertion into the same receiver does not walk the
|
|
173
|
+
// tree again. A node enters a recorded tree only through addChild or addChildAt, which bind the
|
|
174
|
+
// whole incoming tree to that Engine, or through the list replacements below, which forget the
|
|
175
|
+
// record. Detaching or disposing a node takes it out of the tree and leaves the rest as it was,
|
|
176
|
+
// and Engine affinity, once given, does not change.
|
|
177
|
+
const verifiedInsertionTrees = new WeakMap();
|
|
178
|
+
const readVerifiedInsertionTree = verifiedInsertionTrees.get.bind(verifiedInsertionTrees);
|
|
179
|
+
const writeVerifiedInsertionTree = verifiedInsertionTrees.set.bind(verifiedInsertionTrees);
|
|
180
|
+
const deleteVerifiedInsertionTree = verifiedInsertionTrees.delete.bind(verifiedInsertionTrees);
|
|
181
|
+
/** A node whose subtree may now hold other affinity retires the record of every tree containing it. */
|
|
182
|
+
function forgetVerifiedInsertionTrees(node) {
|
|
183
|
+
for (let current = node; current !== undefined; current = readParent(current)) {
|
|
184
|
+
deleteVerifiedInsertionTree(current);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function copyInsertionList(list) {
|
|
188
|
+
const snapshot = [];
|
|
189
|
+
for (let index = 0; index < list.length; index++)
|
|
190
|
+
snapshot[index] = list[index];
|
|
191
|
+
return snapshot;
|
|
192
|
+
}
|
|
193
|
+
function captureInsertionNode(node, edgeParent, repeated) {
|
|
194
|
+
const genuine = insertionHasNode(node);
|
|
195
|
+
const actualParent = readParent(node);
|
|
196
|
+
const actualChildren = readChildList(node);
|
|
197
|
+
const children = actualChildren === undefined ? undefined : copyInsertionList(actualChildren);
|
|
198
|
+
let edgeAgrees = edgeParent === undefined || actualParent === edgeParent;
|
|
199
|
+
if (edgeParent !== undefined && insertionIsRoot(node))
|
|
200
|
+
edgeAgrees = false;
|
|
201
|
+
// A captured root's external direct edge must also agree with its real parent list.
|
|
202
|
+
if (edgeParent === undefined && actualParent !== undefined) {
|
|
203
|
+
const parentChildren = readChildList(actualParent);
|
|
204
|
+
let occurrences = 0;
|
|
205
|
+
if (parentChildren !== undefined) {
|
|
206
|
+
for (let index = 0; index < parentChildren.length; index++)
|
|
207
|
+
if (parentChildren[index] === node)
|
|
208
|
+
occurrences++;
|
|
209
|
+
}
|
|
210
|
+
edgeAgrees = parentChildren !== undefined && occurrences === 1;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
node,
|
|
214
|
+
actualParent,
|
|
215
|
+
children,
|
|
216
|
+
genuine,
|
|
217
|
+
terminated: insertionIsTerminated(node),
|
|
218
|
+
stageRoot: insertionIsRoot(node),
|
|
219
|
+
repeated,
|
|
220
|
+
edgeAgrees
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function captureInsertionTree(root) {
|
|
224
|
+
const records = [];
|
|
225
|
+
const pending = [
|
|
226
|
+
{ node: root, parent: undefined }
|
|
227
|
+
];
|
|
228
|
+
const seen = new InsertionSet();
|
|
229
|
+
while (pending.length !== 0) {
|
|
230
|
+
const current = pending[pending.length - 1];
|
|
231
|
+
pending.length--;
|
|
232
|
+
const repeated = insertionSeenHas(seen, current.node);
|
|
233
|
+
insertionSeenAdd(seen, current.node);
|
|
234
|
+
const record = captureInsertionNode(current.node, current.parent, repeated);
|
|
235
|
+
records[records.length] = record;
|
|
236
|
+
// Record bad/repeated edges without throwing or following them indefinitely.
|
|
237
|
+
if (!record.genuine || repeated || record.children === undefined)
|
|
238
|
+
continue;
|
|
239
|
+
for (let index = 0; index < record.children.length; index++) {
|
|
240
|
+
pending[pending.length] = { node: record.children[index], parent: record.node };
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return records;
|
|
244
|
+
}
|
|
245
|
+
/** Capture the complete posthook authority once, without semantic refusals or hooks. */
|
|
246
|
+
export function captureChildInsertion(receiver, child) {
|
|
247
|
+
// A bound receiver whose whole tree an earlier insertion left bound to the same Engine is not
|
|
248
|
+
// walked again: every record that walk would produce is valid and carries that Engine, so the
|
|
249
|
+
// receiver contributes its own record only.
|
|
250
|
+
const receiverEngine = engineOf(receiver);
|
|
251
|
+
const receiverTree = receiverEngine !== undefined && readVerifiedInsertionTree(receiver) === receiverEngine
|
|
252
|
+
? [captureInsertionNode(receiver, undefined, false)]
|
|
253
|
+
: captureInsertionTree(receiver);
|
|
254
|
+
const incomingTree = captureInsertionTree(child);
|
|
255
|
+
const receiverAncestors = [];
|
|
256
|
+
const seenAncestors = new InsertionSet();
|
|
257
|
+
let repeatedAncestor = false;
|
|
258
|
+
for (let current = receiver; current !== undefined; current = readParent(current)) {
|
|
259
|
+
if (insertionSeenHas(seenAncestors, current)) {
|
|
260
|
+
repeatedAncestor = true;
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
insertionSeenAdd(seenAncestors, current);
|
|
264
|
+
receiverAncestors[receiverAncestors.length] = current;
|
|
265
|
+
}
|
|
266
|
+
const targetChildren = receiverTree[0].children ?? [];
|
|
267
|
+
const oldParent = incomingTree[0].actualParent;
|
|
268
|
+
const distinctSource = oldParent !== undefined && oldParent !== receiver;
|
|
269
|
+
const actualSource = distinctSource ? readChildList(oldParent) : undefined;
|
|
270
|
+
const sourceChildren = actualSource === undefined ? undefined : copyInsertionList(actualSource);
|
|
271
|
+
const sourceEdges = [];
|
|
272
|
+
const sourceSeen = new InsertionSet();
|
|
273
|
+
if (sourceChildren !== undefined) {
|
|
274
|
+
for (let index = 0; index < sourceChildren.length; index++) {
|
|
275
|
+
const node = sourceChildren[index], repeated = insertionSeenHas(sourceSeen, node);
|
|
276
|
+
insertionSeenAdd(sourceSeen, node);
|
|
277
|
+
sourceEdges[index] = captureInsertionNode(node, oldParent, repeated);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const previousChildren = oldParent === receiver ? targetChildren : sourceChildren;
|
|
281
|
+
let oldIndex = -1;
|
|
282
|
+
if (previousChildren !== undefined) {
|
|
283
|
+
for (let index = 0; index < previousChildren.length; index++)
|
|
284
|
+
if (previousChildren[index] === child) {
|
|
285
|
+
oldIndex = index;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
receiver,
|
|
291
|
+
child,
|
|
292
|
+
receiverTree,
|
|
293
|
+
incomingTree,
|
|
294
|
+
receiverAncestors,
|
|
295
|
+
repeatedAncestor,
|
|
296
|
+
targetChildren,
|
|
297
|
+
oldParent,
|
|
298
|
+
sourceChildren,
|
|
299
|
+
sourceEdges,
|
|
300
|
+
sourceContainerGenuine: !distinctSource || actualSource !== undefined,
|
|
301
|
+
oldIndex
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/** Inclusive index checks never coerce boxed, string or other caller values. */
|
|
305
|
+
export function assertChildInsertionIndex(receiver, index) {
|
|
306
|
+
if (typeof index !== "number" ||
|
|
307
|
+
!insertionInteger(index) ||
|
|
308
|
+
index < 0 ||
|
|
309
|
+
index > (readChildList(receiver)?.length ?? 0)) {
|
|
310
|
+
throw new EgretError("INVALID_INDEX");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** Engine openness is checked by ownership before these ordered root semantics. */
|
|
314
|
+
export function validateCapturedInsertionRoots(capture, index) {
|
|
315
|
+
const receiver = capture.receiverTree[0], child = capture.incomingTree[0];
|
|
316
|
+
if (receiver.terminated)
|
|
317
|
+
throw new EgretError("OBJECT_DISPOSED");
|
|
318
|
+
if (child.terminated)
|
|
319
|
+
throw new EgretError("OBJECT_DISPOSED");
|
|
320
|
+
if (child.stageRoot)
|
|
321
|
+
throw new EgretError("STAGE_ROOT_ONLY");
|
|
322
|
+
for (let position = 0; position < capture.receiverAncestors.length; position++) {
|
|
323
|
+
if (capture.receiverAncestors[position] === capture.child)
|
|
324
|
+
throw new EgretError("DISPLAY_CYCLE");
|
|
325
|
+
}
|
|
326
|
+
if (typeof index !== "number" || !insertionInteger(index) || index < 0 || index > capture.targetChildren.length) {
|
|
327
|
+
throw new EgretError("INVALID_INDEX");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/** Identity, life and edge checks precede the corresponding recorded affinity check. */
|
|
331
|
+
export function validateCapturedInsertionNode(record) {
|
|
332
|
+
if (!record.genuine)
|
|
333
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
334
|
+
if (record.terminated)
|
|
335
|
+
throw new EgretError("OBJECT_DISPOSED");
|
|
336
|
+
if (record.repeated || !record.edgeAgrees)
|
|
337
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
338
|
+
}
|
|
339
|
+
/** Validate every current distinct-source direct edge, including unrelated siblings. */
|
|
340
|
+
export function validateCapturedInsertionSource(capture) {
|
|
341
|
+
if (capture.repeatedAncestor || !capture.sourceContainerGenuine)
|
|
342
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
343
|
+
if (capture.oldParent !== undefined && capture.oldIndex < 0)
|
|
344
|
+
throw new EgretError("DISPLAY_TREE_INVARIANT");
|
|
345
|
+
for (let index = 0; index < capture.sourceEdges.length; index++)
|
|
346
|
+
validateCapturedInsertionNode(capture.sourceEdges[index]);
|
|
347
|
+
}
|
|
348
|
+
/** Build both replacements solely from the validated capture; no mapping writes occur. */
|
|
349
|
+
export function prepareCapturedInsertionTree(capture, index) {
|
|
350
|
+
const sameParent = capture.oldParent === capture.receiver;
|
|
351
|
+
const targetCount = capture.targetChildren.length;
|
|
352
|
+
const effectiveIndex = sameParent && index === targetCount ? targetCount - 1 : index === 0 ? 0 : index;
|
|
353
|
+
const targetChanged = !sameParent || capture.oldIndex !== effectiveIndex;
|
|
354
|
+
let targetReplacement;
|
|
355
|
+
if (targetChanged) {
|
|
356
|
+
targetReplacement = [];
|
|
357
|
+
const nextCount = sameParent ? targetCount : targetCount + 1;
|
|
358
|
+
let readIndex = 0;
|
|
359
|
+
for (let writeIndex = 0; writeIndex < nextCount; writeIndex++) {
|
|
360
|
+
if (writeIndex === effectiveIndex)
|
|
361
|
+
targetReplacement[writeIndex] = capture.child;
|
|
362
|
+
else {
|
|
363
|
+
if (sameParent && readIndex === capture.oldIndex)
|
|
364
|
+
readIndex++;
|
|
365
|
+
targetReplacement[writeIndex] = capture.targetChildren[readIndex];
|
|
366
|
+
readIndex++;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
let sourceReplacement;
|
|
371
|
+
if (capture.oldParent !== undefined && !sameParent) {
|
|
372
|
+
sourceReplacement = [];
|
|
373
|
+
const sourceChildren = capture.sourceChildren;
|
|
374
|
+
for (let readIndex = 0, writeIndex = 0; readIndex < sourceChildren.length; readIndex++) {
|
|
375
|
+
if (readIndex !== capture.oldIndex)
|
|
376
|
+
sourceReplacement[writeIndex++] = sourceChildren[readIndex];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return { capture, effectiveIndex, targetReplacement, sourceReplacement, parentChanged: !sameParent };
|
|
380
|
+
}
|
|
381
|
+
/** Publication uses captured native writes only: source, target, then moved parent. */
|
|
382
|
+
export function publishCapturedInsertionTree(plan) {
|
|
383
|
+
if (plan.sourceReplacement !== undefined)
|
|
384
|
+
insertionWriteChildren(plan.capture.oldParent, plan.sourceReplacement);
|
|
385
|
+
if (plan.targetReplacement !== undefined)
|
|
386
|
+
insertionWriteChildren(plan.capture.receiver, plan.targetReplacement);
|
|
387
|
+
if (plan.parentChanged)
|
|
388
|
+
insertionWriteParent(plan.capture.child, plan.capture.receiver);
|
|
389
|
+
// All source/target/edge authority is visible before its allocation-free revisions.
|
|
390
|
+
if (plan.sourceReplacement !== undefined)
|
|
391
|
+
recordVisualChange(plan.capture.oldParent, VISUAL_STRUCTURE);
|
|
392
|
+
if (plan.targetReplacement !== undefined) {
|
|
393
|
+
recordVisualChange(plan.capture.receiver, VISUAL_STRUCTURE);
|
|
394
|
+
recordVisualChange(plan.capture.child, VISUAL_STRUCTURE);
|
|
395
|
+
}
|
|
396
|
+
// Both trees were validated against one Engine and every staged affinity is already written, so a
|
|
397
|
+
// bound receiver's whole tree now carries its Engine. A tree without an Engine is never recorded.
|
|
398
|
+
const engine = engineOf(plan.capture.receiver);
|
|
399
|
+
if (engine !== undefined)
|
|
400
|
+
writeVerifiedInsertionTree(plan.capture.receiver, engine);
|
|
401
|
+
}
|
|
402
|
+
export function captureUiChildren(parent) {
|
|
403
|
+
return copyInsertionList(listOf(parent));
|
|
404
|
+
}
|
|
405
|
+
export function validateUiChildren(parent, expected) {
|
|
406
|
+
const actual = readChildList(parent);
|
|
407
|
+
if (actual === undefined || actual.length !== expected.length)
|
|
408
|
+
return false;
|
|
409
|
+
for (let index = 0; index < actual.length; index++) {
|
|
410
|
+
if (actual[index] !== expected[index] || readParent(actual[index]) !== parent)
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
export function publishUiTree(replacements) {
|
|
416
|
+
for (let index = 0; index < replacements.length; index++) {
|
|
417
|
+
const item = replacements[index];
|
|
418
|
+
for (let childIndex = 0; childIndex < item.previous.length; childIndex++) {
|
|
419
|
+
const child = item.previous[childIndex];
|
|
420
|
+
deleteParent(child);
|
|
421
|
+
recordVisualChange(child, VISUAL_STRUCTURE);
|
|
422
|
+
}
|
|
423
|
+
insertionWriteChildren(item.parent, item.next);
|
|
424
|
+
recordVisualChange(item.parent, VISUAL_STRUCTURE);
|
|
425
|
+
}
|
|
426
|
+
for (let index = 0; index < replacements.length; index++) {
|
|
427
|
+
const item = replacements[index];
|
|
428
|
+
for (let childIndex = 0; childIndex < item.next.length; childIndex++) {
|
|
429
|
+
const child = item.next[childIndex];
|
|
430
|
+
insertionWriteParent(child, item.parent);
|
|
431
|
+
recordVisualChange(child, VISUAL_STRUCTURE);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
// The replacement children were admitted by the UI commit, not by an indexed insertion.
|
|
435
|
+
for (let index = 0; index < replacements.length; index++)
|
|
436
|
+
forgetVerifiedInsertionTrees(replacements[index].parent);
|
|
437
|
+
}
|
|
438
|
+
/** One validated borrowed-child replacement; all storage was allocated in preparation. */
|
|
439
|
+
export function publishPreparedChildren(parent, previous, next) {
|
|
440
|
+
for (let i = 0; i < previous.length; i++) {
|
|
441
|
+
deleteParent(previous[i]);
|
|
442
|
+
recordVisualChange(previous[i], VISUAL_STRUCTURE);
|
|
443
|
+
}
|
|
444
|
+
insertionWriteChildren(parent, next);
|
|
445
|
+
insertionWriteParent(next[0], parent);
|
|
446
|
+
recordVisualChange(parent, VISUAL_STRUCTURE);
|
|
447
|
+
recordVisualChange(next[0], VISUAL_STRUCTURE);
|
|
448
|
+
forgetVerifiedInsertionTrees(parent);
|
|
449
|
+
}
|
|
450
|
+
//# sourceMappingURL=displayTreeState.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Rectangle2D, SharedMaterial2D } from "@egret/contracts";
|
|
2
|
+
import type { DisplayObject } from "./DisplayObject.js";
|
|
3
|
+
import type { RenderEffect2D } from "./renderEffect.js";
|
|
4
|
+
import type { ShapeState } from "./graphicsShape.js";
|
|
5
|
+
export interface Primitive {
|
|
6
|
+
readonly rect: Rectangle2D;
|
|
7
|
+
readonly color: number;
|
|
8
|
+
readonly alpha: number;
|
|
9
|
+
}
|
|
10
|
+
export interface VisualState {
|
|
11
|
+
structureRevision: number;
|
|
12
|
+
transformRevision: number;
|
|
13
|
+
appearanceRevision: number;
|
|
14
|
+
contentRevision: number;
|
|
15
|
+
bindingRevision: number;
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
anchorOffsetX: number;
|
|
19
|
+
anchorOffsetY: number;
|
|
20
|
+
scaleX: number;
|
|
21
|
+
scaleY: number;
|
|
22
|
+
rotation: number;
|
|
23
|
+
/** Degrees by which the y axis and the x axis are turned beyond the rotation; 0 and 0 is no skew. */
|
|
24
|
+
skewX: number;
|
|
25
|
+
skewY: number;
|
|
26
|
+
/** A name the application gives, for getChildByName. */
|
|
27
|
+
name: string;
|
|
28
|
+
alpha: number;
|
|
29
|
+
visible: boolean;
|
|
30
|
+
sharedMaterial: SharedMaterial2D | null;
|
|
31
|
+
renderBoundary: "none" | "isolate";
|
|
32
|
+
renderEffect: RenderEffect2D | undefined;
|
|
33
|
+
clipRect: Rectangle2D | undefined;
|
|
34
|
+
primitives: Primitive[];
|
|
35
|
+
/** What the node draws besides filled rectangles: triangles and a path, which Graphics alone writes. */
|
|
36
|
+
shape: ShapeState | undefined;
|
|
37
|
+
/** What the shared capture keeps of this node between frames; the capture alone reads and writes it. */
|
|
38
|
+
sharedCapture: object | undefined;
|
|
39
|
+
/** How many changes were recorded for this node, of any kind. It only grows. */
|
|
40
|
+
changes: number;
|
|
41
|
+
/** The last capture that visited this node; a capture visits a node once. The captures alone read and write it. */
|
|
42
|
+
seenBy: number;
|
|
43
|
+
}
|
|
44
|
+
export declare const VISUAL_STRUCTURE = 1;
|
|
45
|
+
export declare const VISUAL_TRANSFORM = 2;
|
|
46
|
+
export declare const VISUAL_APPEARANCE = 4;
|
|
47
|
+
export declare const VISUAL_CONTENT = 8;
|
|
48
|
+
export declare const VISUAL_BINDING = 16;
|
|
49
|
+
/**
|
|
50
|
+
* Publish after the original authoritative write. No lifecycle check, callback or
|
|
51
|
+
* explicit allocation may enter tree/ticket commits or terminal cleanup here.
|
|
52
|
+
* Non-display affinity values have no visual state and need no capture revision.
|
|
53
|
+
*/
|
|
54
|
+
export declare function recordVisualChange(node: object, changes: number): void;
|
|
55
|
+
export declare function registerVisual(node: DisplayObject): void;
|
|
56
|
+
export declare function visualOf(node: DisplayObject): VisualState;
|
|
57
|
+
type AnchorAxis = "anchorOffsetX" | "anchorOffsetY";
|
|
58
|
+
export declare function readAnchorOffset(receiver: unknown, axis: AnchorAxis): number;
|
|
59
|
+
export declare function writeAnchorOffset(receiver: unknown, axis: AnchorAxis, value: unknown): void;
|
|
60
|
+
export declare function assertVisualMutable(node: DisplayObject): void;
|
|
61
|
+
/** A refused display value: the error says which property was set and what it was given. */
|
|
62
|
+
export declare function invalidDisplayValue(property: string, value: unknown): Error;
|
|
63
|
+
export declare function finite(value: unknown): value is number;
|
|
64
|
+
export declare function color(value: unknown): value is number;
|
|
65
|
+
/**
|
|
66
|
+
* An alpha as it is kept: a finite number, held to 0 and 1. A game's arithmetic often lands a hair outside (a fade
|
|
67
|
+
* that runs one step long, an easing that overshoots), and that is not worth stopping a frame for. What is not a
|
|
68
|
+
* finite number gives undefined, for the caller to refuse.
|
|
69
|
+
*/
|
|
70
|
+
export declare function alphaOf(value: unknown): number | undefined;
|
|
71
|
+
export declare function unit(value: unknown): value is number;
|
|
72
|
+
export declare function copyRect(value: Rectangle2D, code: string): Rectangle2D;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=displayVisualState.d.ts.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { assertManagedMutable } from "./ui/managedState.js";
|
|
2
|
+
import { assertLive, isDisplayNode } from "./displayTreeState.js";
|
|
3
|
+
import { engineOf } from "./ownership.js";
|
|
4
|
+
import { EgretError } from "./EgretError.js";
|
|
5
|
+
// Authoritative per-node visual state excludes overridable public accessors.
|
|
6
|
+
const states = new WeakMap();
|
|
7
|
+
const readRevisionState = states.get.bind(states);
|
|
8
|
+
const sameValue = Object.is;
|
|
9
|
+
export const VISUAL_STRUCTURE = 1;
|
|
10
|
+
export const VISUAL_TRANSFORM = 2;
|
|
11
|
+
export const VISUAL_APPEARANCE = 4;
|
|
12
|
+
export const VISUAL_CONTENT = 8;
|
|
13
|
+
export const VISUAL_BINDING = 16;
|
|
14
|
+
// Never publish MAX_SAFE_INTEGER: invalidate every old key before restarting.
|
|
15
|
+
const REVISION_RESTART = 9007199254740990;
|
|
16
|
+
/**
|
|
17
|
+
* Publish after the original authoritative write. No lifecycle check, callback or
|
|
18
|
+
* explicit allocation may enter tree/ticket commits or terminal cleanup here.
|
|
19
|
+
* Non-display affinity values have no visual state and need no capture revision.
|
|
20
|
+
*/
|
|
21
|
+
export function recordVisualChange(node, changes) {
|
|
22
|
+
const state = readRevisionState(node);
|
|
23
|
+
if (state === undefined)
|
|
24
|
+
return;
|
|
25
|
+
state.changes++;
|
|
26
|
+
if (((changes & VISUAL_STRUCTURE) !== 0 && state.structureRevision >= REVISION_RESTART) ||
|
|
27
|
+
((changes & VISUAL_TRANSFORM) !== 0 && state.transformRevision >= REVISION_RESTART) ||
|
|
28
|
+
((changes & VISUAL_APPEARANCE) !== 0 && state.appearanceRevision >= REVISION_RESTART) ||
|
|
29
|
+
((changes & VISUAL_CONTENT) !== 0 && state.contentRevision >= REVISION_RESTART) ||
|
|
30
|
+
((changes & VISUAL_BINDING) !== 0 && state.bindingRevision >= REVISION_RESTART)) {
|
|
31
|
+
state.structureRevision = 0;
|
|
32
|
+
state.transformRevision = 0;
|
|
33
|
+
state.appearanceRevision = 0;
|
|
34
|
+
state.contentRevision = 0;
|
|
35
|
+
state.bindingRevision = 0;
|
|
36
|
+
}
|
|
37
|
+
if ((changes & VISUAL_STRUCTURE) !== 0)
|
|
38
|
+
state.structureRevision++;
|
|
39
|
+
if ((changes & VISUAL_TRANSFORM) !== 0)
|
|
40
|
+
state.transformRevision++;
|
|
41
|
+
if ((changes & VISUAL_APPEARANCE) !== 0)
|
|
42
|
+
state.appearanceRevision++;
|
|
43
|
+
if ((changes & VISUAL_CONTENT) !== 0)
|
|
44
|
+
state.contentRevision++;
|
|
45
|
+
if ((changes & VISUAL_BINDING) !== 0)
|
|
46
|
+
state.bindingRevision++;
|
|
47
|
+
}
|
|
48
|
+
export function registerVisual(node) {
|
|
49
|
+
states.set(node, {
|
|
50
|
+
structureRevision: 0,
|
|
51
|
+
transformRevision: 0,
|
|
52
|
+
appearanceRevision: 0,
|
|
53
|
+
contentRevision: 0,
|
|
54
|
+
bindingRevision: 0,
|
|
55
|
+
x: 0,
|
|
56
|
+
y: 0,
|
|
57
|
+
scaleX: 1,
|
|
58
|
+
scaleY: 1,
|
|
59
|
+
rotation: 0,
|
|
60
|
+
skewX: 0,
|
|
61
|
+
skewY: 0,
|
|
62
|
+
name: "",
|
|
63
|
+
alpha: 1,
|
|
64
|
+
anchorOffsetX: 0,
|
|
65
|
+
anchorOffsetY: 0,
|
|
66
|
+
visible: true,
|
|
67
|
+
renderEffect: undefined,
|
|
68
|
+
sharedMaterial: null,
|
|
69
|
+
renderBoundary: "none",
|
|
70
|
+
clipRect: undefined,
|
|
71
|
+
primitives: [],
|
|
72
|
+
shape: undefined,
|
|
73
|
+
sharedCapture: undefined,
|
|
74
|
+
changes: 0,
|
|
75
|
+
seenBy: 0
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export function visualOf(node) {
|
|
79
|
+
return states.get(node);
|
|
80
|
+
}
|
|
81
|
+
/** Authenticate private node identity before lifecycle or caller values. */
|
|
82
|
+
function anchorState(receiver) {
|
|
83
|
+
if (!isDisplayNode(receiver))
|
|
84
|
+
throw new EgretError("INVALID_DISPLAY_OBJECT");
|
|
85
|
+
return visualOf(receiver);
|
|
86
|
+
}
|
|
87
|
+
export function readAnchorOffset(receiver, axis) {
|
|
88
|
+
return anchorState(receiver)[axis];
|
|
89
|
+
}
|
|
90
|
+
export function writeAnchorOffset(receiver, axis, value) {
|
|
91
|
+
const state = anchorState(receiver);
|
|
92
|
+
assertVisualMutable(receiver);
|
|
93
|
+
if (!finite(value))
|
|
94
|
+
throw new EgretError("DISPLAY_VALUE_INVALID");
|
|
95
|
+
const changed = !sameValue(state[axis], value);
|
|
96
|
+
state[axis] = value;
|
|
97
|
+
if (changed)
|
|
98
|
+
recordVisualChange(receiver, VISUAL_TRANSFORM);
|
|
99
|
+
}
|
|
100
|
+
export function assertVisualMutable(node) {
|
|
101
|
+
assertManagedMutable(node);
|
|
102
|
+
assertLive(node);
|
|
103
|
+
engineOf(node)?.assertOpen();
|
|
104
|
+
}
|
|
105
|
+
/** A refused display value: the error says which property was set and what it was given. */
|
|
106
|
+
export function invalidDisplayValue(property, value) {
|
|
107
|
+
// An object is named by its kind alone: a refused value is never read.
|
|
108
|
+
const given = typeof value === "string"
|
|
109
|
+
? JSON.stringify(value.length > 40 ? value.slice(0, 40) + "…" : value)
|
|
110
|
+
: value === null || (typeof value !== "object" && typeof value !== "function" && typeof value !== "symbol")
|
|
111
|
+
? String(value)
|
|
112
|
+
: typeof value === "object"
|
|
113
|
+
? "an object"
|
|
114
|
+
: "a " + typeof value;
|
|
115
|
+
return new EgretError("DISPLAY_VALUE_INVALID", { cause: new RangeError(`${property} was given ${given}`) });
|
|
116
|
+
}
|
|
117
|
+
export function finite(value) {
|
|
118
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
119
|
+
}
|
|
120
|
+
export function color(value) {
|
|
121
|
+
return finite(value) && Number.isInteger(value) && value >= 0 && value <= 0xffffff;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* An alpha as it is kept: a finite number, held to 0 and 1. A game's arithmetic often lands a hair outside (a fade
|
|
125
|
+
* that runs one step long, an easing that overshoots), and that is not worth stopping a frame for. What is not a
|
|
126
|
+
* finite number gives undefined, for the caller to refuse.
|
|
127
|
+
*/
|
|
128
|
+
export function alphaOf(value) {
|
|
129
|
+
return finite(value) ? (value < 0 ? 0 : value > 1 ? 1 : value) : undefined;
|
|
130
|
+
}
|
|
131
|
+
export function unit(value) {
|
|
132
|
+
return finite(value) && value >= 0 && value <= 1;
|
|
133
|
+
}
|
|
134
|
+
export function copyRect(value, code) {
|
|
135
|
+
const { x, y, width, height } = value;
|
|
136
|
+
if (![x, y, width, height].every(finite) || width < 0 || height < 0)
|
|
137
|
+
throw new EgretError(code);
|
|
138
|
+
return Object.freeze({ x, y, width, height });
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=displayVisualState.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The languages an error's sentence can be in. */
|
|
2
|
+
export type ErrorLanguage = 'en' | 'zh';
|
|
3
|
+
/**
|
|
4
|
+
* The language of the sentence in the message of every error made from now on: English unless set. The code of an
|
|
5
|
+
* error is the same in every language.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setErrorLanguage(value: ErrorLanguage): void;
|
|
8
|
+
export declare function getErrorLanguage(): ErrorLanguage;
|
|
9
|
+
/**
|
|
10
|
+
* A sentence for an error code: what went wrong and, for the codes a game meets most, what to do. It is in the
|
|
11
|
+
* language given, or the one set by `setErrorLanguage`. A code this SDK does not know gives an empty string.
|
|
12
|
+
*/
|
|
13
|
+
export declare function describeErrorCode(code: string, inLanguage?: ErrorLanguage): string;
|
|
14
|
+
//# sourceMappingURL=errorHelp.d.ts.map
|