ghostty-web-umd-bindgen 0.1.0

wasm-bindgen bindings for the ghostty-web UMD global GhosttyWeb
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
//! `wasm-bindgen` bindings for the [`ghostty-web`](https://github.com/coder/ghostty-web) UMD global `GhosttyWeb`.
//!
//! Tries to mirror the definitions from `ghostty-web/dist/index.d.ts`.
//! Created from the `ghostty-web` version `0.4.0`.

#![allow(non_snake_case)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::new_without_default)]

pub mod builders;

use js_sys::Array;
use js_sys::Boolean;
use js_sys::Function;
use js_sys::JsOption;
use js_sys::JsString;
use js_sys::Number;
use js_sys::Object;
use js_sys::Promise;
use js_sys::Set;
use js_sys::Uint8Array;
use js_sys::Undefined;
use js_sys::WebAssembly;
pub use wasm_bindgen::JsGeneric;
use wasm_bindgen::prelude::*;
use web_sys::HtmlCanvasElement;
use web_sys::HtmlElement;
use web_sys::HtmlTextAreaElement;
use web_sys::KeyboardEvent;
use web_sys::MouseEvent;
use web_sys::WheelEvent;

/// Opaque terminal pointer (WASM memory address).
pub type TerminalHandle = f64;

/// `IEvent<T> = (listener: (arg: T) => void) => IDisposable`
pub type IEvent<T> = Function<fn(Function<fn(T) -> Undefined>) -> IDisposable>;

/// Void-payload event: `(listener: () => void) => IDisposable`
pub type IEventVoid = Function<fn(Function<fn() -> Undefined>) -> IDisposable>;

/// Cell style flags (bitfield)
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct CellFlags(pub u32);

impl CellFlags
{
    pub const BOLD: Self = Self(1);
    pub const ITALIC: Self = Self(2);
    pub const UNDERLINE: Self = Self(4);
    pub const STRIKETHROUGH: Self = Self(8);
    pub const INVERSE: Self = Self(16);
    pub const INVISIBLE: Self = Self(32);
    pub const BLINK: Self = Self(64);
    pub const FAINT: Self = Self(128);

    #[inline]
    pub const fn bits(self) -> u32 { self.0 }

    #[inline]
    pub const fn contains(self, other: Self) -> bool { (self.0 & other.0) == other.0 }
}

impl core::ops::BitOr for CellFlags
{
    type Output = Self;
    #[inline]
    fn bitor(self, rhs: Self) -> Self { Self(self.0 | rhs.0) }
}

impl core::ops::BitAnd for CellFlags
{
    type Output = Self;
    #[inline]
    fn bitand(self, rhs: Self) -> Self { Self(self.0 & rhs.0) }
}

/// Dirty state from RenderState
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum DirtyState
{
    None = 0,
    Partial = 1,
    Full = 2,
}

impl DirtyState
{
    pub fn from_u32(value: u32) -> Self
    {
        match value
        {
            1 => Self::Partial,
            2 => Self::Full,
            _ => Self::None,
        }
    }
}

/// Key action
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum KeyAction
{
    Release = 0,
    Press = 1,
    Repeat = 2,
}

/// Key encoder options
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum KeyEncoderOption
{
    /// DEC mode 1
    CursorKeyApplication = 0,
    /// DEC mode 66
    KeypadKeyApplication = 1,
    /// DEC mode 1035
    IgnoreKeypadWithNumlock = 2,
    /// DEC mode 1036
    AltEscPrefix = 3,
    /// xterm modifyOtherKeys
    ModifyOtherKeysState2 = 4,
    KittyKeyboardFlags = 5,
}

/// Kitty keyboard protocol flags
///
/// From `include/ghostty/vt/key/encoder.h`
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct KittyKeyFlags(pub u32);

impl KittyKeyFlags
{
    pub const DISABLED: Self = Self(0);
    /// Disambiguate escape codes
    pub const DISAMBIGUATE: Self = Self(1);
    /// Report press and release
    pub const REPORT_EVENTS: Self = Self(2);
    /// Report alternate key codes
    pub const REPORT_ALTERNATES: Self = Self(4);
    /// Report all events
    pub const REPORT_ALL: Self = Self(8);
    /// Report associated text
    pub const REPORT_ASSOCIATED: Self = Self(16);
    pub const ALL: Self = Self(31);

    #[inline]
    pub const fn bits(self) -> u32 { self.0 }
}

impl core::ops::BitOr for KittyKeyFlags
{
    type Output = Self;
    #[inline]
    fn bitor(self, rhs: Self) -> Self { Self(self.0 | rhs.0) }
}

/// Modifier keys
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct Mods(pub u32);

impl Mods
{
    pub const NONE: Self = Self(0);
    pub const SHIFT: Self = Self(1);
    pub const CTRL: Self = Self(2);
    pub const ALT: Self = Self(4);
    /// Windows/Command key
    pub const SUPER: Self = Self(8);
    pub const CAPSLOCK: Self = Self(16);
    pub const NUMLOCK: Self = Self(32);

    #[inline]
    pub const fn bits(self) -> u32 { self.0 }

    #[inline]
    pub const fn contains(self, other: Self) -> bool { (self.0 & other.0) == other.0 }
}

impl core::ops::BitOr for Mods
{
    type Output = Self;
    #[inline]
    fn bitor(self, rhs: Self) -> Self { Self(self.0 | rhs.0) }
}

impl core::ops::BitAnd for Mods
{
    type Output = Self;
    #[inline]
    fn bitand(self, rhs: Self) -> Self { Self(self.0 & rhs.0) }
}

/// Physical key codes matching Ghostty's internal Key enum.
///
/// These values are used by Ghostty's key encoder to produce correct escape
/// sequences. Reference: `ghostty/src/input/key.zig`
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum Key
{
    Unidentified = 0,
    /// `` ` `` and `~`
    Grave = 1,
    /// `\` and `|`
    Backslash = 2,
    /// `[` and `{`
    BracketLeft = 3,
    /// `]` and `}`
    BracketRight = 4,
    /// `,` and `<`
    Comma = 5,
    Zero = 6,
    One = 7,
    Two = 8,
    Three = 9,
    Four = 10,
    Five = 11,
    Six = 12,
    Seven = 13,
    Eight = 14,
    Nine = 15,
    /// `=` and `+`
    Equal = 16,
    IntlBackslash = 17,
    IntlRo = 18,
    IntlYen = 19,
    A = 20,
    B = 21,
    C = 22,
    D = 23,
    E = 24,
    F = 25,
    G = 26,
    H = 27,
    I = 28,
    J = 29,
    K = 30,
    L = 31,
    M = 32,
    N = 33,
    O = 34,
    P = 35,
    Q = 36,
    R = 37,
    S = 38,
    T = 39,
    U = 40,
    V = 41,
    W = 42,
    X = 43,
    Y = 44,
    Z = 45,
    /// `-` and `_`
    Minus = 46,
    /// `.` and `>`
    Period = 47,
    /// `'` and `"`
    Quote = 48,
    /// `;` and `:`
    Semicolon = 49,
    /// `/` and `?`
    Slash = 50,
    AltLeft = 51,
    AltRight = 52,
    Backspace = 53,
    CapsLock = 54,
    ContextMenu = 55,
    ControlLeft = 56,
    ControlRight = 57,
    Enter = 58,
    MetaLeft = 59,
    MetaRight = 60,
    ShiftLeft = 61,
    ShiftRight = 62,
    Space = 63,
    Tab = 64,
    Convert = 65,
    KanaMode = 66,
    NonConvert = 67,
    Delete = 68,
    End = 69,
    Help = 70,
    Home = 71,
    Insert = 72,
    PageDown = 73,
    PageUp = 74,
    Down = 75,
    Left = 76,
    Right = 77,
    Up = 78,
    NumLock = 79,
    Kp0 = 80,
    Kp1 = 81,
    Kp2 = 82,
    Kp3 = 83,
    Kp4 = 84,
    Kp5 = 85,
    Kp6 = 86,
    Kp7 = 87,
    Kp8 = 88,
    Kp9 = 89,
    /// Keypad `+`
    KpPlus = 90,
    KpBackspace = 91,
    KpClear = 92,
    KpClearEntry = 93,
    KpComma = 94,
    /// Keypad `.`
    KpPeriod = 95,
    /// Keypad `/`
    KpDivide = 96,
    /// Keypad Enter
    KpEnter = 97,
    KpEqual = 98,
    KpMemoryAdd = 99,
    KpMemoryClear = 100,
    KpMemoryRecall = 101,
    KpMemoryStore = 102,
    KpMemorySubtract = 103,
    /// Keypad `*`
    KpMultiply = 104,
    KpParenLeft = 105,
    KpParenRight = 106,
    /// Keypad `-`
    KpMinus = 107,
    KpSeparator = 108,
    NumpadUp = 109,
    NumpadDown = 110,
    NumpadRight = 111,
    NumpadLeft = 112,
    NumpadBegin = 113,
    NumpadHome = 114,
    NumpadEnd = 115,
    NumpadInsert = 116,
    NumpadDelete = 117,
    NumpadPageUp = 118,
    NumpadPageDown = 119,
    Escape = 120,
    F1 = 121,
    F2 = 122,
    F3 = 123,
    F4 = 124,
    F5 = 125,
    F6 = 126,
    F7 = 127,
    F8 = 128,
    F9 = 129,
    F10 = 130,
    F11 = 131,
    F12 = 132,
    F13 = 133,
    F14 = 134,
    F15 = 135,
    F16 = 136,
    F17 = 137,
    F18 = 138,
    F19 = 139,
    F20 = 140,
    F21 = 141,
    F22 = 142,
    F23 = 143,
    F24 = 144,
    F25 = 145,
    FnLock = 146,
    PrintScreen = 147,
    ScrollLock = 148,
    Pause = 149,
    BrowserBack = 150,
    BrowserFavorites = 151,
    BrowserForward = 152,
    BrowserHome = 153,
    BrowserRefresh = 154,
    BrowserSearch = 155,
    BrowserStop = 156,
    Eject = 157,
    LaunchApp1 = 158,
    LaunchApp2 = 159,
    LaunchMail = 160,
    MediaPlayPause = 161,
    MediaSelect = 162,
    MediaStop = 163,
    MediaTrackNext = 164,
    MediaTrackPrevious = 165,
    Power = 166,
    Sleep = 167,
    AudioVolumeDown = 168,
    AudioVolumeMute = 169,
    AudioVolumeUp = 170,
    WakeUp = 171,
    Copy = 172,
    Cut = 173,
    Paste = 174,
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ITheme;

    #[wasm_bindgen(method, setter, js_name = foreground)]
    pub fn set_foreground(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = background)]
    pub fn set_background(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = cursor)]
    pub fn set_cursor(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = cursorAccent)]
    pub fn set_cursor_accent(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = selectionBackground)]
    pub fn set_selection_background(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = selectionForeground)]
    pub fn set_selection_foreground(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_black(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_red(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_green(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_yellow(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_blue(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_magenta(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_cyan(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_white(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightBlack)]
    pub fn set_bright_black(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightRed)]
    pub fn set_bright_red(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightGreen)]
    pub fn set_bright_green(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightYellow)]
    pub fn set_bright_yellow(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightBlue)]
    pub fn set_bright_blue(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightMagenta)]
    pub fn set_bright_magenta(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightCyan)]
    pub fn set_bright_cyan(this: &ITheme, value: &str);
    #[wasm_bindgen(method, setter, js_name = brightWhite)]
    pub fn set_bright_white(this: &ITheme, value: &str);
}

impl ITheme
{
    pub fn new() -> Self { Object::new().unchecked_into() }
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ITerminalOptions;

    #[wasm_bindgen(method, setter)]
    pub fn set_cols(this: &ITerminalOptions, value: u32);
    #[wasm_bindgen(method, setter)]
    pub fn set_rows(this: &ITerminalOptions, value: u32);
    #[wasm_bindgen(method, setter, js_name = cursorBlink)]
    pub fn set_cursor_blink(this: &ITerminalOptions, value: bool);
    /// One of `"block"`, `"underline"`, or `"bar"`.
    #[wasm_bindgen(method, setter, js_name = cursorStyle)]
    pub fn set_cursor_style(this: &ITerminalOptions, value: &str);
    #[wasm_bindgen(method, setter)]
    pub fn set_theme(this: &ITerminalOptions, value: &ITheme);
    #[wasm_bindgen(method, setter)]
    pub fn set_scrollback(this: &ITerminalOptions, value: u32);
    #[wasm_bindgen(method, setter, js_name = fontSize)]
    pub fn set_font_size(this: &ITerminalOptions, value: f64);
    #[wasm_bindgen(method, setter, js_name = fontFamily)]
    pub fn set_font_family(this: &ITerminalOptions, value: &str);
    #[wasm_bindgen(method, setter, js_name = allowTransparency)]
    pub fn set_allow_transparency(this: &ITerminalOptions, value: bool);
    #[wasm_bindgen(method, setter, js_name = convertEol)]
    pub fn set_convert_eol(this: &ITerminalOptions, value: bool);
    #[wasm_bindgen(method, setter, js_name = disableStdin)]
    pub fn set_disable_stdin(this: &ITerminalOptions, value: bool);
    #[wasm_bindgen(method, setter, js_name = smoothScrollDuration)]
    pub fn set_smooth_scroll_duration(this: &ITerminalOptions, value: f64);
    #[wasm_bindgen(method, setter)]
    pub fn set_ghostty(this: &ITerminalOptions, value: &Ghostty);
}

impl ITerminalOptions
{
    pub fn new() -> Self { Object::new().unchecked_into() }
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type RendererOptions;

    #[wasm_bindgen(method, setter, js_name = fontSize)]
    pub fn set_font_size(this: &RendererOptions, value: f64);
    #[wasm_bindgen(method, setter, js_name = fontFamily)]
    pub fn set_font_family(this: &RendererOptions, value: &str);
    /// One of `"block"`, `"underline"`, or `"bar"`.
    #[wasm_bindgen(method, setter, js_name = cursorStyle)]
    pub fn set_cursor_style(this: &RendererOptions, value: &str);
    #[wasm_bindgen(method, setter, js_name = cursorBlink)]
    pub fn set_cursor_blink(this: &RendererOptions, value: bool);
    #[wasm_bindgen(method, setter)]
    pub fn set_theme(this: &RendererOptions, value: &ITheme);
    #[wasm_bindgen(method, setter, js_name = devicePixelRatio)]
    pub fn set_device_pixel_ratio(this: &RendererOptions, value: f64);
}

impl RendererOptions
{
    pub fn new() -> Self { Object::new().unchecked_into() }
}

#[wasm_bindgen]
extern "C" {
    /// Terminal configuration (passed to `ghostty_terminal_new_with_config`).
    ///
    /// All color values use `0xRRGGBB` format. A value of `0` means "use
    /// default".
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type GhosttyTerminalConfig;

    #[wasm_bindgen(method, setter, js_name = scrollbackLimit)]
    pub fn set_scrollback_limit(this: &GhosttyTerminalConfig, value: u32);
    #[wasm_bindgen(method, setter, js_name = fgColor)]
    pub fn set_fg_color(this: &GhosttyTerminalConfig, value: u32);
    #[wasm_bindgen(method, setter, js_name = bgColor)]
    pub fn set_bg_color(this: &GhosttyTerminalConfig, value: u32);
    #[wasm_bindgen(method, setter, js_name = cursorColor)]
    pub fn set_cursor_color(this: &GhosttyTerminalConfig, value: u32);
    #[wasm_bindgen(method, setter)]
    pub fn set_palette(this: &GhosttyTerminalConfig, value: &Array<Number>);
}

impl GhosttyTerminalConfig
{
    pub fn new() -> Self { Object::new().unchecked_into() }
}

#[wasm_bindgen]
extern "C" {
    /// Key event structure
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type KeyEvent;

    #[wasm_bindgen(method, setter)]
    pub fn set_action(this: &KeyEvent, value: u32);
    #[wasm_bindgen(method, setter)]
    pub fn set_key(this: &KeyEvent, value: u32);
    #[wasm_bindgen(method, setter)]
    pub fn set_mods(this: &KeyEvent, value: u32);
    #[wasm_bindgen(method, setter, js_name = consumedMods)]
    pub fn set_consumed_mods(this: &KeyEvent, value: u32);
    #[wasm_bindgen(method, setter)]
    pub fn set_composing(this: &KeyEvent, value: bool);
    #[wasm_bindgen(method, setter)]
    pub fn set_utf8(this: &KeyEvent, value: &str);
    #[wasm_bindgen(method, setter, js_name = unshiftedCodepoint)]
    pub fn set_unshifted_codepoint(this: &KeyEvent, value: u32);
}

impl KeyEvent
{
    pub fn new() -> Self { Object::new().unchecked_into() }
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IDisposable;

    #[wasm_bindgen(method)]
    pub fn dispose(this: &IDisposable);
}

#[wasm_bindgen]
extern "C" {
    /// RGB color
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type RGB;

    #[wasm_bindgen(method, getter)]
    pub fn r(this: &RGB) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn g(this: &RGB) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn b(this: &RGB) -> u8;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type FontMetrics;

    #[wasm_bindgen(method, getter)]
    pub fn width(this: &FontMetrics) -> f64;
    #[wasm_bindgen(method, getter)]
    pub fn height(this: &FontMetrics) -> f64;
    #[wasm_bindgen(method, getter)]
    pub fn baseline(this: &FontMetrics) -> f64;
}

#[wasm_bindgen]
extern "C" {
    /// Cursor position and visibility
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type Cursor;

    #[wasm_bindgen(method, getter)]
    pub fn x(this: &Cursor) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn y(this: &Cursor) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn visible(this: &Cursor) -> bool;
}

#[wasm_bindgen]
extern "C" {
    /// Cell structure matching `ghostty_cell_t` in C (16 bytes)
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type GhosttyCell;

    #[wasm_bindgen(method, getter)]
    pub fn codepoint(this: &GhosttyCell) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn fg_r(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn fg_g(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn fg_b(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn bg_r(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn bg_g(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn bg_b(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn flags(this: &GhosttyCell) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn width(this: &GhosttyCell) -> u8;
    #[wasm_bindgen(method, getter)]
    pub fn hyperlink_id(this: &GhosttyCell) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn grapheme_len(this: &GhosttyCell) -> u8;
}

#[wasm_bindgen]
extern "C" {
    /// Cursor state from RenderState (8 bytes packed)
    ///
    /// Layout: `x(u16) + y(u16) + viewport_x(i16) + viewport_y(i16) +
    /// visible(bool)
    /// + blinking(bool) + style(u8) + _pad(u8)`
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type RenderStateCursor;

    #[wasm_bindgen(method, getter)]
    pub fn x(this: &RenderStateCursor) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn y(this: &RenderStateCursor) -> u32;
    #[wasm_bindgen(method, getter, js_name = viewportX)]
    pub fn viewport_x(this: &RenderStateCursor) -> i32;
    #[wasm_bindgen(method, getter, js_name = viewportY)]
    pub fn viewport_y(this: &RenderStateCursor) -> i32;
    #[wasm_bindgen(method, getter)]
    pub fn visible(this: &RenderStateCursor) -> bool;
    #[wasm_bindgen(method, getter)]
    pub fn blinking(this: &RenderStateCursor) -> bool;
    /// One of `"block"`, `"underline"`, or `"bar"`.
    #[wasm_bindgen(method, getter)]
    pub fn style(this: &RenderStateCursor) -> JsString;
}

#[wasm_bindgen]
extern "C" {
    /// Colors from RenderState (12 bytes packed)
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type RenderStateColors;

    #[wasm_bindgen(method, getter)]
    pub fn background(this: &RenderStateColors) -> RGB;
    #[wasm_bindgen(method, getter)]
    pub fn foreground(this: &RenderStateColors) -> RGB;
    #[wasm_bindgen(method, getter)]
    pub fn cursor(this: &RenderStateColors) -> Option<RGB>;
}

#[wasm_bindgen]
extern "C" {
    /// Represents a coordinate in the terminal buffer
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IBufferCellPosition;

    #[wasm_bindgen(method, getter)]
    pub fn x(this: &IBufferCellPosition) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn y(this: &IBufferCellPosition) -> u32;
}

#[wasm_bindgen]
extern "C" {
    /// Buffer range for selection coordinates
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IBufferRange;

    #[wasm_bindgen(method, getter)]
    pub fn start(this: &IBufferRange) -> IBufferCellPosition;
    #[wasm_bindgen(method, getter)]
    pub fn end(this: &IBufferRange) -> IBufferCellPosition;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type SelectionCoordinates;

    #[wasm_bindgen(method, getter, js_name = startCol)]
    pub fn start_col(this: &SelectionCoordinates) -> u32;
    #[wasm_bindgen(method, getter, js_name = startRow)]
    pub fn start_row(this: &SelectionCoordinates) -> u32;
    #[wasm_bindgen(method, getter, js_name = endCol)]
    pub fn end_col(this: &SelectionCoordinates) -> u32;
    #[wasm_bindgen(method, getter, js_name = endRow)]
    pub fn end_row(this: &SelectionCoordinates) -> u32;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ITerminalDimensions;

    #[wasm_bindgen(method, getter)]
    pub fn cols(this: &ITerminalDimensions) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn rows(this: &ITerminalDimensions) -> u32;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ResizeEvent;

    #[wasm_bindgen(method, getter)]
    pub fn cols(this: &ResizeEvent) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn rows(this: &ResizeEvent) -> u32;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type RenderEvent;

    #[wasm_bindgen(method, getter)]
    pub fn start(this: &RenderEvent) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn end(this: &RenderEvent) -> u32;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type Dimensions;

    #[wasm_bindgen(method, getter)]
    pub fn cols(this: &Dimensions) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn rows(this: &Dimensions) -> u32;
}

#[wasm_bindgen]
extern "C" {
    /// Keyboard event with key and DOM event
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IKeyEvent;

    #[wasm_bindgen(method, getter)]
    pub fn key(this: &IKeyEvent) -> JsString;
    #[wasm_bindgen(method, getter, js_name = domEvent)]
    pub fn dom_event(this: &IKeyEvent) -> KeyboardEvent;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type HoveredLinkRange;

    #[wasm_bindgen(method, getter, js_name = startX)]
    pub fn start_x(this: &HoveredLinkRange) -> u32;
    #[wasm_bindgen(method, getter, js_name = startY)]
    pub fn start_y(this: &HoveredLinkRange) -> u32;
    #[wasm_bindgen(method, getter, js_name = endX)]
    pub fn end_x(this: &HoveredLinkRange) -> u32;
    #[wasm_bindgen(method, getter, js_name = endY)]
    pub fn end_y(this: &HoveredLinkRange) -> u32;
}

#[wasm_bindgen]
extern "C" {
    /// Represents a detected link in the terminal
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ILink;

    /// The URL or text of the link
    #[wasm_bindgen(method, getter)]
    pub fn text(this: &ILink) -> JsString;
    /// The range of the link in the buffer (may span multiple lines)
    #[wasm_bindgen(method, getter)]
    pub fn range(this: &ILink) -> IBufferRange;
    /// Called when the link is activated (clicked with modifier)
    #[wasm_bindgen(method)]
    pub fn activate(this: &ILink, event: &MouseEvent);
    /// Optional: called when mouse enters/leaves the link
    #[wasm_bindgen(method)]
    pub fn hover(this: &ILink, is_hovered: bool);
    /// Optional: called to clean up resources
    #[wasm_bindgen(method)]
    pub fn dispose(this: &ILink);
}

#[wasm_bindgen]
extern "C" {
    /// Provides link detection for a specific type of link
    ///
    /// Examples: OSC 8 hyperlinks, URL regex detection
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ILinkProvider;

    /// Provide links for a given row
    ///
    /// - `y`: Absolute row in buffer (0-based)
    /// - `callback`: Called with detected links (or undefined if none)
    #[wasm_bindgen(method, js_name = provideLinks)]
    pub fn provide_links(
        this: &ILinkProvider,
        y: u32,
        callback: &Function<fn(JsOption<Array<ILink>>) -> Undefined>,
    );
    /// Optional: called when terminal is disposed
    #[wasm_bindgen(method)]
    pub fn dispose(this: &ILinkProvider);
}

#[wasm_bindgen]
extern "C" {
    /// A single cell in the buffer
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IBufferCell;

    /// Character(s) in this cell (may be empty, single char, or emoji)
    #[wasm_bindgen(method, js_name = getChars)]
    pub fn get_chars(this: &IBufferCell) -> JsString;
    /// Unicode codepoint (0 for null cell)
    #[wasm_bindgen(method, js_name = getCode)]
    pub fn get_code(this: &IBufferCell) -> u32;
    /// Character width (1 = normal, 2 = wide/emoji, 0 = combining)
    #[wasm_bindgen(method, js_name = getWidth)]
    pub fn get_width(this: &IBufferCell) -> u8;
    /// Foreground color index (for palette colors) or -1 for RGB
    #[wasm_bindgen(method, js_name = getFgColorMode)]
    pub fn get_fg_color_mode(this: &IBufferCell) -> i32;
    /// Background color index (for palette colors) or -1 for RGB
    #[wasm_bindgen(method, js_name = getBgColorMode)]
    pub fn get_bg_color_mode(this: &IBufferCell) -> i32;
    /// Foreground RGB color (or 0 for default)
    #[wasm_bindgen(method, js_name = getFgColor)]
    pub fn get_fg_color(this: &IBufferCell) -> u32;
    /// Background RGB color (or 0 for default)
    #[wasm_bindgen(method, js_name = getBgColor)]
    pub fn get_bg_color(this: &IBufferCell) -> u32;
    /// Whether cell has bold style
    #[wasm_bindgen(method, js_name = isBold)]
    pub fn is_bold(this: &IBufferCell) -> u32;
    /// Whether cell has italic style
    #[wasm_bindgen(method, js_name = isItalic)]
    pub fn is_italic(this: &IBufferCell) -> u32;
    /// Whether cell has underline style
    #[wasm_bindgen(method, js_name = isUnderline)]
    pub fn is_underline(this: &IBufferCell) -> u32;
    /// Whether cell has strikethrough style
    #[wasm_bindgen(method, js_name = isStrikethrough)]
    pub fn is_strikethrough(this: &IBufferCell) -> u32;
    /// Whether cell has blink style
    #[wasm_bindgen(method, js_name = isBlink)]
    pub fn is_blink(this: &IBufferCell) -> u32;
    /// Whether cell has inverse video style
    #[wasm_bindgen(method, js_name = isInverse)]
    pub fn is_inverse(this: &IBufferCell) -> u32;
    /// Whether cell has invisible style
    #[wasm_bindgen(method, js_name = isInvisible)]
    pub fn is_invisible(this: &IBufferCell) -> u32;
    /// Whether cell has faint/dim style
    #[wasm_bindgen(method, js_name = isFaint)]
    pub fn is_faint(this: &IBufferCell) -> u32;
    /// Get hyperlink ID for this cell (0 = no link)
    #[wasm_bindgen(method, js_name = getHyperlinkId)]
    pub fn get_hyperlink_id(this: &IBufferCell) -> u32;
    /// Get the Unicode codepoint for this cell
    #[wasm_bindgen(method, js_name = getCodepoint)]
    pub fn get_codepoint(this: &IBufferCell) -> u32;
    /// Whether cell has dim/faint attribute (boolean version)
    #[wasm_bindgen(method, js_name = isDim)]
    pub fn is_dim(this: &IBufferCell) -> bool;
}

#[wasm_bindgen]
extern "C" {
    /// A single line in the buffer
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IBufferLine;

    /// Length of the line (in columns)
    #[wasm_bindgen(method, getter)]
    pub fn length(this: &IBufferLine) -> u32;
    /// Whether this line wraps to the next line
    #[wasm_bindgen(method, getter, js_name = isWrapped)]
    pub fn is_wrapped(this: &IBufferLine) -> bool;
    /// Get a cell from this line
    ///
    /// - `x`: Column index (0-indexed)
    ///
    /// Returns cell object or undefined if out of bounds
    #[wasm_bindgen(method, js_name = getCell)]
    pub fn get_cell(this: &IBufferLine, x: u32) -> Option<IBufferCell>;
    /// Translate the line to a string
    ///
    /// - `trim_right`: Whether to trim trailing whitespace (default: false)
    /// - `start_column`: Start column (default: 0)
    /// - `end_column`: End column (default: length)
    #[wasm_bindgen(method, js_name = translateToString)]
    pub fn translate_to_string(
        this: &IBufferLine,
        trim_right: Option<bool>,
        start_column: Option<u32>,
        end_column: Option<u32>,
    ) -> JsString;
}

#[wasm_bindgen]
extern "C" {
    /// A terminal buffer (normal or alternate screen)
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IBuffer;

    /// Buffer type: `'normal'` or `'alternate'`
    #[wasm_bindgen(method, getter, js_name = type)]
    pub fn type_(this: &IBuffer) -> JsString;
    /// Cursor X position (0-indexed)
    #[wasm_bindgen(method, getter, js_name = cursorX)]
    pub fn cursor_x(this: &IBuffer) -> u32;
    /// Cursor Y position (0-indexed, relative to viewport)
    #[wasm_bindgen(method, getter, js_name = cursorY)]
    pub fn cursor_y(this: &IBuffer) -> u32;
    /// Viewport Y position (scroll offset, 0 = bottom of scrollback)
    #[wasm_bindgen(method, getter, js_name = viewportY)]
    pub fn viewport_y(this: &IBuffer) -> u32;
    /// Base Y position (always 0 for normal buffer, may vary for alternate)
    #[wasm_bindgen(method, getter, js_name = baseY)]
    pub fn base_y(this: &IBuffer) -> u32;
    /// Total buffer length (rows + scrollback for normal, just rows for
    /// alternate)
    #[wasm_bindgen(method, getter)]
    pub fn length(this: &IBuffer) -> u32;
    /// Get a line from the buffer
    ///
    /// - `y`: Line index (0 = top of scrollback for normal buffer)
    ///
    /// Returns line object or undefined if out of bounds
    #[wasm_bindgen(method, js_name = getLine)]
    pub fn get_line(this: &IBuffer, y: u32) -> Option<IBufferLine>;
    /// Get the null cell (used for empty/uninitialized cells)
    #[wasm_bindgen(method, js_name = getNullCell)]
    pub fn get_null_cell(this: &IBuffer) -> IBufferCell;
}

#[wasm_bindgen]
extern "C" {
    /// Top-level buffer API namespace
    ///
    /// Provides access to active, normal, and alternate screen buffers
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IBufferNamespace;

    /// The currently active buffer (normal or alternate)
    #[wasm_bindgen(method, getter)]
    pub fn active(this: &IBufferNamespace) -> IBuffer;
    /// The normal buffer (primary screen)
    #[wasm_bindgen(method, getter)]
    pub fn normal(this: &IBufferNamespace) -> IBuffer;
    /// The alternate buffer (used by full-screen apps like vim)
    #[wasm_bindgen(method, getter)]
    pub fn alternate(this: &IBufferNamespace) -> IBuffer;
    /// Event fired when buffer changes (normal ↔ alternate)
    #[wasm_bindgen(method, getter, js_name = onBufferChange)]
    pub fn on_buffer_change(this: &IBufferNamespace) -> IEvent<IBuffer>;
}

#[wasm_bindgen]
extern "C" {
    /// Unicode version provider (xterm.js compatibility)
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IUnicodeVersionProvider;

    #[wasm_bindgen(method, getter, js_name = activeVersion)]
    pub fn active_version(this: &IUnicodeVersionProvider) -> JsString;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IRenderable;

    #[wasm_bindgen(method, js_name = getLine)]
    pub fn get_line(this: &IRenderable, y: u32) -> Option<Array<GhosttyCell>>;
    #[wasm_bindgen(method, js_name = getCursor)]
    pub fn get_cursor(this: &IRenderable) -> Cursor;
    #[wasm_bindgen(method, js_name = getDimensions)]
    pub fn get_dimensions(this: &IRenderable) -> Dimensions;
    #[wasm_bindgen(method, js_name = isRowDirty)]
    pub fn is_row_dirty(this: &IRenderable, y: u32) -> bool;
    /// Returns true if a full redraw is needed (e.g., screen change)
    #[wasm_bindgen(method, js_name = needsFullRedraw)]
    pub fn needs_full_redraw(this: &IRenderable) -> bool;
    #[wasm_bindgen(method, js_name = clearDirty)]
    pub fn clear_dirty(this: &IRenderable);
    /// Get the full grapheme string for a cell at (row, col).
    ///
    /// For cells with `grapheme_len > 0`, this returns all codepoints combined.
    /// For simple cells, returns the single character.
    #[wasm_bindgen(method, js_name = getGraphemeString)]
    pub fn get_grapheme_string(this: &IRenderable, row: u32, col: u32) -> JsString;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type IScrollbackProvider;

    #[wasm_bindgen(method, js_name = getScrollbackLine)]
    pub fn get_scrollback_line(
        this: &IScrollbackProvider,
        offset: u32,
    ) -> Option<Array<GhosttyCell>>;
    #[wasm_bindgen(method, js_name = getScrollbackLength)]
    pub fn get_scrollback_length(this: &IScrollbackProvider) -> u32;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ITerminalAddon;

    #[wasm_bindgen(method)]
    pub fn activate(this: &ITerminalAddon, terminal: &ITerminalCore);
    #[wasm_bindgen(method)]
    pub fn dispose(this: &ITerminalAddon);
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object)]
    #[derive(Clone, Debug)]
    pub type ITerminalCore;

    #[wasm_bindgen(method, getter)]
    pub fn cols(this: &ITerminalCore) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn rows(this: &ITerminalCore) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn element(this: &ITerminalCore) -> Option<HtmlElement>;
    #[wasm_bindgen(method, getter)]
    pub fn textarea(this: &ITerminalCore) -> Option<HtmlTextAreaElement>;
}

#[wasm_bindgen(js_namespace = GhosttyWeb)]
extern "C" {
    /// Initialize the ghostty-web library by loading the WASM module.
    ///
    /// Must be called before creating any [`Terminal`] instances.
    ///
    /// This creates a shared WASM instance that all [`Terminal`] instances will
    /// use. For test isolation, pass a [`Ghostty`] instance directly to the
    /// [`Terminal`] constructor.
    #[wasm_bindgen]
    pub async fn init();

    #[wasm_bindgen(js_name = EventEmitter)]
    pub type EventEmitter<T>;

    #[wasm_bindgen(constructor, js_class = "EventEmitter")]
    pub fn new<T: JsGeneric>() -> EventEmitter<T>;

    #[wasm_bindgen(method)]
    pub fn fire<T: JsGeneric>(this: &EventEmitter<T>, arg: T);

    /// `event` is a plain property in TS (`event: IEvent<T>`), not a getter.
    #[wasm_bindgen(method, js_name = event)]
    pub fn event<T: JsGeneric>(this: &EventEmitter<T>) -> IEvent<T>;

    #[wasm_bindgen(method)]
    pub fn dispose<T>(this: &EventEmitter<T>);

    /// Main Ghostty WASM wrapper class
    #[wasm_bindgen(js_name = Ghostty)]
    pub type Ghostty;

    #[wasm_bindgen(constructor, js_class = "Ghostty")]
    pub fn new(wasm_instance: &WebAssembly::Instance) -> Ghostty;

    #[wasm_bindgen(method, js_name = createKeyEncoder)]
    pub fn create_key_encoder(this: &Ghostty) -> KeyEncoder;

    #[wasm_bindgen(method, js_name = createTerminal)]
    pub fn create_terminal(
        this: &Ghostty,
        cols: Option<u32>,
        rows: Option<u32>,
        config: Option<&GhosttyTerminalConfig>,
    ) -> GhosttyTerminal;

    #[wasm_bindgen(static_method_of = Ghostty, js_class = "Ghostty")]
    pub fn load(wasm_path: Option<&str>) -> Promise<Ghostty>;

    /// GhosttyTerminal - High-performance terminal emulator
    ///
    /// Uses Ghostty's native RenderState for optimal performance:
    /// - ONE call to update all state (`renderStateUpdate`)
    /// - ONE call to get all cells (`getViewport`)
    /// - No per-row WASM boundary crossings!
    #[wasm_bindgen(js_name = GhosttyTerminal)]
    pub type GhosttyTerminal;

    #[wasm_bindgen(method, getter)]
    pub fn cols(this: &GhosttyTerminal) -> u32;
    #[wasm_bindgen(method, getter)]
    pub fn rows(this: &GhosttyTerminal) -> u32;

    #[wasm_bindgen(method, js_name = write)]
    pub fn write_str(this: &GhosttyTerminal, data: &str);
    #[wasm_bindgen(method, js_name = write)]
    pub fn write_u8_array(this: &GhosttyTerminal, data: &Uint8Array);

    #[wasm_bindgen(method)]
    pub fn resize(this: &GhosttyTerminal, cols: u32, rows: u32);
    #[wasm_bindgen(method)]
    pub fn free(this: &GhosttyTerminal);

    /// Update render state from terminal.
    ///
    /// This syncs the RenderState with the current Terminal state. The dirty
    /// state (full/partial/none) is stored in the WASM RenderState and can be
    /// queried via [`GhosttyTerminal::is_row_dirty`]. When dirty==full,
    /// `is_row_dirty()` returns true for ALL rows.
    ///
    /// The WASM layer automatically detects screen switches (normal ↔
    /// alternate) and returns FULL dirty state when switching screens
    /// (e.g., vim exit).
    ///
    /// Safe to call multiple times - dirty state persists until
    /// [`GhosttyTerminal::mark_clean`].
    #[wasm_bindgen(method, js_name = update)]
    pub fn update_raw(this: &GhosttyTerminal) -> u32;

    /// Get cursor state from render state.
    ///
    /// Ensures render state is fresh by calling [`GhosttyTerminal::update`].
    #[wasm_bindgen(method, js_name = getCursor)]
    pub fn get_cursor(this: &GhosttyTerminal) -> RenderStateCursor;
    /// Get default colors from render state
    #[wasm_bindgen(method, js_name = getColors)]
    pub fn get_colors(this: &GhosttyTerminal) -> RenderStateColors;
    /// Check if a specific row is dirty
    #[wasm_bindgen(method, js_name = isRowDirty)]
    pub fn is_row_dirty(this: &GhosttyTerminal, y: u32) -> bool;
    /// Mark render state as clean (call after rendering)
    #[wasm_bindgen(method, js_name = markClean)]
    pub fn mark_clean(this: &GhosttyTerminal);
    /// Get ALL viewport cells in ONE WASM call - the key performance
    /// optimization!
    ///
    /// Returns a reusable cell array (zero allocation after warmup).
    #[wasm_bindgen(method, js_name = getViewport)]
    pub fn get_viewport(this: &GhosttyTerminal) -> Array<GhosttyCell>;
    /// Get line - for compatibility, extracts from viewport.
    ///
    /// Ensures render state is fresh by calling [`GhosttyTerminal::update`].
    /// Returns a COPY of the cells to avoid pool reference issues.
    #[wasm_bindgen(method, js_name = getLine)]
    pub fn get_line(this: &GhosttyTerminal, y: u32) -> Option<Array<GhosttyCell>>;
    /// For compatibility with old API
    #[wasm_bindgen(method, js_name = isDirty)]
    pub fn is_dirty(this: &GhosttyTerminal) -> bool;
    /// Check if a full redraw is needed (screen change, resize, etc.)
    ///
    /// Note: This calls [`GhosttyTerminal::update`] to ensure fresh state. Safe
    /// to call multiple times.
    #[wasm_bindgen(method, js_name = needsFullRedraw)]
    pub fn needs_full_redraw(this: &GhosttyTerminal) -> bool;
    /// Mark render state as clean after rendering
    #[wasm_bindgen(method, js_name = clearDirty)]
    pub fn clear_dirty(this: &GhosttyTerminal);
    #[wasm_bindgen(method, js_name = isAlternateScreen)]
    pub fn is_alternate_screen(this: &GhosttyTerminal) -> bool;
    #[wasm_bindgen(method, js_name = hasBracketedPaste)]
    pub fn has_bracketed_paste(this: &GhosttyTerminal) -> bool;
    #[wasm_bindgen(method, js_name = hasFocusEvents)]
    pub fn has_focus_events(this: &GhosttyTerminal) -> bool;
    #[wasm_bindgen(method, js_name = hasMouseTracking)]
    pub fn has_mouse_tracking(this: &GhosttyTerminal) -> bool;
    /// Get dimensions - for compatibility
    #[wasm_bindgen(method, js_name = getDimensions)]
    pub fn get_dimensions(this: &GhosttyTerminal) -> Dimensions;
    /// Get number of scrollback lines (history, not including active screen)
    #[wasm_bindgen(method, js_name = getScrollbackLength)]
    pub fn get_scrollback_length(this: &GhosttyTerminal) -> u32;
    /// Get a line from the scrollback buffer.
    ///
    /// Ensures render state is fresh by calling [`GhosttyTerminal::update`].
    ///
    /// - `offset`: 0 = oldest line, (length-1) = most recent scrollback line
    #[wasm_bindgen(method, js_name = getScrollbackLine)]
    pub fn get_scrollback_line(this: &GhosttyTerminal, offset: u32) -> Option<Array<GhosttyCell>>;
    /// Check if a row in the active screen is wrapped (soft-wrapped to next
    /// line)
    #[wasm_bindgen(method, js_name = isRowWrapped)]
    pub fn is_row_wrapped(this: &GhosttyTerminal, row: u32) -> bool;
    /// Hyperlink URI not yet exposed in simplified API
    #[wasm_bindgen(method, js_name = getHyperlinkUri)]
    pub fn get_hyperlink_uri(this: &GhosttyTerminal, id: u32) -> Option<JsString>;
    /// Check if there are pending responses from the terminal.
    ///
    /// Responses are generated by escape sequences like DSR (Device Status
    /// Report).
    #[wasm_bindgen(method, js_name = hasResponse)]
    pub fn has_response(this: &GhosttyTerminal) -> bool;
    /// Read pending responses from the terminal.
    ///
    /// Returns the response string, or null if no responses pending.
    ///
    /// Responses are generated by escape sequences that require replies:
    /// - DSR 6 (cursor position): Returns `\x1b[row;colR`
    /// - DSR 5 (operating status): Returns `\x1b[0n`
    #[wasm_bindgen(method, js_name = readResponse)]
    pub fn read_response(this: &GhosttyTerminal) -> Option<JsString>;
    /// Query arbitrary terminal mode by number
    ///
    /// - `mode`: Mode number (e.g., 25 for cursor visibility, 2004 for
    ///   bracketed paste)
    /// - `is_ansi`: True for ANSI modes, false for DEC modes (default: false)
    #[wasm_bindgen(method, js_name = getMode)]
    pub fn get_mode(this: &GhosttyTerminal, mode: u32, is_ansi: Option<bool>) -> bool;
    /// Get all codepoints for a grapheme cluster at the given position.
    ///
    /// For most cells this returns a single codepoint, but for complex scripts
    /// (Hindi, emoji with ZWJ, etc.) it returns multiple codepoints.
    ///
    /// Returns array of codepoints, or null on error.
    #[wasm_bindgen(method, js_name = getGrapheme)]
    pub fn get_grapheme(this: &GhosttyTerminal, row: u32, col: u32) -> Option<Array<Number>>;
    /// Get a string representation of the grapheme at the given position.
    ///
    /// This properly handles complex scripts like Hindi, emoji with ZWJ, etc.
    #[wasm_bindgen(method, js_name = getGraphemeString)]
    pub fn get_grapheme_string(this: &GhosttyTerminal, row: u32, col: u32) -> JsString;
    /// Get all codepoints for a grapheme cluster in the scrollback buffer.
    ///
    /// - `offset`: Scrollback line offset (0 = oldest)
    /// - `col`: Column index
    ///
    /// Returns array of codepoints, or null on error.
    #[wasm_bindgen(method, js_name = getScrollbackGrapheme)]
    pub fn get_scrollback_grapheme(
        this: &GhosttyTerminal,
        offset: u32,
        col: u32,
    ) -> Option<Array<Number>>;
    /// Get a string representation of a grapheme in the scrollback buffer.
    #[wasm_bindgen(method, js_name = getScrollbackGraphemeString)]
    pub fn get_scrollback_grapheme_string(
        this: &GhosttyTerminal,
        offset: u32,
        col: u32,
    ) -> JsString;
}

impl GhosttyTerminal
{
    /// Update render state from terminal.
    ///
    /// Typed wrapper around [`GhosttyTerminal::update_raw`]. See that method
    /// for full documentation.
    pub fn update(&self) -> DirtyState { DirtyState::from_u32(self.update_raw()) }
}

#[wasm_bindgen(js_namespace = GhosttyWeb)]
extern "C" {
    /// Key Encoder - converts keyboard events into terminal escape sequences
    #[wasm_bindgen(js_name = KeyEncoder)]
    pub type KeyEncoder;

    #[wasm_bindgen(method, js_name = setOption)]
    pub fn set_option(this: &KeyEncoder, option: u32, value: &JsValue);
    #[wasm_bindgen(method, js_name = setKittyFlags)]
    pub fn set_kitty_flags(this: &KeyEncoder, flags: u32);
    #[wasm_bindgen(method)]
    pub fn encode(this: &KeyEncoder, event: &KeyEvent) -> Uint8Array;
    #[wasm_bindgen(method)]
    pub fn dispose(this: &KeyEncoder);

    #[wasm_bindgen(js_name = CanvasRenderer)]
    pub type CanvasRenderer;

    #[wasm_bindgen(constructor, js_class = "CanvasRenderer")]
    pub fn new(canvas: &HtmlCanvasElement, options: Option<&RendererOptions>) -> CanvasRenderer;

    /// Remeasure font metrics (call after font loads or changes)
    #[wasm_bindgen(method, js_name = remeasureFont)]
    pub fn remeasure_font(this: &CanvasRenderer);
    /// Resize canvas to fit terminal dimensions
    #[wasm_bindgen(method)]
    pub fn resize(this: &CanvasRenderer, cols: u32, rows: u32);
    /// Render the terminal buffer to canvas
    #[wasm_bindgen(method)]
    pub fn render(
        this: &CanvasRenderer,
        buffer: &IRenderable,
        force_all: Option<bool>,
        viewport_y: Option<f64>,
        scrollback_provider: Option<&IScrollbackProvider>,
        scrollbar_opacity: Option<f64>,
    );
    /// Update theme colors
    #[wasm_bindgen(method, js_name = setTheme)]
    pub fn set_theme(this: &CanvasRenderer, theme: &ITheme);
    /// Update font size
    #[wasm_bindgen(method, js_name = setFontSize)]
    pub fn set_font_size(this: &CanvasRenderer, size: f64);
    /// Update font family
    #[wasm_bindgen(method, js_name = setFontFamily)]
    pub fn set_font_family(this: &CanvasRenderer, family: &str);
    /// Update cursor style
    ///
    /// One of `"block"`, `"underline"`, or `"bar"`.
    #[wasm_bindgen(method, js_name = setCursorStyle)]
    pub fn set_cursor_style(this: &CanvasRenderer, style: &str);
    /// Enable/disable cursor blinking
    #[wasm_bindgen(method, js_name = setCursorBlink)]
    pub fn set_cursor_blink(this: &CanvasRenderer, enabled: bool);
    /// Get current font metrics
    #[wasm_bindgen(method, js_name = getMetrics)]
    pub fn get_metrics(this: &CanvasRenderer) -> FontMetrics;
    /// Get canvas element (needed by SelectionManager)
    #[wasm_bindgen(method, js_name = getCanvas)]
    pub fn get_canvas(this: &CanvasRenderer) -> HtmlCanvasElement;
    /// Set selection manager (for rendering selection)
    #[wasm_bindgen(method, js_name = setSelectionManager)]
    pub fn set_selection_manager(this: &CanvasRenderer, manager: &SelectionManager);
    /// Set the currently hovered hyperlink ID for rendering underlines
    #[wasm_bindgen(method, js_name = setHoveredHyperlinkId)]
    pub fn set_hovered_hyperlink_id(this: &CanvasRenderer, hyperlink_id: u32);
    /// Set the currently hovered link range for rendering underlines (for
    /// regex-detected URLs)
    ///
    /// Pass null to clear the hover state
    #[wasm_bindgen(method, js_name = setHoveredLinkRange)]
    pub fn set_hovered_link_range(this: &CanvasRenderer, range: Option<&HoveredLinkRange>);
    /// Get character cell width (for coordinate conversion)
    #[wasm_bindgen(method, getter, js_name = charWidth)]
    pub fn char_width(this: &CanvasRenderer) -> f64;
    /// Get character cell height (for coordinate conversion)
    #[wasm_bindgen(method, getter, js_name = charHeight)]
    pub fn char_height(this: &CanvasRenderer) -> f64;
    /// Clear entire canvas
    #[wasm_bindgen(method)]
    pub fn clear(this: &CanvasRenderer);
    /// Cleanup resources
    #[wasm_bindgen(method)]
    pub fn dispose(this: &CanvasRenderer);

    #[wasm_bindgen(js_name = FitAddon, extends = ITerminalAddon)]
    pub type FitAddon;

    #[wasm_bindgen(constructor, js_class = "FitAddon")]
    pub fn new() -> FitAddon;

    /// Activate the addon (called by [`Terminal::load_addon`])
    #[wasm_bindgen(method)]
    pub fn activate(this: &FitAddon, terminal: &ITerminalCore);
    /// Dispose the addon and clean up resources
    #[wasm_bindgen(method)]
    pub fn dispose(this: &FitAddon);
    /// Fit the terminal to its container
    ///
    /// Calculates optimal dimensions and resizes the terminal. Does nothing if
    /// dimensions cannot be calculated or haven't changed.
    #[wasm_bindgen(method)]
    pub fn fit(this: &FitAddon);
    /// Propose dimensions to fit the terminal to its container
    ///
    /// Calculates cols and rows based on:
    /// - Terminal container element dimensions (`clientWidth`/`Height`)
    /// - Terminal element padding
    /// - Font metrics (character cell size)
    /// - Scrollbar width reservation
    ///
    /// Returns proposed dimensions or undefined if cannot calculate.
    #[wasm_bindgen(method, js_name = proposeDimensions)]
    pub fn propose_dimensions(this: &FitAddon) -> Option<ITerminalDimensions>;
    /// Observe the terminal's container for resize events
    ///
    /// Sets up a `ResizeObserver` to automatically call [`FitAddon::fit`] when
    /// the container size changes. Resize events are debounced to avoid
    /// excessive calls during window drag operations.
    ///
    /// Call [`FitAddon::dispose`] to stop observing.
    #[wasm_bindgen(method, js_name = observeResize)]
    pub fn observe_resize(this: &FitAddon);

    /// InputHandler class
    ///
    /// Attaches keyboard event listeners to a container and converts keyboard
    /// events to terminal input data
    #[wasm_bindgen(js_name = InputHandler)]
    pub type InputHandler;

    /// Create a new InputHandler
    ///
    /// - `ghostty` - Ghostty instance (for creating KeyEncoder)
    /// - `container` - DOM element to attach listeners to
    /// - `on_data` - Callback for terminal data (escape sequences to send to
    ///   PTY)
    /// - `on_bell` - Callback for bell/beep event
    /// - `on_key` - Optional callback for raw key events
    /// - `custom_key_event_handler` - Optional custom key event handler
    /// - `get_mode` - Optional callback to query terminal mode state (for
    ///   application cursor mode)
    #[wasm_bindgen(constructor, js_class = "InputHandler")]
    pub fn new(
        ghostty: &Ghostty,
        container: &HtmlElement,
        on_data: &Function<fn(JsString) -> Undefined>,
        on_bell: &Function<fn() -> Undefined>,
        on_key: Option<&Function<fn(IKeyEvent) -> Undefined>>,
        custom_key_event_handler: Option<&Function<fn(KeyboardEvent) -> Boolean>>,
        get_mode: Option<&Function<fn(Number) -> Boolean>>,
    ) -> InputHandler;

    /// Set custom key event handler (for runtime updates)
    #[wasm_bindgen(method, js_name = setCustomKeyEventHandler)]
    pub fn set_custom_key_event_handler(
        this: &InputHandler,
        handler: &Function<fn(KeyboardEvent) -> Boolean>,
    );
    /// Dispose the InputHandler and remove event listeners
    #[wasm_bindgen(method)]
    pub fn dispose(this: &InputHandler);
    /// Check if handler is disposed
    #[wasm_bindgen(method, js_name = isActive)]
    pub fn is_active(this: &InputHandler) -> bool;

    /// Manages link detection across multiple providers with intelligent
    /// caching
    #[wasm_bindgen(js_name = LinkDetector)]
    pub type LinkDetector;

    #[wasm_bindgen(constructor, js_class = "LinkDetector")]
    pub fn new(terminal: &JsValue) -> LinkDetector;

    /// Register a link provider
    #[wasm_bindgen(method, js_name = registerProvider)]
    pub fn register_provider(this: &LinkDetector, provider: &ILinkProvider);
    /// Get link at the specified buffer position
    ///
    /// - `col`: Column (0-based)
    /// - `row`: Absolute row in buffer (0-based)
    ///
    /// Returns link at position, or undefined if none.
    #[wasm_bindgen(method, js_name = getLinkAt)]
    pub fn get_link_at(this: &LinkDetector, col: u32, row: u32) -> Promise<JsOption<ILink>>;
    /// Invalidate cache when terminal content changes
    ///
    /// Should be called on terminal write, resize, or clear
    #[wasm_bindgen(method, js_name = invalidateCache)]
    pub fn invalidate_cache(this: &LinkDetector);
    /// Invalidate cache for specific rows
    ///
    /// Used when only part of the terminal changed
    #[wasm_bindgen(method, js_name = invalidateRows)]
    pub fn invalidate_rows(this: &LinkDetector, start_row: u32, end_row: u32);
    /// Dispose and cleanup
    #[wasm_bindgen(method)]
    pub fn dispose(this: &LinkDetector);

    /// OSC 8 Hyperlink Provider
    ///
    /// Detects OSC 8 hyperlinks by scanning for `hyperlink_id` in cells.
    /// Automatically handles multi-line links since Ghostty WASM preserves
    /// `hyperlink_id` across wrapped lines.
    #[wasm_bindgen(js_name = OSC8LinkProvider)]
    pub type Osc8LinkProvider;

    #[wasm_bindgen(constructor, js_class = "OSC8LinkProvider")]
    pub fn new(terminal: &JsValue) -> Osc8LinkProvider;

    /// Provide all OSC 8 links on the given row
    ///
    /// Note: This may return links that span multiple rows
    #[wasm_bindgen(method, js_name = provideLinks)]
    pub fn provide_links(
        this: &Osc8LinkProvider,
        y: u32,
        callback: &Function<fn(JsOption<Array<ILink>>) -> Undefined>,
    );
    #[wasm_bindgen(method)]
    pub fn dispose(this: &Osc8LinkProvider);

    /// URL Regex Provider
    ///
    /// Detects plain text URLs on a single line using regex. Does not support
    /// multi-line URLs or file paths.
    ///
    /// Supported protocols:
    /// - `https://`, `http://`
    /// - `mailto:`
    /// - `ftp://`, `ssh://`, `git://`
    /// - `tel:`, `magnet:`
    /// - `gemini://`, `gopher://`, `news:`
    #[wasm_bindgen(js_name = UrlRegexProvider)]
    pub type UrlRegexProvider;

    #[wasm_bindgen(constructor, js_class = "UrlRegexProvider")]
    pub fn new(terminal: &JsValue) -> UrlRegexProvider;

    /// Provide all regex-detected URLs on the given row
    #[wasm_bindgen(method, js_name = provideLinks)]
    pub fn provide_links(
        this: &UrlRegexProvider,
        y: u32,
        callback: &Function<fn(JsOption<Array<ILink>>) -> Undefined>,
    );
    #[wasm_bindgen(method)]
    pub fn dispose(this: &UrlRegexProvider);

    #[wasm_bindgen(js_name = SelectionManager)]
    pub type SelectionManager;

    #[wasm_bindgen(constructor, js_class = "SelectionManager")]
    pub fn new(
        terminal: &Terminal,
        renderer: &CanvasRenderer,
        wasm_term: &GhosttyTerminal,
        textarea: &HtmlTextAreaElement,
    ) -> SelectionManager;

    /// Get the selected text as a string
    #[wasm_bindgen(method, js_name = getSelection)]
    pub fn get_selection(this: &SelectionManager) -> JsString;
    /// Check if there's an active selection
    #[wasm_bindgen(method, js_name = hasSelection)]
    pub fn has_selection(this: &SelectionManager) -> bool;
    /// Clear the selection
    #[wasm_bindgen(method, js_name = clearSelection)]
    pub fn clear_selection(this: &SelectionManager);
    /// Select all text in the terminal
    #[wasm_bindgen(method, js_name = selectAll)]
    pub fn select_all(this: &SelectionManager);
    /// Select text at specific column and row with length
    ///
    /// xterm.js compatible API
    #[wasm_bindgen(method)]
    pub fn select(this: &SelectionManager, column: u32, row: u32, length: u32);
    /// Select entire lines from start to end
    ///
    /// xterm.js compatible API
    #[wasm_bindgen(method, js_name = selectLines)]
    pub fn select_lines(this: &SelectionManager, start: u32, end: u32);
    /// Get selection position as buffer range
    ///
    /// xterm.js compatible API
    #[wasm_bindgen(method, js_name = getSelectionPosition)]
    pub fn get_selection_position(this: &SelectionManager) -> Option<IBufferRange>;
    /// Deselect all text
    ///
    /// xterm.js compatible API
    #[wasm_bindgen(method)]
    pub fn deselect(this: &SelectionManager);
    /// Focus the terminal (make it receive keyboard input)
    #[wasm_bindgen(method)]
    pub fn focus(this: &SelectionManager);
    /// Get current selection coordinates (for rendering)
    #[wasm_bindgen(method, js_name = getSelectionCoords)]
    pub fn get_selection_coords(this: &SelectionManager) -> Option<SelectionCoordinates>;
    /// Get dirty selection rows that need redraw (for clearing old highlight)
    #[wasm_bindgen(method, js_name = getDirtySelectionRows)]
    pub fn get_dirty_selection_rows(this: &SelectionManager) -> Set<Number>;
    /// Clear the dirty selection rows tracking (after redraw)
    #[wasm_bindgen(method, js_name = clearDirtySelectionRows)]
    pub fn clear_dirty_selection_rows(this: &SelectionManager);
    /// Get selection change event accessor
    #[wasm_bindgen(method, getter, js_name = onSelectionChange)]
    pub fn on_selection_change(this: &SelectionManager) -> IEventVoid;
    /// Cleanup resources
    #[wasm_bindgen(method)]
    pub fn dispose(this: &SelectionManager);

    #[wasm_bindgen(js_name = Terminal)]
    pub type Terminal;

    #[wasm_bindgen(constructor, js_class = "Terminal")]
    pub fn new(options: Option<&ITerminalOptions>) -> Terminal;

    #[wasm_bindgen(method, getter)]
    pub fn cols(this: &Terminal) -> u32;
    #[wasm_bindgen(method, setter)]
    pub fn set_cols(this: &Terminal, value: u32);
    #[wasm_bindgen(method, getter)]
    pub fn rows(this: &Terminal) -> u32;
    #[wasm_bindgen(method, setter)]
    pub fn set_rows(this: &Terminal, value: u32);
    #[wasm_bindgen(method, getter)]
    pub fn element(this: &Terminal) -> Option<HtmlElement>;
    #[wasm_bindgen(method, getter)]
    pub fn textarea(this: &Terminal) -> Option<HtmlTextAreaElement>;
    #[wasm_bindgen(method, getter)]
    pub fn buffer(this: &Terminal) -> IBufferNamespace;
    #[wasm_bindgen(method, getter)]
    pub fn unicode(this: &Terminal) -> IUnicodeVersionProvider;
    #[wasm_bindgen(method, getter)]
    pub fn options(this: &Terminal) -> ITerminalOptions;
    #[wasm_bindgen(method, getter, js_name = wasmTerm)]
    pub fn wasm_term(this: &Terminal) -> Option<GhosttyTerminal>;
    #[wasm_bindgen(method, getter)]
    pub fn renderer(this: &Terminal) -> Option<CanvasRenderer>;
    #[wasm_bindgen(method, getter, js_name = viewportY)]
    pub fn viewport_y(this: &Terminal) -> f64;
    #[wasm_bindgen(method, setter, js_name = viewportY)]
    pub fn set_viewport_y(this: &Terminal, value: f64);

    #[wasm_bindgen(method, js_name = onData)]
    pub fn on_data(this: &Terminal, listener: &Function<fn(JsString) -> Undefined>) -> IDisposable;
    #[wasm_bindgen(method, js_name = onResize)]
    pub fn on_resize(
        this: &Terminal,
        listener: &Function<fn(ResizeEvent) -> Undefined>,
    ) -> IDisposable;
    #[wasm_bindgen(method, js_name = onBell)]
    pub fn on_bell(this: &Terminal, listener: &Function<fn() -> Undefined>) -> IDisposable;
    #[wasm_bindgen(method, js_name = onSelectionChange)]
    pub fn on_selection_change(
        this: &Terminal,
        listener: &Function<fn() -> Undefined>,
    ) -> IDisposable;
    #[wasm_bindgen(method, js_name = onKey)]
    pub fn on_key(this: &Terminal, listener: &Function<fn(IKeyEvent) -> Undefined>) -> IDisposable;
    #[wasm_bindgen(method, js_name = onTitleChange)]
    pub fn on_title_change(
        this: &Terminal,
        listener: &Function<fn(JsString) -> Undefined>,
    ) -> IDisposable;
    #[wasm_bindgen(method, js_name = onScroll)]
    pub fn on_scroll(this: &Terminal, listener: &Function<fn(Number) -> Undefined>) -> IDisposable;
    #[wasm_bindgen(method, js_name = onRender)]
    pub fn on_render(
        this: &Terminal,
        listener: &Function<fn(RenderEvent) -> Undefined>,
    ) -> IDisposable;
    #[wasm_bindgen(method, js_name = onCursorMove)]
    pub fn on_cursor_move(this: &Terminal, listener: &Function<fn() -> Undefined>) -> IDisposable;

    /// Open terminal in a parent element
    ///
    /// Initializes all components and starts rendering. Requires a pre-loaded
    /// [`Ghostty`] instance passed to the constructor.
    #[wasm_bindgen(method)]
    pub fn open(this: &Terminal, parent: &HtmlElement);

    /// Write data to terminal
    #[wasm_bindgen(method, js_name = write)]
    pub fn write_str(this: &Terminal, data: &str, callback: Option<&Function<fn() -> Undefined>>);
    /// Write data to terminal
    #[wasm_bindgen(method, js_name = write)]
    pub fn write_u8_array(
        this: &Terminal,
        data: &Uint8Array,
        callback: Option<&Function<fn() -> Undefined>>,
    );

    /// Write data with newline
    #[wasm_bindgen(method, js_name = writeln)]
    pub fn writeln_str(this: &Terminal, data: &str, callback: Option<&Function<fn() -> Undefined>>);
    /// Write data with newline
    #[wasm_bindgen(method, js_name = writeln)]
    pub fn writeln_u8_array(
        this: &Terminal,
        data: &Uint8Array,
        callback: Option<&Function<fn() -> Undefined>>,
    );

    /// Paste text into terminal (triggers bracketed paste if supported)
    #[wasm_bindgen(method)]
    pub fn paste(this: &Terminal, data: &str);
    /// Input data into terminal (as if typed by user)
    ///
    /// - `was_user_input`: If true, triggers `onData` event (default: false for
    ///   compat with some apps)
    #[wasm_bindgen(method)]
    pub fn input(this: &Terminal, data: &str, was_user_input: Option<bool>);
    /// Resize terminal
    #[wasm_bindgen(method)]
    pub fn resize(this: &Terminal, cols: u32, rows: u32);
    /// Clear terminal screen
    #[wasm_bindgen(method)]
    pub fn clear(this: &Terminal);
    /// Reset terminal state
    #[wasm_bindgen(method)]
    pub fn reset(this: &Terminal);
    /// Focus terminal input
    #[wasm_bindgen(method)]
    pub fn focus(this: &Terminal);
    /// Blur terminal (remove focus)
    #[wasm_bindgen(method)]
    pub fn blur(this: &Terminal);
    /// Load an addon
    #[wasm_bindgen(method, js_name = loadAddon)]
    pub fn load_addon(this: &Terminal, addon: &ITerminalAddon);

    /// Get the selected text as a string
    #[wasm_bindgen(method, js_name = getSelection)]
    pub fn get_selection(this: &Terminal) -> JsString;
    /// Check if there's an active selection
    #[wasm_bindgen(method, js_name = hasSelection)]
    pub fn has_selection(this: &Terminal) -> bool;
    /// Clear the current selection
    #[wasm_bindgen(method, js_name = clearSelection)]
    pub fn clear_selection(this: &Terminal);
    /// Select all text in the terminal
    #[wasm_bindgen(method, js_name = selectAll)]
    pub fn select_all(this: &Terminal);
    /// Select text at specific column and row with length
    #[wasm_bindgen(method)]
    pub fn select(this: &Terminal, column: u32, row: u32, length: u32);
    /// Select entire lines from start to end
    #[wasm_bindgen(method, js_name = selectLines)]
    pub fn select_lines(this: &Terminal, start: u32, end: u32);
    /// Get the current viewport Y position.
    ///
    /// This is the number of lines scrolled back from the bottom of the
    /// scrollback buffer. It may be fractional during smooth scrolling.
    #[wasm_bindgen(method, js_name = getViewportY)]
    pub fn get_viewport_y(this: &Terminal) -> f64;
    /// Get selection position as buffer range
    #[wasm_bindgen(method, js_name = getSelectionPosition)]
    pub fn get_selection_position(this: &Terminal) -> Option<IBufferRange>;

    /// Attach a custom keyboard event handler
    ///
    /// Returns true to prevent default handling
    #[wasm_bindgen(method, js_name = attachCustomKeyEventHandler)]
    pub fn attach_custom_key_event_handler(
        this: &Terminal,
        handler: &Function<fn(KeyboardEvent) -> Boolean>,
    );
    /// Attach a custom wheel event handler (Phase 2)
    ///
    /// Returns true to prevent default handling
    #[wasm_bindgen(method, js_name = attachCustomWheelEventHandler)]
    pub fn attach_custom_wheel_event_handler(
        this: &Terminal,
        handler: Option<&Function<fn(WheelEvent) -> Boolean>>,
    );
    /// Register a custom link provider
    ///
    /// Multiple providers can be registered to detect different types of links
    #[wasm_bindgen(method, js_name = registerLinkProvider)]
    pub fn register_link_provider(this: &Terminal, provider: &ILinkProvider);

    /// Scroll viewport by a number of lines
    ///
    /// - `amount`: Number of lines to scroll (positive = down, negative = up)
    #[wasm_bindgen(method, js_name = scrollLines)]
    pub fn scroll_lines(this: &Terminal, amount: i32);
    /// Scroll viewport by a number of pages
    ///
    /// - `amount`: Number of pages to scroll (positive = down, negative = up)
    #[wasm_bindgen(method, js_name = scrollPages)]
    pub fn scroll_pages(this: &Terminal, amount: i32);
    /// Scroll viewport to the top of the scrollback buffer
    #[wasm_bindgen(method, js_name = scrollToTop)]
    pub fn scroll_to_top(this: &Terminal);
    /// Scroll viewport to the bottom (current output)
    #[wasm_bindgen(method, js_name = scrollToBottom)]
    pub fn scroll_to_bottom(this: &Terminal);
    /// Scroll viewport to a specific line in the buffer
    ///
    /// - `line`: Line number (0 = top of scrollback, scrollbackLength = bottom)
    #[wasm_bindgen(method, js_name = scrollToLine)]
    pub fn scroll_to_line(this: &Terminal, line: u32);

    /// Dispose terminal and clean up resources
    #[wasm_bindgen(method)]
    pub fn dispose(this: &Terminal);

    /// Get a line from native WASM scrollback buffer
    ///
    /// Implements [`IScrollbackProvider`]
    #[wasm_bindgen(method, js_name = getScrollbackLine)]
    pub fn get_scrollback_line(this: &Terminal, offset: u32) -> Option<Array<GhosttyCell>>;
    /// Get scrollback length from native WASM
    ///
    /// Implements [`IScrollbackProvider`]
    #[wasm_bindgen(method, js_name = getScrollbackLength)]
    pub fn get_scrollback_length(this: &Terminal) -> u32;
    /// Query terminal mode state
    ///
    /// - `mode`: Mode number (e.g., 2004 for bracketed paste)
    /// - `is_ansi`: True for ANSI modes, false for DEC modes (default: false)
    ///
    /// Returns true if mode is enabled
    #[wasm_bindgen(method, js_name = getMode)]
    pub fn get_mode(this: &Terminal, mode: u32, is_ansi: Option<bool>) -> bool;
    /// Check if bracketed paste mode is enabled
    #[wasm_bindgen(method, js_name = hasBracketedPaste)]
    pub fn has_bracketed_paste(this: &Terminal) -> bool;
    /// Check if focus event reporting is enabled
    #[wasm_bindgen(method, js_name = hasFocusEvents)]
    pub fn has_focus_events(this: &Terminal) -> bool;
    /// Check if mouse tracking is enabled
    #[wasm_bindgen(method, js_name = hasMouseTracking)]
    pub fn has_mouse_tracking(this: &Terminal) -> bool;
}