@egret/runtime 0.0.0-stage → 7.0.1-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) 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 +56 -0
  8. package/dist/AssetManager.js +451 -0
  9. package/dist/AssetRef.d.ts +20 -0
  10. package/dist/AssetRef.js +32 -0
  11. package/dist/Bitmap.d.ts +40 -0
  12. package/dist/Bitmap.js +545 -0
  13. package/dist/ByteReader.d.ts +30 -0
  14. package/dist/ByteReader.js +177 -0
  15. package/dist/ByteWriter.d.ts +29 -0
  16. package/dist/ByteWriter.js +180 -0
  17. package/dist/CancellationController.d.ts +10 -0
  18. package/dist/CancellationController.js +66 -0
  19. package/dist/DisplayObject.d.ts +89 -0
  20. package/dist/DisplayObject.js +340 -0
  21. package/dist/DisplayObjectContainer.d.ts +28 -0
  22. package/dist/DisplayObjectContainer.js +226 -0
  23. package/dist/EgretError.d.ts +11 -0
  24. package/dist/EgretError.js +36 -0
  25. package/dist/Event.d.ts +45 -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 +106 -0
  30. package/dist/Graphics.js +504 -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 +18 -0
  36. package/dist/NineSliceGeometry2D.js +126 -0
  37. package/dist/Scope.d.ts +18 -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 +29 -0
  46. package/dist/Texture.js +177 -0
  47. package/dist/assetManagerOwnerState.d.ts +36 -0
  48. package/dist/assetManagerOwnerState.js +115 -0
  49. package/dist/assetState.d.ts +44 -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 +74 -0
  74. package/dist/displayVisualState.js +140 -0
  75. package/dist/errorHelp.d.ts +14 -0
  76. package/dist/errorHelp.js +432 -0
  77. package/dist/errorHelpZh.d.ts +5 -0
  78. package/dist/errorHelpZh.js +340 -0
  79. package/dist/graphicsFill.d.ts +37 -0
  80. package/dist/graphicsFill.js +302 -0
  81. package/dist/graphicsShape.d.ts +144 -0
  82. package/dist/graphicsShape.js +755 -0
  83. package/dist/index.d.ts +50 -0
  84. package/dist/index.js +28 -0
  85. package/dist/input/PointerRouter.d.ts +4 -0
  86. package/dist/input/PointerRouter.js +453 -0
  87. package/dist/input/index.d.ts +3 -0
  88. package/dist/input/index.js +3 -0
  89. package/dist/input/types.d.ts +58 -0
  90. package/dist/input/types.js +3 -0
  91. package/dist/meshCaptureSnapshot.d.ts +5 -0
  92. package/dist/meshCaptureSnapshot.js +13 -0
  93. package/dist/meshDisplayState.d.ts +18 -0
  94. package/dist/meshDisplayState.js +21 -0
  95. package/dist/ownership.d.ts +75 -0
  96. package/dist/ownership.js +157 -0
  97. package/dist/paragraph/Paragraph.d.ts +13 -0
  98. package/dist/paragraph/Paragraph.js +193 -0
  99. package/dist/paragraph/ParagraphCache.d.ts +5 -0
  100. package/dist/paragraph/ParagraphCache.js +354 -0
  101. package/dist/paragraph/geometry.d.ts +4 -0
  102. package/dist/paragraph/geometry.js +180 -0
  103. package/dist/paragraph/index.d.ts +3 -0
  104. package/dist/paragraph/index.js +3 -0
  105. package/dist/paragraph/request.d.ts +6 -0
  106. package/dist/paragraph/request.js +191 -0
  107. package/dist/paragraph/types.d.ts +183 -0
  108. package/dist/paragraph/types.js +2 -0
  109. package/dist/preparedDisplaySubtree.d.ts +7 -0
  110. package/dist/preparedDisplaySubtree.js +205 -0
  111. package/dist/renderEffect.d.ts +47 -0
  112. package/dist/renderEffect.js +87 -0
  113. package/dist/sequenceClip.d.ts +42 -0
  114. package/dist/sequenceClip.js +196 -0
  115. package/dist/sharedFrameCapture.d.ts +24 -0
  116. package/dist/sharedFrameCapture.js +1069 -0
  117. package/dist/spriteSheet.d.ts +34 -0
  118. package/dist/spriteSheet.js +321 -0
  119. package/dist/srgbBytes.d.ts +3 -0
  120. package/dist/srgbBytes.js +64 -0
  121. package/dist/text/TextField.d.ts +13 -0
  122. package/dist/text/TextField.js +261 -0
  123. package/dist/text/TextRasterCache.d.ts +5 -0
  124. package/dist/text/TextRasterCache.js +1191 -0
  125. package/dist/text/budget.d.ts +51 -0
  126. package/dist/text/budget.js +116 -0
  127. package/dist/text/index.d.ts +4 -0
  128. package/dist/text/index.js +3 -0
  129. package/dist/text/plan.d.ts +16 -0
  130. package/dist/text/plan.js +238 -0
  131. package/dist/text/request.d.ts +44 -0
  132. package/dist/text/request.js +303 -0
  133. package/dist/text/types.d.ts +179 -0
  134. package/dist/text/types.js +2 -0
  135. package/dist/textDisplayState.d.ts +21 -0
  136. package/dist/textDisplayState.js +27 -0
  137. package/dist/ui/displayCommit.d.ts +43 -0
  138. package/dist/ui/displayCommit.js +376 -0
  139. package/dist/ui/editing.d.ts +3 -0
  140. package/dist/ui/editing.js +3 -0
  141. package/dist/ui/heightIndex.d.ts +35 -0
  142. package/dist/ui/heightIndex.js +295 -0
  143. package/dist/ui/index.d.ts +6 -0
  144. package/dist/ui/index.js +6 -0
  145. package/dist/ui/layout.d.ts +9 -0
  146. package/dist/ui/layout.js +349 -0
  147. package/dist/ui/managedState.d.ts +12 -0
  148. package/dist/ui/managedState.js +44 -0
  149. package/dist/ui/textEditState.d.ts +4 -0
  150. package/dist/ui/textEditState.js +206 -0
  151. package/dist/ui/textEditTypes.d.ts +48 -0
  152. package/dist/ui/textEditTypes.js +2 -0
  153. package/dist/ui/types.d.ts +99 -0
  154. package/dist/ui/types.js +2 -0
  155. package/package.json +44 -4
@@ -0,0 +1,191 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { EgretError } from '../EgretError.js';
3
+ import { isImageData2D } from '@egret/contracts';
4
+ function number(value, min, max) {
5
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max)
6
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
7
+ return value === 0 ? 0 : value;
8
+ }
9
+ function text(value, max, empty = false) {
10
+ if (typeof value !== 'string' || value.length > max || (!empty && !value.length))
11
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
12
+ return value;
13
+ }
14
+ function families(value) {
15
+ if (!Array.isArray(value))
16
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
17
+ const count = value.length;
18
+ if (!Number.isSafeInteger(count) || count < 1 || count > 16)
19
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
20
+ const result = [];
21
+ for (let index = 0; index < count; index++)
22
+ result.push(text(value[index], 256));
23
+ return Object.freeze(result);
24
+ }
25
+ function runs(value, source) {
26
+ if (value === undefined)
27
+ return undefined;
28
+ if (!Array.isArray(value))
29
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
30
+ const count = value.length;
31
+ // Bound caller-controlled counts before allocating or reading any element.
32
+ if (!Number.isSafeInteger(count) || count < 0 || count > 256)
33
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
34
+ if (count === 0)
35
+ return undefined;
36
+ const result = [];
37
+ let previous = 0;
38
+ const boundary = (offset) => {
39
+ const before = source.charCodeAt(offset - 1), after = source.charCodeAt(offset);
40
+ return (!(before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) && !(before === 13 && after === 10));
41
+ };
42
+ for (let index = 0; index < count; index++) {
43
+ const row = value[index];
44
+ if (row === null || typeof row !== 'object' || Array.isArray(row))
45
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
46
+ const start = number(row.start, previous, source.length), end = number(row.end, start, source.length);
47
+ if (!Number.isSafeInteger(start) ||
48
+ !Number.isSafeInteger(end) ||
49
+ start === end ||
50
+ !boundary(start) ||
51
+ !boundary(end))
52
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
53
+ const familyInput = row.fontFamilies, sizeInput = row.fontSize, colorInput = row.fillColor;
54
+ if (familyInput === undefined && sizeInput === undefined && colorInput === undefined)
55
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
56
+ const fontFamilies = familyInput === undefined ? undefined : families(familyInput);
57
+ const fontSize = sizeInput === undefined ? undefined : number(sizeInput, 1, 512);
58
+ const fillColor = colorInput === undefined ? undefined : number(colorInput, 0, 0xffffff);
59
+ if (fillColor !== undefined && !Number.isInteger(fillColor))
60
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
61
+ result.push(Object.freeze({
62
+ start,
63
+ end,
64
+ ...(fontFamilies === undefined ? {} : { fontFamilies }),
65
+ ...(fontSize === undefined ? {} : { fontSize }),
66
+ ...(fillColor === undefined ? {} : { fillColor })
67
+ }));
68
+ previous = end;
69
+ }
70
+ return Object.freeze(result);
71
+ }
72
+ /** Snapshot caller values before queueing: later request/style mutations have no authority. */
73
+ export function snapshotParagraphRequest(input) {
74
+ if (input === null || typeof input !== 'object')
75
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
76
+ const source = text(input.text, 8192, true), width = number(input.width, 0.25, 4096);
77
+ const fontFamilies = families(input.fontFamilies);
78
+ const fontSize = number(input.fontSize, 1, 512), lineHeightInput = input.lineHeight;
79
+ const lineHeight = lineHeightInput === undefined ? undefined : number(lineHeightInput, 1, 1024);
80
+ const locale = text(input.locale, 64), direction = input.direction;
81
+ const authoredAlign = input.textAlign;
82
+ if (authoredAlign !== undefined && !['left', 'right', 'center', 'start', 'end', 'justify'].includes(authoredAlign))
83
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
84
+ // Keep the original canonical request and cache key for an explicit left default.
85
+ const textAlign = authoredAlign === 'left' ? undefined : authoredAlign;
86
+ const geometryInput = input.textGeometry;
87
+ if (geometryInput !== undefined && typeof geometryInput !== 'boolean')
88
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
89
+ const textGeometry = geometryInput === true;
90
+ const authoredMaxLines = input.maxLines;
91
+ const maxLines = authoredMaxLines === undefined ? undefined : number(authoredMaxLines, 1, 8193);
92
+ if (maxLines !== undefined && !Number.isSafeInteger(maxLines))
93
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
94
+ const fillColor = number(input.fillColor, 0, 0xffffff), density = number(input.density, 0.25, 4);
95
+ if (!Number.isInteger(fillColor) ||
96
+ (direction !== 'ltr' && direction !== 'rtl') ||
97
+ /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(source))
98
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
99
+ // Reject ill-formed UTF16 rather than silently changing public source offsets.
100
+ for (let i = 0; i < source.length; i++) {
101
+ const unit = source.charCodeAt(i);
102
+ if (unit >= 0xd800 && unit <= 0xdbff) {
103
+ const low = source.charCodeAt(++i);
104
+ if (!(low >= 0xdc00 && low <= 0xdfff))
105
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
106
+ }
107
+ else if (unit >= 0xdc00 && unit <= 0xdfff)
108
+ throw new EgretError('PARAGRAPH_REQUEST_INVALID');
109
+ }
110
+ const styled = runs(input.runs, source);
111
+ const authoredFontSet = input.fontSet;
112
+ const fontSet = authoredFontSet === undefined ? undefined : text(authoredFontSet, 256);
113
+ return Object.freeze({
114
+ ...(fontSet === undefined ? {} : { fontSet }),
115
+ text: source,
116
+ width,
117
+ fontFamilies,
118
+ fontSize,
119
+ ...(lineHeight === undefined ? {} : { lineHeight }),
120
+ locale,
121
+ direction,
122
+ fillColor,
123
+ density,
124
+ ...(textAlign === undefined ? {} : { textAlign }),
125
+ ...(maxLines === undefined ? {} : { maxLines }),
126
+ ...(textGeometry ? { textGeometry: true } : {}),
127
+ ...(styled === undefined ? {} : { runs: styled })
128
+ });
129
+ }
130
+ /** Own public metrics; provider memory or mutable arrays never become committed UI state. */
131
+ export function snapshotParagraphRaster(value, request) {
132
+ try {
133
+ const metrics = value.metrics;
134
+ const authored = metrics.lines, count = authored.length;
135
+ if (metrics.width !== request.width ||
136
+ !Array.isArray(authored) ||
137
+ !Number.isSafeInteger(count) ||
138
+ count > 8193 ||
139
+ count < 0)
140
+ throw new Error('Invalid paragraph layout');
141
+ const height = number(metrics.height, 0, 1048576);
142
+ const truncated = request.maxLines === undefined ? undefined : metrics.truncated;
143
+ if (request.maxLines !== undefined &&
144
+ (count > request.maxLines || typeof truncated !== 'boolean' || (truncated && !request.text.length)))
145
+ throw new Error('Invalid paragraph line-clamp result');
146
+ let previous = 0, baseline = -1;
147
+ const copied = [];
148
+ for (let index = 0; index < count; index++) {
149
+ const line = authored[index];
150
+ const start = number(line.start, 0, request.text.length), end = number(line.end, start, request.text.length);
151
+ if (!Number.isInteger(start) || !Number.isInteger(end) || start < previous)
152
+ throw new Error('Invalid source range');
153
+ previous = end;
154
+ const y = number(line.baseline, 0, height + 1024);
155
+ if (y < baseline)
156
+ throw new Error('Invalid line order');
157
+ baseline = y;
158
+ copied.push(Object.freeze({
159
+ start,
160
+ end,
161
+ baseline: y,
162
+ ascent: number(line.ascent, 0, 1048576),
163
+ descent: number(line.descent, 0, 1048576),
164
+ height: number(line.height, 0, 1048576),
165
+ width: number(line.width, 0, 1048576)
166
+ }));
167
+ }
168
+ const lines = Object.freeze(copied);
169
+ const owned = Object.freeze({
170
+ width: request.width,
171
+ height,
172
+ lines,
173
+ ...(truncated === undefined ? {} : { truncated })
174
+ });
175
+ const image = value.image;
176
+ if (image !== undefined && !isImageData2D(image))
177
+ throw new Error('Invalid paragraph image');
178
+ const offsetX = number(value.offsetX, -1048576, 1048576), offsetY = number(value.offsetY, -1048576, 1048576);
179
+ return Object.freeze({
180
+ metrics: owned,
181
+ image,
182
+ offsetX,
183
+ offsetY,
184
+ ...(request.textGeometry ? { geometry: value.geometry } : {})
185
+ });
186
+ }
187
+ catch (cause) {
188
+ throw new EgretError('PARAGRAPH_PROVIDER_RESULT_INVALID', { cause });
189
+ }
190
+ }
191
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1,183 @@
1
+ import type { CancellationSignal, ImageData2D } from '@egret/contracts';
2
+ import type { AssetLease } from '../AssetLease.js';
3
+ import type { Texture } from '../Texture.js';
4
+ import type { DisplayObjectContainer } from '../DisplayObjectContainer.js';
5
+ export type ParagraphTextAffinity = 'upstream' | 'downstream';
6
+ export interface ParagraphTextBox {
7
+ readonly left: number;
8
+ readonly top: number;
9
+ readonly right: number;
10
+ readonly bottom: number;
11
+ }
12
+ export interface ParagraphTextCluster extends ParagraphTextBox {
13
+ readonly start: number;
14
+ readonly end: number;
15
+ readonly lineIndex: number;
16
+ readonly direction: 'ltr' | 'rtl';
17
+ }
18
+ export interface ParagraphTextLine extends ParagraphTextBox {
19
+ readonly start: number;
20
+ readonly end: number;
21
+ }
22
+ /** Provider data is copied before it acquires cache or committed-display authority. */
23
+ export interface ParagraphTextGeometryData {
24
+ readonly lines: readonly ParagraphTextLine[];
25
+ readonly clusters: readonly ParagraphTextCluster[];
26
+ }
27
+ export interface ParagraphTextCaret {
28
+ readonly offset: number;
29
+ readonly affinity: ParagraphTextAffinity;
30
+ readonly lineIndex: number;
31
+ readonly x: number;
32
+ readonly top: number;
33
+ readonly bottom: number;
34
+ }
35
+ export interface ParagraphTextHit extends ParagraphTextCaret {
36
+ readonly inside: boolean;
37
+ }
38
+ export interface ParagraphTextSelection extends ParagraphTextBox {
39
+ readonly start: number;
40
+ readonly end: number;
41
+ readonly lineIndex: number;
42
+ readonly direction: 'ltr' | 'rtl';
43
+ }
44
+ /** Detached logical coordinates, independent of raster guards and density. */
45
+ export interface ParagraphTextGeometry extends ParagraphTextGeometryData {
46
+ readonly text: string;
47
+ readonly storageBytes: number;
48
+ hitTest(x: number, y: number): ParagraphTextHit | undefined;
49
+ getCaret(offset: number, affinity?: ParagraphTextAffinity): ParagraphTextCaret | undefined;
50
+ getSelectionRects(start: number, end: number): readonly ParagraphTextSelection[];
51
+ }
52
+ export type ParagraphTextAlign = 'left' | 'right' | 'center' | 'start' | 'end' | 'justify';
53
+ /** Explicit opt-in: older providers continue to accept the original requests. */
54
+ export interface ParagraphProviderCapabilities {
55
+ readonly fontSets?: boolean;
56
+ readonly styledRuns?: boolean;
57
+ readonly textAlign?: boolean;
58
+ readonly textGeometry?: boolean;
59
+ readonly maxLines?: boolean;
60
+ }
61
+ /** Sorted, nonoverlapping UTF-16 [start, end); omitted fields inherit paragraph defaults. */
62
+ export interface ParagraphStyleRun {
63
+ readonly start: number;
64
+ readonly end: number;
65
+ readonly fontFamilies?: readonly string[];
66
+ readonly fontSize?: number;
67
+ readonly fillColor?: number;
68
+ }
69
+ export interface ParagraphRequestInput {
70
+ /** Immutable session key from a font-set provider; omission preserves fixed-font APIs. */
71
+ readonly fontSet?: string;
72
+ /** At most 256 nonempty ranges; gaps use paragraph defaults. Empty arrays are omitted. */
73
+ readonly runs?: readonly ParagraphStyleRun[];
74
+ readonly text: string;
75
+ readonly width: number;
76
+ readonly fontFamilies: readonly string[];
77
+ readonly fontSize: number;
78
+ /** Optional minimum logical line height; larger natural font metrics still win. */
79
+ readonly lineHeight?: number;
80
+ readonly locale: string;
81
+ readonly direction: 'ltr' | 'rtl';
82
+ readonly fillColor: number;
83
+ readonly density: number;
84
+ /** Omission preserves physical left alignment; start/end follow base direction. */
85
+ readonly textAlign?: ParagraphTextAlign;
86
+ /** At most this many lines; overflowing text uses the fixed U+2026 marker. */
87
+ readonly maxLines?: number;
88
+ /** Opt in to source hit/selection/caret geometry; omission keeps the old cache key. */
89
+ readonly textGeometry?: boolean;
90
+ }
91
+ export interface ParagraphRequest extends ParagraphRequestInput {
92
+ }
93
+ /** Source ranges are UTF16 [start, end), never glyph or UTF8 byte indices. */
94
+ export interface ParagraphLine {
95
+ readonly start: number;
96
+ readonly end: number;
97
+ readonly baseline: number;
98
+ readonly ascent: number;
99
+ readonly descent: number;
100
+ readonly height: number;
101
+ readonly width: number;
102
+ }
103
+ export interface ParagraphMetrics {
104
+ /** Logical wrapping width and layout height, independent of raster guards/density. */
105
+ readonly width: number;
106
+ readonly height: number;
107
+ readonly lines: readonly ParagraphLine[];
108
+ /** Present for a maxLines request; observed from the prepared native layout. */
109
+ readonly truncated?: boolean;
110
+ }
111
+ export interface ParagraphRaster {
112
+ readonly metrics: ParagraphMetrics;
113
+ readonly geometry?: ParagraphTextGeometryData;
114
+ readonly image: ImageData2D | undefined;
115
+ /** Logical placement of the density-scaled image, including signed ink bearings. */
116
+ readonly offsetX: number;
117
+ readonly offsetY: number;
118
+ }
119
+ export interface ParagraphProvider {
120
+ /** Immutable backend identity. Fixed providers also include their immutable fonts. */
121
+ readonly identity: string;
122
+ readonly capabilities?: ParagraphProviderCapabilities;
123
+ /** Required with fontSets; retired keys refuse even warm-cache demand. */
124
+ hasFontSet?(key: string): boolean;
125
+ prepare(request: ParagraphRequest, context: Readonly<{
126
+ signal: CancellationSignal;
127
+ }>): Promise<ParagraphRaster>;
128
+ }
129
+ export interface ParagraphCacheOptions {
130
+ readonly provider: ParagraphProvider;
131
+ readonly maxEntries?: number;
132
+ readonly maxImageBytes?: number;
133
+ /** Logical metadata accounting; independent from raster image bytes. */
134
+ readonly maxGeometryBytes?: number;
135
+ readonly maxPendingJobs?: number;
136
+ }
137
+ /** The genuine lease may be used by Bitmap; release it once the display retires. */
138
+ export interface PreparedParagraph {
139
+ readonly lease: AssetLease<Texture>;
140
+ readonly geometry?: ParagraphTextGeometry;
141
+ readonly metrics: ParagraphMetrics;
142
+ readonly offsetX: number;
143
+ readonly offsetY: number;
144
+ readonly density: number;
145
+ }
146
+ declare const cacheBrand: unique symbol;
147
+ export interface ParagraphCache {
148
+ readonly [cacheBrand]: true;
149
+ readonly profile: 'readonly-paragraph-v1';
150
+ acquire(request: ParagraphRequestInput, options?: Readonly<{
151
+ signal?: CancellationSignal;
152
+ }>): Promise<PreparedParagraph>;
153
+ /** Retire cached generations without invalidating already borrowed images. */
154
+ invalidate(): void;
155
+ getStatus(): Readonly<{
156
+ closed: boolean;
157
+ generation: number;
158
+ entries: number;
159
+ imageBytes: number;
160
+ geometryBytes: number;
161
+ pendingJobs: number;
162
+ callerLeases: number;
163
+ }>;
164
+ dispose(): void;
165
+ }
166
+ declare const paragraphBrand: unique symbol;
167
+ export interface ParagraphStatus {
168
+ readonly state: 'unprepared' | 'ready' | 'disposed';
169
+ readonly desiredRevision: number;
170
+ readonly committedRevision: number | undefined;
171
+ readonly pending: boolean;
172
+ readonly metrics: ParagraphMetrics | undefined;
173
+ readonly geometry?: ParagraphTextGeometry;
174
+ }
175
+ /** Scope-owned, readonly display container. UI bindings prepare it while detached. */
176
+ export interface Paragraph extends DisplayObjectContainer {
177
+ readonly [paragraphBrand]: true;
178
+ setRequest(request: ParagraphRequestInput): void;
179
+ prepare(): Promise<ParagraphMetrics>;
180
+ getStatus(): ParagraphStatus;
181
+ }
182
+ export {};
183
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ import type { Stage } from './Stage.js';
2
+ import type { EngineContext } from './ownership.js';
3
+ type Operations = Parameters<NonNullable<EngineContext['registerPreparedDisplayOperations']>>[0];
4
+ /** Genuine Stage assembly only. All tree overlays and publication tokens remain private. */
5
+ export declare function createPreparedDisplayOperations(stage: Stage): Operations;
6
+ export {};
7
+ //# sourceMappingURL=preparedDisplaySubtree.d.ts.map
@@ -0,0 +1,205 @@
1
+ import { engineOf, ownerOf } from './ownership.js';
2
+ import { Scope, isScope } from './Scope.js';
3
+ import { EgretError } from './EgretError.js';
4
+ import { assertContainer, childAtOf, childCountOf, isDisplayNode, isStageRoot, isTerminated, parentOf, publishPreparedChildren } from './displayTreeState.js';
5
+ import { visualOf } from './displayVisualState.js';
6
+ import { assertManagedChildrenMutable, assertManagedEdgeMutable } from './ui/managedState.js';
7
+ import { bitmapCaptureState, readBitmapImage } from './Bitmap.js';
8
+ import { readMeshState } from './meshDisplayState.js';
9
+ import { readMeshCaptureImage } from './meshCaptureSnapshot.js';
10
+ import { assertTextFieldScope, readTextFieldState } from './textDisplayState.js';
11
+ import { collectSubtreeSharedFrameContent } from './sharedFrameCapture.js';
12
+ const scopeState = Object.getOwnPropertyDescriptor(Scope.prototype, 'state').get;
13
+ const inherited = ['structureRevision', 'transformRevision', 'appearanceRevision', 'bindingRevision'];
14
+ const affected = [...inherited, 'contentRevision'];
15
+ function fault(code) {
16
+ throw new EgretError('DISPLAY_SUBTREE_' + code);
17
+ }
18
+ /** Genuine Stage assembly only. All tree overlays and publication tokens remain private. */
19
+ export function createPreparedDisplayOperations(stage) {
20
+ const engine = engineOf(stage);
21
+ const records = new WeakMap();
22
+ const pending = new Map();
23
+ function live(node) {
24
+ if (!isDisplayNode(node) || isTerminated(node) || engineOf(node) !== engine)
25
+ fault('NODE_INVALID');
26
+ ownership(node);
27
+ }
28
+ function ownership(node) {
29
+ const chain = [];
30
+ let owner = ownerOf(node);
31
+ while (owner !== undefined) {
32
+ if (chain.length >= 128 || chain.includes(owner))
33
+ fault('OWNER_INVALID');
34
+ chain.push(owner);
35
+ if (isScope(owner)) {
36
+ if (scopeState.call(owner) !== 'open')
37
+ fault('OWNER_CLOSED');
38
+ break;
39
+ }
40
+ owner = ownerOf(owner);
41
+ }
42
+ return chain;
43
+ }
44
+ function resource(node) {
45
+ const bitmap = bitmapCaptureState(node), mesh = readMeshState(node), text = readTextFieldState(node);
46
+ if (bitmap)
47
+ readBitmapImage(bitmap.lease);
48
+ if (mesh)
49
+ readMeshCaptureImage(mesh);
50
+ if (text) {
51
+ assertTextFieldScope(text.scope);
52
+ if (text.committed?.lease)
53
+ readBitmapImage(text.committed.lease);
54
+ }
55
+ }
56
+ function capture(node, full) {
57
+ live(node);
58
+ const keys = full ? affected : inherited, state = visualOf(node);
59
+ const children = full ? Array.from({ length: childCountOf(node) }, (_, i) => childAtOf(node, i)) : undefined;
60
+ if (full)
61
+ resource(node);
62
+ return {
63
+ node,
64
+ parent: parentOf(node),
65
+ owners: ownership(node),
66
+ keys,
67
+ revisions: keys.map(key => state[key]),
68
+ children
69
+ };
70
+ }
71
+ function validate(plan) {
72
+ engine.assertOpen();
73
+ for (const item of plan.captures) {
74
+ live(item.node);
75
+ const state = visualOf(item.node), owners = ownership(item.node);
76
+ if (parentOf(item.node) !== item.parent ||
77
+ owners.length !== item.owners.length ||
78
+ owners.some((owner, i) => owner !== item.owners[i]) ||
79
+ item.keys.some((key, i) => state[key] !== item.revisions[i]))
80
+ fault('STALE');
81
+ if (item.children) {
82
+ if (childCountOf(item.node) !== item.children.length)
83
+ fault('STALE');
84
+ for (let i = 0; i < item.children.length; i++)
85
+ if (childAtOf(item.node, i) !== item.children[i] || parentOf(item.children[i]) !== item.node)
86
+ fault('STALE');
87
+ resource(item.node);
88
+ }
89
+ }
90
+ assertManagedChildrenMutable(plan.target);
91
+ assertManagedEdgeMutable(plan.target, plan.candidate);
92
+ }
93
+ function read(token) {
94
+ engine.assertOpen();
95
+ const plan = records.get(token);
96
+ if (!plan || pending.get(plan.target) !== token)
97
+ fault('RETIRED');
98
+ validate(plan);
99
+ return plan;
100
+ }
101
+ function dispose(token) {
102
+ const plan = records.get(token);
103
+ records.delete(token);
104
+ if (plan && pending.get(plan.target) === token)
105
+ pending.delete(plan.target);
106
+ }
107
+ return Object.freeze({
108
+ prepare(target, candidate) {
109
+ engine.assertOpen();
110
+ live(target);
111
+ live(candidate);
112
+ assertContainer(target);
113
+ if (pending.size >= 32 && !pending.has(target))
114
+ fault('LIMIT');
115
+ if (isStageRoot(target) ||
116
+ isStageRoot(candidate) ||
117
+ target === candidate ||
118
+ parentOf(candidate) !== undefined ||
119
+ !isScope(ownerOf(target)) ||
120
+ !isScope(ownerOf(candidate)))
121
+ fault('ROOT_INVALID');
122
+ // Target plus candidate roots already consume two of the 4,096 node slots.
123
+ // Refuse before the managed-child check clones the target's direct list.
124
+ if (childCountOf(target) > 4094)
125
+ fault('LIMIT');
126
+ assertManagedChildrenMutable(target);
127
+ assertManagedEdgeMutable(target, candidate);
128
+ const captures = [], nodes = new Set();
129
+ function subtree(root) {
130
+ const stack = [{ node: root, depth: 1 }];
131
+ while (stack.length) {
132
+ const { node, depth } = stack.pop();
133
+ if (nodes.has(node))
134
+ fault('OVERLAP');
135
+ if (nodes.size >= 4096 || depth > 128)
136
+ fault('LIMIT');
137
+ live(node);
138
+ const count = childCountOf(node);
139
+ if (count > 4096 - nodes.size - stack.length - 1)
140
+ fault('LIMIT');
141
+ nodes.add(node);
142
+ const item = capture(node, true);
143
+ captures.push(item);
144
+ for (let i = count - 1; i >= 0; i--) {
145
+ const child = item.children[i];
146
+ if (parentOf(child) !== node)
147
+ fault('STALE');
148
+ stack.push({ node: child, depth: depth + 1 });
149
+ }
150
+ }
151
+ }
152
+ subtree(target);
153
+ subtree(candidate);
154
+ let ancestor = parentOf(target), depth = 0;
155
+ while (ancestor) {
156
+ if (++depth > 128)
157
+ fault('LIMIT');
158
+ if (nodes.has(ancestor))
159
+ fault('OVERLAP');
160
+ captures.push(capture(ancestor, false));
161
+ if (ancestor === stage)
162
+ break;
163
+ ancestor = parentOf(ancestor);
164
+ }
165
+ if (ancestor !== stage)
166
+ fault('TARGET_DETACHED');
167
+ for (const [other, token] of pending) {
168
+ if (other === target)
169
+ continue;
170
+ const plan = records.get(token);
171
+ if (captures.some(item => item.node === other))
172
+ fault('OVERLAP');
173
+ for (const node of nodes)
174
+ if (plan.nodes.has(node))
175
+ fault('OVERLAP');
176
+ }
177
+ const previous = captures[0].children, plan = { target, candidate, captures, nodes, previous, next: [candidate] };
178
+ validate(plan);
179
+ const token = Object.freeze({}), old = pending.get(target);
180
+ // A refused request never supersedes a previously admitted request.
181
+ if (old)
182
+ dispose(old);
183
+ records.set(token, plan);
184
+ pending.set(target, token);
185
+ return token;
186
+ },
187
+ validate(token) {
188
+ read(token);
189
+ },
190
+ capture(token) {
191
+ const plan = read(token);
192
+ const result = collectSubtreeSharedFrameContent(stage, plan.target, plan.candidate);
193
+ read(token);
194
+ return result;
195
+ },
196
+ commit(token) {
197
+ const plan = read(token);
198
+ // No callbacks, allocations or further admission after the complete validation pass.
199
+ publishPreparedChildren(plan.target, plan.previous, plan.next);
200
+ dispose(token);
201
+ },
202
+ dispose
203
+ });
204
+ }
205
+ //# sourceMappingURL=preparedDisplaySubtree.js.map
@@ -0,0 +1,47 @@
1
+ import type { Rectangle2D } from '@egret/contracts';
2
+ import type { Bitmap } from './Bitmap.js';
3
+ import type { DisplayObject } from './DisplayObject.js';
4
+ /** Render-only subtree effect. The mask borrows its Bitmap's existing texture lease.
5
+ * maskRect is in the affected node's local coordinates; mask display transforms
6
+ * and opacity do not apply. The mask is not removed from its own display tree. */
7
+ export interface RenderEffect2D {
8
+ readonly blurRadius?: number;
9
+ readonly alphaMask?: Bitmap;
10
+ readonly maskRect?: Rectangle2D;
11
+ /**
12
+ * Twenty numbers, as Egret's ColorMatrixFilter: four rows of red, green, blue and alpha, each four factors and an
13
+ * offset from 0 to 255. Applied to colour as it is seen, without its alpha multiplied in, after the blur.
14
+ */
15
+ readonly colorMatrix?: readonly number[];
16
+ /** A glow from the alpha of what is drawn, as Egret's GlowFilter; with an offset it is a drop shadow. */
17
+ readonly glow?: RenderGlow2D;
18
+ /** A hard line of a colour around what is drawn, a few pixels wide. One effect has a glow or an outline. */
19
+ readonly outline?: RenderOutline2D;
20
+ }
21
+ export interface RenderGlow2D {
22
+ /** 0xRRGGBB. */
23
+ readonly color: number;
24
+ /** 0 to 1; defaults to 1. */
25
+ readonly alpha?: number;
26
+ /** How far it spreads, 0 to 16 logical pixels; defaults to 6, as Egret's. */
27
+ readonly blur?: number;
28
+ /** What its spread alpha is multiplied by, 0 to 255; defaults to 2, as Egret's. */
29
+ readonly strength?: number;
30
+ /** Glow inside the edge instead of outside it. */
31
+ readonly inner?: boolean;
32
+ /** Show the glow alone, without what it glows around. */
33
+ readonly knockout?: boolean;
34
+ /** Where the glow is moved to, in logical pixels of the surface, -256 to 256: a drop shadow. */
35
+ readonly offsetX?: number;
36
+ readonly offsetY?: number;
37
+ }
38
+ export interface RenderOutline2D {
39
+ /** 0xRRGGBB. */
40
+ readonly color: number;
41
+ /** 1 to 8 logical pixels. */
42
+ readonly width: number;
43
+ /** 0 to 1; defaults to 1. */
44
+ readonly alpha?: number;
45
+ }
46
+ export declare function setRenderEffect(node: DisplayObject, input: RenderEffect2D | undefined): void;
47
+ //# sourceMappingURL=renderEffect.d.ts.map