[mod] gitignore xqdoc
This commit is contained in:
parent
d9f80cc9c4
commit
52942a5ce1
30 changed files with 30 additions and 3557 deletions
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Ulrich-Matthias Schäfer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
# svg.panzoom.js
|
||||
|
||||
> A plugin for [svg.js](https://github.com/svgdotjs/svg.js) that enables panzoom for svg elements
|
||||
|
||||
## Getting started
|
||||
|
||||
```
|
||||
npm install @svgdotjs/svg.js @svgdotjs/svg.panzoom.js
|
||||
```
|
||||
|
||||
Include this plugin after including the svg.js library in your html document.
|
||||
|
||||
```
|
||||
<script src="node_modules/@svgdotjs/svg.js/dist/svg.js"></script>
|
||||
<script src="node_modules/@svgdotjs/svg.panzoom.js/dist/svg.panzoom.js"></script>
|
||||
```
|
||||
|
||||
Or for esm just import it:
|
||||
|
||||
```
|
||||
import { SVG } from '@svgdotjs/svg.js'
|
||||
import '@svgdotjs/svg.panzoom.js'
|
||||
```
|
||||
|
||||
To enable pan/zoom on an svg:
|
||||
|
||||
```js
|
||||
// enables panZoom
|
||||
var canvas = SVG()
|
||||
.addTo('#id')
|
||||
.size(1000, 1000)
|
||||
.panZoom()
|
||||
|
||||
// zoom programatically
|
||||
canvas.zoom(lvl, point)
|
||||
```
|
||||
|
||||
You can configure `panZoom` by passing options to it.
|
||||
|
||||
- zoomMin: Minimal zoom level
|
||||
- zoomMax: Maximal zoom level
|
||||
- zoomFactor: How much is zoomed by one mouse wheel step
|
||||
|
||||
This could look like this:
|
||||
|
||||
```js
|
||||
var canvas = SVG()
|
||||
.addTo('#id')
|
||||
.size(1000, 1000)
|
||||
.panZoom({ zoomMin: 0.5, zoomMax: 20 })
|
||||
```
|
||||
|
||||
Setting the min and max value will automatically restrict the zoom to the provided level.
|
||||
However you are still able to change the zoom out of that bonds by calling `zoom(lvl)` programatically.
|
||||
|
||||
On touchable devices a pinchZoom gesture is supported. Min and max values also apply here.
|
||||
|
||||
Zooming is animatable, too:
|
||||
|
||||
```js
|
||||
canvas
|
||||
.zoom(1) // uses center of viewport by default
|
||||
.animate()
|
||||
.zoom(2, { x: 100, y: 100 }) // zoom into specified point
|
||||
```
|
||||
|
||||
To disable `panZoom` or change its options just call it again with `false` or the new options.
|
||||
|
||||
## Options
|
||||
|
||||
You can override the default options by passing an object in to the `.panZoom({options})` call.
|
||||
|
||||
| Option | Default | Description |
|
||||
| ------------ | ---------------- | -------------------------------------------------------------------------------------------------------------- |
|
||||
| panning | true | Enable panning |
|
||||
| pinchZoom | true | Enable pinch to zoom |
|
||||
| wheelZoom | true | Enable mouse wheel zoom |
|
||||
| panButton | 0 | Which mouse button to use for pan ([info](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button)) |
|
||||
| oneFingerPan | false | Enables the ability to pan with only one finger instead of two for touchdevices |
|
||||
| margins | false | An object {top, left, right, bottom} to restrict the pan area towards this side so that at least x user units of the opposite side are still visible |
|
||||
| zoomFactor | 2 | How quickly to zoom when using `wheelZoom` |
|
||||
| zoomMin | Number.MIN_VALUE | The minimum zoom level |
|
||||
| zoomMax | Number.MAX_VALUE | The maximum zoom level |
|
||||
| wheelZoomDeltaModeLinePixels | 17 | The multiplier to convert wheel zoom deltaY values from deltaMode=1 (lines) to deltaMode=0 (pixels) |
|
||||
| wheelZoomDeltaModeScreenPixels | 53 | The multiplier to convert wheel zoom deltaY values from deltaMode=2 (screen) to deltaMode=0 (pixels) |
|
||||
|
||||
### Example:
|
||||
|
||||
```js
|
||||
draw.panZoom({
|
||||
wheelZoom: false,
|
||||
zoomMin: 0.5,
|
||||
zoomMax: 2
|
||||
})
|
||||
```
|
||||
|
||||
This will disable wheel zooming and set the maximum zoom to 2 or 200% and the minimum zoom to 0.5 or 50%.
|
||||
|
||||
## Events
|
||||
|
||||
Multiple events are fired doing different actions. This allow you to respond
|
||||
to actions and in some cases stop an action via `preventDefault()`.
|
||||
|
||||
`zoom` is fired when a mouse wheel event or programmable `zoom()` triggers
|
||||
a zoom. This usually doesn't happen on mobile devices, in which case
|
||||
`pinchZoomStart` is fired when a zoom happens.
|
||||
|
||||
Events fired from SVG.js are [`CustomEvent`s](http://devdocs.io/dom/customevent),
|
||||
so the arguments passed from svg.panzoom.js are in in the `.detail` property.
|
||||
|
||||
| Event Name | Argument Value | preventDefault support |
|
||||
| -------------- | ---------------- | ---------------------- |
|
||||
| zoom | `{ lvl, focus }` | YES |
|
||||
| panStart | `{ event }` | NO |
|
||||
| panEnd | `{ event }` | NO |
|
||||
| panning | `{ box }` | YES |
|
||||
| pinchZoomStart | `{ event }` | YES |
|
||||
| pinchZoomEnd | `{ event }` | NO |
|
||||
|
||||
Where `lvl` is the new zoom level,
|
||||
[`focus`](https://svgjs.com/docs/3.0/classes/#svg-point) is th point of zoom, [`box`](https://svgjs.com/docs/3.0/classes/#svg-box) is the new calculated viewbox
|
||||
and event is the event that triggered the action.
|
||||
|
||||
An example of stopping a pinch-zoom action:
|
||||
|
||||
```js
|
||||
var canvas = SVG()
|
||||
.addTo('#id')
|
||||
.size(1000, 1000)
|
||||
.panZoom()
|
||||
|
||||
canvas.on('pinchZoomStart', function (ev) {
|
||||
ev.preventDefault()
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
|
@ -1,372 +0,0 @@
|
|||
/*!
|
||||
* @svgdotjs/svg.panzoom.js - A plugin for svg.js that enables panzoom for viewport elements
|
||||
* @version 2.1.2
|
||||
* https://github.com/svgdotjs/svg.panzoom.js#readme
|
||||
*
|
||||
* @copyright undefined
|
||||
* @license MIT
|
||||
*
|
||||
* BUILT: Thu Jul 22 2021 14:51:35 GMT+0200 (Mitteleuropäische Sommerzeit)
|
||||
*/;
|
||||
(function (svg_js) {
|
||||
'use strict';
|
||||
|
||||
var normalizeEvent = function normalizeEvent(ev) {
|
||||
return ev.touches || [{
|
||||
clientX: ev.clientX,
|
||||
clientY: ev.clientY
|
||||
}];
|
||||
};
|
||||
|
||||
svg_js.extend(svg_js.Svg, {
|
||||
panZoom: function panZoom(options) {
|
||||
var _options,
|
||||
_options$zoomFactor,
|
||||
_options$zoomMin,
|
||||
_options$zoomMax,
|
||||
_options$wheelZoom,
|
||||
_options$pinchZoom,
|
||||
_options$panning,
|
||||
_options$panButton,
|
||||
_options$oneFingerPan,
|
||||
_options$margins,
|
||||
_options$wheelZoomDel,
|
||||
_options$wheelZoomDel2,
|
||||
_this = this;
|
||||
|
||||
this.off('.panZoom'); // when called with false, disable panZoom
|
||||
|
||||
if (options === false) return this;
|
||||
options = (_options = options) != null ? _options : {};
|
||||
var zoomFactor = (_options$zoomFactor = options.zoomFactor) != null ? _options$zoomFactor : 2;
|
||||
var zoomMin = (_options$zoomMin = options.zoomMin) != null ? _options$zoomMin : Number.MIN_VALUE;
|
||||
var zoomMax = (_options$zoomMax = options.zoomMax) != null ? _options$zoomMax : Number.MAX_VALUE;
|
||||
var doWheelZoom = (_options$wheelZoom = options.wheelZoom) != null ? _options$wheelZoom : true;
|
||||
var doPinchZoom = (_options$pinchZoom = options.pinchZoom) != null ? _options$pinchZoom : true;
|
||||
var doPanning = (_options$panning = options.panning) != null ? _options$panning : true;
|
||||
var panButton = (_options$panButton = options.panButton) != null ? _options$panButton : 0;
|
||||
var oneFingerPan = (_options$oneFingerPan = options.oneFingerPan) != null ? _options$oneFingerPan : false;
|
||||
var margins = (_options$margins = options.margins) != null ? _options$margins : false;
|
||||
var wheelZoomDeltaModeLinePixels = (_options$wheelZoomDel = options.wheelZoomDeltaModeLinePixels) != null ? _options$wheelZoomDel : 17;
|
||||
var wheelZoomDeltaModeScreenPixels = (_options$wheelZoomDel2 = options.wheelZoomDeltaModeScreenPixels) != null ? _options$wheelZoomDel2 : 53;
|
||||
var lastP;
|
||||
var lastTouches;
|
||||
var zoomInProgress = false;
|
||||
var viewbox = this.viewbox();
|
||||
|
||||
var restrictToMargins = function restrictToMargins(box) {
|
||||
if (!margins) return box;
|
||||
var top = margins.top,
|
||||
left = margins.left,
|
||||
bottom = margins.bottom,
|
||||
right = margins.right;
|
||||
|
||||
var _this$attr = _this.attr(['width', 'height']),
|
||||
width = _this$attr.width,
|
||||
height = _this$attr.height;
|
||||
|
||||
var preserveAspectRatio = _this.node.preserveAspectRatio.baseVal; // The current viewport (exactly what is shown on the screen, what we ultimately want to restrict)
|
||||
// is not always exactly the same as current viewbox. They are different when the viewbox aspectRatio and the svg aspectRatio
|
||||
// are different and preserveAspectRatio is not "none". These offsets represent the difference in user coordinates
|
||||
// between the side of the viewbox and the side of the viewport.
|
||||
|
||||
var viewportLeftOffset = 0;
|
||||
var viewportRightOffset = 0;
|
||||
var viewportTopOffset = 0;
|
||||
var viewportBottomOffset = 0; // preserveAspectRatio none has no offsets
|
||||
|
||||
if (preserveAspectRatio.align !== preserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE) {
|
||||
var svgAspectRatio = width / height;
|
||||
var viewboxAspectRatio = viewbox.width / viewbox.height; // when aspectRatios are the same, there are no offsets
|
||||
|
||||
if (viewboxAspectRatio !== svgAspectRatio) {
|
||||
// aspectRatio unknown is like meet because that's the default
|
||||
var isMeet = preserveAspectRatio.meetOrSlice !== preserveAspectRatio.SVG_MEETORSLICE_SLICE;
|
||||
var changedAxis = svgAspectRatio > viewboxAspectRatio ? 'width' : 'height';
|
||||
var isWidth = changedAxis === 'width';
|
||||
var changeHorizontal = isMeet && isWidth || !isMeet && !isWidth;
|
||||
var ratio = changeHorizontal ? svgAspectRatio / viewboxAspectRatio : viewboxAspectRatio / svgAspectRatio;
|
||||
var offset = box[changedAxis] - box[changedAxis] * ratio;
|
||||
|
||||
if (changeHorizontal) {
|
||||
if (preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMAX) {
|
||||
viewportLeftOffset = offset / 2;
|
||||
viewportRightOffset = -offset / 2;
|
||||
} else if (preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMID || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMAX) {
|
||||
viewportRightOffset = -offset;
|
||||
} else if (preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMAX) {
|
||||
viewportLeftOffset = offset;
|
||||
}
|
||||
} else {
|
||||
if (preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMID || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID) {
|
||||
viewportTopOffset = offset / 2;
|
||||
viewportBottomOffset = -offset / 2;
|
||||
} else if (preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN) {
|
||||
viewportBottomOffset = -offset;
|
||||
} else if (preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMAX || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMAX || preserveAspectRatio.align === preserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMAX) {
|
||||
viewportTopOffset = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // when box.x == leftLimit, the image is panned to the left,
|
||||
// i.e the current box is to the right of the initial viewbox,
|
||||
// and only the right part of the initial image is visible, i.e.
|
||||
// the right side of the initial viewbox minus left margin (viewbox.x+viewbox.width-left)
|
||||
// is aligned with the left side of the viewport (box.x + viewportLeftOffset):
|
||||
// viewbox.width + viewbox.x - left = box.x + viewportLeftOffset
|
||||
// viewbox.width + viewbox.x - left - viewportLeftOffset = box.x (= leftLimit)
|
||||
|
||||
|
||||
var leftLimit = viewbox.width + viewbox.x - left - viewportLeftOffset; // when box.x == rightLimit, the image is panned to the right,
|
||||
// i.e the current box is to the left of the initial viewbox
|
||||
// and only the left part of the initial image is visible, i.e
|
||||
// the left side of the initial viewbox plus right margin (viewbox.x + right)
|
||||
// is aligned with the right side of the viewport (box.x + box.width + viewportRightOffset)
|
||||
// viewbox.x + right = box.x + box.width + viewportRightOffset
|
||||
// viewbox.x + right - box.width - viewportRightOffset = box.x (= rightLimit)
|
||||
|
||||
var rightLimit = viewbox.x + right - box.width - viewportRightOffset; // same with top and bottom
|
||||
|
||||
var topLimit = viewbox.height + viewbox.y - top - viewportTopOffset;
|
||||
var bottomLimit = viewbox.y + bottom - box.height - viewportBottomOffset;
|
||||
box.x = Math.min(leftLimit, Math.max(rightLimit, box.x)); // enforce rightLimit <= box.x <= leftLimit
|
||||
|
||||
box.y = Math.min(topLimit, Math.max(bottomLimit, box.y)); // enforce bottomLimit <= box.y <= topLimit
|
||||
|
||||
return box;
|
||||
};
|
||||
|
||||
var wheelZoom = function wheelZoom(ev) {
|
||||
ev.preventDefault(); // When wheeling on a mouse,
|
||||
// - chrome by default uses deltaY = 53, deltaMode = 0 (pixel)
|
||||
// - firefox by default uses deltaY = 3, deltaMode = 1 (line)
|
||||
// - chrome and firefox on windows after configuring "One screen at a time"
|
||||
// use deltaY = 1, deltaMode = 2 (screen)
|
||||
//
|
||||
// Note that when when wheeling on a touchpad, deltaY depends on how fast
|
||||
// you swipe, but the deltaMode is still different between the browsers.
|
||||
//
|
||||
// Normalize everything so that zooming speed is approximately the same in all cases
|
||||
|
||||
var normalizedPixelDeltaY;
|
||||
|
||||
switch (ev.deltaMode) {
|
||||
case 1:
|
||||
normalizedPixelDeltaY = ev.deltaY * wheelZoomDeltaModeLinePixels;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
normalizedPixelDeltaY = ev.deltaY * wheelZoomDeltaModeScreenPixels;
|
||||
break;
|
||||
|
||||
default:
|
||||
// 0 (already pixels) or new mode (avoid crashing)
|
||||
normalizedPixelDeltaY = ev.deltaY;
|
||||
break;
|
||||
}
|
||||
|
||||
var lvl = Math.pow(1 + zoomFactor, -1 * normalizedPixelDeltaY / 100) * this.zoom();
|
||||
var p = this.point(ev.clientX, ev.clientY);
|
||||
|
||||
if (lvl > zoomMax) {
|
||||
lvl = zoomMax;
|
||||
}
|
||||
|
||||
if (lvl < zoomMin) {
|
||||
lvl = zoomMin;
|
||||
}
|
||||
|
||||
if (this.dispatch('zoom', {
|
||||
level: lvl,
|
||||
focus: p
|
||||
}).defaultPrevented) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.zoom(lvl, p);
|
||||
|
||||
if (margins) {
|
||||
var box = restrictToMargins(this.viewbox());
|
||||
this.viewbox(box);
|
||||
}
|
||||
};
|
||||
|
||||
var pinchZoomStart = function pinchZoomStart(ev) {
|
||||
lastTouches = normalizeEvent(ev); // Start panning in case only one touch is found
|
||||
|
||||
if (lastTouches.length < 2) {
|
||||
if (doPanning && oneFingerPan) {
|
||||
panStart.call(this, ev);
|
||||
}
|
||||
|
||||
return;
|
||||
} // Stop panning for more than one touch
|
||||
|
||||
|
||||
if (doPanning && oneFingerPan) {
|
||||
panStop.call(this, ev);
|
||||
} // We call it so late, so the user is still able to scroll / reload the page via gesture
|
||||
// In case oneFingerPan is not active
|
||||
|
||||
|
||||
ev.preventDefault();
|
||||
|
||||
if (this.dispatch('pinchZoomStart', {
|
||||
event: ev
|
||||
}).defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.off('touchstart.panZoom', pinchZoomStart);
|
||||
zoomInProgress = true;
|
||||
svg_js.on(document, 'touchmove.panZoom', pinchZoom, this, {
|
||||
passive: false
|
||||
});
|
||||
svg_js.on(document, 'touchend.panZoom', pinchZoomStop, this, {
|
||||
passive: false
|
||||
});
|
||||
};
|
||||
|
||||
var pinchZoomStop = function pinchZoomStop(ev) {
|
||||
ev.preventDefault();
|
||||
var currentTouches = normalizeEvent(ev);
|
||||
|
||||
if (currentTouches.length > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
zoomInProgress = false;
|
||||
this.dispatch('pinchZoomEnd', {
|
||||
event: ev
|
||||
});
|
||||
svg_js.off(document, 'touchmove.panZoom', pinchZoom);
|
||||
svg_js.off(document, 'touchend.panZoom', pinchZoomStop);
|
||||
this.on('touchstart.panZoom', pinchZoomStart);
|
||||
|
||||
if (currentTouches.length && doPanning && oneFingerPan) {
|
||||
panStart.call(this, ev);
|
||||
}
|
||||
};
|
||||
|
||||
var pinchZoom = function pinchZoom(ev) {
|
||||
ev.preventDefault();
|
||||
var currentTouches = normalizeEvent(ev);
|
||||
var zoom = this.zoom(); // Distance Formula
|
||||
|
||||
var lastDelta = Math.sqrt(Math.pow(lastTouches[0].clientX - lastTouches[1].clientX, 2) + Math.pow(lastTouches[0].clientY - lastTouches[1].clientY, 2));
|
||||
var currentDelta = Math.sqrt(Math.pow(currentTouches[0].clientX - currentTouches[1].clientX, 2) + Math.pow(currentTouches[0].clientY - currentTouches[1].clientY, 2));
|
||||
var zoomAmount = lastDelta / currentDelta;
|
||||
|
||||
if (zoom < zoomMin && zoomAmount > 1 || zoom > zoomMax && zoomAmount < 1) {
|
||||
zoomAmount = 1;
|
||||
}
|
||||
|
||||
var currentFocus = {
|
||||
x: currentTouches[0].clientX + 0.5 * (currentTouches[1].clientX - currentTouches[0].clientX),
|
||||
y: currentTouches[0].clientY + 0.5 * (currentTouches[1].clientY - currentTouches[0].clientY)
|
||||
};
|
||||
var lastFocus = {
|
||||
x: lastTouches[0].clientX + 0.5 * (lastTouches[1].clientX - lastTouches[0].clientX),
|
||||
y: lastTouches[0].clientY + 0.5 * (lastTouches[1].clientY - lastTouches[0].clientY)
|
||||
};
|
||||
var p = this.point(currentFocus.x, currentFocus.y);
|
||||
var focusP = this.point(2 * currentFocus.x - lastFocus.x, 2 * currentFocus.y - lastFocus.y);
|
||||
var box = new svg_js.Box(this.viewbox()).transform(new svg_js.Matrix().translate(-focusP.x, -focusP.y).scale(zoomAmount, 0, 0).translate(p.x, p.y));
|
||||
restrictToMargins(box);
|
||||
this.viewbox(box);
|
||||
lastTouches = currentTouches;
|
||||
this.dispatch('zoom', {
|
||||
box: box,
|
||||
focus: focusP
|
||||
});
|
||||
};
|
||||
|
||||
var panStart = function panStart(ev) {
|
||||
var isMouse = ev.type.indexOf('mouse') > -1; // In case panStart is called with touch, ev.button is undefined
|
||||
|
||||
if (isMouse && ev.button !== panButton && ev.which !== panButton + 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
ev.preventDefault();
|
||||
this.off('mousedown.panZoom', panStart);
|
||||
lastTouches = normalizeEvent(ev);
|
||||
if (zoomInProgress) return;
|
||||
this.dispatch('panStart', {
|
||||
event: ev
|
||||
});
|
||||
lastP = {
|
||||
x: lastTouches[0].clientX,
|
||||
y: lastTouches[0].clientY
|
||||
};
|
||||
svg_js.on(document, 'touchmove.panZoom mousemove.panZoom', panning, this, {
|
||||
passive: false
|
||||
});
|
||||
svg_js.on(document, 'touchend.panZoom mouseup.panZoom', panStop, this, {
|
||||
passive: false
|
||||
});
|
||||
};
|
||||
|
||||
var panStop = function panStop(ev) {
|
||||
ev.preventDefault();
|
||||
svg_js.off(document, 'touchmove.panZoom mousemove.panZoom', panning);
|
||||
svg_js.off(document, 'touchend.panZoom mouseup.panZoom', panStop);
|
||||
this.on('mousedown.panZoom', panStart);
|
||||
this.dispatch('panEnd', {
|
||||
event: ev
|
||||
});
|
||||
};
|
||||
|
||||
var panning = function panning(ev) {
|
||||
ev.preventDefault();
|
||||
var currentTouches = normalizeEvent(ev);
|
||||
var currentP = {
|
||||
x: currentTouches[0].clientX,
|
||||
y: currentTouches[0].clientY
|
||||
};
|
||||
var p1 = this.point(currentP.x, currentP.y);
|
||||
var p2 = this.point(lastP.x, lastP.y);
|
||||
var deltaP = [p2.x - p1.x, p2.y - p1.y];
|
||||
|
||||
if (!deltaP[0] && !deltaP[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var box = new svg_js.Box(this.viewbox()).transform(new svg_js.Matrix().translate(deltaP[0], deltaP[1]));
|
||||
lastP = currentP;
|
||||
restrictToMargins(box);
|
||||
|
||||
if (this.dispatch('panning', {
|
||||
box: box,
|
||||
event: ev
|
||||
}).defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.viewbox(box);
|
||||
};
|
||||
|
||||
if (doWheelZoom) {
|
||||
this.on('wheel.panZoom', wheelZoom, this, {
|
||||
passive: false
|
||||
});
|
||||
}
|
||||
|
||||
if (doPinchZoom) {
|
||||
this.on('touchstart.panZoom', pinchZoomStart, this, {
|
||||
passive: false
|
||||
});
|
||||
}
|
||||
|
||||
if (doPanning) {
|
||||
this.on('mousedown.panZoom', panStart, this, {
|
||||
passive: false
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
}(SVG));
|
||||
//# sourceMappingURL=svg.panzoom.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +0,0 @@
|
|||
/*! @svgdotjs/svg.panzoom.js v2.1.2 MIT*/;
|
||||
!function(D){"use strict";function G(t){return t.touches||[{clientX:t.clientX,clientY:t.clientY}]}D.extend(D.Svg,{panZoom:function(t){var n,e,i,o,a,l,h,s,c,E,u,V=this;if(this.off(".panZoom"),!1===t)return this;function m(t){if(!_)return t;var n=_.top,e=_.left,i=_.bottom,o=_.right,a=V.attr(["width","height"]),l=a.width,h=a.height,s=V.node.preserveAspectRatio.baseVal,c=0,E=0,u=0,m=0;if(s.align!==s.SVG_PRESERVEASPECTRATIO_NONE){var p=l/h,r=x.width/x.height;if(r!=p){var S=s.meetOrSlice!==s.SVG_MEETORSLICE_SLICE,R=r<p?"width":"height",M="width"==R,A=S&&M||!S&&!M,v=A?p/r:r/p,f=t[R]-t[R]*v;A?s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMAX?(c=f/2,E=-f/2):s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMAX?E=-f:s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMIN&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMID&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMAX||(c=f):s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMAXYMID?(u=f/2,m=-f/2):s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMAXYMIN?m=-f:s.align!==s.SVG_PRESERVEASPECTRATIO_XMINYMAX&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMIDYMAX&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMAX||(u=f)}}var d=x.width+x.x-e-c,I=x.x+o-t.width-E,X=x.height+x.y-n-u,P=x.y+i-t.height-m;return t.x=Math.min(d,Math.max(I,t.x)),t.y=Math.min(X,Math.max(P,t.y)),t}function p(t){(S=G(t)).length<2?d&&X&&Z.call(this,t):(d&&X&&O.call(this,t),t.preventDefault(),this.dispatch("pinchZoomStart",{event:t}).defaultPrevented||(this.off("touchstart.panZoom",p),Y=!0,D.on(document,"touchmove.panZoom",w,this,{passive:!1}),D.on(document,"touchend.panZoom",g,this,{passive:!1})))}var r,S,R=null!=(n=(t=null!=t?t:{}).zoomFactor)?n:2,M=null!=(e=t.zoomMin)?e:Number.MIN_VALUE,A=null!=(i=t.zoomMax)?i:Number.MAX_VALUE,v=null==(o=t.wheelZoom)||o,f=null==(a=t.pinchZoom)||a,d=null==(l=t.panning)||l,I=null!=(h=t.panButton)?h:0,X=null!=(s=t.oneFingerPan)&&s,_=null!=(c=t.margins)&&c,P=null!=(E=t.wheelZoomDeltaModeLinePixels)?E:17,T=null!=(u=t.wheelZoomDeltaModeScreenPixels)?u:53,Y=!1,x=this.viewbox(),g=function t(n){n.preventDefault();var e=G(n);1<e.length||(Y=!1,this.dispatch("pinchZoomEnd",{event:n}),D.off(document,"touchmove.panZoom",w),D.off(document,"touchend.panZoom",t),this.on("touchstart.panZoom",p),e.length&&d&&X&&Z.call(this,n))},w=function(t){t.preventDefault();var n=G(t),e=this.zoom(),i=Math.sqrt(Math.pow(S[0].clientX-S[1].clientX,2)+Math.pow(S[0].clientY-S[1].clientY,2))/Math.sqrt(Math.pow(n[0].clientX-n[1].clientX,2)+Math.pow(n[0].clientY-n[1].clientY,2));(e<M&&1<i||A<e&&i<1)&&(i=1);var o={x:n[0].clientX+.5*(n[1].clientX-n[0].clientX),y:n[0].clientY+.5*(n[1].clientY-n[0].clientY)},a=S[0].clientX+.5*(S[1].clientX-S[0].clientX),l=S[0].clientY+.5*(S[1].clientY-S[0].clientY),h=this.point(o.x,o.y),s=this.point(2*o.x-a,2*o.y-l),c=new D.Box(this.viewbox()).transform((new D.Matrix).translate(-s.x,-s.y).scale(i,0,0).translate(h.x,h.y));m(c),this.viewbox(c),S=n,this.dispatch("zoom",{box:c,focus:s})},Z=function t(n){-1<n.type.indexOf("mouse")&&n.button!==I&&n.which!==I+1||(n.preventDefault(),this.off("mousedown.panZoom",t),S=G(n),Y||(this.dispatch("panStart",{event:n}),r={x:S[0].clientX,y:S[0].clientY},D.on(document,"touchmove.panZoom mousemove.panZoom",C,this,{passive:!1}),D.on(document,"touchend.panZoom mouseup.panZoom",O,this,{passive:!1})))},O=function t(n){n.preventDefault(),D.off(document,"touchmove.panZoom mousemove.panZoom",C),D.off(document,"touchend.panZoom mouseup.panZoom",t),this.on("mousedown.panZoom",Z),this.dispatch("panEnd",{event:n})},C=function(t){t.preventDefault();var n=G(t),e={x:n[0].clientX,y:n[0].clientY},i=this.point(e.x,e.y),o=this.point(r.x,r.y),a=[o.x-i.x,o.y-i.y];if(a[0]||a[1]){var l=new D.Box(this.viewbox()).transform((new D.Matrix).translate(a[0],a[1]));r=e,m(l),this.dispatch("panning",{box:l,event:t}).defaultPrevented||this.viewbox(l)}};return v&&this.on("wheel.panZoom",function(t){var n;switch(t.preventDefault(),t.deltaMode){case 1:n=t.deltaY*P;break;case 2:n=t.deltaY*T;break;default:n=t.deltaY}var e=Math.pow(1+R,-1*n/100)*this.zoom(),i=this.point(t.clientX,t.clientY);if(A<e&&(e=A),e<M&&(e=M),this.dispatch("zoom",{level:e,focus:i}).defaultPrevented)return this;if(this.zoom(e,i),_){var o=m(this.viewbox());this.viewbox(o)}},this,{passive:!1}),f&&this.on("touchstart.panZoom",p,this,{passive:!1}),d&&this.on("mousedown.panZoom",Z,this,{passive:!1}),this}})}(SVG);
|
||||
//# sourceMappingURL=svg.panzoom.min.js.map
|
||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue