master
yutent 2024-03-08 14:05:08 +08:00
parent d9eff8e338
commit 0856676330
2 changed files with 48 additions and 71 deletions

View File

@ -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<yutent.io@gmail.com>
* @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 `<filter>` 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('<feGaussianBlur stdDeviation="2"/>'),
| c = paper.circle(10, 10, 10).attr({
| filter: f
| });
\*/
/*
**
* Creates a `<filter>` 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('<feGaussianBlur stdDeviation="2"/>'),
| c = paper.circle(10, 10, 10).attr({
| filter: f
| });
*/
filter(filstr) {
let paper = this
if (paper.type !== 'svg') {

View File

@ -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
}
}