chat-layout 1.0.0-3 → 1.0.0-4
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/index.d.mts +240 -1
- package/index.mjs +141 -0
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A value that can be provided directly or derived lazily from the active canvas context.
|
|
4
|
+
*/
|
|
2
5
|
type DynValue<C extends CanvasRenderingContext2D, T> = T extends Function ? never : T | ((context: C) => T);
|
|
6
|
+
/**
|
|
7
|
+
* Base renderer configuration.
|
|
8
|
+
*/
|
|
3
9
|
interface RendererOptions {}
|
|
10
|
+
/**
|
|
11
|
+
* Describes which items are currently visible after a render pass.
|
|
12
|
+
*/
|
|
4
13
|
interface RenderFeedback {
|
|
5
14
|
/** Smallest visible item index that contributes a positive visible height. */
|
|
6
15
|
minIdx: number;
|
|
@@ -11,65 +20,136 @@ interface RenderFeedback {
|
|
|
11
20
|
/** Largest visible continuous item position, expressed in item coordinates rather than pixels. */
|
|
12
21
|
max: number;
|
|
13
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The main axis direction used by flex containers.
|
|
25
|
+
*/
|
|
14
26
|
type Axis = "row" | "column";
|
|
27
|
+
/**
|
|
28
|
+
* Distribution modes for free space along the main axis.
|
|
29
|
+
*/
|
|
15
30
|
type MainAxisAlignment = "start" | "center" | "end" | "space-between" | "space-around" | "space-evenly";
|
|
31
|
+
/**
|
|
32
|
+
* Alignment modes along the cross axis.
|
|
33
|
+
*/
|
|
16
34
|
type CrossAxisAlignment = "start" | "center" | "end" | "stretch";
|
|
35
|
+
/**
|
|
36
|
+
* Controls whether a flex container fills the available main-axis size or shrink-wraps its content.
|
|
37
|
+
*/
|
|
17
38
|
type MainAxisSize = "fill" | "fit-content";
|
|
39
|
+
/**
|
|
40
|
+
* Logical inline alignment.
|
|
41
|
+
*/
|
|
18
42
|
type TextAlign = "start" | "center" | "end";
|
|
43
|
+
/**
|
|
44
|
+
* Physical inline alignment.
|
|
45
|
+
*/
|
|
19
46
|
type PhysicalTextAlign = "left" | "center" | "right";
|
|
47
|
+
/**
|
|
48
|
+
* Whitespace normalization mode for text measurement and layout.
|
|
49
|
+
*/
|
|
20
50
|
type TextWhitespaceMode = "preserve" | "trim-and-collapse";
|
|
51
|
+
/**
|
|
52
|
+
* Shared text styling options for text nodes.
|
|
53
|
+
*/
|
|
21
54
|
interface TextStyleOptions<C extends CanvasRenderingContext2D> {
|
|
55
|
+
/** Height of each rendered line in CSS pixels. */
|
|
22
56
|
lineHeight: number;
|
|
57
|
+
/** Canvas font string used for measurement and drawing. */
|
|
23
58
|
font: string;
|
|
59
|
+
/** Fill style or resolver used when drawing the text. */
|
|
24
60
|
style: DynValue<C, string>;
|
|
25
61
|
/** Default: preserve input whitespace, including blank lines and edge spaces. */
|
|
26
62
|
whitespace?: TextWhitespaceMode;
|
|
27
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Options for multi-line text nodes.
|
|
66
|
+
*/
|
|
28
67
|
interface MultilineTextOptions<C extends CanvasRenderingContext2D> extends TextStyleOptions<C> {
|
|
29
68
|
/** Logical alignment that matches `Place.align`. */
|
|
30
69
|
align?: TextAlign;
|
|
31
70
|
/** Explicit physical alignment when left/right semantics are required. */
|
|
32
71
|
physicalAlign?: PhysicalTextAlign;
|
|
33
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Options for single-line text nodes.
|
|
75
|
+
*/
|
|
34
76
|
interface TextOptions<C extends CanvasRenderingContext2D> extends TextStyleOptions<C> {}
|
|
77
|
+
/**
|
|
78
|
+
* Optional layout bounds passed down during measurement and drawing.
|
|
79
|
+
*/
|
|
35
80
|
interface LayoutConstraints {
|
|
81
|
+
/** Minimum width the node should occupy. */
|
|
36
82
|
minWidth?: number;
|
|
83
|
+
/** Maximum width the node may occupy. */
|
|
37
84
|
maxWidth?: number;
|
|
85
|
+
/** Minimum height the node should occupy. */
|
|
38
86
|
minHeight?: number;
|
|
87
|
+
/** Maximum height the node may occupy. */
|
|
39
88
|
maxHeight?: number;
|
|
40
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Per-child flex behavior overrides.
|
|
92
|
+
*/
|
|
41
93
|
interface FlexItemOptions {
|
|
94
|
+
/** Share of positive free space assigned to this item. */
|
|
42
95
|
grow?: number;
|
|
43
96
|
/** Compatibility-first default: 0 (opt-in shrink). */
|
|
44
97
|
shrink?: number;
|
|
98
|
+
/** Cross-axis alignment override for this item. */
|
|
45
99
|
alignSelf?: CrossAxisAlignment | "auto";
|
|
46
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Configuration for a flex container node.
|
|
103
|
+
*/
|
|
47
104
|
interface FlexContainerOptions {
|
|
105
|
+
/** Main axis direction. Defaults to `"row"`. */
|
|
48
106
|
direction?: Axis;
|
|
107
|
+
/** Gap inserted between adjacent items. */
|
|
49
108
|
gap?: number;
|
|
109
|
+
/** Main-axis distribution of free space. */
|
|
50
110
|
justifyContent?: MainAxisAlignment;
|
|
111
|
+
/** Default cross-axis alignment for children. */
|
|
51
112
|
alignItems?: CrossAxisAlignment;
|
|
113
|
+
/** Whether children should be laid out in reverse order. */
|
|
52
114
|
reverse?: boolean;
|
|
115
|
+
/** Whether the container fills or shrink-wraps the main axis. */
|
|
53
116
|
mainAxisSize?: MainAxisSize;
|
|
54
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Runtime services exposed to every node during layout, drawing, and hit-testing.
|
|
120
|
+
*/
|
|
55
121
|
interface Context<C extends CanvasRenderingContext2D> {
|
|
122
|
+
/** The backing canvas rendering context. */
|
|
56
123
|
graphics: C;
|
|
57
|
-
/**
|
|
124
|
+
/** Active layout constraints for the current call stack. */
|
|
58
125
|
constraints?: LayoutConstraints;
|
|
126
|
+
/** Measures another node under optional constraints. */
|
|
59
127
|
measureNode(node: Node<C>, constraints?: LayoutConstraints): Box;
|
|
128
|
+
/** Invalidates cached measurements for a node and its ancestors. */
|
|
60
129
|
invalidateNode(node: Node<C>): void;
|
|
130
|
+
/** Resolves a dynamic value against the current graphics context. */
|
|
61
131
|
resolveDynValue<T>(value: DynValue<C, T>): T;
|
|
132
|
+
/** Saves the canvas state for the callback and restores it afterwards. */
|
|
62
133
|
with<T>(this: Context<C>, cb: (g: C) => T): T;
|
|
63
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Width and height pair in CSS pixels.
|
|
137
|
+
*/
|
|
64
138
|
interface Box {
|
|
65
139
|
width: number;
|
|
66
140
|
height: number;
|
|
67
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Pointer test input routed through the node tree.
|
|
144
|
+
*/
|
|
68
145
|
interface HitTest {
|
|
69
146
|
x: number;
|
|
70
147
|
y: number;
|
|
71
148
|
type: "click" | "auxclick" | "hover";
|
|
72
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Fundamental layout node contract.
|
|
152
|
+
*/
|
|
73
153
|
interface Node<C extends CanvasRenderingContext2D> {
|
|
74
154
|
/** Measure the node under the current layout constraints. */
|
|
75
155
|
measure(ctx: Context<C>): Box;
|
|
@@ -78,18 +158,27 @@ interface Node<C extends CanvasRenderingContext2D> {
|
|
|
78
158
|
draw(ctx: Context<C>, x: number, y: number): boolean;
|
|
79
159
|
hittest(ctx: Context<C>, test: HitTest): boolean;
|
|
80
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Rectangular region in local coordinates.
|
|
163
|
+
*/
|
|
81
164
|
interface LayoutRect {
|
|
82
165
|
x: number;
|
|
83
166
|
y: number;
|
|
84
167
|
width: number;
|
|
85
168
|
height: number;
|
|
86
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Stored layout data for a single child node.
|
|
172
|
+
*/
|
|
87
173
|
interface ChildLayoutResult<C extends CanvasRenderingContext2D> {
|
|
88
174
|
node: Node<C>;
|
|
89
175
|
rect: LayoutRect;
|
|
90
176
|
contentBox: LayoutRect;
|
|
91
177
|
constraints?: LayoutConstraints;
|
|
92
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Cached layout data for a container and its children.
|
|
181
|
+
*/
|
|
93
182
|
interface FlexLayoutResult<C extends CanvasRenderingContext2D> {
|
|
94
183
|
containerBox: LayoutRect;
|
|
95
184
|
contentBox: LayoutRect;
|
|
@@ -98,19 +187,37 @@ interface FlexLayoutResult<C extends CanvasRenderingContext2D> {
|
|
|
98
187
|
}
|
|
99
188
|
//#endregion
|
|
100
189
|
//#region src/nodes/base.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* A node that owns an ordered list of child nodes.
|
|
192
|
+
*/
|
|
101
193
|
declare abstract class Group<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
102
194
|
#private;
|
|
195
|
+
/**
|
|
196
|
+
* @param children Initial child nodes, in layout order.
|
|
197
|
+
*/
|
|
103
198
|
constructor(children: Node<C>[]);
|
|
199
|
+
/** Child nodes managed by this group. */
|
|
104
200
|
get children(): readonly Node<C>[];
|
|
201
|
+
/**
|
|
202
|
+
* Replaces the full child list while updating parent links.
|
|
203
|
+
*/
|
|
105
204
|
replaceChildren(nextChildren: Node<C>[]): void;
|
|
106
205
|
abstract measure(ctx: Context<C>): Box;
|
|
107
206
|
abstract draw(ctx: Context<C>, x: number, y: number): boolean;
|
|
108
207
|
abstract hittest(ctx: Context<C>, test: HitTest): boolean;
|
|
109
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* A node that forwards layout and drawing to a single inner node.
|
|
211
|
+
*/
|
|
110
212
|
declare class Wrapper<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
111
213
|
#private;
|
|
214
|
+
/**
|
|
215
|
+
* @param inner Wrapped child node.
|
|
216
|
+
*/
|
|
112
217
|
constructor(inner: Node<C>);
|
|
218
|
+
/** The wrapped child node. */
|
|
113
219
|
get inner(): Node<C>;
|
|
220
|
+
/** Replaces the wrapped child node. */
|
|
114
221
|
set inner(newNode: Node<C>);
|
|
115
222
|
measure(ctx: Context<C>): Box;
|
|
116
223
|
measureMinContent(ctx: Context<C>): Box;
|
|
@@ -119,6 +226,9 @@ declare class Wrapper<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
|
119
226
|
}
|
|
120
227
|
//#endregion
|
|
121
228
|
//#region src/nodes/box.d.ts
|
|
229
|
+
/**
|
|
230
|
+
* Adds padding around a single child node.
|
|
231
|
+
*/
|
|
122
232
|
declare class PaddingBox<C extends CanvasRenderingContext2D> extends Wrapper<C> {
|
|
123
233
|
#private;
|
|
124
234
|
readonly padding: {
|
|
@@ -127,6 +237,10 @@ declare class PaddingBox<C extends CanvasRenderingContext2D> extends Wrapper<C>
|
|
|
127
237
|
left?: number;
|
|
128
238
|
right?: number;
|
|
129
239
|
};
|
|
240
|
+
/**
|
|
241
|
+
* @param inner Wrapped child node.
|
|
242
|
+
* @param padding Padding in CSS pixels on each side.
|
|
243
|
+
*/
|
|
130
244
|
constructor(inner: Node<C>, padding?: {
|
|
131
245
|
top?: number;
|
|
132
246
|
bottom?: number;
|
|
@@ -138,9 +252,16 @@ declare class PaddingBox<C extends CanvasRenderingContext2D> extends Wrapper<C>
|
|
|
138
252
|
draw(ctx: Context<C>, x: number, y: number): boolean;
|
|
139
253
|
hittest(ctx: Context<C>, test: HitTest): boolean;
|
|
140
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* A leaf node with a fixed size and no drawing behavior.
|
|
257
|
+
*/
|
|
141
258
|
declare class Fixed<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
142
259
|
readonly width: number;
|
|
143
260
|
readonly height: number;
|
|
261
|
+
/**
|
|
262
|
+
* @param width Fixed width in CSS pixels.
|
|
263
|
+
* @param height Fixed height in CSS pixels.
|
|
264
|
+
*/
|
|
144
265
|
constructor(width: number, height: number);
|
|
145
266
|
measure(_ctx: Context<C>): Box;
|
|
146
267
|
measureMinContent(_ctx: Context<C>): Box;
|
|
@@ -149,12 +270,26 @@ declare class Fixed<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
|
149
270
|
}
|
|
150
271
|
//#endregion
|
|
151
272
|
//#region src/nodes/flex.d.ts
|
|
273
|
+
/**
|
|
274
|
+
* Wraps a child node with per-item flex options.
|
|
275
|
+
*/
|
|
152
276
|
declare class FlexItem<C extends CanvasRenderingContext2D> extends Wrapper<C> {
|
|
153
277
|
readonly item: FlexItemOptions;
|
|
278
|
+
/**
|
|
279
|
+
* @param inner Wrapped child node.
|
|
280
|
+
* @param item Flex behavior overrides for the child.
|
|
281
|
+
*/
|
|
154
282
|
constructor(inner: Node<C>, item?: FlexItemOptions);
|
|
155
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Lays out children in a single flex row or column.
|
|
286
|
+
*/
|
|
156
287
|
declare class Flex<C extends CanvasRenderingContext2D> extends Group<C> {
|
|
157
288
|
readonly options: FlexContainerOptions;
|
|
289
|
+
/**
|
|
290
|
+
* @param children Child nodes in visual order.
|
|
291
|
+
* @param options Flex container configuration.
|
|
292
|
+
*/
|
|
158
293
|
constructor(children: Node<C>[], options?: FlexContainerOptions);
|
|
159
294
|
measure(ctx: Context<C>): Box;
|
|
160
295
|
measureMinContent(ctx: Context<C>): Box;
|
|
@@ -163,11 +298,18 @@ declare class Flex<C extends CanvasRenderingContext2D> extends Group<C> {
|
|
|
163
298
|
}
|
|
164
299
|
//#endregion
|
|
165
300
|
//#region src/nodes/place.d.ts
|
|
301
|
+
/**
|
|
302
|
+
* Aligns a single child horizontally within the available width.
|
|
303
|
+
*/
|
|
166
304
|
declare class Place<C extends CanvasRenderingContext2D> extends Wrapper<C> {
|
|
167
305
|
readonly options: {
|
|
168
306
|
align?: TextAlign;
|
|
169
307
|
expand?: boolean;
|
|
170
308
|
};
|
|
309
|
+
/**
|
|
310
|
+
* @param inner Wrapped child node.
|
|
311
|
+
* @param options Alignment behavior for the child.
|
|
312
|
+
*/
|
|
171
313
|
constructor(inner: Node<C>, options?: {
|
|
172
314
|
align?: TextAlign;
|
|
173
315
|
expand?: boolean;
|
|
@@ -179,9 +321,16 @@ declare class Place<C extends CanvasRenderingContext2D> extends Wrapper<C> {
|
|
|
179
321
|
}
|
|
180
322
|
//#endregion
|
|
181
323
|
//#region src/nodes/text.d.ts
|
|
324
|
+
/**
|
|
325
|
+
* Draws wrapped text using the configured line height and alignment.
|
|
326
|
+
*/
|
|
182
327
|
declare class MultilineText<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
183
328
|
readonly text: string;
|
|
184
329
|
readonly options: MultilineTextOptions<C>;
|
|
330
|
+
/**
|
|
331
|
+
* @param text Source text to measure and draw.
|
|
332
|
+
* @param options Text layout and drawing options.
|
|
333
|
+
*/
|
|
185
334
|
constructor(text: string, options: MultilineTextOptions<C>);
|
|
186
335
|
measure(ctx: Context<C>): Box;
|
|
187
336
|
measureMinContent(ctx: Context<C>): Box;
|
|
@@ -192,9 +341,16 @@ declare class MultilineText<C extends CanvasRenderingContext2D> implements Node<
|
|
|
192
341
|
type: "click" | "auxclick" | "hover";
|
|
193
342
|
}): boolean;
|
|
194
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Draws a single line of text, clipped logically by measurement width.
|
|
346
|
+
*/
|
|
195
347
|
declare class Text<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
196
348
|
readonly text: string;
|
|
197
349
|
readonly options: TextOptions<C>;
|
|
350
|
+
/**
|
|
351
|
+
* @param text Source text to measure and draw.
|
|
352
|
+
* @param options Text layout and drawing options.
|
|
353
|
+
*/
|
|
198
354
|
constructor(text: string, options: TextOptions<C>);
|
|
199
355
|
measure(ctx: Context<C>): Box;
|
|
200
356
|
measureMinContent(ctx: Context<C>): Box;
|
|
@@ -207,49 +363,105 @@ declare class Text<C extends CanvasRenderingContext2D> implements Node<C> {
|
|
|
207
363
|
}
|
|
208
364
|
//#endregion
|
|
209
365
|
//#region src/renderer/base.d.ts
|
|
366
|
+
/**
|
|
367
|
+
* Base renderer that provides measurement, layout caching, and drawing helpers.
|
|
368
|
+
*/
|
|
210
369
|
declare class BaseRenderer<C extends CanvasRenderingContext2D, O extends {} = {}> {
|
|
211
370
|
#private;
|
|
212
371
|
readonly options: RendererOptions & O;
|
|
372
|
+
/** Canvas rendering context used by this renderer. */
|
|
213
373
|
graphics: C;
|
|
214
374
|
protected get context(): Context<C>;
|
|
375
|
+
/**
|
|
376
|
+
* @param graphics Canvas rendering context used for all layout and drawing.
|
|
377
|
+
* @param options Renderer-specific options.
|
|
378
|
+
*/
|
|
215
379
|
constructor(graphics: C, options: RendererOptions & O);
|
|
216
380
|
protected getRootConstraints(): LayoutConstraints;
|
|
217
381
|
protected getRootContext(): Context<C>;
|
|
218
382
|
protected measureRootNode(node: Node<C>): Box;
|
|
219
383
|
protected drawRootNode(node: Node<C>, x?: number, y?: number): boolean;
|
|
220
384
|
protected hittestRootNode(node: Node<C>, test: HitTest): boolean;
|
|
385
|
+
/**
|
|
386
|
+
* Drops cached measurements for a node and every ancestor that depends on it.
|
|
387
|
+
*/
|
|
221
388
|
invalidateNode(node: Node<C>): void;
|
|
389
|
+
/**
|
|
390
|
+
* Returns the cached layout result for a node under the given constraints, if available.
|
|
391
|
+
*/
|
|
222
392
|
getLayoutResult(node: Node<C>, constraints?: LayoutConstraints): FlexLayoutResult<C> | undefined;
|
|
393
|
+
/**
|
|
394
|
+
* Stores a layout result for later draw and hit-test passes.
|
|
395
|
+
*/
|
|
223
396
|
setLayoutResult(node: Node<C>, result: FlexLayoutResult<C>, constraints?: LayoutConstraints): void;
|
|
224
397
|
protected getTextLayout<T>(node: Node<C>, key: string): T | undefined;
|
|
225
398
|
protected setTextLayout<T>(node: Node<C>, key: string, layout: T): void;
|
|
399
|
+
/**
|
|
400
|
+
* Measures a node under optional constraints, using cached results when possible.
|
|
401
|
+
*/
|
|
226
402
|
measureNode(node: Node<C>, constraints?: LayoutConstraints): Box;
|
|
227
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Immediate-mode renderer for a single root node.
|
|
406
|
+
*/
|
|
228
407
|
declare class DebugRenderer<C extends CanvasRenderingContext2D> extends BaseRenderer<C> {
|
|
408
|
+
/**
|
|
409
|
+
* Clears the viewport and draws the provided root node.
|
|
410
|
+
*/
|
|
229
411
|
draw(node: Node<C>): boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Hit-tests the provided root node using viewport-relative coordinates.
|
|
414
|
+
*/
|
|
230
415
|
hittest(node: Node<C>, test: HitTest): boolean;
|
|
231
416
|
}
|
|
232
417
|
//#endregion
|
|
233
418
|
//#region src/renderer/list-state.d.ts
|
|
419
|
+
/**
|
|
420
|
+
* Mutable list state shared with virtualized renderers.
|
|
421
|
+
*/
|
|
234
422
|
declare class ListState<T extends {}> {
|
|
423
|
+
/** Pixel offset from the anchored item edge. */
|
|
235
424
|
offset: number;
|
|
425
|
+
/** Anchor item index, or `undefined` to use the renderer default. */
|
|
236
426
|
position: number | undefined;
|
|
427
|
+
/** Items currently managed by the renderer. */
|
|
237
428
|
items: T[];
|
|
429
|
+
/**
|
|
430
|
+
* @param items Initial list items.
|
|
431
|
+
*/
|
|
238
432
|
constructor(items?: T[]);
|
|
433
|
+
/** Prepends one or more items. */
|
|
239
434
|
unshift(...items: T[]): void;
|
|
435
|
+
/** Prepends an array of items. */
|
|
240
436
|
unshiftAll(items: T[]): void;
|
|
437
|
+
/** Appends one or more items. */
|
|
241
438
|
push(...items: T[]): void;
|
|
439
|
+
/** Appends an array of items. */
|
|
242
440
|
pushAll(items: T[]): void;
|
|
441
|
+
/**
|
|
442
|
+
* Sets the current anchor item and pixel offset.
|
|
443
|
+
*/
|
|
243
444
|
setAnchor(position: number, offset?: number): void;
|
|
445
|
+
/**
|
|
446
|
+
* Replaces all items and clears scroll state.
|
|
447
|
+
*/
|
|
244
448
|
reset(items?: T[]): void;
|
|
449
|
+
/** Clears the current scroll anchor while keeping the items. */
|
|
245
450
|
resetScroll(): void;
|
|
451
|
+
/** Applies a relative pixel scroll delta. */
|
|
246
452
|
applyScroll(delta: number): void;
|
|
247
453
|
}
|
|
248
454
|
//#endregion
|
|
249
455
|
//#region src/renderer/memo.d.ts
|
|
456
|
+
/**
|
|
457
|
+
* Memoizes `renderItem` by object identity.
|
|
458
|
+
*/
|
|
250
459
|
declare function memoRenderItem<C extends CanvasRenderingContext2D, T extends object>(renderItem: (item: T) => Node<C>): ((item: T) => Node<C>) & {
|
|
251
460
|
reset: (key: T) => boolean;
|
|
252
461
|
};
|
|
462
|
+
/**
|
|
463
|
+
* Memoizes `renderItem` by a caller-provided cache key.
|
|
464
|
+
*/
|
|
253
465
|
declare function memoRenderItemBy<C extends CanvasRenderingContext2D, T, K>(keyOf: (item: T) => K, renderItem: (item: T) => Node<C>): ((item: T) => Node<C>) & {
|
|
254
466
|
reset: (item: T) => boolean;
|
|
255
467
|
resetKey: (key: K) => boolean;
|
|
@@ -276,12 +488,22 @@ interface VisibleWindow<T> {
|
|
|
276
488
|
}
|
|
277
489
|
//#endregion
|
|
278
490
|
//#region src/renderer/virtualized/base.d.ts
|
|
491
|
+
/**
|
|
492
|
+
* Options for programmatic scrolling to a target item.
|
|
493
|
+
*/
|
|
279
494
|
interface JumpToOptions {
|
|
495
|
+
/** Whether to animate the jump. Defaults to `true`. */
|
|
280
496
|
animated?: boolean;
|
|
497
|
+
/** Which edge of the item should align with the viewport. */
|
|
281
498
|
block?: "start" | "center" | "end";
|
|
499
|
+
/** Animation duration in milliseconds. */
|
|
282
500
|
duration?: number;
|
|
501
|
+
/** Called after the jump completes or finishes animating. */
|
|
283
502
|
onComplete?: () => void;
|
|
284
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Shared base class for virtualized list renderers.
|
|
506
|
+
*/
|
|
285
507
|
declare abstract class VirtualizedRenderer<C extends CanvasRenderingContext2D, T extends {}> extends BaseRenderer<C, {
|
|
286
508
|
renderItem: (item: T) => Node<C>;
|
|
287
509
|
list: ListState<T>;
|
|
@@ -290,13 +512,21 @@ declare abstract class VirtualizedRenderer<C extends CanvasRenderingContext2D, T
|
|
|
290
512
|
static readonly MIN_JUMP_DURATION = 160;
|
|
291
513
|
static readonly MAX_JUMP_DURATION = 420;
|
|
292
514
|
static readonly JUMP_DURATION_PER_ITEM = 28;
|
|
515
|
+
/** Current anchor item index. */
|
|
293
516
|
get position(): number | undefined;
|
|
517
|
+
/** Updates the current anchor item index. */
|
|
294
518
|
set position(value: number | undefined);
|
|
519
|
+
/** Pixel offset from the anchored item edge. */
|
|
295
520
|
get offset(): number;
|
|
521
|
+
/** Updates the pixel offset from the anchored item edge. */
|
|
296
522
|
set offset(value: number);
|
|
523
|
+
/** Items currently available to the renderer. */
|
|
297
524
|
get items(): T[];
|
|
525
|
+
/** Replaces the current item collection. */
|
|
298
526
|
set items(value: T[]);
|
|
527
|
+
/** Renders the current visible window. */
|
|
299
528
|
abstract render(feedback?: RenderFeedback): boolean;
|
|
529
|
+
/** Hit-tests the current visible window. */
|
|
300
530
|
abstract hittest(test: {
|
|
301
531
|
x: number;
|
|
302
532
|
y: number;
|
|
@@ -304,6 +534,9 @@ declare abstract class VirtualizedRenderer<C extends CanvasRenderingContext2D, T
|
|
|
304
534
|
}): boolean;
|
|
305
535
|
protected _readListState(): VisibleListState;
|
|
306
536
|
protected _commitListState(state: NormalizedListState): void;
|
|
537
|
+
/**
|
|
538
|
+
* Scrolls the viewport to the requested item index.
|
|
539
|
+
*/
|
|
307
540
|
jumpTo(index: number, options?: JumpToOptions): void;
|
|
308
541
|
protected _resetRenderFeedback(feedback?: RenderFeedback): void;
|
|
309
542
|
protected _accumulateRenderFeedback(feedback: RenderFeedback, idx: number, top: number, height: number): void;
|
|
@@ -327,6 +560,9 @@ declare abstract class VirtualizedRenderer<C extends CanvasRenderingContext2D, T
|
|
|
327
560
|
}
|
|
328
561
|
//#endregion
|
|
329
562
|
//#region src/renderer/virtualized/chat.d.ts
|
|
563
|
+
/**
|
|
564
|
+
* Virtualized renderer anchored to the bottom, suitable for chat-style UIs.
|
|
565
|
+
*/
|
|
330
566
|
declare class ChatRenderer<C extends CanvasRenderingContext2D, T extends {}> extends VirtualizedRenderer<C, T> {
|
|
331
567
|
#private;
|
|
332
568
|
protected _getDefaultJumpBlock(): NonNullable<JumpToOptions["block"]>;
|
|
@@ -339,6 +575,9 @@ declare class ChatRenderer<C extends CanvasRenderingContext2D, T extends {}> ext
|
|
|
339
575
|
}
|
|
340
576
|
//#endregion
|
|
341
577
|
//#region src/renderer/virtualized/timeline.d.ts
|
|
578
|
+
/**
|
|
579
|
+
* Virtualized renderer anchored to the top, suitable for timeline-style UIs.
|
|
580
|
+
*/
|
|
342
581
|
declare class TimelineRenderer<C extends CanvasRenderingContext2D, T extends {}> extends VirtualizedRenderer<C, T> {
|
|
343
582
|
#private;
|
|
344
583
|
protected _getDefaultJumpBlock(): NonNullable<JumpToOptions["block"]>;
|