view-sidebar.js 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214
  1. var sidebar = sidebar || {};
  2. var base = base || require('./base');
  3. sidebar.Sidebar = class {
  4. constructor(host, id) {
  5. this._host = host;
  6. this._id = id ? ('-' + id) : '';
  7. this._stack = [];
  8. this._closeSidebarHandler = () => {
  9. this._pop();
  10. };
  11. this._closeSidebarKeyDownHandler = (e) => {
  12. if (e.keyCode == 27) {
  13. e.preventDefault();
  14. this._pop();
  15. }
  16. };
  17. }
  18. _getElementById(id) {
  19. return this._host.document.getElementById(id + this._id);
  20. }
  21. open(content, title) {
  22. this.close();
  23. this.push(content, title);
  24. }
  25. close() {
  26. this._deactivate();
  27. this._stack = [];
  28. this._hide();
  29. }
  30. push(content, title) {
  31. const item = { title: title, content: content };
  32. this._stack.push(item);
  33. this._activate(item);
  34. }
  35. _pop() {
  36. this._deactivate();
  37. if (this._stack.length > 0) {
  38. this._stack.pop();
  39. }
  40. if (this._stack.length > 0) {
  41. this._activate(this._stack[this._stack.length - 1]);
  42. }
  43. else {
  44. this._hide();
  45. }
  46. }
  47. _hide() {
  48. const sidebar = this._getElementById('sidebar');
  49. if (sidebar) {
  50. sidebar.style.width = '0px';
  51. }
  52. const container = this._getElementById('graph');
  53. if (container) {
  54. container.style.width = '100%';
  55. container.focus();
  56. }
  57. }
  58. _deactivate() {
  59. const sidebar = this._getElementById('sidebar');
  60. if (sidebar) {
  61. const closeButton = this._getElementById('sidebar-closebutton');
  62. if (closeButton) {
  63. closeButton.removeEventListener('click', this._closeSidebarHandler);
  64. closeButton.style.color = '#f8f8f8';
  65. }
  66. this._host.document.removeEventListener('keydown', this._closeSidebarKeyDownHandler);
  67. }
  68. }
  69. _activate(item) {
  70. const sidebar = this._getElementById('sidebar');
  71. if (sidebar) {
  72. sidebar.innerHTML = '';
  73. const title = this._host.document.createElement('h1');
  74. title.classList.add('sidebar-title');
  75. title.innerHTML = item.title ? item.title.toUpperCase() : '';
  76. sidebar.appendChild(title);
  77. const closeButton = this._host.document.createElement('a');
  78. closeButton.classList.add('sidebar-closebutton');
  79. closeButton.setAttribute('id', 'sidebar-closebutton');
  80. closeButton.setAttribute('href', 'javascript:void(0)');
  81. closeButton.innerHTML = '×';
  82. closeButton.addEventListener('click', this._closeSidebarHandler);
  83. sidebar.appendChild(closeButton);
  84. const content = this._host.document.createElement('div');
  85. content.classList.add('sidebar-content');
  86. content.setAttribute('id', 'sidebar-content');
  87. sidebar.appendChild(content);
  88. if (typeof item.content == 'string') {
  89. content.innerHTML = item.content;
  90. }
  91. else if (item.content instanceof Array) {
  92. for (const element of item.content) {
  93. content.appendChild(element);
  94. }
  95. }
  96. else {
  97. content.appendChild(item.content);
  98. }
  99. sidebar.style.width = 'min(calc(100% * 0.6), 500px)';
  100. this._host.document.addEventListener('keydown', this._closeSidebarKeyDownHandler);
  101. }
  102. const container = this._getElementById('graph');
  103. if (container) {
  104. container.style.width = 'max(40vw, calc(100vw - 500px))';
  105. }
  106. }
  107. };
  108. sidebar.NodeSidebar = class {
  109. constructor(host, node) {
  110. this._host = host;
  111. this._node = node;
  112. this._elements = [];
  113. this._attributes = [];
  114. this._inputs = [];
  115. this._outputs = [];
  116. if (node.type) {
  117. let showDocumentation = null;
  118. const type = node.type;
  119. if (type && (type.description || type.inputs || type.outputs || type.attributes)) {
  120. showDocumentation = {};
  121. showDocumentation.text = type.nodes ? '\u0192': '?';
  122. showDocumentation.callback = () => {
  123. this._raise('show-documentation', null);
  124. };
  125. }
  126. this._addProperty('type', new sidebar.ValueTextView(this._host, node.type.name, showDocumentation));
  127. if (node.type.module) {
  128. this._addProperty('module', new sidebar.ValueTextView(this._host, node.type.module));
  129. }
  130. }
  131. if (node.name) {
  132. this._addProperty('name', new sidebar.ValueTextView(this._host, node.name));
  133. }
  134. if (node.location) {
  135. this._addProperty('location', new sidebar.ValueTextView(this._host, node.location));
  136. }
  137. if (node.description) {
  138. this._addProperty('description', new sidebar.ValueTextView(this._host, node.description));
  139. }
  140. if (node.device) {
  141. this._addProperty('device', new sidebar.ValueTextView(this._host, node.device));
  142. }
  143. const attributes = node.attributes;
  144. if (attributes && attributes.length > 0) {
  145. const sortedAttributes = node.attributes.slice();
  146. sortedAttributes.sort((a, b) => {
  147. const au = a.name.toUpperCase();
  148. const bu = b.name.toUpperCase();
  149. return (au < bu) ? -1 : (au > bu) ? 1 : 0;
  150. });
  151. this._addHeader('Attributes');
  152. for (const attribute of sortedAttributes) {
  153. this._addAttribute(attribute.name, attribute);
  154. }
  155. }
  156. const inputs = node.inputs;
  157. if (inputs && inputs.length > 0) {
  158. this._addHeader('Inputs');
  159. for (const input of inputs) {
  160. this._addInput(input.name, input);
  161. }
  162. }
  163. const outputs = node.outputs;
  164. if (outputs && outputs.length > 0) {
  165. this._addHeader('Outputs');
  166. for (const output of outputs) {
  167. this._addOutput(output.name, output);
  168. }
  169. }
  170. const separator = this._host.document.createElement('div');
  171. separator.className = 'sidebar-view-separator';
  172. this._elements.push(separator);
  173. }
  174. render() {
  175. return this._elements;
  176. }
  177. _addHeader(title) {
  178. const headerElement = this._host.document.createElement('div');
  179. headerElement.className = 'sidebar-view-header';
  180. headerElement.innerText = title;
  181. this._elements.push(headerElement);
  182. }
  183. _addProperty(name, value) {
  184. const item = new sidebar.NameValueView(this._host, name, value);
  185. this._elements.push(item.render());
  186. }
  187. _addAttribute(name, attribute) {
  188. const item = new NodeAttributeView(this._host, attribute);
  189. item.on('show-graph', (sender, graph) => {
  190. this._raise('show-graph', graph);
  191. });
  192. const view = new sidebar.NameValueView(this._host, name, item);
  193. this._attributes.push(view);
  194. this._elements.push(view.render());
  195. }
  196. _addInput(name, input) {
  197. if (input.arguments.length > 0) {
  198. const view = new sidebar.ParameterView(this._host, input);
  199. view.on('export-tensor', (sender, tensor) => {
  200. this._raise('export-tensor', tensor);
  201. });
  202. view.on('error', (sender, tensor) => {
  203. this._raise('error', tensor);
  204. });
  205. const item = new sidebar.NameValueView(this._host, name, view);
  206. this._inputs.push(item);
  207. this._elements.push(item.render());
  208. }
  209. }
  210. _addOutput(name, output) {
  211. if (output.arguments.length > 0) {
  212. const item = new sidebar.NameValueView(this._host, name, new sidebar.ParameterView(this._host, output));
  213. this._outputs.push(item);
  214. this._elements.push(item.render());
  215. }
  216. }
  217. toggleInput(name) {
  218. for (const input of this._inputs) {
  219. if (name == input.name) {
  220. input.toggle();
  221. }
  222. }
  223. }
  224. on(event, callback) {
  225. this._events = this._events || {};
  226. this._events[event] = this._events[event] || [];
  227. this._events[event].push(callback);
  228. }
  229. _raise(event, data) {
  230. if (this._events && this._events[event]) {
  231. for (const callback of this._events[event]) {
  232. callback(this, data);
  233. }
  234. }
  235. }
  236. static formatAttributeValue(value, type, quote) {
  237. if (typeof value === 'function') {
  238. return value();
  239. }
  240. if (value && (value instanceof base.Int64 || value instanceof base.Uint64)) {
  241. return value.toString();
  242. }
  243. if (Number.isNaN(value)) {
  244. return 'NaN';
  245. }
  246. switch (type) {
  247. case 'shape':
  248. return value ? value.toString() : '(null)';
  249. case 'shape[]':
  250. if (value && !Array.isArray(value)) {
  251. throw new Error("Invalid shape '" + JSON.stringify(value) + "'.");
  252. }
  253. return value ? value.map((item) => item.toString()).join(', ') : '(null)';
  254. case 'graph':
  255. return value ? value.name : '(null)';
  256. case 'graph[]':
  257. return value ? value.map((graph) => graph.name).join(', ') : '(null)';
  258. case 'tensor':
  259. if (value && value.type && value.type.shape && value.type.shape.dimensions && value.type.shape.dimensions.length == 0) {
  260. return value.toString();
  261. }
  262. return '[...]';
  263. case 'function':
  264. return value.name;
  265. case 'function[]':
  266. return value ? value.map((item) => item.name).join(', ') : '(null)';
  267. }
  268. if (typeof value === 'string' && (!type || type != 'string')) {
  269. return quote ? '"' + value + '"' : value;
  270. }
  271. if (Array.isArray(value)) {
  272. if (value.length == 0) {
  273. return quote ? '[]' : '';
  274. }
  275. let ellipsis = false;
  276. if (value.length > 1000) {
  277. value = value.slice(0, 1000);
  278. ellipsis = true;
  279. }
  280. const itemType = (type && type.endsWith('[]')) ? type.substring(0, type.length - 2) : null;
  281. const array = value.map((item) => {
  282. if (item && (item instanceof base.Int64 || item instanceof base.Uint64)) {
  283. return item.toString();
  284. }
  285. if (Number.isNaN(item)) {
  286. return 'NaN';
  287. }
  288. const quote = !itemType || itemType === 'string';
  289. return sidebar.NodeSidebar.formatAttributeValue(item, itemType, quote);
  290. });
  291. if (ellipsis) {
  292. array.push('\u2026');
  293. }
  294. return quote ? [ '[', array.join(', '), ']' ].join(' ') : array.join(', ');
  295. }
  296. if (value === null) {
  297. return quote ? 'null' : '';
  298. }
  299. if (value === undefined) {
  300. return 'undefined';
  301. }
  302. if (value !== Object(value)) {
  303. return value.toString();
  304. }
  305. const list = [];
  306. const keys = Object.keys(value).filter((key) => !key.startsWith('__') && !key.endsWith('__'));
  307. if (keys.length == 1) {
  308. list.push(sidebar.NodeSidebar.formatAttributeValue(value[Object.keys(value)[0]], null, true));
  309. }
  310. else {
  311. for (const key of keys) {
  312. list.push(key + ': ' + sidebar.NodeSidebar.formatAttributeValue(value[key], null, true));
  313. }
  314. }
  315. let objectType = value.__type__;
  316. if (!objectType && value.constructor.name && value.constructor.name !== 'Object') {
  317. objectType = value.constructor.name;
  318. }
  319. if (objectType) {
  320. return objectType + (list.length == 0 ? '()' : [ '(', list.join(', '), ')' ].join(''));
  321. }
  322. switch (list.length) {
  323. case 0:
  324. return quote ? '()' : '';
  325. case 1:
  326. return list[0];
  327. default:
  328. return quote ? [ '(', list.join(', '), ')' ].join(' ') : list.join(', ');
  329. }
  330. }
  331. };
  332. sidebar.NameValueView = class {
  333. constructor(host, name, value) {
  334. this._host = host;
  335. this._name = name;
  336. this._value = value;
  337. const nameElement = this._host.document.createElement('div');
  338. nameElement.className = 'sidebar-view-item-name';
  339. const nameInputElement = this._host.document.createElement('input');
  340. nameInputElement.setAttribute('type', 'text');
  341. nameInputElement.setAttribute('value', name);
  342. nameInputElement.setAttribute('title', name);
  343. nameInputElement.setAttribute('readonly', 'true');
  344. nameElement.appendChild(nameInputElement);
  345. const valueElement = this._host.document.createElement('div');
  346. valueElement.className = 'sidebar-view-item-value-list';
  347. for (const element of value.render()) {
  348. valueElement.appendChild(element);
  349. }
  350. this._element = this._host.document.createElement('div');
  351. this._element.className = 'sidebar-view-item';
  352. this._element.appendChild(nameElement);
  353. this._element.appendChild(valueElement);
  354. }
  355. get name() {
  356. return this._name;
  357. }
  358. render() {
  359. return this._element;
  360. }
  361. toggle() {
  362. this._value.toggle();
  363. }
  364. };
  365. sidebar.SelectView = class {
  366. constructor(host, values, selected) {
  367. this._host = host;
  368. this._elements = [];
  369. this._values = values;
  370. const selectElement = this._host.document.createElement('select');
  371. selectElement.setAttribute('class', 'sidebar-view-item-select');
  372. selectElement.addEventListener('change', (e) => {
  373. this._raise('change', this._values[e.target.selectedIndex]);
  374. });
  375. this._elements.push(selectElement);
  376. for (const value of values) {
  377. const optionElement = this._host.document.createElement('option');
  378. optionElement.innerText = value.name || '';
  379. if (value == selected) {
  380. optionElement.setAttribute('selected', 'selected');
  381. }
  382. selectElement.appendChild(optionElement);
  383. }
  384. }
  385. render() {
  386. return this._elements;
  387. }
  388. on(event, callback) {
  389. this._events = this._events || {};
  390. this._events[event] = this._events[event] || [];
  391. this._events[event].push(callback);
  392. }
  393. _raise(event, data) {
  394. if (this._events && this._events[event]) {
  395. for (const callback of this._events[event]) {
  396. callback(this, data);
  397. }
  398. }
  399. }
  400. };
  401. sidebar.ValueTextView = class {
  402. constructor(host, value, action) {
  403. this._host = host;
  404. this._elements = [];
  405. const element = this._host.document.createElement('div');
  406. element.className = 'sidebar-view-item-value';
  407. this._elements.push(element);
  408. if (action) {
  409. this._action = this._host.document.createElement('div');
  410. this._action.className = 'sidebar-view-item-value-expander';
  411. this._action.innerHTML = action.text;
  412. this._action.addEventListener('click', () => {
  413. action.callback();
  414. });
  415. element.appendChild(this._action);
  416. }
  417. const list = Array.isArray(value) ? value : [ value ];
  418. let className = 'sidebar-view-item-value-line';
  419. for (const item of list) {
  420. const line = this._host.document.createElement('div');
  421. line.className = className;
  422. line.innerText = item;
  423. element.appendChild(line);
  424. className = 'sidebar-view-item-value-line-border';
  425. }
  426. }
  427. render() {
  428. return this._elements;
  429. }
  430. toggle() {
  431. }
  432. };
  433. class NodeAttributeView {
  434. constructor(host, attribute) {
  435. this._host = host;
  436. this._attribute = attribute;
  437. this._element = this._host.document.createElement('div');
  438. this._element.className = 'sidebar-view-item-value';
  439. const type = this._attribute.type;
  440. if (type) {
  441. this._expander = this._host.document.createElement('div');
  442. this._expander.className = 'sidebar-view-item-value-expander';
  443. this._expander.innerText = '+';
  444. this._expander.addEventListener('click', () => {
  445. this.toggle();
  446. });
  447. this._element.appendChild(this._expander);
  448. }
  449. const value = this._attribute.value;
  450. switch (type) {
  451. case 'graph':
  452. case 'function': {
  453. const line = this._host.document.createElement('div');
  454. line.className = 'sidebar-view-item-value-line-link';
  455. line.innerHTML = value.name;
  456. line.addEventListener('click', () => {
  457. this._raise('show-graph', value);
  458. });
  459. this._element.appendChild(line);
  460. break;
  461. }
  462. default: {
  463. let content = sidebar.NodeSidebar.formatAttributeValue(value, type);
  464. if (content && content.length > 1000) {
  465. content = content.substring(0, 1000) + '\u2026';
  466. }
  467. if (content && typeof content === 'string') {
  468. content = content.split('<').join('&lt;').split('>').join('&gt;');
  469. }
  470. const line = this._host.document.createElement('div');
  471. line.className = 'sidebar-view-item-value-line';
  472. line.innerHTML = content ? content : '&nbsp;';
  473. this._element.appendChild(line);
  474. }
  475. }
  476. }
  477. render() {
  478. return [ this._element ];
  479. }
  480. toggle() {
  481. if (this._expander.innerText == '+') {
  482. this._expander.innerText = '-';
  483. const typeLine = this._host.document.createElement('div');
  484. typeLine.className = 'sidebar-view-item-value-line-border';
  485. const type = this._attribute.type;
  486. const value = this._attribute.value;
  487. if (type == 'tensor' && value && value.type) {
  488. typeLine.innerHTML = 'type: ' + '<code><b>' + value.type.toString() + '</b></code>';
  489. this._element.appendChild(typeLine);
  490. }
  491. else {
  492. typeLine.innerHTML = 'type: ' + '<code><b>' + this._attribute.type + '</b></code>';
  493. this._element.appendChild(typeLine);
  494. }
  495. const description = this._attribute.description;
  496. if (description) {
  497. const descriptionLine = this._host.document.createElement('div');
  498. descriptionLine.className = 'sidebar-view-item-value-line-border';
  499. descriptionLine.innerHTML = description;
  500. this._element.appendChild(descriptionLine);
  501. }
  502. if (this._attribute.type == 'tensor' && value) {
  503. const state = value.state;
  504. const valueLine = this._host.document.createElement('div');
  505. valueLine.className = 'sidebar-view-item-value-line-border';
  506. const contentLine = this._host.document.createElement('pre');
  507. contentLine.innerHTML = state || value.toString();
  508. valueLine.appendChild(contentLine);
  509. this._element.appendChild(valueLine);
  510. }
  511. }
  512. else {
  513. this._expander.innerText = '+';
  514. while (this._element.childElementCount > 2) {
  515. this._element.removeChild(this._element.lastChild);
  516. }
  517. }
  518. }
  519. on(event, callback) {
  520. this._events = this._events || {};
  521. this._events[event] = this._events[event] || [];
  522. this._events[event].push(callback);
  523. }
  524. _raise(event, data) {
  525. if (this._events && this._events[event]) {
  526. for (const callback of this._events[event]) {
  527. callback(this, data);
  528. }
  529. }
  530. }
  531. }
  532. sidebar.ParameterView = class {
  533. constructor(host, list) {
  534. this._list = list;
  535. this._elements = [];
  536. this._items = [];
  537. for (const argument of list.arguments) {
  538. const item = new sidebar.ArgumentView(host, argument);
  539. item.on('export-tensor', (sender, tensor) => {
  540. this._raise('export-tensor', tensor);
  541. });
  542. item.on('error', (sender, tensor) => {
  543. this._raise('error', tensor);
  544. });
  545. this._items.push(item);
  546. this._elements.push(item.render());
  547. }
  548. }
  549. render() {
  550. return this._elements;
  551. }
  552. toggle() {
  553. for (const item of this._items) {
  554. item.toggle();
  555. }
  556. }
  557. on(event, callback) {
  558. this._events = this._events || {};
  559. this._events[event] = this._events[event] || [];
  560. this._events[event].push(callback);
  561. }
  562. _raise(event, data) {
  563. if (this._events && this._events[event]) {
  564. for (const callback of this._events[event]) {
  565. callback(this, data);
  566. }
  567. }
  568. }
  569. };
  570. sidebar.ArgumentView = class {
  571. constructor(host, argument) {
  572. this._host = host;
  573. this._argument = argument;
  574. this._element = this._host.document.createElement('div');
  575. this._element.className = 'sidebar-view-item-value';
  576. const initializer = argument.initializer;
  577. if (initializer) {
  578. this._element.classList.add('sidebar-view-item-value-dark');
  579. }
  580. const quantization = argument.quantization;
  581. const type = argument.type;
  582. const location = this._argument.location !== undefined;
  583. if (type || initializer || quantization || location) {
  584. this._expander = this._host.document.createElement('div');
  585. this._expander.className = 'sidebar-view-item-value-expander';
  586. this._expander.innerText = '+';
  587. this._expander.addEventListener('click', () => {
  588. this.toggle();
  589. });
  590. this._element.appendChild(this._expander);
  591. }
  592. let name = this._argument.name || '';
  593. this._hasId = name ? true : false;
  594. this._hasKind = initializer && initializer.kind ? true : false;
  595. if (this._hasId || (!this._hasKind && !type)) {
  596. this._hasId = true;
  597. const nameLine = this._host.document.createElement('div');
  598. nameLine.className = 'sidebar-view-item-value-line';
  599. if (typeof name !== 'string') {
  600. throw new Error("Invalid argument identifier '" + JSON.stringify(name) + "'.");
  601. }
  602. name = name.split('\n').shift(); // custom argument id
  603. name = name || ' ';
  604. nameLine.innerHTML = '<span class=\'sidebar-view-item-value-line-content\'>name: <b>' + name + '</b></span>';
  605. this._element.appendChild(nameLine);
  606. }
  607. else if (this._hasKind) {
  608. const kindLine = this._host.document.createElement('div');
  609. kindLine.className = 'sidebar-view-item-value-line';
  610. kindLine.innerHTML = 'kind: <b>' + initializer.kind + '</b>';
  611. this._element.appendChild(kindLine);
  612. }
  613. else if (type) {
  614. const typeLine = this._host.document.createElement('div');
  615. typeLine.className = 'sidebar-view-item-value-line-border';
  616. typeLine.innerHTML = 'type: <code><b>' + type.toString().split('<').join('&lt;').split('>').join('&gt;') + '</b></code>';
  617. this._element.appendChild(typeLine);
  618. }
  619. }
  620. render() {
  621. return this._element;
  622. }
  623. toggle() {
  624. if (this._expander) {
  625. if (this._expander.innerText == '+') {
  626. this._expander.innerText = '-';
  627. const initializer = this._argument.initializer;
  628. if (this._hasId && this._hasKind) {
  629. const kindLine = this._host.document.createElement('div');
  630. kindLine.className = 'sidebar-view-item-value-line-border';
  631. kindLine.innerHTML = 'kind: ' + '<b>' + initializer.kind + '</b>';
  632. this._element.appendChild(kindLine);
  633. }
  634. let type = null;
  635. let denotation = null;
  636. if (this._argument.type) {
  637. type = this._argument.type.toString();
  638. denotation = this._argument.type.denotation || null;
  639. }
  640. if (type && (this._hasId || this._hasKind)) {
  641. const typeLine = this._host.document.createElement('div');
  642. typeLine.className = 'sidebar-view-item-value-line-border';
  643. typeLine.innerHTML = 'type: <code><b>' + type.split('<').join('&lt;').split('>').join('&gt;') + '</b></code>';
  644. this._element.appendChild(typeLine);
  645. }
  646. if (denotation) {
  647. const denotationLine = this._host.document.createElement('div');
  648. denotationLine.className = 'sidebar-view-item-value-line-border';
  649. denotationLine.innerHTML = 'denotation: <code><b>' + denotation + '</b></code>';
  650. this._element.appendChild(denotationLine);
  651. }
  652. const description = this._argument.description;
  653. if (description) {
  654. const descriptionLine = this._host.document.createElement('div');
  655. descriptionLine.className = 'sidebar-view-item-value-line-border';
  656. descriptionLine.innerHTML = description;
  657. this._element.appendChild(descriptionLine);
  658. }
  659. const quantization = this._argument.quantization;
  660. if (quantization) {
  661. const quantizationLine = this._host.document.createElement('div');
  662. quantizationLine.className = 'sidebar-view-item-value-line-border';
  663. const content = !Array.isArray(quantization) ? quantization : '<br><br>' + quantization.map((value) => ' ' + value).join('<br>');
  664. quantizationLine.innerHTML = '<span class=\'sidebar-view-item-value-line-content\'>quantization: ' + '<b>' + content + '</b></span>';
  665. this._element.appendChild(quantizationLine);
  666. }
  667. if (this._argument.location !== undefined) {
  668. const location = this._host.document.createElement('div');
  669. location.className = 'sidebar-view-item-value-line-border';
  670. location.innerHTML = 'location: ' + '<b>' + this._argument.location + '</b>';
  671. this._element.appendChild(location);
  672. }
  673. if (initializer) {
  674. const contentLine = this._host.document.createElement('pre');
  675. const valueLine = this._host.document.createElement('div');
  676. try {
  677. const state = initializer.state;
  678. if (state === null && this._host.save &&
  679. initializer.type.dataType && initializer.type.dataType != '?' &&
  680. initializer.type.shape && initializer.type.shape.dimensions /*&& initializer.type.shape.dimensions.length > 0*/) {
  681. this._saveButton = this._host.document.createElement('div');
  682. this._saveButton.className = 'sidebar-view-item-value-expander';
  683. this._saveButton.innerHTML = '&#x1F4BE;';
  684. this._saveButton.addEventListener('click', () => {
  685. this._raise('export-tensor', initializer);
  686. });
  687. this._element.appendChild(this._saveButton);
  688. }
  689. valueLine.className = 'sidebar-view-item-value-line-border';
  690. contentLine.innerHTML = state || initializer.toString();
  691. }
  692. catch (err) {
  693. contentLine.innerHTML = err.toString();
  694. this._raise('error', err);
  695. }
  696. valueLine.appendChild(contentLine);
  697. this._element.appendChild(valueLine);
  698. }
  699. }
  700. else {
  701. this._expander.innerText = '+';
  702. while (this._element.childElementCount > 2) {
  703. this._element.removeChild(this._element.lastChild);
  704. }
  705. }
  706. }
  707. }
  708. on(event, callback) {
  709. this._events = this._events || {};
  710. this._events[event] = this._events[event] || [];
  711. this._events[event].push(callback);
  712. }
  713. _raise(event, data) {
  714. if (this._events && this._events[event]) {
  715. for (const callback of this._events[event]) {
  716. callback(this, data);
  717. }
  718. }
  719. }
  720. };
  721. sidebar.ModelSidebar = class {
  722. constructor(host, model, graph) {
  723. this._host = host;
  724. this._model = model;
  725. this._elements = [];
  726. if (model.format) {
  727. this._addProperty('format', new sidebar.ValueTextView(this._host, model.format));
  728. }
  729. if (model.producer) {
  730. this._addProperty('producer', new sidebar.ValueTextView(this._host, model.producer));
  731. }
  732. if (model.source) {
  733. this._addProperty('source', new sidebar.ValueTextView(this._host, model.source));
  734. }
  735. if (model.name) {
  736. this._addProperty('name', new sidebar.ValueTextView(this._host, model.name));
  737. }
  738. if (model.version) {
  739. this._addProperty('version', new sidebar.ValueTextView(this._host, model.version));
  740. }
  741. if (model.description) {
  742. this._addProperty('description', new sidebar.ValueTextView(this._host, model.description));
  743. }
  744. if (model.author) {
  745. this._addProperty('author', new sidebar.ValueTextView(this._host, model.author));
  746. }
  747. if (model.company) {
  748. this._addProperty('company', new sidebar.ValueTextView(this._host, model.company));
  749. }
  750. if (model.license) {
  751. this._addProperty('license', new sidebar.ValueTextView(this._host, model.license));
  752. }
  753. if (model.domain) {
  754. this._addProperty('domain', new sidebar.ValueTextView(this._host, model.domain));
  755. }
  756. if (model.imports) {
  757. this._addProperty('imports', new sidebar.ValueTextView(this._host, model.imports));
  758. }
  759. if (model.runtime) {
  760. this._addProperty('runtime', new sidebar.ValueTextView(this._host, model.runtime));
  761. }
  762. const metadata = model.metadata;
  763. if (metadata) {
  764. for (const property of model.metadata) {
  765. this._addProperty(property.name, new sidebar.ValueTextView(this._host, property.value));
  766. }
  767. }
  768. const graphs = Array.isArray(model.graphs) ? model.graphs : [];
  769. if (graphs.length > 1) {
  770. const graphSelector = new sidebar.SelectView(this._host, model.graphs, graph);
  771. graphSelector.on('change', (sender, data) => {
  772. this._raise('update-active-graph', data);
  773. });
  774. this._addProperty('subgraph', graphSelector);
  775. }
  776. if (graph) {
  777. if (graph.version) {
  778. this._addProperty('version', new sidebar.ValueTextView(this._host, graph.version));
  779. }
  780. if (graph.type) {
  781. this._addProperty('type', new sidebar.ValueTextView(this._host, graph.type));
  782. }
  783. if (graph.tags) {
  784. this._addProperty('tags', new sidebar.ValueTextView(this._host, graph.tags));
  785. }
  786. if (graph.description) {
  787. this._addProperty('description', new sidebar.ValueTextView(this._host, graph.description));
  788. }
  789. if (Array.isArray(graph.inputs) && graph.inputs.length > 0) {
  790. this._addHeader('Inputs');
  791. for (const input of graph.inputs) {
  792. this.addArgument(input.name, input);
  793. }
  794. }
  795. if (Array.isArray(graph.outputs) && graph.outputs.length > 0) {
  796. this._addHeader('Outputs');
  797. for (const output of graph.outputs) {
  798. this.addArgument(output.name, output);
  799. }
  800. }
  801. }
  802. const separator = this._host.document.createElement('div');
  803. separator.className = 'sidebar-view-separator';
  804. this._elements.push(separator);
  805. }
  806. render() {
  807. return this._elements;
  808. }
  809. _addHeader(title) {
  810. const headerElement = this._host.document.createElement('div');
  811. headerElement.className = 'sidebar-view-header';
  812. headerElement.innerText = title;
  813. this._elements.push(headerElement);
  814. }
  815. _addProperty(name, value) {
  816. const item = new sidebar.NameValueView(this._host, name, value);
  817. this._elements.push(item.render());
  818. }
  819. addArgument(name, argument) {
  820. const view = new sidebar.ParameterView(this._host, argument);
  821. view.toggle();
  822. const item = new sidebar.NameValueView(this._host, name, view);
  823. this._elements.push(item.render());
  824. }
  825. on(event, callback) {
  826. this._events = this._events || {};
  827. this._events[event] = this._events[event] || [];
  828. this._events[event].push(callback);
  829. }
  830. _raise(event, data) {
  831. if (this._events && this._events[event]) {
  832. for (const callback of this._events[event]) {
  833. callback(this, data);
  834. }
  835. }
  836. }
  837. };
  838. sidebar.DocumentationSidebar = class {
  839. constructor(host, metadata) {
  840. this._host = host;
  841. this._metadata = metadata;
  842. }
  843. render() {
  844. if (!this._elements) {
  845. this._elements = [];
  846. const type = sidebar.DocumentationSidebar.formatDocumentation(this._metadata);
  847. const element = this._host.document.createElement('div');
  848. element.setAttribute('class', 'sidebar-view-documentation');
  849. this._append(element, 'h1', type.name);
  850. if (type.summary) {
  851. this._append(element, 'p', type.summary);
  852. }
  853. if (type.description) {
  854. this._append(element, 'p', type.description);
  855. }
  856. if (Array.isArray(type.attributes) && type.attributes.length > 0) {
  857. this._append(element, 'h2', 'Attributes');
  858. const attributes = this._append(element, 'dl');
  859. for (const attribute of type.attributes) {
  860. this._append(attributes, 'dt', attribute.name + (attribute.type ? ': <tt>' + attribute.type + '</tt>' : ''));
  861. this._append(attributes, 'dd', attribute.description);
  862. }
  863. element.appendChild(attributes);
  864. }
  865. if (Array.isArray(type.inputs) && type.inputs.length > 0) {
  866. this._append(element, 'h2', 'Inputs' + (type.inputs_range ? ' (' + type.inputs_range + ')' : ''));
  867. const inputs = this._append(element, 'dl');
  868. for (const input of type.inputs) {
  869. this._append(inputs, 'dt', input.name + (input.type ? ': <tt>' + input.type + '</tt>' : '') + (input.option ? ' (' + input.option + ')' : ''));
  870. this._append(inputs, 'dd', input.description);
  871. }
  872. }
  873. if (Array.isArray(type.outputs) && type.outputs.length > 0) {
  874. this._append(element, 'h2', 'Outputs' + (type.outputs_range ? ' (' + type.outputs_range + ')' : ''));
  875. const outputs = this._append(element, 'dl');
  876. for (const output of type.outputs) {
  877. this._append(outputs, 'dt', output.name + (output.type ? ': <tt>' + output.type + '</tt>' : '') + (output.option ? ' (' + output.option + ')' : ''));
  878. this._append(outputs, 'dd', output.description);
  879. }
  880. }
  881. if (Array.isArray(type.type_constraints) && type.type_constraints.length > 0) {
  882. this._append(element, 'h2', 'Type Constraints');
  883. const type_constraints = this._append(element, 'dl');
  884. for (const type_constraint of type.type_constraints) {
  885. this._append(type_constraints, 'dt', type_constraint.type_param_str + ': ' + type_constraint.allowed_type_strs.map((item) => '<tt>' + item + '</tt>').join(', '));
  886. this._append(type_constraints, 'dd', type_constraint.description);
  887. }
  888. }
  889. if (Array.isArray(type.examples) && type.examples.length > 0) {
  890. this._append(element, 'h2', 'Examples');
  891. for (const example of type.examples) {
  892. this._append(element, 'h3', example.summary);
  893. this._append(element, 'pre', example.code);
  894. }
  895. }
  896. if (Array.isArray(type.references) && type.references.length > 0) {
  897. this._append(element, 'h2', 'References');
  898. const references = this._append(element, 'ul');
  899. for (const reference of type.references) {
  900. this._append(references, 'li', reference.description);
  901. }
  902. }
  903. if (type.domain && type.version && type.support_level) {
  904. this._append(element, 'h2', 'Support');
  905. this._append(element, 'dl', 'In domain <tt>' + type.domain + '</tt> since version <tt>' + type.version + '</tt> at support level <tt>' + type.support_level + '</tt>.');
  906. }
  907. if (!this._host.type !== 'Electron') {
  908. element.addEventListener('click', (e) => {
  909. if (e.target && e.target.href) {
  910. const link = e.target.href;
  911. if (link.startsWith('http://') || link.startsWith('https://')) {
  912. e.preventDefault();
  913. this._raise('navigate', { link: link });
  914. }
  915. }
  916. });
  917. }
  918. this._elements = [ element ];
  919. const separator = this._host.document.createElement('div');
  920. separator.className = 'sidebar-view-separator';
  921. this._elements.push(separator);
  922. }
  923. return this._elements;
  924. }
  925. on(event, callback) {
  926. this._events = this._events || {};
  927. this._events[event] = this._events[event] || [];
  928. this._events[event].push(callback);
  929. }
  930. _raise(event, data) {
  931. if (this._events && this._events[event]) {
  932. for (const callback of this._events[event]) {
  933. callback(this, data);
  934. }
  935. }
  936. }
  937. _append(parent, type, content) {
  938. const element = this._host.document.createElement(type);
  939. if (content) {
  940. element.innerHTML = content;
  941. }
  942. parent.appendChild(element);
  943. return element;
  944. }
  945. static formatDocumentation(source) {
  946. if (source) {
  947. const generator = new markdown.Generator();
  948. const target = {};
  949. if (source.name !== undefined) {
  950. target.name = source.name;
  951. }
  952. if (source.module !== undefined) {
  953. target.module = source.module;
  954. }
  955. if (source.category !== undefined) {
  956. target.category = source.category;
  957. }
  958. if (source.summary !== undefined) {
  959. target.summary = generator.html(source.summary);
  960. }
  961. if (source.description !== undefined) {
  962. target.description = generator.html(source.description);
  963. }
  964. if (Array.isArray(source.attributes)) {
  965. target.attributes = source.attributes.map((source) => {
  966. const target = {};
  967. target.name = source.name;
  968. if (source.type !== undefined) {
  969. target.type = source.type;
  970. }
  971. if (source.option !== undefined) {
  972. target.option = source.option;
  973. }
  974. if (source.optional !== undefined) {
  975. target.optional = source.optional;
  976. }
  977. if (source.required !== undefined) {
  978. target.required = source.required;
  979. }
  980. if (source.minimum !== undefined) {
  981. target.minimum = source.minimum;
  982. }
  983. if (source.src !== undefined) {
  984. target.src = source.src;
  985. }
  986. if (source.src_type !== undefined) {
  987. target.src_type = source.src_type;
  988. }
  989. if (source.description !== undefined) {
  990. target.description = generator.html(source.description);
  991. }
  992. if (source.default !== undefined) {
  993. target.default = source.default;
  994. }
  995. if (source.visible !== undefined) {
  996. target.visible = source.visible;
  997. }
  998. return target;
  999. });
  1000. }
  1001. if (Array.isArray(source.inputs)) {
  1002. target.inputs = source.inputs.map((source) => {
  1003. const target = {};
  1004. target.name = source.name;
  1005. if (source.type !== undefined) {
  1006. target.type = source.type;
  1007. }
  1008. if (source.description !== undefined) {
  1009. target.description = generator.html(source.description);
  1010. }
  1011. if (source.default !== undefined) {
  1012. target.default = source.default;
  1013. }
  1014. if (source.src !== undefined) {
  1015. target.src = source.src;
  1016. }
  1017. if (source.list !== undefined) {
  1018. target.list = source.list;
  1019. }
  1020. if (source.isRef !== undefined) {
  1021. target.isRef = source.isRef;
  1022. }
  1023. if (source.typeAttr !== undefined) {
  1024. target.typeAttr = source.typeAttr;
  1025. }
  1026. if (source.numberAttr !== undefined) {
  1027. target.numberAttr = source.numberAttr;
  1028. }
  1029. if (source.typeListAttr !== undefined) {
  1030. target.typeListAttr = source.typeListAttr;
  1031. }
  1032. if (source.option !== undefined) {
  1033. target.option = source.option;
  1034. }
  1035. if (source.optional !== undefined) {
  1036. target.optional = source.optional;
  1037. }
  1038. if (source.visible !== undefined) {
  1039. target.visible = source.visible;
  1040. }
  1041. return target;
  1042. });
  1043. }
  1044. if (Array.isArray(source.outputs)) {
  1045. target.outputs = source.outputs.map((source) => {
  1046. const target = {};
  1047. target.name = source.name;
  1048. if (source.type) {
  1049. target.type = source.type;
  1050. }
  1051. if (source.description !== undefined) {
  1052. target.description = generator.html(source.description);
  1053. }
  1054. if (source.list !== undefined) {
  1055. target.list = source.list;
  1056. }
  1057. if (source.typeAttr !== undefined) {
  1058. target.typeAttr = source.typeAttr;
  1059. }
  1060. if (source.typeListAttr !== undefined) {
  1061. target.typeListAttr = source.typeAttr;
  1062. }
  1063. if (source.numberAttr !== undefined) {
  1064. target.numberAttr = source.numberAttr;
  1065. }
  1066. if (source.isRef !== undefined) {
  1067. target.isRef = source.isRef;
  1068. }
  1069. if (source.option !== undefined) {
  1070. target.option = source.option;
  1071. }
  1072. return target;
  1073. });
  1074. }
  1075. if (Array.isArray(source.references)) {
  1076. target.references = source.references.map((source) => {
  1077. if (source) {
  1078. target.description = generator.html(source.description);
  1079. }
  1080. return target;
  1081. });
  1082. }
  1083. if (source.version !== undefined) {
  1084. target.version = source.version;
  1085. }
  1086. if (source.operator !== undefined) {
  1087. target.operator = source.operator;
  1088. }
  1089. if (source.identifier !== undefined) {
  1090. target.identifier = source.identifier;
  1091. }
  1092. if (source.package !== undefined) {
  1093. target.package = source.package;
  1094. }
  1095. if (source.support_level !== undefined) {
  1096. target.support_level = source.support_level;
  1097. }
  1098. if (source.min_input !== undefined) {
  1099. target.min_input = source.min_input;
  1100. }
  1101. if (source.max_input !== undefined) {
  1102. target.max_input = source.max_input;
  1103. }
  1104. if (source.min_output !== undefined) {
  1105. target.min_output = source.min_output;
  1106. }
  1107. if (source.max_input !== undefined) {
  1108. target.max_output = source.max_output;
  1109. }
  1110. if (source.inputs_range !== undefined) {
  1111. target.inputs_range = source.inputs_range;
  1112. }
  1113. if (source.outputs_range !== undefined) {
  1114. target.outputs_range = source.outputs_range;
  1115. }
  1116. if (source.examples !== undefined) {
  1117. target.examples = source.examples;
  1118. }
  1119. if (source.constants !== undefined) {
  1120. target.constants = source.constants;
  1121. }
  1122. if (source.type_constraints !== undefined) {
  1123. target.type_constraints = source.type_constraints;
  1124. }
  1125. return target;
  1126. }
  1127. return '';
  1128. }
  1129. };
  1130. sidebar.FindSidebar = class {
  1131. constructor(host, element, graph) {
  1132. this._host = host;
  1133. this._graphElement = element;
  1134. this._graph = graph;
  1135. this._contentElement = this._host.document.createElement('div');
  1136. this._contentElement.setAttribute('class', 'sidebar-view-find');
  1137. this._searchElement = this._host.document.createElement('input');
  1138. this._searchElement.setAttribute('id', 'search');
  1139. this._searchElement.setAttribute('type', 'text');
  1140. this._searchElement.setAttribute('spellcheck', 'false');
  1141. this._searchElement.setAttribute('placeholder', 'Search...');
  1142. this._searchElement.setAttribute('style', 'width: 100%');
  1143. this._searchElement.addEventListener('input', (e) => {
  1144. this.update(e.target.value);
  1145. this._raise('search-text-changed', e.target.value);
  1146. });
  1147. this._resultElement = this._host.document.createElement('ol');
  1148. this._resultElement.addEventListener('click', (e) => {
  1149. this.select(e);
  1150. });
  1151. this._contentElement.appendChild(this._searchElement);
  1152. this._contentElement.appendChild(this._resultElement);
  1153. }
  1154. on(event, callback) {
  1155. this._events = this._events || {};
  1156. this._events[event] = this._events[event] || [];
  1157. this._events[event].push(callback);
  1158. }
  1159. _raise(event, data) {
  1160. if (this._events && this._events[event]) {
  1161. for (const callback of this._events[event]) {
  1162. callback(this, data);
  1163. }
  1164. }
  1165. }
  1166. select(e) {
  1167. const selection = [];
  1168. const id = e.target.id;
  1169. const nodesElement = this._graphElement.getElementById('nodes');
  1170. let nodeElement = nodesElement.firstChild;
  1171. while (nodeElement) {
  1172. if (nodeElement.id == id) {
  1173. selection.push(nodeElement);
  1174. }
  1175. nodeElement = nodeElement.nextSibling;
  1176. }
  1177. const edgePathsElement = this._graphElement.getElementById('edge-paths');
  1178. let edgePathElement = edgePathsElement.firstChild;
  1179. while (edgePathElement) {
  1180. if (edgePathElement.id == id) {
  1181. selection.push(edgePathElement);
  1182. }
  1183. edgePathElement = edgePathElement.nextSibling;
  1184. }
  1185. let initializerElement = this._graphElement.getElementById(id);
  1186. if (initializerElement) {
  1187. while (initializerElement.parentElement) {
  1188. initializerElement = initializerElement.parentElement;
  1189. if (initializerElement.id && initializerElement.id.startsWith('node-')) {
  1190. selection.push(initializerElement);
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. if (selection.length > 0) {
  1196. this._raise('select', selection);
  1197. }
  1198. }
  1199. focus(searchText) {
  1200. this._searchElement.focus();
  1201. this._searchElement.value = '';
  1202. this._searchElement.value = searchText;
  1203. this.update(searchText);
  1204. }
  1205. update(searchText) {
  1206. while (this._resultElement.lastChild) {
  1207. this._resultElement.removeChild(this._resultElement.lastChild);
  1208. }
  1209. let terms = null;
  1210. let callback = null;
  1211. const unquote = searchText.match(new RegExp(/^'(.*)'|"(.*)"$/));
  1212. if (unquote) {
  1213. const term = unquote[1] || unquote[2];
  1214. terms = [ term ];
  1215. callback = (name) => {
  1216. return term == name;
  1217. };
  1218. }
  1219. else {
  1220. terms = searchText.trim().toLowerCase().split(' ').map((term) => term.trim()).filter((term) => term.length > 0);
  1221. callback = (name) => {
  1222. return terms.every((term) => name.toLowerCase().indexOf(term) !== -1);
  1223. };
  1224. }
  1225. const nodes = new Set();
  1226. const edges = new Set();
  1227. for (const node of this._graph.nodes.values()) {
  1228. const label = node.label;
  1229. const initializers = [];
  1230. if (label.class === 'graph-node' || label.class === 'graph-input') {
  1231. for (const input of label.inputs) {
  1232. for (const argument of input.arguments) {
  1233. if (argument.name && !edges.has(argument.name)) {
  1234. const match = (argument, term) => {
  1235. if (argument.name && argument.name.toLowerCase().indexOf(term) !== -1) {
  1236. return true;
  1237. }
  1238. if (argument.type) {
  1239. if (argument.type.dataType && term === argument.type.dataType.toLowerCase()) {
  1240. return true;
  1241. }
  1242. if (argument.type.shape) {
  1243. if (term === argument.type.shape.toString().toLowerCase()) {
  1244. return true;
  1245. }
  1246. if (argument.type.shape && Array.isArray(argument.type.shape.dimensions)) {
  1247. const dimensions = argument.type.shape.dimensions.map((dimension) => dimension ? dimension.toString().toLowerCase() : '');
  1248. if (term === dimensions.join(',')) {
  1249. return true;
  1250. }
  1251. if (dimensions.some((dimension) => term === dimension)) {
  1252. return true;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. return false;
  1258. };
  1259. if (terms.every((term) => match(argument, term))) {
  1260. if (!argument.initializer) {
  1261. const inputItem = this._host.document.createElement('li');
  1262. inputItem.innerText = '\u2192 ' + argument.name.split('\n').shift(); // custom argument id
  1263. inputItem.id = 'edge-' + argument.name;
  1264. this._resultElement.appendChild(inputItem);
  1265. edges.add(argument.name);
  1266. }
  1267. else {
  1268. initializers.push(argument);
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. }
  1275. if (label.class === 'graph-node') {
  1276. const name = label.value.name;
  1277. const type = label.value.type.name;
  1278. if (!nodes.has(label.id) &&
  1279. ((name && callback(name) || (type && callback(type))))) {
  1280. const nameItem = this._host.document.createElement('li');
  1281. nameItem.innerText = '\u25A2 ' + (name || '[' + type + ']');
  1282. nameItem.id = label.id;
  1283. this._resultElement.appendChild(nameItem);
  1284. nodes.add(label.id);
  1285. }
  1286. }
  1287. for (const argument of initializers) {
  1288. if (argument.name) {
  1289. const initializeItem = this._host.document.createElement('li');
  1290. initializeItem.innerText = '\u25A0 ' + argument.name.split('\n').shift(); // custom argument id
  1291. initializeItem.id = 'initializer-' + argument.name;
  1292. this._resultElement.appendChild(initializeItem);
  1293. }
  1294. }
  1295. }
  1296. for (const node of this._graph.nodes.values()) {
  1297. const label = node.label;
  1298. if (label.class === 'graph-node' || label.class === 'graph-output') {
  1299. for (const output of label.outputs) {
  1300. for (const argument of output.arguments) {
  1301. if (argument.name && !edges.has(argument.name) && terms.every((term) => argument.name.toLowerCase().indexOf(term) != -1)) {
  1302. const outputItem = this._host.document.createElement('li');
  1303. outputItem.innerText = '\u2192 ' + argument.name.split('\n').shift(); // custom argument id
  1304. outputItem.id = 'edge-' + argument.name;
  1305. this._resultElement.appendChild(outputItem);
  1306. edges.add(argument.name);
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. this._resultElement.style.display = this._resultElement.childNodes.length != 0 ? 'block' : 'none';
  1313. }
  1314. get content() {
  1315. return this._contentElement;
  1316. }
  1317. };
  1318. const markdown = {};
  1319. markdown.Generator = class {
  1320. constructor() {
  1321. this._newlineRegExp = /^\n+/;
  1322. this._codeRegExp = /^( {4}[^\n]+\n*)+/;
  1323. this._fencesRegExp = /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/;
  1324. this._hrRegExp = /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/;
  1325. this._headingRegExp = /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/;
  1326. this._blockquoteRegExp = /^( {0,3}> ?(([^\n]+(?:\n(?! {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)| {0,3}#{1,6} | {0,3}>| {0,3}(?:`{3,}(?=[^`\n]*\n)|~{3,})[^\n]*\n| {0,3}(?:[*+-]|1[.)]) |<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)|[^\n]*)(?:\n|$))+/;
  1327. this._listRegExp = /^( {0,3})((?:[*+-]|\d{1,9}[.)])) [\s\S]+?(?:\n+(?=\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$))|\n+(?= {0,3}\[((?!\s*\])(?:\\[[\]]|[^[\]])+)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)((?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))))? *(?:\n+|$))|\n{2,}(?! )(?!\1(?:[*+-]|\d{1,9}[.)]) )\n*|\s*$)/;
  1328. this._htmlRegExp = /^ {0,3}(?:<(script|pre|style)[\s>][\s\S]*?(?:<\/\1>[^\n]*\n+|$)|<!--(?!-?>)[\s\S]*?(?:-->|$)[^\n]*(\n+|$)|<\?[\s\S]*?(?:\?>\n*|$)|<![A-Z][\s\S]*?(?:>\n*|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>\n*|$)|<\/?(address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?: +|\n|\/?>)[\s\S]*?(?:\n{2,}|$)|<(?!script|pre|style)([a-z][\w-]*)(?: +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?)*? *\/?>(?=[ \t]*(?:\n|$))[\s\S]*?(?:\n{2,}|$)|<\/(?!script|pre|style)[a-z][\w-]*\s*>(?=[ \t]*(?:\n|$))[\s\S]*?(?:\n{2,}|$))/i;
  1329. this._defRegExp = /^ {0,3}\[((?!\s*\])(?:\\[[\]]|[^[\]])+)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)((?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))))? *(?:\n+|$)/;
  1330. this._nptableRegExp = /^ *([^|\n ].*\|.*)\n {0,3}([-:]+ *\|[-| :]*)(?:\n((?:(?!\n| {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)| {0,3}#{1,6} | {0,3}>| {4}[^\n]| {0,3}(?:`{3,}(?=[^`\n]*\n)|~{3,})[^\n]*\n| {0,3}(?:[*+-]|1[.)]) |<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?: +|\n|\/?>)|<(?:script|pre|style|!--)).*(?:\n|$))*)\n*|$)/;
  1331. this._tableRegExp = /^ *\|(.+)\n {0,3}\|?( *[-:]+[-| :]*)(?:\n *((?:(?!\n| {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)| {0,3}#{1,6} | {0,3}>| {4}[^\n]| {0,3}(?:`{3,}(?=[^`\n]*\n)|~{3,})[^\n]*\n| {0,3}(?:[*+-]|1[.)]) |<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?: +|\n|\/?>)|<(?:script|pre|style|!--)).*(?:\n|$))*)\n*|$)/;
  1332. this._lheadingRegExp = /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/;
  1333. this._textRegExp = /^[^\n]+/;
  1334. this._bulletRegExp = /(?:[*+-]|\d{1,9}[.)])/;
  1335. this._itemRegExp = /^( *)((?:[*+-]|\d{1,9}[.)])) ?[^\n]*(?:\n(?!\1(?:[*+-]|\d{1,9}[.)]) ?)[^\n]*)*/gm;
  1336. this._paragraphRegExp = /^([^\n]+(?:\n(?! {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)| {0,3}#{1,6} | {0,3}>| {0,3}(?:`{3,}(?=[^`\n]*\n)|~{3,})[^\n]*\n| {0,3}(?:[*+-]|1[.)]) |<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/;
  1337. this._backpedalRegExp = /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/;
  1338. this._escapeRegExp = /^\\([!"#$%&'()*+,\-./:;<=>?@[\]\\^_`{|}~~|])/;
  1339. this._escapesRegExp = /\\([!"#$%&'()*+,\-./:;<=>?@[\]\\^_`{|}~])/g;
  1340. /* eslint-disable no-control-regex */
  1341. this._autolinkRegExp = /^<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^\s\x00-\x1f<>]*|[a-zA-Z0-9.!#$%&'*+/=?_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_]))>/;
  1342. this._linkRegExp = /^!?\[((?:\[(?:\\.|[^[\]\\])*\]|\\.|`[^`]*`|[^[\]\\`])*?)\]\(\s*(<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*)(?:\s+("(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)))?\s*\)/;
  1343. /* eslint-enable no-control-regex */
  1344. this._urlRegExp = /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9-]+\.?)+[^\s<]*|^[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/i;
  1345. this._tagRegExp = /^<!--(?!-?>)[\s\S]*?-->|^<\/[a-zA-Z][\w:-]*\s*>|^<[a-zA-Z][\w-]*(?:\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?)*?\s*\/?>|^<\?[\s\S]*?\?>|^<![a-zA-Z]+\s[\s\S]*?>|^<!\[CDATA\[[\s\S]*?\]\]>/;
  1346. this._reflinkRegExp = /^!?\[((?:\[(?:\\.|[^[\]\\])*\]|\\.|`[^`]*`|[^[\]\\`])*?)\]\[(?!\s*\])((?:\\[[\]]?|[^[\]\\])+)\]/;
  1347. this._nolinkRegExp = /^!?\[(?!\s*\])((?:\[[^[\]]*\]|\\[[\]]|[^[\]])*)\](?:\[\])?/;
  1348. this._reflinkSearchRegExp = /!?\[((?:\[(?:\\.|[^[\]\\])*\]|\\.|`[^`]*`|[^[\]\\`])*?)\]\[(?!\s*\])((?:\\[[\]]?|[^[\]\\])+)\]|!?\[(?!\s*\])((?:\[[^[\]]*\]|\\[[\]]|[^[\]])*)\](?:\[\])?(?!\()/g;
  1349. this._strongStartRegExp = /^(?:(\*\*(?=[*!"#$%&'()+\-.,/:;<=>?@[\]`{|}~]))|\*\*)(?![\s])|__/;
  1350. this._strongMiddleRegExp = /^\*\*(?:(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^*]|\\\*)|__[^_]*?__|\*\*\[^\*\]*?\*\*)|\*(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^*]|\\\*)|__[^_]*?__|\*\*\[^\*\]*?\*\*)*?\*)+?\*\*$|^__(?![\s])((?:(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^_]|\\_)|__[^_]*?__|\*\*\[^\*\]*?\*\*)|_(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^_]|\\_)|__[^_]*?__|\*\*\[^\*\]*?\*\*)*?_)+?)__$/;
  1351. this._strongEndAstRegExp = /[^!"#$%&'()+\-.,/:;<=>?@[\]`{|}~\s]\*\*(?!\*)|[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~]\*\*(?!\*)(?:(?=[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~_\s]|$))/g;
  1352. this._strongEndUndRegExp = /[^\s]__(?!_)(?:(?=[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~*\s])|$)/g;
  1353. this._emStartRegExp = /^(?:(\*(?=[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~]))|\*)(?![*\s])|_/;
  1354. this._emMiddleRegExp = /^\*(?:(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^*]|\\\*)|__[^_]*?__|\*\*\[^\*\]*?\*\*)|\*(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^*]|\\\*)|__[^_]*?__|\*\*\[^\*\]*?\*\*)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^_]|\\_)|__[^_]*?__|\*\*\[^\*\]*?\*\*)|_(?:(?!__[^_]*?__|\*\*\[^\*\]*?\*\*)(?:[^_]|\\_)|__[^_]*?__|\*\*\[^\*\]*?\*\*)*?_)+?_$/;
  1355. this._emEndAstRegExp = /[^!"#$%&'()+\-.,/:;<=>?@[\]`{|}~\s]\*(?!\*)|[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~]\*(?!\*)(?:(?=[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~_\s]|$))/g;
  1356. this._emEndUndRegExp = /[^\s]_(?!_)(?:(?=[!"#$%&'()+\-.,/:;<=>?@[\]`{|}~*\s])|$)/g,
  1357. this._codespanRegExp = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
  1358. this._brRegExp = /^( {2,}|\\)\n(?!\s*$)/;
  1359. this._delRegExp = /^~+(?=\S)([\s\S]*?\S)~+/;
  1360. this._textspanRegExp = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<![`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+/=?_`{|}~-](?=[a-zA-Z0-9.!#$%&'*+/=?_`{|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+/=?_`{|}~-]+@))/;
  1361. this._punctuationRegExp = /^([\s*!"#$%&'()+\-.,/:;<=>?@[\]`{|}~])/;
  1362. this._blockSkipRegExp = /\[[^\]]*?\]\([^)]*?\)|`[^`]*?`|<[^>]*?>/g;
  1363. this._escapeTestRegExp = /[&<>"']/;
  1364. this._escapeReplaceRegExp = /[&<>"']/g;
  1365. this._escapeTestNoEncodeRegExp = /[<>"']|&(?!#?\w+;)/;
  1366. this._escapeReplaceNoEncodeRegExp = /[<>"']|&(?!#?\w+;)/g;
  1367. this._escapeReplacementsMap = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
  1368. }
  1369. html(source) {
  1370. const tokens = [];
  1371. const links = new Map();
  1372. this._tokenize(source.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' '), tokens, links, true);
  1373. this._tokenizeBlock(tokens, links);
  1374. const slugs = new Map();
  1375. const result = this._render(tokens, slugs, true);
  1376. return result;
  1377. }
  1378. _tokenize(source, tokens, links, top) {
  1379. source = source.replace(/^ +$/gm, '');
  1380. while (source) {
  1381. let match = this._newlineRegExp.exec(source);
  1382. if (match) {
  1383. source = source.substring(match[0].length);
  1384. if (match[0].length > 1) {
  1385. tokens.push({ type: 'space' });
  1386. }
  1387. continue;
  1388. }
  1389. match = this._codeRegExp.exec(source);
  1390. if (match) {
  1391. source = source.substring(match[0].length);
  1392. const lastToken = tokens[tokens.length - 1];
  1393. if (lastToken && lastToken.type === 'paragraph') {
  1394. lastToken.text += '\n' + match[0].trimRight();
  1395. }
  1396. else {
  1397. const text = match[0].replace(/^ {4}/gm, '').replace(/\n*$/, '');
  1398. tokens.push({ type: 'code', text: text });
  1399. }
  1400. continue;
  1401. }
  1402. match = this._fencesRegExp.exec(source);
  1403. if (match) {
  1404. source = source.substring(match[0].length);
  1405. const language = match[2] ? match[2].trim() : match[2];
  1406. let content = match[3] || '';
  1407. const matchIndent = match[0].match(/^(\s+)(?:```)/);
  1408. if (matchIndent !== null) {
  1409. const indent = matchIndent[1];
  1410. content = content.split('\n').map(node => {
  1411. const match = node.match(/^\s+/);
  1412. return (match !== null && match[0].length >= indent.length) ? node.slice(indent.length) : node;
  1413. }).join('\n');
  1414. }
  1415. tokens.push({ type: 'code', language: language, text: content });
  1416. continue;
  1417. }
  1418. match = this._headingRegExp.exec(source);
  1419. if (match) {
  1420. source = source.substring(match[0].length);
  1421. tokens.push({ type: 'heading', depth: match[1].length, text: match[2] });
  1422. continue;
  1423. }
  1424. match = this._nptableRegExp.exec(source);
  1425. if (match) {
  1426. const header = this._splitCells(match[1].replace(/^ *| *\| *$/g, ''));
  1427. const align = match[2].replace(/^ *|\| *$/g, '').split(/ *\| */);
  1428. if (header.length === align.length) {
  1429. const cells = match[3] ? match[3].replace(/\n$/, '').split('\n') : [];
  1430. const token = { type: 'table', header: header, align: align, cells: cells, raw: match[0] };
  1431. for (let i = 0; i < token.align.length; i++) {
  1432. if (/^ *-+: *$/.test(token.align[i])) {
  1433. token.align[i] = 'right';
  1434. }
  1435. else if (/^ *:-+: *$/.test(token.align[i])) {
  1436. token.align[i] = 'center';
  1437. }
  1438. else if (/^ *:-+ *$/.test(token.align[i])) {
  1439. token.align[i] = 'left';
  1440. }
  1441. else {
  1442. token.align[i] = null;
  1443. }
  1444. }
  1445. token.cells = token.cells.map((cell) => this._splitCells(cell, token.header.length));
  1446. source = source.substring(token.raw.length);
  1447. tokens.push(token);
  1448. continue;
  1449. }
  1450. }
  1451. match = this._hrRegExp.exec(source);
  1452. if (match) {
  1453. source = source.substring(match[0].length);
  1454. tokens.push({ type: 'hr' });
  1455. continue;
  1456. }
  1457. match = this._blockquoteRegExp.exec(source);
  1458. if (match) {
  1459. source = source.substring(match[0].length);
  1460. const text = match[0].replace(/^ *> ?/gm, '');
  1461. tokens.push({ type: 'blockquote', text: text, tokens: this._tokenize(text, [], links, top) });
  1462. continue;
  1463. }
  1464. match = this._listRegExp.exec(source);
  1465. if (match) {
  1466. let raw = match[0];
  1467. const bull = match[2];
  1468. const ordered = bull.length > 1;
  1469. const parent = bull[bull.length - 1] === ')';
  1470. const list = { type: 'list', raw: raw, ordered: ordered, start: ordered ? +bull.slice(0, -1) : '', loose: false, items: [] };
  1471. const itemMatch = match[0].match(this._itemRegExp);
  1472. let next = false;
  1473. const length = itemMatch.length;
  1474. for (let i = 0; i < length; i++) {
  1475. let item = itemMatch[i];
  1476. raw = item;
  1477. let space = item.length;
  1478. item = item.replace(/^ *([*+-]|\d+[.)]) ?/, '');
  1479. if (~item.indexOf('\n ')) {
  1480. space -= item.length;
  1481. item = item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '');
  1482. }
  1483. if (i !== length - 1) {
  1484. const bullet = this._bulletRegExp.exec(itemMatch[i + 1])[0];
  1485. if (ordered ? bullet.length === 1 || (!parent && bullet[bullet.length - 1] === ')') : (bullet.length > 1)) {
  1486. const addBack = itemMatch.slice(i + 1).join('\n');
  1487. list.raw = list.raw.substring(0, list.raw.length - addBack.length);
  1488. i = length - 1;
  1489. }
  1490. }
  1491. let loose = next || /\n\n(?!\s*$)/.test(item);
  1492. if (i !== length - 1) {
  1493. next = item.charAt(item.length - 1) === '\n';
  1494. if (!loose) {
  1495. loose = next;
  1496. }
  1497. }
  1498. if (loose) {
  1499. list.loose = true;
  1500. }
  1501. const task = /^\[[ xX]\] /.test(item);
  1502. let checked = undefined;
  1503. if (task) {
  1504. checked = item[1] !== ' ';
  1505. item = item.replace(/^\[[ xX]\] +/, '');
  1506. }
  1507. list.items.push({ type: 'list_item', raw, task: task, checked: checked, loose: loose, text: item });
  1508. }
  1509. source = source.substring(list.raw.length);
  1510. for (const item of list.items) {
  1511. item.tokens = this._tokenize(item.text, [], links, false);
  1512. }
  1513. tokens.push(list);
  1514. continue;
  1515. }
  1516. match = this._htmlRegExp.exec(source);
  1517. if (match) {
  1518. source = source.substring(match[0].length);
  1519. tokens.push({ type: 'html', pre: (match[1] === 'pre' || match[1] === 'script' || match[1] === 'style'), text: match[0] });
  1520. continue;
  1521. }
  1522. if (top) {
  1523. match = this._defRegExp.exec(source);
  1524. if (match) {
  1525. source = source.substring(match[0].length);
  1526. match[3] = match[3] ? match[3].substring(1, match[3].length - 1) : match[3];
  1527. const tag = match[1].toLowerCase().replace(/\s+/g, ' ');
  1528. if (!links.has(tag)) {
  1529. links.set(tag, { href: match[2], title: match[3] });
  1530. }
  1531. continue;
  1532. }
  1533. }
  1534. match = this._tableRegExp.exec(source);
  1535. if (match) {
  1536. const header = this._splitCells(match[1].replace(/^ *| *\| *$/g, ''));
  1537. const align = match[2].replace(/^ *|\| *$/g, '').split(/ *\| */);
  1538. if (header.length === align.length) {
  1539. const cells = match[3] ? match[3].replace(/\n$/, '').split('\n') : [];
  1540. const token = { type: 'table', header: header, align: align, cells: cells, raw: match[0] };
  1541. for (let i = 0; i < token.align.length; i++) {
  1542. if (/^ *-+: *$/.test(token.align[i])) {
  1543. token.align[i] = 'right';
  1544. }
  1545. else if (/^ *:-+: *$/.test(token.align[i])) {
  1546. token.align[i] = 'center';
  1547. }
  1548. else if (/^ *:-+ *$/.test(token.align[i])) {
  1549. token.align[i] = 'left';
  1550. }
  1551. else {
  1552. token.align[i] = null;
  1553. }
  1554. }
  1555. token.cells = token.cells.map((cell) => this._splitCells(cell.replace(/^ *\| *| *\| *$/g, ''), token.header.length));
  1556. source = source.substring(token.raw.length);
  1557. tokens.push(token);
  1558. continue;
  1559. }
  1560. }
  1561. match = this._lheadingRegExp.exec(source);
  1562. if (match) {
  1563. source = source.substring(match[0].length);
  1564. tokens.push({ type: 'heading', depth: match[2].charAt(0) === '=' ? 1 : 2, text: match[1] });
  1565. continue;
  1566. }
  1567. if (top) {
  1568. match = this._paragraphRegExp.exec(source);
  1569. if (match) {
  1570. source = source.substring(match[0].length);
  1571. tokens.push({ type: 'paragraph', text: match[1].charAt(match[1].length - 1) === '\n' ? match[1].slice(0, -1) : match[1] });
  1572. continue;
  1573. }
  1574. }
  1575. match = this._textRegExp.exec(source);
  1576. if (match) {
  1577. source = source.substring(match[0].length);
  1578. const lastToken = tokens[tokens.length - 1];
  1579. if (lastToken && lastToken.type === 'text') {
  1580. lastToken.text += '\n' + match[0];
  1581. }
  1582. else {
  1583. tokens.push({ type: 'text', text: match[0] });
  1584. }
  1585. continue;
  1586. }
  1587. throw new Error("Unexpected '" + source.charCodeAt(0) + "'.");
  1588. }
  1589. return tokens;
  1590. }
  1591. _tokenizeInline(source, links, inLink, inRawBlock, prevChar) {
  1592. const tokens = [];
  1593. let maskedSource = source;
  1594. if (links.size > 0) {
  1595. while (maskedSource) {
  1596. const match = this._reflinkSearchRegExp.exec(maskedSource);
  1597. if (match) {
  1598. if (links.has(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
  1599. maskedSource = maskedSource.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSource.slice(this._reflinkSearchRegExp.lastIndex);
  1600. }
  1601. continue;
  1602. }
  1603. break;
  1604. }
  1605. }
  1606. while (maskedSource) {
  1607. const match = this._blockSkipRegExp.exec(maskedSource);
  1608. if (match) {
  1609. maskedSource = maskedSource.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSource.slice(this._blockSkipRegExp.lastIndex);
  1610. continue;
  1611. }
  1612. break;
  1613. }
  1614. while (source) {
  1615. let match = this._escapeRegExp.exec(source);
  1616. if (match) {
  1617. source = source.substring(match[0].length);
  1618. tokens.push({ type: 'escape', text: this._escape(match[1]) });
  1619. continue;
  1620. }
  1621. match = this._tagRegExp.exec(source);
  1622. if (match) {
  1623. source = source.substring(match[0].length);
  1624. if (!inLink && /^<a /i.test(match[0])) {
  1625. inLink = true;
  1626. }
  1627. else if (inLink && /^<\/a>/i.test(match[0])) {
  1628. inLink = false;
  1629. }
  1630. if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(match[0])) {
  1631. inRawBlock = true;
  1632. }
  1633. else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(match[0])) {
  1634. inRawBlock = false;
  1635. }
  1636. tokens.push({ type: 'html', raw: match[0], text: match[0] });
  1637. continue;
  1638. }
  1639. match = this._linkRegExp.exec(source);
  1640. if (match) {
  1641. let index = -1;
  1642. const ref = match[2];
  1643. if (ref.indexOf(')') !== -1) {
  1644. let level = 0;
  1645. for (let i = 0; i < ref.length; i++) {
  1646. switch (ref[i]) {
  1647. case '\\':
  1648. i++;
  1649. break;
  1650. case '(':
  1651. level++;
  1652. break;
  1653. case ')':
  1654. level--;
  1655. if (level < 0) {
  1656. index = i;
  1657. i = ref.length;
  1658. }
  1659. break;
  1660. }
  1661. }
  1662. }
  1663. if (index > -1) {
  1664. const length = (match[0].indexOf('!') === 0 ? 5 : 4) + match[1].length + index;
  1665. match[2] = match[2].substring(0, index);
  1666. match[0] = match[0].substring(0, length).trim();
  1667. match[3] = '';
  1668. }
  1669. const title = (match[3] ? match[3].slice(1, -1) : '').replace(this._escapesRegExp, '$1');
  1670. const href = match[2].trim().replace(/^<([\s\S]*)>$/, '$1').replace(this._escapesRegExp, '$1');
  1671. const token = this._outputLink(match, href, title);
  1672. source = source.substring(match[0].length);
  1673. if (token.type === 'link') {
  1674. token.tokens = this._tokenizeInline(token.text, links, true, inRawBlock, '');
  1675. }
  1676. tokens.push(token);
  1677. continue;
  1678. }
  1679. match = this._reflinkRegExp.exec(source) || this._nolinkRegExp.exec(source);
  1680. if (match) {
  1681. let link = (match[2] || match[1]).replace(/\s+/g, ' ');
  1682. link = links.get(link.toLowerCase());
  1683. if (!link || !link.href) {
  1684. const text = match[0].charAt(0);
  1685. source = source.substring(text.length);
  1686. tokens.push({ type: 'text', text: text });
  1687. }
  1688. else {
  1689. source = source.substring(match[0].length);
  1690. const token = this._outputLink(match, link);
  1691. if (token.type === 'link') {
  1692. token.tokens = this._tokenizeInline(token.text, links, true, inRawBlock, '');
  1693. }
  1694. tokens.push(token);
  1695. }
  1696. continue;
  1697. }
  1698. match = this._strongStartRegExp.exec(source);
  1699. if (match && (!match[1] || (match[1] && (prevChar === '' || this._punctuationRegExp.exec(prevChar))))) {
  1700. const masked = maskedSource.slice(-1 * source.length);
  1701. const endReg = match[0] === '**' ? this._strongEndAstRegExp : this._strongEndUndRegExp;
  1702. endReg.lastIndex = 0;
  1703. let cap;
  1704. while ((match = endReg.exec(masked)) != null) {
  1705. cap = this._strongMiddleRegExp.exec(masked.slice(0, match.index + 3));
  1706. if (cap) {
  1707. break;
  1708. }
  1709. }
  1710. if (cap) {
  1711. const text = source.substring(2, cap[0].length - 2);
  1712. source = source.substring(cap[0].length);
  1713. tokens.push({ type: 'strong', text: text, tokens: this._tokenizeInline(text, links, inLink, inRawBlock, '') });
  1714. continue;
  1715. }
  1716. }
  1717. match = this._emStartRegExp.exec(source);
  1718. if (match && (!match[1] || (match[1] && (prevChar === '' || this._punctuationRegExp.exec(prevChar))))) {
  1719. const masked = maskedSource.slice(-1 * source.length);
  1720. const endReg = match[0] === '*' ? this._emEndAstRegExp : this._emEndUndRegExp;
  1721. endReg.lastIndex = 0;
  1722. let cap;
  1723. while ((match = endReg.exec(masked)) != null) {
  1724. cap = this._emMiddleRegExp.exec(masked.slice(0, match.index + 2));
  1725. if (cap) {
  1726. break;
  1727. }
  1728. }
  1729. if (cap) {
  1730. const text = source.slice(1, cap[0].length - 1);
  1731. source = source.substring(cap[0].length);
  1732. tokens.push({ type: 'em', text: text, tokens: this._tokenizeInline(text, links, inLink, inRawBlock, '') });
  1733. continue;
  1734. }
  1735. }
  1736. match = this._codespanRegExp.exec(source);
  1737. if (match) {
  1738. source = source.substring(match[0].length);
  1739. let content = match[2].replace(/\n/g, ' ');
  1740. if (/[^ ]/.test(content) && content.startsWith(' ') && content.endsWith(' ')) {
  1741. content = content.substring(1, content.length - 1);
  1742. }
  1743. tokens.push({ type: 'codespan', text: this._encode(content) });
  1744. continue;
  1745. }
  1746. match = this._brRegExp.exec(source);
  1747. if (match) {
  1748. source = source.substring(match[0].length);
  1749. tokens.push({ type: 'br' });
  1750. continue;
  1751. }
  1752. match = this._delRegExp.exec(source);
  1753. if (match) {
  1754. source = source.substring(match[0].length);
  1755. const text = match[1];
  1756. tokens.push({ type: 'del', text: text, tokens: this._tokenizeInline(text, links, inLink, inRawBlock, '') });
  1757. continue;
  1758. }
  1759. match = this._autolinkRegExp.exec(source);
  1760. if (match) {
  1761. source = source.substring(match[0].length);
  1762. const text = this._escape(match[1]);
  1763. const href = match[2] === '@' ? 'mailto:' + text : text;
  1764. tokens.push({ type: 'link', text: text, href: href, tokens: [ { type: 'text', raw: text, text } ] });
  1765. continue;
  1766. }
  1767. if (!inLink) {
  1768. match = this._urlRegExp.exec(source);
  1769. if (match) {
  1770. const email = match[2] === '@';
  1771. if (!email) {
  1772. let prevCapZero;
  1773. do {
  1774. prevCapZero = match[0];
  1775. match[0] = this._backpedalRegExp.exec(match[0])[0];
  1776. } while (prevCapZero !== match[0]);
  1777. }
  1778. const text = this._escape(match[0]);
  1779. const href = email ? ('mailto:' + text) : (match[1] === 'www.' ? 'http://' + text : text);
  1780. source = source.substring(match[0].length);
  1781. tokens.push({ type: 'link', text: text, href: href, tokens: [ { type: 'text', text: text } ] });
  1782. continue;
  1783. }
  1784. }
  1785. match = this._textspanRegExp.exec(source);
  1786. if (match) {
  1787. source = source.substring(match[0].length);
  1788. prevChar = match[0].slice(-1);
  1789. tokens.push({ type: 'text' , text: inRawBlock ? match[0] : this._escape(match[0]) });
  1790. continue;
  1791. }
  1792. throw new Error("Unexpected '" + source.charCodeAt(0) + "'.");
  1793. }
  1794. return tokens;
  1795. }
  1796. _tokenizeBlock(tokens, links) {
  1797. for (const token of tokens) {
  1798. switch (token.type) {
  1799. case 'paragraph':
  1800. case 'text':
  1801. case 'heading': {
  1802. token.tokens = this._tokenizeInline(token.text, links, false, false, '');
  1803. break;
  1804. }
  1805. case 'table': {
  1806. token.tokens = {};
  1807. token.tokens.header = token.header.map((header) => this._tokenizeInline(header, links, false, false, ''));
  1808. token.tokens.cells = token.cells.map((cell) => cell.map((row) => this._tokenizeInline(row, links, false, false, '')));
  1809. break;
  1810. }
  1811. case 'blockquote': {
  1812. this._tokenizeBlock(token.tokens, links);
  1813. break;
  1814. }
  1815. case 'list': {
  1816. for (const item of token.items) {
  1817. this._tokenizeBlock(item.tokens, links);
  1818. }
  1819. break;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. _render(tokens, slugs, top) {
  1825. let html = '';
  1826. while (tokens.length > 0) {
  1827. const token = tokens.shift();
  1828. switch (token.type) {
  1829. case 'space': {
  1830. continue;
  1831. }
  1832. case 'hr': {
  1833. html += '<hr>\n';
  1834. continue;
  1835. }
  1836. case 'heading': {
  1837. const level = token.depth;
  1838. const id = this._slug(slugs, this._renderInline(token.tokens, true));
  1839. html += '<h' + level + ' id="' + id + '">' + this._renderInline(token.tokens) + '</h' + level + '>\n';
  1840. continue;
  1841. }
  1842. case 'code': {
  1843. const code = token.text;
  1844. const language = (token.language || '').match(/\S*/)[0];
  1845. html += '<pre><code' + (language ? ' class="' + 'language-' + this._encode(language) + '"' : '') + '>' + (token.escaped ? code : this._encode(code)) + '</code></pre>\n';
  1846. continue;
  1847. }
  1848. case 'table': {
  1849. let header = '';
  1850. let cell = '';
  1851. for (let j = 0; j < token.header.length; j++) {
  1852. const content = this._renderInline(token.tokens.header[j]);
  1853. const align = token.align[j];
  1854. cell += '<th' + (align ? ' align="' + align + '"' : '') + '>' + content + '</th>\n';
  1855. }
  1856. header += '<tr>\n' + cell + '</tr>\n';
  1857. let body = '';
  1858. for (let j = 0; j < token.cells.length; j++) {
  1859. const row = token.tokens.cells[j];
  1860. cell = '';
  1861. for (let k = 0; k < row.length; k++) {
  1862. const content = this._renderInline(row[k]);
  1863. const align = token.align[k];
  1864. cell += '<td' + (align ? ' align="' + align + '"' : '') + '>' + content + '</td>\n';
  1865. }
  1866. body += '<tr>\n' + cell + '</tr>\n';
  1867. }
  1868. html += '<table>\n<thead>\n' + header + '</thead>\n' + (body ? '<tbody>' + body + '</tbody>' : body) + '</table>\n';
  1869. continue;
  1870. }
  1871. case 'blockquote': {
  1872. html += '<blockquote>\n' + this._render(token.tokens, slugs, true) + '</blockquote>\n';
  1873. continue;
  1874. }
  1875. case 'list': {
  1876. const ordered = token.ordered;
  1877. const start = token.start;
  1878. const loose = token.loose;
  1879. let body = '';
  1880. for (const item of token.items) {
  1881. let itemBody = '';
  1882. if (item.task) {
  1883. const checkbox = '<input ' + (item.checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + '> ';
  1884. if (loose) {
  1885. if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
  1886. item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
  1887. if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
  1888. item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
  1889. }
  1890. }
  1891. else {
  1892. item.tokens.unshift({ type: 'text', text: checkbox });
  1893. }
  1894. }
  1895. else {
  1896. itemBody += checkbox;
  1897. }
  1898. }
  1899. itemBody += this._render(item.tokens, slugs, loose);
  1900. body += '<li>' + itemBody + '</li>\n';
  1901. }
  1902. const type = (ordered ? 'ol' : 'ul');
  1903. html += '<' + type + (ordered && start !== 1 ? (' start="' + start + '"') : '') + '>\n' + body + '</' + type + '>\n';
  1904. continue;
  1905. }
  1906. case 'html': {
  1907. html += token.text;
  1908. continue;
  1909. }
  1910. case 'paragraph': {
  1911. html += '<p>' + this._renderInline(token.tokens) + '</p>\n';
  1912. continue;
  1913. }
  1914. case 'text': {
  1915. html += top ? '<p>' : '';
  1916. html += token.tokens ? this._renderInline(token.tokens) : token.text;
  1917. while (tokens.length > 0 && tokens[0].type === 'text') {
  1918. const token = tokens.shift();
  1919. html += '\n' + (token.tokens ? this._renderInline(token.tokens) : token.text);
  1920. }
  1921. html += top ? '</p>\n' : '';
  1922. continue;
  1923. }
  1924. default: {
  1925. throw new Error("Unexpected token type '" + token.type + "'.");
  1926. }
  1927. }
  1928. }
  1929. return html;
  1930. }
  1931. _renderInline(tokens, slug) {
  1932. let html = '';
  1933. for (const token of tokens) {
  1934. switch (token.type) {
  1935. case 'escape':
  1936. case 'html':
  1937. case 'text': {
  1938. html += token.text;
  1939. break;
  1940. }
  1941. case 'link': {
  1942. const text = this._renderInline(token.tokens, slug);
  1943. html += slug ? text : '<a href="' + token.href + '"' + (token.title ? ' title="' + token.title + '"' : '') + ' target="_blank">' + text + '</a>';
  1944. break;
  1945. }
  1946. case 'image': {
  1947. html += slug ? token.text : '<img src="' + token.href + '" alt="' + token.text + '"' + (token.title ? ' title="' + token.title + '"' : '') + '>';
  1948. break;
  1949. }
  1950. case 'strong': {
  1951. const text = this._renderInline(token.tokens, slug);
  1952. html += slug ? text : '<strong>' + text + '</strong>';
  1953. break;
  1954. }
  1955. case 'em': {
  1956. const text = this._renderInline(token.tokens, slug);
  1957. html += slug ? text : '<em>' + text + '</em>';
  1958. break;
  1959. }
  1960. case 'codespan': {
  1961. html += slug ? token.text : '<code>' + token.text + '</code>';
  1962. break;
  1963. }
  1964. case 'br': {
  1965. html += slug ? '' : '<br>';
  1966. break;
  1967. }
  1968. case 'del': {
  1969. const text = this._renderInline(token.tokens, slug);
  1970. html += slug ? text : '<del>' + text + '</del>';
  1971. break;
  1972. }
  1973. default: {
  1974. throw new Error("Unexpected token type '" + token.type + "'.");
  1975. }
  1976. }
  1977. }
  1978. return html;
  1979. }
  1980. _outputLink(match, href, title) {
  1981. title = title ? this._escape(title) : null;
  1982. const text = match[1].replace(/\\([[\]])/g, '$1');
  1983. return match[0].charAt(0) !== '!' ?
  1984. { type: 'link', href: href, title: title, text: text } :
  1985. { type: 'image', href: href, title: title, text: this._escape(text) };
  1986. }
  1987. _splitCells(tableRow, count) {
  1988. const row = tableRow.replace(/\|/g, (match, offset, str) => {
  1989. let escaped = false;
  1990. let position = offset;
  1991. while (--position >= 0 && str[position] === '\\') {
  1992. escaped = !escaped;
  1993. }
  1994. return escaped ? '|' : ' |';
  1995. });
  1996. const cells = row.split(/ \|/);
  1997. if (cells.length > count) {
  1998. cells.splice(count);
  1999. }
  2000. else {
  2001. while (cells.length < count) {
  2002. cells.push('');
  2003. }
  2004. }
  2005. return cells.map((cell) => cell.trim().replace(/\\\|/g, '|'));
  2006. }
  2007. _slug(slugs, value) {
  2008. value = value.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, (_, n) => {
  2009. n = n.toLowerCase();
  2010. if (n === 'colon') {
  2011. return ':';
  2012. }
  2013. if (n.charAt(0) === '#') {
  2014. return String.fromCharCode(n.charAt(1) === 'x' ? parseInt(n.substring(2), 16) : +n.substring(1));
  2015. }
  2016. return '';
  2017. });
  2018. value = value.toLowerCase().trim()
  2019. .replace(/<[!/a-z].*?>/ig, '')
  2020. .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
  2021. .replace(/\s/g, '-');
  2022. let slug = value;
  2023. let count = 0;
  2024. if (slugs.has(value)) {
  2025. count = slugs.get(value);
  2026. do {
  2027. count++;
  2028. slug = value + '-' + count;
  2029. }
  2030. while (slugs.has(slug));
  2031. }
  2032. slugs.set(value, count);
  2033. slugs.set(slug, 0);
  2034. return slug;
  2035. }
  2036. _encode(content) {
  2037. if (this._escapeTestRegExp.test(content)) {
  2038. return content.replace(this._escapeReplaceRegExp, (ch) => this._escapeReplacementsMap[ch]);
  2039. }
  2040. return content;
  2041. }
  2042. _escape(content) {
  2043. if (this._escapeTestNoEncodeRegExp.test(content)) {
  2044. return content.replace(this._escapeReplaceNoEncodeRegExp, (ch) => this._escapeReplacementsMap[ch]);
  2045. }
  2046. return content;
  2047. }
  2048. };
  2049. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  2050. module.exports.Sidebar = sidebar.Sidebar;
  2051. module.exports.ModelSidebar = sidebar.ModelSidebar;
  2052. module.exports.NodeSidebar = sidebar.NodeSidebar;
  2053. module.exports.DocumentationSidebar = sidebar.DocumentationSidebar;
  2054. module.exports.FindSidebar = sidebar.FindSidebar;
  2055. }