Skip to content

Commit

Permalink
Updated svg.js version (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Feb 28, 2020
1 parent 79c3069 commit 5659a0a
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 133 deletions.
18 changes: 2 additions & 16 deletions cvat/apps/engine/static/engine/js/3rdparty.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ Subject: [PATCH] Applied patch
---
.../static/engine/js/3rdparty/svg.draggable.js | 1 +
.../static/engine/js/3rdparty/svg.draw.js | 17 +++++++++++++++--
.../engine/static/engine/js/3rdparty/svg.js | 2 +-
.../static/engine/js/3rdparty/svg.resize.min.js | 2 +-
.../static/engine/js/3rdparty/svg.select.js | 5 ++++-
5 files changed, 22 insertions(+), 5 deletions(-)
4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.draggable.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.draggable.js
index d88abf5..aba474c 100644
Expand Down Expand Up @@ -78,19 +77,6 @@ index 68dbf2a..20a6917 100644
}
}

diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.js
index 72737da..c865ef8 100644
--- a/cvat/apps/engine/static/engine/js/3rdparty/svg.js
+++ b/cvat/apps/engine/static/engine/js/3rdparty/svg.js
@@ -3503,7 +3503,7 @@ SVG.off = function(node, event, listener) {
SVG.off(node, event)

delete SVG.listeners[index]
- delete SVG.handlerMap[index]
+ SVG.handlerMap.splice(index, 1)

}
}
diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.min.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.min.js
index 2dca34b..50ef3d3 100644
--- a/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.min.js
Expand Down Expand Up @@ -131,7 +117,7 @@ index 47e07bd..cee6d34 100644

if (!this.pointSelection.isSelected && !this.rectSelection.isSelected) {
this.nested.remove();
+ SVG.off(this.node);
+ SVG.off(this.nested.node);
delete this.nested;
-
}
Expand Down
237 changes: 120 additions & 117 deletions cvat/apps/engine/static/engine/js/3rdparty/svg.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*!
* svg.js - A lightweight library for manipulating and animating SVG.
* @version 2.6.5
* @version 2.7.1
* https://svgdotjs.github.io/
*
* @copyright Wout Fierens <[email protected]>
* @license MIT
*
* BUILT: Sat May 26 2018 22:47:07 GMT+0200 (Mitteleuropäische Sommerzeit)
* BUILT: Fri Nov 30 2018 10:01:55 GMT+0100 (GMT+01:00)
*/;
(function(root, factory) {
/* istanbul ignore next */
Expand All @@ -21,8 +21,12 @@
}
}(typeof window !== "undefined" ? window : this, function(window, document) {

// Find global reference - uses 'this' by default when available,
// falls back to 'window' otherwise (for bundlers like Webpack)
var globalRef = (typeof this !== "undefined") ? this : window;

// The main wrapping element
var SVG = this.SVG = function(element) {
var SVG = globalRef.SVG = function(element) {
if (SVG.supported) {
element = new SVG.Doc(element)

Expand Down Expand Up @@ -158,7 +162,7 @@ SVG.prepare = function() {
// Create parser object
SVG.parser = {
body: body || document.documentElement
, draw: draw.style('opacity:0;position:absolute;left:-100%;top:-100%;overflow:hidden').node
, draw: draw.style('opacity:0;position:absolute;left:-100%;top:-100%;overflow:hidden').attr('focusable', 'false').node
, poly: draw.polyline().node
, path: draw.path().node
, native: SVG.create('svg')
Expand Down Expand Up @@ -1028,6 +1032,7 @@ SVG.Element = SVG.invent({
// make stroke value accessible dynamically
this._stroke = SVG.defaults.attrs.stroke
this._event = null
this._events = {}

// initialize data object
this.dom = {}
Expand All @@ -1036,6 +1041,7 @@ SVG.Element = SVG.invent({
if (this.node = node) {
this.type = node.nodeName
this.node.instance = this
this._events = node._events || {}

// store current attribute value
this._stroke = node.getAttribute('stroke') || this._stroke
Expand Down Expand Up @@ -1201,7 +1207,7 @@ SVG.Element = SVG.invent({
// loop trough ancestors if type is given
while(parent && parent.node instanceof window.SVGElement){
if(typeof type === 'string' ? parent.matches(type) : parent instanceof type) return parent
if(!parent.node.parentNode || parent.node.parentNode.nodeName == '#document') return null // #759, #720
if(!parent.node.parentNode || parent.node.parentNode.nodeName == '#document' || parent.node.parentNode.nodeName == '#document-fragment') return null // #759, #720
parent = SVG.adopt(parent.node.parentNode)
}
}
Expand Down Expand Up @@ -3396,146 +3402,142 @@ SVG.ViewBox = SVG.invent({

})
// Add events to elements
;[ 'click'
, 'dblclick'
, 'mousedown'
, 'mouseup'
, 'mouseover'
, 'mouseout'
, 'mousemove'
// , 'mouseenter' -> not supported by IE
// , 'mouseleave' -> not supported by IE
, 'touchstart'
, 'touchmove'
, 'touchleave'
, 'touchend'
, 'touchcancel' ].forEach(function(event) {

// add event to SVG.Element
SVG.Element.prototype[event] = function(f) {
// bind event to element rather than element node
SVG.on(this.node, event, f)
return this
}
})

// Initialize listeners stack
SVG.listeners = []
SVG.handlerMap = []
;[ 'click',
'dblclick',
'mousedown',
'mouseup',
'mouseover',
'mouseout',
'mousemove',
'mouseenter',
'mouseleave',
'touchstart',
'touchmove',
'touchleave',
'touchend',
'touchcancel' ].forEach(function (event) {
// add event to SVG.Element
SVG.Element.prototype[event] = function (f) {
// bind event to element rather than element node
if (f == null) {
SVG.off(this, event)
} else {
SVG.on(this, event, f)
}
return this
}
})

SVG.listenerId = 0

// Add event binder in the SVG namespace
SVG.on = function(node, event, listener, binding, options) {
// create listener, get object-index
var l = listener.bind(binding || node.instance || node)
, index = (SVG.handlerMap.indexOf(node) + 1 || SVG.handlerMap.push(node)) - 1
, ev = event.split('.')[0]
, ns = event.split('.')[1] || '*'
SVG.on = function (node, events, listener, binding, options) {
var l = listener.bind(binding || node)
var n = node instanceof SVG.Element ? node.node : node

// ensure instance object for nodes which are not adopted
n.instance = n.instance || {_events: {}}

var bag = n.instance._events

// add id to listener
if (!listener._svgjsListenerId) { listener._svgjsListenerId = ++SVG.listenerId }

// ensure valid object
SVG.listeners[index] = SVG.listeners[index] || {}
SVG.listeners[index][ev] = SVG.listeners[index][ev] || {}
SVG.listeners[index][ev][ns] = SVG.listeners[index][ev][ns] || {}
events.split(SVG.regex.delimiter).forEach(function (event) {
var ev = event.split('.')[0]
var ns = event.split('.')[1] || '*'

if(!listener._svgjsListenerId)
listener._svgjsListenerId = ++SVG.listenerId
// ensure valid object
bag[ev] = bag[ev] || {}
bag[ev][ns] = bag[ev][ns] || {}

// reference listener
SVG.listeners[index][ev][ns][listener._svgjsListenerId] = l
// reference listener
bag[ev][ns][listener._svgjsListenerId] = l

// add listener
node.addEventListener(ev, l, options || false)
// add listener
n.addEventListener(ev, l, options || false)
})
}

// Add event unbinder in the SVG namespace
SVG.off = function(node, event, listener) {
var index = SVG.handlerMap.indexOf(node)
, ev = event && event.split('.')[0]
, ns = event && event.split('.')[1]
, namespace = ''

if(index == -1) return
SVG.off = function (node, events, listener, options) {
var n = node instanceof SVG.Element ? node.node : node
if (!n.instance) return

if (listener) {
if(typeof listener == 'function') listener = listener._svgjsListenerId
if(!listener) return
// listener can be a function or a number
if (typeof listener === 'function') {
listener = listener._svgjsListenerId
if (!listener) return
}

// remove listener reference
if (SVG.listeners[index][ev] && SVG.listeners[index][ev][ns || '*']) {
// remove listener
node.removeEventListener(ev, SVG.listeners[index][ev][ns || '*'][listener], false)
var bag = n.instance._events

delete SVG.listeners[index][ev][ns || '*'][listener]
}
;(events || '').split(SVG.regex.delimiter).forEach(function (event) {
var ev = event && event.split('.')[0]
var ns = event && event.split('.')[1]
var namespace, l

} else if (ns && ev) {
// remove all listeners for a namespaced event
if (SVG.listeners[index][ev] && SVG.listeners[index][ev][ns]) {
for (listener in SVG.listeners[index][ev][ns])
SVG.off(node, [ev, ns].join('.'), listener)
if (listener) {
// remove listener reference
if (bag[ev] && bag[ev][ns || '*']) {
// removeListener
n.removeEventListener(ev, bag[ev][ns || '*'][listener], options || false)

delete SVG.listeners[index][ev][ns]
}
delete bag[ev][ns || '*'][listener]
}
} else if (ev && ns) {
// remove all listeners for a namespaced event
if (bag[ev] && bag[ev][ns]) {
for (l in bag[ev][ns]) { SVG.off(n, [ev, ns].join('.'), l) }

} else if (ns){
// remove all listeners for a specific namespace
for(event in SVG.listeners[index]){
for(namespace in SVG.listeners[index][event]){
if(ns === namespace){
SVG.off(node, [event, ns].join('.'))
}
delete bag[ev][ns]
}
} else if (ns) {
// remove all listeners for a specific namespace
for (event in bag) {
for (namespace in bag[event]) {
if (ns === namespace) { SVG.off(n, [event, ns].join('.')) }
}
}
}
} else if (ev) {
// remove all listeners for the event
if (bag[ev]) {
for (namespace in bag[ev]) { SVG.off(n, [ev, namespace].join('.')) }

} else if (ev) {
// remove all listeners for the event
if (SVG.listeners[index][ev]) {
for (namespace in SVG.listeners[index][ev])
SVG.off(node, [ev, namespace].join('.'))
delete bag[ev]
}
} else {
// remove all listeners on a given node
for (event in bag) { SVG.off(n, event) }

delete SVG.listeners[index][ev]
n.instance._events = {}
}

} else {
// remove all listeners on a given node
for (event in SVG.listeners[index])
SVG.off(node, event)

delete SVG.listeners[index]
delete SVG.handlerMap[index]

}
})
}

//
SVG.extend(SVG.Element, {
// Bind given event to listener
on: function(event, listener, binding, options) {
SVG.on(this.node, event, listener, binding, options)

on: function (event, listener, binding, options) {
SVG.on(this, event, listener, binding, options)
return this
}
},
// Unbind event from listener
, off: function(event, listener) {
off: function (event, listener) {
SVG.off(this.node, event, listener)

return this
}
// Fire given event
, fire: function(event, data) {

},
fire: function (event, data) {
// Dispatch event
if(event instanceof window.Event){
this.node.dispatchEvent(event)
}else{
this.node.dispatchEvent(event = new SVG.CustomEvent(event, {detail:data, cancelable: true}))
if (event instanceof window.Event) {
this.node.dispatchEvent(event)
} else {
this.node.dispatchEvent(event = new SVG.CustomEvent(event, {detail: data, cancelable: true}))
}

this._event = event
return this
}
, event: function() {
},
event: function() {
return this._event
}
})
Expand Down Expand Up @@ -3655,7 +3657,7 @@ SVG.Doc = SVG.invent({
}
// custom parent method
, parent: function() {
if(!this.node.parentNode || this.node.parentNode.nodeName == '#document') return null
if(!this.node.parentNode || this.node.parentNode.nodeName == '#document' || this.node.parentNode.nodeName == '#document-fragment') return null
return this.node.parentNode
}
// Fix for possible sub-pixel offset. See:
Expand Down Expand Up @@ -5137,8 +5139,11 @@ SVG.extend(SVG.Parent, SVG.Text, SVG.Tspan, SVG.FX, {
SVG.Set = SVG.invent({
// Initialize
create: function(members) {
// Set initial state
Array.isArray(members) ? this.members = members : this.clear()
if (members instanceof SVG.Set) {
this.members = members.members.slice()
} else {
Array.isArray(members) ? this.members = members : this.clear()
}
}

// Add class methods
Expand Down Expand Up @@ -5281,8 +5286,6 @@ SVG.Set.inherit = function() {
}




SVG.extend(SVG.Element, {
// Store data values on svg nodes
data: function(a, v, r) {
Expand Down Expand Up @@ -5595,4 +5598,4 @@ if (typeof window.CustomEvent !== 'function') {

return SVG

}));
}));

0 comments on commit 5659a0a

Please sign in to comment.