@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.
Files changed (157) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +70 -2
  4. package/README.zh-CN.md +71 -0
  5. package/dist/AssetLease.d.ts +23 -0
  6. package/dist/AssetLease.js +69 -0
  7. package/dist/AssetManager.d.ts +58 -0
  8. package/dist/AssetManager.js +451 -0
  9. package/dist/AssetRef.d.ts +21 -0
  10. package/dist/AssetRef.js +33 -0
  11. package/dist/Bitmap.d.ts +40 -0
  12. package/dist/Bitmap.js +545 -0
  13. package/dist/ByteReader.d.ts +32 -0
  14. package/dist/ByteReader.js +178 -0
  15. package/dist/ByteWriter.d.ts +30 -0
  16. package/dist/ByteWriter.js +181 -0
  17. package/dist/CancellationController.d.ts +10 -0
  18. package/dist/CancellationController.js +66 -0
  19. package/dist/DisplayObject.d.ts +97 -0
  20. package/dist/DisplayObject.js +366 -0
  21. package/dist/DisplayObjectContainer.d.ts +28 -0
  22. package/dist/DisplayObjectContainer.js +226 -0
  23. package/dist/EgretError.d.ts +12 -0
  24. package/dist/EgretError.js +36 -0
  25. package/dist/Event.d.ts +47 -0
  26. package/dist/Event.js +84 -0
  27. package/dist/EventDispatcher.d.ts +24 -0
  28. package/dist/EventDispatcher.js +178 -0
  29. package/dist/Graphics.d.ts +117 -0
  30. package/dist/Graphics.js +548 -0
  31. package/dist/Mesh2D.d.ts +27 -0
  32. package/dist/Mesh2D.js +200 -0
  33. package/dist/NineSliceBitmap.d.ts +24 -0
  34. package/dist/NineSliceBitmap.js +164 -0
  35. package/dist/NineSliceGeometry2D.d.ts +19 -0
  36. package/dist/NineSliceGeometry2D.js +126 -0
  37. package/dist/Scope.d.ts +19 -0
  38. package/dist/Scope.js +133 -0
  39. package/dist/SequencePlayer.d.ts +12 -0
  40. package/dist/SequencePlayer.js +69 -0
  41. package/dist/Sprite.d.ts +8 -0
  42. package/dist/Sprite.js +12 -0
  43. package/dist/Stage.d.ts +14 -0
  44. package/dist/Stage.js +31 -0
  45. package/dist/Texture.d.ts +30 -0
  46. package/dist/Texture.js +178 -0
  47. package/dist/assetManagerOwnerState.d.ts +36 -0
  48. package/dist/assetManagerOwnerState.js +115 -0
  49. package/dist/assetState.d.ts +45 -0
  50. package/dist/assetState.js +2 -0
  51. package/dist/atlasFrameLayout.d.ts +21 -0
  52. package/dist/atlasFrameLayout.js +48 -0
  53. package/dist/bitmapDisplayState.d.ts +24 -0
  54. package/dist/bitmapDisplayState.js +22 -0
  55. package/dist/coordinateInverse.d.ts +4 -0
  56. package/dist/coordinateInverse.js +107 -0
  57. package/dist/diagnostics.d.ts +4 -0
  58. package/dist/diagnostics.js +13 -0
  59. package/dist/displayBounds.d.ts +9 -0
  60. package/dist/displayBounds.js +181 -0
  61. package/dist/displayCoordinates.d.ts +8 -0
  62. package/dist/displayCoordinates.js +81 -0
  63. package/dist/displayHitState.d.ts +18 -0
  64. package/dist/displayHitState.js +97 -0
  65. package/dist/displayHitTest.d.ts +8 -0
  66. package/dist/displayHitTest.js +219 -0
  67. package/dist/displayInputOperations.d.ts +12 -0
  68. package/dist/displayInputOperations.js +71 -0
  69. package/dist/displayTransform.d.ts +5 -0
  70. package/dist/displayTransform.js +38 -0
  71. package/dist/displayTreeState.d.ts +90 -0
  72. package/dist/displayTreeState.js +450 -0
  73. package/dist/displayVisualState.d.ts +76 -0
  74. package/dist/displayVisualState.js +141 -0
  75. package/dist/errorHelp.d.ts +15 -0
  76. package/dist/errorHelp.js +435 -0
  77. package/dist/errorHelpZh.d.ts +5 -0
  78. package/dist/errorHelpZh.js +342 -0
  79. package/dist/geometry.d.ts +173 -0
  80. package/dist/geometry.js +311 -0
  81. package/dist/graphicsFill.d.ts +37 -0
  82. package/dist/graphicsFill.js +302 -0
  83. package/dist/graphicsShape.d.ts +170 -0
  84. package/dist/graphicsShape.js +961 -0
  85. package/dist/index.d.ts +53 -0
  86. package/dist/index.js +31 -0
  87. package/dist/input/PointerRouter.d.ts +4 -0
  88. package/dist/input/PointerRouter.js +453 -0
  89. package/dist/input/index.d.ts +3 -0
  90. package/dist/input/index.js +3 -0
  91. package/dist/input/types.d.ts +64 -0
  92. package/dist/input/types.js +3 -0
  93. package/dist/meshCaptureSnapshot.d.ts +5 -0
  94. package/dist/meshCaptureSnapshot.js +13 -0
  95. package/dist/meshDisplayState.d.ts +18 -0
  96. package/dist/meshDisplayState.js +21 -0
  97. package/dist/ownership.d.ts +75 -0
  98. package/dist/ownership.js +157 -0
  99. package/dist/paragraph/Paragraph.d.ts +13 -0
  100. package/dist/paragraph/Paragraph.js +193 -0
  101. package/dist/paragraph/ParagraphCache.d.ts +5 -0
  102. package/dist/paragraph/ParagraphCache.js +354 -0
  103. package/dist/paragraph/geometry.d.ts +4 -0
  104. package/dist/paragraph/geometry.js +180 -0
  105. package/dist/paragraph/index.d.ts +3 -0
  106. package/dist/paragraph/index.js +3 -0
  107. package/dist/paragraph/request.d.ts +6 -0
  108. package/dist/paragraph/request.js +191 -0
  109. package/dist/paragraph/types.d.ts +183 -0
  110. package/dist/paragraph/types.js +2 -0
  111. package/dist/preparedDisplaySubtree.d.ts +7 -0
  112. package/dist/preparedDisplaySubtree.js +205 -0
  113. package/dist/renderEffect.d.ts +57 -0
  114. package/dist/renderEffect.js +109 -0
  115. package/dist/sequenceClip.d.ts +48 -0
  116. package/dist/sequenceClip.js +197 -0
  117. package/dist/sharedFrameCapture.d.ts +24 -0
  118. package/dist/sharedFrameCapture.js +1128 -0
  119. package/dist/spriteSheet.d.ts +34 -0
  120. package/dist/spriteSheet.js +321 -0
  121. package/dist/srgbBytes.d.ts +3 -0
  122. package/dist/srgbBytes.js +64 -0
  123. package/dist/text/TextField.d.ts +13 -0
  124. package/dist/text/TextField.js +261 -0
  125. package/dist/text/TextRasterCache.d.ts +5 -0
  126. package/dist/text/TextRasterCache.js +1191 -0
  127. package/dist/text/budget.d.ts +51 -0
  128. package/dist/text/budget.js +116 -0
  129. package/dist/text/index.d.ts +4 -0
  130. package/dist/text/index.js +3 -0
  131. package/dist/text/plan.d.ts +16 -0
  132. package/dist/text/plan.js +238 -0
  133. package/dist/text/request.d.ts +44 -0
  134. package/dist/text/request.js +303 -0
  135. package/dist/text/types.d.ts +179 -0
  136. package/dist/text/types.js +2 -0
  137. package/dist/textDisplayState.d.ts +21 -0
  138. package/dist/textDisplayState.js +27 -0
  139. package/dist/ui/displayCommit.d.ts +43 -0
  140. package/dist/ui/displayCommit.js +384 -0
  141. package/dist/ui/editing.d.ts +3 -0
  142. package/dist/ui/editing.js +3 -0
  143. package/dist/ui/heightIndex.d.ts +35 -0
  144. package/dist/ui/heightIndex.js +295 -0
  145. package/dist/ui/index.d.ts +6 -0
  146. package/dist/ui/index.js +6 -0
  147. package/dist/ui/layout.d.ts +9 -0
  148. package/dist/ui/layout.js +349 -0
  149. package/dist/ui/managedState.d.ts +12 -0
  150. package/dist/ui/managedState.js +44 -0
  151. package/dist/ui/textEditState.d.ts +4 -0
  152. package/dist/ui/textEditState.js +206 -0
  153. package/dist/ui/textEditTypes.d.ts +48 -0
  154. package/dist/ui/textEditTypes.js +2 -0
  155. package/dist/ui/types.d.ts +99 -0
  156. package/dist/ui/types.js +2 -0
  157. package/package.json +44 -4
@@ -0,0 +1,261 @@
1
+ import { AssetLease } from '../AssetLease.js';
2
+ import { CancellationController } from '../CancellationController.js';
3
+ import { DisplayObject } from '../DisplayObject.js';
4
+ import { EgretError } from '../EgretError.js';
5
+ import { Scope } from '../Scope.js';
6
+ import { readBitmapImage } from '../Bitmap.js';
7
+ import { assertTextFieldScope, writeTextFieldState } from '../textDisplayState.js';
8
+ const states = new WeakMap();
9
+ const CREATION_TOKEN = Symbol('egret.textFieldFactory');
10
+ const APPLY = Reflect.apply;
11
+ const FREEZE = Object.freeze;
12
+ const USE_SCOPE = Scope.prototype.use;
13
+ const DISPOSE_DISPLAY = DisplayObject.prototype.dispose;
14
+ const RELEASE_LEASE = AssetLease.prototype.release;
15
+ const ABORT = CancellationController.prototype.abort;
16
+ const SAFE_INTEGER = Number.isSafeInteger;
17
+ function stateOf(value) {
18
+ const state = states.get(value);
19
+ if (state === undefined)
20
+ throw new EgretError('TEXT_FIELD_INVALID');
21
+ return state;
22
+ }
23
+ function live(state) {
24
+ if (state.disposed)
25
+ throw new EgretError('TEXT_FIELD_DISPOSED');
26
+ state.cache.context.assertOpen();
27
+ assertTextFieldScope(state.scope);
28
+ }
29
+ function publish(node, state) {
30
+ writeTextFieldState(node, FREEZE({ scope: state.scope, committed: state.committed }));
31
+ }
32
+ function release(committed) {
33
+ if (committed?.lease !== undefined)
34
+ APPLY(RELEASE_LEASE, committed.lease, []);
35
+ }
36
+ function cancel(demand, cause) {
37
+ if (demand === undefined)
38
+ return;
39
+ // Promise authority is retired before the provider's synchronous abort observer.
40
+ demand.reject(cause);
41
+ APPLY(ABORT, demand.controller, [cause]);
42
+ }
43
+ function copyMetrics(value) {
44
+ const copyBounds = (bounds) => FREEZE({ ...bounds });
45
+ return FREEZE({
46
+ logicalBounds: copyBounds(value.logicalBounds),
47
+ inkBounds: value.inkBounds === undefined ? undefined : copyBounds(value.inkBounds),
48
+ contentBounds: copyBounds(value.contentBounds),
49
+ lines: FREEZE(value.lines.map(line => FREEZE({
50
+ source: FREEZE({ ...line.source }),
51
+ advance: line.advance,
52
+ baselineY: line.baselineY,
53
+ inkBounds: line.inkBounds === undefined ? undefined : copyBounds(line.inkBounds)
54
+ }))),
55
+ raster: value.raster === undefined ? undefined : FREEZE({ ...value.raster })
56
+ });
57
+ }
58
+ /** This class never enters a public namespace; only authentic cache assembly constructs it. */
59
+ class TextFieldLeaf extends DisplayObject {
60
+ constructor(scope, cache, token) {
61
+ // prototype.constructor is observable; validate before display registration or external reads.
62
+ if (token !== CREATION_TOKEN)
63
+ throw new EgretError('TEXT_FIELD_INVALID');
64
+ super();
65
+ cache.context.assertOpen();
66
+ assertTextFieldScope(scope);
67
+ cache.assertOpen();
68
+ const state = {
69
+ scope,
70
+ cache,
71
+ disposed: false,
72
+ reading: false,
73
+ desiredRevision: 0,
74
+ desired: undefined,
75
+ committedRevision: undefined,
76
+ metrics: undefined,
77
+ committed: undefined,
78
+ pending: undefined
79
+ };
80
+ states.set(this, state);
81
+ publish(this, state);
82
+ APPLY(USE_SCOPE, scope, [this]);
83
+ }
84
+ setRequest(input) {
85
+ const state = stateOf(this);
86
+ live(state);
87
+ if (state.reading)
88
+ throw new EgretError('TEXT_FIELD_BUSY');
89
+ state.reading = true;
90
+ let previous;
91
+ try {
92
+ // The private callback runs after successful source reads, before semantics.
93
+ const desired = state.cache.adopt(input, () => {
94
+ live(state);
95
+ });
96
+ live(state);
97
+ const revision = state.desiredRevision + 1;
98
+ if (!SAFE_INTEGER(revision))
99
+ throw new EgretError('TEXT_FIELD_REVISION_LIMIT');
100
+ previous = state.pending;
101
+ state.pending = undefined;
102
+ state.desired = desired;
103
+ state.desiredRevision = revision;
104
+ }
105
+ finally {
106
+ state.reading = false;
107
+ }
108
+ // Abort reentry sees the new request and a retired synchronous admission guard.
109
+ cancel(previous, new EgretError('TEXT_FIELD_SUPERSEDED'));
110
+ }
111
+ prepare() {
112
+ return new Promise((resolve, reject) => {
113
+ let state, demand;
114
+ try {
115
+ state = stateOf(this);
116
+ live(state);
117
+ if (state.reading || state.pending !== undefined)
118
+ throw new EgretError('TEXT_FIELD_BUSY');
119
+ if (state.desired === undefined)
120
+ throw new EgretError('TEXT_FIELD_UNPREPARED');
121
+ state.cache.assertOpen();
122
+ const controller = new CancellationController(diagnostic => {
123
+ state.cache.context.captureCleanup(diagnostic.cause);
124
+ state.cache.context.report(diagnostic);
125
+ });
126
+ demand = { revision: state.desiredRevision, controller, resolve, reject };
127
+ state.pending = demand;
128
+ const acquired = state.cache.acquire(state.desired, controller.signal);
129
+ void acquired
130
+ .then(result => {
131
+ let staged;
132
+ let ownsResult = result.kind === 'image';
133
+ try {
134
+ // A stale demand has already rejected; it can only retire its result.
135
+ if (state.pending !== demand) {
136
+ if (result.kind === 'image')
137
+ APPLY(RELEASE_LEASE, result.lease, []);
138
+ ownsResult = false;
139
+ return;
140
+ }
141
+ live(state);
142
+ state.cache.assertOpen();
143
+ if (state.desiredRevision !== demand.revision)
144
+ throw new EgretError('TEXT_FIELD_SUPERSEDED');
145
+ const metrics = copyMetrics(result.metrics);
146
+ let sourceRect;
147
+ if (result.kind === 'image')
148
+ sourceRect = FREEZE({ ...readBitmapImage(result.lease).sourceRect });
149
+ staged = FREEZE({
150
+ contentBounds: metrics.contentBounds,
151
+ raster: metrics.raster === undefined
152
+ ? undefined
153
+ : FREEZE({
154
+ x: metrics.raster.x,
155
+ y: metrics.raster.y,
156
+ width: metrics.raster.logicalWidth,
157
+ height: metrics.raster.logicalHeight
158
+ }),
159
+ lease: result.kind === 'image' ? result.lease : undefined,
160
+ sourceRect
161
+ });
162
+ live(state);
163
+ state.cache.assertOpen();
164
+ if (state.pending !== demand || state.desiredRevision !== demand.revision)
165
+ throw new EgretError('TEXT_FIELD_SUPERSEDED');
166
+ const previous = state.committed;
167
+ state.pending = undefined;
168
+ state.committed = staged;
169
+ state.metrics = metrics;
170
+ state.committedRevision = demand.revision;
171
+ publish(this, state);
172
+ ownsResult = false;
173
+ // Publication precedes old-lease cleanup; terminal reentry cannot roll it back.
174
+ release(previous);
175
+ demand.resolve(metrics);
176
+ }
177
+ catch (cause) {
178
+ if (state.pending === demand)
179
+ state.pending = undefined;
180
+ if (ownsResult && result.kind === 'image') {
181
+ try {
182
+ APPLY(RELEASE_LEASE, result.lease, []);
183
+ }
184
+ catch (cleanup) {
185
+ state.cache.context.captureCleanup(cleanup);
186
+ }
187
+ }
188
+ demand.reject(cause);
189
+ }
190
+ }, cause => {
191
+ if (state.pending === demand) {
192
+ state.pending = undefined;
193
+ demand.reject(cause);
194
+ }
195
+ })
196
+ .catch(cause => {
197
+ // A stale lease retirement can throw; observe and report without resurrecting demand.
198
+ state.cache.context.captureCleanup(cause);
199
+ state.cache.context.report({
200
+ code: 'TEXT_FIELD_CLEANUP_FAILED',
201
+ phase: 'assets',
202
+ severity: 'error',
203
+ cause
204
+ });
205
+ });
206
+ }
207
+ catch (cause) {
208
+ reject(cause);
209
+ }
210
+ });
211
+ }
212
+ getStatus() {
213
+ const state = stateOf(this);
214
+ return FREEZE({
215
+ state: state.disposed ? 'disposed' : state.committedRevision === undefined ? 'unprepared' : 'ready',
216
+ desiredRevision: state.desiredRevision,
217
+ committedRevision: state.committedRevision,
218
+ pending: state.pending !== undefined,
219
+ metrics: state.metrics
220
+ });
221
+ }
222
+ dispose() {
223
+ const state = stateOf(this);
224
+ if (state.disposed)
225
+ return;
226
+ state.disposed = true;
227
+ const pending = state.pending, committed = state.committed;
228
+ state.pending = undefined;
229
+ state.committed = undefined;
230
+ state.desired = undefined;
231
+ publish(this, state);
232
+ let failed = false, first;
233
+ const attempt = (action) => {
234
+ try {
235
+ action();
236
+ }
237
+ catch (cause) {
238
+ if (!failed) {
239
+ failed = true;
240
+ first = cause;
241
+ }
242
+ }
243
+ };
244
+ // Terminate the display before any cancellation/release callback can reenter it.
245
+ attempt(() => {
246
+ APPLY(DISPOSE_DISPLAY, this, []);
247
+ });
248
+ attempt(() => {
249
+ cancel(pending, new EgretError('TEXT_FIELD_DISPOSED'));
250
+ });
251
+ attempt(() => {
252
+ release(committed);
253
+ });
254
+ if (failed)
255
+ throw first;
256
+ }
257
+ }
258
+ export function createTextFieldLeaf(scope, cache) {
259
+ return new TextFieldLeaf(scope, cache, CREATION_TOKEN);
260
+ }
261
+ //# sourceMappingURL=TextField.js.map
@@ -0,0 +1,5 @@
1
+ import type { AssetManager } from '../AssetManager.js';
2
+ import type { TextRasterCache, TextRasterCacheOptions } from './types.js';
3
+ /** Explicit CPU text orchestration; this entry owns no browser font or drawing surface. */
4
+ export declare function createTextRasterCache(assets: AssetManager, options: TextRasterCacheOptions): TextRasterCache;
5
+ //# sourceMappingURL=TextRasterCache.d.ts.map