@battlefieldduck/xterm-svelte 1.0.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -7
- package/dist/Xterm.svelte +50 -25
- package/dist/Xterm.svelte.d.ts +4 -45
- package/dist/XtermAddon.d.ts +0 -4
- package/dist/XtermAddon.js +8 -7
- package/dist/XtermAddonType.d.ts +0 -1
- package/dist/{XtermEvent.d.ts → XtermProps.d.ts} +25 -24
- package/dist/index.d.ts +2 -2
- package/package.json +11 -12
- /package/dist/{XtermEvent.js → XtermProps.js} +0 -0
package/README.md
CHANGED
|
@@ -3,13 +3,23 @@
|
|
|
3
3
|
<img align="right" width="100" height="100" src="https://github.com/BattlefieldDuck/xterm-svelte/assets/29337428/e1055940-ae66-48b5-9a1f-1965949b5757">
|
|
4
4
|
|
|
5
5
|
[](https://github.com/BattlefieldDuck/xterm-svelte/actions/workflows/node-build.yml)
|
|
6
|
+

|
|
6
7
|
[](https://www.npmjs.com/package/@battlefieldduck/xterm-svelte)
|
|
7
8
|

|
|
9
|
+

|
|
10
|
+

|
|
8
11
|
|
|
9
12
|
xterm-svelte is a wrapper for the [xterm.js](https://github.com/xtermjs/xterm.js) library, designed to work seamlessly with SvelteKit. This library allows you to embed a fully functional terminal in your SvelteKit application.
|
|
10
13
|
|
|
11
14
|
Check it out: https://xterm-svelte.pages.dev
|
|
12
15
|
|
|
16
|
+
## Version Compatibility
|
|
17
|
+
|
|
18
|
+
| Version | Svelte Version | Branch | Demonstration |
|
|
19
|
+
| ------- | -------------- | ------------------------------------------------------------------------- | -------------------------------------- |
|
|
20
|
+
| 2.x.x | Svelte 5 | [`main`](https://github.com/BattlefieldDuck/xterm-svelte) | https://xterm-svelte.pages.dev |
|
|
21
|
+
| 1.x.x | Svelte 4 | [`svelte4`](https://github.com/BattlefieldDuck/xterm-svelte/tree/svelte4) | https://svelte4.xterm-svelte.pages.dev |
|
|
22
|
+
|
|
13
23
|
## Features
|
|
14
24
|
|
|
15
25
|
- **Full integration with SvelteKit**
|
|
@@ -49,9 +59,8 @@ Here's a basic example of how to use xterm-svelte in your SvelteKit application:
|
|
|
49
59
|
fontFamily: 'Consolas'
|
|
50
60
|
};
|
|
51
61
|
|
|
52
|
-
async function onLoad(
|
|
62
|
+
async function onLoad(terminal: Terminal) {
|
|
53
63
|
console.log('Child component has loaded');
|
|
54
|
-
const terminal = event.detail.terminal;
|
|
55
64
|
|
|
56
65
|
// FitAddon Usage
|
|
57
66
|
const fitAddon = new (await XtermAddon.FitAddon()).FitAddon();
|
|
@@ -61,18 +70,16 @@ Here's a basic example of how to use xterm-svelte in your SvelteKit application:
|
|
|
61
70
|
terminal.write('Hello World');
|
|
62
71
|
}
|
|
63
72
|
|
|
64
|
-
function onData(
|
|
65
|
-
const data = event.detail;
|
|
73
|
+
function onData(data: string) {
|
|
66
74
|
console.log('onData()', data);
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
function onKey(
|
|
70
|
-
const data = event.detail;
|
|
77
|
+
function onKey(data: { key: string; domEvent: KeyboardEvent }) {
|
|
71
78
|
console.log('onKey()', data);
|
|
72
79
|
}
|
|
73
80
|
</script>
|
|
74
81
|
|
|
75
|
-
<Xterm {options}
|
|
82
|
+
<Xterm {options} {onLoad} {onData} {onKey} />
|
|
76
83
|
```
|
|
77
84
|
|
|
78
85
|
## Contributing
|
package/dist/Xterm.svelte
CHANGED
|
@@ -1,27 +1,52 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import '@xterm/xterm/css/xterm.css';
|
|
3
|
+
import { onMount } from 'svelte';
|
|
4
|
+
import type { XtermProps } from './index.js';
|
|
5
|
+
|
|
6
|
+
let parent = $state<HTMLElement>();
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
options,
|
|
10
|
+
onBell,
|
|
11
|
+
onBinary,
|
|
12
|
+
onCursorMove,
|
|
13
|
+
onData,
|
|
14
|
+
onKey,
|
|
15
|
+
onLineFeed,
|
|
16
|
+
onRender,
|
|
17
|
+
onWriteParsed,
|
|
18
|
+
onResize,
|
|
19
|
+
onScroll,
|
|
20
|
+
onSelectionChange,
|
|
21
|
+
onTitleChange,
|
|
22
|
+
onLoad,
|
|
23
|
+
...rest
|
|
24
|
+
}: XtermProps = $props();
|
|
25
|
+
|
|
26
|
+
onMount(async () => {
|
|
27
|
+
const { Terminal } = await import('@xterm/xterm');
|
|
28
|
+
const terminal = new Terminal(options);
|
|
29
|
+
|
|
30
|
+
terminal.onBell(() => onBell?.());
|
|
31
|
+
terminal.onBinary((data) => onBinary?.(data));
|
|
32
|
+
terminal.onCursorMove(() => onCursorMove?.());
|
|
33
|
+
terminal.onData((data) => onData?.(data));
|
|
34
|
+
terminal.onKey((data) => onKey?.(data));
|
|
35
|
+
terminal.onLineFeed(() => onLineFeed?.());
|
|
36
|
+
terminal.onRender((data) => onRender?.(data));
|
|
37
|
+
terminal.onWriteParsed(() => onWriteParsed?.());
|
|
38
|
+
terminal.onResize((data) => onResize?.(data));
|
|
39
|
+
terminal.onScroll((data) => onScroll?.(data));
|
|
40
|
+
terminal.onSelectionChange(() => onSelectionChange?.());
|
|
41
|
+
terminal.onTitleChange((data) => onTitleChange?.(data));
|
|
42
|
+
|
|
43
|
+
if (parent) {
|
|
44
|
+
terminal.open(parent);
|
|
45
|
+
onLoad?.(terminal);
|
|
46
|
+
} else {
|
|
47
|
+
console.error('[xterm-svelte] Parent element not found');
|
|
48
|
+
}
|
|
49
|
+
});
|
|
25
50
|
</script>
|
|
26
51
|
|
|
27
|
-
<div bind:this={parent}
|
|
52
|
+
<div bind:this={parent} {...rest}></div>
|
package/dist/Xterm.svelte.d.ts
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import '@xterm/xterm/css/xterm.css';
|
|
3
|
-
import type {
|
|
4
|
-
declare const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
options?: (ITerminalOptions & ITerminalInitOnlyOptions) | undefined;
|
|
8
|
-
};
|
|
9
|
-
events: {
|
|
10
|
-
load: CustomEvent<{
|
|
11
|
-
terminal: import("@xterm/xterm").Terminal;
|
|
12
|
-
}>;
|
|
13
|
-
bell: CustomEvent<void>;
|
|
14
|
-
binary: CustomEvent<string>;
|
|
15
|
-
cursormove: CustomEvent<void>;
|
|
16
|
-
data: CustomEvent<string>;
|
|
17
|
-
key: CustomEvent<{
|
|
18
|
-
key: string;
|
|
19
|
-
domEvent: KeyboardEvent;
|
|
20
|
-
}>;
|
|
21
|
-
linefeed: CustomEvent<void>;
|
|
22
|
-
render: CustomEvent<{
|
|
23
|
-
start: number;
|
|
24
|
-
end: number;
|
|
25
|
-
}>;
|
|
26
|
-
writeparsed: CustomEvent<void>;
|
|
27
|
-
resize: CustomEvent<{
|
|
28
|
-
cols: number;
|
|
29
|
-
rows: number;
|
|
30
|
-
}>;
|
|
31
|
-
scroll: CustomEvent<number>;
|
|
32
|
-
selectionchange: CustomEvent<void>;
|
|
33
|
-
titlechange: CustomEvent<string>;
|
|
34
|
-
} & {
|
|
35
|
-
[evt: string]: CustomEvent<any>;
|
|
36
|
-
};
|
|
37
|
-
slots: {};
|
|
38
|
-
exports?: undefined;
|
|
39
|
-
bindings?: undefined;
|
|
40
|
-
};
|
|
41
|
-
export type XtermProps = typeof __propDef.props;
|
|
42
|
-
export type XtermEvents = typeof __propDef.events;
|
|
43
|
-
export type XtermSlots = typeof __propDef.slots;
|
|
44
|
-
export default class Xterm extends SvelteComponent<XtermProps, XtermEvents, XtermSlots> {
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
2
|
+
import type { XtermProps } from './index.js';
|
|
3
|
+
declare const Xterm: import("svelte").Component<XtermProps, {}, "">;
|
|
4
|
+
type Xterm = ReturnType<typeof Xterm>;
|
|
5
|
+
export default Xterm;
|
package/dist/XtermAddon.d.ts
CHANGED
|
@@ -53,10 +53,6 @@ export declare class XtermAddon {
|
|
|
53
53
|
*
|
|
54
54
|
* @returns A promise that resolves to the 'ligatures' addon module.
|
|
55
55
|
*/
|
|
56
|
-
static LigaturesAddon: () => Promise<{
|
|
57
|
-
default: typeof import("@xterm/addon-ligatures");
|
|
58
|
-
LigaturesAddon: typeof import("@xterm/addon-ligatures").LigaturesAddon;
|
|
59
|
-
}>;
|
|
60
56
|
/**
|
|
61
57
|
* Dynamically imports the 'search' addon from `@xterm/addon-search`.
|
|
62
58
|
* @returns A promise that resolves to the 'search' addon module.
|
package/dist/XtermAddon.js
CHANGED
|
@@ -35,13 +35,14 @@ export class XtermAddon {
|
|
|
35
35
|
*
|
|
36
36
|
* @returns A promise that resolves to the 'ligatures' addon module.
|
|
37
37
|
*/
|
|
38
|
-
static LigaturesAddon = async () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
// static LigaturesAddon = async () => {
|
|
39
|
+
// // @ts-ignore
|
|
40
|
+
// if (typeof process === 'undefined' || process.versions == null || process.versions.node == null) {
|
|
41
|
+
// // This is not a Node.js environment
|
|
42
|
+
// throw new Error('This module can only be imported in a Node.js environment');
|
|
43
|
+
// }
|
|
44
|
+
// return await import('@xterm/addon-ligatures');
|
|
45
|
+
// }
|
|
45
46
|
/**
|
|
46
47
|
* Dynamically imports the 'search' addon from `@xterm/addon-search`.
|
|
47
48
|
* @returns A promise that resolves to the 'search' addon module.
|
package/dist/XtermAddonType.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export type * from '@xterm/addon-canvas';
|
|
|
3
3
|
export type * from '@xterm/addon-clipboard';
|
|
4
4
|
export type * from '@xterm/addon-fit';
|
|
5
5
|
export type * from '@xterm/addon-image';
|
|
6
|
-
export type * from '@xterm/addon-ligatures';
|
|
7
6
|
export type * from '@xterm/addon-search';
|
|
8
7
|
export type * from '@xterm/addon-serialize';
|
|
9
8
|
export type * from '@xterm/addon-unicode11';
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import type { Terminal } from "@xterm/xterm";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
load: {
|
|
8
|
-
terminal: Terminal;
|
|
9
|
-
};
|
|
2
|
+
import type { ITerminalOptions, ITerminalInitOnlyOptions } from './index.js';
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
+
export type XtermProps = {
|
|
5
|
+
options?: ITerminalOptions & ITerminalInitOnlyOptions;
|
|
10
6
|
/**
|
|
11
7
|
* Adds an event listener for when the bell is triggered.
|
|
12
8
|
* @returns an `IDisposable` to stop listening.
|
|
13
9
|
*/
|
|
14
|
-
|
|
10
|
+
onBell?: () => void;
|
|
15
11
|
/**
|
|
16
12
|
* Adds an event listener for when a binary event fires. This is used to
|
|
17
13
|
* enable non UTF-8 conformant binary messages to be sent to the backend.
|
|
@@ -21,12 +17,12 @@ export interface XtermEvent {
|
|
|
21
17
|
* binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`.
|
|
22
18
|
* @returns an `IDisposable` to stop listening.
|
|
23
19
|
*/
|
|
24
|
-
|
|
20
|
+
onBinary?: (data: string) => void;
|
|
25
21
|
/**
|
|
26
22
|
* Adds an event listener for the cursor moves.
|
|
27
23
|
* @returns an `IDisposable` to stop listening.
|
|
28
24
|
*/
|
|
29
|
-
|
|
25
|
+
onCursorMove?: () => void;
|
|
30
26
|
/**
|
|
31
27
|
* Adds an event listener for when a data event fires. This happens for
|
|
32
28
|
* example when the user types or pastes into the terminal. The event value
|
|
@@ -34,32 +30,32 @@ export interface XtermEvent {
|
|
|
34
30
|
* on to the backing pty.
|
|
35
31
|
* @returns an `IDisposable` to stop listening.
|
|
36
32
|
*/
|
|
37
|
-
data: string;
|
|
33
|
+
onData?: (data: string) => void;
|
|
38
34
|
/**
|
|
39
35
|
* Adds an event listener for when a key is pressed. The event value
|
|
40
36
|
* contains the string that will be sent in the data event as well as the
|
|
41
37
|
* DOM event that triggered it.
|
|
42
38
|
* @returns an `IDisposable` to stop listening.
|
|
43
39
|
*/
|
|
44
|
-
|
|
40
|
+
onKey?: (data: {
|
|
45
41
|
key: string;
|
|
46
42
|
domEvent: KeyboardEvent;
|
|
47
|
-
};
|
|
43
|
+
}) => void;
|
|
48
44
|
/**
|
|
49
45
|
* Adds an event listener for when a line feed is added.
|
|
50
46
|
* @returns an `IDisposable` to stop listening.
|
|
51
47
|
*/
|
|
52
|
-
|
|
48
|
+
onLineFeed?: () => void;
|
|
53
49
|
/**
|
|
54
50
|
* Adds an event listener for when rows are rendered. The event value
|
|
55
51
|
* contains the start row and end rows of the rendered area (ranges from `0`
|
|
56
52
|
* to `Terminal.rows - 1`).
|
|
57
53
|
* @returns an `IDisposable` to stop listening.
|
|
58
54
|
*/
|
|
59
|
-
|
|
55
|
+
onRender?: (data: {
|
|
60
56
|
start: number;
|
|
61
57
|
end: number;
|
|
62
|
-
};
|
|
58
|
+
}) => void;
|
|
63
59
|
/**
|
|
64
60
|
* Adds an event listener for when data has been parsed by the terminal,
|
|
65
61
|
* after {@link write} is called. This event is useful to listen for any
|
|
@@ -69,31 +65,36 @@ export interface XtermEvent {
|
|
|
69
65
|
* that this can fire when there are still writes pending if there is a lot
|
|
70
66
|
* of data.
|
|
71
67
|
*/
|
|
72
|
-
|
|
68
|
+
onWriteParsed?: () => void;
|
|
73
69
|
/**
|
|
74
70
|
* Adds an event listener for when the terminal is resized. The event value
|
|
75
71
|
* contains the new size.
|
|
76
72
|
* @returns an `IDisposable` to stop listening.
|
|
77
73
|
*/
|
|
78
|
-
|
|
74
|
+
onResize?: (data: {
|
|
79
75
|
cols: number;
|
|
80
76
|
rows: number;
|
|
81
|
-
};
|
|
77
|
+
}) => void;
|
|
82
78
|
/**
|
|
83
79
|
* Adds an event listener for when a scroll occurs. The event value is the
|
|
84
80
|
* new position of the viewport.
|
|
85
81
|
* @returns an `IDisposable` to stop listening.
|
|
86
82
|
*/
|
|
87
|
-
|
|
83
|
+
onScroll?: (data: number) => void;
|
|
88
84
|
/**
|
|
89
85
|
* Adds an event listener for when a selection change occurs.
|
|
90
86
|
* @returns an `IDisposable` to stop listening.
|
|
91
87
|
*/
|
|
92
|
-
|
|
88
|
+
onSelectionChange?: () => void;
|
|
93
89
|
/**
|
|
94
90
|
* Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
|
|
95
91
|
* The event value is the new title.
|
|
96
92
|
* @returns an `IDisposable` to stop listening.
|
|
97
93
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
onTitleChange?: (data: string) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Adds an event listener for when the terminal is loaded.
|
|
97
|
+
* @returns an `IDisposable` to stop listening.
|
|
98
|
+
*/
|
|
99
|
+
onLoad?: (terminal: Terminal) => void;
|
|
100
|
+
} & HTMLAttributes<HTMLDivElement>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Xterm from './Xterm.svelte';
|
|
2
2
|
import { XtermAddon } from './XtermAddon.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { XtermProps } from './XtermProps.js';
|
|
4
4
|
export { Xterm, XtermAddon };
|
|
5
5
|
export type * from '@xterm/xterm';
|
|
6
6
|
export type * from './XtermAddonType.js';
|
|
7
|
-
export type {
|
|
7
|
+
export type { XtermProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@battlefieldduck/xterm-svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A SvelteKit wrapper for Xterm.js, enabling terminal embedding in SvelteKit apps, managing Xterm addons, and providing seamless updates with the latest SvelteKit and Xterm.js versions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -44,28 +44,28 @@
|
|
|
44
44
|
"!dist/**/*.spec.*"
|
|
45
45
|
],
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"svelte": "^
|
|
47
|
+
"svelte": "^5.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@playwright/test": "^1.28.1",
|
|
51
51
|
"@sveltejs/adapter-auto": "^3.0.0",
|
|
52
|
-
"@sveltejs/kit": "^2.5.
|
|
52
|
+
"@sveltejs/kit": "^2.5.27",
|
|
53
53
|
"@sveltejs/package": "^2.0.0",
|
|
54
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
54
|
+
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
|
55
55
|
"@types/eslint": "^8.56.0",
|
|
56
56
|
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
57
57
|
"@typescript-eslint/parser": "^7.7.1",
|
|
58
58
|
"eslint": "^8.56.0",
|
|
59
59
|
"eslint-config-prettier": "^9.1.0",
|
|
60
|
-
"eslint-plugin-svelte": "^2.
|
|
60
|
+
"eslint-plugin-svelte": "^2.45.1",
|
|
61
61
|
"prettier": "^3.1.1",
|
|
62
|
-
"prettier-plugin-svelte": "^3.
|
|
62
|
+
"prettier-plugin-svelte": "^3.2.6",
|
|
63
63
|
"publint": "^0.2.7",
|
|
64
|
-
"svelte": "^
|
|
65
|
-
"svelte-check": "^
|
|
64
|
+
"svelte": "^5.0.0",
|
|
65
|
+
"svelte-check": "^4.0.0",
|
|
66
66
|
"tslib": "^2.4.1",
|
|
67
|
-
"typescript": "^5.
|
|
68
|
-
"vite": "^5.
|
|
67
|
+
"typescript": "^5.5.0",
|
|
68
|
+
"vite": "^5.4.4",
|
|
69
69
|
"vitest": "^2.0.3"
|
|
70
70
|
},
|
|
71
71
|
"svelte": "./dist/index.js",
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"@xterm/addon-clipboard": "^0.1.0",
|
|
78
78
|
"@xterm/addon-fit": "^0.10.0",
|
|
79
79
|
"@xterm/addon-image": "^0.8.0",
|
|
80
|
-
"@xterm/addon-ligatures": "^0.9.0",
|
|
81
80
|
"@xterm/addon-search": "^0.15.0",
|
|
82
81
|
"@xterm/addon-serialize": "^0.13.0",
|
|
83
82
|
"@xterm/addon-unicode11": "^0.8.0",
|
|
@@ -85,4 +84,4 @@
|
|
|
85
84
|
"@xterm/addon-webgl": "^0.18.0",
|
|
86
85
|
"@xterm/xterm": "^5.5.0"
|
|
87
86
|
}
|
|
88
|
-
}
|
|
87
|
+
}
|
|
File without changes
|