{"version":3,"file":"ext-overview_window.js","sources":["../../../../src/editor/extensions/ext-overview_window/ext-overview_window.js"],"sourcesContent":["/**\n * @file ext-overview_window.js\n *\n * @license MIT\n *\n * @copyright 2013 James Sacksteder\n *\n */\nexport default {\n name: 'overview_window',\n init ({$, isChrome, isIE}) {\n const overviewWindowGlobals = {};\n // Disabled in Chrome 48-, see https://github.com/SVG-Edit/svgedit/issues/26 and\n // https://code.google.com/p/chromium/issues/detail?id=565120.\n if (isChrome()) {\n const verIndex = navigator.userAgent.indexOf('Chrome/') + 7;\n const chromeVersion = Number.parseInt(navigator.userAgent.substring(verIndex));\n if (chromeVersion < 49) {\n return undefined;\n }\n }\n\n // Define and insert the base html element.\n const propsWindowHtml =\n '
' +\n '
' +\n '
' +\n '' +\n ' ' +\n '' +\n '
' +\n '
' +\n '
' +\n '
' +\n '
';\n $('#sidepanels').append(propsWindowHtml);\n\n // Define dynamic animation of the view box.\n const updateViewBox = function () {\n const portHeight = Number.parseFloat($('#workarea').css('height'));\n const portWidth = Number.parseFloat($('#workarea').css('width'));\n const portX = $('#workarea').scrollLeft();\n const portY = $('#workarea').scrollTop();\n const windowWidth = Number.parseFloat($('#svgcanvas').css('width'));\n const windowHeight = Number.parseFloat($('#svgcanvas').css('height'));\n const overviewWidth = $('#overviewMiniView').attr('width');\n const overviewHeight = $('#overviewMiniView').attr('height');\n\n const viewBoxX = portX / windowWidth * overviewWidth;\n const viewBoxY = portY / windowHeight * overviewHeight;\n const viewBoxWidth = portWidth / windowWidth * overviewWidth;\n const viewBoxHeight = portHeight / windowHeight * overviewHeight;\n\n $('#overview_window_view_box').css('min-width', viewBoxWidth + 'px');\n $('#overview_window_view_box').css('min-height', viewBoxHeight + 'px');\n $('#overview_window_view_box').css('top', viewBoxY + 'px');\n $('#overview_window_view_box').css('left', viewBoxX + 'px');\n };\n $('#workarea').scroll(function () {\n if (!(overviewWindowGlobals.viewBoxDragging)) {\n updateViewBox();\n }\n });\n $('#workarea').resize(updateViewBox);\n updateViewBox();\n\n // Compensate for changes in zoom and canvas size.\n const updateViewDimensions = function () {\n const viewWidth = $('#svgroot').attr('width');\n const viewHeight = $('#svgroot').attr('height');\n\n let viewX = 640;\n let viewY = 480;\n if (isIE()) {\n // This has only been tested with Firefox 10 and IE 9 (without chrome frame).\n // I am not sure if if is Firefox or IE that is being non compliant here.\n // Either way the one that is noncompliant may become more compliant later.\n // TAG:HACK\n // TAG:VERSION_DEPENDENT\n // TAG:BROWSER_SNIFFING\n viewX = 0;\n viewY = 0;\n }\n\n const svgWidthOld = $('#overviewMiniView').attr('width');\n const svgHeightNew = viewHeight / viewWidth * svgWidthOld;\n $('#overviewMiniView').attr('viewBox', viewX + ' ' + viewY + ' ' + viewWidth + ' ' + viewHeight);\n $('#overviewMiniView').attr('height', svgHeightNew);\n updateViewBox();\n };\n updateViewDimensions();\n\n // Set up the overview window as a controller for the view port.\n overviewWindowGlobals.viewBoxDragging = false;\n const updateViewPortFromViewBox = function () {\n const windowWidth = Number.parseFloat($('#svgcanvas').css('width'));\n const windowHeight = Number.parseFloat($('#svgcanvas').css('height'));\n const overviewWidth = $('#overviewMiniView').attr('width');\n const overviewHeight = $('#overviewMiniView').attr('height');\n const viewBoxX = Number.parseFloat($('#overview_window_view_box').css('left'));\n const viewBoxY = Number.parseFloat($('#overview_window_view_box').css('top'));\n\n const portX = viewBoxX / overviewWidth * windowWidth;\n const portY = viewBoxY / overviewHeight * windowHeight;\n\n $('#workarea').scrollLeft(portX);\n $('#workarea').scrollTop(portY);\n };\n $('#overview_window_view_box').draggable({\n containment: 'parent',\n drag: updateViewPortFromViewBox,\n start () { overviewWindowGlobals.viewBoxDragging = true; },\n stop () { overviewWindowGlobals.viewBoxDragging = false; }\n });\n $('#overviewMiniView').click(function (evt) {\n // Firefox doesn't support evt.offsetX and evt.offsetY.\n const mouseX = (evt.offsetX || evt.originalEvent.layerX);\n const mouseY = (evt.offsetY || evt.originalEvent.layerY);\n const overviewWidth = $('#overviewMiniView').attr('width');\n const overviewHeight = $('#overviewMiniView').attr('height');\n const viewBoxWidth = Number.parseFloat($('#overview_window_view_box').css('min-width'));\n const viewBoxHeight = Number.parseFloat($('#overview_window_view_box').css('min-height'));\n\n let viewBoxX = mouseX - 0.5 * viewBoxWidth;\n let viewBoxY = mouseY - 0.5 * viewBoxHeight;\n // deal with constraints\n if (viewBoxX < 0) {\n viewBoxX = 0;\n }\n if (viewBoxY < 0) {\n viewBoxY = 0;\n }\n if (viewBoxX + viewBoxWidth > overviewWidth) {\n viewBoxX = overviewWidth - viewBoxWidth;\n }\n if (viewBoxY + viewBoxHeight > overviewHeight) {\n viewBoxY = overviewHeight - viewBoxHeight;\n }\n\n $('#overview_window_view_box').css('top', viewBoxY + 'px');\n $('#overview_window_view_box').css('left', viewBoxX + 'px');\n updateViewPortFromViewBox();\n });\n\n return {\n name: 'overview window',\n canvasUpdated: updateViewDimensions,\n workareaResized: updateViewBox\n };\n }\n};\n"],"names":["name","init","$","isChrome","isIE","overviewWindowGlobals","verIndex","navigator","userAgent","indexOf","Number","parseInt","substring","append","updateViewBox","portHeight","parseFloat","css","portWidth","portX","scrollLeft","portY","scrollTop","windowWidth","windowHeight","overviewWidth","attr","overviewHeight","viewBoxX","viewBoxY","viewBoxWidth","viewBoxHeight","scroll","viewBoxDragging","resize","updateViewDimensions","viewWidth","viewHeight","viewX","viewY","svgHeightNew","updateViewPortFromViewBox","draggable","containment","drag","start","stop","click","evt","mouseX","offsetX","originalEvent","layerX","mouseY","offsetY","layerY","canvasUpdated","workareaResized"],"mappings":";;;;;;;;AAQA,MAAe,CACbA,KAAM,kBACNC,0BAAOC,IAAAA,EAAGC,IAAAA,SAAUC,IAAAA,KACZC,EAAwB,MAG1BF,IAAY,KACRG,EAAWC,UAAUC,UAAUC,QAAQ,WAAa,KACpCC,OAAOC,SAASJ,UAAUC,UAAUI,UAAUN,IAChD,UA0BtBJ,EAAE,eAAeW,OAnBf,wrBAsBIC,EAAgB,SAAhBA,oBACEC,EAAaL,OAA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