mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-15 18:08:21 +01:00
1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
{"version":3,"file":"ext-overview_window.js","sources":["../../../../src/editor/extensions/ext-overview_window/dragmove/dragmove.js","../../../../src/editor/extensions/ext-overview_window/ext-overview_window.js"],"sourcesContent":["// https://github.com/knadh/dragmove.js\n// Kailash Nadh (c) 2020.\n// MIT License.\n// can't use npm version as the dragmove is different.\n\nlet _loaded = false\nconst _callbacks = []\nconst _isTouch = window.ontouchstart !== undefined\n\nexport const dragmove = function (target, handler, parent, onStart, onEnd, onDrag) {\n // Register a global event to capture mouse moves (once).\n if (!_loaded) {\n document.addEventListener(_isTouch ? 'touchmove' : 'mousemove', function (e) {\n let c = e\n if (e.touches) {\n c = e.touches[0]\n }\n\n // On mouse move, dispatch the coords to all registered callbacks.\n for (let i = 0; i < _callbacks.length; i++) {\n _callbacks[i](c.clientX, c.clientY)\n }\n })\n }\n\n _loaded = true\n let isMoving = false; let hasStarted = false\n let startX = 0; let startY = 0; let lastX = 0; let lastY = 0\n\n // On the first click and hold, record the offset of the pointer in relation\n // to the point of click inside the element.\n handler.addEventListener(_isTouch ? 'touchstart' : 'mousedown', function (e) {\n e.stopPropagation()\n e.preventDefault()\n if (target.dataset.dragEnabled === 'false') {\n return\n }\n\n let c = e\n if (e.touches) {\n c = e.touches[0]\n }\n\n isMoving = true\n startX = target.offsetLeft - c.clientX\n startY = target.offsetTop - c.clientY\n })\n\n // On leaving click, stop moving.\n document.addEventListener(_isTouch ? 'touchend' : 'mouseup', function () {\n if (onEnd && hasStarted) {\n onEnd(target, parent, parseInt(target.style.left), parseInt(target.style.top))\n }\n\n isMoving = false\n hasStarted = false\n })\n\n // On leaving click, stop moving.\n document.addEventListener(_isTouch ? 'touchmove' : 'mousemove', function () {\n if (onDrag && hasStarted) {\n onDrag(target, parseInt(target.style.left), parseInt(target.style.top))\n }\n })\n\n // Register mouse-move callback to move the element.\n _callbacks.push(function move (x, y) {\n if (!isMoving) {\n return\n }\n\n if (!hasStarted) {\n hasStarted = true\n if (onStart) {\n onStart(target, lastX, lastY)\n }\n }\n\n lastX = x + startX\n lastY = y + startY\n\n // If boundary checking is on, don't let the element cross the viewport.\n if (target.dataset.dragBoundary === 'true') {\n if (lastX < 1 || lastX >= window.innerWidth - target.offsetWidth) {\n return\n }\n if (lastY < 1 || lastY >= window.innerHeight - target.offsetHeight) {\n return\n }\n }\n\n target.style.left = lastX + 'px'\n target.style.top = lastY + 'px'\n })\n}\n\nexport { dragmove as default }\n","/**\n * @file ext-overview_window.js\n *\n * @license MIT\n *\n * @copyright 2013 James Sacksteder\n *\n */\nimport { dragmove } from './dragmove/dragmove.js'\n\nexport default {\n name: 'overview_window',\n init ({ _$ }) {\n const svgEditor = this\n const { $id, $click } = svgEditor.svgCanvas\n const overviewWindowGlobals = {}\n\n // Define and insert the base html element.\n const propsWindowHtml =\n '<div id=\"overview_window_content_pane\" style=\"width:100%; word-wrap:break-word; display:inline-block; margin-top:20px;\">' +\n '<div id=\"overview_window_content\" style=\"position:relative; padding-left:15px; top:0px;\">' +\n '<div style=\"background-color:#A0A0A0; display:inline-block; overflow:visible;\">' +\n '<svg id=\"overviewMiniView\" width=\"132\" height=\"100\" x=\"0\" y=\"0\" viewBox=\"0 0 4800 3600\" ' +\n 'xmlns=\"http://www.w3.org/2000/svg\" ' +\n 'xmlns:xlink=\"http://www.w3.org/1999/xlink\">' +\n '<use x=\"0\" y=\"0\" xlink:href=\"#svgroot\"> </use>' +\n '</svg>' +\n '<div id=\"overview_window_view_box\" style=\"min-width:50px; min-height:50px; position:absolute; top:30px; left:30px; z-index:5; background-color:rgba(255,0,102,0.3);\">' +\n '</div>' +\n '</div>' +\n '</div>' +\n '</div>'\n $id('sidepanel_content').insertAdjacentHTML('beforeend', propsWindowHtml)\n\n // Define dynamic animation of the view box.\n const updateViewBox = () => {\n const { workarea } = svgEditor\n const portHeight = parseFloat(getComputedStyle(workarea, null).height.replace('px', ''))\n const portWidth = parseFloat(getComputedStyle(workarea, null).width.replace('px', ''))\n const portX = workarea.scrollLeft\n const portY = workarea.scrollTop\n const windowWidth = parseFloat(getComputedStyle($id('svgcanvas'), null).width.replace('px', ''))\n const windowHeight = parseFloat(getComputedStyle($id('svgcanvas'), null).height.replace('px', ''))\n const overviewWidth = parseFloat(getComputedStyle($id('overviewMiniView'), null).width.replace('px', ''))\n const overviewHeight = parseFloat(getComputedStyle($id('overviewMiniView'), null).height.replace('px', ''))\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 $id('overview_window_view_box').style.minWidth = viewBoxWidth + 'px'\n $id('overview_window_view_box').style.minHeight = viewBoxHeight + 'px'\n $id('overview_window_view_box').style.top = viewBoxY + 'px'\n $id('overview_window_view_box').style.left = viewBoxX + 'px'\n }\n $id('workarea').addEventListener('scroll', () => {\n if (!(overviewWindowGlobals.viewBoxDragging)) {\n updateViewBox()\n }\n })\n $id('workarea').addEventListener('resize', updateViewBox)\n updateViewBox()\n\n // Compensate for changes in zoom and canvas size.\n const updateViewDimensions = function () {\n const viewWidth = parseFloat(getComputedStyle($id('svgroot'), null).width.replace('px', ''))\n const viewHeight = parseFloat(getComputedStyle($id('svgroot'), null).height.replace('px', ''))\n\n const viewX = 640\n const viewY = 480\n\n const svgWidthOld = parseFloat(getComputedStyle($id('overviewMiniView'), null).width.replace('px', ''))\n const svgHeightNew = viewHeight / viewWidth * svgWidthOld\n $id('overviewMiniView').setAttribute('viewBox', viewX + ' ' + viewY + ' ' + viewWidth + ' ' + viewHeight)\n $id('overviewMiniView').setAttribute('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 = parseFloat(getComputedStyle($id('svgcanvas'), null).width.replace('px', ''))\n const windowHeight = parseFloat(getComputedStyle($id('svgcanvas'), null).height.replace('px', ''))\n const overviewWidth = parseFloat(getComputedStyle($id('overviewMiniView'), null).width.replace('px', ''))\n const overviewHeight = parseFloat(getComputedStyle($id('overviewMiniView'), null).height.replace('px', ''))\n const viewBoxX = parseFloat(getComputedStyle($id('overview_window_view_box'), null).getPropertyValue('left').replace('px', ''))\n const viewBoxY = parseFloat(getComputedStyle($id('overview_window_view_box'), null).getPropertyValue('top').replace('px', ''))\n\n const portX = viewBoxX / overviewWidth * windowWidth\n const portY = viewBoxY / overviewHeight * windowHeight\n $id('workarea').scrollLeft = portX\n $id('workarea').scrollTop = portY\n }\n const onStart = () => {\n overviewWindowGlobals.viewBoxDragging = true\n updateViewPortFromViewBox()\n }\n const onEnd = (el, parent, _x, _y) => {\n if ((el.offsetLeft + el.offsetWidth) > parseFloat(getComputedStyle(parent, null).width.replace('px', ''))) {\n el.style.left = (parseFloat(getComputedStyle(parent, null).width.replace('px', '')) - el.offsetWidth) + 'px'\n } else if (el.offsetLeft < 0) {\n el.style.left = '0px'\n }\n if ((el.offsetTop + el.offsetHeight) > parseFloat(getComputedStyle(parent, null).height.replace('px', ''))) {\n el.style.top = (parseFloat(getComputedStyle(parent, null).height.replace('px', '')) - el.offsetHeight) + 'px'\n } else if (el.offsetTop < 0) {\n el.style.top = '0px'\n }\n overviewWindowGlobals.viewBoxDragging = false\n updateViewPortFromViewBox()\n }\n const onDrag = function () {\n updateViewPortFromViewBox()\n }\n const dragElem = document.querySelector('#overview_window_view_box')\n const parentElem = document.querySelector('#overviewMiniView')\n dragmove(dragElem, dragElem, parentElem, onStart, onEnd, onDrag)\n\n $click($id('overviewMiniView'), (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 = parseFloat(getComputedStyle($id('overviewMiniView'), null).width.replace('px', ''))\n const overviewHeight = parseFloat(getComputedStyle($id('overviewMiniView'), null).height.replace('px', ''))\n const viewBoxWidth = parseFloat(getComputedStyle($id('overview_window_view_box'), null).getPropertyValue('min-width').replace('px', ''))\n const viewBoxHeight = parseFloat(getComputedStyle($id('overview_window_view_box'), null).getPropertyValue('min-height').replace('px', ''))\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 $id('overview_window_view_box').style.top = viewBoxY + 'px'\n $id('overview_window_view_box').style.left = viewBoxX + 'px'\n updateViewPortFromViewBox()\n })\n\n return {\n name: 'overview window',\n canvasUpdated: updateViewDimensions,\n workareaResized: updateViewBox\n }\n }\n}\n"],"names":["_loaded","_callbacks","_isTouch","undefined","window","ontouchstart","extOverview_window","name","init","_ref","svgEditor","this","$id","$click","svgCanvas","overviewWindowGlobals","insertAdjacentHTML","updateViewBox","workarea","portHeight","parseFloat","getComputedStyle","height","replace","portWidth","width","portX","scrollLeft","portY","scrollTop","windowWidth","windowHeight","overviewWidth","overviewHeight","viewBoxX","viewBoxY","viewBoxWidth","viewBoxHeight","style","minWidth","minHeight","top","left","addEventListener","viewBoxDragging","updateViewDimensions","viewWidth","viewHeight","svgHeightNew","setAttribute","viewX","updateViewPortFromViewBox","getPropertyValue","dragElem","document","querySelector","target","handler","parent","onStart","onEnd","onDrag","e","c","touches","i","length","clientX","clientY","isMoving","hasStarted","startX","startY","lastX","lastY","stopPropagation","preventDefault","dataset","dragEnabled","offsetLeft","offsetTop","parseInt","push","move","x","y","dragBoundary","innerWidth","offsetWidth","innerHeight","offsetHeight","dragmove","el","_x","_y","evt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