@xterm/addon-web-links 0.12.0-beta.9 → 0.12.0-beta.90

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.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.WebLinksAddon=t():e.WebLinksAddon=t()}(self,(()=>(()=>{"use strict";var e={6:(e,t)=>{function n(e){try{const t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch(e){return!1}}Object.defineProperty(t,"__esModule",{value:!0}),t.LinkComputer=t.WebLinkProvider=void 0,t.WebLinkProvider=class{constructor(e,t,n,o={}){this._terminal=e,this._regex=t,this._handler=n,this._options=o}provideLinks(e,t){const n=o.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map((e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){const{range:o}=e;this._options.hover(t,n,o)}},e)))}};class o{static computeLink(e,t,r,i){const s=new RegExp(t.source,(t.flags||"")+"g"),[a,c]=o._getWindowedLineStrings(e-1,r),l=a.join("");let d;const p=[];for(;d=s.exec(l);){const e=d[0];if(!n(e))continue;const[t,s]=o._mapStrIdx(r,c,0,d.index),[a,l]=o._mapStrIdx(r,t,s,e.length);if(-1===t||-1===s||-1===a||-1===l)continue;const h={start:{x:s+1,y:t+1},end:{x:l,y:a+1}};p.push({range:h,text:e,activate:i})}return p}static _getWindowedLineStrings(e,t){let n,o=e,r=e,i=0,s="";const a=[];if(n=t.buffer.active.getLine(e)){const e=n.translateToString(!0);if(n.isWrapped&&" "!==e[0]){for(i=0;(n=t.buffer.active.getLine(--o))&&i<2048&&(s=n.translateToString(!0),i+=s.length,a.push(s),n.isWrapped&&-1===s.indexOf(" ")););a.reverse()}for(a.push(e),i=0;(n=t.buffer.active.getLine(++r))&&n.isWrapped&&i<2048&&(s=n.translateToString(!0),i+=s.length,a.push(s),-1===s.indexOf(" ")););}return[a,o]}static _mapStrIdx(e,t,n,o){const r=e.buffer.active,i=r.getNullCell();let s=n;for(;o;){const e=r.getLine(t);if(!e)return[-1,-1];for(let n=s;n<e.length;++n){e.getCell(n,i);const s=i.getChars();if(i.getWidth()&&(o-=s.length||1,n===e.length-1&&""===s)){const e=r.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,i),2===i.getWidth()&&(o+=1))}if(o<0)return[t,n]}t++,s=0}return[t,s]}}t.LinkComputer=o}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.WebLinksAddon=void 0;const t=n(6),r=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function i(e,t){const n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}e.WebLinksAddon=class{constructor(e=i,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;const n=this._options,o=n.urlRegex||r;this._linkProvider=this._terminal.registerLinkProvider(new t.WebLinkProvider(this._terminal,o,this._handler,n))}dispose(){this._linkProvider?.dispose()}}})(),o})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.WebLinksAddon=t():e.WebLinksAddon=t()}(globalThis,(()=>(()=>{"use strict";var e={490:(e,t)=>{function n(e){try{const t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch(e){return!1}}Object.defineProperty(t,"__esModule",{value:!0}),t.LinkComputer=t.WebLinkProvider=void 0,t.WebLinkProvider=class{constructor(e,t,n,o={}){this._terminal=e,this._regex=t,this._handler=n,this._options=o}provideLinks(e,t){const n=o.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map((e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){const{range:o}=e;this._options.hover(t,n,o)}},e)))}};class o{static computeLink(e,t,r,i){const s=new RegExp(t.source,(t.flags||"")+"g"),[a,c]=o._getWindowedLineStrings(e-1,r),l=a.join("");let d;const p=[];for(;d=s.exec(l);){const e=d[0];if(!n(e))continue;const[t,s]=o._mapStrIdx(r,c,0,d.index),[a,l]=o._mapStrIdx(r,t,s,e.length);if(-1===t||-1===s||-1===a||-1===l)continue;const h={start:{x:s+1,y:t+1},end:{x:l,y:a+1}};p.push({range:h,text:e,activate:i})}return p}static _getWindowedLineStrings(e,t){let n,o=e,r=e,i=0,s="";const a=[];if(n=t.buffer.active.getLine(e)){const e=n.translateToString(!0);if(n.isWrapped&&" "!==e[0]){for(i=0;(n=t.buffer.active.getLine(--o))&&i<2048&&(s=n.translateToString(!0),i+=s.length,a.push(s),n.isWrapped&&-1===s.indexOf(" ")););a.reverse()}for(a.push(e),i=0;(n=t.buffer.active.getLine(++r))&&n.isWrapped&&i<2048&&(s=n.translateToString(!0),i+=s.length,a.push(s),-1===s.indexOf(" ")););}return[a,o]}static _mapStrIdx(e,t,n,o){const r=e.buffer.active,i=r.getNullCell();let s=n;for(;o;){const e=r.getLine(t);if(!e)return[-1,-1];for(let n=s;n<e.length;++n){e.getCell(n,i);const s=i.getChars();if(i.getWidth()&&(o-=s.length||1,n===e.length-1&&""===s)){const e=r.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,i),2===i.getWidth()&&(o+=1))}if(o<0)return[t,n]}t++,s=0}return[t,s]}}t.LinkComputer=o}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.WebLinksAddon=void 0;const t=n(490),r=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function i(e,t){const n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}e.WebLinksAddon=class{constructor(e=i,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;const n=this._options,o=n.urlRegex||r;this._linkProvider=this._terminal.registerLinkProvider(new t.WebLinkProvider(this._terminal,o,this._handler,n))}dispose(){this._linkProvider?.dispose()}}})(),o})()));
2
2
  //# sourceMappingURL=addon-web-links.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"addon-web-links.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,MAAM,I,oCCkCT,SAASC,EAAMC,GACb,IACE,MAAMC,EAAM,IAAIC,IAAIF,GACdG,EAAaF,EAAIG,UAAYH,EAAII,SACnC,GAAGJ,EAAIK,aAAaL,EAAII,YAAYJ,EAAIG,YAAYH,EAAIM,OACxDN,EAAII,SACF,GAAGJ,EAAIK,aAAaL,EAAII,YAAYJ,EAAIM,OACxC,GAAGN,EAAIK,aAAaL,EAAIM,OAC9B,OAAOP,EAAUQ,oBAAoBC,WAAWN,EAAWK,oB,CAC3D,MAAOE,GACP,OAAO,C,CAEX,C,yFA1CA,wBAEE,WAAAC,CACmBC,EACAC,EACAC,EACAC,EAAiC,CAAC,GAHlC,KAAAH,UAAAA,EACA,KAAAC,OAAAA,EACA,KAAAC,SAAAA,EACA,KAAAC,SAAAA,CA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AApBA,EAAKM,aACPR,GAAe,G,CAKvB,GAAIA,EAAc,EAChB,MAAO,CAACb,EAAWiB,E,CAGvBjB,IACAJ,EAAQ,C,CAEV,MAAO,CAACI,EAAWJ,EACrB,EA5IF,gB,GCxDI0B,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAazF,QAGrB,IAAIC,EAASqF,EAAyBE,GAAY,CAGjDxF,QAAS,CAAC,GAOX,OAHA2F,EAAoBH,GAAUvF,EAAQA,EAAOD,QAASuF,GAG/CtF,EAAOD,OACf,C,qGCfA,aAaM4F,EAAiB,4EAGvB,SAASC,EAAW3D,EAAmBC,GACrC,MAAM2D,EAAYC,OAAOC,OACzB,GAAIF,EAAW,CACb,IACEA,EAAUG,OAAS,I,CACnB,M,CAGFH,EAAUI,SAASC,KAAOhE,C,MAE1BiE,QAAQC,KAAK,sDAEjB,CAEA,sBAIE,WAAApF,CACUG,EAAqDyE,EACrDxE,EAAiC,CAAC,GADlC,KAAAD,SAAAA,EACA,KAAAC,SAAAA,CAEV,CAEO,QAAAkB,CAASD,GACdV,KAAKV,UAAYoB,EACjB,MAAMgE,EAAU1E,KAAKP,SACfgB,EAAQiE,EAAQC,UAAYX,EAClChE,KAAK4E,cAAgB5E,KAAKV,UAAUuF,qBAAqB,IAAI,EAAAC,gBAAgB9E,KAAKV,UAAWmB,EAAOT,KAAKR,SAAUkF,GACrH,CAEO,OAAAK,GACL/E,KAAK4E,eAAeG,SACtB,E","sources":["webpack://WebLinksAddon/webpack/universalModuleDefinition","webpack://WebLinksAddon/./src/WebLinkProvider.ts","webpack://WebLinksAddon/webpack/bootstrap","webpack://WebLinksAddon/./src/WebLinksAddon.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[\"WebLinksAddon\"] = factory();\n\telse\n\t\troot[\"WebLinksAddon\"] = factory();\n})(self, () => {\nreturn ","/**\n * Copyright (c) 2019 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport { ILinkProvider, ILink, Terminal, IViewportRange, IBufferLine } from '@xterm/xterm';\n\nexport interface ILinkProviderOptions {\n hover?(event: MouseEvent, text: string, location: IViewportRange): void;\n leave?(event: MouseEvent, text: string): void;\n urlRegex?: RegExp;\n}\n\nexport class WebLinkProvider implements ILinkProvider {\n\n constructor(\n private readonly _terminal: Terminal,\n private readonly _regex: RegExp,\n private readonly _handler: (event: MouseEvent, uri: string) => void,\n private readonly _options: ILinkProviderOptions = {}\n ) {\n\n }\n\n public provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void {\n const links = LinkComputer.computeLink(y, this._regex, this._terminal, this._handler);\n callback(this._addCallbacks(links));\n }\n\n private _addCallbacks(links: ILink[]): ILink[] {\n return links.map(link => {\n link.leave = this._options.leave;\n link.hover = (event: MouseEvent, uri: string): void => {\n if (this._options.hover) {\n const { range } = link;\n this._options.hover(event, uri, range);\n }\n };\n return link;\n });\n }\n}\n\nfunction isUrl(urlString: string): boolean {\n try {\n const url = new URL(urlString);\n const parsedBase = url.password && url.username\n ? `${url.protocol}//${url.username}:${url.password}@${url.host}`\n : url.username\n ? `${url.protocol}//${url.username}@${url.host}`\n : `${url.protocol}//${url.host}`;\n return urlString.toLocaleLowerCase().startsWith(parsedBase.toLocaleLowerCase());\n } catch (e) {\n return false;\n }\n}\n\nexport class LinkComputer {\n public static computeLink(y: number, regex: RegExp, terminal: Terminal, activate: (event: MouseEvent, uri: string) => void): ILink[] {\n const rex = new RegExp(regex.source, (regex.flags || '') + 'g');\n\n const [lines, startLineIndex] = LinkComputer._getWindowedLineStrings(y - 1, terminal);\n const line = lines.join('');\n\n let match;\n const result: ILink[] = [];\n\n while (match = rex.exec(line)) {\n const text = match[0];\n\n // check via URL if the matched text would form a proper url\n if (!isUrl(text)) {\n continue;\n }\n\n // map string positions back to buffer positions\n // values are 0-based right side excluding\n const [startY, startX] = LinkComputer._mapStrIdx(terminal, startLineIndex, 0, match.index);\n const [endY, endX] = LinkComputer._mapStrIdx(terminal, startY, startX, text.length);\n\n if (startY === -1 || startX === -1 || endY === -1 || endX === -1) {\n continue;\n }\n\n // range expects values 1-based right side including, thus +1 except for endX\n const range = {\n start: {\n x: startX + 1,\n y: startY + 1\n },\n end: {\n x: endX,\n y: endY + 1\n }\n };\n\n result.push({ range, text, activate });\n }\n\n return result;\n }\n\n /**\n * Get wrapped content lines for the current line index.\n * The top/bottom line expansion stops at whitespaces or length > 2048.\n * Returns an array with line strings and the top line index.\n *\n * NOTE: We pull line strings with trimRight=true on purpose to make sure\n * to correctly match urls with early wrapped wide chars. This corrupts the string index\n * for 1:1 backmapping to buffer positions, thus needs an additional correction in _mapStrIdx.\n */\n private static _getWindowedLineStrings(lineIndex: number, terminal: Terminal): [string[], number] {\n let line: IBufferLine | undefined;\n let topIdx = lineIndex;\n let bottomIdx = lineIndex;\n let length = 0;\n let content = '';\n const lines: string[] = [];\n\n if ((line = terminal.buffer.active.getLine(lineIndex))) {\n const currentContent = line.translateToString(true);\n\n // expand top, stop on whitespaces or length > 2048\n if (line.isWrapped && currentContent[0] !== ' ') {\n length = 0;\n while ((line = terminal.buffer.active.getLine(--topIdx)) && length < 2048) {\n content = line.translateToString(true);\n length += content.length;\n lines.push(content);\n if (!line.isWrapped || content.indexOf(' ') !== -1) {\n break;\n }\n }\n lines.reverse();\n }\n\n // append current line\n lines.push(currentContent);\n\n // expand bottom, stop on whitespaces or length > 2048\n length = 0;\n while ((line = terminal.buffer.active.getLine(++bottomIdx)) && line.isWrapped && length < 2048) {\n content = line.translateToString(true);\n length += content.length;\n lines.push(content);\n if (content.indexOf(' ') !== -1) {\n break;\n }\n }\n }\n return [lines, topIdx];\n }\n\n /**\n * Map a string index back to buffer positions.\n * Returns buffer position as [lineIndex, columnIndex] 0-based,\n * or [-1, -1] in case the lookup ran into a non-existing line.\n */\n private static _mapStrIdx(terminal: Terminal, lineIndex: number, rowIndex: number, stringIndex: number): [number, number] {\n const buf = terminal.buffer.active;\n const cell = buf.getNullCell();\n let start = rowIndex;\n while (stringIndex) {\n const line = buf.getLine(lineIndex);\n if (!line) {\n return [-1, -1];\n }\n for (let i = start; i < line.length; ++i) {\n line.getCell(i, cell);\n const chars = cell.getChars();\n const width = cell.getWidth();\n if (width) {\n stringIndex -= chars.length || 1;\n\n // correct stringIndex for early wrapped wide chars:\n // - currently only happens at last cell\n // - cells to the right are reset with chars='' and width=1 in InputHandler.print\n // - follow-up line must be wrapped and contain wide char at first cell\n // --> if all these conditions are met, correct stringIndex by +1\n if (i === line.length - 1 && chars === '') {\n const line = buf.getLine(lineIndex + 1);\n if (line && line.isWrapped) {\n line.getCell(0, cell);\n if (cell.getWidth() === 2) {\n stringIndex += 1;\n }\n }\n }\n }\n if (stringIndex < 0) {\n return [lineIndex, i];\n }\n }\n lineIndex++;\n start = 0;\n }\n return [lineIndex, start];\n }\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](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","/**\n * Copyright (c) 2019 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';\nimport type { WebLinksAddon as IWebLinksApi } from '@xterm/addon-web-links';\nimport { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';\n\n// consider everthing starting with http:// or https://\n// up to first whitespace, `\"` or `'` as url\n// NOTE: The repeated end clause is needed to not match a dangling `:`\n// resembling the old (...)*([^:\"\\'\\\\s]) final path clause\n// additionally exclude early + final:\n// - unsafe from rfc3986: !*'()\n// - unsafe chars from rfc1738: {}|\\^~[]` (minus [] as we need them for ipv6 adresses, also allow ~)\n// also exclude as finals:\n// - final interpunction like ,.!?\n// - any sort of brackets <>()[]{} (not spec conform, but often used to enclose urls)\n// - unsafe chars from rfc1738: {}|\\^~[]`\nconst strictUrlRegex = /(https?|HTTPS?):[/]{2}[^\\s\"'!*(){}|\\\\\\^<>`]*[^\\s\"':,.!?{}|\\\\\\^~\\[\\]`()<>]/;\n\n\nfunction handleLink(event: MouseEvent, uri: string): void {\n const newWindow = window.open();\n if (newWindow) {\n try {\n newWindow.opener = null;\n } catch {\n // no-op, Electron can throw\n }\n newWindow.location.href = uri;\n } else {\n console.warn('Opening link blocked as opener could not be cleared');\n }\n}\n\nexport class WebLinksAddon implements ITerminalAddon , IWebLinksApi {\n private _terminal: Terminal | undefined;\n private _linkProvider: IDisposable | undefined;\n\n constructor(\n private _handler: (event: MouseEvent, uri: string) => void = handleLink,\n private _options: ILinkProviderOptions = {}\n ) {\n }\n\n public activate(terminal: Terminal): void {\n this._terminal = terminal;\n const options = this._options as ILinkProviderOptions;\n const regex = options.urlRegex || strictUrlRegex;\n this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, regex, this._handler, options));\n }\n\n public dispose(): void {\n this._linkProvider?.dispose();\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","isUrl","urlString","url","URL","parsedBase","password","username","protocol","host","toLocaleLowerCase","startsWith","e","constructor","_terminal","_regex","_handler","_options","provideLinks","y","callback","links","LinkComputer","computeLink","this","_addCallbacks","map","link","leave","hover","event","uri","range","regex","terminal","activate","rex","RegExp","source","flags","lines","startLineIndex","_getWindowedLineStrings","line","join","match","result","exec","text","startY","startX","_mapStrIdx","index","endY","endX","length","start","x","end","push","lineIndex","topIdx","bottomIdx","content","buffer","active","getLine","currentContent","translateToString","isWrapped","indexOf","reverse","rowIndex","stringIndex","buf","cell","getNullCell","i","getCell","chars","getChars","getWidth","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","strictUrlRegex","handleLink","newWindow","window","open","opener","location","href","console","warn","options","urlRegex","_linkProvider","registerLinkProvider","WebLinkProvider","dispose"],"sourceRoot":""}
1
+ {"version":3,"file":"addon-web-links.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,YAAY,I,sCCkCf,SAASC,EAAMC,GACb,IACE,MAAMC,EAAM,IAAIC,IAAIF,GACdG,EAAaF,EAAIG,UAAYH,EAAII,SACnC,GAAGJ,EAAIK,aAAaL,EAAII,YAAYJ,EAAIG,YAAYH,EAAIM,OACxDN,EAAII,SACF,GAAGJ,EAAIK,aAAaL,EAAII,YAAYJ,EAAIM,OACxC,GAAGN,EAAIK,aAAaL,EAAIM,OAC9B,OAAOP,EAAUQ,oBAAoBC,WAAWN,EAAWK,oBAC7D,CAAE,MAAOE,GACP,OAAO,CACT,CACF,C,yFA1CA,wBAEE,WAAAC,CACmBC,EACAC,EACAC,EACAC,EAAiC,CAAC,GAHlC,KAAAH,UAAAA,EACA,KAAAC,OAAAA,EACA,KAAAC,SAAAA,EACA,KAAAC,SAAAA,CAGnB,CAEO,YAAAC,CAAaC,EAAWC,GAC7B,MAAMC,EAAQC,EAAaC,YAAYJ,EAAGK,KAAKT,OAAQS,KAAKV,UAAWU,KAAKR,UAC5EI,EAASI,KAAKC,cAAcJ,GAC9B,CAEQ,aAAAI,CAAcJ,GACpB,OAAOA,EAAMK,KAAIC,IACfA,EAAKC,MAAQ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C,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAazF,QAGrB,IAAIC,EAASqF,EAAyBE,GAAY,CAGjDxF,QAAS,CAAC,GAOX,OAHA2F,EAAoBH,GAAUvF,EAAQA,EAAOD,QAASuF,GAG/CtF,EAAOD,OACf,C,qGCfA,eAaM4F,EAAiB,4EAGvB,SAASC,EAAW3D,EAAmBC,GACrC,MAAM2D,EAAYC,OAAOC,OACzB,GAAIF,EAAW,CACb,IACEA,EAAUG,OAAS,IACrB,CAAE,MAEF,CACAH,EAAUI,SAASC,KAAOhE,CAC5B,MACEiE,QAAQC,KAAK,sDAEjB,CAEA,sBAIE,WAAApF,CACUG,EAAqDyE,EACrDxE,EAAiC,CAAC,GADlC,KAAAD,SAAAA,EACA,KAAAC,SAAAA,CAEV,CAEO,QAAAkB,CAASD,GACdV,KAAKV,UAAYoB,EACjB,MAAMgE,EAAU1E,KAAKP,SACfgB,EAAQiE,EAAQC,UAAYX,EAClChE,KAAK4E,cAAgB5E,KAAKV,UAAUuF,qBAAqB,IAAI,EAAAC,gBAAgB9E,KAAKV,UAAWmB,EAAOT,KAAKR,SAAUkF,GACrH,CAEO,OAAAK,GACL/E,KAAK4E,eAAeG,SACtB,E","sources":["webpack://WebLinksAddon/webpack/universalModuleDefinition","webpack://WebLinksAddon/./src/WebLinkProvider.ts","webpack://WebLinksAddon/webpack/bootstrap","webpack://WebLinksAddon/./src/WebLinksAddon.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[\"WebLinksAddon\"] = factory();\n\telse\n\t\troot[\"WebLinksAddon\"] = factory();\n})(globalThis, () => {\nreturn ","/**\n * Copyright (c) 2019 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport { ILinkProvider, ILink, Terminal, IViewportRange, IBufferLine } from '@xterm/xterm';\n\nexport interface ILinkProviderOptions {\n hover?(event: MouseEvent, text: string, location: IViewportRange): void;\n leave?(event: MouseEvent, text: string): void;\n urlRegex?: RegExp;\n}\n\nexport class WebLinkProvider implements ILinkProvider {\n\n constructor(\n private readonly _terminal: Terminal,\n private readonly _regex: RegExp,\n private readonly _handler: (event: MouseEvent, uri: string) => void,\n private readonly _options: ILinkProviderOptions = {}\n ) {\n\n }\n\n public provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void {\n const links = LinkComputer.computeLink(y, this._regex, this._terminal, this._handler);\n callback(this._addCallbacks(links));\n }\n\n private _addCallbacks(links: ILink[]): ILink[] {\n return links.map(link => {\n link.leave = this._options.leave;\n link.hover = (event: MouseEvent, uri: string): void => {\n if (this._options.hover) {\n const { range } = link;\n this._options.hover(event, uri, range);\n }\n };\n return link;\n });\n }\n}\n\nfunction isUrl(urlString: string): boolean {\n try {\n const url = new URL(urlString);\n const parsedBase = url.password && url.username\n ? `${url.protocol}//${url.username}:${url.password}@${url.host}`\n : url.username\n ? `${url.protocol}//${url.username}@${url.host}`\n : `${url.protocol}//${url.host}`;\n return urlString.toLocaleLowerCase().startsWith(parsedBase.toLocaleLowerCase());\n } catch (e) {\n return false;\n }\n}\n\nexport class LinkComputer {\n public static computeLink(y: number, regex: RegExp, terminal: Terminal, activate: (event: MouseEvent, uri: string) => void): ILink[] {\n const rex = new RegExp(regex.source, (regex.flags || '') + 'g');\n\n const [lines, startLineIndex] = LinkComputer._getWindowedLineStrings(y - 1, terminal);\n const line = lines.join('');\n\n let match;\n const result: ILink[] = [];\n\n while (match = rex.exec(line)) {\n const text = match[0];\n\n // check via URL if the matched text would form a proper url\n if (!isUrl(text)) {\n continue;\n }\n\n // map string positions back to buffer positions\n // values are 0-based right side excluding\n const [startY, startX] = LinkComputer._mapStrIdx(terminal, startLineIndex, 0, match.index);\n const [endY, endX] = LinkComputer._mapStrIdx(terminal, startY, startX, text.length);\n\n if (startY === -1 || startX === -1 || endY === -1 || endX === -1) {\n continue;\n }\n\n // range expects values 1-based right side including, thus +1 except for endX\n const range = {\n start: {\n x: startX + 1,\n y: startY + 1\n },\n end: {\n x: endX,\n y: endY + 1\n }\n };\n\n result.push({ range, text, activate });\n }\n\n return result;\n }\n\n /**\n * Get wrapped content lines for the current line index.\n * The top/bottom line expansion stops at whitespaces or length > 2048.\n * Returns an array with line strings and the top line index.\n *\n * NOTE: We pull line strings with trimRight=true on purpose to make sure\n * to correctly match urls with early wrapped wide chars. This corrupts the string index\n * for 1:1 backmapping to buffer positions, thus needs an additional correction in _mapStrIdx.\n */\n private static _getWindowedLineStrings(lineIndex: number, terminal: Terminal): [string[], number] {\n let line: IBufferLine | undefined;\n let topIdx = lineIndex;\n let bottomIdx = lineIndex;\n let length = 0;\n let content = '';\n const lines: string[] = [];\n\n if ((line = terminal.buffer.active.getLine(lineIndex))) {\n const currentContent = line.translateToString(true);\n\n // expand top, stop on whitespaces or length > 2048\n if (line.isWrapped && currentContent[0] !== ' ') {\n length = 0;\n while ((line = terminal.buffer.active.getLine(--topIdx)) && length < 2048) {\n content = line.translateToString(true);\n length += content.length;\n lines.push(content);\n if (!line.isWrapped || content.indexOf(' ') !== -1) {\n break;\n }\n }\n lines.reverse();\n }\n\n // append current line\n lines.push(currentContent);\n\n // expand bottom, stop on whitespaces or length > 2048\n length = 0;\n while ((line = terminal.buffer.active.getLine(++bottomIdx)) && line.isWrapped && length < 2048) {\n content = line.translateToString(true);\n length += content.length;\n lines.push(content);\n if (content.indexOf(' ') !== -1) {\n break;\n }\n }\n }\n return [lines, topIdx];\n }\n\n /**\n * Map a string index back to buffer positions.\n * Returns buffer position as [lineIndex, columnIndex] 0-based,\n * or [-1, -1] in case the lookup ran into a non-existing line.\n */\n private static _mapStrIdx(terminal: Terminal, lineIndex: number, rowIndex: number, stringIndex: number): [number, number] {\n const buf = terminal.buffer.active;\n const cell = buf.getNullCell();\n let start = rowIndex;\n while (stringIndex) {\n const line = buf.getLine(lineIndex);\n if (!line) {\n return [-1, -1];\n }\n for (let i = start; i < line.length; ++i) {\n line.getCell(i, cell);\n const chars = cell.getChars();\n const width = cell.getWidth();\n if (width) {\n stringIndex -= chars.length || 1;\n\n // correct stringIndex for early wrapped wide chars:\n // - currently only happens at last cell\n // - cells to the right are reset with chars='' and width=1 in InputHandler.print\n // - follow-up line must be wrapped and contain wide char at first cell\n // --> if all these conditions are met, correct stringIndex by +1\n if (i === line.length - 1 && chars === '') {\n const line = buf.getLine(lineIndex + 1);\n if (line && line.isWrapped) {\n line.getCell(0, cell);\n if (cell.getWidth() === 2) {\n stringIndex += 1;\n }\n }\n }\n }\n if (stringIndex < 0) {\n return [lineIndex, i];\n }\n }\n lineIndex++;\n start = 0;\n }\n return [lineIndex, start];\n }\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](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","/**\n * Copyright (c) 2019 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';\nimport type { WebLinksAddon as IWebLinksApi } from '@xterm/addon-web-links';\nimport { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';\n\n// consider everthing starting with http:// or https://\n// up to first whitespace, `\"` or `'` as url\n// NOTE: The repeated end clause is needed to not match a dangling `:`\n// resembling the old (...)*([^:\"\\'\\\\s]) final path clause\n// additionally exclude early + final:\n// - unsafe from rfc3986: !*'()\n// - unsafe chars from rfc1738: {}|\\^~[]` (minus [] as we need them for ipv6 adresses, also allow ~)\n// also exclude as finals:\n// - final interpunction like ,.!?\n// - any sort of brackets <>()[]{} (not spec conform, but often used to enclose urls)\n// - unsafe chars from rfc1738: {}|\\^~[]`\nconst strictUrlRegex = /(https?|HTTPS?):[/]{2}[^\\s\"'!*(){}|\\\\\\^<>`]*[^\\s\"':,.!?{}|\\\\\\^~\\[\\]`()<>]/;\n\n\nfunction handleLink(event: MouseEvent, uri: string): void {\n const newWindow = window.open();\n if (newWindow) {\n try {\n newWindow.opener = null;\n } catch {\n // no-op, Electron can throw\n }\n newWindow.location.href = uri;\n } else {\n console.warn('Opening link blocked as opener could not be cleared');\n }\n}\n\nexport class WebLinksAddon implements ITerminalAddon , IWebLinksApi {\n private _terminal: Terminal | undefined;\n private _linkProvider: IDisposable | undefined;\n\n constructor(\n private _handler: (event: MouseEvent, uri: string) => void = handleLink,\n private _options: ILinkProviderOptions = {}\n ) {\n }\n\n public activate(terminal: Terminal): void {\n this._terminal = terminal;\n const options = this._options as ILinkProviderOptions;\n const regex = options.urlRegex || strictUrlRegex;\n this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, regex, this._handler, options));\n }\n\n public dispose(): void {\n this._linkProvider?.dispose();\n }\n}\n"],"names":["root","factory","exports","module","define","amd","globalThis","isUrl","urlString","url","URL","parsedBase","password","username","protocol","host","toLocaleLowerCase","startsWith","e","constructor","_terminal","_regex","_handler","_options","provideLinks","y","callback","links","LinkComputer","computeLink","this","_addCallbacks","map","link","leave","hover","event","uri","range","regex","terminal","activate","rex","RegExp","source","flags","lines","startLineIndex","_getWindowedLineStrings","line","join","match","result","exec","text","startY","startX","_mapStrIdx","index","endY","endX","length","start","x","end","push","lineIndex","topIdx","bottomIdx","content","buffer","active","getLine","currentContent","translateToString","isWrapped","indexOf","reverse","rowIndex","stringIndex","buf","cell","getNullCell","i","getCell","chars","getChars","getWidth","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","strictUrlRegex","handleLink","newWindow","window","open","opener","location","href","console","warn","options","urlRegex","_linkProvider","registerLinkProvider","WebLinkProvider","dispose"],"sourceRoot":""}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ *
5
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
6
+ * @license MIT
7
+ *
8
+ * Originally forked from (with the author's permission):
9
+ * Fabrice Bellard's javascript vt100 for jslinux:
10
+ * http://bellard.org/jslinux/
11
+ * Copyright (c) 2011 Fabrice Bellard
12
+ */
13
+ /*---------------------------------------------------------------------------------------------
14
+ * Copyright (c) Microsoft Corporation. All rights reserved.
15
+ * Licensed under the MIT License. See License.txt in the project root for license information.
16
+ *--------------------------------------------------------------------------------------------*/
17
+ var v=class{constructor(e,t,n,o={}){this._terminal=e;this._regex=t;this._handler=n;this._options=o}provideLinks(e,t){let n=g.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map(t=>(t.leave=this._options.leave,t.hover=(n,o)=>{if(this._options.hover){let{range:p}=t;this._options.hover(n,o,p)}},t))}};function k(l){try{let e=new URL(l),t=e.password&&e.username?`${e.protocol}//${e.username}:${e.password}@${e.host}`:e.username?`${e.protocol}//${e.username}@${e.host}`:`${e.protocol}//${e.host}`;return l.toLocaleLowerCase().startsWith(t.toLocaleLowerCase())}catch{return!1}}var g=class l{static computeLink(e,t,n,o){let p=new RegExp(t.source,(t.flags||"")+"g"),[i,r]=l._getWindowedLineStrings(e-1,n),s=i.join(""),a,d=[];for(;a=p.exec(s);){let u=a[0];if(!k(u))continue;let[c,h]=l._mapStrIdx(n,r,0,a.index),[m,f]=l._mapStrIdx(n,c,h,u.length);if(c===-1||h===-1||m===-1||f===-1)continue;let b={start:{x:h+1,y:c+1},end:{x:f,y:m+1}};d.push({range:b,text:u,activate:o})}return d}static _getWindowedLineStrings(e,t){let n,o=e,p=e,i=0,r="",s=[];if(n=t.buffer.active.getLine(e)){let a=n.translateToString(!0);if(n.isWrapped&&a[0]!==" "){for(i=0;(n=t.buffer.active.getLine(--o))&&i<2048&&(r=n.translateToString(!0),i+=r.length,s.push(r),!(!n.isWrapped||r.indexOf(" ")!==-1)););s.reverse()}for(s.push(a),i=0;(n=t.buffer.active.getLine(++p))&&n.isWrapped&&i<2048&&(r=n.translateToString(!0),i+=r.length,s.push(r),r.indexOf(" ")===-1););}return[s,o]}static _mapStrIdx(e,t,n,o){let p=e.buffer.active,i=p.getNullCell(),r=n;for(;o;){let s=p.getLine(t);if(!s)return[-1,-1];for(let a=r;a<s.length;++a){s.getCell(a,i);let d=i.getChars();if(i.getWidth()&&(o-=d.length||1,a===s.length-1&&d==="")){let c=p.getLine(t+1);c&&c.isWrapped&&(c.getCell(0,i),i.getWidth()===2&&(o+=1))}if(o<0)return[t,a]}t++,r=0}return[t,r]}};var _=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function w(l,e){let t=window.open();if(t){try{t.opener=null}catch{}t.location.href=e}else console.warn("Opening link blocked as opener could not be cleared")}var L=class{constructor(e=w,t={}){this._handler=e;this._options=t}activate(e){this._terminal=e;let t=this._options,n=t.urlRegex||_;this._linkProvider=this._terminal.registerLinkProvider(new v(this._terminal,n,this._handler,t))}dispose(){this._linkProvider?.dispose()}};export{L as WebLinksAddon};
18
+ //# sourceMappingURL=addon-web-links.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/WebLinkProvider.ts", "../src/WebLinksAddon.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) 2019 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport { ILinkProvider, ILink, Terminal, IViewportRange, IBufferLine } from '@xterm/xterm';\n\nexport interface ILinkProviderOptions {\n hover?(event: MouseEvent, text: string, location: IViewportRange): void;\n leave?(event: MouseEvent, text: string): void;\n urlRegex?: RegExp;\n}\n\nexport class WebLinkProvider implements ILinkProvider {\n\n constructor(\n private readonly _terminal: Terminal,\n private readonly _regex: RegExp,\n private readonly _handler: (event: MouseEvent, uri: string) => void,\n private readonly _options: ILinkProviderOptions = {}\n ) {\n\n }\n\n public provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void {\n const links = LinkComputer.computeLink(y, this._regex, this._terminal, this._handler);\n callback(this._addCallbacks(links));\n }\n\n private _addCallbacks(links: ILink[]): ILink[] {\n return links.map(link => {\n link.leave = this._options.leave;\n link.hover = (event: MouseEvent, uri: string): void => {\n if (this._options.hover) {\n const { range } = link;\n this._options.hover(event, uri, range);\n }\n };\n return link;\n });\n }\n}\n\nfunction isUrl(urlString: string): boolean {\n try {\n const url = new URL(urlString);\n const parsedBase = url.password && url.username\n ? `${url.protocol}//${url.username}:${url.password}@${url.host}`\n : url.username\n ? `${url.protocol}//${url.username}@${url.host}`\n : `${url.protocol}//${url.host}`;\n return urlString.toLocaleLowerCase().startsWith(parsedBase.toLocaleLowerCase());\n } catch (e) {\n return false;\n }\n}\n\nexport class LinkComputer {\n public static computeLink(y: number, regex: RegExp, terminal: Terminal, activate: (event: MouseEvent, uri: string) => void): ILink[] {\n const rex = new RegExp(regex.source, (regex.flags || '') + 'g');\n\n const [lines, startLineIndex] = LinkComputer._getWindowedLineStrings(y - 1, terminal);\n const line = lines.join('');\n\n let match;\n const result: ILink[] = [];\n\n while (match = rex.exec(line)) {\n const text = match[0];\n\n // check via URL if the matched text would form a proper url\n if (!isUrl(text)) {\n continue;\n }\n\n // map string positions back to buffer positions\n // values are 0-based right side excluding\n const [startY, startX] = LinkComputer._mapStrIdx(terminal, startLineIndex, 0, match.index);\n const [endY, endX] = LinkComputer._mapStrIdx(terminal, startY, startX, text.length);\n\n if (startY === -1 || startX === -1 || endY === -1 || endX === -1) {\n continue;\n }\n\n // range expects values 1-based right side including, thus +1 except for endX\n const range = {\n start: {\n x: startX + 1,\n y: startY + 1\n },\n end: {\n x: endX,\n y: endY + 1\n }\n };\n\n result.push({ range, text, activate });\n }\n\n return result;\n }\n\n /**\n * Get wrapped content lines for the current line index.\n * The top/bottom line expansion stops at whitespaces or length > 2048.\n * Returns an array with line strings and the top line index.\n *\n * NOTE: We pull line strings with trimRight=true on purpose to make sure\n * to correctly match urls with early wrapped wide chars. This corrupts the string index\n * for 1:1 backmapping to buffer positions, thus needs an additional correction in _mapStrIdx.\n */\n private static _getWindowedLineStrings(lineIndex: number, terminal: Terminal): [string[], number] {\n let line: IBufferLine | undefined;\n let topIdx = lineIndex;\n let bottomIdx = lineIndex;\n let length = 0;\n let content = '';\n const lines: string[] = [];\n\n if ((line = terminal.buffer.active.getLine(lineIndex))) {\n const currentContent = line.translateToString(true);\n\n // expand top, stop on whitespaces or length > 2048\n if (line.isWrapped && currentContent[0] !== ' ') {\n length = 0;\n while ((line = terminal.buffer.active.getLine(--topIdx)) && length < 2048) {\n content = line.translateToString(true);\n length += content.length;\n lines.push(content);\n if (!line.isWrapped || content.indexOf(' ') !== -1) {\n break;\n }\n }\n lines.reverse();\n }\n\n // append current line\n lines.push(currentContent);\n\n // expand bottom, stop on whitespaces or length > 2048\n length = 0;\n while ((line = terminal.buffer.active.getLine(++bottomIdx)) && line.isWrapped && length < 2048) {\n content = line.translateToString(true);\n length += content.length;\n lines.push(content);\n if (content.indexOf(' ') !== -1) {\n break;\n }\n }\n }\n return [lines, topIdx];\n }\n\n /**\n * Map a string index back to buffer positions.\n * Returns buffer position as [lineIndex, columnIndex] 0-based,\n * or [-1, -1] in case the lookup ran into a non-existing line.\n */\n private static _mapStrIdx(terminal: Terminal, lineIndex: number, rowIndex: number, stringIndex: number): [number, number] {\n const buf = terminal.buffer.active;\n const cell = buf.getNullCell();\n let start = rowIndex;\n while (stringIndex) {\n const line = buf.getLine(lineIndex);\n if (!line) {\n return [-1, -1];\n }\n for (let i = start; i < line.length; ++i) {\n line.getCell(i, cell);\n const chars = cell.getChars();\n const width = cell.getWidth();\n if (width) {\n stringIndex -= chars.length || 1;\n\n // correct stringIndex for early wrapped wide chars:\n // - currently only happens at last cell\n // - cells to the right are reset with chars='' and width=1 in InputHandler.print\n // - follow-up line must be wrapped and contain wide char at first cell\n // --> if all these conditions are met, correct stringIndex by +1\n if (i === line.length - 1 && chars === '') {\n const line = buf.getLine(lineIndex + 1);\n if (line && line.isWrapped) {\n line.getCell(0, cell);\n if (cell.getWidth() === 2) {\n stringIndex += 1;\n }\n }\n }\n }\n if (stringIndex < 0) {\n return [lineIndex, i];\n }\n }\n lineIndex++;\n start = 0;\n }\n return [lineIndex, start];\n }\n}\n", "/**\n * Copyright (c) 2019 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';\nimport type { WebLinksAddon as IWebLinksApi } from '@xterm/addon-web-links';\nimport { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';\n\n// consider everthing starting with http:// or https://\n// up to first whitespace, `\"` or `'` as url\n// NOTE: The repeated end clause is needed to not match a dangling `:`\n// resembling the old (...)*([^:\"\\'\\\\s]) final path clause\n// additionally exclude early + final:\n// - unsafe from rfc3986: !*'()\n// - unsafe chars from rfc1738: {}|\\^~[]` (minus [] as we need them for ipv6 adresses, also allow ~)\n// also exclude as finals:\n// - final interpunction like ,.!?\n// - any sort of brackets <>()[]{} (not spec conform, but often used to enclose urls)\n// - unsafe chars from rfc1738: {}|\\^~[]`\nconst strictUrlRegex = /(https?|HTTPS?):[/]{2}[^\\s\"'!*(){}|\\\\\\^<>`]*[^\\s\"':,.!?{}|\\\\\\^~\\[\\]`()<>]/;\n\n\nfunction handleLink(event: MouseEvent, uri: string): void {\n const newWindow = window.open();\n if (newWindow) {\n try {\n newWindow.opener = null;\n } catch {\n // no-op, Electron can throw\n }\n newWindow.location.href = uri;\n } else {\n console.warn('Opening link blocked as opener could not be cleared');\n }\n}\n\nexport class WebLinksAddon implements ITerminalAddon , IWebLinksApi {\n private _terminal: Terminal | undefined;\n private _linkProvider: IDisposable | undefined;\n\n constructor(\n private _handler: (event: MouseEvent, uri: string) => void = handleLink,\n private _options: ILinkProviderOptions = {}\n ) {\n }\n\n public activate(terminal: Terminal): void {\n this._terminal = terminal;\n const options = this._options as ILinkProviderOptions;\n const regex = options.urlRegex || strictUrlRegex;\n this._linkProvider = this._terminal.registerLinkProvider(new WebLinkProvider(this._terminal, regex, this._handler, options));\n }\n\n public dispose(): void {\n this._linkProvider?.dispose();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAaO,IAAMA,EAAN,KAA+C,CAEpD,YACmBC,EACAC,EACAC,EACAC,EAAiC,CAAC,EACnD,CAJiB,eAAAH,EACA,YAAAC,EACA,cAAAC,EACA,cAAAC,CAGnB,CAEO,aAAaC,EAAWC,EAAsD,CACnF,IAAMC,EAAQC,EAAa,YAAYH,EAAG,KAAK,OAAQ,KAAK,UAAW,KAAK,QAAQ,EACpFC,EAAS,KAAK,cAAcC,CAAK,CAAC,CACpC,CAEQ,cAAcA,EAAyB,CAC7C,OAAOA,EAAM,IAAIE,IACfA,EAAK,MAAQ,KAAK,SAAS,MAC3BA,EAAK,MAAQ,CAACC,EAAmBC,IAAsB,CACrD,GAAI,KAAK,SAAS,MAAO,CACvB,GAAM,CAAE,MAAAC,CAAM,EAAIH,EAClB,KAAK,SAAS,MAAMC,EAAOC,EAAKC,CAAK,CACvC,CACF,EACOH,EACR,CACH,CACF,EAEA,SAASI,EAAMC,EAA4B,CACzC,GAAI,CACF,IAAMC,EAAM,IAAI,IAAID,CAAS,EACvBE,EAAaD,EAAI,UAAYA,EAAI,SACnC,GAAGA,EAAI,QAAQ,KAAKA,EAAI,QAAQ,IAAIA,EAAI,QAAQ,IAAIA,EAAI,IAAI,GAC5DA,EAAI,SACF,GAAGA,EAAI,QAAQ,KAAKA,EAAI,QAAQ,IAAIA,EAAI,IAAI,GAC5C,GAAGA,EAAI,QAAQ,KAAKA,EAAI,IAAI,GAClC,OAAOD,EAAU,kBAAkB,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CAAK,CAC1B,CACF,EClLA,IAAMG,EAAiB,4EAGvB,SAASC,EAAWC,EAAmBC,EAAmB,CACxD,IAAMC,EAAY,OAAO,KAAK,EAC9B,GAAIA,EAAW,CACb,GAAI,CACFA,EAAU,OAAS,IACrB,MAAQ,CAER,CACAA,EAAU,SAAS,KAAOD,CAC5B,MACE,QAAQ,KAAK,qDAAqD,CAEtE,CAEO,IAAME,EAAN,KAA6D,CAIlE,YACUC,EAAqDL,EACrDM,EAAiC,CAAC,EAC1C,CAFQ,cAAAD,EACA,cAAAC,CAEV,CAEO,SAASC,EAA0B,CACxC,KAAK,UAAYA,EACjB,IAAMC,EAAU,KAAK,SACfC,EAAQD,EAAQ,UAAYT,EAClC,KAAK,cAAgB,KAAK,UAAU,qBAAqB,IAAIW,EAAgB,KAAK,UAAWD,EAAO,KAAK,SAAUD,CAAO,CAAC,CAC7H,CAEO,SAAgB,CACrB,KAAK,eAAe,QAAQ,CAC9B,CACF",
6
+ "names": ["WebLinkProvider", "_terminal", "_regex", "_handler", "_options", "y", "callback", "links", "LinkComputer", "link", "event", "uri", "range", "isUrl", "urlString", "url", "parsedBase", "_LinkComputer", "regex", "terminal", "activate", "rex", "lines", "startLineIndex", "line", "match", "result", "text", "startY", "startX", "endY", "endX", "lineIndex", "topIdx", "bottomIdx", "length", "content", "currentContent", "rowIndex", "stringIndex", "buf", "cell", "start", "i", "chars", "strictUrlRegex", "handleLink", "event", "uri", "newWindow", "WebLinksAddon", "_handler", "_options", "terminal", "options", "regex", "WebLinkProvider"]
7
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@xterm/addon-web-links",
3
- "version": "0.12.0-beta.9",
3
+ "version": "0.12.0-beta.90",
4
4
  "author": {
5
5
  "name": "The xterm.js authors",
6
6
  "url": "https://xtermjs.org/"
7
7
  },
8
8
  "main": "lib/addon-web-links.js",
9
+ "module": "lib/addon-web-links.mjs",
9
10
  "types": "typings/addon-web-links.d.ts",
10
11
  "repository": "https://github.com/xtermjs/xterm.js/tree/master/addons/addon-web-links",
11
12
  "license": "MIT",
@@ -18,9 +19,11 @@
18
19
  "build": "../../node_modules/.bin/tsc -p .",
19
20
  "prepackage": "npm run build",
20
21
  "package": "../../node_modules/.bin/webpack",
21
- "prepublishOnly": "npm run package"
22
+ "prepublishOnly": "npm run package",
23
+ "start": "node ../../demo/start"
22
24
  },
23
25
  "peerDependencies": {
24
- "@xterm/xterm": "^5.0.0"
25
- }
26
+ "@xterm/xterm": "^5.6.0-beta.90"
27
+ },
28
+ "commit": "c21f32d012fb23b20a3d3de46e109ad9295fc1a4"
26
29
  }