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"); * @author yutent<yutent.io@gmail.com>
// you may not use this file except in compliance with the License. * @date 2024/03/08 10:59:09
// 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 { 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 { export class Snap {
static _ = { $ } static _ = { $ }
/*\ /*
** **
* Parses SVG fragment and converts it into a @Fragment * Parses SVG fragment and converts it into a @Fragment
** **
\*/ */
static parse(svg) { static parse(svg) {
let f = doc.createDocumentFragment(), let f = doc.createDocumentFragment(),
full = true, full = true,
@ -285,7 +264,7 @@ export class Snap {
return value return value
} }
/*\ /*
** **
* Returns you topmost element under given point. * 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 - y (number) y coordinate from the top left corner of the window
> Usage > Usage
| Snap.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"}); | Snap.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"});
\*/ */
static getElementByPoint(x, y) { static getElementByPoint(x, y) {
let paper = this, let target = doc.elementFromPoint(x, y)
svg = paper.canvas,
target = doc.elementFromPoint(x, y)
if (!target) { if (!target) {
return null return null
@ -963,7 +940,7 @@ export class Paper {
return this.el('polygon', attr) return this.el('polygon', attr)
} }
/*\ /*
** **
* Creates an element on paper with a given name and no attributes * Creates an element on paper with a given name and no attributes
** **
@ -983,14 +960,14 @@ export class Paper {
| cy: 10, | cy: 10,
| r: 10 | r: 10
| }); | });
\*/ */
el(name, attr) { el(name, attr) {
let el = make(name, this.node) let el = make(name, this.node)
attr && el.attr(attr) attr && el.attr(attr)
return el return el
} }
/*\ /*
* *
* Draws a rectangle * Draws a rectangle
** **
@ -1007,7 +984,7 @@ export class Paper {
| let c = paper.rect(10, 10, 50, 50); | let c = paper.rect(10, 10, 50, 50);
| // rectangle with rounded corners | // rectangle with rounded corners
| let c = paper.rect(40, 40, 50, 50, 10); | let c = paper.rect(40, 40, 50, 50, 10);
\*/ */
rect(x, y, w, h, rx, ry) { rect(x, y, w, h, rx, ry) {
let attr let attr
if (ry == null) { if (ry == null) {
@ -1150,7 +1127,7 @@ export class Paper {
return el return el
} }
/*\ /*
** **
* Creates a `<filter>` element * Creates a `<filter>` element
** **
@ -1162,7 +1139,7 @@ export class Paper {
| c = paper.circle(10, 10, 10).attr({ | c = paper.circle(10, 10, 10).attr({
| filter: f | filter: f
| }); | });
\*/ */
filter(filstr) { filter(filstr) {
let paper = this let paper = this
if (paper.type !== 'svg') { if (paper.type !== 'svg') {

View File

@ -103,7 +103,7 @@ function repush(arr, item) {
let l = arr.length - 1 // 要减1, 最后如果本身在最后, 不用变 let l = arr.length - 1 // 要减1, 最后如果本身在最后, 不用变
for (let i = 0; i < l; i++) { for (let i = 0; i < l; i++) {
if (arr[i] === item) { if (arr[i] === item) {
;[a[i], a[l]] = [a[l], a[i]] ;[arr[i], arr[l]] = [arr[l], arr[i]]
break break
} }
} }