chat-layout 0.0.19 → 0.1.1

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.js DELETED
@@ -1,999 +0,0 @@
1
- // @bun
2
- // text.civet
3
- function layoutFirstLine(ctx, text, maxWidth) {
4
- if (maxWidth < 0) {
5
- maxWidth = 0;
6
- }
7
- const line = text.replaceAll(/[^\S\n]+/g, " ").split(`
8
- `, 1)[0].trim();
9
- const { width: textWidth, fontBoundingBoxAscent: ascent = 0, fontBoundingBoxDescent: descent = 0 } = ctx.graphics.measureText(line);
10
- const shift = ascent - descent;
11
- if (textWidth <= maxWidth) {
12
- return { width: textWidth, text: line, shift };
13
- } else {
14
- const { width, text: text2 } = splitToFitText(ctx, line, maxWidth, textWidth);
15
- return { width, text: text2, shift };
16
- }
17
- }
18
- function layoutText(ctx, text, maxWidth) {
19
- if (maxWidth < 0) {
20
- maxWidth = 0;
21
- }
22
- const results = [];
23
- for (let ref = text.replaceAll(/[^\S\n]+/g, " ").split(`
24
- `), i = 0, len = ref.length;i < len; i++) {
25
- const line = ref[i];
26
- const trimed = line.trim();
27
- if (!trimed) {
28
- continue;
29
- }
30
- results.push(trimed);
31
- }
32
- const inputLines = results;
33
- if (inputLines.length === 0) {
34
- return { width: 0, lines: [] };
35
- }
36
- let width = 0;
37
- const lines = [];
38
- for (let i1 = 0, len1 = inputLines.length;i1 < len1; i1++) {
39
- let line = inputLines[i1];
40
- let { width: textWidth, fontBoundingBoxAscent: ascent = 0, fontBoundingBoxDescent: descent = 0 } = ctx.graphics.measureText(line);
41
- const shift = ascent - descent;
42
- if (textWidth <= maxWidth) {
43
- width = Math.max(width, textWidth);
44
- lines.push({ width: textWidth, text: line, shift });
45
- } else {
46
- while (textWidth > maxWidth) {
47
- const splited = splitToFitText(ctx, line, maxWidth, textWidth);
48
- if (splited.width === 0) {
49
- return { width: 0, lines: [] };
50
- }
51
- width = Math.max(width, splited.width);
52
- lines.push({ text: splited.text, width: splited.width, shift });
53
- line = splited.rest;
54
- ({ width: textWidth } = ctx.graphics.measureText(line));
55
- }
56
- if (textWidth > 0) {
57
- width = Math.max(width, textWidth);
58
- lines.push({ width: textWidth, text: line, shift });
59
- }
60
- }
61
- }
62
- return { width, lines };
63
- }
64
- function splitToFitText(ctx, text, width, totalWidth) {
65
- const arr = ctx.splitText(text);
66
- let guess = Math.floor(width / totalWidth * arr.length);
67
- let guessText;
68
- let { width: guessWidth } = ctx.graphics.measureText(guessText = arr.slice(0, guess).join(""));
69
- while (!(guessWidth >= width)) {
70
- guess++;
71
- ({ width: guessWidth } = ctx.graphics.measureText(guessText = arr.slice(0, guess).join("")));
72
- }
73
- while (guessWidth > width) {
74
- const lastSpace = arr.lastIndexOf(" ", guess - 1);
75
- if (lastSpace > 0) {
76
- guess = lastSpace;
77
- } else {
78
- guess--;
79
- }
80
- ({ width: guessWidth } = ctx.graphics.measureText(guessText = arr.slice(0, guess).join("")));
81
- }
82
- return {
83
- text: guessText,
84
- width: guessWidth,
85
- rest: arr.slice(guess).join("").trimStart()
86
- };
87
- }
88
-
89
- // utils.civet
90
- function shallow(object) {
91
- return Object.create(object);
92
- }
93
- function shallowMerge(object, other) {
94
- return { __proto__: object, ...other };
95
- }
96
-
97
- // registry.civet
98
- var registry = new WeakMap;
99
- function registerNodeParent(node, parent) {
100
- registry.set(node, parent);
101
- }
102
- function unregisterNodeParent(node) {
103
- registry.delete(node);
104
- }
105
- function getNodeParent(node) {
106
- return registry.get(node);
107
- }
108
-
109
- // nodes.civet
110
- class Group {
111
- children;
112
- constructor(children) {
113
- this.children = children;
114
- for (let i = 0, len = children.length;i < len; i++) {
115
- const child = children[i];
116
- registerNodeParent(child, this);
117
- }
118
- }
119
- get flex() {
120
- let results = false;
121
- for (let ref = this.children, i1 = 0, len1 = ref.length;i1 < len1; i1++) {
122
- const item = ref[i1];
123
- if (item.flex) {
124
- results = true;
125
- break;
126
- }
127
- }
128
- return results;
129
- }
130
- }
131
-
132
- class VStack extends Group {
133
- options;
134
- constructor(children, options = {}) {
135
- super(children);
136
- this.options = options;
137
- }
138
- measure(ctx) {
139
- let width = 0;
140
- let height = 0;
141
- if (this.options.alignment != null) {
142
- ctx.alignment = this.options.alignment;
143
- }
144
- for (let ref1 = this.children, i2 = 0, len2 = ref1.length;i2 < len2; i2++) {
145
- const index = i2;
146
- const child = ref1[i2];
147
- if (this.options.gap != null && index !== 0) {
148
- height += this.options.gap;
149
- }
150
- let result = shallow(ctx).measureNode(child);
151
- height += result.height;
152
- width = Math.max(width, result.width);
153
- }
154
- ctx.remainingWidth -= width;
155
- return { width, height };
156
- }
157
- draw(ctx, x, y) {
158
- let result = false;
159
- const fullwidth = ctx.measureNode(this).width;
160
- const alignment = this.options.alignment ?? ctx.alignment;
161
- if (this.options.alignment != null) {
162
- ctx.alignment = this.options.alignment;
163
- }
164
- for (let ref2 = this.children, i3 = 0, len3 = ref2.length;i3 < len3; i3++) {
165
- const index = i3;
166
- const child = ref2[i3];
167
- if (this.options.gap != null && index !== 0) {
168
- y += this.options.gap;
169
- }
170
- let { width, height } = shallow(ctx).measureNode(child);
171
- const curctx = shallow(ctx);
172
- let ref3;
173
- if (alignment === "right") {
174
- ref3 = child.draw(curctx, x + fullwidth - width, y);
175
- } else if (alignment === "center") {
176
- ref3 = child.draw(curctx, x + (fullwidth - width) / 2, y);
177
- } else {
178
- ref3 = child.draw(curctx, x, y);
179
- }
180
- const request_redraw = ref3;
181
- result ||= request_redraw;
182
- y += height;
183
- }
184
- return result;
185
- }
186
- hittest(ctx, test) {
187
- let y = 0;
188
- const fullwidth = ctx.measureNode(this).width;
189
- const alignment = this.options.alignment ?? ctx.alignment;
190
- if (this.options.alignment != null) {
191
- ctx.alignment = this.options.alignment;
192
- }
193
- for (let ref4 = this.children, i4 = 0, len4 = ref4.length;i4 < len4; i4++) {
194
- const index = i4;
195
- const child = ref4[i4];
196
- if (this.options.gap != null && index !== 0) {
197
- y += this.options.gap;
198
- }
199
- let { width, height } = shallow(ctx).measureNode(child);
200
- const curctx = shallow(ctx);
201
- if (test.y >= y && test.y < y + height) {
202
- let ref5;
203
- if (alignment === "right") {
204
- ref5 = test.x - fullwidth + width;
205
- } else if (alignment === "center") {
206
- ref5 = test.x - (fullwidth - width) / 2;
207
- } else {
208
- ref5 = test.x;
209
- }
210
- const x = ref5;
211
- if (x < 0 || x >= width) {
212
- return false;
213
- }
214
- return child.hittest(curctx, shallowMerge(test, {
215
- x,
216
- y: test.y - y
217
- }));
218
- }
219
- y += height;
220
- }
221
- return false;
222
- }
223
- }
224
-
225
- class HStack extends Group {
226
- children;
227
- options;
228
- constructor(children, options = {}) {
229
- super(children);
230
- this.children = children;
231
- this.options = options;
232
- }
233
- measure(ctx) {
234
- let width = 0;
235
- let height = 0;
236
- let firstflex;
237
- for (let ref6 = this.children, i5 = 0, len5 = ref6.length;i5 < len5; i5++) {
238
- const index = i5;
239
- const child = ref6[i5];
240
- if (this.options.gap != null && index !== 0) {
241
- width += this.options.gap;
242
- }
243
- if (firstflex == null && child.flex) {
244
- firstflex = child;
245
- continue;
246
- }
247
- const curctx = shallow(ctx);
248
- curctx.remainingWidth = ctx.remainingWidth - width;
249
- const result = curctx.measureNode(child);
250
- width += result.width;
251
- height = Math.max(height, result.height);
252
- }
253
- if (firstflex != null) {
254
- const curctx = shallow(ctx);
255
- curctx.remainingWidth = ctx.remainingWidth - width;
256
- const result = curctx.measureNode(firstflex);
257
- width += result.width;
258
- height = Math.max(height, result.height);
259
- }
260
- return { width, height };
261
- }
262
- draw(ctx, x, y) {
263
- let result = false;
264
- const reverse = this.options.reverse ?? ctx.reverse;
265
- if (this.options.reverse) {
266
- ctx.reverse = this.options.reverse;
267
- }
268
- if (reverse) {
269
- x += ctx.measureNode(this).width;
270
- for (let ref7 = this.children, i6 = 0, len6 = ref7.length;i6 < len6; i6++) {
271
- const index = i6;
272
- const child = ref7[i6];
273
- let ref8;
274
- if (ref8 = this.options.gap != null && index !== 0 ? this.options.gap : undefined) {
275
- const gap = ref8;
276
- x -= gap;
277
- ctx.remainingWidth -= gap;
278
- }
279
- const { width } = shallow(ctx).measureNode(child);
280
- x -= width;
281
- const request_redraw = child.draw(shallow(ctx), x, y);
282
- result ||= request_redraw;
283
- ctx.remainingWidth -= width;
284
- }
285
- } else {
286
- for (let ref9 = this.children, i7 = 0, len7 = ref9.length;i7 < len7; i7++) {
287
- const index = i7;
288
- const child = ref9[i7];
289
- let ref10;
290
- if (ref10 = this.options.gap != null && index !== 0 ? this.options.gap : undefined) {
291
- const gap = ref10;
292
- x += gap;
293
- ctx.remainingWidth -= gap;
294
- }
295
- const request_redraw = child.draw(shallow(ctx), x, y);
296
- result ||= request_redraw;
297
- const { width } = shallow(ctx).measureNode(child);
298
- ctx.remainingWidth -= width;
299
- x += width;
300
- }
301
- }
302
- return result;
303
- }
304
- hittest(ctx, test) {
305
- const reverse = this.options.reverse ?? ctx.reverse;
306
- if (this.options.reverse) {
307
- ctx.reverse = this.options.reverse;
308
- }
309
- if (reverse) {
310
- let x = ctx.measureNode(this).width;
311
- for (let ref11 = this.children, i8 = 0, len8 = ref11.length;i8 < len8; i8++) {
312
- const index = i8;
313
- const child = ref11[i8];
314
- let ref12;
315
- if (ref12 = this.options.gap != null && index !== 0 ? this.options.gap : undefined) {
316
- const gap = ref12;
317
- x -= gap;
318
- ctx.remainingWidth -= gap;
319
- }
320
- const { width, height } = shallow(ctx).measureNode(child);
321
- x -= width;
322
- let ref13;
323
- if (x <= (ref13 = test.x) && ref13 < x + width) {
324
- if (test.y >= height) {
325
- return false;
326
- }
327
- return child.hittest(shallow(ctx), shallowMerge(test, {
328
- x: test.x - x
329
- }));
330
- }
331
- ctx.remainingWidth -= width;
332
- }
333
- } else {
334
- let x = 0;
335
- for (let ref14 = this.children, i9 = 0, len9 = ref14.length;i9 < len9; i9++) {
336
- const index = i9;
337
- const child = ref14[i9];
338
- let ref15;
339
- if (ref15 = this.options.gap != null && index !== 0 ? this.options.gap : undefined) {
340
- const gap = ref15;
341
- x += gap;
342
- ctx.remainingWidth -= gap;
343
- }
344
- const { width, height } = shallow(ctx).measureNode(child);
345
- let ref16;
346
- if (x <= (ref16 = test.x) && ref16 < x + width) {
347
- if (test.y >= height) {
348
- return false;
349
- }
350
- return child.hittest(shallow(ctx), shallowMerge(test, {
351
- x: test.x - x
352
- }));
353
- }
354
- x += width;
355
- ctx.remainingWidth -= width;
356
- }
357
- }
358
- return false;
359
- }
360
- }
361
-
362
- class Wrapper {
363
- #inner;
364
- constructor(inner1) {
365
- this.#inner = inner1;
366
- registerNodeParent(this.#inner, this);
367
- }
368
- get inner() {
369
- return this.#inner;
370
- }
371
- set inner(newnode) {
372
- if (newnode === this.#inner) {
373
- return;
374
- }
375
- unregisterNodeParent(this.#inner);
376
- this.#inner = newnode;
377
- registerNodeParent(newnode, this);
378
- }
379
- get flex() {
380
- return this.inner.flex;
381
- }
382
- measure(ctx) {
383
- return this.inner.measure(ctx);
384
- }
385
- draw(ctx, x, y) {
386
- return this.inner.draw(ctx, x, y);
387
- }
388
- hittest(ctx, test) {
389
- return this.inner.hittest(ctx, test);
390
- }
391
- }
392
-
393
- class PaddingBox extends Wrapper {
394
- padding;
395
- constructor(inner, padding = {}) {
396
- super(inner);
397
- this.padding = padding;
398
- }
399
- get #top() {
400
- return this.padding.top ?? 0;
401
- }
402
- get #bottom() {
403
- return this.padding.bottom ?? 0;
404
- }
405
- get #left() {
406
- return this.padding.left ?? 0;
407
- }
408
- get #right() {
409
- return this.padding.right ?? 0;
410
- }
411
- measure(ctx) {
412
- ctx.remainingWidth -= this.#left + this.#right;
413
- const { width, height } = ctx.measureNode(this.inner);
414
- return {
415
- width: width + this.#left + this.#right,
416
- height: height + this.#top + this.#bottom
417
- };
418
- }
419
- draw(ctx, x, y) {
420
- ctx.remainingWidth -= this.#left + this.#right;
421
- return this.inner.draw(ctx, x + this.#left, y + this.#top);
422
- }
423
- hittest(ctx, test) {
424
- ctx.remainingWidth -= this.#left + this.#right;
425
- const { width, height } = shallow(ctx).measureNode(this.inner);
426
- let ref17;
427
- let ref18;
428
- if (0 <= (ref17 = test.x - this.#left) && ref17 < width && (0 <= (ref18 = test.y - this.#top) && ref18 < height)) {
429
- return this.inner.hittest(shallow(ctx), shallowMerge(test, {
430
- x: test.x - this.#left,
431
- y: test.y - this.#top
432
- }));
433
- }
434
- return false;
435
- }
436
- }
437
-
438
- class AlignBox extends Wrapper {
439
- options;
440
- #shift = 0;
441
- constructor(inner, options) {
442
- super(inner);
443
- this.options = options;
444
- }
445
- measure(ctx) {
446
- ctx.alignment = this.options.alignment;
447
- const { width, height } = ctx.measureNode(this.inner);
448
- let ref19;
449
- switch (this.options.alignment) {
450
- case "center": {
451
- ref19 = (ctx.remainingWidth - width) / 2;
452
- break;
453
- }
454
- case "right": {
455
- ref19 = ctx.remainingWidth - width;
456
- break;
457
- }
458
- default: {
459
- ref19 = 0;
460
- }
461
- }
462
- this.#shift = ref19;
463
- return {
464
- width: ctx.remainingWidth,
465
- height
466
- };
467
- }
468
- draw(ctx, x, y) {
469
- ctx.alignment = this.options.alignment;
470
- return this.inner.draw(ctx, x + this.#shift, y);
471
- }
472
- hittest(ctx, test) {
473
- ctx.alignment = this.options.alignment;
474
- const { width } = shallow(ctx).measureNode(this.inner);
475
- let ref20;
476
- if (0 <= (ref20 = test.x - this.#shift) && ref20 < width) {
477
- return this.inner.hittest(shallow(ctx), shallowMerge(test, {
478
- x: test.x - this.#shift
479
- }));
480
- }
481
- return false;
482
- }
483
- }
484
-
485
- class MultilineText {
486
- text;
487
- options;
488
- #width = 0;
489
- #lines = [];
490
- constructor(text, options) {
491
- this.text = text;
492
- this.options = options;
493
- }
494
- get flex() {
495
- return true;
496
- }
497
- measure(ctx) {
498
- return ctx.with((g) => {
499
- g.font = this.options.font;
500
- const { width: width1, lines } = layoutText(ctx, this.text, ctx.remainingWidth);
501
- this.#width = width1;
502
- this.#lines = lines;
503
- return { width: this.#width, height: this.#lines.length * this.options.lineHeight };
504
- });
505
- }
506
- draw(ctx, x, y) {
507
- return ctx.with((g) => {
508
- g.font = this.options.font;
509
- g.fillStyle = ctx.resolveDynValue(this.options.style);
510
- switch (this.options.alignment) {
511
- case "left": {
512
- for (let ref21 = this.#lines, i10 = 0, len10 = ref21.length;i10 < len10; i10++) {
513
- const { text, shift } = ref21[i10];
514
- g.fillText(text, x, y + (this.options.lineHeight + shift) / 2);
515
- y += this.options.lineHeight;
516
- }
517
- break;
518
- }
519
- case "right": {
520
- x += this.#width;
521
- g.textAlign = "right";
522
- for (let ref22 = this.#lines, i11 = 0, len11 = ref22.length;i11 < len11; i11++) {
523
- const { text, shift } = ref22[i11];
524
- g.fillText(text, x, y + (this.options.lineHeight + shift) / 2);
525
- y += this.options.lineHeight;
526
- }
527
- break;
528
- }
529
- case "center": {
530
- x += this.#width / 2;
531
- g.textAlign = "center";
532
- for (let ref23 = this.#lines, i12 = 0, len12 = ref23.length;i12 < len12; i12++) {
533
- const { text, shift } = ref23[i12];
534
- g.fillText(text, x, y + (this.options.lineHeight + shift) / 2);
535
- y += this.options.lineHeight;
536
- }
537
- break;
538
- }
539
- }
540
- return false;
541
- });
542
- }
543
- hittest(ctx, test) {
544
- return false;
545
- }
546
- }
547
-
548
- class Text {
549
- text;
550
- options;
551
- constructor(text, options) {
552
- this.text = text;
553
- this.options = options;
554
- }
555
- #width = 0;
556
- #text = "";
557
- #shift = 0;
558
- get flex() {
559
- return false;
560
- }
561
- measure(ctx) {
562
- return ctx.with((g) => {
563
- g.font = this.options.font;
564
- const { width: width2, text: text1, shift: shift1 } = layoutFirstLine(ctx, this.text, ctx.remainingWidth);
565
- this.#width = width2;
566
- this.#text = text1;
567
- this.#shift = shift1;
568
- return { width: this.#width, height: this.options.lineHeight };
569
- });
570
- }
571
- draw(ctx, x, y) {
572
- return ctx.with((g) => {
573
- g.font = this.options.font;
574
- g.fillStyle = ctx.resolveDynValue(this.options.style);
575
- g.fillText(this.#text, x, y + (this.options.lineHeight + this.#shift) / 2);
576
- return false;
577
- });
578
- }
579
- hittest(ctx, test) {
580
- return false;
581
- }
582
- }
583
-
584
- class Fixed {
585
- width;
586
- height;
587
- constructor(width, height) {
588
- this.width = width;
589
- this.height = height;
590
- }
591
- get flex() {
592
- return false;
593
- }
594
- measure(ctx) {
595
- return { width: this.width, height: this.height };
596
- }
597
- draw(ctx, x, y) {
598
- return false;
599
- }
600
- hittest(ctx, test) {
601
- return false;
602
- }
603
- }
604
- // renderer.civet
605
- var concatAssign = (lhs, rhs) => (rhs?.[Symbol.isConcatSpreadable] ?? Array.isArray(rhs) ? lhs.push.apply(lhs, rhs) : lhs.push(rhs), lhs);
606
-
607
- class BaseRenderer {
608
- options;
609
- graphics;
610
- #ctx;
611
- #lastWidth;
612
- #cache = new WeakMap;
613
- get context() {
614
- return shallow(this.#ctx);
615
- }
616
- constructor(graphics1, options) {
617
- this.options = options;
618
- this.graphics = graphics1;
619
- this.graphics.textRendering = "optimizeLegibility";
620
- const self = this;
621
- this.#ctx = {
622
- graphics: this.graphics,
623
- get remainingWidth() {
624
- return this.graphics.canvas.clientWidth;
625
- },
626
- set remainingWidth(value) {
627
- Object.defineProperty(this, "remainingWidth", { value, writable: true });
628
- },
629
- alignment: "left",
630
- reverse: false,
631
- measureNode(node) {
632
- return self.measureNode(node, this);
633
- },
634
- invalidateNode: this.invalidateNode.bind(this),
635
- resolveDynValue(value) {
636
- if (typeof value === "function") {
637
- return value(this.graphics);
638
- } else {
639
- return value;
640
- }
641
- },
642
- with(cb) {
643
- this.graphics.save();
644
- try {
645
- return cb(this.graphics);
646
- } finally {
647
- this.graphics.restore();
648
- }
649
- },
650
- splitText(text) {
651
- return options.splitText(text);
652
- }
653
- };
654
- this.#lastWidth = this.graphics.canvas.clientWidth;
655
- }
656
- invalidateNode(node) {
657
- this.#cache.delete(node);
658
- let it = node;
659
- while (it = getNodeParent(it)) {
660
- this.#cache.delete(it);
661
- }
662
- }
663
- measureNode(node, ctx) {
664
- let ref;
665
- if (this.#lastWidth != this.graphics.canvas.clientWidth) {
666
- this.#cache = new WeakMap;
667
- this.#lastWidth = this.graphics.canvas.clientWidth;
668
- } else if ((ref = this.#cache.get(node)) != null) {
669
- const result2 = ref;
670
- return result2;
671
- }
672
- const result = node.measure(ctx ?? this.context);
673
- this.#cache.set(node, result);
674
- return result;
675
- }
676
- }
677
-
678
- class DebugRenderer extends BaseRenderer {
679
- draw(node) {
680
- const { clientWidth: viewportWidth, clientHeight: viewportHeight } = this.graphics.canvas;
681
- this.graphics.clearRect(0, 0, viewportWidth, viewportHeight);
682
- return node.draw(this.context, 0, 0);
683
- }
684
- hittest(node, test) {
685
- return node.hittest(this.context, test);
686
- }
687
- }
688
- function memoRenderItem(renderItem) {
689
- const cache = new WeakMap;
690
- function fn(item) {
691
- let ref1;
692
- if ((ref1 = cache.get(item)) != null) {
693
- const result2 = ref1;
694
- return result2;
695
- }
696
- const result = renderItem(item);
697
- cache.set(item, result);
698
- return result;
699
- }
700
- return Object.assign(fn, { reset: cache.delete.bind(cache) });
701
- }
702
-
703
- class ListState {
704
- offset = 0;
705
- position = NaN;
706
- items = [];
707
- unshift(...items) {
708
- return this.unshiftAll(items);
709
- }
710
- unshiftAll(items) {
711
- this.position += items.length;
712
- return this.items = items.concat(this.items);
713
- }
714
- push(...items) {
715
- return this.pushAll(items);
716
- }
717
- pushAll(items) {
718
- return concatAssign(this.items, items);
719
- }
720
- reset() {
721
- this.items = [];
722
- this.offset = 0;
723
- this.position = NaN;
724
- }
725
- resetScroll() {
726
- this.offset = 0;
727
- this.position = NaN;
728
- }
729
- applyScroll(delta) {
730
- return this.offset += delta;
731
- }
732
- }
733
-
734
- class VirtualizedRenderer extends BaseRenderer {
735
- get position() {
736
- return this.options.list.position;
737
- }
738
- set position(value) {
739
- this.options.list.position = value;
740
- }
741
- get offset() {
742
- return this.options.list.offset;
743
- }
744
- set offset(value) {
745
- this.options.list.offset = value;
746
- }
747
- get items() {
748
- return this.options.list.items;
749
- }
750
- set items(value) {
751
- this.options.list.items = value;
752
- }
753
- _renderDrawList(list, shift, feedback) {
754
- let result = false;
755
- const viewportHeight = this.graphics.canvas.clientHeight;
756
- for (let i1 = 0, len = list.length;i1 < len; i1++) {
757
- const { idx, node, offset, height } = list[i1];
758
- const y = offset + shift;
759
- if (y + height < 0 || y > viewportHeight) {
760
- continue;
761
- }
762
- if (feedback != null) {
763
- feedback.minIdx = isNaN(feedback.minIdx) ? idx : Math.min(idx, feedback.minIdx);
764
- feedback.maxIdx = isNaN(feedback.maxIdx) ? idx : Math.max(idx, feedback.maxIdx);
765
- if (feedback.minIdx === idx) {
766
- feedback.min = idx - Math.min(0, y) / height;
767
- }
768
- if (feedback.maxIdx === idx) {
769
- feedback.max = idx - Math.max(0, y + height - viewportHeight) / height;
770
- }
771
- }
772
- if (node.draw(this.context, 0, y)) {
773
- result = true;
774
- }
775
- }
776
- return result;
777
- }
778
- }
779
-
780
- class TimelineRenderer extends VirtualizedRenderer {
781
- render(feedback) {
782
- const { clientWidth: viewportWidth, clientHeight: viewportHeight } = this.graphics.canvas;
783
- this.graphics.clearRect(0, 0, viewportWidth, viewportHeight);
784
- let drawlength = 0;
785
- if (isNaN(this.position)) {
786
- this.position = 0;
787
- }
788
- if (this.offset > 0) {
789
- if (this.position == 0) {
790
- this.offset = 0;
791
- } else {
792
- for (let i2 = this.position - 1;i2 >= 0; --i2) {
793
- const i = i2;
794
- const item = this.items[i];
795
- const node = this.options.renderItem(item);
796
- const { height } = this.measureNode(node);
797
- this.position = i;
798
- this.offset -= height;
799
- if (this.offset <= 0) {
800
- break;
801
- }
802
- }
803
- if (this.position == 0 && this.offset > 0) {
804
- this.offset = 0;
805
- }
806
- }
807
- }
808
- let y = this.offset;
809
- const drawlist = [];
810
- for (let end = this.items.length, i3 = this.position;i3 < end; ++i3) {
811
- const i = i3;
812
- const item = this.items[i];
813
- const node = this.options.renderItem(item);
814
- const { height } = this.measureNode(node);
815
- if (y + height > 0) {
816
- drawlist.push({ idx: i, node, offset: y, height });
817
- drawlength += height;
818
- } else {
819
- this.offset += height;
820
- this.position = i + 1;
821
- }
822
- y += height;
823
- if (y >= viewportHeight) {
824
- break;
825
- }
826
- }
827
- let shift = 0;
828
- if (y < viewportHeight) {
829
- if (this.position == 0 && drawlength < viewportHeight) {
830
- shift = -this.offset;
831
- this.offset = 0;
832
- } else {
833
- shift = viewportHeight - y;
834
- y = this.offset += shift;
835
- let lastidx = -1;
836
- for (let i4 = this.position - 1;i4 >= 0; --i4) {
837
- const i = i4;
838
- const item = this.items[lastidx = i];
839
- const node = this.options.renderItem(item);
840
- const { height } = this.measureNode(node);
841
- drawlength += height;
842
- y -= height;
843
- drawlist.push({ idx: i, node, offset: y - shift, height });
844
- if (y < 0) {
845
- break;
846
- }
847
- }
848
- if (lastidx == 0 && drawlength < viewportHeight) {
849
- shift = -drawlist[drawlist.length - 1].offset;
850
- this.position = 0;
851
- this.offset = 0;
852
- }
853
- }
854
- }
855
- return this._renderDrawList(drawlist, shift, feedback);
856
- }
857
- hittest(test) {
858
- const viewportHeight = this.graphics.canvas.clientHeight;
859
- let y = this.offset;
860
- for (let end1 = this.items.length, i5 = this.position;i5 < end1; ++i5) {
861
- const i = i5;
862
- const item = this.items[i];
863
- const node = this.options.renderItem(item);
864
- const { height } = this.measureNode(node);
865
- if (test.y < y + height) {
866
- return node.hittest(this.context, shallowMerge(test, { y: test.y - y }));
867
- }
868
- y += height;
869
- if (y >= viewportHeight) {
870
- break;
871
- }
872
- }
873
- return false;
874
- }
875
- }
876
-
877
- class ChatRenderer extends VirtualizedRenderer {
878
- render(feedback) {
879
- const { clientWidth: viewportWidth, clientHeight: viewportHeight } = this.graphics.canvas;
880
- this.graphics.clearRect(0, 0, viewportWidth, viewportHeight);
881
- let drawlength = 0;
882
- if (isNaN(this.position)) {
883
- this.position = this.items.length - 1;
884
- }
885
- if (this.offset < 0) {
886
- if (this.position == this.items.length - 1) {
887
- this.offset = 0;
888
- } else {
889
- for (let end2 = this.items.length, i6 = this.position + 1;i6 < end2; ++i6) {
890
- const i = i6;
891
- const item = this.items[i];
892
- const node = this.options.renderItem(item);
893
- const { height } = this.measureNode(node);
894
- this.position = i;
895
- this.offset += height;
896
- if (this.offset > 0) {
897
- break;
898
- }
899
- }
900
- }
901
- }
902
- let y = viewportHeight + this.offset;
903
- const drawlist = [];
904
- for (let i7 = this.position;i7 >= 0; --i7) {
905
- const i = i7;
906
- const item = this.items[i];
907
- const node = this.options.renderItem(item);
908
- const { height } = this.measureNode(node);
909
- y -= height;
910
- if (y <= viewportHeight) {
911
- drawlist.push({ idx: i, node, offset: y, height });
912
- drawlength += height;
913
- } else {
914
- this.offset -= height;
915
- this.position = i - 1;
916
- }
917
- if (y < 0) {
918
- break;
919
- }
920
- }
921
- let shift = 0;
922
- if (y > 0) {
923
- shift = -y;
924
- if (drawlength < viewportHeight) {
925
- y = drawlength;
926
- for (let end3 = this.items.length, i8 = this.position + 1;i8 < end3; ++i8) {
927
- const i = i8;
928
- const item = this.items[i];
929
- const node = this.options.renderItem(item);
930
- const { height } = this.measureNode(node);
931
- drawlist.push({ idx: i, node, offset: y - shift, height });
932
- y = drawlength += height;
933
- this.position = i;
934
- if (y >= viewportHeight) {
935
- break;
936
- }
937
- }
938
- if (drawlength < viewportHeight) {
939
- this.offset = 0;
940
- } else {
941
- this.offset = drawlength - viewportHeight;
942
- }
943
- } else {
944
- this.offset = drawlength - viewportHeight;
945
- }
946
- }
947
- return this._renderDrawList(drawlist, shift, feedback);
948
- }
949
- hittest(test) {
950
- const viewportHeight = this.graphics.canvas.clientHeight;
951
- let drawlength = 0;
952
- const results = [];
953
- for (let i9 = this.position;i9 >= 0; --i9) {
954
- const i = i9;
955
- const item = this.items[i];
956
- const node = this.options.renderItem(item);
957
- const { height } = this.measureNode(node);
958
- drawlength += height;
959
- results.push([node, height]);
960
- }
961
- const heights = results;
962
- let y = drawlength < viewportHeight ? drawlength : viewportHeight + this.offset;
963
- if (test.y > y) {
964
- return false;
965
- }
966
- for (let i10 = 0, len1 = heights.length;i10 < len1; i10++) {
967
- const [node, height] = heights[i10];
968
- y -= height;
969
- if (test.y > y) {
970
- return node.hittest(this.context, shallowMerge(test, { y: test.y - y }));
971
- }
972
- }
973
- return false;
974
- }
975
- }
976
- export {
977
- unregisterNodeParent,
978
- registerNodeParent,
979
- memoRenderItem,
980
- getNodeParent,
981
- Wrapper,
982
- VirtualizedRenderer,
983
- VStack,
984
- TimelineRenderer,
985
- Text,
986
- PaddingBox,
987
- MultilineText,
988
- ListState,
989
- HStack,
990
- Group,
991
- Fixed,
992
- DebugRenderer,
993
- ChatRenderer,
994
- BaseRenderer,
995
- AlignBox
996
- };
997
-
998
- //# debugId=79360317C92E227D64756E2164756E21
999
- //# sourceMappingURL=index.js.map