rsvim_core 0.1.3-alpha.2

The core library for RSVIM text editor.
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
/**
 * ---
 * title: Rsvim API
 * sidebar_position: 2
 * ---
 *
 * The `Rsvim` global object, it contains two groups:
 * - General APIs.
 * - Editor APIs.
 *
 * @packageDocumentation
 *
 * @categoryDescription Global Object
 * The global object.
 *
 * @categoryDescription Editor APIs
 * These APIs are specific for editor, such as buffers, windows, key mappings, etc.
 *
 * @categoryDescription General APIs
 * These APIs are general for common javascript-based runtime, similar to [Deno APIs](https://docs.deno.com/api/deno/).
 */
/** @hidden */
function isNull(arg) {
    return arg === undefined || arg === null;
}
/** @hidden */
function isString(arg) {
    return typeof arg === "string";
}
/** @hidden */
function checkNotNull(arg, msg) {
    if (isNull(arg)) {
        throw new TypeError(`${msg} cannot be undefined or null`);
    }
}
/** @hidden */
function checkIsNumber(arg, msg) {
    if (typeof arg !== "number") {
        throw new TypeError(`${msg} must be a number, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkIsInteger(arg, msg) {
    checkIsNumber(arg, msg);
    if (!Number.isInteger(arg)) {
        throw new TypeError(`${msg} must be an integer, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkIsBoolean(arg, msg) {
    if (typeof arg !== "boolean") {
        throw new TypeError(`${msg} must be a boolean, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkIsString(arg, msg) {
    if (!isString(arg)) {
        throw new TypeError(`${msg} must be a string, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkOptionalString(arg, msg) {
    if (!(isString(arg) || isNull(arg))) {
        throw new TypeError(`${msg} must be a string?, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkMatchPattern(arg, pat, msg) {
    checkIsString(arg, msg);
    if (!pat.test(arg)) {
        throw new Error(`${msg} is invalid pattern: ${arg}"`);
    }
}
/** @hidden */
function checkIsFunction(arg, msg) {
    if (typeof arg !== "function") {
        throw new TypeError(`${msg} must be a function, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkIsObject(arg, msg) {
    if (typeof arg !== "object") {
        throw new TypeError(`${msg} must be an object, but found ${typeof arg}`);
    }
}
/** @hidden */
function checkIsUint8Array(arg, msg) {
    if (!(arg instanceof Uint8Array)) {
        throw new TypeError(`${msg} must be a Uint8Array, buf found ${typeof arg}`);
    }
}
/** @hidden */
function checkIsOptions(arg, options, msg) {
    if (!options.includes(arg)) {
        throw new RangeError(`${msg} is an invalid option: ${arg}`);
    }
}
/** @hidden */
function boundByIntegers(arg, bound) {
    if (arg < bound[0]) {
        return bound[0];
    }
    if (arg > bound[1]) {
        return bound[1];
    }
    return arg;
}
/** @hidden */
function setDefaultFields(arg, defaults) {
    for (const [key, val] of Object.entries(defaults)) {
        if (!Object.hasOwn(arg, key)) {
            Object.defineProperty(arg, key, { value: val, writable: true });
        }
    }
}
/**
 * The `Rsvim` global object.
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim'.
 * const vim = Rsvim;
 * ```
 *
 * @category Global Object
 * @hideconstructor
 */
export class Rsvim {
    buf = new RsvimBuf();
    cmd = new RsvimCmd();
    fs = new RsvimFs();
    opt = new RsvimOpt();
    rt = new RsvimRt();
    syn = new RsvimSyn();
}
/**
 * The `Rsvim.buf` global object for Vim buffers.
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim.buf'.
 * const buf = Rsvim.buf;
 * ```
 *
 * @category Editor APIs
 * @hideconstructor
 */
export class RsvimBuf {
    /**
     * Get current buffer's ID.
     *
     * The "current" buffer is the buffer that the window where your cursor is
     * located is binded to.
     *
     * :::warning
     * When the editor is not initialized, i.e. there's no buffer/window created. It
     * will return `undefined`. Once the editor is initialized, there will always have a
     * valid buffer binded to the "current" window (where your cursor is). It will return
     * the valid buffer ID.
     * :::
     *
     * @returns {(number | undefined)} It returns a valid buffer ID if the editor is initialized.
     * Otherwise it returns `undefined` if the editor is not initialized.
     *
     * @example
     * ```javascript
     * const bufId = Rsvim.buf.current();
     * ```
     */
    current() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.buf_current();
    }
    /**
     * List all buffers' IDs.
     *
     * :::warning
     * When the editor is not initialized, i.e. there's no buffer/window created. It
     * will return an empty array. Once the editor is initialized, there will have at least 1
     * buffer binded to the "current" window (where your cursor is). It will return all the
     * buffer IDs as an array.
     * :::
     *
     * @returns {number[]} All the buffers' IDs as an array. If there's no
     * buffer (i.e. the editor is not initialized), it returns an empty array.
     *
     * @example
     * ```javascript
     * const bufIds = Rsvim.buf.list();
     * ```
     */
    list() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.buf_list();
    }
    /**
     * Write (save) buffer's text contents to local filesystem synchronizely.
     *
     * @param {number} bufId - The buffer's ID that you want to write to filesystem.
     *
     * @returns {number} It returns a positive integer to indicate how many bytes
     * have been written to the file, if written successfully.
     *
     * @throws Throws {@link !TypeError} if the parameter is invalid, or {@link !Error} if failed to write buffer to file system.
     *
     * @example
     * ```javascript
     * const bufId = Rsvim.buf.currentBufferId();
     * try {
     *   const bytes = Rsvim.buf.writeSync(bufId);
     *   Rsvim.cmd.echo(`Buffer ${bufId} has been saved, ${bytes} bytes written`);
     * } catch (e) {
     *   Rsvim.cmd.echo(`Error: failed to save buffer ${bufId}, exception: ${e}`);
     * }
     * ```
     */
    writeSync(bufId) {
        checkIsInteger(bufId, `"Rsvim.buf.writeSync" bufId`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.buf_write_sync(bufId);
    }
}
/**
 * The `Rsvim.cmd` global object for Ex commands.
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim.cmd'.
 * const cmd = Rsvim.cmd;
 * ```
 *
 * @category Editor APIs
 * @hideconstructor
 */
export class RsvimCmd {
    /**
     * Create a ex command with a callback function.
     *
     * :::warning
     * The builtin command `js` cannot be override.
     * :::
     *
     * @param {string} name - Command name that is going to create. Only letters (`a-z` and `A-Z`), digits (`0-9`), underscore (`_`) and exclamation (`!`) are allowed in a command name. Command name must not begin with a digit.
     * @param {RsvimCmd.CommandCallback} callback - Async callback function that implements the command. It accepts an `ctx` parameter that contains all the information when user is running it. See {@link RsvimCmd.CommandCallback}.
     * @param {RsvimCmd.CommandAttributes} attributes - (Optional) Attributes that control the command behavior, by default is `{bang:false, nargs:"0"}`, see {@link RsvimCmd.CommandAttributes}.
     * @param {RsvimCmd.CommandOptions} options - (Optional) Options that control how the command is created, by default is `{force:true}`, see {@link RsvimCmd.CommandOptions}.
     * @returns {(RsvimCmd.CommandDefinition | undefined)} It returns `undefined` is the command is newly created. Or it returns a command definition that was defined previously.
     *
     * @throws Throws {@link !TypeError} if any parameters are invalid. Or throws {@link Error} if command name or alias already exists, but `force` option is not set to override existing command forcibly.
     *
     * @example
     * ```javascript
     * async function write(ctx: RsvimCmd.CommandContext): void {
     *   try {
     *     const bytes = Rsvim.buf.writeSync(ctx.currentBufferId);
     *
     *     // Call other async APIs
     *     const file = await Rsvim.fs.open("message.txt");
     *     const buffer = new Uint8Array(100);
     *     const read = await file.read(buffer);
     *     const message = new TextDecoder().decode(buffer);
     *
     *     Rsvim.cmd.echo(`Buffer ${bufId} has been saved, ${bytes} bytes written with message: ${message}`);
     *   } catch (e) {
     *     Rsvim.cmd.echo(`Error: failed to save buffer ${bufId}, exception: ${e}`);
     *   }
     * }
     * Rsvim.cmd.create("write", write);
     * ```
     */
    create(name, callback, attributes, options) {
        checkMatchPattern(name, /^[A-Za-z_!][A-Za-z0-9_!]*$/, `"Rsvim.cmd.create" name`);
        checkIsFunction(callback, `"Rsvim.cmd.create" callback`);
        attributes = attributes ?? { bang: false, nargs: "0" };
        checkIsObject(attributes, `"Rsvim.cmd.create" attributes`);
        setDefaultFields(attributes, { bang: false, nargs: "0" });
        checkIsBoolean(attributes.bang, `"Rsvim.cmd.create" bang attribute`);
        checkIsOptions(attributes.nargs, ["0", "1", "?", "+", "*"], `"Rsvim.cmd.create" nargs attribute`);
        options = options ?? { force: true };
        checkIsObject(options, `"Rsvim.cmd.create" options`);
        setDefaultFields(options, { force: true });
        checkIsBoolean(options.force, `"Rsvim.cmd.create" force option`);
        checkOptionalString(options.alias, `"Rsvim.cmd.create" alias option`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.cmd_create(name, callback, attributes, options);
    }
    /**
     * Echo message to the command-line.
     *
     * @param {any} message - It accepts string and other primitive types, except `null` and `undefined`.
     *
     * @throws Throws {@link !TypeError} if the parameter is `null` or `undefined` or no parameter provided.
     *
     * @example
     * ```javascript
     * Rsvim.cmd.echo("Hello Rsvim!");
     * ```
     */
    echo(message) {
        checkNotNull(message, `"Rsvim.cmd.echo" message`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.cmd_echo(message);
    }
    /**
     * List all registered ex command names.
     *
     * :::warning
     * The builtin `js` command will not be listed here.
     * :::
     *
     * @returns {string[]} Returns all registered ex command names, except the `js` command.
     *
     * @example
     * ```javascript
     * Rsvim.cmd.list().forEach((name) => {
     *   Rsvim.cmd.echo(`Command: ${name}`);
     * });
     * ```
     */
    list() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.cmd_list();
    }
    /**
     * Get ex command definition by name.
     *
     * :::warning
     * The builtin `js` command cannot be get.
     * :::
     *
     * @returns {(RsvimCmd.CommandDefinition | undefined)} Returns command definition by its name, except the `js` command.
     *
     * @example
     * ```javascript
     * const def = Rsvim.cmd.get("write");
     * Rsvim.cmd.echo(`Command: ${def.name}`);
     * ```
     */
    get(name) {
        checkIsString(name, `"Rsvim.cmd.get" name`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.cmd_get(name);
    }
    /**
     * Remove an ex command by name.
     *
     * :::warning
     * The builtin command `js` cannot be removed.
     * :::
     *
     * @param {string} name - The command name to be removed.
     * @returns {(RsvimCmd.CommandDefinition | undefined)} Returns the removed {@link RsvimCmd.CommandDefinition}, or `undefined` if no command is been removed.
     *
     * @throws Throws {@link !TypeError} if name is not a string.
     *
     * @example
     * ```javascript
     * Rsvim.cmd.list().forEach((cmd) => {
     *   // Remove all registered commands.
     *   Rsvim.cmd.remove(cmd.name);
     * });
     * ```
     */
    remove(name) {
        checkIsString(name, `"Rsvim.cmd.remove" name`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.cmd_remove(name);
    }
}
/**
 * The `Rsvim.fs` global object for file system and file IO.
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim.fs'.
 * const fs = Rsvim.fs;
 * ```
 *
 * @category General APIs
 * @hideconstructor
 */
export class RsvimFs {
    /**
     * Open a file and resolve to an instance of {@link RsvimFs.File}. The file does not need to previously exist if using the `create` or `createNew` open options.
     * The caller have to close the file to prevent resource leaking, see {@link RsvimFs.File.close}.
     *
     * @param {string} path - File path.
     * @param {RsvimFs.OpenOptions} options - (Optional) Open options, by default is `{read: true}`. See {@link RsvimFs.OpenOptions}.
     * @returns {Promise<RsvimFs.File>} It resolves to an instance of {@link RsvimFs.File}.
     *
     * @throws Throws {@link !TypeError} if any parameters are invalid. Or throws {@link Error} if failed to open/create the file.
     *
     * @example
     * ```javascript
     * const file = await Rsvim.fs.open("README.md");
     * ```
     */
    async open(path, options) {
        checkIsString(path, `"Rsvim.fs.open" path`);
        options = options ?? { read: true };
        checkIsObject(options, `"Rsvim.fs.open" options`);
        setDefaultFields(options, {
            append: false,
            create: false,
            createNew: false,
            read: false,
            truncate: false,
            write: false,
        });
        checkIsBoolean(options.append, `"Rsvim.fs.open" append option`);
        checkIsBoolean(options.create, `"Rsvim.fs.open" create option`);
        checkIsBoolean(options.createNew, `"Rsvim.fs.open" createNew option`);
        checkIsBoolean(options.read, `"Rsvim.fs.open" read option`);
        checkIsBoolean(options.truncate, `"Rsvim.fs.open" truncate option`);
        checkIsBoolean(options.write, `"Rsvim.fs.open" write option`);
        // @ts-ignore Ignore warning
        const handle = await __InternalRsvimGlobalObject.fs_open(path, options);
        return new RsvimFs.File(handle);
    }
    /**
     * The sync version of {@link open}.
     *
     * @param {string} path
     * @param {RsvimFs.OpenOptions} options
     * @returns {RsvimFs.File}
     *
     * @throws
     *
     * @example
     * ```javascript
     * const file = Rsvim.fs.openSync("README.md");
     * ```
     */
    openSync(path, options) {
        checkIsString(path, `"Rsvim.fs.openSync" path`);
        options = options ?? { read: true };
        checkIsObject(options, `"Rsvim.fs.open" options`);
        setDefaultFields(options, {
            append: false,
            create: false,
            createNew: false,
            read: false,
            truncate: false,
            write: false,
        });
        checkIsBoolean(options.append, `"Rsvim.fs.open" append option`);
        checkIsBoolean(options.create, `"Rsvim.fs.open" create option`);
        checkIsBoolean(options.createNew, `"Rsvim.fs.open" createNew option`);
        checkIsBoolean(options.read, `"Rsvim.fs.open" read option`);
        checkIsBoolean(options.truncate, `"Rsvim.fs.open" truncate option`);
        checkIsBoolean(options.write, `"Rsvim.fs.open" write option`);
        // @ts-ignore Ignore warning
        const handle = __InternalRsvimGlobalObject.fs_open_sync(path, options);
        return new RsvimFs.File(handle);
    }
    /**
     * Read a file in binary mode, i.e. into an array of bytes buffer, without open/close a file descriptor/handle.
     *
     * @param {string} path - File path to read.
     * @returns {Promise<Uint8Array>} It resolves to {@link !Uint8Array} that contains all the file contents as bytes array.
     *
     * @throws Throws {@link !TypeError} if the file name is invalid. Or throws {@link Error} if failed to read the file.
     *
     * @example
     * ```javascript
     * const buffer = await Rsvim.fs.readFile("README.md");
     * ```
     */
    async readFile(path) {
        checkIsString(path, `"Rsvim.fs.readFile" path`);
        // @ts-ignore Ignore warning
        return await __InternalRsvimGlobalObject.fs_read_file(path);
    }
    /**
     * The sync version of {@link readFile}.
     *
     * @param {string} path
     * @returns {Uint8Array}
     *
     * @throws
     *
     * @example
     * ```javascript
     * const buffer = Rsvim.fs.readFileSync("README.md");
     * ```
     */
    readFileSync(path) {
        checkIsString(path, `"Rsvim.fs.readFileSync" path`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.fs_read_file_sync(path);
    }
    /**
     * Read a file in text mode, i.e. into a string, without open/close a file descriptor/handle.
     *
     * @param {string} path - File path to read.
     * @returns {Promise<string>} It resolves to text string that contains all the file contents.
     *
     * @throws Throws {@link !TypeError} if the file name is invalid. Or throws {@link Error} if failed to read the file.
     *
     * @example
     * ```javascript
     * const payload = await Rsvim.fs.readTextFile("README.md");
     * ```
     */
    async readTextFile(path) {
        checkIsString(path, `"Rsvim.fs.readTextFile" path`);
        // @ts-ignore Ignore warning
        return await __InternalRsvimGlobalObject.fs_read_text_file(path);
    }
    /**
     * The sync version of {@link readTextFile}.
     *
     * @param {string} path
     * @returns {string}
     *
     * @throws
     *
     * @example
     * ```javascript
     * const payload = Rsvim.fs.readTextFileSync("README.md");
     * ```
     */
    readTextFileSync(path) {
        checkIsString(path, `"Rsvim.fs.readTextFileSync" path`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.fs_read_text_file_sync(path);
    }
}
(function (RsvimFs) {
    /**
     * The File object that access to an open file on filesystem.
     *
     * @see {@link RsvimFs.open}
     */
    class File {
        /** @hidden */
        #rid;
        /** @hidden */
        constructor(rid) {
            this.#rid = rid;
        }
        /**
         * Close the file.
         *
         * @example
         * ```javascript
         * const file = await Rsvim.fs.open("README.md");
         * // do work with the `file` object
         * file.close();
         *
         * // Or
         *
         * using file = await Rsvim.fs.open("README.md");
         * // do work with the `file` object
         * ```
         */
        close() {
            if (!isNull(this.#rid)) {
                // @ts-ignore Ignore warning
                __InternalRsvimGlobalObject.fs_close(this.#rid);
            }
            this.#rid = null;
        }
        /**
         * Close the file with `using` without `close` API.
         *
         * @example
         * ```javascript
         * using file = await Rsvim.fs.open("README.md");
         * // do work with the `file` object
         * ```
         *
         * @see {@link close}
         */
        [Symbol.dispose]() {
            this.close();
        }
        /**
         * File is already been closed.
         *
         * @example
         * ```javascript
         * const file = await Rsvim.fs.open("README.md");
         * if (!file.isDisposed()) {
         *   file.close();
         * }
         * ```
         */
        get isDisposed() {
            return isNull(this.#rid);
        }
        /**
         * Read a file into a buffer.
         *
         * :::warning
         * It is not guaranteed that the full buffer will be read in a single call.
         * :::
         *
         * @param {Uint8Array} buf - Read bytes into buffer.
         * @returns {Promise<number>} It resolves to either the number of bytes read during the operation or `0`(EOF) if there was no more to read.
         *
         * @throws Throws {@link !TypeError} if buf is not a Uint8Array.
         *
         * @example
         * ```javascript
         * using file = await Rsvim.fs.open("README.md");
         * const buf = new Uint8Array(100);
         * const n = await file.read(buf); // read 11 bytes
         * const text = new TextDecoder().decode(buf); // decode into UTF-8 string "hello world"
         * ```
         */
        async read(buf) {
            checkIsUint8Array(buf, `"RsvimFs.File.read" buf`);
            // @ts-ignore Ignore warning
            const n = await __InternalRsvimGlobalObject.fs_read(this.#rid, buf.buffer);
            return n;
        }
        /**
         * The sync version of {@link read}.
         *
         * @param {Uint8Array} buf
         * @returns {number}
         *
         * @throws
         *
         * @example
         * ```javascript
         * using file = await Rsvim.fs.open("README.md");
         * const buf = new Uint8Array(100);
         * const n = file.readSync(buf); // read 11 bytes
         * const text = new TextDecoder().decode(buf); // decode into UTF-8 string "hello world"
         * ```
         */
        readSync(buf) {
            checkIsUint8Array(buf, `"RsvimFs.File.readSync" buf`);
            // @ts-ignore Ignore warning
            return __InternalRsvimGlobalObject.fs_read_sync(this.#rid, buf.buffer);
        }
        /**
         * Write a buffer into a file.
         *
         * :::warning
         * It is not guaranteed that the full buffer will be written in a single call.
         * :::
         *
         * @param {Uint8Array} buf - Read bytes into buffer.
         * @returns {Promise<number>} It resolves to either the number of bytes written during the operation or `0` if there was nothing to write.
         *
         * @throws Throws {@link !TypeError} if buf is not a Uint8Array.
         *
         * @example
         * ```javascript
         * using file = await Rsvim.fs.open("README.md", {write:true,create:true});
         * const buf = new TextEncoder().encode("hello world");
         * const n = await file.write(buf); // write 11 bytes
         * ```
         */
        async write(buf) {
            checkIsUint8Array(buf, `"RsvimFs.File.write" buf`);
            // @ts-ignore Ignore warning
            const n = await __InternalRsvimGlobalObject.fs_write(this.#rid, buf.buffer);
            return n;
        }
        /**
         * The sync version of {@link write}.
         *
         * @param {Uint8Array} buf
         * @returns {number}
         *
         * @throws
         *
         * @example
         * ```javascript
         * using file = await Rsvim.fs.open("README.md", {write:true,create:true});
         * const buf = new TextEncoder().encode("hello world");
         * const n = file.writeSync(buf); // write 11 bytes
         * ```
         */
        writeSync(buf) {
            checkIsUint8Array(buf, `"RsvimFs.File.writeSync" buf`);
            // @ts-ignore Ignore warning
            return __InternalRsvimGlobalObject.fs_write_sync(this.#rid, buf.buffer);
        }
    }
    RsvimFs.File = File;
})(RsvimFs || (RsvimFs = {}));
/**
 * The `Rsvim.opt` global object for global editor options. These options will change the editor's behavior
 * and suit user's personal habits.
 *
 * There are 3 kinds of editor option:
 * - Global options: Options that are global that you use one value for all Rsvim component instances such
 *   as buffer, window, statusline, etc. When you change the option, it will take effect immediately and
 *   affect all existing instances.
 * - Local options: Options that only apply to one component instance, each instance has its own copy of
 *   this option, thus each can have its own value. This allow you to set an option in one instance, without
 *   modifying other instances.
 * - Global local options: Options that are global, and will be copy to a newly created Rsvim component
 *   instance. A global-local-option always has its corresponding local-option. When you change the option,
 *   it only will apply to the newly created instances, but cannot modify existing instances.
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim.opt'.
 * const opt = Rsvim.opt;
 * ```
 *
 * @category Editor APIs
 * @hideconstructor
 */
export class RsvimOpt {
    /**
     * Get the _expand-tab_ option. Local to buffer.
     *
     * When in insert mode, inserts [spaces](https://en.wikipedia.org/wiki/Whitespace_character) (ASCII `32`)
     * instead of a [horizontal tab](https://en.wikipedia.org/wiki/Tab_key) (ASCII `9`).
     *
     * See {@link shiftWidth} to get the number of spaces when inserting.
     *
     * @returns {boolean}
     *
     * @defaultValue `false`
     *
     * @example
     * ```javascript
     * // Get the 'expand-tab' option.
     * const value = Rsvim.opt.expandTab;
     * ```
     */
    get expandTab() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_expand_tab();
    }
    /**
     * Set the _expand-tab_ option.
     *
     * @param {boolean} value - The _expand-tab_ option.
     * @throws Throws {@link !TypeError} if value is not a boolean.
     *
     * @example
     * ```javascript
     * // Set the 'expand-tab' option.
     * Rsvim.opt.expandTab = true;
     * ```
     */
    set expandTab(value) {
        checkIsBoolean(value, `"Rsvim.opt.expandTab" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_expand_tab(value);
    }
    /**
     * Get the _file-encoding_ option. Local to buffer.
     *
     * Sets the [character encoding](https://en.wikipedia.org/wiki/Character_encoding) for the file of this buffer.
     * This will determine which character encoding is used when RSVIM read/write a file from file system.
     *
     * :::warning
     * For now, only **utf-8** encoding is supported.
     * :::
     *
     * @returns {RsvimOpt.FileEncodingOption}
     *
     * @defaultValue `"utf-8"`
     *
     * @example
     * ```javascript
     * // Get the 'file-encoding' option.
     * const value = Rsvim.opt.fileEncoding;
     * ```
     */
    get fileEncoding() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_file_encoding();
    }
    /**
     * Set the _file-encoding_ option.
     *
     * @param {RsvimOpt.FileEncodingOption} value - The _file-encoding_ option.
     * @throws Throws {@link !RangeError} if value is an invalid option.
     *
     * @example
     * ```javascript
     * // Set the 'file-encoding' option.
     * Rsvim.opt.fileEncoding = "utf-8";
     * ```
     */
    set fileEncoding(value) {
        checkIsOptions(value, ["utf-8"], `"Rsvim.opt.fileEncoding" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_file_encoding(value);
    }
    /**
     * Get the _file-format_ option. Local to buffer.
     *
     * Sets the [line end](https://en.wikipedia.org/wiki/Newline) for the buffer. There are 3 kinds of line end:
     * - `CRLF`: used by [Windows](https://www.microsoft.com/windows).
     * - `LF`: used by [Linux](https://en.wikipedia.org/wiki/Linux) and [Unix](https://en.wikipedia.org/wiki/Unix) (include [MacOS](https://www.apple.com/macos/)).
     * - `CR`: used by [classic MacOS](https://en.wikipedia.org/wiki/Classic_Mac_OS).
     *
     * :::warning
     * Today's Mac also uses `LF` as line end, you should never use `CR` any more.
     * :::
     *
     * For this option, it has below choices:
     * - `"dos"`: equivalent to `CRLF` line end.
     * - `"unix"`: equivalent to `LF` line end.
     * - `"mac"`: equivalent to `CR` line end.
     *
     * @returns {RsvimOpt.FileFormatOption}
     *
     * @defaultValue `"dos"` for Windows/MS-DOS, `"unix"` for Linux/Unix/MacOS.
     *
     * @example
     * ```javascript
     * // Get the 'file-format' option.
     * const value = Rsvim.opt.fileFormat;
     * ```
     */
    get fileFormat() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_file_format();
    }
    /**
     * Set the _file-format_ option.
     *
     * @param {RsvimOpt.FileFormatOption} value - The _file-format_ option.
     * @throws Throws {@link !RangeError} if value is an invalid option.
     *
     * @example
     * ```javascript
     * // Set the 'file-format' option.
     * Rsvim.opt.fileFormat = "unix";
     * ```
     */
    set fileFormat(value) {
        checkIsOptions(value, ["dos", "unix", "mac"], `"Rsvim.opt.fileFormat" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_file_format(value);
    }
    /**
     * Get the _fix-end-of-line_ option. Local to buffer.
     *
     * WHen writing a file and this options is enabled, `EOL` (`LF`, `CR`, `CRLF`) at the end of file will be restored if missing. Disable this option if you want to preserve the situation from the original file.
     *
     * @see {@link fileFormat}
     *
     * @returns {boolean}
     *
     * @defaultValue `true`
     *
     * @example
     * ```javascript
     * // Get the 'fix-end-of-line' option.
     * const value = Rsvim.opt.fixEndOfLine;
     * ```
     */
    get fixEndOfLine() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_fix_end_of_line();
    }
    /**
     * Set the _fix-end-of-line_ option.
     *
     * @param {boolean} value - The _fix-end-of-line_ option.
     * @throws Throws {@link !RangeError} if value is not a boolean.
     *
     * @example
     * ```javascript
     * // Set the 'fix-end-of-line' option.
     * Rsvim.opt.fixEndOfLine = false;
     * ```
     */
    set fixEndOfLine(value) {
        checkIsBoolean(value, `"Rsvim.opt.fixEndOfLine" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_fix_end_of_line(value);
    }
    /**
     * Get the _line-break_ option. This options is also known as
     * [word wrap](https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap). Local to window.
     *
     * If `true`, Vim will wrap long lines by a word boundary rather than at the last character that fits on the screen.
     * It only affects the way the file is displayed, not its contents.
     *
     * This option is not used when the {@link wrap} option is `false`.
     *
     * @returns {boolean}
     *
     * @defaultValue `false`
     *
     * @example
     * ```javascript
     * // Get the 'lineBreak' option.
     * const value = Rsvim.opt.lineBreak;
     * ```
     */
    get lineBreak() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_line_break();
    }
    /**
     * Set the _line-break_ option.
     *
     * @param {boolean} value - The _line-break_ option.
     * @throws Throws {@link !TypeError} if value is not a boolean.
     *
     * @example
     * ```javascript
     * // Set the 'lineBreak' option.
     * Rsvim.opt.lineBreak = true;
     * ```
     */
    set lineBreak(value) {
        checkIsBoolean(value, `"Rsvim.opt.lineBreak" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_line_break(value);
    }
    /**
     * Get the _shift-width_ option. Local to buffer.
     *
     * When {@link expandTab} is `true`, the number of spaces that is used when inserts a
     * [horizontal tab](https://en.wikipedia.org/wiki/Tab_key) (ASCII `9`).
     *
     * When {@link expandTab} is `false`, this option is not been used.
     *
     *
     * @returns {number}
     *
     * @defaultValue `8`
     *
     * @example
     * ```javascript
     * // Get the 'shift-width' option.
     * const value = Rsvim.opt.shiftWidth;
     * ```
     */
    get shiftWidth() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_shift_width();
    }
    /**
     * Set the _shift-width_ option. It only accepts an integer between `[1,255]`, if the value is out of range, it will be bound to this range.
     *
     *
     * @param {number} value - The _shift-width_ option.
     * @throws Throws {@link !TypeError} if value is not an integer.
     *
     * @example
     * ```javascript
     * // Set the 'shift-width' option.
     * Rsvim.opt.shiftWidth = 4;
     * ```
     */
    set shiftWidth(value) {
        checkIsInteger(value, `"Rsvim.opt.shiftWidth" value`);
        value = boundByIntegers(value, [1, 255]);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_shift_width(value);
    }
    /**
     * Get the _syntax-parser-lib-path_ option. Global option.
     *
     * By default the syntax parser libs are stored in `${RSVIM_CONFIG_HOME}/.tree-sitter-parsers` folder. `${RSVIM_CONFIG_HOME}` is the configuration home for rsvim.
     *
     * @see [Rsvim Configuration](https://rsvim.github.io/docs/manual/configuration)
     *
     * @returns {string}
     *
     * @defaultValue `${RSVIM_CONFIG_HOME}/.tree-sitter-parsers`
     *
     * @example
     * ```javascript
     * // Get the 'syntax-parser-lib-path' option.
     * const value = Rsvim.opt.syntaxParserLibPath;
     * ```
     */
    get syntaxParserLibPath() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_syntax_parser_lib_path();
    }
    /**
     * Set the _syntax-parser-lib-path_ option. It only accepts a string which represents the file path on your local machine, which is used to save all compiled tree-sitter parser dynamic libraries.
     *
     * @param {string} value - The _syntax-parser-lib-path_ option.
     * @throws Throws {@link !TypeError} if value is not an string.
     *
     * @example
     * ```javascript
     * // Set the 'syntax-parser-lib-path' option.
     * Rsvim.opt.syntaxParserLibPath = ".";
     * ```
     */
    set syntaxParserLibPath(value) {
        checkIsString(value, `"Rsvim.opt.syntaxParserLibPath" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_syntax_parser_lib_path(value);
    }
    /**
     * Get the _tab-stop_ option. This option is also known as
     * [tab-size](https://developer.mozilla.org/en-US/docs/Web/CSS/tab-size).
     * Local to buffer.
     *
     * This option changes how text is displayed.
     *
     * Defines how many columns (on the terminal) used to display the
     * [horizontal tab](https://en.wikipedia.org/wiki/Tab_key) (ASCII `9`). This value should be between `[1,255]`.
     *
     *
     * @returns {number}
     *
     * @defaultValue `8`
     *
     * @example
     * ```javascript
     * // Get the 'tab-stop' option.
     * const value = Rsvim.opt.tabStop;
     * ```
     */
    get tabStop() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_tab_stop();
    }
    /**
     * Set the _tab-stop_ option. It only accepts an integer between `[1,255]`, if the value is out of range, it will be bound to this range.
     *
     * @param {number} value - The _tab-stop_ option.
     * @throws Throws {@link !TypeError} if value is not an integer.
     *
     * @example
     * ```javascript
     * // Set the 'tab-stop' option.
     * Rsvim.opt.tabStop = 4;
     * ```
     */
    set tabStop(value) {
        checkIsInteger(value, `"Rsvim.opt.tabStop" value`);
        value = boundByIntegers(value, [1, 255]);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_tab_stop(value);
    }
    /**
     * Get the _wrap_ option. This option is also known as
     * [line wrap](https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap). Local to window.
     *
     * This option changes how text is displayed.
     *
     * When `true`, lines longer than the width of the window will wrap and
     * displaying continues on the next line. When `false` lines will not wrap
     * and only part of long lines will be displayed. When the cursor is
     * moved to a part that is not shown, the screen will scroll horizontally.
     *
     * The line will be broken in the middle of a word if necessary. See {@link lineBreak}
     * to get the break at a word boundary.
     *
     * @returns {boolean}
     *
     * @defaultValue `true`
     *
     * @example
     * ```javascript
     * // Get the 'wrap' option.
     * const value = Rsvim.opt.wrap;
     * ```
     */
    get wrap() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.opt_get_wrap();
    }
    /**
     * Set the _wrap_ option.
     *
     * @param {boolean} value - The _wrap_ option.
     * @throws Throws {@link !TypeError} if value is not a boolean.
     *
     * @example
     * ```javascript
     * // Set the 'wrap' option.
     * Rsvim.opt.wrap = true;
     * ```
     */
    set wrap(value) {
        checkIsBoolean(value, `"Rsvim.opt.wrap" value`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.opt_set_wrap(value);
    }
}
/**
 * The `Rsvim.rt` global object for javascript runtime (editor process).
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim.rt'.
 * const rt = Rsvim.rt;
 * ```
 *
 * @category General APIs
 * @hideconstructor
 */
export class RsvimRt {
    /**
     * Exit editor.
     *
     * :::tip
     * To ensure file system data safety, editor will wait for all the ongoing file write operations
     * to complete before actually exiting, however any new write requests will be rejected.
     * :::
     *
     * @param {exitCode?} exitCode - (Optional) The editor process exit with this exit code, by default with code `0`.
     *
     * @throws Throws {@link !TypeError} if `exitCode` is neither an integer nor `undefined`.
     *
     * @example
     * ```javascript
     * // Exit with default exit code `0`.
     * Rsvim.rt.exit();
     *
     * // Exit with error exit code `-1`.
     * Rsvim.rt.exit(-1);
     * ```
     */
    exit(exitCode) {
        exitCode = exitCode ?? 0;
        checkIsInteger(exitCode, `"Rsvim.rt.exit" code`);
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.rt_exit(exitCode);
    }
}
/**
 * The `Rsvim.syn` global object for javascript runtime (editor process).
 *
 * @example
 * ```javascript
 * // Create a alias to 'Rsvim.syn'.
 * const syn = Rsvim.syn;
 * ```
 *
 * @category Editor APIs
 * @hideconstructor
 */
export class RsvimSyn {
    /**
     * Load tree-sitter parsers.
     *
     * @see [tree-sitter - List of parsers](https://github.com/tree-sitter/tree-sitter/wiki/List-of-parsers)
     *
     * @param {RsvimSyn.LoadParserOptions} options - Load options.
     *
     * @returns {string[]} It returns all the loaded parser names.
     *
     * @throws Throws {@link !TypeError} if `options` is an invalid option, throws {@link !Error} if failed to load.
     *
     * @example
     * ```javascript
     * // Load `tree-sitter-c` parser.
     * const parserNames = await Rsvim.syn.loadParser({grammarPath: "./tree-sitter-c"});
     * Rsvim.cmd.echo(`Loaded parsers: ${parserNames}`);
     * ```
     */
    async loadParser(options) {
        checkIsObject(options, `"Rsvim.syn.loadParser" options`);
        checkIsString(options.grammarPath, `"Rsvim.syn.loadParser" grammarPath option`);
        const parserNames = 
        // @ts-ignore Ignore warning
        await __InternalRsvimGlobalObject.syn_load_parser(options);
        return parserNames;
    }
    /**
     * Load tree-sitter parsers synchronizely.
     *
     * @see {@link loadParser}
     *
     * @param {RsvimSyn.LoadParserOptions} options - Load options.
     *
     * @returns {string[]} It returns all the loaded parser names.
     *
     * @throws Throws {@link !TypeError} if `options` is an invalid option, throws {@link !Error} if failed to load.
     *
     * @example
     * ```javascript
     * // Load `tree-sitter-c` parser synchronizely.
     * const parserNames = Rsvim.syn.loadParserSync({grammarPath: "./tree-sitter-c"});
     * Rsvim.cmd.echo(`Loaded parsers: ${parserNames}`);
     * ```
     */
    loadParserSync(options) {
        checkIsObject(options, `"Rsvim.syn.loadParserSync" options`);
        checkIsString(options.grammarPath, `"Rsvim.syn.loadParserSync" grammarPath option`);
        const parserNames = 
        // @ts-ignore Ignore warning
        __InternalRsvimGlobalObject.syn_load_parser_sync(options);
        return parserNames;
    }
    /**
     * List all loaded tree-sitter parsers.
     *
     * @returns {string[]} It returns all the loaded parser names.
     *
     * @example
     * ```javascript
     * // Print all loaded parser names.
     * const allParserNames = Rsvim.syn.listParsers();
     * Rsvim.cmd.echo(`All loaded parsers: ${allParserNames}`);
     * ```
     */
    listParsers() {
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.syn_list_parsers();
    }
    /**
     * Get tree-sitter parser metadata by parser name.
     *
     * @param {string} name - The parser's name.
     *
     * @returns {RsvimSyn.ParserMetadata | undefined} It returns all the loaded parser names.
     *
     * @example
     * ```javascript
     * // Get parser metadata by name.
     * const parserMetadata = Rsvim.syn.getParserMetadata("rust");
     * Rsvim.cmd.echo(`Rust parser metadata: ${parserMetadata}`);
     * ```
     */
    getParserMetadata(name) {
        checkIsString(name, `"Rsvim.syn.getParserMetadata" name`);
        // @ts-ignore Ignore warning
        return __InternalRsvimGlobalObject.syn_get_parser_metadata(name);
    }
}
(function (globalThis) {
    globalThis.Rsvim = new Rsvim();
})(globalThis);