@xterm/addon-clipboard 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.
- package/LICENSE +19 -0
- package/README.md +53 -0
- package/lib/addon-clipboard.js +2 -0
- package/lib/addon-clipboard.js.map +1 -0
- package/package.json +29 -0
- package/src/ClipboardAddon.ts +99 -0
- package/typings/addon-clipboard.d.ts +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2023, The xterm.js authors (https://github.com/xtermjs/xterm.js)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
## @xterm/addon-clipboard
|
|
2
|
+
|
|
3
|
+
An addon for [xterm.js](https://github.com/xtermjs/xterm.js) that enables
|
|
4
|
+
accessing the system clipboard. This addon requires xterm.js v4+.
|
|
5
|
+
|
|
6
|
+
### Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install --save @xterm/addon-clipboard
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { Terminal } from 'xterm';
|
|
16
|
+
import { ClipboardAddon } from '@xterm/addon-clipboard';
|
|
17
|
+
|
|
18
|
+
const terminal = new Terminal();
|
|
19
|
+
const clipboardAddon = new ClipboardAddon();
|
|
20
|
+
terminal.loadAddon(clipboardAddon);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To use a custom clipboard provider
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Terminal } from '@xterm/xterm';
|
|
27
|
+
import { ClipboardAddon, IClipboardProvider, ClipboardSelectionType } from '@xterm/addon-clipboard';
|
|
28
|
+
|
|
29
|
+
function b64Encode(data: string): string {
|
|
30
|
+
// Base64 encode impl
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function b64Decode(data: string): string {
|
|
34
|
+
// Base64 decode impl
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class MyCustomClipboardProvider implements IClipboardProvider {
|
|
38
|
+
private _data: string
|
|
39
|
+
public readText(selection: ClipboardSelectionType): Promise<string> {
|
|
40
|
+
return Promise.resolve(b64Encode(this._data));
|
|
41
|
+
}
|
|
42
|
+
public writeText(selection: ClipboardSelectionType, data: string): Promise<void> {
|
|
43
|
+
this._data = b64Decode(data);
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const terminal = new Terminal();
|
|
49
|
+
const clipboardAddon = new ClipboardAddon(new MyCustomClipboardProvider());
|
|
50
|
+
terminal.loadAddon(clipboardAddon);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
See the full [API](https://github.com/xtermjs/xterm.js/blob/master/addons/addon-clipboard/typings/addon-clipboard.d.ts) for more advanced usage.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardAddon=e():t.ClipboardAddon=e()}(self,(()=>(()=>{var t={575:function(t,e,r){"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==r.g&&r.g,t.exports=function(){"use strict";var t,e="3.7.7",r=e,n="function"==typeof Buffer,o="function"==typeof TextDecoder?new TextDecoder:void 0,i="function"==typeof TextEncoder?new TextEncoder:void 0,u=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),a=(t={},u.forEach((function(e,r){return t[e]=r})),t),c=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,f=String.fromCharCode.bind(String),s="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):function(t){return new Uint8Array(Array.prototype.slice.call(t,0))},d=function(t){return t.replace(/=/g,"").replace(/[+\/]/g,(function(t){return"+"==t?"-":"_"}))},l=function(t){return t.replace(/[^A-Za-z0-9\+\/]/g,"")},p=function(t){for(var e,r,n,o,i="",a=t.length%3,c=0;c<t.length;){if((r=t.charCodeAt(c++))>255||(n=t.charCodeAt(c++))>255||(o=t.charCodeAt(c++))>255)throw new TypeError("invalid character found");i+=u[(e=r<<16|n<<8|o)>>18&63]+u[e>>12&63]+u[e>>6&63]+u[63&e]}return a?i.slice(0,a-3)+"===".substring(a):i},h="function"==typeof btoa?function(t){return btoa(t)}:n?function(t){return Buffer.from(t,"binary").toString("base64")}:p,b=n?function(t){return Buffer.from(t).toString("base64")}:function(t){for(var e=[],r=0,n=t.length;r<n;r+=4096)e.push(f.apply(null,t.subarray(r,r+4096)));return h(e.join(""))},y=function(t,e){return void 0===e&&(e=!1),e?d(b(t)):b(t)},x=function(t){if(t.length<2)return(e=t.charCodeAt(0))<128?t:e<2048?f(192|e>>>6)+f(128|63&e):f(224|e>>>12&15)+f(128|e>>>6&63)+f(128|63&e);var e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320);return f(240|e>>>18&7)+f(128|e>>>12&63)+f(128|e>>>6&63)+f(128|63&e)},A=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,g=function(t){return t.replace(A,x)},v=n?function(t){return Buffer.from(t,"utf8").toString("base64")}:i?function(t){return b(i.encode(t))}:function(t){return h(g(t))},B=function(t,e){return void 0===e&&(e=!1),e?d(v(t)):v(t)},C=function(t){return B(t,!0)},m=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,w=function(t){switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return f(55296+(e>>>10))+f(56320+(1023&e));case 3:return f((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return f((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},T=function(t){return t.replace(m,w)},_=function(t){if(t=t.replace(/\s+/g,""),!c.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(3&t.length));for(var e,r,n,o="",i=0;i<t.length;)e=a[t.charAt(i++)]<<18|a[t.charAt(i++)]<<12|(r=a[t.charAt(i++)])<<6|(n=a[t.charAt(i++)]),o+=64===r?f(e>>16&255):64===n?f(e>>16&255,e>>8&255):f(e>>16&255,e>>8&255,255&e);return o},F="function"==typeof atob?function(t){return atob(l(t))}:n?function(t){return Buffer.from(t,"base64").toString("binary")}:_,U=n?function(t){return s(Buffer.from(t,"base64"))}:function(t){return s(F(t).split("").map((function(t){return t.charCodeAt(0)})))},P=function(t){return U(S(t))},j=n?function(t){return Buffer.from(t,"base64").toString("utf8")}:o?function(t){return o.decode(U(t))}:function(t){return T(F(t))},S=function(t){return l(t.replace(/[-_]/g,(function(t){return"-"==t?"+":"/"})))},E=function(t){return j(S(t))},R=function(t){return{value:t,enumerable:!1,writable:!0,configurable:!0}},O=function(){var t=function(t,e){return Object.defineProperty(String.prototype,t,R(e))};t("fromBase64",(function(){return E(this)})),t("toBase64",(function(t){return B(this,t)})),t("toBase64URI",(function(){return B(this,!0)})),t("toBase64URL",(function(){return B(this,!0)})),t("toUint8Array",(function(){return P(this)}))},D=function(){var t=function(t,e){return Object.defineProperty(Uint8Array.prototype,t,R(e))};t("toBase64",(function(t){return y(this,t)})),t("toBase64URI",(function(){return y(this,!0)})),t("toBase64URL",(function(){return y(this,!0)}))},z={version:e,VERSION:r,atob:F,atobPolyfill:_,btoa:h,btoaPolyfill:p,fromBase64:E,toBase64:B,encode:B,encodeURI:C,encodeURL:C,utob:g,btou:T,decode:E,isValid:function(t){if("string"!=typeof t)return!1;var e=t.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(e)||!/[^\s0-9a-zA-Z\-_]/.test(e)},fromUint8Array:y,toUint8Array:P,extendString:O,extendUint8Array:D,extendBuiltins:function(){O(),D()},Base64:{}};return Object.keys(z).forEach((function(t){return z.Base64[t]=z[t]})),z}()}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}();var n={};return(()=>{"use strict";var t=n;Object.defineProperty(t,"__esModule",{value:!0}),t.Base64=t.BrowserClipboardProvider=t.ClipboardAddon=void 0;const e=r(575);t.ClipboardAddon=class{constructor(t=new i,e=new o){this._base64=t,this._provider=e}activate(t){this._terminal=t,this._disposable=t.parser.registerOscHandler(52,(t=>this._setOrReportClipboard(t)))}dispose(){return this._disposable?.dispose()}_readText(t,e){const r=this._base64.encodeText(e);this._terminal?.input(`]52;${t};${r}`,!1)}_setOrReportClipboard(t){const e=t.split(";");if(e.length<2)return!0;const r=e[0],n=e[1];if("?"===n){const t=this._provider.readText(r);return t instanceof Promise?t.then((t=>(this._readText(r,t),!0))):(this._readText(r,t),!0)}let o="";try{o=this._base64.decodeText(n)}catch{}const i=this._provider.writeText(r,o);return!(i instanceof Promise)||i.then((()=>!0))}};class o{async readText(t){return"c"!==t?Promise.resolve(""):navigator.clipboard.readText()}async writeText(t,e){return"c"!==t?Promise.resolve():navigator.clipboard.writeText(e)}}t.BrowserClipboardProvider=o;class i{encodeText(t){return e.Base64.encode(t)}decodeText(t){const r=e.Base64.decode(t);return e.Base64.isValid(t)&&e.Base64.encode(r)===t?r:""}}t.Base64=i})(),n})()));
|
|
2
|
+
//# sourceMappingURL=addon-clipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addon-clipboard.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAwB,eAAID,IAE5BD,EAAqB,eAAIC,GAC1B,CATD,CASGK,MAAM,I,iCCcU,oBAATA,KAAuBA,KACT,oBAAXC,OAAyBA,YACV,IAAX,EAAAC,GAAyB,EAAAA,EAnBhCL,EAAOD,QAoBI,WACjB,aAYA,IAWQO,EAXJC,EAAU,QAIVC,EAAUD,EACVE,EAA+B,mBAAXC,OACpBC,EAA6B,mBAAhBC,YAA6B,IAAIA,iBAAgBC,EAC9DC,EAA6B,mBAAhBC,YAA6B,IAAIA,iBAAgBF,EAE9DG,EAASC,MAAMC,UAAUC,MAAMC,KADvB,qEAERC,GACIf,EAAM,CAAC,EAGZU,EAFGM,SAAQ,SAAUC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,EACKL,QAAQM,QAAQ,IAElBC,UAAUC,UAAUT,UAC7B,CAEO,eAAMK,CAAUC,EAAmCP,GACxD,MAAkB,MAAdO,EACKL,QAAQM,UAEVC,UAAUC,UAAUJ,UAAUN,EACvC,EAbF,6BAgBA,MAAa9B,EACJ,UAAAyB,CAAWN,GAChB,OAAO,SAASjE,OAAOiE,EACzB,CACO,UAAAe,CAAWf,GAChB,MAAMW,EAAO,SAASrD,OAAO0C,GAC7B,OAAK,SAASvB,QAAQuB,IAAS,SAASjE,OAAO4E,KAAUX,EAGlDW,EAFE,EAGX,EAVF,U","sources":["webpack://ClipboardAddon/webpack/universalModuleDefinition","webpack://ClipboardAddon/./node_modules/js-base64/base64.js","webpack://ClipboardAddon/webpack/bootstrap","webpack://ClipboardAddon/webpack/runtime/global","webpack://ClipboardAddon/./src/ClipboardAddon.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ClipboardAddon\"] = factory();\n\telse\n\t\troot[\"ClipboardAddon\"] = factory();\n})(self, () => {\nreturn ","//\n// THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND!\n//\n;\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined'\n ? module.exports = factory()\n : typeof define === 'function' && define.amd\n ? define(factory) :\n // cf. https://github.com/dankogai/js-base64/issues/119\n (function () {\n // existing version for noConflict()\n var _Base64 = global.Base64;\n var gBase64 = factory();\n gBase64.noConflict = function () {\n global.Base64 = _Base64;\n return gBase64;\n };\n if (global.Meteor) { // Meteor.js\n Base64 = gBase64;\n }\n global.Base64 = gBase64;\n })();\n}((typeof self !== 'undefined' ? self\n : typeof window !== 'undefined' ? window\n : typeof global !== 'undefined' ? global\n : this), function () {\n 'use strict';\n /**\n * base64.ts\n *\n * Licensed under the BSD 3-Clause License.\n * http://opensource.org/licenses/BSD-3-Clause\n *\n * References:\n * http://en.wikipedia.org/wiki/Base64\n *\n * @author Dan Kogai (https://github.com/dankogai)\n */\n var version = '3.7.7';\n /**\n * @deprecated use lowercase `version`.\n */\n var VERSION = version;\n var _hasBuffer = typeof Buffer === 'function';\n var _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;\n var _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;\n var b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n var b64chs = Array.prototype.slice.call(b64ch);\n var b64tab = (function (a) {\n var tab = {};\n a.forEach(function (c, i) { return tab[c] = i; });\n return tab;\n })(b64chs);\n var b64re = /^(?:[A-Za-z\\d+\\/]{4})*?(?:[A-Za-z\\d+\\/]{2}(?:==)?|[A-Za-z\\d+\\/]{3}=?)?$/;\n var _fromCC = String.fromCharCode.bind(String);\n var _U8Afrom = typeof Uint8Array.from === 'function'\n ? Uint8Array.from.bind(Uint8Array)\n : function (it) { return new Uint8Array(Array.prototype.slice.call(it, 0)); };\n var _mkUriSafe = function (src) { return src\n .replace(/=/g, '').replace(/[+\\/]/g, function (m0) { return m0 == '+' ? '-' : '_'; }); };\n var _tidyB64 = function (s) { return s.replace(/[^A-Za-z0-9\\+\\/]/g, ''); };\n /**\n * polyfill version of `btoa`\n */\n var btoaPolyfill = function (bin) {\n // console.log('polyfilled');\n var u32, c0, c1, c2, asc = '';\n var pad = bin.length % 3;\n for (var i = 0; i < bin.length;) {\n if ((c0 = bin.charCodeAt(i++)) > 255 ||\n (c1 = bin.charCodeAt(i++)) > 255 ||\n (c2 = bin.charCodeAt(i++)) > 255)\n throw new TypeError('invalid character found');\n u32 = (c0 << 16) | (c1 << 8) | c2;\n asc += b64chs[u32 >> 18 & 63]\n + b64chs[u32 >> 12 & 63]\n + b64chs[u32 >> 6 & 63]\n + b64chs[u32 & 63];\n }\n return pad ? asc.slice(0, pad - 3) + \"===\".substring(pad) : asc;\n };\n /**\n * does what `window.btoa` of web browsers do.\n * @param {String} bin binary string\n * @returns {string} Base64-encoded string\n */\n var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }\n : _hasBuffer ? function (bin) { return Buffer.from(bin, 'binary').toString('base64'); }\n : btoaPolyfill;\n var _fromUint8Array = _hasBuffer\n ? function (u8a) { return Buffer.from(u8a).toString('base64'); }\n : function (u8a) {\n // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326\n var maxargs = 0x1000;\n var strs = [];\n for (var i = 0, l = u8a.length; i < l; i += maxargs) {\n strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));\n }\n return _btoa(strs.join(''));\n };\n /**\n * converts a Uint8Array to a Base64 string.\n * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5\n * @returns {string} Base64 string\n */\n var fromUint8Array = function (u8a, urlsafe) {\n if (urlsafe === void 0) { urlsafe = false; }\n return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);\n };\n // This trick is found broken https://github.com/dankogai/js-base64/issues/130\n // const utob = (src: string) => unescape(encodeURIComponent(src));\n // reverting good old fationed regexp\n var cb_utob = function (c) {\n if (c.length < 2) {\n var cc = c.charCodeAt(0);\n return cc < 0x80 ? c\n : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))\n + _fromCC(0x80 | (cc & 0x3f)))\n : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))\n + _fromCC(0x80 | ((cc >>> 6) & 0x3f))\n + _fromCC(0x80 | (cc & 0x3f)));\n }\n else {\n var cc = 0x10000\n + (c.charCodeAt(0) - 0xD800) * 0x400\n + (c.charCodeAt(1) - 0xDC00);\n return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))\n + _fromCC(0x80 | ((cc >>> 12) & 0x3f))\n + _fromCC(0x80 | ((cc >>> 6) & 0x3f))\n + _fromCC(0x80 | (cc & 0x3f)));\n }\n };\n var re_utob = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFFF]|[^\\x00-\\x7F]/g;\n /**\n * @deprecated should have been internal use only.\n * @param {string} src UTF-8 string\n * @returns {string} UTF-16 string\n */\n var utob = function (u) { return u.replace(re_utob, cb_utob); };\n //\n var _encode = _hasBuffer\n ? function (s) { return Buffer.from(s, 'utf8').toString('base64'); }\n : _TE\n ? function (s) { return _fromUint8Array(_TE.encode(s)); }\n : function (s) { return _btoa(utob(s)); };\n /**\n * converts a UTF-8-encoded string to a Base64 string.\n * @param {boolean} [urlsafe] if `true` make the result URL-safe\n * @returns {string} Base64 string\n */\n var encode = function (src, urlsafe) {\n if (urlsafe === void 0) { urlsafe = false; }\n return urlsafe\n ? _mkUriSafe(_encode(src))\n : _encode(src);\n };\n /**\n * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.\n * @returns {string} Base64 string\n */\n var encodeURI = function (src) { return encode(src, true); };\n // This trick is found broken https://github.com/dankogai/js-base64/issues/130\n // const btou = (src: string) => decodeURIComponent(escape(src));\n // reverting good old fationed regexp\n var re_btou = /[\\xC0-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF7][\\x80-\\xBF]{3}/g;\n var cb_btou = function (cccc) {\n switch (cccc.length) {\n case 4:\n var cp = ((0x07 & cccc.charCodeAt(0)) << 18)\n | ((0x3f & cccc.charCodeAt(1)) << 12)\n | ((0x3f & cccc.charCodeAt(2)) << 6)\n | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;\n return (_fromCC((offset >>> 10) + 0xD800)\n + _fromCC((offset & 0x3FF) + 0xDC00));\n case 3:\n return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)\n | ((0x3f & cccc.charCodeAt(1)) << 6)\n | (0x3f & cccc.charCodeAt(2)));\n default:\n return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)\n | (0x3f & cccc.charCodeAt(1)));\n }\n };\n /**\n * @deprecated should have been internal use only.\n * @param {string} src UTF-16 string\n * @returns {string} UTF-8 string\n */\n var btou = function (b) { return b.replace(re_btou, cb_btou); };\n /**\n * polyfill version of `atob`\n */\n var atobPolyfill = function (asc) {\n // console.log('polyfilled');\n asc = asc.replace(/\\s+/g, '');\n if (!b64re.test(asc))\n throw new TypeError('malformed base64.');\n asc += '=='.slice(2 - (asc.length & 3));\n var u24, bin = '', r1, r2;\n for (var i = 0; i < asc.length;) {\n u24 = b64tab[asc.charAt(i++)] << 18\n | b64tab[asc.charAt(i++)] << 12\n | (r1 = b64tab[asc.charAt(i++)]) << 6\n | (r2 = b64tab[asc.charAt(i++)]);\n bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)\n : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)\n : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);\n }\n return bin;\n };\n /**\n * does what `window.atob` of web browsers do.\n * @param {String} asc Base64-encoded string\n * @returns {string} binary string\n */\n var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }\n : _hasBuffer ? function (asc) { return Buffer.from(asc, 'base64').toString('binary'); }\n : atobPolyfill;\n //\n var _toUint8Array = _hasBuffer\n ? function (a) { return _U8Afrom(Buffer.from(a, 'base64')); }\n : function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };\n /**\n * converts a Base64 string to a Uint8Array.\n */\n var toUint8Array = function (a) { return _toUint8Array(_unURI(a)); };\n //\n var _decode = _hasBuffer\n ? function (a) { return Buffer.from(a, 'base64').toString('utf8'); }\n : _TD\n ? function (a) { return _TD.decode(_toUint8Array(a)); }\n : function (a) { return btou(_atob(a)); };\n var _unURI = function (a) { return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; })); };\n /**\n * converts a Base64 string to a UTF-8 string.\n * @param {String} src Base64 string. Both normal and URL-safe are supported\n * @returns {string} UTF-8 string\n */\n var decode = function (src) { return _decode(_unURI(src)); };\n /**\n * check if a value is a valid Base64 string\n * @param {String} src a value to check\n */\n var isValid = function (src) {\n if (typeof src !== 'string')\n return false;\n var s = src.replace(/\\s+/g, '').replace(/={0,2}$/, '');\n return !/[^\\s0-9a-zA-Z\\+/]/.test(s) || !/[^\\s0-9a-zA-Z\\-_]/.test(s);\n };\n //\n var _noEnum = function (v) {\n return {\n value: v, enumerable: false, writable: true, configurable: true\n };\n };\n /**\n * extend String.prototype with relevant methods\n */\n var extendString = function () {\n var _add = function (name, body) { return Object.defineProperty(String.prototype, name, _noEnum(body)); };\n _add('fromBase64', function () { return decode(this); });\n _add('toBase64', function (urlsafe) { return encode(this, urlsafe); });\n _add('toBase64URI', function () { return encode(this, true); });\n _add('toBase64URL', function () { return encode(this, true); });\n _add('toUint8Array', function () { return toUint8Array(this); });\n };\n /**\n * extend Uint8Array.prototype with relevant methods\n */\n var extendUint8Array = function () {\n var _add = function (name, body) { return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body)); };\n _add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });\n _add('toBase64URI', function () { return fromUint8Array(this, true); });\n _add('toBase64URL', function () { return fromUint8Array(this, true); });\n };\n /**\n * extend Builtin prototypes with relevant methods\n */\n var extendBuiltins = function () {\n extendString();\n extendUint8Array();\n };\n var gBase64 = {\n version: version,\n VERSION: VERSION,\n atob: _atob,\n atobPolyfill: atobPolyfill,\n btoa: _btoa,\n btoaPolyfill: btoaPolyfill,\n fromBase64: decode,\n toBase64: encode,\n encode: encode,\n encodeURI: encodeURI,\n encodeURL: encodeURI,\n utob: utob,\n btou: btou,\n decode: decode,\n isValid: isValid,\n fromUint8Array: fromUint8Array,\n toUint8Array: toUint8Array,\n extendString: extendString,\n extendUint8Array: extendUint8Array,\n extendBuiltins: extendBuiltins\n };\n //\n // export Base64 to the namespace\n //\n // ES5 is yet to have Object.assign() that may make transpilers unhappy.\n // gBase64.Base64 = Object.assign({}, gBase64);\n gBase64.Base64 = {};\n Object.keys(gBase64).forEach(function (k) { return gBase64.Base64[k] = gBase64[k]; });\n return gBase64;\n}));\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","/**\n * Copyright (c) 2023 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { IDisposable, ITerminalAddon, Terminal } from '@xterm/xterm';\nimport { type IClipboardProvider, ClipboardSelectionType, type IBase64 } from '@xterm/addon-clipboard';\nimport { Base64 as JSBase64 } from 'js-base64';\n\nexport class ClipboardAddon implements ITerminalAddon {\n private _terminal?: Terminal;\n private _disposable?: IDisposable;\n\n constructor(\n private _base64: IBase64 = new Base64(),\n private _provider: IClipboardProvider = new BrowserClipboardProvider()\n ) {}\n\n public activate(terminal: Terminal): void {\n this._terminal = terminal;\n this._disposable = terminal.parser.registerOscHandler(52, data => this._setOrReportClipboard(data));\n }\n\n public dispose(): void {\n return this._disposable?.dispose();\n }\n\n private _readText(sel: ClipboardSelectionType, data: string): void {\n const b64 = this._base64.encodeText(data);\n this._terminal?.input(`\\x1b]52;${sel};${b64}\\x07`, false);\n }\n\n private _setOrReportClipboard(data: string): boolean | Promise<boolean> {\n const args = data.split(';');\n if (args.length < 2) {\n return true;\n }\n\n const pc = args[0] as ClipboardSelectionType;\n const pd = args[1];\n if (pd === '?') {\n const text = this._provider.readText(pc);\n\n // Report clipboard\n if (text instanceof Promise) {\n return text.then((data) => {\n this._readText(pc, data);\n return true;\n });\n }\n\n this._readText(pc, text);\n return true;\n }\n\n // Clear clipboard if text is not a base64 encoded string.\n let text = '';\n try {\n text = this._base64.decodeText(pd);\n } catch {}\n\n\n const result = this._provider.writeText(pc, text);\n if (result instanceof Promise) {\n return result.then(() => true);\n }\n\n return true;\n }\n}\n\nexport class BrowserClipboardProvider implements IClipboardProvider {\n public async readText(selection: ClipboardSelectionType): Promise<string> {\n if (selection !== 'c') {\n return Promise.resolve('');\n }\n return navigator.clipboard.readText();\n }\n\n public async writeText(selection: ClipboardSelectionType, text: string): Promise<void> {\n if (selection !== 'c') {\n return Promise.resolve();\n }\n return navigator.clipboard.writeText(text);\n }\n}\n\nexport class Base64 implements IBase64 {\n public encodeText(data: string): string {\n return JSBase64.encode(data);\n }\n public decodeText(data: string): string {\n const text = JSBase64.decode(data);\n if (!JSBase64.isValid(data) || JSBase64.encode(text) !== data) {\n return '';\n }\n return text;\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","window","g","tab","version","VERSION","_hasBuffer","Buffer","_TD","TextDecoder","undefined","_TE","TextEncoder","b64chs","Array","prototype","slice","call","b64tab","forEach","c","i","b64re","_fromCC","String","fromCharCode","bind","_U8Afrom","Uint8Array","from","it","_mkUriSafe","src","replace","m0","_tidyB64","s","btoaPolyfill","bin","u32","c0","c1","c2","asc","pad","length","charCodeAt","TypeError","substring","_btoa","btoa","toString","_fromUint8Array","u8a","strs","l","push","apply","subarray","join","fromUint8Array","urlsafe","cb_utob","cc","re_utob","utob","u","_encode","encode","encodeURI","re_btou","cb_btou","cccc","offset","btou","b","atobPolyfill","test","u24","r1","r2","charAt","_atob","atob","_toUint8Array","a","split","map","toUint8Array","_unURI","_decode","decode","_noEnum","v","value","enumerable","writable","configurable","extendString","_add","name","body","Object","defineProperty","this","extendUint8Array","gBase64","fromBase64","toBase64","encodeURL","isValid","extendBuiltins","keys","k","Base64","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","globalThis","Function","e","constructor","_base64","_provider","BrowserClipboardProvider","activate","terminal","_terminal","_disposable","parser","registerOscHandler","data","_setOrReportClipboard","dispose","_readText","sel","b64","encodeText","input","args","pc","pd","text","readText","Promise","then","decodeText","result","writeText","selection","resolve","navigator","clipboard"],"sourceRoot":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xterm/addon-clipboard",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "The xterm.js authors",
|
|
6
|
+
"url": "https://xtermjs.org/"
|
|
7
|
+
},
|
|
8
|
+
"main": "lib/addon-clipboard.js",
|
|
9
|
+
"types": "typings/addon-clipboard.d.ts",
|
|
10
|
+
"repository": "https://github.com/xtermjs/xterm.js/tree/master/addons/addon-clipboard",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"terminal",
|
|
14
|
+
"xterm",
|
|
15
|
+
"xterm.js"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "../../node_modules/.bin/tsc -p .",
|
|
19
|
+
"prepackage": "npm run build",
|
|
20
|
+
"package": "../../node_modules/.bin/webpack",
|
|
21
|
+
"prepublishOnly": "npm run package"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@xterm/xterm": "^5.4.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"js-base64": "^3.7.5"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { IDisposable, ITerminalAddon, Terminal } from '@xterm/xterm';
|
|
7
|
+
import { type IClipboardProvider, ClipboardSelectionType, type IBase64 } from '@xterm/addon-clipboard';
|
|
8
|
+
import { Base64 as JSBase64 } from 'js-base64';
|
|
9
|
+
|
|
10
|
+
export class ClipboardAddon implements ITerminalAddon {
|
|
11
|
+
private _terminal?: Terminal;
|
|
12
|
+
private _disposable?: IDisposable;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private _base64: IBase64 = new Base64(),
|
|
16
|
+
private _provider: IClipboardProvider = new BrowserClipboardProvider()
|
|
17
|
+
) {}
|
|
18
|
+
|
|
19
|
+
public activate(terminal: Terminal): void {
|
|
20
|
+
this._terminal = terminal;
|
|
21
|
+
this._disposable = terminal.parser.registerOscHandler(52, data => this._setOrReportClipboard(data));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public dispose(): void {
|
|
25
|
+
return this._disposable?.dispose();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private _readText(sel: ClipboardSelectionType, data: string): void {
|
|
29
|
+
const b64 = this._base64.encodeText(data);
|
|
30
|
+
this._terminal?.input(`\x1b]52;${sel};${b64}\x07`, false);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _setOrReportClipboard(data: string): boolean | Promise<boolean> {
|
|
34
|
+
const args = data.split(';');
|
|
35
|
+
if (args.length < 2) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pc = args[0] as ClipboardSelectionType;
|
|
40
|
+
const pd = args[1];
|
|
41
|
+
if (pd === '?') {
|
|
42
|
+
const text = this._provider.readText(pc);
|
|
43
|
+
|
|
44
|
+
// Report clipboard
|
|
45
|
+
if (text instanceof Promise) {
|
|
46
|
+
return text.then((data) => {
|
|
47
|
+
this._readText(pc, data);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this._readText(pc, text);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Clear clipboard if text is not a base64 encoded string.
|
|
57
|
+
let text = '';
|
|
58
|
+
try {
|
|
59
|
+
text = this._base64.decodeText(pd);
|
|
60
|
+
} catch {}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const result = this._provider.writeText(pc, text);
|
|
64
|
+
if (result instanceof Promise) {
|
|
65
|
+
return result.then(() => true);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class BrowserClipboardProvider implements IClipboardProvider {
|
|
73
|
+
public async readText(selection: ClipboardSelectionType): Promise<string> {
|
|
74
|
+
if (selection !== 'c') {
|
|
75
|
+
return Promise.resolve('');
|
|
76
|
+
}
|
|
77
|
+
return navigator.clipboard.readText();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async writeText(selection: ClipboardSelectionType, text: string): Promise<void> {
|
|
81
|
+
if (selection !== 'c') {
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
return navigator.clipboard.writeText(text);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class Base64 implements IBase64 {
|
|
89
|
+
public encodeText(data: string): string {
|
|
90
|
+
return JSBase64.encode(data);
|
|
91
|
+
}
|
|
92
|
+
public decodeText(data: string): string {
|
|
93
|
+
const text = JSBase64.decode(data);
|
|
94
|
+
if (!JSBase64.isValid(data) || JSBase64.encode(text) !== data) {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
return text;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Terminal, ITerminalAddon } from '@xterm/xterm';
|
|
7
|
+
|
|
8
|
+
declare module '@xterm/addon-clipboard' {
|
|
9
|
+
/**
|
|
10
|
+
* An xterm.js addon that enables accessing the system clipboard from
|
|
11
|
+
* xterm.js.
|
|
12
|
+
*/
|
|
13
|
+
export class ClipboardAddon implements ITerminalAddon {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new clipboard addon.
|
|
16
|
+
*/
|
|
17
|
+
constructor(provider?: IClipboardProvider);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Activates the addon
|
|
21
|
+
* @param terminal The terminal the addon is being loaded in.
|
|
22
|
+
*/
|
|
23
|
+
public activate(terminal: Terminal): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Disposes the addon.
|
|
27
|
+
*/
|
|
28
|
+
public dispose(): void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Clipboard selection type. This is used to specify which selection buffer to
|
|
33
|
+
* read or write to.
|
|
34
|
+
* - SYSTEM `c`: The system clipboard.
|
|
35
|
+
* - PRIMARY `p`: The primary clipboard. This is provided for compatibility
|
|
36
|
+
* with Linux X11.
|
|
37
|
+
*/
|
|
38
|
+
export const enum ClipboardSelectionType {
|
|
39
|
+
SYSTEM = 'c',
|
|
40
|
+
PRIMARY = 'p',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface IBase64 {
|
|
44
|
+
/**
|
|
45
|
+
* Converts a utf-8 string to a base64 string.
|
|
46
|
+
* @param data The utf-8 string to convert to base64 string.
|
|
47
|
+
*/
|
|
48
|
+
encodeText(data: string): string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Converts a base64 string to a utf-8 string.
|
|
52
|
+
* @param data The base64 string to convert to utf-8 string.
|
|
53
|
+
* @throws An error if the input is not valid base64.
|
|
54
|
+
*/
|
|
55
|
+
decodeText(data: string): string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A default Base64 encoding and decoding type.
|
|
60
|
+
**/
|
|
61
|
+
export class Base64 implements IBase64 {
|
|
62
|
+
/**
|
|
63
|
+
* Converts a utf-8 string to a base64 string.
|
|
64
|
+
* @param data The utf-8 string to convert to base64 string.
|
|
65
|
+
*/
|
|
66
|
+
public encodeText(data: string): string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Converts a base64 string to a utf-8 string.
|
|
70
|
+
* @param data The base64 string to convert to utf-8 string.
|
|
71
|
+
* @throws An error if the input is not valid base64.
|
|
72
|
+
*/
|
|
73
|
+
public decodeText(data: string): string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface IClipboardProvider {
|
|
77
|
+
/**
|
|
78
|
+
* Gets the clipboard content.
|
|
79
|
+
* @param selection The clipboard selection to read.
|
|
80
|
+
* @returns A promise that resolves with clipboard selection data.
|
|
81
|
+
*/
|
|
82
|
+
readText(selection: ClipboardSelectionType): string | Promise<string>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sets the clipboard content.
|
|
86
|
+
* @param selection The clipboard selection to set.
|
|
87
|
+
* @param data The clipboard text to write.
|
|
88
|
+
*/
|
|
89
|
+
writeText(selection: ClipboardSelectionType, text: string): void | Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The clipboard provider interface that enables xterm.js to access the system clipboard.
|
|
94
|
+
*/
|
|
95
|
+
export class BrowserClipboardProvider implements IClipboardProvider{
|
|
96
|
+
/**
|
|
97
|
+
* Reads text from the clipboard.
|
|
98
|
+
* @param selection The selection type to read from.
|
|
99
|
+
* @returns A promise that resolves with the text from the clipboard.
|
|
100
|
+
*/
|
|
101
|
+
public readText(selection: ClipboardSelectionType): Promise<string>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Writes text to the clipboard.
|
|
105
|
+
* @param selection The selection type to write to.
|
|
106
|
+
* @param data The text to write to the clipboard.
|
|
107
|
+
* @returns A promise that resolves when the text has been written to the clipboard.
|
|
108
|
+
*/
|
|
109
|
+
public writeText(selection: ClipboardSelectionType, data: string): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
}
|