@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 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
  [![Node.js Build](https://github.com/BattlefieldDuck/xterm-svelte/actions/workflows/node-build.yml/badge.svg)](https://github.com/BattlefieldDuck/xterm-svelte/actions/workflows/node-build.yml)
6
+ ![NPM Type Definitions](https://img.shields.io/npm/types/%40battlefieldduck%2Fxterm-svelte)
6
7
  [![NPM Version](https://img.shields.io/npm/v/%40battlefieldduck%2Fxterm-svelte)](https://www.npmjs.com/package/@battlefieldduck/xterm-svelte)
7
8
  ![NPM Downloads](https://img.shields.io/npm/dw/%40battlefieldduck%2Fxterm-svelte)
9
+ ![NPM Downloads](https://img.shields.io/npm/d18m/%40battlefieldduck%2Fxterm-svelte)
10
+ ![NPM License](https://img.shields.io/npm/l/%40battlefieldduck%2Fxterm-svelte)
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(event: CustomEvent<{ terminal: Terminal }>) {
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(event: CustomEvent<string>) {
65
- const data = event.detail;
73
+ function onData(data: string) {
66
74
  console.log('onData()', data);
67
75
  }
68
76
 
69
- function onKey(event: CustomEvent<{ key: string; domEvent: KeyboardEvent }>) {
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} on:load={onLoad} on:data={onData} on:key={onKey} />
82
+ <Xterm {options} {onLoad} {onData} {onKey} />
76
83
  ```
77
84
 
78
85
  ## Contributing
package/dist/Xterm.svelte CHANGED
@@ -1,27 +1,52 @@
1
- <script>import "@xterm/xterm/css/xterm.css";
2
- import { onMount, createEventDispatcher } from "svelte";
3
- let parent;
4
- let props = { ...$$restProps };
5
- export let options = void 0;
6
- const dispatch = createEventDispatcher();
7
- onMount(async () => {
8
- const { Terminal } = await import("@xterm/xterm");
9
- const terminal = new Terminal(options);
10
- terminal.onBell(() => dispatch("bell"));
11
- terminal.onBinary((data) => dispatch("binary", data));
12
- terminal.onCursorMove(() => dispatch("cursormove"));
13
- terminal.onData((data) => dispatch("data", data));
14
- terminal.onKey((data) => dispatch("key", data));
15
- terminal.onLineFeed(() => dispatch("linefeed"));
16
- terminal.onRender((data) => dispatch("render", data));
17
- terminal.onWriteParsed(() => dispatch("writeparsed"));
18
- terminal.onResize((data) => dispatch("resize", data));
19
- terminal.onScroll((data) => dispatch("scroll", data));
20
- terminal.onSelectionChange(() => dispatch("selectionchange"));
21
- terminal.onTitleChange((data) => dispatch("titlechange", data));
22
- terminal.open(parent);
23
- dispatch("load", { terminal });
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} class={props.class} style={props.style}></div>
52
+ <div bind:this={parent} {...rest}></div>
@@ -1,46 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import '@xterm/xterm/css/xterm.css';
3
- import type { ITerminalOptions, ITerminalInitOnlyOptions } from './index.js';
4
- declare const __propDef: {
5
- props: {
6
- [x: string]: any;
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;
@@ -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.
@@ -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
- if (typeof process === 'undefined' || process.versions == null || process.versions.node == null) {
40
- // This is not a Node.js environment
41
- throw new Error('This module can only be imported in a Node.js environment');
42
- }
43
- return await import('@xterm/addon-ligatures');
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.
@@ -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
- export interface XtermEvent {
3
- /**
4
- * Adds an event listener for when the terminal is loaded.
5
- * @returns an `IDisposable` to stop listening.
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
- bell: void;
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
- binary: string;
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
- cursormove: void;
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
- key: {
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
- linefeed: void;
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
- render: {
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
- writeparsed: void;
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
- resize: {
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
- scroll: number;
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
- selectionchange: void;
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
- titlechange: string;
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 { XtermEvent } from './XtermEvent.js';
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 { XtermEvent };
7
+ export type { XtermProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@battlefieldduck/xterm-svelte",
3
- "version": "1.0.1",
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": "^4.0.0"
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.7",
52
+ "@sveltejs/kit": "^2.5.27",
53
53
  "@sveltejs/package": "^2.0.0",
54
- "@sveltejs/vite-plugin-svelte": "^3.0.0",
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.38.0",
60
+ "eslint-plugin-svelte": "^2.45.1",
61
61
  "prettier": "^3.1.1",
62
- "prettier-plugin-svelte": "^3.1.2",
62
+ "prettier-plugin-svelte": "^3.2.6",
63
63
  "publint": "^0.2.7",
64
- "svelte": "^4.2.7",
65
- "svelte-check": "^3.7.0",
64
+ "svelte": "^5.0.0",
65
+ "svelte-check": "^4.0.0",
66
66
  "tslib": "^2.4.1",
67
- "typescript": "^5.0.0",
68
- "vite": "^5.2.10",
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