@egret/contracts 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.
Files changed (43) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +22 -2
  4. package/README.zh-CN.md +23 -0
  5. package/dist/CancellationSignal.d.ts +12 -0
  6. package/dist/CancellationSignal.js +2 -0
  7. package/dist/Diagnostic.d.ts +11 -0
  8. package/dist/Diagnostic.js +2 -0
  9. package/dist/Disposable.d.ts +11 -0
  10. package/dist/Disposable.js +2 -0
  11. package/dist/HostAdapter.d.ts +17 -0
  12. package/dist/HostAdapter.js +2 -0
  13. package/dist/ImageData2D.d.ts +49 -0
  14. package/dist/ImageData2D.js +133 -0
  15. package/dist/Point2D.d.ts +6 -0
  16. package/dist/Point2D.js +2 -0
  17. package/dist/ProjectFormat.generated.d.ts +129 -0
  18. package/dist/ProjectFormat.generated.js +4 -0
  19. package/dist/RenderFrame2D.d.ts +22 -0
  20. package/dist/RenderFrame2D.js +2 -0
  21. package/dist/ResourceManifest.d.ts +75 -0
  22. package/dist/ResourceManifest.js +2 -0
  23. package/dist/SharedGeometry2D.d.ts +31 -0
  24. package/dist/SharedGeometry2D.js +177 -0
  25. package/dist/SharedMaterial2D.d.ts +46 -0
  26. package/dist/SharedMaterial2D.js +188 -0
  27. package/dist/SharedRenderFrame2D.d.ts +132 -0
  28. package/dist/SharedRenderFrame2D.js +5 -0
  29. package/dist/TextureViewRegion2D.d.ts +20 -0
  30. package/dist/TextureViewRegion2D.js +2 -0
  31. package/dist/TexturedGeometry2D.d.ts +30 -0
  32. package/dist/TexturedGeometry2D.js +167 -0
  33. package/dist/index.d.ts +20 -0
  34. package/dist/index.js +6 -0
  35. package/dist/resources/fontArtifact.d.ts +7 -0
  36. package/dist/resources/fontArtifact.js +37 -0
  37. package/dist/resources/index.d.ts +4 -0
  38. package/dist/resources/index.js +4 -0
  39. package/dist/resources/manifestAdmission.d.ts +10 -0
  40. package/dist/resources/manifestAdmission.js +457 -0
  41. package/dist/resources/sha256.d.ts +3 -0
  42. package/dist/resources/sha256.js +111 -0
  43. package/package.json +25 -4
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,21 @@
1
+ First-party code and documentation: Apache-2.0; see LICENSE.
2
+
3
+ robust-predicates 3.0.3 by Vladimir Agafonkin
4
+ https://github.com/mourner/robust-predicates
5
+ License: Unlicense. The unmodified license text is retained in
6
+ third-party/robust-predicates-3.0.3.LICENSE and the installed package.
7
+ Used through its public package root for orient2d in private DOM-free
8
+ rectangle preparation. This dependency does not establish native GPU,
9
+ browser bundle-size, performance or complete-engine acceptance.
10
+
11
+ jsonc-parser 3.3.1 by Microsoft Corporation
12
+ https://github.com/microsoft/node-jsonc-parser
13
+ License: MIT. The unmodified Microsoft copyright and permission notice is
14
+ retained in third-party/jsonc-parser-3.3.1.LICENSE and the installed package.
15
+ Only createScanner and visit are used through its public package root in
16
+ the private headless project adapters. First-party schema generation,
17
+ validation, canonical bytes, transactions and history are independently authored.
18
+ The 0.14.0 engineering preview has bounded headless implementation evidence;
19
+ editor, migration, browser/bundler, Native SDK and performance remain unaccepted.
20
+ Native Node public-root CJS interoperability is separate from the shipped
21
+ ESM entry's extensionless-import limitation.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @egret/contracts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [简体中文](README.zh-CN.md)
4
+
5
+ Egret's experimental type package defines `CancellationSignal`, `Disposable`/`Releasable`, `Diagnostic` and `HostAdapter` contracts from the lifecycle specification. It has no package or third-party runtime dependencies, DOM/Node environment globals, or host-initialization side effects.
6
+
7
+ The existing readonly `Rectangle2D` is reused by receiver-local content measurement. Read the [bounds contract](../../knowledge-base/en/docs/display-content-bounds-contract.md); no additional contract value or geometry class is introduced.
8
+
9
+ `Point2D` is a readonly type-only logical coordinate result. Read the [coordinate contract](../../knowledge-base/en/docs/display-coordinate-query-contract.md).
10
+
11
+ ## Host and frame obligations
12
+
13
+ `HostAdapter.surface` denotes stable object identity; the host owns physical resources. `close()` resolves only after safely returning the surface and completing in-flight host work. If it rejects, Engine retains the exclusive reservation. The injected millisecond-deadline port should support synchronous cancellation. Type contracts do not verify a real host.
14
+
15
+ The [shared render profile contract](../../knowledge-base/en/docs/shared-render-profile-contract.md) defines `SharedRenderFrame2D`, its commands, pages and regions, `SharedFrameOptions2D` and `SharedRenderHostAdapter`; `Matrix2D`, `Rectangle2D` and `ClipRectangle2D` are the geometry they use. `renderSharedFrame` synchronously returns `undefined`; host `close` still proves completion of in-flight work. A CPU frame does not serve as a device completion fence.
16
+
17
+ Through the engine facade, `DisplayObject` provides `x`, `y`, `scaleX`, `scaleY`, `rotation`, `alpha`, `visible` and `clipRect`; `Sprite.graphics` owns rectangle fills, and `Engine.captureSharedFrame`/`renderSharedFrame` capture/submit immutable frames. The browser Hosts belong to the separate `@egret/engine/webgpu` and `@egret/engine/webgl2` entries; the root remains DOM-free.
18
+
19
+ ## Verification and scope
20
+
21
+ From the repository root, run `node tools/verify.mjs` for strict compilation, declarations/import boundaries and positive/negative type samples. Design and version-bound evidence live in the [knowledge base](../../knowledge-base/en/README.md) and [display/frame implementation record](../../knowledge-base/en/docs/display-and-frame-implementation-record.md). Attribution is in the [source record](../../source-origin.json).
22
+
23
+ Interfaces remain experimental. Full text, texture, animation, UI and 3D execution, GPU/Native acceptance, target-device performance, editors, Agent services and complete migration remain separate obligations. Package version `0.0.0`, protocol `1.0` and `private: true` remain unchanged; accidental npm publication stays disabled. First-party code and this document use [Apache-2.0](../../LICENSE).
@@ -0,0 +1,23 @@
1
+ # @egret/contracts
2
+
3
+ [English](README.md) | 简体中文
4
+
5
+ 白鹭实验性类型包,依据生命周期规格定义 `CancellationSignal`、`Disposable`/`Releasable`、`Diagnostic` 和 `HostAdapter` 合同。没有包依赖或第三方运行时依赖、DOM/Node 环境全局,也没有宿主初始化副作用。
6
+
7
+ 接收者局部内容测量复用已有只读 `Rectangle2D`,见[边界契约](../../knowledge-base/Cns/docs/显示内容边界契约.md);不新增契约运行时值或几何类。
8
+
9
+ `Point2D` 是只读、仅类型的逻辑坐标结果。 阅读[坐标契约](../../knowledge-base/Cns/docs/显示坐标查询契约.md)。
10
+
11
+ ## 宿主与帧义务
12
+
13
+ `HostAdapter.surface` 表示稳定对象身份,物理资源由宿主负责。`close()` 仅在安全归还 surface 并完成宿主在途工作后 resolve;拒绝时 Engine 保留独占预留。注入的毫秒 deadline 端口应支持同步取消。类型合同本身不验证真实宿主。
14
+
15
+ [共享渲染 Profile 契约](../../knowledge-base/Cns/docs/shared-render-profile-contract.md)定义 `SharedRenderFrame2D` 及其命令、页与区域,以及 `SharedFrameOptions2D` 与 `SharedRenderHostAdapter`;`Matrix2D`、`Rectangle2D`、`ClipRectangle2D` 是它们使用的几何类型。`renderSharedFrame` 同步返回 `undefined`;宿主 `close` 仍证明在途工作完成,CPU 帧不能充当设备完成栅栏。
16
+
17
+ 通过引擎门面,`DisplayObject` 提供 `x`、`y`、`scaleX`、`scaleY`、`rotation`、`alpha`、`visible` 与 `clipRect`;`Sprite.graphics` 拥有矩形填充,`Engine.captureSharedFrame`/`renderSharedFrame` 捕获/提交不可变帧。浏览器宿主位于独立的 `@egret/engine/webgpu` 与 `@egret/engine/webgl2` 入口,根入口保持无 DOM。
18
+
19
+ ## 验证与范围
20
+
21
+ 在仓库根运行 `node tools/verify.mjs`,检查严格编译、声明/导入边界及正负类型样例。设计和绑定版本的证据见[知识库](../../knowledge-base/Cns/README.md)及[显示与帧实现记录](../../knowledge-base/Cns/docs/显示与帧执行实现记录.md),归属见[来源记录](../../source-origin.json)。
22
+
23
+ 接口保持实验性质。完整文字、纹理、动画、UI 与 3D 执行、GPU/Native 验收、目标设备性能、编辑器、Agent 服务及完整迁移仍有独立义务。包版本 `0.0.0`、协议 `1.0` 与 `private: true` 保持不变,继续禁止意外 npm 发布。第一方代码与本文采用 [Apache-2.0](../../LICENSE)。
@@ -0,0 +1,12 @@
1
+ /** A DOM-free cancellation listener; it receives no host Event object. */
2
+ export type CancellationListener = () => void;
3
+ /** One-way cancellation state. A late subscriber must inspect aborted itself. */
4
+ export interface CancellationSignal {
5
+ readonly aborted: boolean;
6
+ readonly reason: unknown;
7
+ addEventListener(type: "abort", listener: CancellationListener, options?: {
8
+ readonly once?: boolean;
9
+ }): void;
10
+ removeEventListener(type: "abort", listener: CancellationListener): void;
11
+ }
12
+ //# sourceMappingURL=CancellationSignal.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CancellationSignal.js.map
@@ -0,0 +1,11 @@
1
+ /** Diagnostics describe this headless lifecycle slice only. */
2
+ export interface Diagnostic {
3
+ readonly code: string;
4
+ readonly phase: "cancellation" | "scope" | "display-tree" | "engine" | "assets" | "graphics";
5
+ readonly severity: "error" | "warning";
6
+ readonly cause?: unknown;
7
+ readonly cleanupErrors?: readonly unknown[];
8
+ }
9
+ /** Observation only: throwing cannot change cleanup or cancellation progress. */
10
+ export type DiagnosticHandler = (diagnostic: Diagnostic) => void;
11
+ //# sourceMappingURL=Diagnostic.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Diagnostic.js.map
@@ -0,0 +1,11 @@
1
+ /** Synchronous terminal cleanup. Scope catches failures and continues cleanup. */
2
+ export interface Disposable {
3
+ dispose(): void;
4
+ }
5
+ /** Releases a lease; resource ownership and disposal remain with its provider. */
6
+ export interface Releasable {
7
+ release(): void;
8
+ }
9
+ /** Scope prefers dispose() when a value implements both cleanup protocols. */
10
+ export type ScopeValue = Disposable | Releasable;
11
+ //# sourceMappingURL=Disposable.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Disposable.js.map
@@ -0,0 +1,17 @@
1
+ /** Host owns the surface and any borrowed device. Core never destroys them. */
2
+ export interface HostAdapter {
3
+ /** Stable identity used to prevent concurrent engines borrowing one surface. */
4
+ readonly surface: object;
5
+ /** Startup may be asynchronous; createEngine returns only after it succeeds. */
6
+ start?(): void | Promise<void>;
7
+ /** Stops new work synchronously; close still proves completion of pending work. */
8
+ stop?(): void;
9
+ /** Resolves only after safe return of the surface and completion of host work.
10
+ * Rejection does not prove safe return; core keeps that surface quarantined.
11
+ * This prototype provides no force-release/recovery override.
12
+ */
13
+ close(): Promise<void>;
14
+ /** Milliseconds. Cancellation must be synchronous and idempotent. */
15
+ setTimeout(callback: () => void, delayMs: number): () => void;
16
+ }
17
+ //# sourceMappingURL=HostAdapter.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=HostAdapter.js.map
@@ -0,0 +1,49 @@
1
+ declare const imageData2DBrand: unique symbol;
2
+ /** The size and pixels of an image to copy: sRGB RGBA, eight bits a channel, rows top to bottom. */
3
+ export interface ImageData2DInput {
4
+ readonly width: number;
5
+ readonly height: number;
6
+ readonly pixels: Uint8Array<ArrayBuffer>;
7
+ readonly format?: 'rgba8unorm';
8
+ readonly colorSpace?: 'srgb';
9
+ readonly alphaMode?: 'straight';
10
+ readonly origin?: 'top-left';
11
+ }
12
+ /** Immutable CPU byte identity; the brand conveys no asset or GPU authority. */
13
+ export interface ImageData2D {
14
+ readonly [imageData2DBrand]: true;
15
+ readonly width: number;
16
+ readonly height: number;
17
+ readonly bytesPerRow: number;
18
+ readonly byteLength: number;
19
+ readonly format: 'rgba8unorm';
20
+ readonly colorSpace: 'srgb';
21
+ readonly alphaMode: 'straight';
22
+ readonly origin: 'top-left';
23
+ }
24
+ /** A rectangle of an image in whole pixels, from its top left corner. */
25
+ export interface TextureRegion2D {
26
+ readonly x: number;
27
+ readonly y: number;
28
+ readonly width: number;
29
+ readonly height: number;
30
+ }
31
+ /** The largest image accepted: its longest edge and its number of pixels. */
32
+ export declare const IMAGE_LIMITS_2D: Readonly<{
33
+ readonly maxSourceEdge: 4096;
34
+ readonly maxSourcePixels: 4194304;
35
+ readonly maxImagesPerFrame: 64;
36
+ readonly maxViewsPerFrame: 128;
37
+ readonly maxImageTableBytes: 16777216;
38
+ readonly maxProjectionBytes: 16777216;
39
+ readonly maxImageScratchBytes: 33554432;
40
+ readonly maxPendingTextureBytes: 33554432;
41
+ }>;
42
+ /** Copies the pixels into an image this module owns; a wrong size or pixel count is refused with a TypeError. */
43
+ export declare function createImageData2D(input: ImageData2DInput): ImageData2D;
44
+ /** Whether a value is an image made by `createImageData2D`, without reading any of its properties. */
45
+ export declare function isImageData2D(value: unknown): value is ImageData2D;
46
+ /** A fresh copy of an image's pixels, which the caller owns. */
47
+ export declare function copyImageData2DPixels(image: ImageData2D): Uint8Array<ArrayBuffer>;
48
+ export {};
49
+ //# sourceMappingURL=ImageData2D.d.ts.map
@@ -0,0 +1,133 @@
1
+ // Capture normal-realm intrinsics once. Descriptor code cannot replace the
2
+ // validation/copy path with instance getters, iterators, or species callbacks.
3
+ const Bytes = Uint8Array;
4
+ const apply = Reflect.apply;
5
+ const freeze = Object.freeze;
6
+ const TypeFault = TypeError;
7
+ const RangeFault = RangeError;
8
+ const finite = Number.isFinite;
9
+ const safeInteger = Number.isSafeInteger;
10
+ const typedArrayPrototype = Object.getPrototypeOf(Bytes.prototype);
11
+ const tagGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
12
+ const bufferGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'buffer').get;
13
+ const offsetGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'byteOffset').get;
14
+ const lengthGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'byteLength').get;
15
+ const bufferLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get;
16
+ const resizableGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable')?.get;
17
+ const detachedGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached')?.get;
18
+ const setBytes = typedArrayPrototype.set;
19
+ const weakHas = WeakMap.prototype.has;
20
+ const weakGet = WeakMap.prototype.get;
21
+ const weakSet = WeakMap.prototype.set;
22
+ const owned = new WeakMap();
23
+ /** The largest image accepted: its longest edge and its number of pixels. */
24
+ export const IMAGE_LIMITS_2D = freeze({
25
+ // One image is at most 2048 x 2048 pixels, or any other shape of that area within the edge bound.
26
+ maxSourceEdge: 4096,
27
+ maxSourcePixels: 4194304,
28
+ maxImagesPerFrame: 64,
29
+ maxViewsPerFrame: 128,
30
+ maxImageTableBytes: 16777216,
31
+ maxProjectionBytes: 16777216,
32
+ maxImageScratchBytes: 33554432,
33
+ maxPendingTextureBytes: 33554432
34
+ });
35
+ function read(source, key) {
36
+ try {
37
+ return source[key];
38
+ }
39
+ catch (cause) {
40
+ throw new TypeFault('Image descriptor read failed', { cause });
41
+ }
42
+ }
43
+ function dimension(value) {
44
+ if (typeof value !== 'number')
45
+ throw new TypeFault('Image dimension must be numeric');
46
+ if (!finite(value) || !safeInteger(value) || value <= 0)
47
+ throw new RangeFault('Image dimension must be a positive safe integer');
48
+ return value;
49
+ }
50
+ function literal(value, expected) {
51
+ if (value !== undefined && value !== expected)
52
+ throw new TypeFault('Unsupported image metadata');
53
+ }
54
+ function cloneBytes(source, length) {
55
+ const result = new Bytes(length);
56
+ // Allocation errors escape intact; neither copy route invokes user code.
57
+ apply(setBytes, result, [source]);
58
+ return result;
59
+ }
60
+ /** Copies the pixels into an image this module owns; a wrong size or pixel count is refused with a TypeError. */
61
+ export function createImageData2D(input) {
62
+ if (typeof input !== 'object' || input === null)
63
+ throw new TypeFault('Image descriptor must be an object');
64
+ // Complete the ordered snapshot before semantic checks. A later throwing
65
+ // getter wins over an earlier malformed field, including during reentry.
66
+ const widthInput = read(input, 'width');
67
+ const heightInput = read(input, 'height');
68
+ const pixels = read(input, 'pixels');
69
+ const format = read(input, 'format');
70
+ const colorSpace = read(input, 'colorSpace');
71
+ const alphaMode = read(input, 'alphaMode');
72
+ const origin = read(input, 'origin');
73
+ const width = dimension(widthInput);
74
+ const height = dimension(heightInput);
75
+ const pixelCount = width * height;
76
+ const bytesPerRow = 4 * width;
77
+ const byteLength = 4 * pixelCount;
78
+ if (width > IMAGE_LIMITS_2D.maxSourceEdge ||
79
+ height > IMAGE_LIMITS_2D.maxSourceEdge ||
80
+ !safeInteger(pixelCount) ||
81
+ pixelCount > IMAGE_LIMITS_2D.maxSourcePixels ||
82
+ !safeInteger(bytesPerRow) ||
83
+ !safeInteger(byteLength))
84
+ throw new RangeFault('Image source capacity exceeded');
85
+ literal(format, 'rgba8unorm');
86
+ literal(colorSpace, 'srgb');
87
+ literal(alphaMode, 'straight');
88
+ literal(origin, 'top-left');
89
+ if (apply(tagGetter, pixels, []) !== 'Uint8Array')
90
+ throw new TypeFault('Image pixels must be intrinsic Uint8Array');
91
+ const backing = apply(bufferGetter, pixels, []);
92
+ // The ArrayBuffer getter rejects SharedArrayBuffer, including cross realm.
93
+ apply(bufferLengthGetter, backing, []);
94
+ if (resizableGetter && apply(resizableGetter, backing, []))
95
+ throw new TypeFault('Resizable image backing is unsupported');
96
+ if (detachedGetter) {
97
+ if (apply(detachedGetter, backing, []))
98
+ throw new TypeFault('Detached image backing is unsupported');
99
+ }
100
+ else {
101
+ // A zero-length intrinsic view still checks attachment in older realms.
102
+ new Bytes(backing, 0, 0);
103
+ }
104
+ apply(offsetGetter, pixels, []);
105
+ if (apply(lengthGetter, pixels, []) !== byteLength)
106
+ throw new RangeFault('Image pixels must have exact tight byte length');
107
+ const copy = cloneBytes(pixels, byteLength);
108
+ const image = freeze({
109
+ width,
110
+ height,
111
+ bytesPerRow,
112
+ byteLength,
113
+ format: 'rgba8unorm',
114
+ colorSpace: 'srgb',
115
+ alphaMode: 'straight',
116
+ origin: 'top-left'
117
+ });
118
+ apply(weakSet, owned, [image, copy]);
119
+ return image;
120
+ }
121
+ /** Whether a value is an image made by `createImageData2D`, without reading any of its properties. */
122
+ export function isImageData2D(value) {
123
+ return typeof value === 'object' && value !== null && apply(weakHas, owned, [value]);
124
+ }
125
+ /** A fresh copy of an image's pixels, which the caller owns. */
126
+ export function copyImageData2DPixels(image) {
127
+ // Identity authentication performs no property reads on forged/proxied values.
128
+ if (!isImageData2D(image))
129
+ throw new TypeFault('Image identity is not owned by this module');
130
+ const source = apply(weakGet, owned, [image]);
131
+ return cloneBytes(source, apply(lengthGetter, source, []));
132
+ }
133
+ //# sourceMappingURL=ImageData2D.js.map
@@ -0,0 +1,6 @@
1
+ /** An owned logical-coordinate value; query results are frozen at runtime. */
2
+ export interface Point2D {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ }
6
+ //# sourceMappingURL=Point2D.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Point2D.js.map