{"version":3,"names":[],"mappings":"","sources":["algorithm_visualizer.js"],"sourcesContent":["/**\n * algorithm-visualizer - Algorithm Visualizer\n * @version v0.1.0\n * @author Jason Park & contributors\n * @link https://github.com/parkjs814/AlgorithmVisualizer#readme\n * @license MIT\n */\n(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o');\n\n var dragging = false;\n if (vertical) {\n (function () {\n $divider.addClass('vertical');\n\n var _left = -thickness / 2;\n $divider.css({\n top: 0,\n bottom: 0,\n left: _left,\n width: thickness\n });\n\n var x = void 0;\n $divider.mousedown(function (_ref) {\n var pageX = _ref.pageX;\n\n x = pageX;\n dragging = true;\n });\n\n $(document).mousemove(function (_ref2) {\n var pageX = _ref2.pageX;\n\n if (dragging) {\n var new_left = $second.position().left + pageX - x;\n var percent = new_left / $parent.width() * 100;\n percent = Math.min(90, Math.max(10, percent));\n $first.css('right', 100 - percent + '%');\n $second.css('left', percent + '%');\n x = pageX;\n appInstance.getTracerManager().resize();\n $('.files_bar > .wrapper').scroll();\n }\n });\n\n $(document).mouseup(function (e) {\n dragging = false;\n });\n })();\n } else {\n (function () {\n\n $divider.addClass('horizontal');\n var _top = -thickness / 2;\n $divider.css({\n top: _top,\n height: thickness,\n left: 0,\n right: 0\n });\n\n var y = void 0;\n $divider.mousedown(function (_ref3) {\n var pageY = _ref3.pageY;\n\n y = pageY;\n dragging = true;\n });\n\n $(document).mousemove(function (_ref4) {\n var pageY = _ref4.pageY;\n\n if (dragging) {\n var new_top = $second.position().top + pageY - y;\n var percent = new_top / $parent.height() * 100;\n percent = Math.min(90, Math.max(10, percent));\n $first.css('bottom', 100 - percent + '%');\n $second.css('top', percent + '%');\n y = pageY;\n appInstance.getTracerManager().resize();\n }\n });\n\n $(document).mouseup(function (e) {\n dragging = false;\n });\n })();\n }\n\n $second.append($divider);\n};\n\nmodule.exports = function () {\n var dividers = [['v', $('.sidemenu'), $('.workspace')], ['v', $('.viewer_container'), $('.editor_container')], ['h', $('.data_container'), $('.code_container')]];\n for (var i = 0; i < dividers.length; i++) {\n addDividerToDom(dividers[i]);\n }\n};\n\n},{\"../../app\":3}],7:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../../app');\n\nmodule.exports = function () {\n $(document).on('click', 'a', function (e) {\n e.preventDefault();\n\n if (!window.open($(undefined).attr('href'), '_blank')) {\n alert('Please allow popups for this site');\n }\n });\n\n $(document).mouseup(function (e) {\n appInstance.getTracerManager().command('mouseup', e);\n });\n};\n\n},{\"../../app\":3}],8:[function(require,module,exports){\n'use strict';\n\nvar definitelyBigger = function definitelyBigger(x, y) {\n return x > y + 2;\n};\n\nmodule.exports = function () {\n\n $('.files_bar > .btn-left').click(function () {\n var $wrapper = $('.files_bar > .wrapper');\n var clipWidth = $wrapper.width();\n var scrollLeft = $wrapper.scrollLeft();\n\n $($wrapper.children('button').get().reverse()).each(function () {\n var left = $(this).position().left;\n var right = left + $(this).outerWidth();\n if (0 > left) {\n $wrapper.scrollLeft(scrollLeft + right - clipWidth);\n return false;\n }\n });\n });\n\n $('.files_bar > .btn-right').click(function () {\n var $wrapper = $('.files_bar > .wrapper');\n var clipWidth = $wrapper.width();\n var scrollLeft = $wrapper.scrollLeft();\n\n $wrapper.children('button').each(function () {\n var left = $(this).position().left;\n var right = left + $(this).outerWidth();\n if (clipWidth < right) {\n $wrapper.scrollLeft(scrollLeft + left);\n return false;\n }\n });\n });\n\n $('.files_bar > .wrapper').scroll(function () {\n\n var $wrapper = $('.files_bar > .wrapper');\n var clipWidth = $wrapper.width();\n var $left = $wrapper.children('button:first-child');\n var $right = $wrapper.children('button:last-child');\n var left = $left.position().left;\n var right = $right.position().left + $right.outerWidth();\n\n if (definitelyBigger(0, left) && definitelyBigger(clipWidth, right)) {\n var scrollLeft = $wrapper.scrollLeft();\n $wrapper.scrollLeft(scrollLeft + clipWidth - right);\n return;\n }\n\n var lefter = definitelyBigger(0, left);\n var righter = definitelyBigger(right, clipWidth);\n $wrapper.toggleClass('shadow-left', lefter);\n $wrapper.toggleClass('shadow-right', righter);\n $('.files_bar > .btn-left').attr('disabled', !lefter);\n $('.files_bar > .btn-right').attr('disabled', !righter);\n });\n};\n\n},{}],9:[function(require,module,exports){\n'use strict';\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar appInstance = require('../../app');\nvar Toast = require('../toast');\n\nvar parseFloat = Number.parseFloat;\n\n\nvar minInterval = 0.1;\nvar maxInterval = 10;\nvar startInterval = 0.5;\nvar stepInterval = 0.1;\n\nvar normalize = function normalize(sec) {\n\n var interval = void 0;\n var message = void 0;\n if (sec < minInterval) {\n interval = minInterval;\n message = 'Interval of ' + sec + ' seconds is too low. Setting to min allowed interval of ' + minInterval + ' second(s).';\n } else if (sec > maxInterval) {\n interval = minInterval;\n message = 'Interval of ' + sec + ' seconds is too high. Setting to max allowed interval of ' + maxInterval + ' second(s).';\n } else {\n interval = sec;\n message = 'Interval has been set to ' + sec + ' second(s).';\n }\n\n return [interval, message];\n};\n\nmodule.exports = function () {\n\n var $interval = $('#interval');\n $interval.val(startInterval);\n $interval.attr({\n max: maxInterval,\n min: minInterval,\n step: stepInterval\n });\n\n $('#interval').on('change', function () {\n var tracerManager = appInstance.getTracerManager();\n\n var _normalize = normalize(parseFloat($(this).val()));\n\n var _normalize2 = _slicedToArray(_normalize, 2);\n\n var seconds = _normalize2[0];\n var message = _normalize2[1];\n\n\n $(this).val(seconds);\n tracerManager.interval = seconds * 1000;\n Toast.showInfoToast(message);\n });\n};\n\n},{\"../../app\":3,\"../toast\":21}],10:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../../app');\n\nmodule.exports = function () {\n\n var $module_container = $('.module_container');\n\n $module_container.on('mousedown', '.module_wrapper', function (e) {\n appInstance.getTracerManager().findOwner(this).mousedown(e);\n });\n\n $module_container.on('mousemove', '.module_wrapper', function (e) {\n appInstance.getTracerManager().findOwner(this).mousemove(e);\n });\n\n $module_container.on('DOMMouseScroll mousewheel', '.module_wrapper', function (e) {\n appInstance.getTracerManager().findOwner(this).mousewheel(e);\n });\n};\n\n},{\"../../app\":3}],11:[function(require,module,exports){\n'use strict';\n\nmodule.exports = function () {\n $('#powered-by').click(function () {\n $('#powered-by-list button').toggleClass('collapse');\n });\n};\n\n},{}],12:[function(require,module,exports){\n'use strict';\n\nvar Server = require('../../server');\nvar showAlgorithm = require('../show_algorithm');\n\nmodule.exports = function () {\n $('#scratch-paper').click(function () {\n var category = null;\n var algorithm = 'scratch_paper';\n Server.loadAlgorithm(category, algorithm).then(function (data) {\n showAlgorithm(category, algorithm, data);\n });\n });\n};\n\n},{\"../../server\":41,\"../show_algorithm\":16}],13:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../../app');\n\nvar sidemenu_percent = void 0;\n\nmodule.exports = function () {\n $('#navigation').click(function () {\n var $sidemenu = $('.sidemenu');\n var $workspace = $('.workspace');\n\n $sidemenu.toggleClass('active');\n $('.nav-dropdown').toggleClass('fa-caret-down fa-caret-up');\n\n if ($sidemenu.hasClass('active')) {\n $sidemenu.css('right', 100 - sidemenu_percent + '%');\n $workspace.css('left', sidemenu_percent + '%');\n } else {\n sidemenu_percent = $workspace.position().left / $('body').width() * 100;\n $sidemenu.css('right', 0);\n $workspace.css('left', 0);\n }\n\n appInstance.getTracerManager().resize();\n });\n};\n\n},{\"../../app\":3}],14:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../../app');\nvar Server = require('../../server');\nvar Toast = require('../toast');\n\nmodule.exports = function () {\n\n // shared\n $('#shared').mouseup(function () {\n $(this).select();\n });\n\n $('#btn_share').click(function () {\n\n var $icon = $(this).find('.fa-share');\n $icon.addClass('fa-spin fa-spin-faster');\n\n Server.shareScratchPaper().then(function (url) {\n $icon.removeClass('fa-spin fa-spin-faster');\n $('#shared').removeClass('collapse');\n $('#shared').val(url);\n Toast.showInfoToast('Shareable link is created.');\n });\n });\n\n // control\n\n $('#btn_run').click(function () {\n $('#btn_trace').click();\n var err = appInstance.getEditor().execute();\n if (err) {\n console.error(err);\n Toast.showErrorToast(err);\n }\n });\n $('#btn_pause').click(function () {\n if (appInstance.getTracerManager().isPause()) {\n appInstance.getTracerManager().resumeStep();\n } else {\n appInstance.getTracerManager().pauseStep();\n }\n });\n $('#btn_prev').click(function () {\n appInstance.getTracerManager().pauseStep();\n appInstance.getTracerManager().prevStep();\n });\n $('#btn_next').click(function () {\n appInstance.getTracerManager().pauseStep();\n appInstance.getTracerManager().nextStep();\n });\n\n // description & trace\n\n $('#btn_desc').click(function () {\n $('.tab_container > .tab').removeClass('active');\n $('#tab_desc').addClass('active');\n $('.tab_bar > button').removeClass('active');\n $(this).addClass('active');\n });\n\n $('#btn_trace').click(function () {\n $('.tab_container > .tab').removeClass('active');\n $('#tab_module').addClass('active');\n $('.tab_bar > button').removeClass('active');\n $(this).addClass('active');\n });\n};\n\n},{\"../../app\":3,\"../../server\":41,\"../toast\":21}],15:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../../app');\n\nmodule.exports = function () {\n $(window).resize(function () {\n appInstance.getTracerManager().resize();\n });\n};\n\n},{\"../../app\":3}],16:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../app');\n\nvar _require = require('../utils');\n\nvar isScratchPaper = _require.isScratchPaper;\n\n\nvar showDescription = require('./show_description');\nvar showFiles = require('./show_files');\n\nmodule.exports = function (category, algorithm, data) {\n var $menu = void 0;\n var category_name = void 0;\n var algorithm_name = void 0;\n\n if (isScratchPaper(category, algorithm)) {\n $menu = $('#scratch-paper');\n category_name = '';\n algorithm_name = 'Scratch Paper';\n } else {\n $menu = $('[data-category=\"' + category + '\"][data-algorithm=\"' + algorithm + '\"]');\n var categoryObj = appInstance.getCategory(category);\n category_name = categoryObj.name;\n algorithm_name = categoryObj.list[algorithm];\n }\n\n $('.sidemenu button').removeClass('active');\n $menu.addClass('active');\n $('#btn_desc').click();\n\n $('#category').html(category_name);\n $('#algorithm').html(algorithm_name);\n $('#tab_desc > .wrapper').empty();\n $('.files_bar > .wrapper').empty();\n $('#explanation').html('');\n\n appInstance.setLastFileUsed(null);\n appInstance.getEditor().clearContent();\n\n var files = data.files;\n\n\n delete data.files;\n\n showDescription(data);\n showFiles(category, algorithm, files);\n};\n\n},{\"../app\":3,\"../utils\":53,\"./show_description\":18,\"./show_files\":19}],17:[function(require,module,exports){\n'use strict';\n\nvar appInstance = require('../app');\nvar Server = require('../server');\nvar showAlgorithm = require('./show_algorithm');\n\nvar _$ = $;\nvar each = _$.each;\n\n\nvar addAlgorithmToCategoryDOM = function addAlgorithmToCategoryDOM(category, subList, algorithm) {\n var $algorithm = $('