@leafer/image-web
Advanced tools
+2
-2
| { | ||
| "name": "@leafer/image-web", | ||
| "version": "1.0.0-alpha.9", | ||
| "version": "1.0.0-alpha.10", | ||
| "description": "@leafer/image-web", | ||
@@ -22,4 +22,4 @@ "author": "Chao (Leafer) Wan", | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.0.0-alpha.9" | ||
| "@leafer/interface": "1.0.0-alpha.10" | ||
| } | ||
| } |
+19
-3
@@ -1,12 +0,28 @@ | ||
| import { IObject } from "@leafer/interface" | ||
| import { ILeaferImage, ILeaferImageConfig } from "@leafer/interface" | ||
| export class LeaferImage { | ||
| export class LeaferImage implements ILeaferImage { | ||
| constructor(_options: IObject) { | ||
| options: ILeaferImageConfig | ||
| constructor(_options: ILeaferImageConfig) { | ||
| this.options = _options | ||
| this.load() | ||
| } | ||
| load(): Promise<HTMLImageElement | HTMLCanvasElement> { | ||
| return new Promise((resolve, reject) => { | ||
| let src: string = this.options.url | ||
| let img = new Image() | ||
| img.setAttribute('crossOrigin', 'anonymous') | ||
| img.crossOrigin = 'anonymous' | ||
| img.onload = () => resolve(img) | ||
| img.onerror = (e) => { console.error(e, this), reject(new Error('load Image error')) } | ||
| img.src = src.includes("?") ? src + "&xhr" : src + "?xhr" // 需要带上xhr区分image标签的缓存,否则导致浏览器跨域问题 | ||
| }) | ||
| } | ||
| public destory(): void { | ||
| } | ||
| } |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
2623
39.97%20
233.33%0
-100%