@egret/runtime 0.0.0-stage → 7.0.2
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 +58 -0
- package/dist/AssetManager.js +451 -0
- package/dist/AssetRef.d.ts +21 -0
- package/dist/AssetRef.js +33 -0
- package/dist/Bitmap.d.ts +40 -0
- package/dist/Bitmap.js +545 -0
- package/dist/ByteReader.d.ts +32 -0
- package/dist/ByteReader.js +178 -0
- package/dist/ByteWriter.d.ts +30 -0
- package/dist/ByteWriter.js +181 -0
- package/dist/CancellationController.d.ts +10 -0
- package/dist/CancellationController.js +66 -0
- package/dist/DisplayObject.d.ts +97 -0
- package/dist/DisplayObject.js +366 -0
- package/dist/DisplayObjectContainer.d.ts +28 -0
- package/dist/DisplayObjectContainer.js +226 -0
- package/dist/EgretError.d.ts +12 -0
- package/dist/EgretError.js +36 -0
- package/dist/Event.d.ts +47 -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 +117 -0
- package/dist/Graphics.js +548 -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 +19 -0
- package/dist/NineSliceGeometry2D.js +126 -0
- package/dist/Scope.d.ts +19 -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 +30 -0
- package/dist/Texture.js +178 -0
- package/dist/assetManagerOwnerState.d.ts +36 -0
- package/dist/assetManagerOwnerState.js +115 -0
- package/dist/assetState.d.ts +45 -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 +76 -0
- package/dist/displayVisualState.js +141 -0
- package/dist/errorHelp.d.ts +15 -0
- package/dist/errorHelp.js +435 -0
- package/dist/errorHelpZh.d.ts +5 -0
- package/dist/errorHelpZh.js +342 -0
- package/dist/geometry.d.ts +173 -0
- package/dist/geometry.js +311 -0
- package/dist/graphicsFill.d.ts +37 -0
- package/dist/graphicsFill.js +302 -0
- package/dist/graphicsShape.d.ts +170 -0
- package/dist/graphicsShape.js +961 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +31 -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 +64 -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 +57 -0
- package/dist/renderEffect.js +109 -0
- package/dist/sequenceClip.d.ts +48 -0
- package/dist/sequenceClip.js +197 -0
- package/dist/sharedFrameCapture.d.ts +24 -0
- package/dist/sharedFrameCapture.js +1128 -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 +384 -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,34 @@
|
|
|
1
|
+
import type { Disposable, TextureRegion2D } from "@egret/contracts";
|
|
2
|
+
import type { AssetLease } from "./AssetLease.js";
|
|
3
|
+
import type { Bitmap } from "./Bitmap.js";
|
|
4
|
+
import type { Texture } from "./Texture.js";
|
|
5
|
+
import type { AtlasFrameLayout } from "./atlasFrameLayout.js";
|
|
6
|
+
type AtlasRegion = TextureRegion2D & {
|
|
7
|
+
readonly layout?: AtlasFrameLayout;
|
|
8
|
+
};
|
|
9
|
+
declare const SPRITE_SHEET_BRAND: unique symbol;
|
|
10
|
+
/** One packed absolute rectangle, indexed by its exact UTF-16 name. */
|
|
11
|
+
export interface SpriteSheetFrameInput {
|
|
12
|
+
readonly layout?: AtlasFrameLayout;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly x: number;
|
|
15
|
+
readonly y: number;
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
}
|
|
19
|
+
/** Immutable metadata plus a separately revocable borrow of one original lease. */
|
|
20
|
+
export interface SpriteSheet extends Disposable {
|
|
21
|
+
readonly [SPRITE_SHEET_BRAND]: void;
|
|
22
|
+
readonly frameCount: number;
|
|
23
|
+
readonly names: readonly string[];
|
|
24
|
+
readonly atlasWidth: number;
|
|
25
|
+
readonly atlasHeight: number;
|
|
26
|
+
readonly isDisposed: boolean;
|
|
27
|
+
getRegion(name: string): AtlasRegion;
|
|
28
|
+
createBitmap(name: string): Bitmap;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
}
|
|
31
|
+
/** Build one exact-name table from a genuine full-image lease without acquiring another resource. */
|
|
32
|
+
export declare function createSpriteSheet(atlasLease: AssetLease<Texture>, frames: readonly SpriteSheetFrameInput[], profile?: "trim-rotation-v1"): SpriteSheet;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=spriteSheet.d.ts.map
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { isAssetLease } from "./AssetLease.js";
|
|
2
|
+
import { applyBitmapAtlasFrame, readBitmapImage, spriteSheetBitmapOperations } from "./Bitmap.js";
|
|
3
|
+
import { EgretError } from "./EgretError.js";
|
|
4
|
+
import { commitBinding, engineOf } from "./ownership.js";
|
|
5
|
+
import { captureAtlasFrameLayout, copyAtlasFrameLayout } from "./atlasFrameLayout.js";
|
|
6
|
+
const states = new WeakMap();
|
|
7
|
+
const arrayIsArray = Array.isArray;
|
|
8
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
9
|
+
const apply = Reflect.apply;
|
|
10
|
+
function stateOf(receiver) {
|
|
11
|
+
const state = states.get(receiver);
|
|
12
|
+
if (state === undefined)
|
|
13
|
+
throw new EgretError("SPRITE_SHEET_INVALID");
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
/** Original context and private resource slots precede caller-controlled fields. */
|
|
17
|
+
function readAtlas(engine, lease, expectedImage) {
|
|
18
|
+
engine.assertOpen();
|
|
19
|
+
const snapshot = readBitmapImage(lease);
|
|
20
|
+
const { image, sourceRect } = snapshot;
|
|
21
|
+
if (snapshot.viewRegion !== null ||
|
|
22
|
+
sourceRect.x !== 0 ||
|
|
23
|
+
sourceRect.y !== 0 ||
|
|
24
|
+
sourceRect.width !== image.width ||
|
|
25
|
+
sourceRect.height !== image.height ||
|
|
26
|
+
(expectedImage !== undefined && image !== expectedImage)) {
|
|
27
|
+
throw new EgretError("SPRITE_SHEET_ATLAS_INVALID");
|
|
28
|
+
}
|
|
29
|
+
return snapshot;
|
|
30
|
+
}
|
|
31
|
+
/** A successful source operation is revalidated outside its read-fault catch. */
|
|
32
|
+
function readSource(operation, revalidate) {
|
|
33
|
+
let result;
|
|
34
|
+
let failed = false;
|
|
35
|
+
let cause;
|
|
36
|
+
try {
|
|
37
|
+
result = operation();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
failed = true;
|
|
41
|
+
cause = error;
|
|
42
|
+
}
|
|
43
|
+
// The occurrence flag preserves a caller that throws undefined.
|
|
44
|
+
if (failed)
|
|
45
|
+
throw new EgretError("SPRITE_SHEET_READ_FAILED", { cause });
|
|
46
|
+
revalidate();
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function own(input, key, revalidate) {
|
|
50
|
+
return readSource(() => apply(hasOwnProperty, input, [key]), revalidate);
|
|
51
|
+
}
|
|
52
|
+
function readField(input, key, revalidate) {
|
|
53
|
+
const present = own(input, key, revalidate);
|
|
54
|
+
const value = present ? readSource(() => input[key], revalidate) : undefined;
|
|
55
|
+
return { present, value };
|
|
56
|
+
}
|
|
57
|
+
/** Missing known fields are staged; a later read occurrence keeps its priority. */
|
|
58
|
+
function stageFrames(input, revalidate, atlasLayout) {
|
|
59
|
+
if (!readSource(() => arrayIsArray(input), revalidate))
|
|
60
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
61
|
+
if (!own(input, "length", revalidate))
|
|
62
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
63
|
+
const length = readSource(() => input.length, revalidate);
|
|
64
|
+
if (typeof length !== "number" || !Number.isSafeInteger(length) || length < 1) {
|
|
65
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
66
|
+
}
|
|
67
|
+
if (length > 1024)
|
|
68
|
+
throw new EgretError("SPRITE_SHEET_LIMIT");
|
|
69
|
+
const staged = [];
|
|
70
|
+
for (let index = 0; index < length; index += 1) {
|
|
71
|
+
if (!own(input, String(index), revalidate))
|
|
72
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
73
|
+
const record = readSource(() => input[index], revalidate);
|
|
74
|
+
if (record === null || typeof record !== "object")
|
|
75
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
76
|
+
if (readSource(() => arrayIsArray(record), revalidate))
|
|
77
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
78
|
+
const name = readField(record, "name", revalidate);
|
|
79
|
+
const x = readField(record, "x", revalidate);
|
|
80
|
+
const y = readField(record, "y", revalidate);
|
|
81
|
+
const width = readField(record, "width", revalidate);
|
|
82
|
+
const height = readField(record, "height", revalidate);
|
|
83
|
+
const layout = atlasLayout
|
|
84
|
+
? captureAtlasFrameLayout(record, (source, key) => readField(source, key, revalidate), callback => readSource(callback, revalidate))
|
|
85
|
+
: undefined;
|
|
86
|
+
staged.push({ name, x, y, width, height, ...(layout === undefined ? {} : { layout }) });
|
|
87
|
+
}
|
|
88
|
+
return staged;
|
|
89
|
+
}
|
|
90
|
+
function qualifyName(value) {
|
|
91
|
+
if (typeof value !== "string")
|
|
92
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
93
|
+
if (value.length === 0)
|
|
94
|
+
throw new EgretError("SPRITE_SHEET_NAME_INVALID");
|
|
95
|
+
if (value.length > 128)
|
|
96
|
+
throw new EgretError("SPRITE_SHEET_LIMIT");
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
function coordinate(value, positive) {
|
|
100
|
+
if (typeof value !== "number")
|
|
101
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
102
|
+
if (!Number.isSafeInteger(value) || (positive ? value <= 0 : value < 0)) {
|
|
103
|
+
throw new EgretError("SPRITE_SHEET_REGION_INVALID");
|
|
104
|
+
}
|
|
105
|
+
return value === 0 ? 0 : value;
|
|
106
|
+
}
|
|
107
|
+
function findRegion(state, name) {
|
|
108
|
+
const key = qualifyName(name);
|
|
109
|
+
const region = state.regions.get(key);
|
|
110
|
+
if (region === undefined)
|
|
111
|
+
throw new EgretError("SPRITE_SHEET_FRAME_UNKNOWN");
|
|
112
|
+
return region;
|
|
113
|
+
}
|
|
114
|
+
function assertCreationLive(state, lease) {
|
|
115
|
+
if (state.disposed)
|
|
116
|
+
throw new EgretError("SPRITE_SHEET_DISPOSED");
|
|
117
|
+
// Keep context authority after disposal, but never reconstruct a dropped borrow.
|
|
118
|
+
readAtlas(state.engine, lease, state.image);
|
|
119
|
+
}
|
|
120
|
+
/** Only an operation throw is wrapped; successful terminal side effects stay lifecycle errors. */
|
|
121
|
+
function bitmapOperation(operation) {
|
|
122
|
+
let result;
|
|
123
|
+
let failed = false;
|
|
124
|
+
let cause;
|
|
125
|
+
try {
|
|
126
|
+
result = operation();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
failed = true;
|
|
130
|
+
cause = error;
|
|
131
|
+
}
|
|
132
|
+
if (failed)
|
|
133
|
+
throw new EgretError("SPRITE_SHEET_BITMAP_FAILED", { cause });
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
function recordCleanup(state, cause) {
|
|
137
|
+
// Observers and recording failures cannot replace the selected primary error.
|
|
138
|
+
try {
|
|
139
|
+
state.engine.captureCleanup(cause);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
/* Preserve the primary. */
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
state.engine.report({ code: "SPRITE_SHEET_BITMAP_FAILED", phase: "display-tree", severity: "error", cause });
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
/* Advanced context observers are observation only. */
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** A private failed Bitmap is retired once; caller-owned leases are never released. */
|
|
152
|
+
function retireFailedBitmap(state, bitmap, primary) {
|
|
153
|
+
if (bitmap === undefined)
|
|
154
|
+
return primary;
|
|
155
|
+
let cleanupFailed = false;
|
|
156
|
+
let cleanupCause;
|
|
157
|
+
try {
|
|
158
|
+
spriteSheetBitmapOperations.dispose(bitmap);
|
|
159
|
+
}
|
|
160
|
+
catch (cause) {
|
|
161
|
+
cleanupFailed = true;
|
|
162
|
+
cleanupCause = cause;
|
|
163
|
+
}
|
|
164
|
+
if (!cleanupFailed)
|
|
165
|
+
return primary;
|
|
166
|
+
recordCleanup(state, cleanupCause);
|
|
167
|
+
if (primary instanceof EgretError) {
|
|
168
|
+
return new EgretError(primary.code, {
|
|
169
|
+
cause: primary.cause,
|
|
170
|
+
cleanupErrors: [...primary.cleanupErrors, cleanupCause]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return new EgretError("SPRITE_SHEET_BITMAP_FAILED", { cause: primary, cleanupErrors: [cleanupCause] });
|
|
174
|
+
}
|
|
175
|
+
function createBitmap(receiver, name) {
|
|
176
|
+
const state = stateOf(receiver);
|
|
177
|
+
if (state.disposed)
|
|
178
|
+
throw new EgretError("SPRITE_SHEET_DISPOSED");
|
|
179
|
+
state.engine.assertOpen();
|
|
180
|
+
if (state.creatingBitmap)
|
|
181
|
+
throw new EgretError("SPRITE_SHEET_REENTRANT");
|
|
182
|
+
state.creatingBitmap = true;
|
|
183
|
+
let bitmap;
|
|
184
|
+
try {
|
|
185
|
+
const lease = state.lease;
|
|
186
|
+
assertCreationLive(state, lease);
|
|
187
|
+
const region = findRegion(state, name);
|
|
188
|
+
bitmap = bitmapOperation(() => spriteSheetBitmapOperations.construct(lease));
|
|
189
|
+
assertCreationLive(state, lease);
|
|
190
|
+
if (region.layout === undefined)
|
|
191
|
+
bitmapOperation(() => spriteSheetBitmapOperations.setCrop(bitmap, region));
|
|
192
|
+
else
|
|
193
|
+
bitmapOperation(() => applyBitmapAtlasFrame(bitmap, region));
|
|
194
|
+
assertCreationLive(state, lease);
|
|
195
|
+
// Return no cache or ownership claim: the caller owns the genuine Bitmap.
|
|
196
|
+
return bitmap;
|
|
197
|
+
}
|
|
198
|
+
catch (primary) {
|
|
199
|
+
throw retireFailedBitmap(state, bitmap, primary);
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
state.creatingBitmap = false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** Facade methods close over no factory input, lease or image. */
|
|
206
|
+
function createFacade() {
|
|
207
|
+
function receiverState(receiver) {
|
|
208
|
+
if (receiver !== sheet)
|
|
209
|
+
throw new EgretError("SPRITE_SHEET_INVALID");
|
|
210
|
+
return stateOf(receiver);
|
|
211
|
+
}
|
|
212
|
+
const sheet = Object.freeze({
|
|
213
|
+
get frameCount() {
|
|
214
|
+
return receiverState(this).names.length;
|
|
215
|
+
},
|
|
216
|
+
get names() {
|
|
217
|
+
return receiverState(this).names;
|
|
218
|
+
},
|
|
219
|
+
get atlasWidth() {
|
|
220
|
+
return receiverState(this).atlasWidth;
|
|
221
|
+
},
|
|
222
|
+
get atlasHeight() {
|
|
223
|
+
return receiverState(this).atlasHeight;
|
|
224
|
+
},
|
|
225
|
+
get isDisposed() {
|
|
226
|
+
return receiverState(this).disposed;
|
|
227
|
+
},
|
|
228
|
+
getRegion(name) {
|
|
229
|
+
return findRegion(receiverState(this), name);
|
|
230
|
+
},
|
|
231
|
+
createBitmap(name) {
|
|
232
|
+
receiverState(this);
|
|
233
|
+
return createBitmap(this, name);
|
|
234
|
+
},
|
|
235
|
+
dispose() {
|
|
236
|
+
const state = receiverState(this);
|
|
237
|
+
if (state.disposed)
|
|
238
|
+
return;
|
|
239
|
+
// Retire the borrow before any subsequent cleanup/reentry opportunity.
|
|
240
|
+
state.disposed = true;
|
|
241
|
+
state.lease = undefined;
|
|
242
|
+
state.image = undefined;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return sheet;
|
|
246
|
+
}
|
|
247
|
+
/** Build one exact-name table from a genuine full-image lease without acquiring another resource. */
|
|
248
|
+
export function createSpriteSheet(atlasLease, frames, profile) {
|
|
249
|
+
if (!isAssetLease(atlasLease))
|
|
250
|
+
throw new EgretError("SPRITE_SHEET_LEASE_INVALID");
|
|
251
|
+
const engine = engineOf(atlasLease);
|
|
252
|
+
const snapshot = readAtlas(engine, atlasLease);
|
|
253
|
+
const { image } = snapshot;
|
|
254
|
+
if (profile !== undefined && profile !== "trim-rotation-v1")
|
|
255
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
256
|
+
const revalidate = () => {
|
|
257
|
+
readAtlas(engine, atlasLease, image);
|
|
258
|
+
};
|
|
259
|
+
const staged = stageFrames(frames, revalidate, profile !== undefined);
|
|
260
|
+
const validated = [];
|
|
261
|
+
const seenNames = new Set();
|
|
262
|
+
let totalNameUnits = 0;
|
|
263
|
+
for (const frame of staged) {
|
|
264
|
+
if (!frame.name.present || !frame.x.present || !frame.y.present || !frame.width.present || !frame.height.present) {
|
|
265
|
+
throw new EgretError("SPRITE_SHEET_INPUT_INVALID");
|
|
266
|
+
}
|
|
267
|
+
const name = qualifyName(frame.name.value);
|
|
268
|
+
totalNameUnits += name.length;
|
|
269
|
+
if (totalNameUnits > 32768)
|
|
270
|
+
throw new EgretError("SPRITE_SHEET_LIMIT");
|
|
271
|
+
if (seenNames.has(name))
|
|
272
|
+
throw new EgretError("SPRITE_SHEET_NAME_INVALID");
|
|
273
|
+
const x = coordinate(frame.x.value, false);
|
|
274
|
+
const y = coordinate(frame.y.value, false);
|
|
275
|
+
const width = coordinate(frame.width.value, true);
|
|
276
|
+
const height = coordinate(frame.height.value, true);
|
|
277
|
+
const right = x + width, bottom = y + height;
|
|
278
|
+
if (!Number.isSafeInteger(right) || !Number.isSafeInteger(bottom) || right > image.width || bottom > image.height) {
|
|
279
|
+
throw new EgretError("SPRITE_SHEET_REGION_INVALID");
|
|
280
|
+
}
|
|
281
|
+
seenNames.add(name);
|
|
282
|
+
const layout = frame.layout === undefined
|
|
283
|
+
? undefined
|
|
284
|
+
: copyAtlasFrameLayout(frame.layout, width, height, kind => {
|
|
285
|
+
throw new EgretError(kind === "shape" ? "SPRITE_SHEET_INPUT_INVALID" : "SPRITE_SHEET_REGION_INVALID");
|
|
286
|
+
});
|
|
287
|
+
validated.push({ name, x, y, width, height, ...(layout === undefined ? {} : { layout }) });
|
|
288
|
+
}
|
|
289
|
+
// Allocate public-owned crops only after the complete staged table qualifies.
|
|
290
|
+
const names = [];
|
|
291
|
+
const regions = new Map();
|
|
292
|
+
for (const frame of validated) {
|
|
293
|
+
regions.set(frame.name, Object.freeze({
|
|
294
|
+
x: frame.x,
|
|
295
|
+
y: frame.y,
|
|
296
|
+
width: frame.width,
|
|
297
|
+
height: frame.height,
|
|
298
|
+
...(frame.layout === undefined ? {} : { layout: frame.layout })
|
|
299
|
+
}));
|
|
300
|
+
names.push(frame.name);
|
|
301
|
+
}
|
|
302
|
+
const state = {
|
|
303
|
+
engine,
|
|
304
|
+
names: Object.freeze(names),
|
|
305
|
+
regions,
|
|
306
|
+
atlasWidth: image.width,
|
|
307
|
+
atlasHeight: image.height,
|
|
308
|
+
lease: atlasLease,
|
|
309
|
+
image,
|
|
310
|
+
disposed: false,
|
|
311
|
+
creatingBitmap: false
|
|
312
|
+
};
|
|
313
|
+
const sheet = createFacade();
|
|
314
|
+
const binding = [sheet];
|
|
315
|
+
revalidate();
|
|
316
|
+
// All callback-capable work is complete before private state/affinity publication.
|
|
317
|
+
states.set(sheet, state);
|
|
318
|
+
commitBinding(binding, engine);
|
|
319
|
+
return sheet;
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=spriteSheet.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The sRGB transfer of each byte, decoded to linear light: the value of
|
|
3
|
+
// c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4 for c = byte / 255,
|
|
4
|
+
// written out as numbers. The power is not computed when a game runs, because JavaScript engines differ in its last
|
|
5
|
+
// bit, and a frame prepared from the same scene must hold the same numbers in every one of them.
|
|
6
|
+
// packages/engine/src/srgbBytes.ts and packages/engine/rendering/srgbBytes.ts hold the same table: the three sources may
|
|
7
|
+
// not import each other, and tests/srgb-byte-table.test.mjs requires them to be equal.
|
|
8
|
+
const TABLE = Object.freeze([
|
|
9
|
+
0, 0.0003035269835488375, 0.000607053967097675, 0.0009105809506465125, 0.00121410793419535, 0.0015176349177441874,
|
|
10
|
+
0.001821161901293025, 0.0021246888848418626, 0.0024282158683907, 0.0027317428519395373, 0.003035269835488375,
|
|
11
|
+
0.003346535763899161, 0.003676507324047436, 0.004024717018496307, 0.004391442037410293, 0.004776953480693729,
|
|
12
|
+
0.005181516702338386, 0.005605391624202723, 0.006048833022857054, 0.006512090792594475, 0.006995410187265387,
|
|
13
|
+
0.007499032043226175, 0.008023192985384994, 0.008568125618069307, 0.009134058702220787, 0.00972121732023785,
|
|
14
|
+
0.010329823029626936, 0.010960094006488246, 0.011612245179743885, 0.012286488356915872, 0.012983032342173012,
|
|
15
|
+
0.013702083047289686, 0.014443843596092545, 0.01520851442291271, 0.01599629336550963, 0.016807375752887384,
|
|
16
|
+
0.017641954488384078, 0.018500220128379697, 0.019382360956935723, 0.0202885630566524, 0.021219010376003555,
|
|
17
|
+
0.02217388479338738, 0.02315336617811041, 0.024157632448504756, 0.02518685962736163, 0.026241221894849898,
|
|
18
|
+
0.027320891639074894, 0.028426039504420793, 0.0295568344378088, 0.030713443732993635, 0.03189603307301153,
|
|
19
|
+
0.033104766570885055, 0.03433980680868217, 0.03560131487502034, 0.03688945040110004, 0.0382043715953465,
|
|
20
|
+
0.03954623527673284, 0.04091519690685319, 0.042311410620809675, 0.043735029256973465, 0.04518620438567554,
|
|
21
|
+
0.046665086336880095, 0.04817182422688942, 0.04970656598412723, 0.05126945837404324, 0.052860647023180246,
|
|
22
|
+
0.05448027644244237, 0.05612849004960009, 0.05780543019106723, 0.0595112381629812, 0.06124605423161761,
|
|
23
|
+
0.06301001765316767, 0.06480326669290577, 0.06662593864377289, 0.06847816984440017, 0.07036009569659588,
|
|
24
|
+
0.07227185068231748, 0.07421356838014963, 0.07618538148130785, 0.07818742180518633, 0.08021982031446832,
|
|
25
|
+
0.0822827071298148, 0.08437621154414882, 0.08650046203654976, 0.08865558628577294, 0.09084171118340768,
|
|
26
|
+
0.09305896284668745, 0.0953074666309647, 0.09758734714186246, 0.09989872824711389, 0.10224173308810132,
|
|
27
|
+
0.10461648409110419, 0.10702310297826761, 0.10946171077829933, 0.1119324278369056, 0.11443537382697373,
|
|
28
|
+
0.11697066775851084, 0.11953842798834562, 0.12213877222960187, 0.12477181756095049, 0.12743768043564743,
|
|
29
|
+
0.1301364766903643, 0.13286832155381798, 0.13563332965520566, 0.13843161503245183, 0.14126329114027164,
|
|
30
|
+
0.14412847085805777, 0.14702726649759498, 0.14995978981060856, 0.15292615199615017, 0.1559264637078274,
|
|
31
|
+
0.1589608350608804, 0.162029375639111, 0.1651321945016676, 0.16826940018969075, 0.1714411007328226,
|
|
32
|
+
0.17464740365558504, 0.17788841598362912, 0.18116424424986022, 0.184474994500441, 0.18782077230067787,
|
|
33
|
+
0.19120168274079138, 0.1946178304415758, 0.19806931955994886, 0.20155625379439707, 0.20507873639031693,
|
|
34
|
+
0.20863687014525575, 0.21223075741405523, 0.21586050011389926, 0.2195261997292692, 0.2232279573168085,
|
|
35
|
+
0.22696587351009836, 0.23074004852434915, 0.23455058216100522, 0.238397573812271, 0.24228112246555486,
|
|
36
|
+
0.24620132670783548, 0.25015828472995344, 0.25415209433082675, 0.2581828529215958, 0.26225065752969623,
|
|
37
|
+
0.26635560480286247, 0.2704977910130658, 0.27467731206038465, 0.2788942634768104, 0.2831487404299921,
|
|
38
|
+
0.2874408377269175, 0.29177064981753587, 0.2961382707983211, 0.3005437944157765, 0.3049873140698863,
|
|
39
|
+
0.30946892281750854, 0.31398871337571754, 0.31854677812509186, 0.32314320911295075, 0.3277780980565422,
|
|
40
|
+
0.33245153634617935, 0.33716361504833037, 0.3419144249086609, 0.3467040563550296, 0.35153259950043936,
|
|
41
|
+
0.3564001441459435, 0.3613067797835095, 0.3662525955988395, 0.3712376804741491, 0.3762621229909065,
|
|
42
|
+
0.38132601143253014, 0.386429433787049, 0.39157247774972326, 0.39675523072562685, 0.4019777798321958,
|
|
43
|
+
0.4072402119017367, 0.41254261348390375, 0.4178850708481375, 0.4232676699860717, 0.4286904966139066,
|
|
44
|
+
0.43415363617474895, 0.4396571738409188, 0.44520119451622786, 0.45078578283822346, 0.45641102318040466,
|
|
45
|
+
0.4620769996544071, 0.467783796112159, 0.47353149614800955, 0.4793201831008268, 0.4851499400560704,
|
|
46
|
+
0.4910208498478356, 0.4969329950608704, 0.5028864580325687, 0.5088813208549338, 0.5149176653765214,
|
|
47
|
+
0.5209955732043543, 0.5271151257058131, 0.5332764040105052, 0.5394794890121072, 0.5457244613701866,
|
|
48
|
+
0.5520114015120001, 0.5583403896342679, 0.5647115057049292, 0.5711248294648731, 0.5775804404296506,
|
|
49
|
+
0.5840784178911641, 0.5906188409193369, 0.5972017883637634, 0.6038273388553378, 0.6104955708078648,
|
|
50
|
+
0.6172065624196511, 0.6239603916750761, 0.6307571363461468, 0.6375968739940326, 0.6444796819705821,
|
|
51
|
+
0.6514056374198242, 0.6583748172794485, 0.665387298282272, 0.6724431569576875, 0.6795424696330938, 0.6866853124353135,
|
|
52
|
+
0.6938717612919899, 0.7011018919329731, 0.7083757798916868, 0.7156935005064807, 0.7230551289219693,
|
|
53
|
+
0.7304607400903537, 0.7379104087727308, 0.7454042095403874, 0.7529422167760779, 0.7605245046752924, 0.768151147247507,
|
|
54
|
+
0.7758222183174236, 0.7835377915261935, 0.7912979403326302, 0.799102738014409, 0.8069522576692516, 0.8148465722161012,
|
|
55
|
+
0.8227857543962835, 0.8307698767746546, 0.83879901174074, 0.846873231509858, 0.8549926081242338, 0.8631572134541023,
|
|
56
|
+
0.8713671191987972, 0.8796223968878317, 0.8879231178819663, 0.8962693533742664, 0.9046611743911496,
|
|
57
|
+
0.9130986517934192, 0.9215818562772946, 0.9301108583754237, 0.938685728457888, 0.9473065367331999, 0.9559733532492861,
|
|
58
|
+
0.9646862478944651, 0.9734452903984125, 0.9822505503331171, 0.9911020971138298, 1
|
|
59
|
+
]);
|
|
60
|
+
/** The linear-light value of an sRGB byte; only the low eight bits of `code` are read. */
|
|
61
|
+
export function decodeSRGBByte(code) {
|
|
62
|
+
return TABLE[code & 255];
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=srgbBytes.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CancellationSignal } from '@egret/contracts';
|
|
2
|
+
import { DisplayObject } from '../DisplayObject.js';
|
|
3
|
+
import { Scope } from '../Scope.js';
|
|
4
|
+
import type { EngineContext } from '../ownership.js';
|
|
5
|
+
import type { PreparedTextRaster, TextRasterRequestInput } from './types.js';
|
|
6
|
+
export interface TextFieldCachePort {
|
|
7
|
+
readonly context: EngineContext;
|
|
8
|
+
assertOpen(): void;
|
|
9
|
+
adopt(input: TextRasterRequestInput, revalidate: () => void): TextRasterRequestInput;
|
|
10
|
+
acquire(input: TextRasterRequestInput, signal: CancellationSignal): Promise<PreparedTextRaster>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createTextFieldLeaf(scope: Scope, cache: TextFieldCachePort): DisplayObject;
|
|
13
|
+
//# sourceMappingURL=TextField.d.ts.map
|