Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

@leafer/platform

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer/platform - npm Package Compare versions

Comparing version
1.9.12
to
1.10.0
+4
-4
package.json
{
"name": "@leafer/platform",
"version": "1.9.12",
"version": "1.10.0",
"description": "@leafer/platform",

@@ -25,8 +25,8 @@ "author": "Chao (Leafer) Wan",

"dependencies": {
"@leafer/data": "1.9.12",
"@leafer/debug": "1.9.12"
"@leafer/data": "1.10.0",
"@leafer/debug": "1.10.0"
},
"devDependencies": {
"@leafer/interface": "1.9.12"
"@leafer/interface": "1.10.0"
}
}

@@ -1,4 +0,7 @@

import { IPlatform } from '@leafer/interface'
import { IPlatform, IObject, IBoundsData, ICanvasPattern, IMatrixData, ILeaferImagePatternPaint, ISizeData, ICanvasContext2D } from '@leafer/interface'
import { DataHelper } from '@leafer/data'
const { floor, max } = Math
export const Platform: IPlatform = {

@@ -16,2 +19,8 @@ toURL(text: string, fileType?: 'text' | 'svg'): string {

crossOrigin: 'anonymous',
isLarge(size: ISizeData, scaleX?: number, scaleY?: number, largeSize?: number): boolean {
return size.width * size.height * (scaleX ? scaleX * scaleY : 1) > (largeSize || image.maxCacheSize)
},
isSuperLarge(size: ISizeData, scaleX?: number, scaleY?: number): boolean {
return image.isLarge(size, scaleX, scaleY, image.maxPatternSize)
},
getRealURL(url: string): string {

@@ -22,4 +31,27 @@ const { prefix, suffix } = Platform.image

return url
},
resize(image: any, width: number, height: number, xGap?: number, yGap?: number, clip?: IBoundsData, smooth?: boolean, opacity?: number, _filters?: IObject): any {
const canvas = Platform.origin.createCanvas(max(floor(width + (xGap || 0)), 1), max(floor(height + (yGap || 0)), 1),)
const ctx: ICanvasContext2D = canvas.getContext('2d')
if (opacity) ctx.globalAlpha = opacity
ctx.imageSmoothingEnabled = smooth === false ? false : true // 平滑绘制
if (clip) {
const scaleX = width / clip.width, scaleY = height / clip.height
ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY)
ctx.drawImage(image, 0, 0, image.width, image.height)
} else ctx.drawImage(image, 0, 0, width, height)
return canvas
},
setPatternTransform(pattern: ICanvasPattern, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): void {
try {
if (transform && pattern.setTransform) {
pattern.setTransform(transform) // maybe error
transform = undefined
}
} catch { }
if (paint) DataHelper.stintSet(paint, 'transform', transform)
}
}
}
}
const { image } = Platform