gesso-core 0.1.0
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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/CanvasSurface-CrG-uJ5o.js +17273 -0
- package/dist/CanvasSurface-CrG-uJ5o.js.map +1 -0
- package/dist/index-DuZEAhyZ.d.ts +15815 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13350 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +232 -0
- package/dist/testing.js +560 -0
- package/dist/testing.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { $t as Canvas2DRenderer, Aa as ScrollSink, Bs as TextMeasurer, Da as PointerControllerOptions, Ea as UiKeyboardController, Ha as UiFocusManager, If as UiInputDispatcher, La as UiGestureRecognizer, Lm as UiNodeType, Mm as LayoutRecord, Na as UiWheelController, Nc as UiGraph, Oa as UiPointerController, Qi as UiPlatformAdapter, Sp as LayoutResult, Xi as PlatformEventTarget, Zi as PlatformSurface, as as Canvas2DContext, bp as Constraints, ca as UiTouchScroller, dn as CanvasSurface, hi as LayoutEngine, io as UiHitTester, jp as UiNode, ka as ScrollContainerState, os as Canvas2DGradient, sa as TouchScrollerOptions, un as CanvasHost, xp as LayoutBox } from "./index-DuZEAhyZ.js";
|
|
2
|
+
//#region src/layout/LayoutTestUtils.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared helpers for layout specs: builds UiNode trees through
|
|
5
|
+
* the real graph and drives LayoutEngine.
|
|
6
|
+
*/
|
|
7
|
+
declare class LayoutHarness {
|
|
8
|
+
readonly graph: UiGraph;
|
|
9
|
+
readonly engine: LayoutEngine;
|
|
10
|
+
constructor(textMeasurer?: TextMeasurer);
|
|
11
|
+
createNode(id: string, type: UiNodeType): UiNode;
|
|
12
|
+
append(parent: UiNode, ...children: UiNode[]): void;
|
|
13
|
+
layout(node: UiNode, constraints?: Constraints): LayoutResult;
|
|
14
|
+
record(node: UiNode): LayoutRecord;
|
|
15
|
+
box(node: UiNode): LayoutBox;
|
|
16
|
+
boxOf(node: UiNode): LayoutBox;
|
|
17
|
+
/** Where the node is seen: scroll offsets and sticky shifts applied. */
|
|
18
|
+
visibleBox(node: UiNode): LayoutBox;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/input/UiInputTestUtils.d.ts
|
|
22
|
+
/**
|
|
23
|
+
* Shared harness for input specs.
|
|
24
|
+
*
|
|
25
|
+
* Builds real UiNode trees through UiGraph + LayoutEngine so hit
|
|
26
|
+
* testing, dispatch, focus and gestures are tested against actual
|
|
27
|
+
* layout geometry rather than hand-written boxes.
|
|
28
|
+
*/
|
|
29
|
+
declare class InputTestHarness {
|
|
30
|
+
readonly layout: LayoutHarness;
|
|
31
|
+
readonly root: UiNode;
|
|
32
|
+
readonly dispatcher: UiInputDispatcher;
|
|
33
|
+
/** Shared, so a spec can read back what a controller scrolled. */
|
|
34
|
+
readonly scrollSink: HarnessScrollSink;
|
|
35
|
+
/** A measurer is needed only by specs whose trees contain real text. */
|
|
36
|
+
constructor(width?: number, height?: number, textMeasurer?: TextMeasurer);
|
|
37
|
+
node(id: string, type: UiNodeType, props?: Record<string, unknown>): UiNode;
|
|
38
|
+
add(parent: UiNode, ...children: UiNode[]): void;
|
|
39
|
+
layoutTree(): void;
|
|
40
|
+
createHitTester(): UiHitTester;
|
|
41
|
+
createPointerController(): UiPointerController;
|
|
42
|
+
createGestureRecognizer(): UiGestureRecognizer;
|
|
43
|
+
createFocusManager(): UiFocusManager;
|
|
44
|
+
createKeyboardController(): UiKeyboardController;
|
|
45
|
+
createWheelController(): UiWheelController;
|
|
46
|
+
/**
|
|
47
|
+
* A pointer controller with a gesture recognizer behind it, for the
|
|
48
|
+
* specs that need a real Pan rather than a hand-made one.
|
|
49
|
+
*/
|
|
50
|
+
createGesturePointerController(options?: PointerControllerOptions): UiPointerController;
|
|
51
|
+
createTouchScroller(options?: TouchScrollerOptions): UiTouchScroller;
|
|
52
|
+
createPlatformAdapter(): UiPlatformAdapter;
|
|
53
|
+
box(node: UiNode): {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Minimal fake event target for testing the platform adapter.
|
|
62
|
+
*/
|
|
63
|
+
declare class FakeEventTarget implements PlatformEventTarget {
|
|
64
|
+
private readonly listeners;
|
|
65
|
+
addEventListener(type: string, listener: ((event: Event) => void) | null): void;
|
|
66
|
+
removeEventListener(type: string, listener: ((event: Event) => void) | null): void;
|
|
67
|
+
emit(type: string, event: Event): void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Fake PlatformSurface for tests. Emits DOM-like events from plain
|
|
71
|
+
* objects so PointerEvent/WheelEvent/KeyboardEvent constructors are
|
|
72
|
+
* not required in the test environment.
|
|
73
|
+
*/
|
|
74
|
+
declare class FakePlatformSurface implements PlatformSurface {
|
|
75
|
+
readonly pointerTarget: FakeEventTarget;
|
|
76
|
+
readonly keyboardTarget: FakeEventTarget;
|
|
77
|
+
localX: number;
|
|
78
|
+
localY: number;
|
|
79
|
+
/** The last `touch-action` the adapter asked for; '' before any. */
|
|
80
|
+
touchAction: string;
|
|
81
|
+
clientToLocal(_clientX: number, _clientY: number): {
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
};
|
|
85
|
+
setTouchAction(value: string): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* ScrollSink backed by the harness LayoutEngine. Updates the
|
|
89
|
+
* container's scrollX/scrollY properties, then re-lays out so the
|
|
90
|
+
* engine re-reads and clamps the offset, mirroring how the app layer
|
|
91
|
+
* drives scroll through node properties.
|
|
92
|
+
*/
|
|
93
|
+
declare class HarnessScrollSink implements ScrollSink {
|
|
94
|
+
private readonly harness;
|
|
95
|
+
/** Every scroll asked for, in order, so a spec can read the behaviour hint. */
|
|
96
|
+
readonly calls: {
|
|
97
|
+
node: UiNode;
|
|
98
|
+
dx: number;
|
|
99
|
+
dy: number;
|
|
100
|
+
behavior: string;
|
|
101
|
+
}[];
|
|
102
|
+
/** Containers whose scrollbars were revealed. */
|
|
103
|
+
readonly revealed: UiNode[];
|
|
104
|
+
constructor(harness: InputTestHarness);
|
|
105
|
+
containerState(node: UiNode): ScrollContainerState | undefined;
|
|
106
|
+
scrollBy(node: UiNode, dx: number, dy: number, behavior?: string): void;
|
|
107
|
+
scrollContainers(): Iterable<UiNode>;
|
|
108
|
+
revealScrollbars(node: UiNode): void;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/rendering/RenderTestUtils.d.ts
|
|
112
|
+
interface RecordedCall {
|
|
113
|
+
name: string;
|
|
114
|
+
args: unknown[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The gradient a recording context hands back, carrying what it was
|
|
118
|
+
* asked for so a test can read the whole paint rather than a `[object
|
|
119
|
+
* CanvasGradient]`. A real one is opaque, which is exactly what makes
|
|
120
|
+
* a gradient hard to assert on without this.
|
|
121
|
+
*/
|
|
122
|
+
declare class RecordedGradient implements Canvas2DGradient {
|
|
123
|
+
readonly kind: 'linear' | 'radial';
|
|
124
|
+
readonly args: readonly number[];
|
|
125
|
+
readonly stops: {
|
|
126
|
+
offset: number;
|
|
127
|
+
color: string;
|
|
128
|
+
}[];
|
|
129
|
+
constructor(kind: 'linear' | 'radial', args: readonly number[]);
|
|
130
|
+
addColorStop(offset: number, color: string): void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Deterministic Canvas2D spy: records every call and style
|
|
134
|
+
* assignment so tests can assert the exact draw sequence.
|
|
135
|
+
*/
|
|
136
|
+
declare class RecordingCanvasContext implements Canvas2DContext {
|
|
137
|
+
readonly calls: RecordedCall[];
|
|
138
|
+
private _fillStyle;
|
|
139
|
+
private _strokeStyle;
|
|
140
|
+
private _lineWidth;
|
|
141
|
+
private _lineJoin;
|
|
142
|
+
private _globalAlpha;
|
|
143
|
+
private _font;
|
|
144
|
+
private _textAlign;
|
|
145
|
+
private _textBaseline;
|
|
146
|
+
/**
|
|
147
|
+
* Tracking, which is a context property rather than part of the font
|
|
148
|
+
* shorthand — and sticky, so a spec can check it was cleared as well
|
|
149
|
+
* as that it was set.
|
|
150
|
+
*/
|
|
151
|
+
letterSpacing: string;
|
|
152
|
+
get fillStyle(): string | Canvas2DGradient | CanvasPattern;
|
|
153
|
+
set fillStyle(value: string | Canvas2DGradient | CanvasPattern);
|
|
154
|
+
get strokeStyle(): string | Canvas2DGradient | CanvasPattern;
|
|
155
|
+
set strokeStyle(value: string | Canvas2DGradient | CanvasPattern);
|
|
156
|
+
get lineWidth(): number;
|
|
157
|
+
set lineWidth(value: number);
|
|
158
|
+
get lineJoin(): CanvasLineJoin;
|
|
159
|
+
set lineJoin(value: CanvasLineJoin);
|
|
160
|
+
get globalAlpha(): number;
|
|
161
|
+
set globalAlpha(value: number);
|
|
162
|
+
get font(): string;
|
|
163
|
+
set font(value: string);
|
|
164
|
+
get textAlign(): CanvasTextAlign;
|
|
165
|
+
set textAlign(value: CanvasTextAlign);
|
|
166
|
+
get textBaseline(): CanvasTextBaseline;
|
|
167
|
+
set textBaseline(value: CanvasTextBaseline);
|
|
168
|
+
save(): void;
|
|
169
|
+
restore(): void;
|
|
170
|
+
translate(x: number, y: number): void;
|
|
171
|
+
scale(x: number, y: number): void;
|
|
172
|
+
rotate(angle: number): void;
|
|
173
|
+
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
174
|
+
clearRect(x: number, y: number, width: number, height: number): void;
|
|
175
|
+
fillRect(x: number, y: number, width: number, height: number): void;
|
|
176
|
+
strokeRect(x: number, y: number, width: number, height: number): void;
|
|
177
|
+
beginPath(): void;
|
|
178
|
+
moveTo(x: number, y: number): void;
|
|
179
|
+
lineTo(x: number, y: number): void;
|
|
180
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
181
|
+
closePath(): void;
|
|
182
|
+
rect(x: number, y: number, width: number, height: number): void;
|
|
183
|
+
clip(): void;
|
|
184
|
+
fill(): void;
|
|
185
|
+
stroke(): void;
|
|
186
|
+
fillText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
187
|
+
measureText(text: string): TextMetrics;
|
|
188
|
+
drawImage(image: ImageBitmap, dx: number, dy: number, dw: number, dh: number): void;
|
|
189
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number): RecordedGradient;
|
|
190
|
+
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): RecordedGradient;
|
|
191
|
+
private record;
|
|
192
|
+
}
|
|
193
|
+
declare function callNames(context: RecordingCanvasContext): string[];
|
|
194
|
+
declare function callsOf(context: RecordingCanvasContext, name: string): RecordedCall[];
|
|
195
|
+
declare function callArgs(context: RecordingCanvasContext, name: string): unknown[][];
|
|
196
|
+
declare function savedDepth(context: RecordingCanvasContext): number;
|
|
197
|
+
/**
|
|
198
|
+
* A canvas host backed by a recording context.
|
|
199
|
+
*/
|
|
200
|
+
declare class FakeCanvasHost implements CanvasHost {
|
|
201
|
+
private readonly context;
|
|
202
|
+
width: number;
|
|
203
|
+
height: number;
|
|
204
|
+
private contextRequests;
|
|
205
|
+
constructor(context: Canvas2DContext | null);
|
|
206
|
+
getContext(_contextId: '2d'): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | null;
|
|
207
|
+
get contextRequestCount(): number;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Shared harness: a real UiGraph + LayoutEngine + Canvas2DRenderer
|
|
211
|
+
* over a recording context. Deterministic layout comes from the
|
|
212
|
+
* CharacterCountTextMeasurer, shared by layout and renderer.
|
|
213
|
+
*/
|
|
214
|
+
declare class RenderHarness {
|
|
215
|
+
readonly graph: UiGraph;
|
|
216
|
+
readonly measurer: TextMeasurer;
|
|
217
|
+
readonly engine: LayoutEngine;
|
|
218
|
+
readonly context: RecordingCanvasContext;
|
|
219
|
+
readonly host: FakeCanvasHost;
|
|
220
|
+
readonly surface: CanvasSurface;
|
|
221
|
+
readonly renderer: Canvas2DRenderer;
|
|
222
|
+
constructor(logicalWidth?: number, logicalHeight?: number, dpr?: number);
|
|
223
|
+
createNode(id: string, type: UiNodeType): UiNode;
|
|
224
|
+
append(parent: UiNode, ...children: UiNode[]): void;
|
|
225
|
+
layout(node: UiNode, constraints?: Constraints): LayoutResult;
|
|
226
|
+
render(node: UiNode): void;
|
|
227
|
+
record(node: UiNode): LayoutRecord;
|
|
228
|
+
box(node: UiNode): LayoutBox;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
export { FakeCanvasHost, FakeEventTarget, FakePlatformSurface, InputTestHarness, type RecordedCall, RecordingCanvasContext, RenderHarness, callArgs, callNames, callsOf, savedDepth };
|
|
232
|
+
//# sourceMappingURL=testing.d.ts.map
|