update
parent
c714af4a11
commit
d9eff8e338
|
@ -54,11 +54,9 @@ eve.on('snap.util.attr', function (val) {
|
||||||
})(-10)
|
})(-10)
|
||||||
|
|
||||||
eve.on('snap.util.equal', function (name, b) {
|
eve.on('snap.util.equal', function (name, b) {
|
||||||
let A,
|
let a = String(this.attr(name) || '')
|
||||||
B,
|
let bplus = String(b).match(reAddon)
|
||||||
a = String(this.attr(name) || ''),
|
|
||||||
el = this,
|
|
||||||
bplus = String(b).match(reAddon)
|
|
||||||
if (bplus) {
|
if (bplus) {
|
||||||
eve.stop()
|
eve.stop()
|
||||||
let unit = bplus[3] || '',
|
let unit = bplus[3] || '',
|
||||||
|
|
151
src/mina.js
151
src/mina.js
|
@ -1,18 +1,10 @@
|
||||||
// Copyright (c) 2017 Adobe Systems Incorporated. All rights reserved.
|
/**
|
||||||
//
|
* {}
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
* @author yutent<yutent.io@gmail.com>
|
||||||
// you may not use this file except in compliance with the License.
|
* @date 2024/03/08 10:20:25
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
import eve from './eve.js'
|
import eve from './eve.js'
|
||||||
import { Snap } from './svg.js'
|
|
||||||
import { uuid } from './utils.js'
|
import { uuid } from './utils.js'
|
||||||
|
|
||||||
let animations = {},
|
let animations = {},
|
||||||
|
@ -127,74 +119,71 @@ let animations = {},
|
||||||
a.update()
|
a.update()
|
||||||
}
|
}
|
||||||
requestID = len ? requestAnimFrame(frame) : false
|
requestID = len ? requestAnimFrame(frame) : false
|
||||||
},
|
|
||||||
/*\
|
|
||||||
* mina
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Generic animation of numbers
|
|
||||||
**
|
|
||||||
- a (number) start _slave_ number
|
|
||||||
- A (number) end _slave_ number
|
|
||||||
- b (number) start _master_ number (start time in general case)
|
|
||||||
- B (number) end _master_ number (end time in general case)
|
|
||||||
- get (function) getter of _master_ number (see @mina.time)
|
|
||||||
- set (function) setter of _slave_ number
|
|
||||||
- easing (function) #optional easing function, default is @mina.linear
|
|
||||||
= (object) animation descriptor
|
|
||||||
o {
|
|
||||||
o id (string) animation id,
|
|
||||||
o start (number) start _slave_ number,
|
|
||||||
o end (number) end _slave_ number,
|
|
||||||
o b (number) start _master_ number,
|
|
||||||
o s (number) animation status (0..1),
|
|
||||||
o dur (number) animation duration,
|
|
||||||
o spd (number) animation speed,
|
|
||||||
o get (function) getter of _master_ number (see @mina.time),
|
|
||||||
o set (function) setter of _slave_ number,
|
|
||||||
o easing (function) easing function, default is @mina.linear,
|
|
||||||
o status (function) status getter/setter,
|
|
||||||
o speed (function) speed getter/setter,
|
|
||||||
o duration (function) duration getter/setter,
|
|
||||||
o stop (function) animation stopper
|
|
||||||
o pause (function) pauses the animation
|
|
||||||
o resume (function) resumes the animation
|
|
||||||
o update (function) calles setter with the right value of the animation
|
|
||||||
o }
|
|
||||||
\*/
|
|
||||||
mina = function (a, A, b, B, get, set, easing) {
|
|
||||||
let anim = {
|
|
||||||
id: uuid('M'),
|
|
||||||
start: a,
|
|
||||||
end: A,
|
|
||||||
b: b,
|
|
||||||
s: 0,
|
|
||||||
dur: B - b,
|
|
||||||
spd: 1,
|
|
||||||
get: get,
|
|
||||||
set: set,
|
|
||||||
easing: easing || mina.linear,
|
|
||||||
status: sta,
|
|
||||||
speed: speed,
|
|
||||||
duration: duration,
|
|
||||||
stop: stopit,
|
|
||||||
pause: pause,
|
|
||||||
resume: resume,
|
|
||||||
update: update
|
|
||||||
}
|
|
||||||
animations[anim.id] = anim
|
|
||||||
let len = 0,
|
|
||||||
i
|
|
||||||
for (i in animations)
|
|
||||||
if (animations.hasOwnProperty(i)) {
|
|
||||||
len++
|
|
||||||
if (len == 2) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
len == 1 && frame()
|
|
||||||
return anim
|
|
||||||
}
|
}
|
||||||
|
/***
|
||||||
|
* Generic animation of numbers
|
||||||
|
**
|
||||||
|
* a (number) start _slave_ number
|
||||||
|
* A (number) end _slave_ number
|
||||||
|
* b (number) start _master_ number (start time in general case)
|
||||||
|
* B (number) end _master_ number (end time in general case)
|
||||||
|
* get (function) getter of _master_ number (see @mina.time)
|
||||||
|
* set (function) setter of _slave_ number
|
||||||
|
* easing (function) #optional easing function, default is @mina.linear
|
||||||
|
= (object) animation descriptor
|
||||||
|
{
|
||||||
|
id (string) animation id,
|
||||||
|
start (number) start _slave_ number,
|
||||||
|
end (number) end _slave_ number,
|
||||||
|
b (number) start _master_ number,
|
||||||
|
s (number) animation status (0..1),
|
||||||
|
dur (number) animation duration,
|
||||||
|
spd (number) animation speed,
|
||||||
|
get (function) getter of _master_ number (see @mina.time),
|
||||||
|
set (function) setter of _slave_ number,
|
||||||
|
easing (function) easing function, default is @mina.linear,
|
||||||
|
status (function) status getter/setter,
|
||||||
|
speed (function) speed getter/setter,
|
||||||
|
duration (function) duration getter/setter,
|
||||||
|
stop (function) animation stopper
|
||||||
|
pause (function) pauses the animation
|
||||||
|
resume (function) resumes the animation
|
||||||
|
update (function) calles setter with the right value of the animation
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
export const mina = function (a, A, b, B, get, set, easing) {
|
||||||
|
let anim = {
|
||||||
|
id: uuid('M'),
|
||||||
|
start: a,
|
||||||
|
end: A,
|
||||||
|
b: b,
|
||||||
|
s: 0,
|
||||||
|
dur: B - b,
|
||||||
|
spd: 1,
|
||||||
|
get: get,
|
||||||
|
set: set,
|
||||||
|
easing: easing || mina.linear,
|
||||||
|
status: sta,
|
||||||
|
speed: speed,
|
||||||
|
duration: duration,
|
||||||
|
stop: stopit,
|
||||||
|
pause: pause,
|
||||||
|
resume: resume,
|
||||||
|
update: update
|
||||||
|
}
|
||||||
|
animations[anim.id] = anim
|
||||||
|
let len = 0,
|
||||||
|
i
|
||||||
|
for (i in animations)
|
||||||
|
if (animations.hasOwnProperty(i)) {
|
||||||
|
len++
|
||||||
|
if (len == 2) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len == 1 && frame()
|
||||||
|
return anim
|
||||||
|
}
|
||||||
/*\
|
/*\
|
||||||
* mina.time
|
* mina.time
|
||||||
[ method ]
|
[ method ]
|
||||||
|
|
332
src/mouse.js
332
src/mouse.js
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
import eve from './eve.js'
|
import eve from './eve.js'
|
||||||
import { Snap, SnapElement, Paper } from './svg.js'
|
import { Snap, SnapElement } from './svg.js'
|
||||||
import { is } from './utils.js'
|
import { is } from './utils.js'
|
||||||
import { doc, win } from './lib/constants.js'
|
import { doc, win } from './lib/constants.js'
|
||||||
|
|
||||||
|
@ -169,287 +169,62 @@ let elproto = SnapElement.prototype,
|
||||||
}
|
}
|
||||||
drag = []
|
drag = []
|
||||||
}
|
}
|
||||||
/*\
|
|
||||||
* SnapElement.click
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a click event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.unclick
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a click event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.dblclick
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a double click event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.undblclick
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a double click event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.mousedown
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a mousedown event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.unmousedown
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a mousedown event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.mousemove
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a mousemove event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.unmousemove
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a mousemove event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.mouseout
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a mouseout event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.unmouseout
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a mouseout event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.mouseover
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a mouseover event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.unmouseover
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a mouseover event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.mouseup
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a mouseup event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.unmouseup
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a mouseup event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.touchstart
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a touchstart event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.untouchstart
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a touchstart event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.touchmove
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a touchmove event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.untouchmove
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a touchmove event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.touchend
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a touchend event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.untouchend
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a touchend event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
|
|
||||||
/*\
|
|
||||||
* SnapElement.touchcancel
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds a touchcancel event handler to the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
/*\
|
|
||||||
* SnapElement.untouchcancel
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes a touchcancel event handler from the element
|
|
||||||
- handler (function) handler for the event
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
for (let i = events.length; i--; ) {
|
for (let i = events.length; i--; ) {
|
||||||
;(function (eventName) {
|
let eventName = events[i]
|
||||||
Snap[eventName] = elproto[eventName] = function (fn, scope) {
|
|
||||||
if (is(fn, 'function')) {
|
Snap[eventName] = elproto[eventName] = function (fn, scope) {
|
||||||
this.events = this.events || []
|
if (is(fn, 'function')) {
|
||||||
this.events.push({
|
this.events = this.events || []
|
||||||
name: eventName,
|
this.events.push({
|
||||||
f: fn,
|
name: eventName,
|
||||||
unbind: addEvent(this.node || document, eventName, fn, scope || this)
|
f: fn,
|
||||||
})
|
unbind: addEvent(this.node || document, eventName, fn, scope || this)
|
||||||
} else {
|
})
|
||||||
for (let i = 0, ii = this.events.length; i < ii; i++)
|
} else {
|
||||||
if (this.events[i].name == eventName) {
|
for (let i = 0, ii = this.events.length; i < ii; i++)
|
||||||
try {
|
if (this.events[i].name == eventName) {
|
||||||
this.events[i].f.call(this)
|
try {
|
||||||
} catch (e) {}
|
this.events[i].f.call(this)
|
||||||
}
|
} catch (e) {}
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
Snap['un' + eventName] = elproto['un' + eventName] = function (fn) {
|
|
||||||
let events = this.events || [],
|
|
||||||
l = events.length
|
|
||||||
while (l--)
|
|
||||||
if (events[l].name == eventName && (events[l].f == fn || !fn)) {
|
|
||||||
events[l].unbind()
|
|
||||||
events.splice(l, 1)
|
|
||||||
!events.length && delete this.events
|
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
})(events[i])
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
Snap['un' + eventName] = elproto['un' + eventName] = function (fn) {
|
||||||
|
let events = this.events || [],
|
||||||
|
l = events.length
|
||||||
|
while (l--)
|
||||||
|
if (events[l].name == eventName && (events[l].f == fn || !fn)) {
|
||||||
|
events[l].unbind()
|
||||||
|
events.splice(l, 1)
|
||||||
|
!events.length && delete this.events
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*\
|
/***
|
||||||
* SnapElement.hover
|
* Adds hover event handlers to the element
|
||||||
[ method ]
|
* f_in (function) handler for hover in
|
||||||
**
|
* f_out (function) handler for hover out
|
||||||
* Adds hover event handlers to the element
|
* icontext (object) #optional context for hover in handler
|
||||||
- f_in (function) handler for hover in
|
* ocontext (object) #optional context for hover out handler
|
||||||
- f_out (function) handler for hover out
|
*/
|
||||||
- icontext (object) #optional context for hover in handler
|
|
||||||
- ocontext (object) #optional context for hover out handler
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
elproto.hover = function (f_in, f_out, scope_in, scope_out) {
|
elproto.hover = function (f_in, f_out, scope_in, scope_out) {
|
||||||
return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in)
|
return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in)
|
||||||
}
|
}
|
||||||
/*\
|
/**
|
||||||
* SnapElement.unhover
|
* Removes hover event handlers from the element
|
||||||
[ method ]
|
* f_in (function) handler for hover in
|
||||||
**
|
* f_out (function) handler for hover out
|
||||||
* Removes hover event handlers from the element
|
*/
|
||||||
- f_in (function) handler for hover in
|
|
||||||
- f_out (function) handler for hover out
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
elproto.unhover = function (f_in, f_out) {
|
elproto.unhover = function (f_in, f_out) {
|
||||||
return this.unmouseover(f_in).unmouseout(f_out)
|
return this.unmouseover(f_in).unmouseout(f_out)
|
||||||
}
|
}
|
||||||
let draggable = []
|
let draggable = []
|
||||||
// SIERRA unclear what _context_ refers to for starting, ending, moving the drag gesture.
|
|
||||||
// SIERRA SnapElement.drag(): _x position of the mouse_: Where are the x/y values offset from?
|
|
||||||
// SIERRA SnapElement.drag(): much of this member's doc appears to be duplicated for some reason.
|
|
||||||
// SIERRA Unclear about this sentence: _Additionally following drag events will be triggered: drag.start.<id> on start, drag.end.<id> on end and drag.move.<id> on every move._ Is there a global _drag_ object to which you can assign handlers keyed by an element's id?
|
|
||||||
/*\
|
|
||||||
* SnapElement.drag
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Adds event handlers for an element's drag gesture
|
|
||||||
**
|
|
||||||
- onmove (function) handler for moving
|
|
||||||
- onstart (function) handler for drag start
|
|
||||||
- onend (function) handler for drag end
|
|
||||||
- mcontext (object) #optional context for moving handler
|
|
||||||
- scontext (object) #optional context for drag start handler
|
|
||||||
- econtext (object) #optional context for drag end handler
|
|
||||||
* Additionaly following `drag` events are triggered: `drag.start.<id>` on start,
|
|
||||||
* `drag.end.<id>` on end and `drag.move.<id>` on every move. When element is dragged over another element
|
|
||||||
* `drag.over.<id>` fires as well.
|
|
||||||
*
|
|
||||||
* Start event and start handler are called in specified context or in context of the element with following parameters:
|
|
||||||
o x (number) x position of the mouse
|
|
||||||
o y (number) y position of the mouse
|
|
||||||
o event (object) DOM event object
|
|
||||||
* Move event and move handler are called in specified context or in context of the element with following parameters:
|
|
||||||
o dx (number) shift by x from the start point
|
|
||||||
o dy (number) shift by y from the start point
|
|
||||||
o x (number) x position of the mouse
|
|
||||||
o y (number) y position of the mouse
|
|
||||||
o event (object) DOM event object
|
|
||||||
* End event and end handler are called in specified context or in context of the element with following parameters:
|
|
||||||
o event (object) DOM event object
|
|
||||||
= (object) @SnapElement
|
|
||||||
\*/
|
|
||||||
elproto.drag = function (
|
elproto.drag = function (
|
||||||
onmove,
|
onmove,
|
||||||
onstart,
|
onstart,
|
||||||
|
@ -498,22 +273,7 @@ elproto.drag = function (
|
||||||
el.mousedown(init)
|
el.mousedown(init)
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* SnapElement.onDragOver
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Shortcut to assign event handler for `drag.over.<id>` event, where `id` is the element's `id` (see @SnapElement.id)
|
|
||||||
- f (function) handler for event, first argument would be the element you are dragging over
|
|
||||||
\*/
|
|
||||||
// elproto.onDragOver = function (f) {
|
|
||||||
// f ? eve.on("snap.drag.over." + this.id, f) : eve.unbind("snap.drag.over." + this.id);
|
|
||||||
// };
|
|
||||||
/*\
|
|
||||||
* SnapElement.undrag
|
|
||||||
[ method ]
|
|
||||||
**
|
|
||||||
* Removes all drag event handlers from the given element
|
|
||||||
\*/
|
|
||||||
elproto.undrag = function () {
|
elproto.undrag = function () {
|
||||||
let i = draggable.length
|
let i = draggable.length
|
||||||
while (i--)
|
while (i--)
|
||||||
|
|
47
src/paper.js
47
src/paper.js
|
@ -14,27 +14,19 @@ let proto = Paper.prototype
|
||||||
// gradients
|
// gradients
|
||||||
;(function () {
|
;(function () {
|
||||||
// gradients' helpers
|
// gradients' helpers
|
||||||
/*\
|
/**
|
||||||
* SnapElement.stops
|
* Only for gradients!
|
||||||
[ method ]
|
* Returns array of gradient stops elements.
|
||||||
**
|
*/
|
||||||
* Only for gradients!
|
|
||||||
* Returns array of gradient stops elements.
|
|
||||||
= (array) the stops array.
|
|
||||||
\*/
|
|
||||||
function Gstops() {
|
function Gstops() {
|
||||||
return this.selectAll('stop')
|
return this.selectAll('stop')
|
||||||
}
|
}
|
||||||
/*\
|
/**
|
||||||
* SnapElement.addStop
|
* Only for gradients!
|
||||||
[ method ]
|
* Adds another stop to the gradient.
|
||||||
**
|
* color (string) stops color
|
||||||
* Only for gradients!
|
* offset (number) stops offset 0..100
|
||||||
* Adds another stop to the gradient.
|
*/
|
||||||
- color (string) stops color
|
|
||||||
- offset (number) stops offset 0..100
|
|
||||||
= (object) gradient element
|
|
||||||
\*/
|
|
||||||
function GaddStop(color, offset) {
|
function GaddStop(color, offset) {
|
||||||
let stop = $('stop'),
|
let stop = $('stop'),
|
||||||
attr = {
|
attr = {
|
||||||
|
@ -75,17 +67,14 @@ let proto = Paper.prototype
|
||||||
return Snap._.box(cx - r, cy - r, r * 2, r * 2)
|
return Snap._.box(cx - r, cy - r, r * 2, r * 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*\
|
/**
|
||||||
* SnapElement.setStops
|
* Only for gradients!
|
||||||
[ method ]
|
* Updates stops of the gradient based on passed gradient descriptor. See @Ppaer.gradient
|
||||||
**
|
- str (string) gradient descriptor part after `()`.
|
||||||
* Only for gradients!
|
= (object) gradient element
|
||||||
* Updates stops of the gradient based on passed gradient descriptor. See @Ppaer.gradient
|
| let g = paper.gradient("l(0, 0, 1, 1)#000-#f00-#fff");
|
||||||
- str (string) gradient descriptor part after `()`.
|
| g.setStops("#fff-#000-#f00-#fc0");
|
||||||
= (object) gradient element
|
*/
|
||||||
| let g = paper.gradient("l(0, 0, 1, 1)#000-#f00-#fff");
|
|
||||||
| g.setStops("#fff-#000-#f00-#fc0");
|
|
||||||
\*/
|
|
||||||
function GsetStops(str) {
|
function GsetStops(str) {
|
||||||
let grad = str,
|
let grad = str,
|
||||||
stops = this.stops()
|
stops = this.stops()
|
||||||
|
|
512
src/path.js
512
src/path.js
|
@ -1,29 +1,21 @@
|
||||||
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
|
/**
|
||||||
//
|
* {}
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
* @author yutent<yutent.io@gmail.com>
|
||||||
// you may not use this file except in compliance with the License.
|
* @date 2024/03/08 10:57:37
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
import { Snap, SnapElement, unit2px } from './svg.js'
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
import { Snap, SnapElement, Paper, Fragment, unit2px } from './svg.js'
|
|
||||||
import { is, clone, cacher } from './utils.js'
|
import { is, clone, cacher } from './utils.js'
|
||||||
|
|
||||||
let elproto = SnapElement.prototype,
|
let elproto = SnapElement.prototype,
|
||||||
has = 'hasOwnProperty',
|
has = 'hasOwnProperty',
|
||||||
p2s = /,?([a-z]),?/gi,
|
p2s = /,?([a-z]),?/gi,
|
||||||
toFloat = parseFloat,
|
PI = Math.PI,
|
||||||
math = Math,
|
mmin = Math.min,
|
||||||
PI = math.PI,
|
mmax = Math.max,
|
||||||
mmin = math.min,
|
pow = Math.pow,
|
||||||
mmax = math.max,
|
abs = Math.abs
|
||||||
pow = math.pow,
|
|
||||||
abs = math.abs
|
|
||||||
function paths(ps) {
|
function paths(ps) {
|
||||||
let p = (paths.ps = paths.ps || {})
|
let p = (paths.ps = paths.ps || {})
|
||||||
if (p[ps]) {
|
if (p[ps]) {
|
||||||
|
@ -34,11 +26,12 @@ function paths(ps) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
for (let key in p)
|
for (let key in p) {
|
||||||
if (p[has](key) && key != ps) {
|
if (p[has](key) && key != ps) {
|
||||||
p[key].sleep--
|
p[key].sleep--
|
||||||
!p[key].sleep && delete p[key]
|
!p[key].sleep && delete p[key]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return p[ps]
|
return p[ps]
|
||||||
}
|
}
|
||||||
|
@ -63,9 +56,9 @@ function box(x, y, width, height) {
|
||||||
y2: y + height,
|
y2: y + height,
|
||||||
cx: x + width / 2,
|
cx: x + width / 2,
|
||||||
cy: y + height / 2,
|
cy: y + height / 2,
|
||||||
r1: math.min(width, height) / 2,
|
r1: Math.min(width, height) / 2,
|
||||||
r2: math.max(width, height) / 2,
|
r2: Math.max(width, height) / 2,
|
||||||
r0: math.sqrt(width * width + height * height) / 2,
|
r0: Math.sqrt(width * width + height * height) / 2,
|
||||||
path: rectPath(x, y, width, height),
|
path: rectPath(x, y, width, height),
|
||||||
vb: [x, y, width, height].join(' ')
|
vb: [x, y, width, height].join(' ')
|
||||||
}
|
}
|
||||||
|
@ -221,7 +214,7 @@ function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
|
||||||
ay = t1 * p1y + t * c1y,
|
ay = t1 * p1y + t * c1y,
|
||||||
cx = t1 * c2x + t * p2x,
|
cx = t1 * c2x + t * p2x,
|
||||||
cy = t1 * c2y + t * p2y,
|
cy = t1 * c2y + t * p2y,
|
||||||
alpha = 90 - (math.atan2(mx - nx, my - ny) * 180) / PI
|
alpha = 90 - (Math.atan2(mx - nx, my - ny) * 180) / PI
|
||||||
// (mx > nx || my < ny) && (alpha += 180);
|
// (mx > nx || my < ny) && (alpha += 180);
|
||||||
return {
|
return {
|
||||||
x: x,
|
x: x,
|
||||||
|
@ -297,7 +290,7 @@ function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
|
||||||
xbase = base3(ct, x1, x2, x3, x4),
|
xbase = base3(ct, x1, x2, x3, x4),
|
||||||
ybase = base3(ct, y1, y2, y3, y4),
|
ybase = base3(ct, y1, y2, y3, y4),
|
||||||
comb = xbase * xbase + ybase * ybase
|
comb = xbase * xbase + ybase * ybase
|
||||||
sum += Cvalues[i] * math.sqrt(comb)
|
sum += Cvalues[i] * Math.sqrt(comb)
|
||||||
}
|
}
|
||||||
return z2 * sum
|
return z2 * sum
|
||||||
}
|
}
|
||||||
|
@ -863,15 +856,15 @@ function a2c(
|
||||||
y2,
|
y2,
|
||||||
recursive
|
recursive
|
||||||
) {
|
) {
|
||||||
// for more information of where this math came from visit:
|
// for more information of where this Math came from visit:
|
||||||
// http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
|
// http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
|
||||||
let _120 = (PI * 120) / 180,
|
let _120 = (PI * 120) / 180,
|
||||||
rad = (PI / 180) * (+angle || 0),
|
rad = (PI / 180) * (+angle || 0),
|
||||||
res = [],
|
res = [],
|
||||||
xy,
|
xy,
|
||||||
rotate = cacher(function (x, y, rad) {
|
rotate = cacher(function (x, y, rad) {
|
||||||
let X = x * math.cos(rad) - y * math.sin(rad),
|
let X = x * Math.cos(rad) - y * Math.sin(rad),
|
||||||
Y = x * math.sin(rad) + y * math.cos(rad)
|
Y = x * Math.sin(rad) + y * Math.cos(rad)
|
||||||
return { x: X, y: Y }
|
return { x: X, y: Y }
|
||||||
})
|
})
|
||||||
if (!rx || !ry) {
|
if (!rx || !ry) {
|
||||||
|
@ -884,13 +877,13 @@ function a2c(
|
||||||
xy = rotate(x2, y2, -rad)
|
xy = rotate(x2, y2, -rad)
|
||||||
x2 = xy.x
|
x2 = xy.x
|
||||||
y2 = xy.y
|
y2 = xy.y
|
||||||
let cos = math.cos((PI / 180) * angle),
|
let cos = Math.cos((PI / 180) * angle),
|
||||||
sin = math.sin((PI / 180) * angle),
|
sin = Math.sin((PI / 180) * angle),
|
||||||
x = (x1 - x2) / 2,
|
x = (x1 - x2) / 2,
|
||||||
y = (y1 - y2) / 2
|
y = (y1 - y2) / 2
|
||||||
let h = (x * x) / (rx * rx) + (y * y) / (ry * ry)
|
let h = (x * x) / (rx * rx) + (y * y) / (ry * ry)
|
||||||
if (h > 1) {
|
if (h > 1) {
|
||||||
h = math.sqrt(h)
|
h = Math.sqrt(h)
|
||||||
rx = h * rx
|
rx = h * rx
|
||||||
ry = h * ry
|
ry = h * ry
|
||||||
}
|
}
|
||||||
|
@ -898,7 +891,7 @@ function a2c(
|
||||||
ry2 = ry * ry,
|
ry2 = ry * ry,
|
||||||
k =
|
k =
|
||||||
(large_arc_flag == sweep_flag ? -1 : 1) *
|
(large_arc_flag == sweep_flag ? -1 : 1) *
|
||||||
math.sqrt(
|
Math.sqrt(
|
||||||
abs(
|
abs(
|
||||||
(rx2 * ry2 - rx2 * y * y - ry2 * x * x) /
|
(rx2 * ry2 - rx2 * y * y - ry2 * x * x) /
|
||||||
(rx2 * y * y + ry2 * x * x)
|
(rx2 * y * y + ry2 * x * x)
|
||||||
|
@ -906,8 +899,8 @@ function a2c(
|
||||||
),
|
),
|
||||||
cx = (k * rx * y) / ry + (x1 + x2) / 2,
|
cx = (k * rx * y) / ry + (x1 + x2) / 2,
|
||||||
cy = (k * -ry * x) / rx + (y1 + y2) / 2,
|
cy = (k * -ry * x) / rx + (y1 + y2) / 2,
|
||||||
f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
|
f1 = Math.asin(((y1 - cy) / ry).toFixed(9)),
|
||||||
f2 = math.asin(((y2 - cy) / ry).toFixed(9))
|
f2 = Math.asin(((y2 - cy) / ry).toFixed(9))
|
||||||
|
|
||||||
f1 = x1 < cx ? PI - f1 : f1
|
f1 = x1 < cx ? PI - f1 : f1
|
||||||
f2 = x2 < cx ? PI - f2 : f2
|
f2 = x2 < cx ? PI - f2 : f2
|
||||||
|
@ -931,8 +924,8 @@ function a2c(
|
||||||
x2old = x2,
|
x2old = x2,
|
||||||
y2old = y2
|
y2old = y2
|
||||||
f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1)
|
f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1)
|
||||||
x2 = cx + rx * math.cos(f2)
|
x2 = cx + rx * Math.cos(f2)
|
||||||
y2 = cy + ry * math.sin(f2)
|
y2 = cy + ry * Math.sin(f2)
|
||||||
res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [
|
res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [
|
||||||
f2,
|
f2,
|
||||||
f2old,
|
f2old,
|
||||||
|
@ -941,11 +934,11 @@ function a2c(
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
df = f2 - f1
|
df = f2 - f1
|
||||||
let c1 = math.cos(f1),
|
let c1 = Math.cos(f1),
|
||||||
s1 = math.sin(f1),
|
s1 = Math.sin(f1),
|
||||||
c2 = math.cos(f2),
|
c2 = Math.cos(f2),
|
||||||
s2 = math.sin(f2),
|
s2 = Math.sin(f2),
|
||||||
t = math.tan(df / 4),
|
t = Math.tan(df / 4),
|
||||||
hx = (4 / 3) * rx * t,
|
hx = (4 / 3) * rx * t,
|
||||||
hy = (4 / 3) * ry * t,
|
hy = (4 / 3) * ry * t,
|
||||||
m1 = [x1, y1],
|
m1 = [x1, y1],
|
||||||
|
@ -1020,7 +1013,7 @@ function curveDim(x0, y0, x1, y1, x2, y2, x3, y3) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b2ac = b * b - 4 * c * a
|
b2ac = b * b - 4 * c * a
|
||||||
sqrtb2ac = math.sqrt(b2ac)
|
sqrtb2ac = Math.sqrt(b2ac)
|
||||||
if (b2ac < 0) {
|
if (b2ac < 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1199,10 +1192,10 @@ function path2curve(path, path2) {
|
||||||
seg2len = p2 && seg2.length
|
seg2len = p2 && seg2.length
|
||||||
attrs.x = seg[seglen - 2]
|
attrs.x = seg[seglen - 2]
|
||||||
attrs.y = seg[seglen - 1]
|
attrs.y = seg[seglen - 1]
|
||||||
attrs.bx = toFloat(seg[seglen - 4]) || attrs.x
|
attrs.bx = +seg[seglen - 4] || attrs.x
|
||||||
attrs.by = toFloat(seg[seglen - 3]) || attrs.y
|
attrs.by = +seg[seglen - 3] || attrs.y
|
||||||
attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x)
|
attrs2.bx = p2 && (+seg2[seg2len - 4] || attrs2.x)
|
||||||
attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y)
|
attrs2.by = p2 && (+seg2[seg2len - 3] || attrs2.y)
|
||||||
attrs2.x = p2 && seg2[seg2len - 2]
|
attrs2.x = p2 && seg2[seg2len - 2]
|
||||||
attrs2.y = p2 && seg2[seg2len - 1]
|
attrs2.y = p2 && seg2[seg2len - 1]
|
||||||
}
|
}
|
||||||
|
@ -1272,46 +1265,36 @@ function catmullRom2bezier(crp, z) {
|
||||||
// export
|
// export
|
||||||
Snap.path = paths
|
Snap.path = paths
|
||||||
|
|
||||||
/*\
|
/**
|
||||||
* Snap.path.getTotalLength
|
* Returns the length of the given path in pixels
|
||||||
[ method ]
|
**
|
||||||
**
|
* path (string) SVG path string
|
||||||
* Returns the length of the given path in pixels
|
**
|
||||||
**
|
*/
|
||||||
- path (string) SVG path string
|
|
||||||
**
|
|
||||||
= (number) length
|
|
||||||
\*/
|
|
||||||
Snap.path.getTotalLength = getTotalLength
|
Snap.path.getTotalLength = getTotalLength
|
||||||
/*\
|
/**
|
||||||
* Snap.path.getPointAtLength
|
* Returns the coordinates of the point located at the given length along the given path
|
||||||
[ method ]
|
**
|
||||||
**
|
* path (string) SVG path string
|
||||||
* Returns the coordinates of the point located at the given length along the given path
|
* length (number) length, in pixels, from the start of the path, excluding non-rendering jumps
|
||||||
**
|
**
|
||||||
- path (string) SVG path string
|
= (object) representation of the point:
|
||||||
- length (number) length, in pixels, from the start of the path, excluding non-rendering jumps
|
{
|
||||||
**
|
x: (number) x coordinate,
|
||||||
= (object) representation of the point:
|
y: (number) y coordinate,
|
||||||
o {
|
alpha: (number) angle of derivative
|
||||||
o x: (number) x coordinate,
|
}
|
||||||
o y: (number) y coordinate,
|
*/
|
||||||
o alpha: (number) angle of derivative
|
|
||||||
o }
|
|
||||||
\*/
|
|
||||||
Snap.path.getPointAtLength = getPointAtLength
|
Snap.path.getPointAtLength = getPointAtLength
|
||||||
/*\
|
/**
|
||||||
* Snap.path.getSubpath
|
* Returns the subpath of a given path between given start and end lengths
|
||||||
[ method ]
|
**
|
||||||
**
|
- path (string) SVG path string
|
||||||
* Returns the subpath of a given path between given start and end lengths
|
- from (number) length, in pixels, from the start of the path to the start of the segment
|
||||||
**
|
- to (number) length, in pixels, from the start of the path to the end of the segment
|
||||||
- path (string) SVG path string
|
**
|
||||||
- from (number) length, in pixels, from the start of the path to the start of the segment
|
= (string) path string definition for the segment
|
||||||
- to (number) length, in pixels, from the start of the path to the end of the segment
|
*/
|
||||||
**
|
|
||||||
= (string) path string definition for the segment
|
|
||||||
\*/
|
|
||||||
Snap.path.getSubpath = function (path, from, to) {
|
Snap.path.getSubpath = function (path, from, to) {
|
||||||
if (this.getTotalLength(path) - to < 1e-6) {
|
if (this.getTotalLength(path) - to < 1e-6) {
|
||||||
return getSubpathsAtLength(path, from).end
|
return getSubpathsAtLength(path, from).end
|
||||||
|
@ -1319,133 +1302,113 @@ Snap.path.getSubpath = function (path, from, to) {
|
||||||
let a = getSubpathsAtLength(path, to, 1)
|
let a = getSubpathsAtLength(path, to, 1)
|
||||||
return from ? getSubpathsAtLength(a, from).end : a
|
return from ? getSubpathsAtLength(a, from).end : a
|
||||||
}
|
}
|
||||||
/*\
|
/**
|
||||||
* SnapElement.getTotalLength
|
* Returns the length of the path in pixels (only works for `path` elements)
|
||||||
[ method ]
|
= (number) length
|
||||||
**
|
*/
|
||||||
* Returns the length of the path in pixels (only works for `path` elements)
|
|
||||||
= (number) length
|
|
||||||
\*/
|
|
||||||
elproto.getTotalLength = function () {
|
elproto.getTotalLength = function () {
|
||||||
if (this.node.getTotalLength) {
|
if (this.node.getTotalLength) {
|
||||||
return this.node.getTotalLength()
|
return this.node.getTotalLength()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// SIERRA SnapElement.getPointAtLength()/SnapElement.getTotalLength(): If a <path> is broken into different segments, is the jump distance to the new coordinates set by the _M_ or _m_ commands calculated as part of the path's total length?
|
// SIERRA SnapElement.getPointAtLength()/SnapElement.getTotalLength(): If a <path> is broken into different segments, is the jump distance to the new coordinates set by the _M_ or _m_ commands calculated as part of the path's total length?
|
||||||
/*\
|
/**
|
||||||
* SnapElement.getPointAtLength
|
* Returns coordinates of the point located at the given length on the given path (only works for `path` elements)
|
||||||
[ method ]
|
**
|
||||||
**
|
- length (number) length, in pixels, from the start of the path, excluding non-rendering jumps
|
||||||
* Returns coordinates of the point located at the given length on the given path (only works for `path` elements)
|
**
|
||||||
**
|
= (object) representation of the point:
|
||||||
- length (number) length, in pixels, from the start of the path, excluding non-rendering jumps
|
{
|
||||||
**
|
x: (number) x coordinate,
|
||||||
= (object) representation of the point:
|
y: (number) y coordinate,
|
||||||
o {
|
alpha: (number) angle of derivative
|
||||||
o x: (number) x coordinate,
|
}
|
||||||
o y: (number) y coordinate,
|
*/
|
||||||
o alpha: (number) angle of derivative
|
|
||||||
o }
|
|
||||||
\*/
|
|
||||||
elproto.getPointAtLength = function (length) {
|
elproto.getPointAtLength = function (length) {
|
||||||
return getPointAtLength(this.attr('d'), length)
|
return getPointAtLength(this.attr('d'), length)
|
||||||
}
|
}
|
||||||
// SIERRA SnapElement.getSubpath(): Similar to the problem for SnapElement.getPointAtLength(). Unclear how this would work for a segmented path. Overall, the concept of _subpath_ and what I'm calling a _segment_ (series of non-_M_ or _Z_ commands) is unclear.
|
// SIERRA SnapElement.getSubpath(): Similar to the problem for SnapElement.getPointAtLength(). Unclear how this would work for a segmented path. Overall, the concept of _subpath_ and what I'm calling a _segment_ (series of non-_M_ or _Z_ commands) is unclear.
|
||||||
/*\
|
/**
|
||||||
* SnapElement.getSubpath
|
* Returns subpath of a given element from given start and end lengths (only works for `path` elements)
|
||||||
[ method ]
|
**
|
||||||
**
|
- from (number) length, in pixels, from the start of the path to the start of the segment
|
||||||
* Returns subpath of a given element from given start and end lengths (only works for `path` elements)
|
- to (number) length, in pixels, from the start of the path to the end of the segment
|
||||||
**
|
**
|
||||||
- from (number) length, in pixels, from the start of the path to the start of the segment
|
= (string) path string definition for the segment
|
||||||
- to (number) length, in pixels, from the start of the path to the end of the segment
|
*/
|
||||||
**
|
|
||||||
= (string) path string definition for the segment
|
|
||||||
\*/
|
|
||||||
elproto.getSubpath = function (from, to) {
|
elproto.getSubpath = function (from, to) {
|
||||||
return Snap.path.getSubpath(this.attr('d'), from, to)
|
return Snap.path.getSubpath(this.attr('d'), from, to)
|
||||||
}
|
}
|
||||||
Snap._.box = box
|
Snap._.box = box
|
||||||
/*\
|
/**
|
||||||
* Snap.path.findDotsAtSegment
|
* Utility method
|
||||||
[ method ]
|
**
|
||||||
**
|
* Finds dot coordinates on the given cubic beziér curve at the given t
|
||||||
* Utility method
|
- p1x (number) x of the first point of the curve
|
||||||
**
|
- p1y (number) y of the first point of the curve
|
||||||
* Finds dot coordinates on the given cubic beziér curve at the given t
|
- c1x (number) x of the first anchor of the curve
|
||||||
- p1x (number) x of the first point of the curve
|
- c1y (number) y of the first anchor of the curve
|
||||||
- p1y (number) y of the first point of the curve
|
- c2x (number) x of the second anchor of the curve
|
||||||
- c1x (number) x of the first anchor of the curve
|
- c2y (number) y of the second anchor of the curve
|
||||||
- c1y (number) y of the first anchor of the curve
|
- p2x (number) x of the second point of the curve
|
||||||
- c2x (number) x of the second anchor of the curve
|
- p2y (number) y of the second point of the curve
|
||||||
- c2y (number) y of the second anchor of the curve
|
- t (number) position on the curve (0..1)
|
||||||
- p2x (number) x of the second point of the curve
|
= (object) point information in format:
|
||||||
- p2y (number) y of the second point of the curve
|
{
|
||||||
- t (number) position on the curve (0..1)
|
x: (number) x coordinate of the point,
|
||||||
= (object) point information in format:
|
y: (number) y coordinate of the point,
|
||||||
o {
|
m: {
|
||||||
o x: (number) x coordinate of the point,
|
x: (number) x coordinate of the left anchor,
|
||||||
o y: (number) y coordinate of the point,
|
y: (number) y coordinate of the left anchor
|
||||||
o m: {
|
},
|
||||||
o x: (number) x coordinate of the left anchor,
|
n: {
|
||||||
o y: (number) y coordinate of the left anchor
|
x: (number) x coordinate of the right anchor,
|
||||||
o },
|
y: (number) y coordinate of the right anchor
|
||||||
o n: {
|
},
|
||||||
o x: (number) x coordinate of the right anchor,
|
start: {
|
||||||
o y: (number) y coordinate of the right anchor
|
x: (number) x coordinate of the start of the curve,
|
||||||
o },
|
y: (number) y coordinate of the start of the curve
|
||||||
o start: {
|
},
|
||||||
o x: (number) x coordinate of the start of the curve,
|
end: {
|
||||||
o y: (number) y coordinate of the start of the curve
|
x: (number) x coordinate of the end of the curve,
|
||||||
o },
|
y: (number) y coordinate of the end of the curve
|
||||||
o end: {
|
},
|
||||||
o x: (number) x coordinate of the end of the curve,
|
alpha: (number) angle of the curve derivative at the point
|
||||||
o y: (number) y coordinate of the end of the curve
|
}
|
||||||
o },
|
*/
|
||||||
o alpha: (number) angle of the curve derivative at the point
|
|
||||||
o }
|
|
||||||
\*/
|
|
||||||
Snap.path.findDotsAtSegment = findDotsAtSegment
|
Snap.path.findDotsAtSegment = findDotsAtSegment
|
||||||
/*\
|
/**
|
||||||
* Snap.path.bezierBBox
|
**
|
||||||
[ method ]
|
* Returns the bounding box of a given cubic beziér curve
|
||||||
**
|
- p1x (number) x of the first point of the curve
|
||||||
* Utility method
|
- p1y (number) y of the first point of the curve
|
||||||
**
|
- c1x (number) x of the first anchor of the curve
|
||||||
* Returns the bounding box of a given cubic beziér curve
|
- c1y (number) y of the first anchor of the curve
|
||||||
- p1x (number) x of the first point of the curve
|
- c2x (number) x of the second anchor of the curve
|
||||||
- p1y (number) y of the first point of the curve
|
- c2y (number) y of the second anchor of the curve
|
||||||
- c1x (number) x of the first anchor of the curve
|
- p2x (number) x of the second point of the curve
|
||||||
- c1y (number) y of the first anchor of the curve
|
- p2y (number) y of the second point of the curve
|
||||||
- c2x (number) x of the second anchor of the curve
|
* or
|
||||||
- c2y (number) y of the second anchor of the curve
|
- bez (array) array of six points for beziér curve
|
||||||
- p2x (number) x of the second point of the curve
|
= (object) bounding box
|
||||||
- p2y (number) y of the second point of the curve
|
o {
|
||||||
* or
|
o x: (number) x coordinate of the left top point of the box,
|
||||||
- bez (array) array of six points for beziér curve
|
o y: (number) y coordinate of the left top point of the box,
|
||||||
= (object) bounding box
|
o x2: (number) x coordinate of the right bottom point of the box,
|
||||||
o {
|
o y2: (number) y coordinate of the right bottom point of the box,
|
||||||
o x: (number) x coordinate of the left top point of the box,
|
o width: (number) width of the box,
|
||||||
o y: (number) y coordinate of the left top point of the box,
|
o height: (number) height of the box
|
||||||
o x2: (number) x coordinate of the right bottom point of the box,
|
o }
|
||||||
o y2: (number) y coordinate of the right bottom point of the box,
|
*/
|
||||||
o width: (number) width of the box,
|
|
||||||
o height: (number) height of the box
|
|
||||||
o }
|
|
||||||
\*/
|
|
||||||
Snap.path.bezierBBox = bezierBBox
|
Snap.path.bezierBBox = bezierBBox
|
||||||
/*\
|
/**
|
||||||
* Snap.path.isPointInsideBBox
|
**
|
||||||
[ method ]
|
* Returns `true` if given point is inside bounding box
|
||||||
**
|
- bbox (string) bounding box
|
||||||
* Utility method
|
- x (string) x coordinate of the point
|
||||||
**
|
- y (string) y coordinate of the point
|
||||||
* Returns `true` if given point is inside bounding box
|
= (boolean) `true` if point is inside
|
||||||
- bbox (string) bounding box
|
*/
|
||||||
- x (string) x coordinate of the point
|
|
||||||
- y (string) y coordinate of the point
|
|
||||||
= (boolean) `true` if point is inside
|
|
||||||
\*/
|
|
||||||
Snap.path.isPointInsideBBox = isPointInsideBBox
|
Snap.path.isPointInsideBBox = isPointInsideBBox
|
||||||
Snap.closest = function (x, y, X, Y) {
|
Snap.closest = function (x, y, X, Y) {
|
||||||
let r = 100,
|
let r = 100,
|
||||||
|
@ -1506,108 +1469,75 @@ Snap.closest = function (x, y, X, Y) {
|
||||||
= (boolean) `true` if bounding boxes intersect
|
= (boolean) `true` if bounding boxes intersect
|
||||||
\*/
|
\*/
|
||||||
Snap.path.isBBoxIntersect = isBBoxIntersect
|
Snap.path.isBBoxIntersect = isBBoxIntersect
|
||||||
/*\
|
/**
|
||||||
* Snap.path.intersection
|
* Finds intersections of two paths
|
||||||
[ method ]
|
- path1 (string) path string
|
||||||
**
|
- path2 (string) path string
|
||||||
* Utility method
|
= (array) dots of intersection
|
||||||
**
|
o [
|
||||||
* Finds intersections of two paths
|
o {
|
||||||
- path1 (string) path string
|
o x: (number) x coordinate of the point,
|
||||||
- path2 (string) path string
|
o y: (number) y coordinate of the point,
|
||||||
= (array) dots of intersection
|
o t1: (number) t value for segment of path1,
|
||||||
o [
|
o t2: (number) t value for segment of path2,
|
||||||
o {
|
o segment1: (number) order number for segment of path1,
|
||||||
o x: (number) x coordinate of the point,
|
o segment2: (number) order number for segment of path2,
|
||||||
o y: (number) y coordinate of the point,
|
o bez1: (array) eight coordinates representing beziér curve for the segment of path1,
|
||||||
o t1: (number) t value for segment of path1,
|
o bez2: (array) eight coordinates representing beziér curve for the segment of path2
|
||||||
o t2: (number) t value for segment of path2,
|
o }
|
||||||
o segment1: (number) order number for segment of path1,
|
o ]
|
||||||
o segment2: (number) order number for segment of path2,
|
*/
|
||||||
o bez1: (array) eight coordinates representing beziér curve for the segment of path1,
|
|
||||||
o bez2: (array) eight coordinates representing beziér curve for the segment of path2
|
|
||||||
o }
|
|
||||||
o ]
|
|
||||||
\*/
|
|
||||||
Snap.path.intersection = pathIntersection
|
Snap.path.intersection = pathIntersection
|
||||||
Snap.path.intersectionNumber = pathIntersectionNumber
|
Snap.path.intersectionNumber = pathIntersectionNumber
|
||||||
/*\
|
/**
|
||||||
* Snap.path.isPointInside
|
* Returns `true` if given point is inside a given closed path.
|
||||||
[ method ]
|
*
|
||||||
**
|
* Note: fill mode doesn’t affect the result of this method.
|
||||||
* Utility method
|
- path (string) path string
|
||||||
**
|
- x (number) x of the point
|
||||||
* Returns `true` if given point is inside a given closed path.
|
- y (number) y of the point
|
||||||
*
|
= (boolean) `true` if point is inside the path
|
||||||
* Note: fill mode doesn’t affect the result of this method.
|
*/
|
||||||
- path (string) path string
|
|
||||||
- x (number) x of the point
|
|
||||||
- y (number) y of the point
|
|
||||||
= (boolean) `true` if point is inside the path
|
|
||||||
\*/
|
|
||||||
Snap.path.isPointInside = isPointInsidePath
|
Snap.path.isPointInside = isPointInsidePath
|
||||||
/*\
|
/**
|
||||||
* Snap.path.getBBox
|
* Returns the bounding box of a given path
|
||||||
[ method ]
|
- path (string) path string
|
||||||
**
|
= (object) bounding box
|
||||||
* Utility method
|
o {
|
||||||
**
|
o x: (number) x coordinate of the left top point of the box,
|
||||||
* Returns the bounding box of a given path
|
o y: (number) y coordinate of the left top point of the box,
|
||||||
- path (string) path string
|
o x2: (number) x coordinate of the right bottom point of the box,
|
||||||
= (object) bounding box
|
o y2: (number) y coordinate of the right bottom point of the box,
|
||||||
o {
|
o width: (number) width of the box,
|
||||||
o x: (number) x coordinate of the left top point of the box,
|
o height: (number) height of the box
|
||||||
o y: (number) y coordinate of the left top point of the box,
|
o }
|
||||||
o x2: (number) x coordinate of the right bottom point of the box,
|
*/
|
||||||
o y2: (number) y coordinate of the right bottom point of the box,
|
|
||||||
o width: (number) width of the box,
|
|
||||||
o height: (number) height of the box
|
|
||||||
o }
|
|
||||||
\*/
|
|
||||||
Snap.path.getBBox = pathBBox
|
Snap.path.getBBox = pathBBox
|
||||||
Snap.path.get = getPath
|
Snap.path.get = getPath
|
||||||
/*\
|
/**
|
||||||
* Snap.path.toRelative
|
* Converts path coordinates into relative values
|
||||||
[ method ]
|
- path (string) path string
|
||||||
**
|
= (array) path string
|
||||||
* Utility method
|
*/
|
||||||
**
|
|
||||||
* Converts path coordinates into relative values
|
|
||||||
- path (string) path string
|
|
||||||
= (array) path string
|
|
||||||
\*/
|
|
||||||
Snap.path.toRelative = pathToRelative
|
Snap.path.toRelative = pathToRelative
|
||||||
/*\
|
/**
|
||||||
* Snap.path.toAbsolute
|
* Converts path coordinates into absolute values
|
||||||
[ method ]
|
- path (string) path string
|
||||||
**
|
= (array) path string
|
||||||
* Utility method
|
*/
|
||||||
**
|
|
||||||
* Converts path coordinates into absolute values
|
|
||||||
- path (string) path string
|
|
||||||
= (array) path string
|
|
||||||
\*/
|
|
||||||
Snap.path.toAbsolute = pathToAbsolute
|
Snap.path.toAbsolute = pathToAbsolute
|
||||||
/*\
|
/**
|
||||||
* Snap.path.toCubic
|
* Converts path to a new path where all segments are cubic beziér curves
|
||||||
[ method ]
|
- pathString (string|array) path string or array of segments
|
||||||
**
|
= (array) array of segments
|
||||||
* Utility method
|
*/
|
||||||
**
|
|
||||||
* Converts path to a new path where all segments are cubic beziér curves
|
|
||||||
- pathString (string|array) path string or array of segments
|
|
||||||
= (array) array of segments
|
|
||||||
\*/
|
|
||||||
Snap.path.toCubic = path2curve
|
Snap.path.toCubic = path2curve
|
||||||
/*\
|
/**
|
||||||
* Snap.path.map
|
* Transform the path string with the given matrix
|
||||||
[ method ]
|
- path (string) path string
|
||||||
**
|
- matrix (object) see @Matrix
|
||||||
* Transform the path string with the given matrix
|
= (string) transformed path string
|
||||||
- path (string) path string
|
*/
|
||||||
- matrix (object) see @Matrix
|
|
||||||
= (string) transformed path string
|
|
||||||
\*/
|
|
||||||
Snap.path.map = mapPath
|
Snap.path.map = mapPath
|
||||||
Snap.path.toString = toString
|
Snap.path.toString = toString
|
||||||
Snap.path.clone = pathClone
|
Snap.path.clone = pathClone
|
||||||
|
|
Loading…
Reference in New Issue