first commit
This commit is contained in:
commit
eb2f504652
32490 changed files with 5731109 additions and 0 deletions
49
node_modules/panzoom/lib/createTextSelectionInterceptor.js
generated
vendored
Normal file
49
node_modules/panzoom/lib/createTextSelectionInterceptor.js
generated
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Disallows selecting text.
|
||||
*/
|
||||
module.exports = createTextSelectionInterceptor;
|
||||
|
||||
function createTextSelectionInterceptor(useFake) {
|
||||
if (useFake) {
|
||||
return {
|
||||
capture: noop,
|
||||
release: noop
|
||||
};
|
||||
}
|
||||
|
||||
var dragObject;
|
||||
var prevSelectStart;
|
||||
var prevDragStart;
|
||||
var wasCaptured = false;
|
||||
|
||||
return {
|
||||
capture: capture,
|
||||
release: release
|
||||
};
|
||||
|
||||
function capture(domObject) {
|
||||
wasCaptured = true;
|
||||
prevSelectStart = window.document.onselectstart;
|
||||
prevDragStart = window.document.ondragstart;
|
||||
|
||||
window.document.onselectstart = disabled;
|
||||
|
||||
dragObject = domObject;
|
||||
dragObject.ondragstart = disabled;
|
||||
}
|
||||
|
||||
function release() {
|
||||
if (!wasCaptured) return;
|
||||
|
||||
wasCaptured = false;
|
||||
window.document.onselectstart = prevSelectStart;
|
||||
if (dragObject) dragObject.ondragstart = prevDragStart;
|
||||
}
|
||||
}
|
||||
|
||||
function disabled(e) {
|
||||
e.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
52
node_modules/panzoom/lib/domController.js
generated
vendored
Normal file
52
node_modules/panzoom/lib/domController.js
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
module.exports = makeDomController;
|
||||
|
||||
module.exports.canAttach = isDomElement;
|
||||
|
||||
function makeDomController(domElement, options) {
|
||||
var elementValid = isDomElement(domElement);
|
||||
if (!elementValid) {
|
||||
throw new Error('panzoom requires DOM element to be attached to the DOM tree');
|
||||
}
|
||||
|
||||
var owner = domElement.parentElement;
|
||||
domElement.scrollTop = 0;
|
||||
|
||||
if (!options.disableKeyboardInteraction) {
|
||||
owner.setAttribute('tabindex', 0);
|
||||
}
|
||||
|
||||
var api = {
|
||||
getBBox: getBBox,
|
||||
getOwner: getOwner,
|
||||
applyTransform: applyTransform,
|
||||
};
|
||||
|
||||
return api;
|
||||
|
||||
function getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
function getBBox() {
|
||||
// TODO: We should probably cache this?
|
||||
return {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: domElement.clientWidth,
|
||||
height: domElement.clientHeight
|
||||
};
|
||||
}
|
||||
|
||||
function applyTransform(transform) {
|
||||
// TODO: Should we cache this?
|
||||
domElement.style.transformOrigin = '0 0 0';
|
||||
domElement.style.transform = 'matrix(' +
|
||||
transform.scale + ', 0, 0, ' +
|
||||
transform.scale + ', ' +
|
||||
transform.x + ', ' + transform.y + ')';
|
||||
}
|
||||
}
|
||||
|
||||
function isDomElement(element) {
|
||||
return element && element.parentElement && element.style;
|
||||
}
|
||||
16
node_modules/panzoom/lib/getSvgTransformMatrix.js
generated
vendored
Normal file
16
node_modules/panzoom/lib/getSvgTransformMatrix.js
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Returns transformation matrix for an element. If no such transformation matrix
|
||||
* exist - a new one is created.
|
||||
*/
|
||||
module.exports = getSvgTransformMatrix;
|
||||
|
||||
function getSvgTransformMatrix(svgElement) {
|
||||
var baseVal = svgElement.transform.baseVal;
|
||||
if (baseVal.numberOfItems) return baseVal.getItem(0);
|
||||
|
||||
var owner = svgElement.ownerSVGElement || svgElement;
|
||||
var transform = owner.createSVGTransform();
|
||||
svgElement.transform.baseVal.appendItem(transform);
|
||||
|
||||
return transform;
|
||||
}
|
||||
136
node_modules/panzoom/lib/kinetic.js
generated
vendored
Normal file
136
node_modules/panzoom/lib/kinetic.js
generated
vendored
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/**
|
||||
* Allows smooth kinetic scrolling of the surface
|
||||
*/
|
||||
module.exports = kinetic;
|
||||
|
||||
function kinetic(getPoint, scroll, settings) {
|
||||
if (typeof settings !== 'object') {
|
||||
// setting could come as boolean, we should ignore it, and use an object.
|
||||
settings = {};
|
||||
}
|
||||
|
||||
var minVelocity = typeof settings.minVelocity === 'number' ? settings.minVelocity : 5;
|
||||
var amplitude = typeof settings.amplitude === 'number' ? settings.amplitude : 0.25;
|
||||
var cancelAnimationFrame = typeof settings.cancelAnimationFrame === 'function' ? settings.cancelAnimationFrame : getCancelAnimationFrame();
|
||||
var requestAnimationFrame = typeof settings.requestAnimationFrame === 'function' ? settings.requestAnimationFrame : getRequestAnimationFrame();
|
||||
|
||||
var lastPoint;
|
||||
var timestamp;
|
||||
var timeConstant = 342;
|
||||
|
||||
var ticker;
|
||||
var vx, targetX, ax;
|
||||
var vy, targetY, ay;
|
||||
|
||||
var raf;
|
||||
|
||||
return {
|
||||
start: start,
|
||||
stop: stop,
|
||||
cancel: dispose
|
||||
};
|
||||
|
||||
function dispose() {
|
||||
cancelAnimationFrame(ticker);
|
||||
cancelAnimationFrame(raf);
|
||||
}
|
||||
|
||||
function start() {
|
||||
lastPoint = getPoint();
|
||||
|
||||
ax = ay = vx = vy = 0;
|
||||
timestamp = new Date();
|
||||
|
||||
cancelAnimationFrame(ticker);
|
||||
cancelAnimationFrame(raf);
|
||||
|
||||
// we start polling the point position to accumulate velocity
|
||||
// Once we stop(), we will use accumulated velocity to keep scrolling
|
||||
// an object.
|
||||
ticker = requestAnimationFrame(track);
|
||||
}
|
||||
|
||||
function track() {
|
||||
var now = Date.now();
|
||||
var elapsed = now - timestamp;
|
||||
timestamp = now;
|
||||
|
||||
var currentPoint = getPoint();
|
||||
|
||||
var dx = currentPoint.x - lastPoint.x;
|
||||
var dy = currentPoint.y - lastPoint.y;
|
||||
|
||||
lastPoint = currentPoint;
|
||||
|
||||
var dt = 1000 / (1 + elapsed);
|
||||
|
||||
// moving average
|
||||
vx = 0.8 * dx * dt + 0.2 * vx;
|
||||
vy = 0.8 * dy * dt + 0.2 * vy;
|
||||
|
||||
ticker = requestAnimationFrame(track);
|
||||
}
|
||||
|
||||
function stop() {
|
||||
cancelAnimationFrame(ticker);
|
||||
cancelAnimationFrame(raf);
|
||||
|
||||
var currentPoint = getPoint();
|
||||
|
||||
targetX = currentPoint.x;
|
||||
targetY = currentPoint.y;
|
||||
timestamp = Date.now();
|
||||
|
||||
if (vx < -minVelocity || vx > minVelocity) {
|
||||
ax = amplitude * vx;
|
||||
targetX += ax;
|
||||
}
|
||||
|
||||
if (vy < -minVelocity || vy > minVelocity) {
|
||||
ay = amplitude * vy;
|
||||
targetY += ay;
|
||||
}
|
||||
|
||||
raf = requestAnimationFrame(autoScroll);
|
||||
}
|
||||
|
||||
function autoScroll() {
|
||||
var elapsed = Date.now() - timestamp;
|
||||
|
||||
var moving = false;
|
||||
var dx = 0;
|
||||
var dy = 0;
|
||||
|
||||
if (ax) {
|
||||
dx = -ax * Math.exp(-elapsed / timeConstant);
|
||||
|
||||
if (dx > 0.5 || dx < -0.5) moving = true;
|
||||
else dx = ax = 0;
|
||||
}
|
||||
|
||||
if (ay) {
|
||||
dy = -ay * Math.exp(-elapsed / timeConstant);
|
||||
|
||||
if (dy > 0.5 || dy < -0.5) moving = true;
|
||||
else dy = ay = 0;
|
||||
}
|
||||
|
||||
if (moving) {
|
||||
scroll(targetX + dx, targetY + dy);
|
||||
raf = requestAnimationFrame(autoScroll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getCancelAnimationFrame() {
|
||||
if (typeof cancelAnimationFrame === 'function') return cancelAnimationFrame;
|
||||
return clearTimeout;
|
||||
}
|
||||
|
||||
function getRequestAnimationFrame() {
|
||||
if (typeof requestAnimationFrame === 'function') return requestAnimationFrame;
|
||||
|
||||
return function (handler) {
|
||||
return setTimeout(handler, 16);
|
||||
};
|
||||
}
|
||||
79
node_modules/panzoom/lib/svgController.js
generated
vendored
Normal file
79
node_modules/panzoom/lib/svgController.js
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
module.exports = makeSvgController;
|
||||
module.exports.canAttach = isSVGElement;
|
||||
|
||||
function makeSvgController(svgElement, options) {
|
||||
if (!isSVGElement(svgElement)) {
|
||||
throw new Error('svg element is required for svg.panzoom to work');
|
||||
}
|
||||
|
||||
var owner = svgElement.ownerSVGElement;
|
||||
if (!owner) {
|
||||
throw new Error(
|
||||
'Do not apply panzoom to the root <svg> element. ' +
|
||||
'Use its child instead (e.g. <g></g>). ' +
|
||||
'As of March 2016 only FireFox supported transform on the root element');
|
||||
}
|
||||
|
||||
if (!options.disableKeyboardInteraction) {
|
||||
owner.setAttribute('tabindex', 0);
|
||||
}
|
||||
|
||||
var api = {
|
||||
getBBox: getBBox,
|
||||
getScreenCTM: getScreenCTM,
|
||||
getOwner: getOwner,
|
||||
applyTransform: applyTransform,
|
||||
initTransform: initTransform
|
||||
};
|
||||
|
||||
return api;
|
||||
|
||||
function getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
function getBBox() {
|
||||
var bbox = svgElement.getBBox();
|
||||
return {
|
||||
left: bbox.x,
|
||||
top: bbox.y,
|
||||
width: bbox.width,
|
||||
height: bbox.height,
|
||||
};
|
||||
}
|
||||
|
||||
function getScreenCTM() {
|
||||
var ctm = owner.getCTM();
|
||||
if (!ctm) {
|
||||
// This is likely firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=873106
|
||||
// The code below is not entirely correct, but still better than nothing
|
||||
return owner.getScreenCTM();
|
||||
}
|
||||
return ctm;
|
||||
}
|
||||
|
||||
function initTransform(transform) {
|
||||
var screenCTM = svgElement.getCTM();
|
||||
|
||||
// The above line returns null on Firefox
|
||||
if (screenCTM === null) {
|
||||
screenCTM = document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGMatrix();
|
||||
}
|
||||
|
||||
transform.x = screenCTM.e;
|
||||
transform.y = screenCTM.f;
|
||||
transform.scale = screenCTM.a;
|
||||
owner.removeAttributeNS(null, 'viewBox');
|
||||
}
|
||||
|
||||
function applyTransform(transform) {
|
||||
svgElement.setAttribute('transform', 'matrix(' +
|
||||
transform.scale + ' 0 0 ' +
|
||||
transform.scale + ' ' +
|
||||
transform.x + ' ' + transform.y + ')');
|
||||
}
|
||||
}
|
||||
|
||||
function isSVGElement(element) {
|
||||
return element && element.ownerSVGElement && element.getCTM;
|
||||
}
|
||||
7
node_modules/panzoom/lib/transform.js
generated
vendored
Normal file
7
node_modules/panzoom/lib/transform.js
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module.exports = Transform;
|
||||
|
||||
function Transform() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.scale = 1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue