1
- // svg-pan-zoom v3.4.1
1
+ // svg-pan-zoom v3.5.0
2
2
// https://github.com/ariutta/svg-pan-zoom
3
3
( 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 ) {
4
4
var svgPanZoom = require ( './svg-pan-zoom.js' ) ;
@@ -371,6 +371,9 @@ ShadowViewport.prototype.setCTM = function(newCTM) {
371
371
if ( this . options . beforeZoom ( this . getRelativeZoom ( ) , this . computeRelativeZoom ( newCTM . a ) ) === false ) {
372
372
newCTM . a = newCTM . d = this . activeState . zoom
373
373
willZoom = false
374
+ } else {
375
+ this . updateCache ( newCTM ) ;
376
+ this . options . onZoom ( this . getRelativeZoom ( ) )
374
377
}
375
378
}
376
379
@@ -413,18 +416,15 @@ ShadowViewport.prototype.setCTM = function(newCTM) {
413
416
// Update willPan flag
414
417
if ( preventPanX && preventPanY ) {
415
418
willPan = false
419
+ } else {
420
+ this . updateCache ( newCTM ) ;
421
+ this . options . onPan ( this . getPan ( ) ) ;
416
422
}
417
423
}
418
424
419
425
// Check again if should zoom or pan
420
426
if ( willZoom || willPan ) {
421
- this . updateCache ( newCTM )
422
-
423
427
this . updateCTMOnNextFrame ( )
424
-
425
- // After callbacks
426
- if ( willZoom ) { this . options . onZoom ( this . getRelativeZoom ( ) ) }
427
- if ( willPan ) { this . options . onPan ( this . getPan ( ) ) }
428
428
}
429
429
}
430
430
}
@@ -468,11 +468,18 @@ ShadowViewport.prototype.updateCTMOnNextFrame = function() {
468
468
* Update viewport CTM with cached CTM
469
469
*/
470
470
ShadowViewport . prototype . updateCTM = function ( ) {
471
+ var ctm = this . getCTM ( )
472
+
471
473
// Updates SVG element
472
- SvgUtils . setCTM ( this . viewport , this . getCTM ( ) , this . defs )
474
+ SvgUtils . setCTM ( this . viewport , ctm , this . defs )
473
475
474
476
// Free the lock
475
477
this . pendingUpdate = false
478
+
479
+ // Notify about the update
480
+ if ( this . options . onUpdatedCTM ) {
481
+ this . options . onUpdatedCTM ( ctm )
482
+ }
476
483
}
477
484
478
485
module . exports = function ( viewport , options ) {
@@ -511,6 +518,7 @@ var optionsDefaults = {
511
518
, onPan : null
512
519
, customEventsHandler : null
513
520
, eventsListenerElement : null
521
+ , onUpdatedCTM : null
514
522
}
515
523
516
524
SvgPanZoom . prototype . init = function ( svg , options ) {
@@ -555,6 +563,9 @@ SvgPanZoom.prototype.init = function(svg, options) {
555
563
, onPan : function ( point ) {
556
564
if ( that . viewport && that . options . onPan ) { return that . options . onPan ( point ) }
557
565
}
566
+ , onUpdatedCTM : function ( ctm ) {
567
+ if ( that . viewport && that . options . onUpdatedCTM ) { return that . options . onUpdatedCTM ( ctm ) }
568
+ }
558
569
} )
559
570
560
571
// Wrap callbacks into public API context
@@ -563,6 +574,7 @@ SvgPanZoom.prototype.init = function(svg, options) {
563
574
publicInstance . setOnZoom ( this . options . onZoom )
564
575
publicInstance . setBeforePan ( this . options . beforePan )
565
576
publicInstance . setOnPan ( this . options . onPan )
577
+ publicInstance . setOnUpdatedCTM ( this . options . onUpdatedCTM )
566
578
567
579
if ( this . options . controlIconsEnabled ) {
568
580
ControlIcons . enable ( this )
@@ -1075,6 +1087,7 @@ SvgPanZoom.prototype.destroy = function() {
1075
1087
this . onZoom = null
1076
1088
this . beforePan = null
1077
1089
this . onPan = null
1090
+ this . onUpdatedCTM = null
1078
1091
1079
1092
// Destroy custom event handlers
1080
1093
if ( this . options . customEventsHandler != null ) { // jshint ignore:line
@@ -1108,6 +1121,9 @@ SvgPanZoom.prototype.destroy = function() {
1108
1121
// Delete options and its contents
1109
1122
delete this . options
1110
1123
1124
+ // Delete viewport to make public shadow viewport functions uncallable
1125
+ delete this . viewport
1126
+
1111
1127
// Destroy public instance and rewrite getPublicInstance
1112
1128
delete this . publicInstance
1113
1129
delete this . pi
@@ -1179,6 +1195,8 @@ SvgPanZoom.prototype.getPublicInstance = function() {
1179
1195
, zoomIn : function ( ) { this . zoomBy ( 1 + that . options . zoomScaleSensitivity ) ; return that . pi }
1180
1196
, zoomOut : function ( ) { this . zoomBy ( 1 / ( 1 + that . options . zoomScaleSensitivity ) ) ; return that . pi }
1181
1197
, getZoom : function ( ) { return that . getRelativeZoom ( ) }
1198
+ // CTM update
1199
+ , setOnUpdatedCTM : function ( fn ) { that . options . onUpdatedCTM = fn === null ? null : Utils . proxy ( fn , that . publicInstance ) ; return that . pi }
1182
1200
// Reset
1183
1201
, resetZoom : function ( ) { that . resetZoom ( ) ; return that . pi }
1184
1202
, resetPan : function ( ) { that . resetPan ( ) ; return that . pi }
0 commit comments