@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,45 @@
|
|
|
1
|
+
import type { CancellationSignal } from "@egret/contracts";
|
|
2
|
+
import type { AssetLease } from "./AssetLease.js";
|
|
3
|
+
import type { AssetRef } from "./AssetRef.js";
|
|
4
|
+
import type { CancellationController } from "./CancellationController.js";
|
|
5
|
+
/** Erased callbacks stay inside the manager; public generics remain invariant. */
|
|
6
|
+
export interface ProviderBinding {
|
|
7
|
+
readonly load: (ref: AssetRef<never>, context: AssetLoadContext) => Promise<unknown>;
|
|
8
|
+
readonly dispose: (value: unknown) => void;
|
|
9
|
+
}
|
|
10
|
+
/** What a provider is given with each load: the signal that tells it the load is no longer wanted. */
|
|
11
|
+
export interface AssetLoadContext {
|
|
12
|
+
readonly signal: CancellationSignal;
|
|
13
|
+
readonly resourceGeneration: number;
|
|
14
|
+
readonly taskId: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Identity {
|
|
17
|
+
readonly type: object;
|
|
18
|
+
generation: number;
|
|
19
|
+
}
|
|
20
|
+
/** Installing is a transaction: detach waits until addEventListener has returned. */
|
|
21
|
+
export interface Waiter {
|
|
22
|
+
pending: boolean;
|
|
23
|
+
installing: boolean;
|
|
24
|
+
listening: boolean;
|
|
25
|
+
readonly signal: CancellationSignal | undefined;
|
|
26
|
+
readonly listener: () => void;
|
|
27
|
+
readonly resolve: (lease: AssetLease<unknown>) => void;
|
|
28
|
+
readonly reject: (cause: unknown) => void;
|
|
29
|
+
readonly entry: Entry;
|
|
30
|
+
}
|
|
31
|
+
export interface Entry {
|
|
32
|
+
readonly ref: AssetRef<never>;
|
|
33
|
+
readonly provider: ProviderBinding;
|
|
34
|
+
readonly controller: CancellationController;
|
|
35
|
+
readonly generation: number;
|
|
36
|
+
readonly taskId: number;
|
|
37
|
+
readonly waiters: Set<Waiter>;
|
|
38
|
+
readonly leases: Set<AssetLease<unknown>>;
|
|
39
|
+
state: "loading" | "ready" | "terminal";
|
|
40
|
+
started: boolean;
|
|
41
|
+
hasValue: boolean;
|
|
42
|
+
cleanupAttempted: boolean;
|
|
43
|
+
value: unknown;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=assetState.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Logical canvas and unpacked placement of a clockwise-packed atlas rectangle. */
|
|
2
|
+
export interface AtlasFrameLayout {
|
|
3
|
+
readonly sourceWidth: number;
|
|
4
|
+
readonly sourceHeight: number;
|
|
5
|
+
readonly trimX: number;
|
|
6
|
+
readonly trimY: number;
|
|
7
|
+
readonly packedRotation: 0 | 90;
|
|
8
|
+
}
|
|
9
|
+
interface Field {
|
|
10
|
+
readonly present: boolean;
|
|
11
|
+
readonly value: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface CapturedLayout {
|
|
14
|
+
readonly fields?: readonly Field[];
|
|
15
|
+
}
|
|
16
|
+
/** Capture only; each factory owns its staging and semantic scheduling. */
|
|
17
|
+
export declare function captureAtlasFrameLayout(frame: object, read: (source: object, key: string) => Field, operation: <T>(callback: () => T) => T): CapturedLayout;
|
|
18
|
+
/** Validate scalars and allocate a frozen owned copy, retaining no caller graph. */
|
|
19
|
+
export declare function copyAtlasFrameLayout(captured: CapturedLayout, width: number, height: number, reject: (kind: 'shape' | 'region') => never): AtlasFrameLayout;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=atlasFrameLayout.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const keys = ['sourceWidth', 'sourceHeight', 'trimX', 'trimY', 'packedRotation'];
|
|
2
|
+
/** Capture only; each factory owns its staging and semantic scheduling. */
|
|
3
|
+
export function captureAtlasFrameLayout(frame, read, operation) {
|
|
4
|
+
const field = read(frame, 'layout');
|
|
5
|
+
if (!field.present || field.value === null || typeof field.value !== 'object')
|
|
6
|
+
return {};
|
|
7
|
+
if (operation(() => Array.isArray(field.value)))
|
|
8
|
+
return {};
|
|
9
|
+
const source = field.value;
|
|
10
|
+
const fields = [];
|
|
11
|
+
for (const key of keys)
|
|
12
|
+
fields.push(read(source, key));
|
|
13
|
+
return { fields };
|
|
14
|
+
}
|
|
15
|
+
/** Validate scalars and allocate a frozen owned copy, retaining no caller graph. */
|
|
16
|
+
export function copyAtlasFrameLayout(captured, width, height, reject) {
|
|
17
|
+
const fields = captured.fields;
|
|
18
|
+
if (fields === undefined || fields.some(field => !field.present))
|
|
19
|
+
return reject('shape');
|
|
20
|
+
const values = fields.map(field => field.value);
|
|
21
|
+
const [sourceWidth, sourceHeight, trimX, trimY, packedRotation] = values;
|
|
22
|
+
if (typeof sourceWidth !== 'number' ||
|
|
23
|
+
!Number.isSafeInteger(sourceWidth) ||
|
|
24
|
+
sourceWidth <= 0 ||
|
|
25
|
+
typeof sourceHeight !== 'number' ||
|
|
26
|
+
!Number.isSafeInteger(sourceHeight) ||
|
|
27
|
+
sourceHeight <= 0 ||
|
|
28
|
+
typeof trimX !== 'number' ||
|
|
29
|
+
!Number.isSafeInteger(trimX) ||
|
|
30
|
+
trimX < 0 ||
|
|
31
|
+
typeof trimY !== 'number' ||
|
|
32
|
+
!Number.isSafeInteger(trimY) ||
|
|
33
|
+
trimY < 0 ||
|
|
34
|
+
(packedRotation !== 0 && packedRotation !== 90))
|
|
35
|
+
return reject('region');
|
|
36
|
+
const right = trimX + (packedRotation === 90 ? height : width);
|
|
37
|
+
const bottom = trimY + (packedRotation === 90 ? width : height);
|
|
38
|
+
if (!Number.isSafeInteger(right) || !Number.isSafeInteger(bottom) || right > sourceWidth || bottom > sourceHeight)
|
|
39
|
+
return reject('region');
|
|
40
|
+
return Object.freeze({
|
|
41
|
+
sourceWidth,
|
|
42
|
+
sourceHeight,
|
|
43
|
+
trimX: trimX === 0 ? 0 : trimX,
|
|
44
|
+
trimY: trimY === 0 ? 0 : trimY,
|
|
45
|
+
packedRotation: packedRotation === 0 ? 0 : 90
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=atlasFrameLayout.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AtlasFrameLayout } from './atlasFrameLayout.js';
|
|
2
|
+
import type { DisplayObject } from './DisplayObject.js';
|
|
3
|
+
import type { AssetLease } from './AssetLease.js';
|
|
4
|
+
import type { Texture } from './Texture.js';
|
|
5
|
+
import type { TextureRegion2D, TextureViewRegion2D } from '@egret/contracts';
|
|
6
|
+
export interface BitmapCaptureState {
|
|
7
|
+
readonly layout?: AtlasFrameLayout;
|
|
8
|
+
readonly lease: AssetLease<Texture>;
|
|
9
|
+
readonly sourceRect: TextureRegion2D;
|
|
10
|
+
readonly viewRegion: TextureViewRegion2D | null;
|
|
11
|
+
readonly width: number;
|
|
12
|
+
readonly height: number;
|
|
13
|
+
}
|
|
14
|
+
/** Call-local internal read view; it grants no lease or published-state authority. */
|
|
15
|
+
export interface BitmapCaptureView {
|
|
16
|
+
read(node: DisplayObject): BitmapCaptureState | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** A registered cleared slot remains different from an unregistered receiver. */
|
|
19
|
+
export declare function hasBitmapState(value: unknown): boolean;
|
|
20
|
+
/** Read cached metadata only; this port grants no live image entitlement. */
|
|
21
|
+
export declare function readBitmapState(node: DisplayObject): BitmapCaptureState | undefined;
|
|
22
|
+
/** Bitmap alone writes its slot, preserving existing mutation/lifetime guards. */
|
|
23
|
+
export declare function writeBitmapState(node: DisplayObject, value: BitmapCaptureState | undefined): void;
|
|
24
|
+
//# sourceMappingURL=bitmapDisplayState.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { recordVisualChange, VISUAL_CONTENT, VISUAL_BINDING } from './displayVisualState.js';
|
|
2
|
+
// One authoritative slot table, moved from Bitmap without duplicating geometry.
|
|
3
|
+
// Resource references remain type-only; revisions retain no resource ownership.
|
|
4
|
+
const states = new WeakMap();
|
|
5
|
+
const readPublishedState = states.get.bind(states);
|
|
6
|
+
/** A registered cleared slot remains different from an unregistered receiver. */
|
|
7
|
+
export function hasBitmapState(value) {
|
|
8
|
+
return states.has(value);
|
|
9
|
+
}
|
|
10
|
+
/** Read cached metadata only; this port grants no live image entitlement. */
|
|
11
|
+
export function readBitmapState(node) {
|
|
12
|
+
return states.get(node);
|
|
13
|
+
}
|
|
14
|
+
/** Bitmap alone writes its slot, preserving existing mutation/lifetime guards. */
|
|
15
|
+
export function writeBitmapState(node, value) {
|
|
16
|
+
const changed = readPublishedState(node) !== value;
|
|
17
|
+
states.set(node, value);
|
|
18
|
+
// Single writes, batch commits and conditional rollback share this publication.
|
|
19
|
+
if (changed)
|
|
20
|
+
recordVisualChange(node, VISUAL_CONTENT | VISUAL_BINDING);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=bitmapDisplayState.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Matrix2D, Point2D } from '@egret/contracts';
|
|
2
|
+
/** Exact rank belongs to the stored finite world matrix, not authored scales. */
|
|
3
|
+
export declare function invertCoordinatePoint(matrix: Matrix2D, x: number, y: number): Point2D;
|
|
4
|
+
//# sourceMappingURL=coordinateInverse.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { EgretError } from './EgretError.js';
|
|
2
|
+
const FRACTION_MASK = (1n << 52n) - 1n;
|
|
3
|
+
const MAX_BITS = 8192;
|
|
4
|
+
function magnitude(n) {
|
|
5
|
+
return n < 0n ? -n : n;
|
|
6
|
+
}
|
|
7
|
+
function bits(n) {
|
|
8
|
+
return n === 0n ? 0 : magnitude(n).toString(2).length;
|
|
9
|
+
}
|
|
10
|
+
function bounded(n) {
|
|
11
|
+
if (bits(n) > MAX_BITS)
|
|
12
|
+
throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
/** Finite binary64 is decoded exactly; both DataView operations use big endian. */
|
|
16
|
+
function decodeFiniteDyadic(value, view) {
|
|
17
|
+
view.setFloat64(0, value, false);
|
|
18
|
+
const raw = view.getBigUint64(0, false);
|
|
19
|
+
const encodedExponent = Number((raw >> 52n) & 0x7ffn);
|
|
20
|
+
const fraction = raw & FRACTION_MASK;
|
|
21
|
+
const integer = encodedExponent === 0 ? fraction : (1n << 52n) | fraction;
|
|
22
|
+
return {
|
|
23
|
+
integer: raw >> 63n === 0n ? integer : -integer,
|
|
24
|
+
exponent: encodedExponent === 0 ? -1074 : encodedExponent - 1075
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Only the fixed two/four inverse products are admitted, with no rounded sum. */
|
|
28
|
+
function sumDyadicProducts(terms) {
|
|
29
|
+
const products = terms.map(([left, right, sign]) => ({
|
|
30
|
+
integer: bounded(left.integer * right.integer * BigInt(sign)),
|
|
31
|
+
exponent: left.exponent + right.exponent
|
|
32
|
+
}));
|
|
33
|
+
const nonzero = products.filter(product => product.integer !== 0n);
|
|
34
|
+
if (nonzero.length === 0)
|
|
35
|
+
return { integer: 0n, exponent: 0 };
|
|
36
|
+
const exponent = Math.min(...nonzero.map(product => product.exponent));
|
|
37
|
+
let integer = 0n;
|
|
38
|
+
for (const product of nonzero) {
|
|
39
|
+
integer = bounded(integer + bounded(product.integer << BigInt(product.exponent - exponent)));
|
|
40
|
+
}
|
|
41
|
+
return { integer, exponent };
|
|
42
|
+
}
|
|
43
|
+
/** Round the exact rational once, including subnormal ties and overflow carry. */
|
|
44
|
+
function roundDyadicRatio(numerator, denominator) {
|
|
45
|
+
if (numerator.integer === 0n)
|
|
46
|
+
return 0;
|
|
47
|
+
const negative = numerator.integer < 0n !== denominator.integer < 0n;
|
|
48
|
+
let n = magnitude(numerator.integer);
|
|
49
|
+
let d = magnitude(denominator.integer);
|
|
50
|
+
let binaryExponent = bits(n) - bits(d);
|
|
51
|
+
if (binaryExponent >= 0) {
|
|
52
|
+
if (n < bounded(d << BigInt(binaryExponent)))
|
|
53
|
+
binaryExponent--;
|
|
54
|
+
}
|
|
55
|
+
else if (bounded(n << BigInt(-binaryExponent)) < d)
|
|
56
|
+
binaryExponent--;
|
|
57
|
+
const exponentDifference = numerator.exponent - denominator.exponent;
|
|
58
|
+
const k = binaryExponent + exponentDifference;
|
|
59
|
+
if (k > 1023)
|
|
60
|
+
throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
|
|
61
|
+
if (k < -1075)
|
|
62
|
+
return 0;
|
|
63
|
+
const quantum = k >= -1022 ? k - 52 : -1074;
|
|
64
|
+
const shift = exponentDifference - quantum;
|
|
65
|
+
if (shift >= 0)
|
|
66
|
+
n = bounded(n << BigInt(shift));
|
|
67
|
+
else
|
|
68
|
+
d = bounded(d << BigInt(-shift));
|
|
69
|
+
let significand = n / d;
|
|
70
|
+
const remainder = n % d;
|
|
71
|
+
const twiceRemainder = remainder << 1n;
|
|
72
|
+
if (twiceRemainder > d || (twiceRemainder === d && (significand & 1n) !== 0n))
|
|
73
|
+
significand++;
|
|
74
|
+
const result = Number(significand) * 2 ** quantum;
|
|
75
|
+
if (!Number.isFinite(result))
|
|
76
|
+
throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
|
|
77
|
+
return result === 0 ? 0 : negative ? -result : result;
|
|
78
|
+
}
|
|
79
|
+
/** Exact rank belongs to the stored finite world matrix, not authored scales. */
|
|
80
|
+
export function invertCoordinatePoint(matrix, x, y) {
|
|
81
|
+
const view = new DataView(new ArrayBuffer(8));
|
|
82
|
+
const a = decodeFiniteDyadic(matrix.a, view), b = decodeFiniteDyadic(matrix.b, view);
|
|
83
|
+
const c = decodeFiniteDyadic(matrix.c, view), d = decodeFiniteDyadic(matrix.d, view);
|
|
84
|
+
const tx = decodeFiniteDyadic(matrix.tx, view), ty = decodeFiniteDyadic(matrix.ty, view);
|
|
85
|
+
const gx = decodeFiniteDyadic(x, view), gy = decodeFiniteDyadic(y, view);
|
|
86
|
+
const determinant = sumDyadicProducts([
|
|
87
|
+
[a, d, 1],
|
|
88
|
+
[b, c, -1]
|
|
89
|
+
]);
|
|
90
|
+
if (determinant.integer === 0n)
|
|
91
|
+
throw new EgretError('COORDINATE_TRANSFORM_SINGULAR');
|
|
92
|
+
const nx = sumDyadicProducts([
|
|
93
|
+
[d, gx, 1],
|
|
94
|
+
[d, tx, -1],
|
|
95
|
+
[c, gy, -1],
|
|
96
|
+
[c, ty, 1]
|
|
97
|
+
]);
|
|
98
|
+
const ny = sumDyadicProducts([
|
|
99
|
+
[a, gy, 1],
|
|
100
|
+
[a, ty, -1],
|
|
101
|
+
[b, gx, -1],
|
|
102
|
+
[b, tx, 1]
|
|
103
|
+
]);
|
|
104
|
+
// Both coordinates finish before the caller can publish an owned point.
|
|
105
|
+
return { x: roundDyadicRatio(nx, determinant), y: roundDyadicRatio(ny, determinant) };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=coordinateInverse.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Diagnostic, DiagnosticHandler } from "@egret/contracts";
|
|
2
|
+
/** Observer failures have no authority to interrupt cancellation or cleanup. */
|
|
3
|
+
export declare function reportDiagnostic(handler: DiagnosticHandler | undefined, diagnostic: Diagnostic): void;
|
|
4
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Observer failures have no authority to interrupt cancellation or cleanup. */
|
|
2
|
+
export function reportDiagnostic(handler, diagnostic) {
|
|
3
|
+
try {
|
|
4
|
+
// Freeze the diagnostic envelope; application-owned cause objects stay borrowed.
|
|
5
|
+
handler?.(Object.freeze(diagnostic));
|
|
6
|
+
}
|
|
7
|
+
catch (cause) {
|
|
8
|
+
// The lifecycle failure remains in Diagnostic.cause / Engine's failure list.
|
|
9
|
+
// Do not call a failing observer recursively or replace the original failure.
|
|
10
|
+
void cause;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rectangle2D } from '@egret/contracts';
|
|
2
|
+
/** Receiver-inclusive node and content budgets for logical local measurement. */
|
|
3
|
+
export interface BoundsQueryOptions {
|
|
4
|
+
readonly maxNodes?: number;
|
|
5
|
+
readonly maxPrimitives?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Private state only: no display-class value import, resource lookup or public hook. */
|
|
8
|
+
export declare function queryDisplayBounds(receiver: unknown, options: unknown): Rectangle2D;
|
|
9
|
+
//# sourceMappingURL=displayBounds.d.ts.map
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { resolveShape } from './graphicsShape.js';
|
|
2
|
+
import { readBitmapState } from './bitmapDisplayState.js';
|
|
3
|
+
import { readMeshState } from './meshDisplayState.js';
|
|
4
|
+
import { assertTextFieldScope, readTextFieldState } from './textDisplayState.js';
|
|
5
|
+
import { assertLive, childAtOf, childCountOf, isDisplayNode, parentOf } from './displayTreeState.js';
|
|
6
|
+
import { composeDisplayTransform } from './displayTransform.js';
|
|
7
|
+
import { finite, visualOf } from './displayVisualState.js';
|
|
8
|
+
import { engineOf } from './ownership.js';
|
|
9
|
+
import { EgretError } from './EgretError.js';
|
|
10
|
+
function live(node) {
|
|
11
|
+
assertLive(node);
|
|
12
|
+
engineOf(node)?.assertOpen();
|
|
13
|
+
}
|
|
14
|
+
function budgetsOf(node, options) {
|
|
15
|
+
let nodes, primitives;
|
|
16
|
+
if (options !== undefined) {
|
|
17
|
+
if (options === null || typeof options !== 'object')
|
|
18
|
+
throw new EgretError('BOUNDS_INPUT_INVALID');
|
|
19
|
+
let array;
|
|
20
|
+
// Revoked Proxy admission can throw. Array rejection is a semantic failure
|
|
21
|
+
// outside the source catch, and normal lookup retains inherited getters.
|
|
22
|
+
try {
|
|
23
|
+
array = Array.isArray(options);
|
|
24
|
+
}
|
|
25
|
+
catch (cause) {
|
|
26
|
+
throw new EgretError('BOUNDS_INPUT_INVALID', { cause });
|
|
27
|
+
}
|
|
28
|
+
if (array)
|
|
29
|
+
throw new EgretError('BOUNDS_INPUT_INVALID');
|
|
30
|
+
try {
|
|
31
|
+
nodes = options.maxNodes;
|
|
32
|
+
primitives = options.maxPrimitives;
|
|
33
|
+
}
|
|
34
|
+
catch (cause) {
|
|
35
|
+
throw new EgretError('BOUNDS_INPUT_INVALID', { cause });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Finish both successful source reads before lifetime and numeric semantics.
|
|
39
|
+
// Throwing reads retain exact supplied causes, even after terminal side effects.
|
|
40
|
+
live(node);
|
|
41
|
+
const maxNodes = nodes === undefined ? 4096 : nodes;
|
|
42
|
+
const maxPrimitives = primitives === undefined ? 65536 : primitives;
|
|
43
|
+
if (!finite(maxNodes) || !Number.isInteger(maxNodes) || maxNodes < 1 || maxNodes > 65536) {
|
|
44
|
+
throw new EgretError('BOUNDS_INPUT_INVALID');
|
|
45
|
+
}
|
|
46
|
+
if (!finite(maxPrimitives) || !Number.isInteger(maxPrimitives) || maxPrimitives < 1 || maxPrimitives > 262144) {
|
|
47
|
+
throw new EgretError('BOUNDS_INPUT_INVALID');
|
|
48
|
+
}
|
|
49
|
+
return { maxNodes, maxPrimitives };
|
|
50
|
+
}
|
|
51
|
+
/** Private state only: no display-class value import, resource lookup or public hook. */
|
|
52
|
+
export function queryDisplayBounds(receiver, options) {
|
|
53
|
+
if (!isDisplayNode(receiver))
|
|
54
|
+
throw new EgretError('BOUNDS_RECEIVER_INVALID');
|
|
55
|
+
const node = receiver;
|
|
56
|
+
live(node);
|
|
57
|
+
const { maxNodes, maxPrimitives } = budgetsOf(node, options);
|
|
58
|
+
const seen = new Set(), visited = [], stack = [];
|
|
59
|
+
let items = 0, hasContent = false, minX = 0, minY = 0, maxX = 0, maxY = 0;
|
|
60
|
+
function admitItem() {
|
|
61
|
+
// Admission precedes indexing the next primitive's geometry or Bitmap size.
|
|
62
|
+
if (items >= maxPrimitives)
|
|
63
|
+
throw new EgretError('BOUNDS_CONTENT_LIMIT');
|
|
64
|
+
items++;
|
|
65
|
+
}
|
|
66
|
+
function point(matrix, x, y) {
|
|
67
|
+
const px = matrix.a * x + matrix.c * y + matrix.tx;
|
|
68
|
+
const py = matrix.b * x + matrix.d * y + matrix.ty;
|
|
69
|
+
if (!finite(px) || !finite(py))
|
|
70
|
+
throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
|
|
71
|
+
if (!hasContent) {
|
|
72
|
+
minX = maxX = px;
|
|
73
|
+
minY = maxY = py;
|
|
74
|
+
hasContent = true;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
minX = Math.min(minX, px);
|
|
78
|
+
minY = Math.min(minY, py);
|
|
79
|
+
maxX = Math.max(maxX, px);
|
|
80
|
+
maxY = Math.max(maxY, py);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function rectangle(matrix, x, y, width, height) {
|
|
84
|
+
// Authored zero extent consumes budget but does not evaluate endpoints.
|
|
85
|
+
// Positive content may still collapse to a point or line through rounding.
|
|
86
|
+
if (width === 0 || height === 0)
|
|
87
|
+
return;
|
|
88
|
+
const right = x + width, bottom = y + height;
|
|
89
|
+
if (!finite(right) || !finite(bottom))
|
|
90
|
+
throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
|
|
91
|
+
point(matrix, x, y);
|
|
92
|
+
point(matrix, right, y);
|
|
93
|
+
point(matrix, right, bottom);
|
|
94
|
+
point(matrix, x, bottom);
|
|
95
|
+
}
|
|
96
|
+
function enter(current, matrix) {
|
|
97
|
+
if (!isDisplayNode(current) || seen.has(current))
|
|
98
|
+
throw new EgretError('DISPLAY_TREE_INVARIANT');
|
|
99
|
+
live(current);
|
|
100
|
+
seen.add(current);
|
|
101
|
+
visited.push(current);
|
|
102
|
+
const primitives = visualOf(current).primitives;
|
|
103
|
+
for (let index = 0; index < primitives.length; index++) {
|
|
104
|
+
admitItem();
|
|
105
|
+
const rect = primitives[index].rect;
|
|
106
|
+
rectangle(matrix, rect.x, rect.y, rect.width, rect.height);
|
|
107
|
+
}
|
|
108
|
+
const shapeState = visualOf(current).shape, shape = shapeState === undefined ? undefined : resolveShape(shapeState);
|
|
109
|
+
if (shape !== undefined) {
|
|
110
|
+
admitItem();
|
|
111
|
+
rectangle(matrix, shape.bounds.x, shape.bounds.y, shape.bounds.width, shape.bounds.height);
|
|
112
|
+
}
|
|
113
|
+
const bitmap = readBitmapState(current);
|
|
114
|
+
if (bitmap !== undefined) {
|
|
115
|
+
admitItem();
|
|
116
|
+
rectangle(matrix, 0, 0, bitmap.width, bitmap.height);
|
|
117
|
+
}
|
|
118
|
+
const mesh = readMeshState(current);
|
|
119
|
+
if (mesh !== undefined) {
|
|
120
|
+
const geometry = mesh.geometry;
|
|
121
|
+
for (let triangle = 0; triangle < geometry.triangleCount; triangle++) {
|
|
122
|
+
// Debit before all three index reads; shared geometry still costs per use.
|
|
123
|
+
admitItem();
|
|
124
|
+
const offset = 3 * triangle;
|
|
125
|
+
const first = geometry.indices[offset], second = geometry.indices[offset + 1], third = geometry.indices[offset + 2];
|
|
126
|
+
// Logical bounds retain authored point/line triangles and skip unused XY.
|
|
127
|
+
point(matrix, geometry.positions[2 * first], geometry.positions[2 * first + 1]);
|
|
128
|
+
point(matrix, geometry.positions[2 * second], geometry.positions[2 * second + 1]);
|
|
129
|
+
point(matrix, geometry.positions[2 * third], geometry.positions[2 * third + 1]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const text = readTextFieldState(current);
|
|
133
|
+
if (text !== undefined) {
|
|
134
|
+
assertTextFieldScope(text.scope);
|
|
135
|
+
if (text.committed !== undefined) {
|
|
136
|
+
admitItem();
|
|
137
|
+
const rect = text.committed.contentBounds;
|
|
138
|
+
rectangle(matrix, rect.x, rect.y, rect.width, rect.height);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
stack.push({ node: current, matrix, children: childCountOf(current), nextChild: 0 });
|
|
142
|
+
}
|
|
143
|
+
// The receiver's frame is identity. Its own and all ancestor transforms are
|
|
144
|
+
// excluded, so no inverse or receiver/ancestor composition is evaluated.
|
|
145
|
+
enter(node, { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 });
|
|
146
|
+
while (stack.length !== 0) {
|
|
147
|
+
const frame = stack[stack.length - 1];
|
|
148
|
+
if (frame.nextChild === frame.children) {
|
|
149
|
+
stack.pop();
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
// Check before indexed retrieval: no eager child snapshot or sibling stack.
|
|
153
|
+
if (visited.length >= maxNodes)
|
|
154
|
+
throw new EgretError('BOUNDS_TREE_LIMIT');
|
|
155
|
+
const child = childAtOf(frame.node, frame.nextChild++);
|
|
156
|
+
if (child === undefined || !isDisplayNode(child) || seen.has(child) || parentOf(child) !== frame.node) {
|
|
157
|
+
throw new EgretError('DISPLAY_TREE_INVARIANT');
|
|
158
|
+
}
|
|
159
|
+
live(child);
|
|
160
|
+
const matrix = composeDisplayTransform(frame.matrix, visualOf(child));
|
|
161
|
+
// Completed descendant matrices are checked even for empty/zero-only nodes.
|
|
162
|
+
if (![matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty].every(finite)) {
|
|
163
|
+
throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
|
|
164
|
+
}
|
|
165
|
+
enter(child, matrix);
|
|
166
|
+
}
|
|
167
|
+
const width = hasContent ? maxX - minX : 0, height = hasContent ? maxY - minY : 0;
|
|
168
|
+
if (!finite(width) || !finite(height))
|
|
169
|
+
throw new EgretError('BOUNDS_ARITHMETIC_RANGE');
|
|
170
|
+
for (const current of visited)
|
|
171
|
+
live(current);
|
|
172
|
+
// Ordinary binary64 subtraction is intentional, not an outward enclosure.
|
|
173
|
+
// Saved output retains no authority, options, primitive or resource reference.
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
x: minX === 0 ? 0 : minX,
|
|
176
|
+
y: minY === 0 ? 0 : minY,
|
|
177
|
+
width: width === 0 ? 0 : width,
|
|
178
|
+
height: height === 0 ? 0 : height
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=displayBounds.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Point2D } from '@egret/contracts';
|
|
2
|
+
/** Receiver-inclusive ancestor budget; omitted maxNodes defaults to 4096. */
|
|
3
|
+
export interface CoordinateQueryOptions {
|
|
4
|
+
readonly maxNodes?: number;
|
|
5
|
+
}
|
|
6
|
+
/** Private identity/state authority excludes getters and subclass hooks. */
|
|
7
|
+
export declare function queryDisplayPoint(receiver: unknown, x: unknown, y: unknown, options: unknown, inverse: boolean): Point2D;
|
|
8
|
+
//# sourceMappingURL=displayCoordinates.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isDisplayNode, assertLive, parentOf } from './displayTreeState.js';
|
|
2
|
+
import { engineOf } from './ownership.js';
|
|
3
|
+
import { finite, visualOf } from './displayVisualState.js';
|
|
4
|
+
import { composeDisplayTransform } from './displayTransform.js';
|
|
5
|
+
import { invertCoordinatePoint } from './coordinateInverse.js';
|
|
6
|
+
import { EgretError } from './EgretError.js';
|
|
7
|
+
function live(node) {
|
|
8
|
+
assertLive(node);
|
|
9
|
+
engineOf(node)?.assertOpen();
|
|
10
|
+
}
|
|
11
|
+
function budgetOf(node, options) {
|
|
12
|
+
let requested;
|
|
13
|
+
if (options !== undefined) {
|
|
14
|
+
if (options === null || typeof options !== 'object')
|
|
15
|
+
throw new EgretError('COORDINATE_INPUT_INVALID');
|
|
16
|
+
let array;
|
|
17
|
+
// Admission can itself throw for a revoked Proxy; semantic rejection stays
|
|
18
|
+
// outside the source catch so it is never mistaken for an adapter failure.
|
|
19
|
+
try {
|
|
20
|
+
array = Array.isArray(options);
|
|
21
|
+
}
|
|
22
|
+
catch (cause) {
|
|
23
|
+
throw new EgretError('COORDINATE_INPUT_INVALID', { cause });
|
|
24
|
+
}
|
|
25
|
+
if (array)
|
|
26
|
+
throw new EgretError('COORDINATE_INPUT_INVALID');
|
|
27
|
+
try {
|
|
28
|
+
requested = options.maxNodes;
|
|
29
|
+
}
|
|
30
|
+
catch (cause) {
|
|
31
|
+
throw new EgretError('COORDINATE_INPUT_INVALID', { cause });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// A successful caller read may mutate, reparent, dispose or close the node.
|
|
35
|
+
// Throwing reads preserve their exact cause without this later recheck.
|
|
36
|
+
live(node);
|
|
37
|
+
const maxNodes = requested === undefined ? 4096 : requested;
|
|
38
|
+
if (!finite(maxNodes) || !Number.isInteger(maxNodes) || maxNodes < 1 || maxNodes > 65536) {
|
|
39
|
+
throw new EgretError('COORDINATE_INPUT_INVALID');
|
|
40
|
+
}
|
|
41
|
+
return maxNodes;
|
|
42
|
+
}
|
|
43
|
+
/** Private identity/state authority excludes getters and subclass hooks. */
|
|
44
|
+
export function queryDisplayPoint(receiver, x, y, options, inverse) {
|
|
45
|
+
if (!isDisplayNode(receiver))
|
|
46
|
+
throw new EgretError('COORDINATE_RECEIVER_INVALID');
|
|
47
|
+
const node = receiver;
|
|
48
|
+
live(node);
|
|
49
|
+
const px = x === undefined ? 0 : x, py = y === undefined ? 0 : y;
|
|
50
|
+
if (!finite(px) || !finite(py))
|
|
51
|
+
throw new EgretError('COORDINATE_INPUT_INVALID');
|
|
52
|
+
const maxNodes = budgetOf(node, options);
|
|
53
|
+
const path = [], seen = new Set();
|
|
54
|
+
for (let current = node; current !== undefined; current = parentOf(current)) {
|
|
55
|
+
if (path.length >= maxNodes)
|
|
56
|
+
throw new EgretError('COORDINATE_TREE_LIMIT');
|
|
57
|
+
if (seen.has(current))
|
|
58
|
+
throw new EgretError('DISPLAY_TREE_INVARIANT');
|
|
59
|
+
live(current);
|
|
60
|
+
seen.add(current);
|
|
61
|
+
path.push(current);
|
|
62
|
+
}
|
|
63
|
+
let world = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
64
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
65
|
+
world = composeDisplayTransform(world, visualOf(path[i]));
|
|
66
|
+
if (!Object.values(world).every(finite))
|
|
67
|
+
throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
|
|
68
|
+
}
|
|
69
|
+
const result = inverse
|
|
70
|
+
? invertCoordinatePoint(world, px, py)
|
|
71
|
+
: {
|
|
72
|
+
x: world.a * px + world.c * py + world.tx,
|
|
73
|
+
y: world.b * px + world.d * py + world.ty
|
|
74
|
+
};
|
|
75
|
+
if (!finite(result.x) || !finite(result.y))
|
|
76
|
+
throw new EgretError('COORDINATE_ARITHMETIC_RANGE');
|
|
77
|
+
for (const current of path)
|
|
78
|
+
live(current);
|
|
79
|
+
return Object.freeze({ x: result.x === 0 ? 0 : result.x, y: result.y === 0 ? 0 : result.y });
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=displayCoordinates.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rectangle2D } from '@egret/contracts';
|
|
2
|
+
import type { DisplayObject } from './DisplayObject.js';
|
|
3
|
+
interface DisplayHitState {
|
|
4
|
+
touchEnabled: boolean;
|
|
5
|
+
hitArea: Rectangle2D | undefined;
|
|
6
|
+
touchChildren: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function registerDisplayHitNode(node: DisplayObject): void;
|
|
9
|
+
export declare function registerDisplayHitContainer(node: DisplayObject): void;
|
|
10
|
+
/** Genuine identity is checked before any receiver property can be consulted. */
|
|
11
|
+
export declare function readDisplayHitState(receiver: unknown): DisplayHitState;
|
|
12
|
+
export declare function writeDisplayTouchEnabled(receiver: unknown, value: unknown): void;
|
|
13
|
+
export declare function readDisplayTouchChildren(receiver: unknown): boolean;
|
|
14
|
+
export declare function writeDisplayTouchChildren(receiver: unknown, value: unknown): void;
|
|
15
|
+
/** Read caller fields once in fixed order; source faults never become semantics. */
|
|
16
|
+
export declare function writeDisplayHitArea(receiver: unknown, source: unknown): void;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=displayHitState.d.ts.map
|