@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,51 @@
|
|
|
1
|
+
import { EgretError } from '../EgretError.js';
|
|
2
|
+
import type { TextRasterCacheStatus } from './types.js';
|
|
3
|
+
/** Logical limits count retained work; they do not estimate process memory. */
|
|
4
|
+
export interface TextBudgetLimits {
|
|
5
|
+
readonly maxGenerations: number;
|
|
6
|
+
readonly maxPendingJobs: number;
|
|
7
|
+
readonly maxWaiters: number;
|
|
8
|
+
readonly maxCallerLeases: number;
|
|
9
|
+
readonly maxResidentEntries: number;
|
|
10
|
+
readonly maxMetadataBytes: number;
|
|
11
|
+
readonly maxLogicalImageBytes: number;
|
|
12
|
+
readonly maxPendingRasterBytes: number;
|
|
13
|
+
}
|
|
14
|
+
type CounterFields = Omit<TextRasterCacheStatus, 'closed' | 'fontGeneration'>;
|
|
15
|
+
export type TextBudgetCounters = {
|
|
16
|
+
-readonly [K in keyof CounterFields]: CounterFields[K];
|
|
17
|
+
};
|
|
18
|
+
export type TextBudgetDelta = Partial<TextBudgetCounters>;
|
|
19
|
+
export type TextBudgetFailure = (code: 'TEXT_COUNTER_EXHAUSTED' | 'TEXT_CACHE_BUDGET', cause?: unknown) => EgretError;
|
|
20
|
+
export declare const TEXT_BUDGET_DEFAULTS: Readonly<{
|
|
21
|
+
readonly maxGenerations: 64;
|
|
22
|
+
readonly maxPendingJobs: 4;
|
|
23
|
+
readonly maxWaiters: 128;
|
|
24
|
+
readonly maxCallerLeases: 128;
|
|
25
|
+
readonly maxResidentEntries: 32;
|
|
26
|
+
readonly maxMetadataBytes: 2097152;
|
|
27
|
+
readonly maxLogicalImageBytes: 16777216;
|
|
28
|
+
readonly maxPendingRasterBytes: 8388608;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const TEXT_BUDGET_MINIMA: Readonly<{
|
|
31
|
+
readonly maxGenerations: 1;
|
|
32
|
+
readonly maxPendingJobs: 1;
|
|
33
|
+
readonly maxWaiters: 1;
|
|
34
|
+
readonly maxCallerLeases: 1;
|
|
35
|
+
readonly maxResidentEntries: 0;
|
|
36
|
+
readonly maxMetadataBytes: 4096;
|
|
37
|
+
readonly maxLogicalImageBytes: 1;
|
|
38
|
+
readonly maxPendingRasterBytes: 1;
|
|
39
|
+
}>;
|
|
40
|
+
/** Proposals are checked before any counter changes or persistent allocation. */
|
|
41
|
+
export declare class TextBudget {
|
|
42
|
+
readonly limits: TextBudgetLimits;
|
|
43
|
+
private readonly counters;
|
|
44
|
+
constructor(limits: TextBudgetLimits);
|
|
45
|
+
check(delta: TextBudgetDelta, failure: TextBudgetFailure): void;
|
|
46
|
+
/** Internal terminal transitions have already established their exact charge. */
|
|
47
|
+
commit(delta: TextBudgetDelta): void;
|
|
48
|
+
snapshot(): Readonly<TextBudgetCounters>;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { EgretError } from '../EgretError.js';
|
|
2
|
+
const freeze = Object.freeze;
|
|
3
|
+
const finite = Number.isSafeInteger;
|
|
4
|
+
const keys = freeze([
|
|
5
|
+
'occupiedSlots',
|
|
6
|
+
'currentGenerations',
|
|
7
|
+
'retiredGenerations',
|
|
8
|
+
'quarantinedGenerations',
|
|
9
|
+
'pendingJobs',
|
|
10
|
+
'pendingWaiters',
|
|
11
|
+
'callerLeaseSlots',
|
|
12
|
+
'activeCallerLeases',
|
|
13
|
+
'residentEntries',
|
|
14
|
+
'residentBytes',
|
|
15
|
+
'liveImageBytes',
|
|
16
|
+
'reservedImageBytes',
|
|
17
|
+
'pendingRasterBytes',
|
|
18
|
+
'quarantinedImageBytes',
|
|
19
|
+
'quarantinedRasterBytes',
|
|
20
|
+
'metadataBytes',
|
|
21
|
+
'idleWaiters',
|
|
22
|
+
'cleanupFailureCount',
|
|
23
|
+
'lateProviderFailureCount'
|
|
24
|
+
]);
|
|
25
|
+
export const TEXT_BUDGET_DEFAULTS = freeze({
|
|
26
|
+
maxGenerations: 64,
|
|
27
|
+
maxPendingJobs: 4,
|
|
28
|
+
maxWaiters: 128,
|
|
29
|
+
maxCallerLeases: 128,
|
|
30
|
+
maxResidentEntries: 32,
|
|
31
|
+
maxMetadataBytes: 2097152,
|
|
32
|
+
maxLogicalImageBytes: 16777216,
|
|
33
|
+
maxPendingRasterBytes: 8388608
|
|
34
|
+
});
|
|
35
|
+
export const TEXT_BUDGET_MINIMA = freeze({
|
|
36
|
+
maxGenerations: 1,
|
|
37
|
+
maxPendingJobs: 1,
|
|
38
|
+
maxWaiters: 1,
|
|
39
|
+
maxCallerLeases: 1,
|
|
40
|
+
maxResidentEntries: 0,
|
|
41
|
+
maxMetadataBytes: 4096,
|
|
42
|
+
maxLogicalImageBytes: 1,
|
|
43
|
+
maxPendingRasterBytes: 1
|
|
44
|
+
});
|
|
45
|
+
/** Proposals are checked before any counter changes or persistent allocation. */
|
|
46
|
+
export class TextBudget {
|
|
47
|
+
limits;
|
|
48
|
+
counters = {
|
|
49
|
+
occupiedSlots: 0,
|
|
50
|
+
currentGenerations: 0,
|
|
51
|
+
retiredGenerations: 0,
|
|
52
|
+
quarantinedGenerations: 0,
|
|
53
|
+
pendingJobs: 0,
|
|
54
|
+
pendingWaiters: 0,
|
|
55
|
+
callerLeaseSlots: 0,
|
|
56
|
+
activeCallerLeases: 0,
|
|
57
|
+
residentEntries: 0,
|
|
58
|
+
residentBytes: 0,
|
|
59
|
+
liveImageBytes: 0,
|
|
60
|
+
reservedImageBytes: 0,
|
|
61
|
+
pendingRasterBytes: 0,
|
|
62
|
+
quarantinedImageBytes: 0,
|
|
63
|
+
quarantinedRasterBytes: 0,
|
|
64
|
+
metadataBytes: 4096,
|
|
65
|
+
idleWaiters: 0,
|
|
66
|
+
cleanupFailureCount: 0,
|
|
67
|
+
lateProviderFailureCount: 0
|
|
68
|
+
};
|
|
69
|
+
constructor(limits) {
|
|
70
|
+
this.limits = limits;
|
|
71
|
+
}
|
|
72
|
+
check(delta, failure) {
|
|
73
|
+
const next = (key) => {
|
|
74
|
+
const value = this.counters[key] + (delta[key] ?? 0);
|
|
75
|
+
if (!finite(value) || value < 0)
|
|
76
|
+
throw failure('TEXT_COUNTER_EXHAUSTED');
|
|
77
|
+
return value;
|
|
78
|
+
};
|
|
79
|
+
// Admission precedence is part of the contract, even for combined proposals.
|
|
80
|
+
if (next('pendingWaiters') > this.limits.maxWaiters)
|
|
81
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
82
|
+
if (next('callerLeaseSlots') > this.limits.maxCallerLeases)
|
|
83
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
84
|
+
if (next('occupiedSlots') > 32)
|
|
85
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
86
|
+
if (next('currentGenerations') + next('retiredGenerations') > this.limits.maxGenerations)
|
|
87
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
88
|
+
if (next('pendingJobs') > this.limits.maxPendingJobs)
|
|
89
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
90
|
+
if (next('metadataBytes') > this.limits.maxMetadataBytes)
|
|
91
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
92
|
+
if (next('liveImageBytes') + next('reservedImageBytes') > this.limits.maxLogicalImageBytes)
|
|
93
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
94
|
+
if (next('pendingRasterBytes') > this.limits.maxPendingRasterBytes)
|
|
95
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
96
|
+
if (next('residentEntries') > this.limits.maxResidentEntries || next('idleWaiters') > 8)
|
|
97
|
+
throw failure('TEXT_CACHE_BUDGET');
|
|
98
|
+
for (const key of keys)
|
|
99
|
+
next(key);
|
|
100
|
+
}
|
|
101
|
+
/** Internal terminal transitions have already established their exact charge. */
|
|
102
|
+
commit(delta) {
|
|
103
|
+
for (const key of keys) {
|
|
104
|
+
const difference = delta[key] ?? 0;
|
|
105
|
+
const value = this.counters[key] + difference;
|
|
106
|
+
if (!finite(value) || value < 0)
|
|
107
|
+
throw new EgretError('TEXT_COUNTER_EXHAUSTED');
|
|
108
|
+
}
|
|
109
|
+
for (const key of keys)
|
|
110
|
+
this.counters[key] += delta[key] ?? 0;
|
|
111
|
+
}
|
|
112
|
+
snapshot() {
|
|
113
|
+
return freeze({ ...this.counters });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=budget.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TextValueInvocation } from './request.js';
|
|
2
|
+
import type { TextPlanInput, TextRasterPlan, TextRasterRequest } from './types.js';
|
|
3
|
+
declare const issuerBrand: unique symbol;
|
|
4
|
+
/** Private per-measure authority. Only the captured createPlan reaches the provider. */
|
|
5
|
+
export interface TextRasterPlanIssuer {
|
|
6
|
+
readonly [issuerBrand]: true;
|
|
7
|
+
readonly createPlan: (input: TextPlanInput) => TextRasterPlan;
|
|
8
|
+
}
|
|
9
|
+
export declare function createTextRasterPlanIssuer(request: TextRasterRequest, invocation: TextValueInvocation): TextRasterPlanIssuer;
|
|
10
|
+
/** Close only after measure settles; closing never erases its own terminal-cleanup plan. */
|
|
11
|
+
export declare function closeTextRasterPlanIssuer(issuer: TextRasterPlanIssuer): void;
|
|
12
|
+
export declare function readIssuedTextRasterPlan(issuer: TextRasterPlanIssuer): TextRasterPlan | undefined;
|
|
13
|
+
/** Exact private issuer/invocation/plan identities are checked before public plan fields. */
|
|
14
|
+
export declare function requireIssuedTextRasterPlan(issuer: TextRasterPlanIssuer, value: unknown, invocation: TextValueInvocation): TextRasterPlan;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { createTextValueFailure, requireOwnedTextRasterRequest, takeTextValueFailure } from './request.js';
|
|
2
|
+
const apply = Reflect.apply;
|
|
3
|
+
const freeze = Object.freeze;
|
|
4
|
+
const TypeFault = TypeError;
|
|
5
|
+
const RangeFault = RangeError;
|
|
6
|
+
const finite = Number.isFinite;
|
|
7
|
+
const safeInteger = Number.isSafeInteger;
|
|
8
|
+
const isArray = Array.isArray;
|
|
9
|
+
const Lines = Array;
|
|
10
|
+
const abs = Math.abs;
|
|
11
|
+
const floor = Math.floor;
|
|
12
|
+
const ceil = Math.ceil;
|
|
13
|
+
const min = Math.min;
|
|
14
|
+
const max = Math.max;
|
|
15
|
+
const weakGet = WeakMap.prototype.get;
|
|
16
|
+
const weakSet = WeakMap.prototype.set;
|
|
17
|
+
const issuers = new WeakMap();
|
|
18
|
+
const plans = new WeakMap();
|
|
19
|
+
function invalid(invocation, message) {
|
|
20
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_INVALID', new TypeFault(message));
|
|
21
|
+
}
|
|
22
|
+
function limit(invocation, message) {
|
|
23
|
+
throw createTextValueFailure(invocation, 'TEXT_REQUEST_LIMIT', new RangeFault(message));
|
|
24
|
+
}
|
|
25
|
+
function coordinate(value, invocation, label) {
|
|
26
|
+
if (typeof value !== 'number' || !finite(value) || abs(value) > 1048576) {
|
|
27
|
+
invalid(invocation, label + ' must be a finite bounded coordinate');
|
|
28
|
+
}
|
|
29
|
+
return value === 0 ? 0 : value;
|
|
30
|
+
}
|
|
31
|
+
function bounds(left, top, right, bottom, invocation) {
|
|
32
|
+
const width = coordinate(right - left, invocation, 'Bounds width');
|
|
33
|
+
const height = coordinate(bottom - top, invocation, 'Bounds height');
|
|
34
|
+
return freeze({ x: left, y: top, width, height });
|
|
35
|
+
}
|
|
36
|
+
function issuerState(value) {
|
|
37
|
+
const state = apply(weakGet, issuers, [value]);
|
|
38
|
+
if (state === undefined)
|
|
39
|
+
throw new TypeFault('Authentic private text plan issuer required');
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
function lineFields(value, invocation) {
|
|
43
|
+
if (typeof value !== 'object' || value === null)
|
|
44
|
+
invalid(invocation, 'Text plan line must be a record');
|
|
45
|
+
let advance, hasInk, inkLeft, inkTop;
|
|
46
|
+
let inkRight, inkBottom;
|
|
47
|
+
try {
|
|
48
|
+
const line = value;
|
|
49
|
+
advance = line.advance;
|
|
50
|
+
hasInk = line.hasInk;
|
|
51
|
+
inkLeft = line.inkLeft;
|
|
52
|
+
inkTop = line.inkTop;
|
|
53
|
+
inkRight = line.inkRight;
|
|
54
|
+
inkBottom = line.inkBottom;
|
|
55
|
+
}
|
|
56
|
+
catch (cause) {
|
|
57
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_INVALID', cause);
|
|
58
|
+
}
|
|
59
|
+
return { advance, hasInk, inkLeft, inkTop, inkRight, inkBottom };
|
|
60
|
+
}
|
|
61
|
+
function createPlan(state, input) {
|
|
62
|
+
const invocation = state.invocation;
|
|
63
|
+
// These gates precede every descriptor read, including nested createPlan calls.
|
|
64
|
+
if (state.closed)
|
|
65
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_SCOPE_CLOSED');
|
|
66
|
+
if (state.issued !== undefined || state.creating) {
|
|
67
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_ALREADY_CREATED');
|
|
68
|
+
}
|
|
69
|
+
state.creating = true;
|
|
70
|
+
try {
|
|
71
|
+
if (typeof input !== 'object' || input === null)
|
|
72
|
+
invalid(invocation, 'Text plan must be a record');
|
|
73
|
+
let baselineValue, lineTable;
|
|
74
|
+
try {
|
|
75
|
+
baselineValue = input.baselineOffset;
|
|
76
|
+
lineTable = input.lines;
|
|
77
|
+
}
|
|
78
|
+
catch (cause) {
|
|
79
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_INVALID', cause);
|
|
80
|
+
}
|
|
81
|
+
if (!isArray(lineTable))
|
|
82
|
+
invalid(invocation, 'Text plan lines must be an array');
|
|
83
|
+
let lineCount;
|
|
84
|
+
try {
|
|
85
|
+
lineCount = lineTable.length;
|
|
86
|
+
}
|
|
87
|
+
catch (cause) {
|
|
88
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_INVALID', cause);
|
|
89
|
+
}
|
|
90
|
+
const request = state.request;
|
|
91
|
+
const count = request.sourceLines.length;
|
|
92
|
+
if (lineCount !== count)
|
|
93
|
+
invalid(invocation, 'Text plan line count must match the owned request');
|
|
94
|
+
const baselineOffset = coordinate(baselineValue, invocation, 'Baseline offset');
|
|
95
|
+
const lines = new Lines(count);
|
|
96
|
+
let maxAdvance = 0;
|
|
97
|
+
let hasAnyInk = false;
|
|
98
|
+
let unionLeft = 0, unionTop = 0, unionRight = 0, unionBottom = 0;
|
|
99
|
+
for (let i = 0; i < count; i++) {
|
|
100
|
+
let row;
|
|
101
|
+
try {
|
|
102
|
+
row = lineTable[i];
|
|
103
|
+
}
|
|
104
|
+
catch (cause) {
|
|
105
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_INVALID', cause);
|
|
106
|
+
}
|
|
107
|
+
const fields = lineFields(row, invocation);
|
|
108
|
+
const advance = coordinate(fields.advance, invocation, 'Line advance');
|
|
109
|
+
if (advance < 0)
|
|
110
|
+
invalid(invocation, 'Line advance must be nonnegative');
|
|
111
|
+
if (typeof fields.hasInk !== 'boolean')
|
|
112
|
+
invalid(invocation, 'Line hasInk must be boolean');
|
|
113
|
+
const left = coordinate(fields.inkLeft, invocation, 'Line ink left');
|
|
114
|
+
const top = coordinate(fields.inkTop, invocation, 'Line ink top');
|
|
115
|
+
const right = coordinate(fields.inkRight, invocation, 'Line ink right');
|
|
116
|
+
const bottom = coordinate(fields.inkBottom, invocation, 'Line ink bottom');
|
|
117
|
+
if (fields.hasInk) {
|
|
118
|
+
if (!(left < right && top < bottom))
|
|
119
|
+
invalid(invocation, 'Real ink must have positive signed extents');
|
|
120
|
+
}
|
|
121
|
+
else if (left !== 0 || top !== 0 || right !== 0 || bottom !== 0) {
|
|
122
|
+
invalid(invocation, 'An inkless line must have zero ink coordinates');
|
|
123
|
+
}
|
|
124
|
+
const baselineDelta = coordinate(i * request.lineHeight, invocation, 'Line baseline delta');
|
|
125
|
+
const baselineY = coordinate(baselineOffset + baselineDelta, invocation, 'Line baseline');
|
|
126
|
+
let inkBounds;
|
|
127
|
+
if (fields.hasInk) {
|
|
128
|
+
const absoluteTop = coordinate(baselineY + top, invocation, 'Absolute ink top');
|
|
129
|
+
const absoluteBottom = coordinate(baselineY + bottom, invocation, 'Absolute ink bottom');
|
|
130
|
+
inkBounds = bounds(left, absoluteTop, right, absoluteBottom, invocation);
|
|
131
|
+
if (hasAnyInk) {
|
|
132
|
+
unionLeft = min(unionLeft, left);
|
|
133
|
+
unionTop = min(unionTop, absoluteTop);
|
|
134
|
+
unionRight = max(unionRight, right);
|
|
135
|
+
unionBottom = max(unionBottom, absoluteBottom);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
unionLeft = left;
|
|
139
|
+
unionTop = absoluteTop;
|
|
140
|
+
unionRight = right;
|
|
141
|
+
unionBottom = absoluteBottom;
|
|
142
|
+
hasAnyInk = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
maxAdvance = max(maxAdvance, advance);
|
|
146
|
+
lines[i] = freeze({ source: request.sourceLines[i], advance, baselineY, inkBounds });
|
|
147
|
+
}
|
|
148
|
+
const logicalHeight = coordinate(count * request.lineHeight, invocation, 'Logical height');
|
|
149
|
+
const logicalBounds = bounds(0, 0, maxAdvance, logicalHeight, invocation);
|
|
150
|
+
const inkBounds = hasAnyInk ? bounds(unionLeft, unionTop, unionRight, unionBottom, invocation) : undefined;
|
|
151
|
+
const contentBounds = hasAnyInk
|
|
152
|
+
? bounds(min(0, unionLeft), min(0, unionTop), max(maxAdvance, unionRight), max(logicalHeight, unionBottom), invocation)
|
|
153
|
+
: logicalBounds;
|
|
154
|
+
let raster;
|
|
155
|
+
if (hasAnyInk) {
|
|
156
|
+
const density = request.density;
|
|
157
|
+
// Keep the original union endpoints rather than reconstructing right/bottom from widths.
|
|
158
|
+
const scaledLeft = coordinate(unionLeft * density, invocation, 'Scaled ink left');
|
|
159
|
+
const scaledTop = coordinate(unionTop * density, invocation, 'Scaled ink top');
|
|
160
|
+
const scaledRight = coordinate(unionRight * density, invocation, 'Scaled ink right');
|
|
161
|
+
const scaledBottom = coordinate(unionBottom * density, invocation, 'Scaled ink bottom');
|
|
162
|
+
const pixelLeft = coordinate(floor(scaledLeft) - 2, invocation, 'Raster left');
|
|
163
|
+
const pixelTop = coordinate(floor(scaledTop) - 2, invocation, 'Raster top');
|
|
164
|
+
const pixelRight = coordinate(ceil(scaledRight) + 2, invocation, 'Raster right');
|
|
165
|
+
const pixelBottom = coordinate(ceil(scaledBottom) + 2, invocation, 'Raster bottom');
|
|
166
|
+
const width = pixelRight - pixelLeft;
|
|
167
|
+
const height = pixelBottom - pixelTop;
|
|
168
|
+
if (!safeInteger(width) || !safeInteger(height) || width <= 0 || height <= 0 || width > 4096 || height > 4096)
|
|
169
|
+
limit(invocation, 'Raster edge limit');
|
|
170
|
+
const pixels = width * height;
|
|
171
|
+
if (!safeInteger(pixels) || pixels > 1048576)
|
|
172
|
+
limit(invocation, 'Raster pixel limit');
|
|
173
|
+
const byteLength = 4 * pixels;
|
|
174
|
+
if (!safeInteger(byteLength) || byteLength > 4194304)
|
|
175
|
+
limit(invocation, 'Raster byte limit');
|
|
176
|
+
const x = coordinate(pixelLeft / density, invocation, 'Raster x');
|
|
177
|
+
const y = coordinate(pixelTop / density, invocation, 'Raster y');
|
|
178
|
+
const logicalWidth = coordinate(width / density, invocation, 'Raster logical width');
|
|
179
|
+
const rasterLogicalHeight = coordinate(height / density, invocation, 'Raster logical height');
|
|
180
|
+
raster = freeze({
|
|
181
|
+
pixelLeft,
|
|
182
|
+
pixelTop,
|
|
183
|
+
width,
|
|
184
|
+
height,
|
|
185
|
+
byteLength,
|
|
186
|
+
density,
|
|
187
|
+
x,
|
|
188
|
+
y,
|
|
189
|
+
logicalWidth,
|
|
190
|
+
logicalHeight: rasterLogicalHeight
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const metrics = freeze({
|
|
194
|
+
logicalBounds,
|
|
195
|
+
inkBounds,
|
|
196
|
+
contentBounds,
|
|
197
|
+
lines: freeze(lines),
|
|
198
|
+
raster
|
|
199
|
+
});
|
|
200
|
+
const plan = freeze({ request, metrics });
|
|
201
|
+
if (state.closed)
|
|
202
|
+
throw createTextValueFailure(invocation, 'TEXT_PLAN_SCOPE_CLOSED');
|
|
203
|
+
apply(weakSet, plans, [plan, state]);
|
|
204
|
+
state.issued = plan;
|
|
205
|
+
return plan;
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
state.creating = false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export function createTextRasterPlanIssuer(request, invocation) {
|
|
212
|
+
const owned = requireOwnedTextRasterRequest(request, invocation);
|
|
213
|
+
const state = { request: owned, invocation, closed: false, creating: false, issued: undefined };
|
|
214
|
+
const issuer = freeze({ createPlan: (input) => createPlan(state, input) });
|
|
215
|
+
apply(weakSet, issuers, [issuer, state]);
|
|
216
|
+
return issuer;
|
|
217
|
+
}
|
|
218
|
+
/** Close only after measure settles; closing never erases its own terminal-cleanup plan. */
|
|
219
|
+
export function closeTextRasterPlanIssuer(issuer) {
|
|
220
|
+
issuerState(issuer).closed = true;
|
|
221
|
+
}
|
|
222
|
+
export function readIssuedTextRasterPlan(issuer) {
|
|
223
|
+
return issuerState(issuer).issued;
|
|
224
|
+
}
|
|
225
|
+
/** Exact private issuer/invocation/plan identities are checked before public plan fields. */
|
|
226
|
+
export function requireIssuedTextRasterPlan(issuer, value, invocation) {
|
|
227
|
+
const state = issuerState(issuer);
|
|
228
|
+
// Authenticate the invocation without consuming a note or reopening its closed failure scope.
|
|
229
|
+
takeTextValueFailure(invocation, undefined);
|
|
230
|
+
const owner = typeof value === 'object' && value !== null
|
|
231
|
+
? apply(weakGet, plans, [value])
|
|
232
|
+
: undefined;
|
|
233
|
+
if (state.invocation !== invocation || owner !== state || value !== state.issued) {
|
|
234
|
+
invalid(invocation, 'The exact plan issued for this invocation is required');
|
|
235
|
+
}
|
|
236
|
+
return state.issued;
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=plan.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EgretError } from '../EgretError.js';
|
|
2
|
+
import type { TextRasterRequest, TextRasterRequestInput } from './types.js';
|
|
3
|
+
declare const invocationBrand: unique symbol;
|
|
4
|
+
declare const snapshotBrand: unique symbol;
|
|
5
|
+
declare const summaryBrand: unique symbol;
|
|
6
|
+
/** Private operation identity; a public error code never supplies this authority. */
|
|
7
|
+
export interface TextValueInvocation {
|
|
8
|
+
readonly [invocationBrand]: true;
|
|
9
|
+
}
|
|
10
|
+
export type TextValueFailureCode = 'TEXT_REQUEST_INVALID' | 'TEXT_REQUEST_LIMIT' | 'TEXT_PLAN_INVALID' | 'TEXT_PLAN_ALREADY_CREATED' | 'TEXT_PLAN_SCOPE_CLOSED' | 'TEXT_CACHE_BUDGET' | 'TEXT_COUNTER_EXHAUSTED';
|
|
11
|
+
export interface TextValueFailure {
|
|
12
|
+
readonly code: TextValueFailureCode;
|
|
13
|
+
readonly error: EgretError;
|
|
14
|
+
}
|
|
15
|
+
export interface TextRasterRequestSnapshot {
|
|
16
|
+
readonly [snapshotBrand]: true;
|
|
17
|
+
}
|
|
18
|
+
/** A transient scalar proposal. The cache must admit its charge before owned creation. */
|
|
19
|
+
export interface TextRasterRequestSummary {
|
|
20
|
+
readonly [summaryBrand]: true;
|
|
21
|
+
readonly sourceCodeUnits: number;
|
|
22
|
+
readonly lineCount: number;
|
|
23
|
+
readonly metadataBytes: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function createTextValueInvocation(): TextValueInvocation;
|
|
26
|
+
export declare function closeTextValueInvocation(value: TextValueInvocation): void;
|
|
27
|
+
/** Only fresh first-party creation attaches a note; closed notes cannot be consumed. */
|
|
28
|
+
export declare function createTextValueFailure(invocation: TextValueInvocation, code: TextValueFailureCode, cause?: unknown): EgretError;
|
|
29
|
+
/** Exact active operation and one consumption; no instanceof/code/cause inspection. */
|
|
30
|
+
export declare function takeTextValueFailure(invocation: TextValueInvocation, cause: unknown): TextValueFailure | undefined;
|
|
31
|
+
/** Snapshot all ten fields first. The cache performs its post-read lifecycle check next. */
|
|
32
|
+
export declare function snapshotTextRasterRequest(input: TextRasterRequestInput, invocation: TextValueInvocation): TextRasterRequestSnapshot;
|
|
33
|
+
/** No source-line array, serialized key or resource identity is created here. */
|
|
34
|
+
export declare function summarizeTextRasterRequest(snapshot: TextRasterRequestSnapshot, providerIdentity: string, fontGeneration: number, invocation: TextValueInvocation): TextRasterRequestSummary;
|
|
35
|
+
/** Project validated field scalars without granting cache request/plan authority. */
|
|
36
|
+
export declare function createTextFieldRequestInput(summary: TextRasterRequestSummary, invocation: TextValueInvocation): TextRasterRequestInput;
|
|
37
|
+
/** Call only after the cache commits the summary's exact generation metadata charge. */
|
|
38
|
+
export declare function createOwnedTextRasterRequest(summary: TextRasterRequestSummary, invocation: TextValueInvocation): TextRasterRequest;
|
|
39
|
+
export declare function isOwnedTextRasterRequest(value: unknown): value is TextRasterRequest;
|
|
40
|
+
export declare function requireOwnedTextRasterRequest(value: unknown, invocation: TextValueInvocation): TextRasterRequest;
|
|
41
|
+
/** Bounded route lookup compares authenticated normalized scalars without allocating a key. */
|
|
42
|
+
export declare function matchesTextRasterRequestSummary(request: TextRasterRequest, summary: TextRasterRequestSummary, providerIdentity: string, fontGeneration: number): boolean;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=request.d.ts.map
|