From 0856676330bd213ea9ec332b3d455d0054290e31 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 8 Mar 2024 14:05:08 +0800 Subject: [PATCH] update --- src/svg.js | 117 +++++++++++++++++++++------------------------------ src/utils.js | 2 +- 2 files changed, 48 insertions(+), 71 deletions(-) diff --git a/src/svg.js b/src/svg.js index a36ba8d..29df646 100644 --- a/src/svg.js +++ b/src/svg.js @@ -1,16 +1,9 @@ -// Copyright (c) 2013 - 2017 Adobe Systems Incorporated. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// 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. +/** + * {} + * @author yutent + * @date 2024/03/08 10:59:09 + */ + import eve from './eve.js' import { @@ -102,28 +95,14 @@ export class Fragment { } } -/*\ - ** - * Creates a drawing surface or wraps existing SVG element. - ** - - width (number|string) width of surface - - height (number|string) height of surface - * or - - DOM (SVGElement) element to be wrapped into Snap structure - * or - - array (array) array of elements (will return set of elements) - * or - - query (string) CSS query selector - = (object) @SnapElement -\*/ export class Snap { static _ = { $ } - /*\ - ** - * Parses SVG fragment and converts it into a @Fragment - ** -\*/ + /* + ** + * Parses SVG fragment and converts it into a @Fragment + ** + */ static parse(svg) { let f = doc.createDocumentFragment(), full = true, @@ -285,7 +264,7 @@ export class Snap { return value } - /*\ + /* ** * Returns you topmost element under given point. ** @@ -294,11 +273,9 @@ export class Snap { - y (number) y coordinate from the top left corner of the window > Usage | Snap.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"}); -\*/ +*/ static getElementByPoint(x, y) { - let paper = this, - svg = paper.canvas, - target = doc.elementFromPoint(x, y) + let target = doc.elementFromPoint(x, y) if (!target) { return null @@ -963,7 +940,7 @@ export class Paper { return this.el('polygon', attr) } - /*\ + /* ** * Creates an element on paper with a given name and no attributes ** @@ -983,31 +960,31 @@ export class Paper { | cy: 10, | r: 10 | }); -\*/ +*/ el(name, attr) { let el = make(name, this.node) attr && el.attr(attr) return el } - /*\ - * - * Draws a rectangle - ** - - x (number) x coordinate of the top left corner - - y (number) y coordinate of the top left corner - - width (number) width - - height (number) height - - rx (number) #optional horizontal radius for rounded corners, default is 0 - - ry (number) #optional vertical radius for rounded corners, default is rx or 0 - = (object) the `rect` element - ** - > Usage - | // regular rectangle - | let c = paper.rect(10, 10, 50, 50); - | // rectangle with rounded corners - | let c = paper.rect(40, 40, 50, 50, 10); - \*/ + /* + * + * Draws a rectangle + ** + - x (number) x coordinate of the top left corner + - y (number) y coordinate of the top left corner + - width (number) width + - height (number) height + - rx (number) #optional horizontal radius for rounded corners, default is 0 + - ry (number) #optional vertical radius for rounded corners, default is rx or 0 + = (object) the `rect` element + ** + > Usage + | // regular rectangle + | let c = paper.rect(10, 10, 50, 50); + | // rectangle with rounded corners + | let c = paper.rect(40, 40, 50, 50, 10); + */ rect(x, y, w, h, rx, ry) { let attr if (ry == null) { @@ -1150,19 +1127,19 @@ export class Paper { return el } - /*\ - ** - * Creates a `` element - ** - - filstr (string) SVG fragment of filter provided as a string - = (object) @SnapElement - * Note: It is recommended to use filters embedded into the page inside an empty SVG element. - > Usage - | let f = paper.filter(''), - | c = paper.circle(10, 10, 10).attr({ - | filter: f - | }); - \*/ + /* + ** + * Creates a `` element + ** + - filstr (string) SVG fragment of filter provided as a string + = (object) @SnapElement + * Note: It is recommended to use filters embedded into the page inside an empty SVG element. + > Usage + | let f = paper.filter(''), + | c = paper.circle(10, 10, 10).attr({ + | filter: f + | }); + */ filter(filstr) { let paper = this if (paper.type !== 'svg') { diff --git a/src/utils.js b/src/utils.js index 470b6a2..b2b32f6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -103,7 +103,7 @@ function repush(arr, item) { let l = arr.length - 1 // 要减1, 最后如果本身在最后, 不用变 for (let i = 0; i < l; i++) { if (arr[i] === item) { - ;[a[i], a[l]] = [a[l], a[i]] + ;[arr[i], arr[l]] = [arr[l], arr[i]] break } }