master
yutent 2024-03-12 14:55:40 +08:00
parent c22a7adbb0
commit ca02ac252b
4 changed files with 86 additions and 110 deletions

View File

@ -1,24 +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/12 14:42:41
// 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.
// ┌────────────────────────────────────────────────────────────┐ \\
// │ Eve 0.5.4 - JavaScript Events Library │ \\
// ├────────────────────────────────────────────────────────────┤ \\
// │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
// └────────────────────────────────────────────────────────────┘ \\
let version = '0.5.4', let has = 'hasOwnProperty',
has = 'hasOwnProperty',
separator = /[\.\/]/, separator = /[\.\/]/,
comaseparator = /\s*,\s*/, comaseparator = /\s*,\s*/,
wildcard = '*', wildcard = '*',
@ -50,9 +36,7 @@ let version = '0.5.4',
function (ar) { function (ar) {
return ar instanceof Array || objtos.call(ar) == '[object Array]' return ar instanceof Array || objtos.call(ar) == '[object Array]'
}, },
/*\ /*
* eve
[ method ]
* Fires event with given `name`, given scope and other parameters. * Fires event with given `name`, given scope and other parameters.
@ -61,10 +45,9 @@ let version = '0.5.4',
- varargs (...) the rest of arguments will be sent to event handlers - varargs (...) the rest of arguments will be sent to event handlers
= (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value. = (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value.
\*/ */
eve = function (name, scope) { eve = function (name, scope, ...args) {
let oldstop = stop, let oldstop = stop,
args = Array.prototype.slice.call(arguments, 2),
listeners = eve.listeners(name), listeners = eve.listeners(name),
z = 0, z = 0,
l, l,
@ -124,16 +107,14 @@ let version = '0.5.4',
} }
// Undocumented. Debug only. // Undocumented. Debug only.
eve._events = events eve._events = events
/*\ /*
* eve.listeners
[ method ]
* Internal method which gives you array of all event handlers that will be triggered by the given `name`. * Internal method which gives you array of all event handlers that will be triggered by the given `name`.
- name (string) name of the event, dot (`.`) or slash (`/`) separated - name (string) name of the event, dot (`.`) or slash (`/`) separated
= (array) array of event handlers = (array) array of event handlers
\*/ */
eve.listeners = function (name) { eve.listeners = function (name) {
let names = isArray(name) ? name : name.split(separator), let names = isArray(name) ? name : name.split(separator),
e = events, e = events,
@ -184,9 +165,7 @@ eve.separator = function (sep) {
separator = /[\.\/]/ separator = /[\.\/]/
} }
} }
/*\ /*
* eve.on
[ method ]
** **
* Binds given event handler with a given name. You can use wildcards `*` for the names: * Binds given event handler with a given name. You can use wildcards `*` for the names:
| eve.on("*.under.*", f); | eve.on("*.under.*", f);
@ -208,16 +187,14 @@ eve.separator = function (sep) {
* *
* If you want to put your handler before non-indexed handlers, specify a negative value. * If you want to put your handler before non-indexed handlers, specify a negative value.
* Note: I assume most of the time you dont need to worry about z-index, but its nice to have this feature just in case. * Note: I assume most of the time you dont need to worry about z-index, but its nice to have this feature just in case.
\*/ */
eve.on = function (name, f) { eve.on = function (name, f) {
if (typeof f != 'function') {
return function () {}
}
let names = isArray(name) let names = isArray(name)
? isArray(name[0]) ? isArray(name[0])
? name ? name
: [name] : [name]
: Str(name).split(comaseparator) : Str(name).split(comaseparator)
for (let i = 0, ii = names.length; i < ii; i++) { for (let i = 0, ii = names.length; i < ii; i++) {
;(function (name) { ;(function (name) {
let names = isArray(name) ? name : Str(name).split(separator), let names = isArray(name) ? name : Str(name).split(separator),

View File

@ -10,67 +10,67 @@ export const xlink = 'http://www.w3.org/1999/xlink'
export const xmlns = 'http://www.w3.org/2000/svg' export const xmlns = 'http://www.w3.org/2000/svg'
export const CSS_ATTR = { export const CSS_ATTR = {
// 'alignment-baseline': 1, 'alignment-baseline': 1,
// 'baseline-shift': 1, 'baseline-shift': 1,
// clip: 1, clip: 1,
// 'clip-path': 1, 'clip-path': 1,
// 'clip-rule': 1, 'clip-rule': 1,
// color: 1, color: 1,
// 'color-interpolation': 1, 'color-interpolation': 1,
// 'color-interpolation-filters': 1, 'color-interpolation-filters': 1,
// 'color-profile': 1, 'color-profile': 1,
// 'color-rendering': 1, 'color-rendering': 1,
// cursor: 1, cursor: 1,
// direction: 1, direction: 1,
// display: 1, display: 1,
// 'dominant-baseline': 1, 'dominant-baseline': 1,
// 'enable-background': 1, 'enable-background': 1,
// fill: 1, fill: 1,
// 'fill-opacity': 1, 'fill-opacity': 1,
// 'fill-rule': 1, 'fill-rule': 1,
// filter: 1, filter: 1,
// 'flood-color': 1, 'flood-color': 1,
// 'flood-opacity': 1, 'flood-opacity': 1,
// font: 1, font: 1,
// 'font-family': 1, 'font-family': 1,
// 'font-size': 1, 'font-size': 1,
// 'font-size-adjust': 1, 'font-size-adjust': 1,
// 'font-stretch': 1, 'font-stretch': 1,
// 'font-style': 1, 'font-style': 1,
// 'font-variant': 1, 'font-variant': 1,
// 'font-weight': 1, 'font-weight': 1,
// 'glyph-orientation-horizontal': 1, 'glyph-orientation-horizontal': 1,
// 'glyph-orientation-vertical': 1, 'glyph-orientation-vertical': 1,
// 'image-rendering': 1, 'image-rendering': 1,
// kerning: 1, kerning: 1,
// 'letter-spacing': 1, 'letter-spacing': 1,
// 'lighting-color': 1, 'lighting-color': 1,
// marker: 1, marker: 1,
// 'marker-end': 1, 'marker-end': 1,
// 'marker-mid': 1, 'marker-mid': 1,
// 'marker-start': 1, 'marker-start': 1,
// mask: 1, mask: 1,
// opacity: 1, opacity: 1,
// overflow: 1, overflow: 1,
// 'pointer-events': 1, 'pointer-events': 1,
// 'shape-rendering': 1, 'shape-rendering': 1,
// 'stop-color': 1, 'stop-color': 1,
// 'stop-opacity': 1, 'stop-opacity': 1,
// stroke: 1, stroke: 1,
// 'stroke-dasharray': 1, 'stroke-dasharray': 1,
// 'stroke-dashoffset': 1, 'stroke-dashoffset': 1,
// 'stroke-linecap': 1, 'stroke-linecap': 1,
// 'stroke-linejoin': 1, 'stroke-linejoin': 1,
// 'stroke-miterlimit': 1, 'stroke-miterlimit': 1,
// 'stroke-opacity': 1, 'stroke-opacity': 1,
// 'stroke-width': 1, 'stroke-width': 1,
// 'text-anchor': 1, 'text-anchor': 1,
// 'text-decoration': 1, 'text-decoration': 1,
// 'text-rendering': 1, 'text-rendering': 1,
// 'unicode-bidi': 1, 'unicode-bidi': 1,
// visibility: 1, visibility: 1,
// 'word-spacing': 1, 'word-spacing': 1,
// 'writing-mode': 1 'writing-mode': 1
} }
export const ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i export const ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i

View File

@ -987,19 +987,19 @@ export class Paper {
*/ */
rect(x, y, w, h, rx, ry) { rect(x, y, w, h, rx, ry) {
let attr let attr
if (ry == null) { if (ry === void 0) {
ry = rx ry = rx
} }
if (is(x, 'object') && x == '[object Object]') { if (is(x, 'object') && x == '[object Object]') {
attr = x attr = x
} else if (x != null) { } else if (x !== void 0) {
attr = { attr = {
x: x, x: x,
y: y, y: y,
width: w, width: w,
height: h height: h
} }
if (rx != null) { if (rx !== void 0) {
attr.rx = rx attr.rx = rx
attr.ry = ry attr.ry = ry
} }
@ -1403,7 +1403,6 @@ eve.on('snap.util.getattr', function () {
eve.on('snap.util.attr', function (value) { eve.on('snap.util.attr', function (value) {
let key = eve.nt().split('.').at(-1) let key = eve.nt().split('.').at(-1)
let attr = { [key]: value }
let css = key.replace(/[A-Z]/g, function (letter) { let css = key.replace(/[A-Z]/g, function (letter) {
return '-' + letter.toLowerCase() return '-' + letter.toLowerCase()
@ -1411,6 +1410,6 @@ eve.on('snap.util.attr', function (value) {
if (CSS_ATTR[css]) { if (CSS_ATTR[css]) {
this.node.style[css] = value == null ? E : value this.node.style[css] = value == null ? E : value
} else { } else {
$(this.node, attr) $(this.node, { [css]: value })
} }
}) })

View File

@ -29,21 +29,21 @@ export function is(o, type) {
export function $(el, attr) { export function $(el, attr) {
if (attr) { if (attr) {
if (el == '#text') { if (el === '#text') {
el = doc.createTextNode(attr.text || attr['#text'] || '') el = doc.createTextNode(attr.text || attr['#text'] || '')
} }
if (el == '#comment') { if (el === '#comment') {
el = doc.createComment(attr.text || attr['#text'] || '') el = doc.createComment(attr.text || attr['#text'] || '')
} }
if (typeof el == 'string') { if (typeof el === 'string') {
el = $(el) el = $(el)
} }
if (typeof attr == 'string') { if (typeof attr === 'string') {
if (el.nodeType == 1) { if (el.nodeType === 1) {
if (attr.slice(0, 6) == 'xlink:') { if (attr.slice(0, 6) === 'xlink:') {
return el.getAttributeNS(xlink, attr.slice(6)) return el.getAttributeNS(xlink, attr.slice(6))
} }
if (attr.slice(0, 4) == 'xml:') { if (attr.slice(0, 4) === 'xml:') {
return el.getAttributeNS(xmlns, attr.slice(4)) return el.getAttributeNS(xmlns, attr.slice(4))
} }
return el.getAttribute(attr) return el.getAttribute(attr)