@mizchi/vlmkit-core 0.9.0 → 0.11.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.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/a11y-semantic.d.mts +1 -6
  3. package/dist/a11y-semantic.mjs +1 -6
  4. package/dist/apng.d.mts +42 -0
  5. package/dist/apng.mjs +199 -0
  6. package/dist/arg-reader.d.mts +3 -1
  7. package/dist/arg-reader.mjs +8 -1
  8. package/dist/auth-state.d.mts +14 -3
  9. package/dist/auth-state.mjs +30 -6
  10. package/dist/bitmap-font.d.mts +48 -0
  11. package/dist/bitmap-font.mjs +945 -0
  12. package/dist/browser-launch.d.mts +65 -0
  13. package/dist/browser-launch.mjs +194 -0
  14. package/dist/cli-args.d.mts +1 -6
  15. package/dist/cli-args.mjs +1 -6
  16. package/dist/cli-error.d.mts +79 -1
  17. package/dist/cli-error.mjs +188 -20
  18. package/dist/dom-equivalence.d.mts +2 -7
  19. package/dist/dom-equivalence.mjs +1 -6
  20. package/dist/element-compare.mjs +8 -11
  21. package/dist/filmstrip.d.mts +121 -0
  22. package/dist/filmstrip.mjs +181 -0
  23. package/dist/gate-config.d.mts +107 -22
  24. package/dist/gate-config.mjs +138 -9
  25. package/dist/heatmap.d.mts +48 -4
  26. package/dist/heatmap.mjs +157 -12
  27. package/dist/index.d.mts +8 -6
  28. package/dist/index.mjs +6 -4
  29. package/dist/mask.d.mts +66 -2
  30. package/dist/mask.mjs +91 -4
  31. package/dist/page-load.d.mts +83 -0
  32. package/dist/page-load.mjs +116 -0
  33. package/dist/page-open.d.mts +123 -2
  34. package/dist/page-open.mjs +176 -6
  35. package/dist/plugin/args.d.mts +86 -0
  36. package/dist/plugin/args.mjs +162 -0
  37. package/dist/plugin/browser.d.mts +6 -0
  38. package/dist/plugin/browser.mjs +6 -0
  39. package/dist/plugin/cli-entry.d.mts +11 -0
  40. package/dist/plugin/cli-entry.mjs +69 -0
  41. package/dist/plugin/contract.d.mts +270 -0
  42. package/dist/plugin/contract.mjs +51 -0
  43. package/dist/plugin/index.d.mts +82 -0
  44. package/dist/plugin/index.mjs +81 -0
  45. package/dist/plugin/load.d.mts +36 -0
  46. package/dist/plugin/load.mjs +98 -0
  47. package/dist/plugin/registry.d.mts +60 -0
  48. package/dist/plugin/registry.mjs +160 -0
  49. package/dist/plugin/rule-tier.d.mts +65 -0
  50. package/dist/plugin/rule-tier.mjs +77 -0
  51. package/dist/plugin/rules.d.mts +112 -0
  52. package/dist/plugin/rules.mjs +188 -0
  53. package/dist/plugin/runner.d.mts +198 -0
  54. package/dist/plugin/runner.mjs +440 -0
  55. package/dist/png-utils.d.mts +31 -1
  56. package/dist/png-utils.mjs +24 -1
  57. package/dist/project-config.d.mts +12 -0
  58. package/dist/project-config.mjs +28 -0
  59. package/dist/rect-overlap.d.mts +41 -0
  60. package/dist/rect-overlap.mjs +28 -0
  61. package/dist/run-ledger.d.mts +56 -2
  62. package/dist/run-ledger.mjs +102 -11
  63. package/dist/types.d.mts +60 -1
  64. package/dist/version.d.mts +20 -0
  65. package/dist/version.mjs +20 -0
  66. package/dist/webp.d.mts +31 -0
  67. package/dist/webp.mjs +105 -0
  68. package/package.json +19 -3
  69. package/dist/legacy-names.d.mts +0 -48
  70. package/dist/legacy-names.mjs +0 -134
@@ -0,0 +1,945 @@
1
+ //#region src/bitmap-font.ts
2
+ /**
3
+ * A 5x7 bitmap font, drawn here rather than taken from the system.
4
+ *
5
+ * Labels were kept out of the filmstrip on the grounds that text would make the
6
+ * output depend on font rendering — the class of platform-dependent pixel this
7
+ * toolkit exists to catch. A dogfood agent answered that precisely:
8
+ *
9
+ * "The rationale (font rendering is platform-dependent pixels) is sound for VRT
10
+ * baselines, but this artifact is *not* a baseline — it is an attachment whose
11
+ * whole job is to be read by a human out of context."
12
+ *
13
+ * Nothing pixel-compares a filmstrip. And glyphs we own settle it either way:
14
+ * identical bytes on every platform, no fontconfig, no hinting, no metrics, no
15
+ * async font load to race a screenshot.
16
+ *
17
+ * Coverage is printable ASCII (0x20-0x7e), which is what a CSS selector, a
18
+ * millisecond count and a row index need. Anything outside it is dropped rather
19
+ * than substituted, so a label can never come out as a row of boxes.
20
+ */
21
+ /** Rows are top-to-bottom, `1` = ink. Each string is 5 columns wide. */
22
+ const GLYPHS = {
23
+ " ": [
24
+ "00000",
25
+ "00000",
26
+ "00000",
27
+ "00000",
28
+ "00000",
29
+ "00000",
30
+ "00000"
31
+ ],
32
+ "!": [
33
+ "00100",
34
+ "00100",
35
+ "00100",
36
+ "00100",
37
+ "00100",
38
+ "00000",
39
+ "00100"
40
+ ],
41
+ "\"": [
42
+ "01010",
43
+ "01010",
44
+ "00000",
45
+ "00000",
46
+ "00000",
47
+ "00000",
48
+ "00000"
49
+ ],
50
+ "#": [
51
+ "01010",
52
+ "01010",
53
+ "11111",
54
+ "01010",
55
+ "11111",
56
+ "01010",
57
+ "01010"
58
+ ],
59
+ $: [
60
+ "00100",
61
+ "01111",
62
+ "10100",
63
+ "01110",
64
+ "00101",
65
+ "11110",
66
+ "00100"
67
+ ],
68
+ "%": [
69
+ "11001",
70
+ "11010",
71
+ "00010",
72
+ "00100",
73
+ "01000",
74
+ "01011",
75
+ "10011"
76
+ ],
77
+ "&": [
78
+ "01100",
79
+ "10010",
80
+ "10100",
81
+ "01000",
82
+ "10101",
83
+ "10010",
84
+ "01101"
85
+ ],
86
+ "'": [
87
+ "00100",
88
+ "00100",
89
+ "00000",
90
+ "00000",
91
+ "00000",
92
+ "00000",
93
+ "00000"
94
+ ],
95
+ "(": [
96
+ "00010",
97
+ "00100",
98
+ "01000",
99
+ "01000",
100
+ "01000",
101
+ "00100",
102
+ "00010"
103
+ ],
104
+ ")": [
105
+ "01000",
106
+ "00100",
107
+ "00010",
108
+ "00010",
109
+ "00010",
110
+ "00100",
111
+ "01000"
112
+ ],
113
+ "*": [
114
+ "00000",
115
+ "00100",
116
+ "10101",
117
+ "01110",
118
+ "10101",
119
+ "00100",
120
+ "00000"
121
+ ],
122
+ "+": [
123
+ "00000",
124
+ "00100",
125
+ "00100",
126
+ "11111",
127
+ "00100",
128
+ "00100",
129
+ "00000"
130
+ ],
131
+ ",": [
132
+ "00000",
133
+ "00000",
134
+ "00000",
135
+ "00000",
136
+ "00000",
137
+ "00100",
138
+ "01000"
139
+ ],
140
+ "-": [
141
+ "00000",
142
+ "00000",
143
+ "00000",
144
+ "01110",
145
+ "00000",
146
+ "00000",
147
+ "00000"
148
+ ],
149
+ ".": [
150
+ "00000",
151
+ "00000",
152
+ "00000",
153
+ "00000",
154
+ "00000",
155
+ "01100",
156
+ "01100"
157
+ ],
158
+ "/": [
159
+ "00001",
160
+ "00010",
161
+ "00010",
162
+ "00100",
163
+ "01000",
164
+ "01000",
165
+ "10000"
166
+ ],
167
+ "0": [
168
+ "01110",
169
+ "10001",
170
+ "10011",
171
+ "10101",
172
+ "11001",
173
+ "10001",
174
+ "01110"
175
+ ],
176
+ "1": [
177
+ "00100",
178
+ "01100",
179
+ "00100",
180
+ "00100",
181
+ "00100",
182
+ "00100",
183
+ "01110"
184
+ ],
185
+ "2": [
186
+ "01110",
187
+ "10001",
188
+ "00001",
189
+ "00010",
190
+ "00100",
191
+ "01000",
192
+ "11111"
193
+ ],
194
+ "3": [
195
+ "11110",
196
+ "00001",
197
+ "00001",
198
+ "01110",
199
+ "00001",
200
+ "00001",
201
+ "11110"
202
+ ],
203
+ "4": [
204
+ "00010",
205
+ "00110",
206
+ "01010",
207
+ "10010",
208
+ "11111",
209
+ "00010",
210
+ "00010"
211
+ ],
212
+ "5": [
213
+ "11111",
214
+ "10000",
215
+ "11110",
216
+ "00001",
217
+ "00001",
218
+ "10001",
219
+ "01110"
220
+ ],
221
+ "6": [
222
+ "00110",
223
+ "01000",
224
+ "10000",
225
+ "11110",
226
+ "10001",
227
+ "10001",
228
+ "01110"
229
+ ],
230
+ "7": [
231
+ "11111",
232
+ "00001",
233
+ "00010",
234
+ "00100",
235
+ "01000",
236
+ "01000",
237
+ "01000"
238
+ ],
239
+ "8": [
240
+ "01110",
241
+ "10001",
242
+ "10001",
243
+ "01110",
244
+ "10001",
245
+ "10001",
246
+ "01110"
247
+ ],
248
+ "9": [
249
+ "01110",
250
+ "10001",
251
+ "10001",
252
+ "01111",
253
+ "00001",
254
+ "00010",
255
+ "01100"
256
+ ],
257
+ ":": [
258
+ "00000",
259
+ "01100",
260
+ "01100",
261
+ "00000",
262
+ "01100",
263
+ "01100",
264
+ "00000"
265
+ ],
266
+ ";": [
267
+ "00000",
268
+ "01100",
269
+ "01100",
270
+ "00000",
271
+ "01100",
272
+ "00100",
273
+ "01000"
274
+ ],
275
+ "<": [
276
+ "00010",
277
+ "00100",
278
+ "01000",
279
+ "10000",
280
+ "01000",
281
+ "00100",
282
+ "00010"
283
+ ],
284
+ "=": [
285
+ "00000",
286
+ "00000",
287
+ "11111",
288
+ "00000",
289
+ "11111",
290
+ "00000",
291
+ "00000"
292
+ ],
293
+ ">": [
294
+ "01000",
295
+ "00100",
296
+ "00010",
297
+ "00001",
298
+ "00010",
299
+ "00100",
300
+ "01000"
301
+ ],
302
+ "?": [
303
+ "01110",
304
+ "10001",
305
+ "00001",
306
+ "00010",
307
+ "00100",
308
+ "00000",
309
+ "00100"
310
+ ],
311
+ "@": [
312
+ "01110",
313
+ "10001",
314
+ "10111",
315
+ "10101",
316
+ "10111",
317
+ "10000",
318
+ "01110"
319
+ ],
320
+ A: [
321
+ "01110",
322
+ "10001",
323
+ "10001",
324
+ "11111",
325
+ "10001",
326
+ "10001",
327
+ "10001"
328
+ ],
329
+ B: [
330
+ "11110",
331
+ "10001",
332
+ "10001",
333
+ "11110",
334
+ "10001",
335
+ "10001",
336
+ "11110"
337
+ ],
338
+ C: [
339
+ "01110",
340
+ "10001",
341
+ "10000",
342
+ "10000",
343
+ "10000",
344
+ "10001",
345
+ "01110"
346
+ ],
347
+ D: [
348
+ "11110",
349
+ "10001",
350
+ "10001",
351
+ "10001",
352
+ "10001",
353
+ "10001",
354
+ "11110"
355
+ ],
356
+ E: [
357
+ "11111",
358
+ "10000",
359
+ "10000",
360
+ "11110",
361
+ "10000",
362
+ "10000",
363
+ "11111"
364
+ ],
365
+ F: [
366
+ "11111",
367
+ "10000",
368
+ "10000",
369
+ "11110",
370
+ "10000",
371
+ "10000",
372
+ "10000"
373
+ ],
374
+ G: [
375
+ "01110",
376
+ "10001",
377
+ "10000",
378
+ "10111",
379
+ "10001",
380
+ "10001",
381
+ "01110"
382
+ ],
383
+ H: [
384
+ "10001",
385
+ "10001",
386
+ "10001",
387
+ "11111",
388
+ "10001",
389
+ "10001",
390
+ "10001"
391
+ ],
392
+ I: [
393
+ "01110",
394
+ "00100",
395
+ "00100",
396
+ "00100",
397
+ "00100",
398
+ "00100",
399
+ "01110"
400
+ ],
401
+ J: [
402
+ "00111",
403
+ "00010",
404
+ "00010",
405
+ "00010",
406
+ "00010",
407
+ "10010",
408
+ "01100"
409
+ ],
410
+ K: [
411
+ "10001",
412
+ "10010",
413
+ "10100",
414
+ "11000",
415
+ "10100",
416
+ "10010",
417
+ "10001"
418
+ ],
419
+ L: [
420
+ "10000",
421
+ "10000",
422
+ "10000",
423
+ "10000",
424
+ "10000",
425
+ "10000",
426
+ "11111"
427
+ ],
428
+ M: [
429
+ "10001",
430
+ "11011",
431
+ "10101",
432
+ "10101",
433
+ "10001",
434
+ "10001",
435
+ "10001"
436
+ ],
437
+ N: [
438
+ "10001",
439
+ "11001",
440
+ "10101",
441
+ "10011",
442
+ "10001",
443
+ "10001",
444
+ "10001"
445
+ ],
446
+ O: [
447
+ "01110",
448
+ "10001",
449
+ "10001",
450
+ "10001",
451
+ "10001",
452
+ "10001",
453
+ "01110"
454
+ ],
455
+ P: [
456
+ "11110",
457
+ "10001",
458
+ "10001",
459
+ "11110",
460
+ "10000",
461
+ "10000",
462
+ "10000"
463
+ ],
464
+ Q: [
465
+ "01110",
466
+ "10001",
467
+ "10001",
468
+ "10001",
469
+ "10101",
470
+ "10011",
471
+ "01111"
472
+ ],
473
+ R: [
474
+ "11110",
475
+ "10001",
476
+ "10001",
477
+ "11110",
478
+ "10100",
479
+ "10010",
480
+ "10001"
481
+ ],
482
+ S: [
483
+ "01111",
484
+ "10000",
485
+ "10000",
486
+ "01110",
487
+ "00001",
488
+ "00001",
489
+ "11110"
490
+ ],
491
+ T: [
492
+ "11111",
493
+ "00100",
494
+ "00100",
495
+ "00100",
496
+ "00100",
497
+ "00100",
498
+ "00100"
499
+ ],
500
+ U: [
501
+ "10001",
502
+ "10001",
503
+ "10001",
504
+ "10001",
505
+ "10001",
506
+ "10001",
507
+ "01110"
508
+ ],
509
+ V: [
510
+ "10001",
511
+ "10001",
512
+ "10001",
513
+ "10001",
514
+ "10001",
515
+ "01010",
516
+ "00100"
517
+ ],
518
+ W: [
519
+ "10001",
520
+ "10001",
521
+ "10001",
522
+ "10101",
523
+ "10101",
524
+ "11011",
525
+ "10001"
526
+ ],
527
+ X: [
528
+ "10001",
529
+ "10001",
530
+ "01010",
531
+ "00100",
532
+ "01010",
533
+ "10001",
534
+ "10001"
535
+ ],
536
+ Y: [
537
+ "10001",
538
+ "10001",
539
+ "01010",
540
+ "00100",
541
+ "00100",
542
+ "00100",
543
+ "00100"
544
+ ],
545
+ Z: [
546
+ "11111",
547
+ "00001",
548
+ "00010",
549
+ "00100",
550
+ "01000",
551
+ "10000",
552
+ "11111"
553
+ ],
554
+ "[": [
555
+ "00110",
556
+ "00100",
557
+ "00100",
558
+ "00100",
559
+ "00100",
560
+ "00100",
561
+ "00110"
562
+ ],
563
+ "\\": [
564
+ "10000",
565
+ "01000",
566
+ "01000",
567
+ "00100",
568
+ "00010",
569
+ "00010",
570
+ "00001"
571
+ ],
572
+ "]": [
573
+ "01100",
574
+ "00100",
575
+ "00100",
576
+ "00100",
577
+ "00100",
578
+ "00100",
579
+ "01100"
580
+ ],
581
+ "^": [
582
+ "00100",
583
+ "01010",
584
+ "10001",
585
+ "00000",
586
+ "00000",
587
+ "00000",
588
+ "00000"
589
+ ],
590
+ _: [
591
+ "00000",
592
+ "00000",
593
+ "00000",
594
+ "00000",
595
+ "00000",
596
+ "00000",
597
+ "11111"
598
+ ],
599
+ "`": [
600
+ "01000",
601
+ "00100",
602
+ "00000",
603
+ "00000",
604
+ "00000",
605
+ "00000",
606
+ "00000"
607
+ ],
608
+ a: [
609
+ "00000",
610
+ "00000",
611
+ "01110",
612
+ "00001",
613
+ "01111",
614
+ "10001",
615
+ "01111"
616
+ ],
617
+ b: [
618
+ "10000",
619
+ "10000",
620
+ "11110",
621
+ "10001",
622
+ "10001",
623
+ "10001",
624
+ "11110"
625
+ ],
626
+ c: [
627
+ "00000",
628
+ "00000",
629
+ "01110",
630
+ "10000",
631
+ "10000",
632
+ "10001",
633
+ "01110"
634
+ ],
635
+ d: [
636
+ "00001",
637
+ "00001",
638
+ "01111",
639
+ "10001",
640
+ "10001",
641
+ "10001",
642
+ "01111"
643
+ ],
644
+ e: [
645
+ "00000",
646
+ "00000",
647
+ "01110",
648
+ "10001",
649
+ "11111",
650
+ "10000",
651
+ "01110"
652
+ ],
653
+ f: [
654
+ "00110",
655
+ "01000",
656
+ "01000",
657
+ "11110",
658
+ "01000",
659
+ "01000",
660
+ "01000"
661
+ ],
662
+ g: [
663
+ "00000",
664
+ "00000",
665
+ "01110",
666
+ "10010",
667
+ "01110",
668
+ "00010",
669
+ "01100"
670
+ ],
671
+ h: [
672
+ "10000",
673
+ "10000",
674
+ "11110",
675
+ "10001",
676
+ "10001",
677
+ "10001",
678
+ "10001"
679
+ ],
680
+ i: [
681
+ "00100",
682
+ "00000",
683
+ "01100",
684
+ "00100",
685
+ "00100",
686
+ "00100",
687
+ "01110"
688
+ ],
689
+ j: [
690
+ "00100",
691
+ "00000",
692
+ "00100",
693
+ "00100",
694
+ "00100",
695
+ "00100",
696
+ "01000"
697
+ ],
698
+ k: [
699
+ "10000",
700
+ "10000",
701
+ "10010",
702
+ "10100",
703
+ "11000",
704
+ "10100",
705
+ "10010"
706
+ ],
707
+ l: [
708
+ "01100",
709
+ "00100",
710
+ "00100",
711
+ "00100",
712
+ "00100",
713
+ "00100",
714
+ "01110"
715
+ ],
716
+ m: [
717
+ "00000",
718
+ "00000",
719
+ "11010",
720
+ "10101",
721
+ "10101",
722
+ "10101",
723
+ "10101"
724
+ ],
725
+ n: [
726
+ "00000",
727
+ "00000",
728
+ "11110",
729
+ "10001",
730
+ "10001",
731
+ "10001",
732
+ "10001"
733
+ ],
734
+ o: [
735
+ "00000",
736
+ "00000",
737
+ "01110",
738
+ "10001",
739
+ "10001",
740
+ "10001",
741
+ "01110"
742
+ ],
743
+ p: [
744
+ "00000",
745
+ "00000",
746
+ "11100",
747
+ "10010",
748
+ "11100",
749
+ "10000",
750
+ "10000"
751
+ ],
752
+ q: [
753
+ "00000",
754
+ "00000",
755
+ "01110",
756
+ "10010",
757
+ "01110",
758
+ "00010",
759
+ "00010"
760
+ ],
761
+ r: [
762
+ "00000",
763
+ "00000",
764
+ "01110",
765
+ "10001",
766
+ "10000",
767
+ "10000",
768
+ "10000"
769
+ ],
770
+ s: [
771
+ "00000",
772
+ "00000",
773
+ "01111",
774
+ "10000",
775
+ "01110",
776
+ "00001",
777
+ "11110"
778
+ ],
779
+ t: [
780
+ "01000",
781
+ "01000",
782
+ "11110",
783
+ "01000",
784
+ "01000",
785
+ "01001",
786
+ "00110"
787
+ ],
788
+ u: [
789
+ "00000",
790
+ "00000",
791
+ "10001",
792
+ "10001",
793
+ "10001",
794
+ "10001",
795
+ "01111"
796
+ ],
797
+ v: [
798
+ "00000",
799
+ "00000",
800
+ "10001",
801
+ "10001",
802
+ "10001",
803
+ "01010",
804
+ "00100"
805
+ ],
806
+ w: [
807
+ "00000",
808
+ "00000",
809
+ "10001",
810
+ "10001",
811
+ "10101",
812
+ "10101",
813
+ "01010"
814
+ ],
815
+ x: [
816
+ "00000",
817
+ "00000",
818
+ "10001",
819
+ "01010",
820
+ "00100",
821
+ "01010",
822
+ "10001"
823
+ ],
824
+ y: [
825
+ "00000",
826
+ "00000",
827
+ "10001",
828
+ "10001",
829
+ "01110",
830
+ "00010",
831
+ "01100"
832
+ ],
833
+ z: [
834
+ "00000",
835
+ "00000",
836
+ "11111",
837
+ "00010",
838
+ "00100",
839
+ "01000",
840
+ "11111"
841
+ ],
842
+ "{": [
843
+ "00110",
844
+ "00100",
845
+ "00100",
846
+ "01000",
847
+ "00100",
848
+ "00100",
849
+ "00110"
850
+ ],
851
+ "|": [
852
+ "00100",
853
+ "00100",
854
+ "00100",
855
+ "00100",
856
+ "00100",
857
+ "00100",
858
+ "00100"
859
+ ],
860
+ "}": [
861
+ "01100",
862
+ "00100",
863
+ "00100",
864
+ "00010",
865
+ "00100",
866
+ "00100",
867
+ "01100"
868
+ ],
869
+ "~": [
870
+ "00000",
871
+ "00000",
872
+ "01001",
873
+ "10101",
874
+ "10010",
875
+ "00000",
876
+ "00000"
877
+ ]
878
+ };
879
+ const GLYPH_WIDTH = 5;
880
+ const GLYPH_HEIGHT = 7;
881
+ /** One blank column between glyphs, so an advance is 6 columns at scale 1. */
882
+ const ADVANCE = 6;
883
+ /** Height in px of one line at `scale`. */
884
+ function textHeight(scale = 1) {
885
+ return 7 * scale;
886
+ }
887
+ /** Width in px of `text` at `scale`, excluding the trailing blank column. */
888
+ function measureText(text, scale = 1) {
889
+ const drawable = [...text].filter((ch) => ch in GLYPHS).length;
890
+ if (drawable === 0) return 0;
891
+ return (drawable * ADVANCE - 1) * scale;
892
+ }
893
+ /**
894
+ * The longest prefix of `text` that fits in `maxWidth`, with a trailing `..` when
895
+ * something was dropped.
896
+ *
897
+ * Truncation is at the *end* deliberately, even though the distinguishing part of a
898
+ * CSS selector is usually its tail: a label whose head is cut cannot be matched back
899
+ * to the terminal output at all, while one whose tail is cut still can.
900
+ */
901
+ function fitText(text, maxWidth, scale = 1) {
902
+ if (measureText(text, scale) <= maxWidth) return text;
903
+ const ellipsis = "..";
904
+ const room = maxWidth - measureText(ellipsis, scale);
905
+ if (room <= 0) return "";
906
+ let out = "";
907
+ for (const ch of text) {
908
+ if (measureText(out + ch, scale) > room) break;
909
+ out += ch;
910
+ }
911
+ return out + ellipsis;
912
+ }
913
+ /**
914
+ * Draw `text` into an RGBA buffer with its top-left at (x, y). Writes fully opaque
915
+ * ink; pixels outside the buffer are skipped rather than wrapped.
916
+ */
917
+ function drawText(target, text, x, y, rgb, scale = 1) {
918
+ let cursor = x;
919
+ for (const ch of text) {
920
+ const glyph = GLYPHS[ch];
921
+ if (!glyph) continue;
922
+ for (let row = 0; row < 7; row++) {
923
+ const bits = glyph[row];
924
+ for (let col = 0; col < 5; col++) {
925
+ if (bits[col] !== "1") continue;
926
+ for (let dy = 0; dy < scale; dy++) {
927
+ const py = y + row * scale + dy;
928
+ if (py < 0 || py >= target.height) continue;
929
+ for (let dx = 0; dx < scale; dx++) {
930
+ const px = cursor + col * scale + dx;
931
+ if (px < 0 || px >= target.width) continue;
932
+ const i = (py * target.width + px) * 4;
933
+ target.data[i] = rgb[0];
934
+ target.data[i + 1] = rgb[1];
935
+ target.data[i + 2] = rgb[2];
936
+ target.data[i + 3] = 255;
937
+ }
938
+ }
939
+ }
940
+ }
941
+ cursor += ADVANCE * scale;
942
+ }
943
+ }
944
+ //#endregion
945
+ export { GLYPH_HEIGHT, GLYPH_WIDTH, drawText, fitText, measureText, textHeight };