@egret/runtime 0.0.0-stage → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +70 -2
- package/README.zh-CN.md +71 -0
- package/dist/AssetLease.d.ts +23 -0
- package/dist/AssetLease.js +69 -0
- package/dist/AssetManager.d.ts +58 -0
- package/dist/AssetManager.js +451 -0
- package/dist/AssetRef.d.ts +21 -0
- package/dist/AssetRef.js +33 -0
- package/dist/Bitmap.d.ts +40 -0
- package/dist/Bitmap.js +545 -0
- package/dist/ByteReader.d.ts +32 -0
- package/dist/ByteReader.js +178 -0
- package/dist/ByteWriter.d.ts +30 -0
- package/dist/ByteWriter.js +181 -0
- package/dist/CancellationController.d.ts +10 -0
- package/dist/CancellationController.js +66 -0
- package/dist/DisplayObject.d.ts +97 -0
- package/dist/DisplayObject.js +366 -0
- package/dist/DisplayObjectContainer.d.ts +28 -0
- package/dist/DisplayObjectContainer.js +226 -0
- package/dist/EgretError.d.ts +12 -0
- package/dist/EgretError.js +36 -0
- package/dist/Event.d.ts +47 -0
- package/dist/Event.js +84 -0
- package/dist/EventDispatcher.d.ts +24 -0
- package/dist/EventDispatcher.js +178 -0
- package/dist/Graphics.d.ts +117 -0
- package/dist/Graphics.js +548 -0
- package/dist/Mesh2D.d.ts +27 -0
- package/dist/Mesh2D.js +200 -0
- package/dist/NineSliceBitmap.d.ts +24 -0
- package/dist/NineSliceBitmap.js +164 -0
- package/dist/NineSliceGeometry2D.d.ts +19 -0
- package/dist/NineSliceGeometry2D.js +126 -0
- package/dist/Scope.d.ts +19 -0
- package/dist/Scope.js +133 -0
- package/dist/SequencePlayer.d.ts +12 -0
- package/dist/SequencePlayer.js +69 -0
- package/dist/Sprite.d.ts +8 -0
- package/dist/Sprite.js +12 -0
- package/dist/Stage.d.ts +14 -0
- package/dist/Stage.js +31 -0
- package/dist/Texture.d.ts +30 -0
- package/dist/Texture.js +178 -0
- package/dist/assetManagerOwnerState.d.ts +36 -0
- package/dist/assetManagerOwnerState.js +115 -0
- package/dist/assetState.d.ts +45 -0
- package/dist/assetState.js +2 -0
- package/dist/atlasFrameLayout.d.ts +21 -0
- package/dist/atlasFrameLayout.js +48 -0
- package/dist/bitmapDisplayState.d.ts +24 -0
- package/dist/bitmapDisplayState.js +22 -0
- package/dist/coordinateInverse.d.ts +4 -0
- package/dist/coordinateInverse.js +107 -0
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.js +13 -0
- package/dist/displayBounds.d.ts +9 -0
- package/dist/displayBounds.js +181 -0
- package/dist/displayCoordinates.d.ts +8 -0
- package/dist/displayCoordinates.js +81 -0
- package/dist/displayHitState.d.ts +18 -0
- package/dist/displayHitState.js +97 -0
- package/dist/displayHitTest.d.ts +8 -0
- package/dist/displayHitTest.js +219 -0
- package/dist/displayInputOperations.d.ts +12 -0
- package/dist/displayInputOperations.js +71 -0
- package/dist/displayTransform.d.ts +5 -0
- package/dist/displayTransform.js +38 -0
- package/dist/displayTreeState.d.ts +90 -0
- package/dist/displayTreeState.js +450 -0
- package/dist/displayVisualState.d.ts +76 -0
- package/dist/displayVisualState.js +141 -0
- package/dist/errorHelp.d.ts +15 -0
- package/dist/errorHelp.js +435 -0
- package/dist/errorHelpZh.d.ts +5 -0
- package/dist/errorHelpZh.js +342 -0
- package/dist/geometry.d.ts +173 -0
- package/dist/geometry.js +311 -0
- package/dist/graphicsFill.d.ts +37 -0
- package/dist/graphicsFill.js +302 -0
- package/dist/graphicsShape.d.ts +170 -0
- package/dist/graphicsShape.js +961 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +31 -0
- package/dist/input/PointerRouter.d.ts +4 -0
- package/dist/input/PointerRouter.js +453 -0
- package/dist/input/index.d.ts +3 -0
- package/dist/input/index.js +3 -0
- package/dist/input/types.d.ts +64 -0
- package/dist/input/types.js +3 -0
- package/dist/meshCaptureSnapshot.d.ts +5 -0
- package/dist/meshCaptureSnapshot.js +13 -0
- package/dist/meshDisplayState.d.ts +18 -0
- package/dist/meshDisplayState.js +21 -0
- package/dist/ownership.d.ts +75 -0
- package/dist/ownership.js +157 -0
- package/dist/paragraph/Paragraph.d.ts +13 -0
- package/dist/paragraph/Paragraph.js +193 -0
- package/dist/paragraph/ParagraphCache.d.ts +5 -0
- package/dist/paragraph/ParagraphCache.js +354 -0
- package/dist/paragraph/geometry.d.ts +4 -0
- package/dist/paragraph/geometry.js +180 -0
- package/dist/paragraph/index.d.ts +3 -0
- package/dist/paragraph/index.js +3 -0
- package/dist/paragraph/request.d.ts +6 -0
- package/dist/paragraph/request.js +191 -0
- package/dist/paragraph/types.d.ts +183 -0
- package/dist/paragraph/types.js +2 -0
- package/dist/preparedDisplaySubtree.d.ts +7 -0
- package/dist/preparedDisplaySubtree.js +205 -0
- package/dist/renderEffect.d.ts +57 -0
- package/dist/renderEffect.js +109 -0
- package/dist/sequenceClip.d.ts +48 -0
- package/dist/sequenceClip.js +197 -0
- package/dist/sharedFrameCapture.d.ts +24 -0
- package/dist/sharedFrameCapture.js +1128 -0
- package/dist/spriteSheet.d.ts +34 -0
- package/dist/spriteSheet.js +321 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/text/TextField.d.ts +13 -0
- package/dist/text/TextField.js +261 -0
- package/dist/text/TextRasterCache.d.ts +5 -0
- package/dist/text/TextRasterCache.js +1191 -0
- package/dist/text/budget.d.ts +51 -0
- package/dist/text/budget.js +116 -0
- package/dist/text/index.d.ts +4 -0
- package/dist/text/index.js +3 -0
- package/dist/text/plan.d.ts +16 -0
- package/dist/text/plan.js +238 -0
- package/dist/text/request.d.ts +44 -0
- package/dist/text/request.js +303 -0
- package/dist/text/types.d.ts +179 -0
- package/dist/text/types.js +2 -0
- package/dist/textDisplayState.d.ts +21 -0
- package/dist/textDisplayState.js +27 -0
- package/dist/ui/displayCommit.d.ts +43 -0
- package/dist/ui/displayCommit.js +384 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/heightIndex.d.ts +35 -0
- package/dist/ui/heightIndex.js +295 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +6 -0
- package/dist/ui/layout.d.ts +9 -0
- package/dist/ui/layout.js +349 -0
- package/dist/ui/managedState.d.ts +12 -0
- package/dist/ui/managedState.js +44 -0
- package/dist/ui/textEditState.d.ts +4 -0
- package/dist/ui/textEditState.js +206 -0
- package/dist/ui/textEditTypes.d.ts +48 -0
- package/dist/ui/textEditTypes.js +2 -0
- package/dist/ui/types.d.ts +99 -0
- package/dist/ui/types.js +2 -0
- package/package.json +44 -4
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { readBitmapState as bitmapCaptureState } from './bitmapDisplayState.js';
|
|
2
|
+
import { assertLive, isDisplayNode } from './displayTreeState.js';
|
|
3
|
+
import { engineOf } from './ownership.js';
|
|
4
|
+
import { assertVisualMutable, copyRect, visualOf, recordVisualChange, VISUAL_APPEARANCE } from './displayVisualState.js';
|
|
5
|
+
import { EgretError } from './EgretError.js';
|
|
6
|
+
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
7
|
+
const between = (value, low, high) => finite(value) && value >= low && value <= high;
|
|
8
|
+
const colour = (value) => Number.isSafeInteger(value) && value >= 0 && value <= 0xffffff;
|
|
9
|
+
const flag = (value) => {
|
|
10
|
+
if (value !== undefined && typeof value !== 'boolean')
|
|
11
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
12
|
+
return value === true;
|
|
13
|
+
};
|
|
14
|
+
function readMatrix(input) {
|
|
15
|
+
if (!Array.isArray(input) || input.length !== 20)
|
|
16
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
17
|
+
const copy = Array.from({ length: 20 }, (_, i) => {
|
|
18
|
+
const value = input[i];
|
|
19
|
+
if (!finite(value) || Math.abs(value) > 65536)
|
|
20
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
21
|
+
return value;
|
|
22
|
+
});
|
|
23
|
+
return Object.freeze(copy);
|
|
24
|
+
}
|
|
25
|
+
function readGlow(input) {
|
|
26
|
+
if (input === null || typeof input !== 'object')
|
|
27
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
28
|
+
const { color, alpha = 1, blur = 6, strength = 2, offsetX = 0, offsetY = 0 } = input, inner = flag(input.inner), knockout = flag(input.knockout);
|
|
29
|
+
if (!colour(color) ||
|
|
30
|
+
!between(alpha, 0, 1) ||
|
|
31
|
+
!between(blur, 0, 16) ||
|
|
32
|
+
!between(strength, 0, 255) ||
|
|
33
|
+
!between(offsetX, -256, 256) ||
|
|
34
|
+
!between(offsetY, -256, 256))
|
|
35
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
36
|
+
return Object.freeze({ color, alpha, blur, strength, inner, knockout, offsetX, offsetY });
|
|
37
|
+
}
|
|
38
|
+
function readOutline(input) {
|
|
39
|
+
if (input === null || typeof input !== 'object')
|
|
40
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
41
|
+
const { color, width, alpha = 1 } = input;
|
|
42
|
+
if (!colour(color) || !between(width, 1, 8) || !between(alpha, 0, 1))
|
|
43
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
44
|
+
return Object.freeze({ color, width, alpha });
|
|
45
|
+
}
|
|
46
|
+
export function setRenderEffect(node, input) {
|
|
47
|
+
assertVisualMutable(node);
|
|
48
|
+
let value;
|
|
49
|
+
if (input !== undefined) {
|
|
50
|
+
if (input === null || typeof input !== 'object')
|
|
51
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
52
|
+
const radius = input.blurRadius ?? 0, mask = input.alphaMask, rect = input.maskRect, shapeMask = input.shapeMask;
|
|
53
|
+
if (!Number.isInteger(radius) || radius < 0 || radius > 8)
|
|
54
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
55
|
+
let bounds;
|
|
56
|
+
if (mask !== undefined) {
|
|
57
|
+
if (!bitmapCaptureState(mask))
|
|
58
|
+
throw new EgretError('DISPLAY_EFFECT_MASK_INVALID');
|
|
59
|
+
assertLive(mask);
|
|
60
|
+
if (engineOf(mask) !== engineOf(node))
|
|
61
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
62
|
+
if (rect === undefined)
|
|
63
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
64
|
+
bounds = copyRect(rect, 'DISPLAY_EFFECT_INVALID');
|
|
65
|
+
if (bounds.width <= 0 || bounds.height <= 0)
|
|
66
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
67
|
+
}
|
|
68
|
+
else if (rect !== undefined)
|
|
69
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
70
|
+
if (shapeMask !== undefined) {
|
|
71
|
+
if (mask !== undefined || shapeMask === null || typeof shapeMask !== 'object' || !isDisplayNode(shapeMask))
|
|
72
|
+
throw new EgretError('DISPLAY_EFFECT_MASK_INVALID');
|
|
73
|
+
assertLive(shapeMask);
|
|
74
|
+
if (engineOf(shapeMask) !== engineOf(node))
|
|
75
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
76
|
+
if (shapeMask === node)
|
|
77
|
+
throw new EgretError('DISPLAY_EFFECT_MASK_INVALID');
|
|
78
|
+
}
|
|
79
|
+
const matrix = input.colorMatrix === undefined ? undefined : readMatrix(input.colorMatrix);
|
|
80
|
+
const glow = input.glow === undefined ? undefined : readGlow(input.glow), outline = input.outline === undefined ? undefined : readOutline(input.outline);
|
|
81
|
+
if (glow !== undefined && outline !== undefined)
|
|
82
|
+
throw new EgretError('DISPLAY_EFFECT_INVALID');
|
|
83
|
+
value = Object.freeze({
|
|
84
|
+
blurRadius: radius,
|
|
85
|
+
...(mask === undefined ? {} : { alphaMask: mask, maskRect: bounds }),
|
|
86
|
+
...(shapeMask === undefined ? {} : { shapeMask }),
|
|
87
|
+
...(matrix === undefined ? {} : { colorMatrix: matrix }),
|
|
88
|
+
...(glow === undefined ? {} : { glow }),
|
|
89
|
+
...(outline === undefined ? {} : { outline })
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// Descriptor reads may execute application getters; publish only after life recheck.
|
|
93
|
+
assertVisualMutable(node);
|
|
94
|
+
const state = visualOf(node), before = state.renderEffect?.shapeMask, after = value?.shapeMask;
|
|
95
|
+
state.renderEffect = value;
|
|
96
|
+
recordVisualChange(node, VISUAL_APPEARANCE);
|
|
97
|
+
// A node that becomes a mask stops being drawn; one no longer a mask of anything is drawn again.
|
|
98
|
+
if (before !== after) {
|
|
99
|
+
if (before !== undefined && !before.isDisposed) {
|
|
100
|
+
visualOf(before).maskUses--;
|
|
101
|
+
recordVisualChange(before, VISUAL_APPEARANCE);
|
|
102
|
+
}
|
|
103
|
+
if (after !== undefined) {
|
|
104
|
+
visualOf(after).maskUses++;
|
|
105
|
+
recordVisualChange(after, VISUAL_APPEARANCE);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=renderEffect.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AtlasFrameLayout } from './atlasFrameLayout.js';
|
|
2
|
+
/** One frame of a sequence to make: its rectangle on the atlas, how long it shows, and its trim and rotation. */
|
|
3
|
+
export interface SequenceFrameInput {
|
|
4
|
+
readonly layout?: AtlasFrameLayout;
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
readonly width: number;
|
|
8
|
+
readonly height: number;
|
|
9
|
+
readonly durationSeconds: number;
|
|
10
|
+
}
|
|
11
|
+
/** The atlas size and the frames of a sequence to make. */
|
|
12
|
+
export interface SequenceClipInput {
|
|
13
|
+
readonly atlasWidth: number;
|
|
14
|
+
readonly atlasHeight: number;
|
|
15
|
+
readonly frames: readonly SequenceFrameInput[];
|
|
16
|
+
}
|
|
17
|
+
/** Whether a sequence plays once and stops on its last frame, or loops. */
|
|
18
|
+
export type SequencePlaybackMode = 'once' | 'loop';
|
|
19
|
+
/** Public immutable sequence metadata; authentic values come from createSequenceClip. */
|
|
20
|
+
export interface SequenceClip {
|
|
21
|
+
readonly atlasWidth: number;
|
|
22
|
+
readonly atlasHeight: number;
|
|
23
|
+
readonly frameCount: number;
|
|
24
|
+
readonly durationSeconds: number;
|
|
25
|
+
}
|
|
26
|
+
/** The rectangle of the atlas a sequence shows at one moment, with its trim and rotation. */
|
|
27
|
+
export interface SequenceRegion {
|
|
28
|
+
readonly layout?: AtlasFrameLayout;
|
|
29
|
+
readonly x: number;
|
|
30
|
+
readonly y: number;
|
|
31
|
+
readonly width: number;
|
|
32
|
+
readonly height: number;
|
|
33
|
+
}
|
|
34
|
+
/** What a sequence shows at a position: its frame and region, and whether it has reached its end or stopped. */
|
|
35
|
+
export interface SequenceSample {
|
|
36
|
+
readonly frameIndex: number;
|
|
37
|
+
readonly region: SequenceRegion;
|
|
38
|
+
readonly positionSeconds: number;
|
|
39
|
+
readonly atEnd: boolean;
|
|
40
|
+
readonly stopped: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Checks and freezes a sequence from its atlas size and frames; malformed input is refused. */
|
|
43
|
+
export declare function createSequenceClip(input: unknown, profile?: 'trim-rotation-v1'): SequenceClip;
|
|
44
|
+
export declare function sampleSequenceClip(clip: SequenceClip, elapsedSeconds: number, options: {
|
|
45
|
+
readonly mode: 'once' | 'loop';
|
|
46
|
+
readonly stopAtSeconds?: number;
|
|
47
|
+
}): SequenceSample;
|
|
48
|
+
//# sourceMappingURL=sequenceClip.d.ts.map
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { captureAtlasFrameLayout, copyAtlasFrameLayout } from './atlasFrameLayout.js';
|
|
2
|
+
class SequenceClipError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, cause) {
|
|
5
|
+
super(code, { cause });
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = 'SequenceClipError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const MAX_FRAMES = 1024;
|
|
11
|
+
// Identity comes only from this module. Copies and proxies never gain authority,
|
|
12
|
+
// and the private value retains no caller object, array, clock or image resource.
|
|
13
|
+
const clips = new WeakMap();
|
|
14
|
+
function admitObject(value) {
|
|
15
|
+
if (typeof value !== 'object' || value === null)
|
|
16
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
17
|
+
let array;
|
|
18
|
+
// Catch only the source admission operation. Preserve its actual cause;
|
|
19
|
+
// never recreate a revoked proxy's native exception with a second probe.
|
|
20
|
+
try {
|
|
21
|
+
array = Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
catch (cause) {
|
|
24
|
+
throw new SequenceClipError('SEQ_READ_FAILED', cause);
|
|
25
|
+
}
|
|
26
|
+
if (array)
|
|
27
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function admitFrames(value) {
|
|
31
|
+
let array;
|
|
32
|
+
try {
|
|
33
|
+
array = Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
catch (cause) {
|
|
36
|
+
throw new SequenceClipError('SEQ_READ_FAILED', cause);
|
|
37
|
+
}
|
|
38
|
+
if (!array)
|
|
39
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function captureOwn(source, key) {
|
|
43
|
+
let present, value = undefined;
|
|
44
|
+
try {
|
|
45
|
+
present = Object.hasOwn(source, key);
|
|
46
|
+
if (present)
|
|
47
|
+
value = source[key];
|
|
48
|
+
}
|
|
49
|
+
catch (cause) {
|
|
50
|
+
// Never classify caller throws by their name, class or code. This wrapper
|
|
51
|
+
// preserves the actual occurrence and exact cause, including throw undefined.
|
|
52
|
+
throw new SequenceClipError('SEQ_READ_FAILED', cause);
|
|
53
|
+
}
|
|
54
|
+
return { present, value };
|
|
55
|
+
}
|
|
56
|
+
function positiveSafeInteger(value) {
|
|
57
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
58
|
+
}
|
|
59
|
+
function nonnegativeSafeInteger(value) {
|
|
60
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
61
|
+
}
|
|
62
|
+
function nonnegativeFinite(value) {
|
|
63
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
64
|
+
}
|
|
65
|
+
function positiveZero(value) {
|
|
66
|
+
return value === 0 ? 0 : value;
|
|
67
|
+
}
|
|
68
|
+
/** Checks and freezes a sequence from its atlas size and frames; malformed input is refused. */
|
|
69
|
+
export function createSequenceClip(input, profile) {
|
|
70
|
+
const source = admitObject(input);
|
|
71
|
+
if (profile !== undefined && profile !== 'trim-rotation-v1')
|
|
72
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
73
|
+
// Capture all required own fields in order before interpreting their values.
|
|
74
|
+
// Missing fields do not suppress a later source fault in this capture stage.
|
|
75
|
+
const widthField = captureOwn(source, 'atlasWidth');
|
|
76
|
+
const heightField = captureOwn(source, 'atlasHeight');
|
|
77
|
+
const framesField = captureOwn(source, 'frames');
|
|
78
|
+
const frames = admitFrames(framesField.value);
|
|
79
|
+
const lengthField = captureOwn(frames, 'length');
|
|
80
|
+
const length = lengthField.value;
|
|
81
|
+
if (!framesField.present || !lengthField.present || !positiveSafeInteger(length))
|
|
82
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
83
|
+
if (length > MAX_FRAMES)
|
|
84
|
+
throw new SequenceClipError('SEQ_BUDGET');
|
|
85
|
+
const atlasWidth = widthField.value, atlasHeight = heightField.value;
|
|
86
|
+
if (!widthField.present ||
|
|
87
|
+
!heightField.present ||
|
|
88
|
+
!positiveSafeInteger(atlasWidth) ||
|
|
89
|
+
!positiveSafeInteger(atlasHeight))
|
|
90
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
91
|
+
const regions = [], ends = [];
|
|
92
|
+
let durationSeconds = 0;
|
|
93
|
+
for (let index = 0; index < length; index++) {
|
|
94
|
+
const entry = captureOwn(frames, String(index));
|
|
95
|
+
if (!entry.present)
|
|
96
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
97
|
+
const frame = admitObject(entry.value);
|
|
98
|
+
const xField = captureOwn(frame, 'x');
|
|
99
|
+
const yField = captureOwn(frame, 'y');
|
|
100
|
+
const frameWidthField = captureOwn(frame, 'width');
|
|
101
|
+
const frameHeightField = captureOwn(frame, 'height');
|
|
102
|
+
const durationField = captureOwn(frame, 'durationSeconds');
|
|
103
|
+
const capturedLayout = profile === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: captureAtlasFrameLayout(frame, captureOwn, callback => {
|
|
106
|
+
try {
|
|
107
|
+
return callback();
|
|
108
|
+
}
|
|
109
|
+
catch (cause) {
|
|
110
|
+
throw new SequenceClipError('SEQ_READ_FAILED', cause);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
if (!xField.present ||
|
|
114
|
+
!yField.present ||
|
|
115
|
+
!frameWidthField.present ||
|
|
116
|
+
!frameHeightField.present ||
|
|
117
|
+
!durationField.present)
|
|
118
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
119
|
+
const x = xField.value, y = yField.value, width = frameWidthField.value, height = frameHeightField.value;
|
|
120
|
+
if (!nonnegativeSafeInteger(x) ||
|
|
121
|
+
!nonnegativeSafeInteger(y) ||
|
|
122
|
+
!positiveSafeInteger(width) ||
|
|
123
|
+
!positiveSafeInteger(height))
|
|
124
|
+
throw new SequenceClipError('SEQ_REGION_INVALID');
|
|
125
|
+
const right = x + width, bottom = y + height;
|
|
126
|
+
if (!Number.isSafeInteger(right) || !Number.isSafeInteger(bottom) || right > atlasWidth || bottom > atlasHeight)
|
|
127
|
+
throw new SequenceClipError('SEQ_REGION_INVALID');
|
|
128
|
+
const layout = capturedLayout === undefined
|
|
129
|
+
? undefined
|
|
130
|
+
: copyAtlasFrameLayout(capturedLayout, width, height, kind => {
|
|
131
|
+
throw new SequenceClipError(kind === 'shape' ? 'SEQ_INPUT_INVALID' : 'SEQ_REGION_INVALID');
|
|
132
|
+
});
|
|
133
|
+
const duration = durationField.value;
|
|
134
|
+
if (typeof duration !== 'number' || !Number.isFinite(duration) || duration <= 0)
|
|
135
|
+
throw new SequenceClipError('SEQ_TIME_INVALID');
|
|
136
|
+
// Seconds stay binary64, including positive subnormals. Each input-order
|
|
137
|
+
// increment must survive rounding; no integer-tick or float32 conversion.
|
|
138
|
+
const end = durationSeconds + duration;
|
|
139
|
+
if (!Number.isFinite(end) || end <= durationSeconds)
|
|
140
|
+
throw new SequenceClipError('SEQ_TIME_INVALID');
|
|
141
|
+
regions.push({
|
|
142
|
+
x: positiveZero(x),
|
|
143
|
+
y: positiveZero(y),
|
|
144
|
+
width,
|
|
145
|
+
height,
|
|
146
|
+
...(layout === undefined ? {} : { layout })
|
|
147
|
+
});
|
|
148
|
+
ends.push(end);
|
|
149
|
+
durationSeconds = end;
|
|
150
|
+
}
|
|
151
|
+
for (const region of regions)
|
|
152
|
+
Object.freeze(region);
|
|
153
|
+
const owned = Object.freeze({
|
|
154
|
+
regions: Object.freeze(regions),
|
|
155
|
+
ends: Object.freeze(ends),
|
|
156
|
+
durationSeconds
|
|
157
|
+
});
|
|
158
|
+
const clip = Object.freeze({ atlasWidth, atlasHeight, frameCount: length, durationSeconds });
|
|
159
|
+
// Publish identity only after all validation, owned allocation and freezing.
|
|
160
|
+
clips.set(clip, owned);
|
|
161
|
+
return clip;
|
|
162
|
+
}
|
|
163
|
+
export function sampleSequenceClip(clip, elapsedSeconds, options) {
|
|
164
|
+
const owned = typeof clip === 'object' && clip !== null ? clips.get(clip) : undefined;
|
|
165
|
+
if (!owned)
|
|
166
|
+
throw new SequenceClipError('SEQ_CLIP_INVALID');
|
|
167
|
+
if (!nonnegativeFinite(elapsedSeconds))
|
|
168
|
+
throw new SequenceClipError('SEQ_TIME_INVALID');
|
|
169
|
+
const source = admitObject(options);
|
|
170
|
+
const modeField = captureOwn(source, 'mode');
|
|
171
|
+
const stopField = captureOwn(source, 'stopAtSeconds');
|
|
172
|
+
const mode = modeField.value, stopAtSeconds = stopField.value;
|
|
173
|
+
if (!modeField.present || (mode !== 'once' && mode !== 'loop'))
|
|
174
|
+
throw new SequenceClipError('SEQ_INPUT_INVALID');
|
|
175
|
+
const stopped = stopField.present && stopAtSeconds !== undefined;
|
|
176
|
+
if (stopped && !nonnegativeFinite(stopAtSeconds))
|
|
177
|
+
throw new SequenceClipError('SEQ_TIME_INVALID');
|
|
178
|
+
const time = stopped ? stopAtSeconds : elapsedSeconds;
|
|
179
|
+
const atEnd = mode === 'once' && time >= owned.durationSeconds;
|
|
180
|
+
const positionSeconds = positiveZero(mode === 'loop' ? time % owned.durationSeconds : atEnd ? owned.durationSeconds : time);
|
|
181
|
+
let frameIndex = owned.ends.length - 1;
|
|
182
|
+
if (!atEnd) {
|
|
183
|
+
// Upper bound selects the first end strictly greater than the position.
|
|
184
|
+
// With 1..1024 ends this takes at most 11 comparisons, independent of cycles.
|
|
185
|
+
let low = 0, high = owned.ends.length;
|
|
186
|
+
while (low < high) {
|
|
187
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
188
|
+
if (positionSeconds < owned.ends[middle])
|
|
189
|
+
high = middle;
|
|
190
|
+
else
|
|
191
|
+
low = middle + 1;
|
|
192
|
+
}
|
|
193
|
+
frameIndex = low;
|
|
194
|
+
}
|
|
195
|
+
return Object.freeze({ frameIndex, region: owned.regions[frameIndex], positionSeconds, atEnd, stopped });
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=sequenceClip.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SharedGeometry2D, SharedMaterial2D, SharedPage2D, SharedRegion2D, SharedRenderCommand2D, TexturedGeometry2D } from '@egret/contracts';
|
|
2
|
+
import type { Stage } from './Stage.js';
|
|
3
|
+
import type { DisplayObject } from './DisplayObject.js';
|
|
4
|
+
import type { DisplayObjectContainer } from './DisplayObjectContainer.js';
|
|
5
|
+
import type { BitmapCaptureView } from './bitmapDisplayState.js';
|
|
6
|
+
export interface CapturedSharedContent2D {
|
|
7
|
+
readonly commands: readonly SharedRenderCommand2D[];
|
|
8
|
+
readonly pages: readonly SharedPage2D[];
|
|
9
|
+
readonly regions: readonly SharedRegion2D[];
|
|
10
|
+
readonly materials: readonly SharedMaterial2D[];
|
|
11
|
+
readonly geometries: readonly (TexturedGeometry2D | SharedGeometry2D)[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Iterative capture. All mutable owners stay inside this invocation, except what each node keeps of its own
|
|
15
|
+
* derived records.
|
|
16
|
+
*/
|
|
17
|
+
export declare function collectSharedFrameContent(stage: Stage): CapturedSharedContent2D;
|
|
18
|
+
/** The same capture with nothing kept read or written: every record is derived anew. Never forwarded by a package root. */
|
|
19
|
+
export declare function collectFreshSharedFrameContent(stage: Stage): CapturedSharedContent2D;
|
|
20
|
+
/** Runtime-private fixed Bitmap assembly; never forwarded by a package root. */
|
|
21
|
+
export declare function collectPreparedSharedFrameContent(stage: Stage, view: BitmapCaptureView): CapturedSharedContent2D;
|
|
22
|
+
/** Private single-edge overlay; ordinary capture always uses the unchanged live readers. */
|
|
23
|
+
export declare function collectSubtreeSharedFrameContent(stage: Stage, target: DisplayObjectContainer, candidate: DisplayObject): CapturedSharedContent2D;
|
|
24
|
+
//# sourceMappingURL=sharedFrameCapture.d.ts.map
|