@thazhemadam/vim-state 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ import type { VimMode } from "./state.js";
2
+ import type { VimSnapshot } from "./machine.js";
3
+ /** Rendered status labels shown by the Pi adapter. */
4
+ export type VimModeLabel = "INSERT" | "NORMAL" | "OPERATOR" | "VISUAL" | "VISUAL LINE" | "REPLACE";
5
+ export declare function getVimMode(snapshot: VimSnapshot): VimMode;
6
+ export declare function isVimOperatorMode(snapshot: VimSnapshot): boolean;
7
+ export declare function isVimVisualMode(snapshot: VimSnapshot): boolean;
8
+ /** Return the user-visible mode label, including parser substates worth showing. */
9
+ export declare function getVimModeLabel(snapshot: VimSnapshot): VimModeLabel;
@@ -0,0 +1,59 @@
1
+ export function getVimMode(snapshot) {
2
+ switch (snapshot.value) {
3
+ case "insert":
4
+ return "insert";
5
+ case "normal":
6
+ case "find-forward":
7
+ case "find-backward":
8
+ case "till-forward":
9
+ case "till-backward":
10
+ case "g-prefix":
11
+ case "operator-find-forward":
12
+ case "operator-find-backward":
13
+ case "operator-till-forward":
14
+ case "operator-till-backward":
15
+ case "operator-inner-object":
16
+ case "operator-around-object":
17
+ case "operator-pending":
18
+ case "visual-char":
19
+ case "visual-line":
20
+ case "replace-once":
21
+ return "normal";
22
+ case "replace":
23
+ return "replace";
24
+ default:
25
+ throw new Error(`Unknown Vim machine state: ${JSON.stringify(snapshot.value)}`);
26
+ }
27
+ }
28
+ export function isVimOperatorMode(snapshot) {
29
+ return (snapshot.value === "operator-pending" ||
30
+ snapshot.value === "operator-find-forward" ||
31
+ snapshot.value === "operator-find-backward" ||
32
+ snapshot.value === "operator-till-forward" ||
33
+ snapshot.value === "operator-till-backward" ||
34
+ snapshot.value === "operator-inner-object" ||
35
+ snapshot.value === "operator-around-object");
36
+ }
37
+ export function isVimVisualMode(snapshot) {
38
+ return snapshot.value === "visual-char" || snapshot.value === "visual-line";
39
+ }
40
+ /** Return the user-visible mode label, including parser substates worth showing. */
41
+ export function getVimModeLabel(snapshot) {
42
+ if (isVimOperatorMode(snapshot)) {
43
+ return "OPERATOR";
44
+ }
45
+ if (snapshot.value === "visual-char") {
46
+ return "VISUAL";
47
+ }
48
+ if (snapshot.value === "visual-line") {
49
+ return "VISUAL LINE";
50
+ }
51
+ switch (getVimMode(snapshot)) {
52
+ case "insert":
53
+ return "INSERT";
54
+ case "normal":
55
+ return "NORMAL";
56
+ case "replace":
57
+ return "REPLACE";
58
+ }
59
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Public modal state values exposed by the Vim core.
3
+ *
4
+ * Keep this aligned with `vimMachine` state node names and Vim's observable
5
+ * `mode()` values where practical.
6
+ */
7
+ export type VimMode = "insert" | "normal" | "replace";
8
+ export declare const initialVimMode: VimMode;
package/dist/state.js ADDED
@@ -0,0 +1 @@
1
+ export const initialVimMode = "insert";
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@thazhemadam/vim-state",
3
+ "version": "0.1.0",
4
+ "license": "LGPL-3.0-only",
5
+ "description": "Reusable Vim modal state machine and host-neutral editor semantics.",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/thazhemadam/vim-state.git",
10
+ "directory": "packages/vim-state"
11
+ },
12
+ "homepage": "https://github.com/thazhemadam/vim-state/tree/main/packages/vim-state#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/thazhemadam/vim-state/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "LICENSE",
22
+ "LICENSE.GPL",
23
+ "README.md"
24
+ ],
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "build": "tsc -p tsconfig.build.json",
35
+ "check": "tsc --noEmit && oxlint",
36
+ "lint": "oxlint",
37
+ "lint:fix": "oxlint --fix",
38
+ "prepack": "npm run build",
39
+ "test": "tsx --test test/**/*.test.ts"
40
+ },
41
+ "dependencies": {
42
+ "xstate": "5.32.1"
43
+ },
44
+ "devDependencies": {
45
+ "oxlint": "^1.70.0",
46
+ "tsx": "^4.22.4",
47
+ "typescript": "^5.9.3"
48
+ }
49
+ }