effects.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // SPDX-FileCopyrightText: 2012-2023 MOD Audio UG
  2. // SPDX-License-Identifier: AGPL-3.0-or-later
  3. /*
  4. * effectBox
  5. *
  6. * The interface for searching, selecting and installing plugins
  7. *
  8. * Properties:
  9. * - mode: The search mode, indicated by top buttons
  10. * - searchbox: dom of search's input
  11. * - resultCanvas: dom div in which results will be shown
  12. * - categoryBrowse: dom div with category menu
  13. * - results: dictionary containing detailed data of all plugins
  14. * displayed
  15. */
  16. JqueryClass('effectBox', {
  17. init: function (options) {
  18. var self = $(this)
  19. options = $.extend({
  20. pedalboard: $('<div>'),
  21. windowManager: null,
  22. saveConfigValue: function (key, value) {},
  23. }, options)
  24. self.data(options)
  25. self.data('showPluginsRenderId', 0)
  26. var searchbox = self.find('input[type=search]')
  27. // make sure searchbox is empty on init
  28. searchbox.val("")
  29. self.data('searchbox', searchbox)
  30. searchbox.cleanableInput()
  31. var lastKeyTimeout = null
  32. searchbox.keydown(function (e) {
  33. if (e.keyCode == 13) { // detect enter
  34. if (lastKeyTimeout != null) {
  35. clearTimeout(lastKeyTimeout)
  36. lastKeyTimeout = null
  37. }
  38. self.effectBox('search')
  39. return false
  40. }
  41. else if (e.keyCode == 8 || e.keyCode == 46) { // detect delete and backspace
  42. if (lastKeyTimeout != null) {
  43. clearTimeout(lastKeyTimeout)
  44. }
  45. lastKeyTimeout = setTimeout(function () {
  46. self.effectBox('search')
  47. }, 400);
  48. }
  49. })
  50. searchbox.keypress(function (e) { // keypress won't detect delete and backspace but will only allow inputable keys
  51. if (e.which == 13) {
  52. return
  53. }
  54. if (lastKeyTimeout != null) {
  55. clearTimeout(lastKeyTimeout)
  56. }
  57. lastKeyTimeout = setTimeout(function () {
  58. self.effectBox('search')
  59. }, 400);
  60. })
  61. searchbox.on('cut', function(e) {
  62. if (lastKeyTimeout != null) {
  63. clearTimeout(lastKeyTimeout)
  64. }
  65. lastKeyTimeout = setTimeout(function () {
  66. self.effectBox('search')
  67. }, 400);
  68. })
  69. searchbox.on('paste', function(e) {
  70. if (lastKeyTimeout != null) {
  71. clearTimeout(lastKeyTimeout)
  72. }
  73. lastKeyTimeout = setTimeout(function () {
  74. self.effectBox('search')
  75. }, 400);
  76. })
  77. var settingsBox = self.find('#plugins-library-settings-window')
  78. settingsBox.window({
  79. windowName: "Plugin Library",
  80. windowManager: options.windowManager,
  81. trigger: self.find('.js-settings-trigger')
  82. })
  83. self.find('.js-settings-trigger').click(function(){
  84. $('#effectSearch').focus() // will focus the input when clicking the search icon
  85. })
  86. self.droppable({
  87. accept: '.js-available-effect',
  88. drop: function (event, ui) {
  89. //ui.helper.consumed = true
  90. }
  91. })
  92. self.data('category', null)
  93. // CATEGORY TABS
  94. self.find('ul.js-category-tabs li').click(function () {
  95. var category = $(this).attr('id').replace(/^effect-tab-/, '')
  96. self.effectBox('setCategory', category)
  97. })
  98. self.find('.js-effects-fold').click(function () {
  99. self.effectBox('toggle')
  100. options.saveConfigValue("plugins-folded", self.hasClass('folded') ? "true" : "false")
  101. })
  102. self.find('.nav-left').click(function () {
  103. self.effectBox('shiftLeft')
  104. })
  105. self.find('.nav-right').click(function () {
  106. self.effectBox('shiftRight')
  107. })
  108. // CATEGORY WRAPPERS
  109. self.find(".plugins-wrapper").each(function () {
  110. $(this).data("pos", 0);
  111. $(this).data("plug", 0);
  112. })
  113. // CATEGORY SCROLL
  114. self.on('DOMMouseScroll mousewheel', function ( event ) {
  115. if( event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0 )
  116. self.effectBox('shiftNext');
  117. else
  118. self.effectBox('shiftPrev');
  119. self.effectBox('scrolling');
  120. return false;
  121. });
  122. self.data("scrollTO", false);
  123. //self.effectBox('fold')
  124. if (FAVORITES.length > 0) {
  125. self.effectBox('setCategory', 'Favorites')
  126. } else {
  127. self.effectBox('setCategory', 'All')
  128. }
  129. // don't search just yet.
  130. // it's a little expensive, let init time go for loading the pedalboard first
  131. self.effectBox('showPlugins', [])
  132. self.mouseenter(function () { self.effectBox('mouseEnter'); });
  133. $("#main-menu").mouseenter(function () { self.trigger("mouseenter") });
  134. return self
  135. },
  136. fold: function () {
  137. var self = $(this)
  138. //self.find('.js-effects-list').hide()
  139. self.addClass('folded')
  140. //self.find('.js-effects-fold').hide()
  141. },
  142. unfold: function () {
  143. var self = $(this)
  144. //self.find('.js-effects-list').show()
  145. self.removeClass('folded')
  146. //self.find('.js-effects-fold').show()
  147. },
  148. toggle: function () {
  149. var self = $(this);
  150. if (self.hasClass('auto')) {
  151. self.trigger("mouseleave");
  152. self.effectBox('unfold')
  153. } else
  154. self.effectBox('fold')
  155. self.toggleClass("auto");
  156. },
  157. mouseEnter: function (e) {
  158. var self = $(this);
  159. if (self.hasClass('auto')) {
  160. self.one("mouseleave", function () { self.effectBox('fold'); });
  161. self.effectBox('unfold');
  162. }
  163. },
  164. setCategory: function (category) {
  165. var self = $(this)
  166. self.find('ul.js-category-tabs li').removeClass('selected')
  167. self.find('.plugins-wrapper').removeClass("selected");
  168. self.find('#effect-tab-' + category).addClass('selected')
  169. self.find('#effect-content-' + category).addClass("selected");
  170. self.data('category', category)
  171. self.effectBox('unfold')
  172. self.effectBox('calculateNavigation')
  173. },
  174. search: function (callback) {
  175. var self = $(this)
  176. var searchbox = self.data('searchbox')
  177. var term = searchbox.val()
  178. if (term)
  179. {
  180. var allplugins = desktop.pluginIndexerData
  181. var plugins = []
  182. var ret = desktop.pluginIndexer.search(term)
  183. for (var i in ret) {
  184. var uri = ret[i].ref
  185. plugins.push(allplugins[uri])
  186. }
  187. self.effectBox('showPlugins', plugins)
  188. }
  189. else
  190. {
  191. $.ajax({
  192. method: 'GET',
  193. url: '/effect/list',
  194. success: function (plugins) {
  195. var i, plugin, allplugins = {}
  196. for (i in plugins) {
  197. plugin = plugins[i]
  198. plugin.installedVersion = [plugin.builder, plugin.minorVersion, plugin.microVersion, plugin.release]
  199. allplugins[plugin.uri] = plugin
  200. }
  201. desktop.resetPluginIndexer(allplugins)
  202. self.effectBox('showPlugins', plugins, callback)
  203. },
  204. cache: false,
  205. dataType: 'json'
  206. });
  207. }
  208. },
  209. showPlugins: function (plugins, callback) {
  210. var self = $(this)
  211. self.effectBox('cleanResults')
  212. plugins.sort(function (a, b) {
  213. a = a.label.toLowerCase()
  214. b = b.label.toLowerCase()
  215. if (a > b) {
  216. return 1
  217. }
  218. if (a < b) {
  219. return -1
  220. }
  221. return 0
  222. })
  223. // count plugins first
  224. var pluginCount = plugins.length
  225. var categories = {
  226. 'Favorites': 0,
  227. 'All': 0,
  228. 'ControlVoltage': 0,
  229. 'Delay': 0,
  230. 'Distortion': 0,
  231. 'Dynamics': 0,
  232. 'Filter': 0,
  233. 'Generator': 0,
  234. 'MIDI': 0,
  235. 'Modulator': 0,
  236. 'Reverb': 0,
  237. 'Simulator': 0,
  238. 'Spatial': 0,
  239. 'Spectral': 0,
  240. 'Utility': 0,
  241. 'MaxGen': 0,
  242. 'Camomile': 0,
  243. }
  244. var category
  245. for (i in plugins) {
  246. category = plugins[i].category[0]
  247. if (category) {
  248. if (categories[category] == null)
  249. categories[category] = 1
  250. else
  251. categories[category] += 1
  252. }
  253. if (FAVORITES.indexOf(plugins[i].uri) >= 0) {
  254. categories.Favorites += 1
  255. }
  256. categories.All += 1
  257. }
  258. // display plugin count
  259. for (category in categories) {
  260. var tab = self.find('#effect-tab-' + category)
  261. tab.find('.count').text('(' + categories[category] + ')')
  262. }
  263. if (categories[category] == 0) {
  264. self.find('#effect-tab-MaxGen').hide()
  265. } else {
  266. self.find('#effect-tab-MaxGen').show()
  267. }
  268. // disable navigation while we render plugins
  269. self.find('.nav-left').addClass('disabled')
  270. self.find('.nav-right').addClass('disabled')
  271. var renderedIndex = 0
  272. // current render id, to check if another render has been called
  273. var currentRenderId = self.data('showPluginsRenderId')+1
  274. self.data('showPluginsRenderId', currentRenderId)
  275. // render plugins
  276. var plugin
  277. function renderNextPlugin() {
  278. if (self.data('showPluginsRenderId') != currentRenderId) {
  279. // another render is in place, stop this one
  280. if (callback) { callback() }
  281. return
  282. }
  283. if (renderedIndex >= pluginCount) {
  284. // if we get here it means we finished rendering
  285. self.effectBox('calculateNavigation')
  286. if (self.data('showPluginsRenderId') == currentRenderId) {
  287. // no other renders in queue, take the chance and reset the id
  288. self.data('showPluginsRenderId', 0)
  289. }
  290. if (callback) { callback() }
  291. return
  292. }
  293. plugin = plugins[renderedIndex]
  294. category = plugin.category[0]
  295. self.effectBox('renderPlugin', plugin, self.find('#effect-content-All'))
  296. if (FAVORITES.indexOf(plugin.uri) >= 0) {
  297. self.effectBox('renderPlugin', plugin, self.find('#effect-content-Favorites'))
  298. }
  299. if (category && category != 'All') {
  300. self.effectBox('renderPlugin', plugin, self.find('#effect-content-' + category))
  301. }
  302. renderedIndex += 1
  303. setTimeout(renderNextPlugin, 1);
  304. }
  305. renderNextPlugin(0)
  306. },
  307. renderPlugin: function (plugin, container, replace) {
  308. var self = $(this)
  309. if (container.length == 0)
  310. return
  311. var uri = escape(plugin.uri)
  312. var ver = [plugin.builder, plugin.microVersion, plugin.minorVersion, plugin.release].join('_')
  313. var plugin_data = {
  314. uri : uri,
  315. brand : plugin.brand || "&nbsp;",
  316. label : plugin.label,
  317. thumbnail_href: (plugin.gui && plugin.gui.thumbnail)
  318. ? ("/effect/image/thumbnail.png?uri=" + uri + "&v=" + ver)
  319. : "/resources/pedals/default-thumbnail.png",
  320. licensed: plugin.licensed > 0,
  321. demo: plugin.licensed < 0,
  322. }
  323. if (window.devicePixelRatio && window.devicePixelRatio >= 2) {
  324. plugin_data.thumbnail_href = plugin_data.thumbnail_href.replace("thumbnail","screenshot")
  325. }
  326. var div = document.createElement("div");
  327. div.innerHTML = Mustache.render(TEMPLATES.plugin, plugin_data);
  328. var rendered = $(Array.prototype.slice.call(div.childNodes, 0));
  329. self.data('pedalboard').pedalboard('registerAvailablePlugin', rendered, plugin, {
  330. distance: 2,
  331. delay: 100,
  332. start: function () {
  333. if (self.data('info'))
  334. self.data('info').remove()
  335. self.data('windowManager').closeWindows(null, true)
  336. self.window('fade')
  337. },
  338. stop: function () {
  339. self.window('unfade')
  340. }
  341. })
  342. rendered.click(function () {
  343. self.effectBox('showPluginInfo', plugin)
  344. })
  345. if (replace) {
  346. rendered.insertAfter(replace)
  347. replace.remove()
  348. } else {
  349. container.append(rendered)
  350. }
  351. var index = self.data('index')
  352. if (!index[plugin.uri])
  353. index[plugin.uri] = []
  354. index[plugin.uri].push([plugin, rendered, container])
  355. },
  356. showPluginInfo: function (plugin) {
  357. var self = $(this)
  358. var uri = escape(plugin.uri)
  359. var showInfo = function() {
  360. // formating numbers and flooring ranges up to two decimal cases
  361. for (var i = 0; i < plugin.ports.control.input.length; i++) {
  362. plugin.ports.control.input[i].formatted = format(plugin.ports.control.input[i])
  363. }
  364. if (plugin.ports.cv && plugin.ports.cv.input) {
  365. for (var i = 0; i < plugin.ports.cv.input.length; i++) {
  366. plugin.ports.cv.input[i].formatted = format(plugin.ports.cv.input[i])
  367. }
  368. }
  369. if (plugin.ports.cv && plugin.ports.cv.output) {
  370. for (var i = 0; i < plugin.ports.cv.output.length; i++) {
  371. plugin.ports.cv.output[i].formatted = format(plugin.ports.cv.output[i])
  372. }
  373. }
  374. var ver = [plugin.builder, plugin.microVersion, plugin.minorVersion, plugin.release].join('_')
  375. var metadata = {
  376. author: plugin.author,
  377. uri: plugin.uri,
  378. thumbnail_href: (plugin.gui && plugin.gui.thumbnail)
  379. ? "/effect/image/thumbnail.png?uri=" + uri + "&v=" + ver
  380. : "/resources/pedals/default-thumbnail.png",
  381. screenshot_href: (plugin.gui && plugin.gui.screenshot)
  382. ? "/effect/image/screenshot.png?uri=" + uri + "&v=" + ver
  383. : "/resources/pedals/default-screenshot.png",
  384. category: plugin.category[0] || "None",
  385. installed_version: version(plugin.installedVersion),
  386. latest_version: "DO NOT SHOW THIS!!", // not shown on local plugin bar
  387. package_name: plugin.bundles[0].replace(/\.lv2$/, ''),
  388. comment: plugin.comment.trim() || "No description available",
  389. brand : plugin.brand,
  390. name : plugin.name,
  391. label : plugin.label,
  392. ports : plugin.ports,
  393. demo : plugin.licensed < 0,
  394. licensed: plugin.licensed > 0,
  395. installed: true,
  396. favorite_class: FAVORITES.indexOf(plugin.uri) >= 0 ? "favorite" : "",
  397. plugin_href: PLUGINS_URL + '/' + btoa(plugin.uri),
  398. pedalboard_href: desktop.getPedalboardHref(plugin.uri),
  399. discussion_href: plugin.gui.discussionURL,
  400. documentation_href: (plugin.gui && plugin.gui.documentation)
  401. ? '/effect/file/documentation?uri=' + uri + '&v=' + ver
  402. : '',
  403. build_env_uppercase: (plugin.buildEnvironment || "LOCAL").toUpperCase(),
  404. show_build_env: plugin.buildEnvironment !== "prod",
  405. };
  406. var render = function(metadata) {
  407. var info = $(Mustache.render(TEMPLATES.cloudplugin_info, metadata))
  408. // hide install etc buttons
  409. info.find('.js-remove').hide()
  410. info.find('.js-install').hide()
  411. info.find('.js-upgrade').hide()
  412. info.find('.js-latest-version').hide()
  413. // hide control ports table if none available
  414. if (plugin.ports.control.input.length == 0) {
  415. info.find('.plugin-controlports').hide()
  416. }
  417. // hide cv inputs table if none available
  418. if (!plugin.ports.cv || (plugin.ports.cv && plugin.ports.cv.input && plugin.ports.cv.input.length == 0)) {
  419. info.find('.plugin-cvinputs').hide()
  420. }
  421. // hide cv ouputs ports table if none available
  422. if (!plugin.ports.cv || (plugin.ports.cv && plugin.ports.cv.output && plugin.ports.cv.output.length == 0)) {
  423. info.find('.plugin-cvoutputs').hide()
  424. }
  425. info.find('.favorite-button').on('click', function () {
  426. var isFavorite = $(this).hasClass('favorite'),
  427. widget = $(this)
  428. $.ajax({
  429. url: '/favorites/' + (isFavorite ? 'remove' : 'add'),
  430. type: 'POST',
  431. data: {
  432. uri: plugin.uri,
  433. },
  434. success: function (ok) {
  435. if (! ok) {
  436. console.log("favorite action failed")
  437. return
  438. }
  439. if (isFavorite) {
  440. // was favorite, not anymore
  441. widget.removeClass('favorite');
  442. remove_from_array(FAVORITES, plugin.uri)
  443. self.find('#effect-content-Favorites').find('[mod-uri="'+escape(plugin.uri)+'"]').remove()
  444. } else {
  445. // was not favorite, now is
  446. widget.addClass('favorite');
  447. FAVORITES.push(plugin.uri)
  448. self.effectBox('renderPlugin', plugin, self.find('#effect-content-Favorites'))
  449. }
  450. self.find('#effect-tab-Favorites').find('.count').text('(' + FAVORITES.length + ')')
  451. },
  452. cache: false,
  453. dataType: 'json'
  454. })
  455. });
  456. if (metadata.shopify_id && !metadata.licensed) {
  457. desktop.createBuyButton(metadata.shopify_id)
  458. }
  459. info.window({
  460. windowName: "Plugin Info",
  461. windowManager: self.data('windowManager'),
  462. close: function () {
  463. info.remove()
  464. self.data('info', null)
  465. }
  466. })
  467. info.appendTo($('body'))
  468. info.window('open')
  469. self.data('info', info)
  470. }
  471. render(metadata)
  472. if (!metadata.licensed) {
  473. desktop.fetchShopProduct(plugin.uri).then(function(product) {
  474. if (product) {
  475. metadata.shopify_id = product.id
  476. metadata.price = product.selectedVariant.price
  477. render(metadata)
  478. } else if (metadata.demo) {
  479. metadata.coming = true
  480. render(metadata)
  481. }
  482. })
  483. }
  484. }
  485. if (plugin.bundles) {
  486. showInfo()
  487. } else {
  488. var renderedVersion = [plugin.builder,
  489. plugin.microVersion,
  490. plugin.minorVersion,
  491. plugin.release].join('_');
  492. $.ajax({
  493. url: "/effect/get",
  494. data: {
  495. uri: plugin.uri,
  496. version: VERSION,
  497. plugin_version: renderedVersion,
  498. },
  499. success: function (pluginData) {
  500. plugin = $.extend(plugin, pluginData)
  501. // FIXME: needed?
  502. desktop.pluginIndexerData[plugin.uri] = plugin
  503. showInfo()
  504. },
  505. cache: !!plugin.buildEnvironment,
  506. dataType: 'json'
  507. })
  508. }
  509. },
  510. cleanResults: function () {
  511. var self = $(this)
  512. self.find('.plugins-wrapper').html('')
  513. self.find('ul.js-category-tabs li span.count').each(function () {
  514. $(this).text()
  515. });
  516. self.effectBox('resetShift')
  517. self.data('index', {})
  518. //$('#js-effect-info').hide()
  519. },
  520. calculateNavigation: function () {
  521. var self = $(this)
  522. var wrapper = self.find('.plugins-wrapper.selected')
  523. if (wrapper.length == 0)
  524. return
  525. var shift = wrapper.position().left
  526. var maxShift = Math.max(0, wrapper.width() - wrapper.parent().width())
  527. if (shift == 0)
  528. self.find('.nav-left').addClass('disabled')
  529. else
  530. self.find('.nav-left').removeClass('disabled')
  531. if (shift == maxShift)
  532. self.find('.nav-right').addClass('disabled')
  533. else
  534. self.find('.nav-right').removeClass('disabled')
  535. },
  536. resetShift: function () {
  537. $(this).find('.plugins-wrapper').css('left', 0)
  538. },
  539. shiftLeft: function () {
  540. $(this).effectBox('shiftDir', -1);
  541. },
  542. shiftRight: function () {
  543. $(this).effectBox('shiftDir', 1);
  544. },
  545. // This whole scrolling and shifting thing is very expensive due
  546. // to lots of relayouts and redraws. This is because we want to
  547. // snap to plugins on the left border of the container. We should
  548. // switch to a less greedy concept. Maybe next century.
  549. shiftDir: function (dir) {
  550. var self = $(this);
  551. var wrapper = self.find('.plugins-wrapper.selected');
  552. var parent = wrapper.parent().parent();
  553. var plugins = wrapper.children();
  554. var pos = wrapper.data("pos");
  555. var pw = parent.width();
  556. var ww = wrapper.width();
  557. var pos = Math.min(0,
  558. Math.max(-(ww - pw), pos - pw * dir + 64));
  559. var shift = 0;
  560. if (pos != -(ww - pw)) {
  561. for (var i = 0; i < plugins.length; i++) {
  562. var plugw = $(plugins[i]).outerWidth();
  563. if (shift + plugw >= -pos) {
  564. pos = -shift;
  565. wrapper.data("plug", i);
  566. break;
  567. }
  568. shift += plugw;
  569. }
  570. }
  571. wrapper.data("pos", pos);
  572. wrapper[0].style.left = pos + "px";
  573. },
  574. shiftPrev: function () {
  575. $(this).effectBox('shiftAlter', -1);
  576. },
  577. shiftNext: function () {
  578. $(this).effectBox('shiftAlter', 1);
  579. },
  580. shiftAlter: function (dir) {
  581. var self = $(this);
  582. var wrapper = self.find('.plugins-wrapper.selected');
  583. var parent = wrapper.parent().parent();
  584. var children = wrapper.children();
  585. var plug = wrapper.data("plug");
  586. var pw = parent.width();
  587. var ww = wrapper.width();
  588. if (ww < pw) return;
  589. plug = Math.min(children.length-1, Math.max(0, plug + dir));
  590. var pos = Math.max(-(ww - pw),
  591. -$(children[plug]).position().left);
  592. while (-$(children[plug]).position().left < pos)
  593. plug--;
  594. wrapper[0].style.left = pos + "px";
  595. wrapper.data("pos", pos);
  596. wrapper.data("plug", plug);
  597. },
  598. scrolling: function () {
  599. var self = $(this);
  600. var scrollTO = self.data("scrollTO");
  601. if (scrollTO) {
  602. clearTimeout(scrollTO);
  603. } else {
  604. self.addClass("scrolling");
  605. }
  606. self.data("scrollTO", setTimeout(function () {
  607. self.data("scrollTO", false);
  608. self.removeClass("scrolling");
  609. }, 200));
  610. }
  611. })
  612. function version(v) {
  613. if (!v || !v.length)
  614. return '0.0-0'
  615. return ""+v[1]+"."+v[2]+"-"+v[3]
  616. }