@egret/contracts 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 +22 -2
- package/README.zh-CN.md +23 -0
- package/dist/CancellationSignal.d.ts +12 -0
- package/dist/CancellationSignal.js +2 -0
- package/dist/Diagnostic.d.ts +11 -0
- package/dist/Diagnostic.js +2 -0
- package/dist/Disposable.d.ts +11 -0
- package/dist/Disposable.js +2 -0
- package/dist/HostAdapter.d.ts +17 -0
- package/dist/HostAdapter.js +2 -0
- package/dist/ImageData2D.d.ts +43 -0
- package/dist/ImageData2D.js +129 -0
- package/dist/Point2D.d.ts +6 -0
- package/dist/Point2D.js +2 -0
- package/dist/ProjectFormat.generated.d.ts +129 -0
- package/dist/ProjectFormat.generated.js +4 -0
- package/dist/RenderFrame2D.d.ts +20 -0
- package/dist/RenderFrame2D.js +2 -0
- package/dist/ResourceManifest.d.ts +75 -0
- package/dist/ResourceManifest.js +2 -0
- package/dist/SharedGeometry2D.d.ts +27 -0
- package/dist/SharedGeometry2D.js +176 -0
- package/dist/SharedMaterial2D.d.ts +39 -0
- package/dist/SharedMaterial2D.js +179 -0
- package/dist/SharedRenderFrame2D.d.ts +107 -0
- package/dist/SharedRenderFrame2D.js +4 -0
- package/dist/TextureViewRegion2D.d.ts +20 -0
- package/dist/TextureViewRegion2D.js +2 -0
- package/dist/TexturedGeometry2D.d.ts +25 -0
- package/dist/TexturedGeometry2D.js +165 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +6 -0
- package/dist/resources/fontArtifact.d.ts +7 -0
- package/dist/resources/fontArtifact.js +37 -0
- package/dist/resources/index.d.ts +4 -0
- package/dist/resources/index.js +4 -0
- package/dist/resources/manifestAdmission.d.ts +10 -0
- package/dist/resources/manifestAdmission.js +457 -0
- package/dist/resources/sha256.d.ts +3 -0
- package/dist/resources/sha256.js +111 -0
- package/package.json +25 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
declare const projectIdBrand: unique symbol;
|
|
2
|
+
declare const entityIdBrand: unique symbol;
|
|
3
|
+
declare const fileIdBrand: unique symbol;
|
|
4
|
+
declare const transactionIdBrand: unique symbol;
|
|
5
|
+
export type ProjectId = string & {
|
|
6
|
+
readonly [projectIdBrand]: true;
|
|
7
|
+
};
|
|
8
|
+
export type EntityId = string & {
|
|
9
|
+
readonly [entityIdBrand]: true;
|
|
10
|
+
};
|
|
11
|
+
export type FileId = string & {
|
|
12
|
+
readonly [fileIdBrand]: true;
|
|
13
|
+
};
|
|
14
|
+
export type TransactionId = string & {
|
|
15
|
+
readonly [transactionIdBrand]: true;
|
|
16
|
+
};
|
|
17
|
+
export type ProjectRevision = number;
|
|
18
|
+
export type Sha256 = string;
|
|
19
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
20
|
+
readonly [key: string]: JsonValue;
|
|
21
|
+
};
|
|
22
|
+
export type JsonObject = {
|
|
23
|
+
readonly [key: string]: JsonValue;
|
|
24
|
+
};
|
|
25
|
+
export interface ProjectVersionPins {
|
|
26
|
+
readonly engineVersion: string;
|
|
27
|
+
readonly resourceFormatVersion: string;
|
|
28
|
+
readonly toolProtocolVersion: "1.0";
|
|
29
|
+
}
|
|
30
|
+
export type ProjectReference = {
|
|
31
|
+
readonly slot: string;
|
|
32
|
+
readonly target: "entity";
|
|
33
|
+
readonly id: EntityId;
|
|
34
|
+
readonly expectedKind: string;
|
|
35
|
+
} | {
|
|
36
|
+
readonly slot: string;
|
|
37
|
+
readonly target: "file";
|
|
38
|
+
readonly id: FileId;
|
|
39
|
+
readonly expectedRole: ProjectFileRole;
|
|
40
|
+
};
|
|
41
|
+
export interface ProjectEntity {
|
|
42
|
+
readonly id: EntityId;
|
|
43
|
+
readonly kind: string;
|
|
44
|
+
readonly dataSchemaVersion: string;
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly data: JsonObject;
|
|
47
|
+
readonly references: readonly ProjectReference[];
|
|
48
|
+
}
|
|
49
|
+
export type ProjectFileRole = "source" | "asset" | "configuration" | "legacy-original" | "other";
|
|
50
|
+
export interface ProjectFile {
|
|
51
|
+
readonly id: FileId;
|
|
52
|
+
readonly path: string;
|
|
53
|
+
readonly role: ProjectFileRole;
|
|
54
|
+
readonly mediaType: string;
|
|
55
|
+
readonly sha256: Sha256;
|
|
56
|
+
readonly byteLength: number;
|
|
57
|
+
}
|
|
58
|
+
export interface ProjectSnapshot {
|
|
59
|
+
readonly projectSchemaVersion: "1.0";
|
|
60
|
+
readonly projectId: ProjectId;
|
|
61
|
+
readonly revision: ProjectRevision;
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly versions: ProjectVersionPins;
|
|
64
|
+
readonly roots: readonly EntityId[];
|
|
65
|
+
readonly entities: readonly ProjectEntity[];
|
|
66
|
+
readonly files: readonly ProjectFile[];
|
|
67
|
+
readonly retiredEntityIds: readonly EntityId[];
|
|
68
|
+
readonly retiredFileIds: readonly FileId[];
|
|
69
|
+
}
|
|
70
|
+
export interface ProjectTransactionSource {
|
|
71
|
+
readonly actorId: string;
|
|
72
|
+
readonly actorKind: "creator" | "agent" | "legacy-converter" | "tool";
|
|
73
|
+
readonly toolId: string;
|
|
74
|
+
readonly toolVersion: string;
|
|
75
|
+
readonly intent: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ProjectTransactionScope {
|
|
78
|
+
readonly entityIds: readonly EntityId[];
|
|
79
|
+
readonly fileIds: readonly FileId[];
|
|
80
|
+
readonly metadata: boolean;
|
|
81
|
+
readonly roots: boolean;
|
|
82
|
+
}
|
|
83
|
+
export type ProjectOperation = {
|
|
84
|
+
readonly op: "putEntity";
|
|
85
|
+
readonly entity: ProjectEntity;
|
|
86
|
+
} | {
|
|
87
|
+
readonly op: "removeEntity";
|
|
88
|
+
readonly id: EntityId;
|
|
89
|
+
} | {
|
|
90
|
+
readonly op: "putFile";
|
|
91
|
+
readonly file: ProjectFile;
|
|
92
|
+
} | {
|
|
93
|
+
readonly op: "removeFile";
|
|
94
|
+
readonly id: FileId;
|
|
95
|
+
} | {
|
|
96
|
+
readonly op: "setMetadata";
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly versions: ProjectVersionPins;
|
|
99
|
+
} | {
|
|
100
|
+
readonly op: "setRoots";
|
|
101
|
+
readonly roots: readonly EntityId[];
|
|
102
|
+
};
|
|
103
|
+
export interface ProjectEditTransaction {
|
|
104
|
+
readonly command: "edit";
|
|
105
|
+
readonly toolProtocolVersion: "1.0";
|
|
106
|
+
readonly projectId: ProjectId;
|
|
107
|
+
readonly transactionId: TransactionId;
|
|
108
|
+
readonly baseRevision: ProjectRevision;
|
|
109
|
+
readonly source: ProjectTransactionSource;
|
|
110
|
+
readonly scope: ProjectTransactionScope;
|
|
111
|
+
readonly operations: readonly ProjectOperation[];
|
|
112
|
+
}
|
|
113
|
+
export interface ProjectRestoreTransaction {
|
|
114
|
+
readonly command: "restore";
|
|
115
|
+
readonly toolProtocolVersion: "1.0";
|
|
116
|
+
readonly projectId: ProjectId;
|
|
117
|
+
readonly transactionId: TransactionId;
|
|
118
|
+
readonly baseRevision: ProjectRevision;
|
|
119
|
+
readonly source: ProjectTransactionSource;
|
|
120
|
+
readonly targetRevision: ProjectRevision;
|
|
121
|
+
}
|
|
122
|
+
export type ProjectTransaction = ProjectEditTransaction | ProjectRestoreTransaction;
|
|
123
|
+
export interface ProjectHistory {
|
|
124
|
+
readonly historySchemaVersion: "1.0";
|
|
125
|
+
readonly baseline: ProjectSnapshot;
|
|
126
|
+
readonly transactions: readonly ProjectTransaction[];
|
|
127
|
+
}
|
|
128
|
+
export {};
|
|
129
|
+
//# sourceMappingURL=ProjectFormat.generated.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Immutable logical-coordinate values shared by CPU capture and render hosts. */
|
|
2
|
+
export interface Matrix2D {
|
|
3
|
+
readonly a: number;
|
|
4
|
+
readonly b: number;
|
|
5
|
+
readonly c: number;
|
|
6
|
+
readonly d: number;
|
|
7
|
+
readonly tx: number;
|
|
8
|
+
readonly ty: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Rectangle2D {
|
|
11
|
+
readonly x: number;
|
|
12
|
+
readonly y: number;
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ClipRectangle2D {
|
|
17
|
+
readonly matrix: Matrix2D;
|
|
18
|
+
readonly rect: Rectangle2D;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=RenderFrame2D.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { EntityId, JsonObject, ProjectFile, ProjectId, ProjectVersionPins } from './ProjectFormat.generated.js';
|
|
2
|
+
declare const admittedManifestBrand: unique symbol;
|
|
3
|
+
export interface ResourceBuildSourceEntry {
|
|
4
|
+
readonly id: EntityId;
|
|
5
|
+
readonly resourceKind: string;
|
|
6
|
+
readonly source: ProjectFile;
|
|
7
|
+
readonly importer: {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly version: string;
|
|
10
|
+
};
|
|
11
|
+
readonly settings: JsonObject;
|
|
12
|
+
readonly artifactFormatVersion: string;
|
|
13
|
+
readonly targetProfile: string;
|
|
14
|
+
readonly dependencies: readonly EntityId[];
|
|
15
|
+
readonly provenance: JsonObject;
|
|
16
|
+
}
|
|
17
|
+
export interface ResourceBuildEntry extends ResourceBuildSourceEntry {
|
|
18
|
+
readonly artifact: ProjectFile;
|
|
19
|
+
}
|
|
20
|
+
export interface ResourceBuildPlanDescription {
|
|
21
|
+
readonly format: 'egret.resource-build-plan/1';
|
|
22
|
+
readonly projectId: ProjectId;
|
|
23
|
+
readonly targetProfile: string;
|
|
24
|
+
readonly versions: ProjectVersionPins;
|
|
25
|
+
readonly entries: readonly ResourceBuildSourceEntry[];
|
|
26
|
+
}
|
|
27
|
+
export interface ResourceBuildKeyEntry extends ResourceBuildSourceEntry {
|
|
28
|
+
readonly buildKey: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ResourceBuildKeyPlan {
|
|
31
|
+
readonly format: 'egret.resource-build-keys/1';
|
|
32
|
+
readonly projectId: ProjectId;
|
|
33
|
+
readonly targetProfile: string;
|
|
34
|
+
readonly versions: ProjectVersionPins;
|
|
35
|
+
readonly entries: readonly ResourceBuildKeyEntry[];
|
|
36
|
+
}
|
|
37
|
+
export interface ResourceBuildDescription {
|
|
38
|
+
readonly format: 'egret.resource-build/1';
|
|
39
|
+
readonly projectId: ProjectId;
|
|
40
|
+
readonly targetProfile: string;
|
|
41
|
+
readonly versions: ProjectVersionPins;
|
|
42
|
+
readonly entries: readonly ResourceBuildEntry[];
|
|
43
|
+
}
|
|
44
|
+
export interface ResourceManifestEntry extends ResourceBuildEntry {
|
|
45
|
+
readonly buildKey: string;
|
|
46
|
+
readonly runtimeIdentity: string;
|
|
47
|
+
}
|
|
48
|
+
export interface AdmittedResourceManifest {
|
|
49
|
+
readonly [admittedManifestBrand]: true;
|
|
50
|
+
readonly format: 'egret.resource-manifest/1';
|
|
51
|
+
readonly projectId: ProjectId;
|
|
52
|
+
readonly targetProfile: string;
|
|
53
|
+
readonly versions: ProjectVersionPins;
|
|
54
|
+
readonly entries: readonly ResourceManifestEntry[];
|
|
55
|
+
}
|
|
56
|
+
export type ResourceManifestDiagnosticCode = 'RESOURCE_INPUT_INVALID' | 'RESOURCE_LIMIT_EXCEEDED' | 'RESOURCE_FORMAT_UNSUPPORTED' | 'RESOURCE_DEPENDENCY_INVALID' | 'RESOURCE_ID_DUPLICATE' | 'RESOURCE_KEY_MISMATCH' | 'RESOURCE_FILE_MISMATCH' | 'RESOURCE_PATH_INVALID';
|
|
57
|
+
export interface ResourceManifestDiagnostic {
|
|
58
|
+
readonly code: ResourceManifestDiagnosticCode;
|
|
59
|
+
readonly pointer: string;
|
|
60
|
+
readonly message: string;
|
|
61
|
+
}
|
|
62
|
+
export type ResourceManifestResult<T> = {
|
|
63
|
+
readonly ok: true;
|
|
64
|
+
readonly value: T;
|
|
65
|
+
readonly diagnostics: readonly [];
|
|
66
|
+
} | {
|
|
67
|
+
readonly ok: false;
|
|
68
|
+
readonly diagnostics: readonly [ResourceManifestDiagnostic];
|
|
69
|
+
};
|
|
70
|
+
export interface ResourceManifestIdentityInputs {
|
|
71
|
+
readonly build: string;
|
|
72
|
+
readonly runtime: string;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=ResourceManifest.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const sharedGeometry2DBrand: unique symbol;
|
|
2
|
+
export type SharedFloatArray2D = Float32Array<ArrayBuffer> | Float64Array<ArrayBuffer>;
|
|
3
|
+
export type SharedIndexArray2D = Uint16Array<ArrayBuffer> | Uint32Array<ArrayBuffer>;
|
|
4
|
+
export interface SharedGeometryInput2D {
|
|
5
|
+
readonly positions: SharedFloatArray2D;
|
|
6
|
+
readonly uvs: SharedFloatArray2D;
|
|
7
|
+
readonly lightColors: SharedFloatArray2D;
|
|
8
|
+
readonly darkColors: SharedFloatArray2D;
|
|
9
|
+
readonly indices: SharedIndexArray2D;
|
|
10
|
+
}
|
|
11
|
+
/** Immutable CPU geometry identity; the brand grants no asset or GPU authority. */
|
|
12
|
+
export interface SharedGeometry2D {
|
|
13
|
+
readonly [sharedGeometry2DBrand]: true;
|
|
14
|
+
readonly vertexCount: number;
|
|
15
|
+
readonly indexCount: number;
|
|
16
|
+
readonly triangleCount: number;
|
|
17
|
+
readonly logicalByteLength: number;
|
|
18
|
+
readonly positions: readonly number[];
|
|
19
|
+
readonly uvs: readonly number[];
|
|
20
|
+
readonly lightColors: readonly number[];
|
|
21
|
+
readonly darkColors: readonly number[];
|
|
22
|
+
readonly indices: readonly number[];
|
|
23
|
+
}
|
|
24
|
+
export declare function createSharedGeometry2D(input: SharedGeometryInput2D): SharedGeometry2D;
|
|
25
|
+
export declare function isSharedGeometry2D(value: unknown): value is SharedGeometry2D;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=SharedGeometry2D.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Capture normal-realm intrinsics before descriptor callbacks can replace them.
|
|
2
|
+
// Admission and copying do not read instance properties, iterators or species.
|
|
3
|
+
const Floats32 = Float32Array;
|
|
4
|
+
const Floats64 = Float64Array;
|
|
5
|
+
const Indices16 = Uint16Array;
|
|
6
|
+
const Indices32 = Uint32Array;
|
|
7
|
+
const Bytes = Uint8Array;
|
|
8
|
+
const Numbers = Array;
|
|
9
|
+
const apply = Reflect.apply;
|
|
10
|
+
const freeze = Object.freeze;
|
|
11
|
+
const setPrototypeOf = Object.setPrototypeOf;
|
|
12
|
+
const arrayPrototype = Numbers.prototype;
|
|
13
|
+
const TypeFault = TypeError;
|
|
14
|
+
const RangeFault = RangeError;
|
|
15
|
+
const finite = Number.isFinite;
|
|
16
|
+
const integer = Number.isInteger;
|
|
17
|
+
const safeInteger = Number.isSafeInteger;
|
|
18
|
+
const fround = Math.fround;
|
|
19
|
+
const abs = Math.abs;
|
|
20
|
+
const typedArrayPrototype = Object.getPrototypeOf(Bytes.prototype);
|
|
21
|
+
const tagGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
|
|
22
|
+
const bufferGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'buffer').get;
|
|
23
|
+
const offsetGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'byteOffset').get;
|
|
24
|
+
const lengthGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'byteLength').get;
|
|
25
|
+
const bufferLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get;
|
|
26
|
+
const resizableGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable')?.get;
|
|
27
|
+
const detachedGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached')?.get;
|
|
28
|
+
const setElements = typedArrayPrototype.set;
|
|
29
|
+
const weakHas = WeakMap.prototype.has;
|
|
30
|
+
const weakSet = WeakMap.prototype.set;
|
|
31
|
+
const owned = new WeakMap();
|
|
32
|
+
function read(source, key) {
|
|
33
|
+
try {
|
|
34
|
+
return source[key];
|
|
35
|
+
}
|
|
36
|
+
catch (cause) {
|
|
37
|
+
throw new TypeFault('Shared geometry descriptor read failed', { cause });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function floatBrand(value) {
|
|
41
|
+
const tag = apply(tagGetter, value, []);
|
|
42
|
+
if (tag !== 'Float32Array' && tag !== 'Float64Array')
|
|
43
|
+
throw new TypeFault('Shared geometry array brand is unsupported');
|
|
44
|
+
return tag;
|
|
45
|
+
}
|
|
46
|
+
function indexBrand(value) {
|
|
47
|
+
const tag = apply(tagGetter, value, []);
|
|
48
|
+
if (tag !== 'Uint16Array' && tag !== 'Uint32Array')
|
|
49
|
+
throw new TypeFault('Shared geometry array brand is unsupported');
|
|
50
|
+
return tag;
|
|
51
|
+
}
|
|
52
|
+
function elementLength(value, tag) {
|
|
53
|
+
const backing = apply(bufferGetter, value, []);
|
|
54
|
+
// This captured getter rejects SharedArrayBuffer, including cross realm.
|
|
55
|
+
// Native intrinsic faults escape intact rather than becoming policy errors.
|
|
56
|
+
apply(bufferLengthGetter, backing, []);
|
|
57
|
+
if (resizableGetter && apply(resizableGetter, backing, []))
|
|
58
|
+
throw new TypeFault('Shared geometry backing is unsupported');
|
|
59
|
+
if (detachedGetter) {
|
|
60
|
+
if (apply(detachedGetter, backing, []))
|
|
61
|
+
throw new TypeFault('Shared geometry backing is unsupported');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Reuse the established zero-length attachment check for older realms.
|
|
65
|
+
new Bytes(backing, 0, 0);
|
|
66
|
+
}
|
|
67
|
+
apply(offsetGetter, value, []);
|
|
68
|
+
const byteLength = apply(lengthGetter, value, []);
|
|
69
|
+
const elementBytes = tag === 'Float64Array' ? 8 : tag === 'Uint16Array' ? 2 : 4;
|
|
70
|
+
return byteLength / elementBytes;
|
|
71
|
+
}
|
|
72
|
+
function copyPayload(source, tag, length) {
|
|
73
|
+
const copy = tag === 'Float32Array'
|
|
74
|
+
? new Floats32(length)
|
|
75
|
+
: tag === 'Float64Array'
|
|
76
|
+
? new Floats64(length)
|
|
77
|
+
: tag === 'Uint16Array'
|
|
78
|
+
? new Indices16(length)
|
|
79
|
+
: new Indices32(length);
|
|
80
|
+
// Native allocation/copy failures escape. TypedArray set reads only the
|
|
81
|
+
// intrinsic used range and cannot invoke the caller's iterator or species.
|
|
82
|
+
apply(setElements, copy, [source]);
|
|
83
|
+
return copy;
|
|
84
|
+
}
|
|
85
|
+
function canonical(source, length, kind, vertexCount) {
|
|
86
|
+
// Fill private own indices without inherited setters, then expose a normal frozen array.
|
|
87
|
+
const output = [];
|
|
88
|
+
setPrototypeOf(output, null);
|
|
89
|
+
for (let index = 0; index < length; index++) {
|
|
90
|
+
const value = source[index];
|
|
91
|
+
if (!finite(value) ||
|
|
92
|
+
(kind === 'unit' && (value < 0 || value > 1)) ||
|
|
93
|
+
(kind === 'index' && (!integer(value) || value < 0 || value >= vertexCount))) {
|
|
94
|
+
throw new RangeFault('Shared geometry numeric range is invalid');
|
|
95
|
+
}
|
|
96
|
+
// New floating payloads are f32-roundtrip Numbers. This is a declared
|
|
97
|
+
// canonical input representation, not a GPU interpolation error bound.
|
|
98
|
+
const rounded = kind === 'index' ? value : fround(value);
|
|
99
|
+
if (!finite(rounded) || (kind === 'uv' && abs(rounded) > 1048576)) {
|
|
100
|
+
throw new RangeFault('Shared geometry numeric range is invalid');
|
|
101
|
+
}
|
|
102
|
+
// Equality with zero converts both signed zeros to positive zero.
|
|
103
|
+
output[index] = rounded === 0 ? 0 : rounded;
|
|
104
|
+
}
|
|
105
|
+
setPrototypeOf(output, arrayPrototype);
|
|
106
|
+
return freeze(output);
|
|
107
|
+
}
|
|
108
|
+
export function createSharedGeometry2D(input) {
|
|
109
|
+
if (typeof input !== 'object' || input === null)
|
|
110
|
+
throw new TypeFault('Shared geometry descriptor must be an object');
|
|
111
|
+
// G1: finish all successful ordered reads before examining any field.
|
|
112
|
+
// Local staging makes descriptor reentry independent of this invocation.
|
|
113
|
+
const positionsInput = read(input, 'positions');
|
|
114
|
+
const uvsInput = read(input, 'uvs');
|
|
115
|
+
const lightColorsInput = read(input, 'lightColors');
|
|
116
|
+
const darkColorsInput = read(input, 'darkColors');
|
|
117
|
+
const indicesInput = read(input, 'indices');
|
|
118
|
+
// G2 must finish for every field before G3 touches the first backing.
|
|
119
|
+
const positionsTag = floatBrand(positionsInput);
|
|
120
|
+
const uvsTag = floatBrand(uvsInput);
|
|
121
|
+
const lightColorsTag = floatBrand(lightColorsInput);
|
|
122
|
+
const darkColorsTag = floatBrand(darkColorsInput);
|
|
123
|
+
const indicesTag = indexBrand(indicesInput);
|
|
124
|
+
const positionsLength = elementLength(positionsInput, positionsTag);
|
|
125
|
+
const uvsLength = elementLength(uvsInput, uvsTag);
|
|
126
|
+
const lightColorsLength = elementLength(lightColorsInput, lightColorsTag);
|
|
127
|
+
const darkColorsLength = elementLength(darkColorsInput, darkColorsTag);
|
|
128
|
+
const indicesLength = elementLength(indicesInput, indicesTag);
|
|
129
|
+
const vertexCount = positionsLength / 2;
|
|
130
|
+
const indexCount = indicesLength;
|
|
131
|
+
// G4: shape outranks capacity; both precede copies and canonical arrays.
|
|
132
|
+
if (!safeInteger(vertexCount) ||
|
|
133
|
+
!safeInteger(indexCount) ||
|
|
134
|
+
uvsLength !== positionsLength ||
|
|
135
|
+
lightColorsLength !== 4 * vertexCount ||
|
|
136
|
+
darkColorsLength !== 3 * vertexCount ||
|
|
137
|
+
!((vertexCount === 0 && indexCount === 0) || (vertexCount >= 3 && indexCount >= 3 && indexCount % 3 === 0))) {
|
|
138
|
+
throw new RangeFault('Shared geometry array shape is invalid');
|
|
139
|
+
}
|
|
140
|
+
const logicalByteLength = 88 * vertexCount + 4 * indexCount;
|
|
141
|
+
if (vertexCount > 65536 || indexCount > 196608 || !safeInteger(logicalByteLength) || logicalByteLength > 4980736) {
|
|
142
|
+
throw new RangeFault('Shared geometry capacity exceeded');
|
|
143
|
+
}
|
|
144
|
+
// G5 capacity above precedes all allocations below. G6 completes all five
|
|
145
|
+
// native copies before G7 examines any copied component.
|
|
146
|
+
const positionsCopy = copyPayload(positionsInput, positionsTag, positionsLength);
|
|
147
|
+
const uvsCopy = copyPayload(uvsInput, uvsTag, uvsLength);
|
|
148
|
+
const lightColorsCopy = copyPayload(lightColorsInput, lightColorsTag, lightColorsLength);
|
|
149
|
+
const darkColorsCopy = copyPayload(darkColorsInput, darkColorsTag, darkColorsLength);
|
|
150
|
+
const indicesCopy = copyPayload(indicesInput, indicesTag, indicesLength);
|
|
151
|
+
const positions = canonical(positionsCopy, positionsLength, 'position', vertexCount);
|
|
152
|
+
const uvs = canonical(uvsCopy, uvsLength, 'uv', vertexCount);
|
|
153
|
+
const lightColors = canonical(lightColorsCopy, lightColorsLength, 'unit', vertexCount);
|
|
154
|
+
const darkColors = canonical(darkColorsCopy, darkColorsLength, 'unit', vertexCount);
|
|
155
|
+
const indices = canonical(indicesCopy, indicesLength, 'index', vertexCount);
|
|
156
|
+
// Logical accounting describes canonical payload units, not physical heap
|
|
157
|
+
// usage or an allocation guarantee. Only the completed frozen value is owned.
|
|
158
|
+
const geometry = freeze({
|
|
159
|
+
vertexCount,
|
|
160
|
+
indexCount,
|
|
161
|
+
triangleCount: indexCount / 3,
|
|
162
|
+
logicalByteLength,
|
|
163
|
+
positions,
|
|
164
|
+
uvs,
|
|
165
|
+
lightColors,
|
|
166
|
+
darkColors,
|
|
167
|
+
indices
|
|
168
|
+
});
|
|
169
|
+
apply(weakSet, owned, [geometry, true]);
|
|
170
|
+
return geometry;
|
|
171
|
+
}
|
|
172
|
+
export function isSharedGeometry2D(value) {
|
|
173
|
+
// WeakMap identity performs no property read, even on revoked Proxies.
|
|
174
|
+
return typeof value === 'object' && value !== null && apply(weakHas, owned, [value]);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=SharedGeometry2D.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare const sharedMaterial2DBrand: unique symbol;
|
|
2
|
+
type Blend = 'normal' | 'add-accumulate' | 'add-preserve' | 'multiply-factor' | 'screen' | 'erase';
|
|
3
|
+
type Domain = 'page' | 'region';
|
|
4
|
+
type Filter = 'nearest' | 'linear';
|
|
5
|
+
type Address = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
6
|
+
type Isolation = 'bounded' | 'strict';
|
|
7
|
+
export interface SharedMaterialInput2D {
|
|
8
|
+
readonly light?: readonly number[] | undefined;
|
|
9
|
+
readonly dark?: readonly number[] | undefined;
|
|
10
|
+
readonly blend?: Blend | undefined;
|
|
11
|
+
readonly samplingDomain?: Domain | undefined;
|
|
12
|
+
readonly filter?: Filter | undefined;
|
|
13
|
+
readonly addressU?: Address | undefined;
|
|
14
|
+
readonly addressV?: Address | undefined;
|
|
15
|
+
readonly regionIsolation?: Isolation | undefined;
|
|
16
|
+
readonly mipLevel?: number | undefined;
|
|
17
|
+
readonly minFilter?: Filter | undefined;
|
|
18
|
+
readonly magFilter?: Filter | undefined;
|
|
19
|
+
readonly maxAnisotropy?: number | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface SharedMaterial2D {
|
|
22
|
+
readonly [sharedMaterial2DBrand]: true;
|
|
23
|
+
readonly light: readonly [number, number, number, number];
|
|
24
|
+
readonly dark: readonly [number, number, number];
|
|
25
|
+
readonly blend: Blend;
|
|
26
|
+
readonly samplingDomain: Domain;
|
|
27
|
+
readonly filter: Filter;
|
|
28
|
+
readonly addressU: Address;
|
|
29
|
+
readonly addressV: Address;
|
|
30
|
+
readonly regionIsolation: Isolation;
|
|
31
|
+
readonly mipLevel: 0;
|
|
32
|
+
readonly minFilter: Filter;
|
|
33
|
+
readonly magFilter: Filter;
|
|
34
|
+
readonly maxAnisotropy: 1;
|
|
35
|
+
}
|
|
36
|
+
export declare function createSharedMaterial2D(input: SharedMaterialInput2D): SharedMaterial2D;
|
|
37
|
+
export declare function isSharedMaterial2D(value: unknown): value is SharedMaterial2D;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=SharedMaterial2D.d.ts.map
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// All operations used after an external descriptor read are captured once.
|
|
2
|
+
// Indexed copying never consults caller iterators, species or inherited slots.
|
|
3
|
+
const Numbers = Array;
|
|
4
|
+
const isArray = Array.isArray;
|
|
5
|
+
const own = Object.prototype.hasOwnProperty;
|
|
6
|
+
const defineProperty = Object.defineProperty;
|
|
7
|
+
const freeze = Object.freeze;
|
|
8
|
+
const apply = Reflect.apply;
|
|
9
|
+
const finite = Number.isFinite;
|
|
10
|
+
const safeInteger = Number.isSafeInteger;
|
|
11
|
+
const fround = Math.fround;
|
|
12
|
+
const TypeFault = TypeError;
|
|
13
|
+
const RangeFault = RangeError;
|
|
14
|
+
const weakHas = WeakMap.prototype.has;
|
|
15
|
+
const weakSet = WeakMap.prototype.set;
|
|
16
|
+
const owned = new WeakMap();
|
|
17
|
+
const missing = Symbol('egret.sharedMaterialMissingSlot');
|
|
18
|
+
function read(source, key) {
|
|
19
|
+
try {
|
|
20
|
+
return source[key];
|
|
21
|
+
}
|
|
22
|
+
catch (cause) {
|
|
23
|
+
throw new TypeFault('Shared material descriptor read failed', { cause });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function tupleBrand(value) {
|
|
27
|
+
let array;
|
|
28
|
+
try {
|
|
29
|
+
array = isArray(value);
|
|
30
|
+
}
|
|
31
|
+
catch (cause) {
|
|
32
|
+
throw new TypeFault('Shared material descriptor read failed', { cause });
|
|
33
|
+
}
|
|
34
|
+
if (!array)
|
|
35
|
+
throw new TypeFault('Shared material color tuple must be an Array');
|
|
36
|
+
}
|
|
37
|
+
function readSlot(source, index) {
|
|
38
|
+
try {
|
|
39
|
+
return apply(own, source, [index]) ? source[index] : missing;
|
|
40
|
+
}
|
|
41
|
+
catch (cause) {
|
|
42
|
+
throw new TypeFault('Shared material descriptor read failed', { cause });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function put(target, index, value) {
|
|
46
|
+
// Null-prototype descriptors exclude inherited get/set members, and defining
|
|
47
|
+
// own elements bypasses any indexed setter on the Array prototype.
|
|
48
|
+
const descriptor = { __proto__: null, value, writable: true, enumerable: true, configurable: true };
|
|
49
|
+
defineProperty(target, index, descriptor);
|
|
50
|
+
}
|
|
51
|
+
function color(source, length) {
|
|
52
|
+
const result = new Numbers(length);
|
|
53
|
+
for (let index = 0; index < length; index++) {
|
|
54
|
+
const value = source[index];
|
|
55
|
+
if (typeof value !== 'number' || !finite(value) || value < 0 || value > 1) {
|
|
56
|
+
throw new RangeFault('Shared material numeric range is invalid');
|
|
57
|
+
}
|
|
58
|
+
const rounded = fround(value);
|
|
59
|
+
put(result, index, rounded === 0 ? 0 : rounded);
|
|
60
|
+
}
|
|
61
|
+
return freeze(result);
|
|
62
|
+
}
|
|
63
|
+
function filter(value) {
|
|
64
|
+
if (value !== 'nearest' && value !== 'linear')
|
|
65
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
function address(value) {
|
|
69
|
+
if (value !== 'clamp-to-edge' && value !== 'repeat' && value !== 'mirror-repeat') {
|
|
70
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
export function createSharedMaterial2D(input) {
|
|
75
|
+
if (typeof input !== 'object' || input === null || isArray(input)) {
|
|
76
|
+
throw new TypeFault('Shared material descriptor must be a record');
|
|
77
|
+
}
|
|
78
|
+
// Complete the twelve top-level reads before examining either tuple.
|
|
79
|
+
const lightInput = read(input, 'light');
|
|
80
|
+
const darkInput = read(input, 'dark');
|
|
81
|
+
const blendInput = read(input, 'blend');
|
|
82
|
+
const domainInput = read(input, 'samplingDomain');
|
|
83
|
+
const filterInput = read(input, 'filter');
|
|
84
|
+
const addressUInput = read(input, 'addressU');
|
|
85
|
+
const addressVInput = read(input, 'addressV');
|
|
86
|
+
const isolationInput = read(input, 'regionIsolation');
|
|
87
|
+
const mipInput = read(input, 'mipLevel');
|
|
88
|
+
const minInput = read(input, 'minFilter');
|
|
89
|
+
const magInput = read(input, 'magFilter');
|
|
90
|
+
const anisotropyInput = read(input, 'maxAnisotropy');
|
|
91
|
+
if (lightInput !== undefined)
|
|
92
|
+
tupleBrand(lightInput);
|
|
93
|
+
if (darkInput !== undefined)
|
|
94
|
+
tupleBrand(darkInput);
|
|
95
|
+
const lightLength = lightInput === undefined ? 4 : read(lightInput, 'length');
|
|
96
|
+
const darkLength = darkInput === undefined ? 3 : read(darkInput, 'length');
|
|
97
|
+
if (lightLength !== 4 || darkLength !== 3)
|
|
98
|
+
throw new RangeFault('Shared material color tuple shape is invalid');
|
|
99
|
+
const lightValues = new Numbers(4);
|
|
100
|
+
const darkValues = new Numbers(3);
|
|
101
|
+
let hole = false;
|
|
102
|
+
for (let index = 0; index < 4; index++) {
|
|
103
|
+
const value = lightInput === undefined ? 1 : readSlot(lightInput, index);
|
|
104
|
+
if (value === missing)
|
|
105
|
+
hole = true;
|
|
106
|
+
put(lightValues, index, value);
|
|
107
|
+
}
|
|
108
|
+
for (let index = 0; index < 3; index++) {
|
|
109
|
+
const value = darkInput === undefined ? 0 : readSlot(darkInput, index);
|
|
110
|
+
if (value === missing)
|
|
111
|
+
hole = true;
|
|
112
|
+
put(darkValues, index, value);
|
|
113
|
+
}
|
|
114
|
+
// A hole is remembered until all successful own-slot reads finish. No
|
|
115
|
+
// component validation or option failure can hide a later source exception.
|
|
116
|
+
if (hole)
|
|
117
|
+
throw new RangeFault('Shared material color tuple shape is invalid');
|
|
118
|
+
const light = color(lightValues, 4);
|
|
119
|
+
const dark = color(darkValues, 3);
|
|
120
|
+
const blend = blendInput === undefined ? 'normal' : blendInput;
|
|
121
|
+
if (blend !== 'normal' &&
|
|
122
|
+
blend !== 'add-accumulate' &&
|
|
123
|
+
blend !== 'add-preserve' &&
|
|
124
|
+
blend !== 'multiply-factor' &&
|
|
125
|
+
blend !== 'screen' &&
|
|
126
|
+
blend !== 'erase')
|
|
127
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
128
|
+
const samplingDomain = domainInput === undefined ? 'region' : domainInput;
|
|
129
|
+
if (samplingDomain !== 'page' && samplingDomain !== 'region')
|
|
130
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
131
|
+
const selectedFilter = filter(filterInput === undefined ? 'nearest' : filterInput);
|
|
132
|
+
const addressU = address(addressUInput === undefined ? 'clamp-to-edge' : addressUInput);
|
|
133
|
+
const addressV = address(addressVInput === undefined ? 'clamp-to-edge' : addressVInput);
|
|
134
|
+
const regionIsolation = isolationInput === undefined ? 'bounded' : isolationInput;
|
|
135
|
+
if (regionIsolation !== 'bounded' && regionIsolation !== 'strict')
|
|
136
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
137
|
+
const mipLevel = mipInput === undefined ? 0 : mipInput;
|
|
138
|
+
if (typeof mipLevel !== 'number' || !safeInteger(mipLevel) || mipLevel < 0) {
|
|
139
|
+
throw new RangeFault('Shared material numeric range is invalid');
|
|
140
|
+
}
|
|
141
|
+
if (mipLevel !== 0)
|
|
142
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
143
|
+
const minFilter = filter(minInput === undefined ? selectedFilter : minInput);
|
|
144
|
+
const magFilter = filter(magInput === undefined ? selectedFilter : magInput);
|
|
145
|
+
const maxAnisotropy = anisotropyInput === undefined ? 1 : anisotropyInput;
|
|
146
|
+
if (typeof maxAnisotropy !== 'number' || !safeInteger(maxAnisotropy) || maxAnisotropy <= 0) {
|
|
147
|
+
throw new RangeFault('Shared material numeric range is invalid');
|
|
148
|
+
}
|
|
149
|
+
if (maxAnisotropy !== 1)
|
|
150
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
151
|
+
if (minFilter !== selectedFilter ||
|
|
152
|
+
magFilter !== selectedFilter ||
|
|
153
|
+
(samplingDomain === 'region' && (addressU !== 'clamp-to-edge' || addressV !== 'clamp-to-edge')) ||
|
|
154
|
+
(samplingDomain === 'page' && regionIsolation !== 'bounded')) {
|
|
155
|
+
throw new TypeFault('Shared material option is unsupported');
|
|
156
|
+
}
|
|
157
|
+
// Publication is callback-free. The contracts registry is the only brand
|
|
158
|
+
// owner; runtime and rendering authenticate through the contracts root.
|
|
159
|
+
const material = freeze({
|
|
160
|
+
light,
|
|
161
|
+
dark,
|
|
162
|
+
blend,
|
|
163
|
+
samplingDomain,
|
|
164
|
+
filter: selectedFilter,
|
|
165
|
+
addressU,
|
|
166
|
+
addressV,
|
|
167
|
+
regionIsolation,
|
|
168
|
+
mipLevel: 0,
|
|
169
|
+
minFilter,
|
|
170
|
+
magFilter,
|
|
171
|
+
maxAnisotropy: 1
|
|
172
|
+
});
|
|
173
|
+
apply(weakSet, owned, [material, true]);
|
|
174
|
+
return material;
|
|
175
|
+
}
|
|
176
|
+
export function isSharedMaterial2D(value) {
|
|
177
|
+
return typeof value === 'object' && value !== null && apply(weakHas, owned, [value]);
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=SharedMaterial2D.js.map
|