Skip to content

Commit

Permalink
Merge pull request #230 from ariutta/fix-typescript
Browse files Browse the repository at this point in the history
fix: typescript definition, add getSizes
  • Loading branch information
bumbu authored Jan 16, 2017
2 parents b831a39 + 295fdff commit ca0f127
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-pan-zoom",
"version": "3.4.0",
"version": "3.4.1",
"homepage": "https://github.com/ariutta/svg-pan-zoom",
"authors": [
"Andrea Leofreddi <a.leofreddi@itcharm.com>",
Expand Down
29 changes: 23 additions & 6 deletions dist/svg-pan-zoom.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for svg-pan-zoom v3.3.0
// Type definitions for svg-pan-zoom v3.4.1
// Project: https://github.com/ariutta/svg-pan-zoom
// Definitions by: César Vidril <https://github.com/Yimiprod>
// Definitions: https://github.com/ariutta/svg-pan-zoom
Expand Down Expand Up @@ -28,14 +28,14 @@ declare namespace SvgPanZoom {
}

interface CustomEventHandler {
haltEventListeners: string[],
init: (options: CustomEventOptions) => void,
destroy: Function
init: (options: CustomEventOptions) => void;
haltEventListeners: string[];
destroy: Function;
}

interface CustomEventOptions {
svgElement: SVGSVGElement,
instance: Instance
svgElement: SVGSVGElement;
instance: Instance;
}

interface Point {
Expand All @@ -48,6 +48,16 @@ declare namespace SvgPanZoom {
y: number|boolean;
}

interface Sizes {
width: number;
height: number;
realZoom: number;
viewBox: {
width: number;
height: number;
}
}

interface Instance {
/**
* Creates a new SvgPanZoom instance with given element selector.
Expand Down Expand Up @@ -192,6 +202,13 @@ declare namespace SvgPanZoom {
*/
resize(): Instance;

/**
* Get all calculate svg dimensions
*
* @return {Object} {width: 0, height: 0, realZoom: 0, viewBox: { width: 0, height: 0 }}
*/
getSizes(): Sizes;

reset(): Instance;

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/svg-pan-zoom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// svg-pan-zoom v3.4.0
// svg-pan-zoom v3.4.1
// https://github.com/ariutta/svg-pan-zoom
(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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var svgPanZoom = require('./svg-pan-zoom.js');
Expand Down
4 changes: 2 additions & 2 deletions dist/svg-pan-zoom.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-pan-zoom",
"version": "3.4.0",
"version": "3.4.1",
"main": "dist/svg-pan-zoom.js",
"types": "dist/svg-pan-zoom.d.ts",
"browser": "src/browserify.js",
Expand Down
117 changes: 117 additions & 0 deletions tests/test_typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
var svgPanZoomOptions : SvgPanZoom.Options = {
panEnabled: true // enable or disable panning (default enabled)
, controlIconsEnabled: false // insert icons to give user an option in addition to mouse events to control pan/zoom (default disabled)
, zoomEnabled: true // enable or disable zooming (default enabled)
, dblClickZoomEnabled: true // enable or disable zooming by double clicking (default enabled)
, zoomScaleSensitivity: 0.2 // Zoom sensitivity
, minZoom: 0.5 // Minimum Zoom level
, maxZoom: 10 // Maximum Zoom level
, fit: true // enable or disable viewport fit in SVG (default true)
, center: true // enable or disable viewport centering in SVG (default true)
, beforeZoom: null
, onZoom: function(){}
, beforePan: null
, onPan: function(){}
, refreshRate: 60 // in hz
};

var panZoomTiger: SvgPanZoom.Instance = svgPanZoom('#demo-tiger');

var svgElement = <SVGElement>document.querySelector('#demo-tiger');
panZoomTiger = svgPanZoom(svgElement);

panZoomTiger = svgPanZoom('#demo-tiger', {
panEnabled: true
, controlIconsEnabled: false
, zoomEnabled: true
, dblClickZoomEnabled: true
, mouseWheelZoomEnabled: true
, preventMouseEventsDefault: true
, zoomScaleSensitivity: 0.2
, minZoom: 0.5
, maxZoom: 10
, fit: true
, contain: false
, center: true
, refreshRate: 'auto'
, beforeZoom: function(oldScale, newScale){ return true; }
, onZoom: function(newScale){}
, beforePan: function(oldPan, newPan){ return {x: true, y: true}; }
, customEventsHandler: null
, eventsListenerElement: null
});

/**
* PAN
*/
// Pan to rendered point x = 50, y = 50
panZoomTiger.pan({x: 50, y: 50});

// Pan by x = 50, y = 50 of rendered pixels
panZoomTiger.panBy({x: 50, y: 50});

panZoomTiger.getPan();

panZoomTiger.resetPan();

panZoomTiger.enablePan();
panZoomTiger.disablePan();

panZoomTiger.isPanEnabled();

/**
* ZOOM
*/
// Set zoom level to 2
panZoomTiger.zoom(2);

// Zoom by 130%
panZoomTiger.zoomBy(1.3);

// Set zoom level to 2 at point
panZoomTiger.zoomAtPoint(2, {x: 50, y: 50});

// Zoom by 130% at point
panZoomTiger.zoomAtPointBy(1.3, {x: 50, y: 50});

panZoomTiger.zoomIn();
panZoomTiger.zoomOut();

panZoomTiger.getZoom();

panZoomTiger.resetZoom();

panZoomTiger.enableZoom();
panZoomTiger.disableZoom();

panZoomTiger.isZoomEnabled();

/**
* controls
*/
panZoomTiger.enableControlIcons();
panZoomTiger.disableControlIcons();
panZoomTiger.isControlIconsEnabled();

panZoomTiger.enableDblClickZoom();
panZoomTiger.disableDblClickZoom();
panZoomTiger.isDblClickZoomEnabled();

panZoomTiger.enableMouseWheelZoom();
panZoomTiger.disableMouseWheelZoom();
panZoomTiger.isMouseWheelZoomEnabled();

panZoomTiger.center();
panZoomTiger.fit();
panZoomTiger.contain();

panZoomTiger.resize(); // update SVG cached size and controls positions
panZoomTiger.getSizes();

panZoomTiger.updateBBox();

panZoomTiger.fit().center(); // can chain method

panZoomTiger.destroy(); // destroy instance

delete panZoomTiger;
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": "./",
"typeRoots": [
"./"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"dist/svg-pan-zoom.d.ts",
"tests/test_typescript.ts"
]
}

0 comments on commit ca0f127

Please sign in to comment.