You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@leafer-ui/export

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer-ui/export - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+4
-4
package.json
{
"name": "@leafer-ui/export",
"version": "1.0.1",
"version": "1.0.2",
"description": "@leafer-ui/export",

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

"dependencies": {
"@leafer/core": "1.0.1"
"@leafer/core": "1.0.2"
},
"devDependencies": {
"@leafer/interface": "1.0.1",
"@leafer-ui/interface": "1.0.1"
"@leafer/interface": "1.0.2",
"@leafer-ui/interface": "1.0.2"
}
}
import { IExportFileType, IFunction, IRenderOptions, IBoundsData, IBounds, ILocationType, ILeaf } from '@leafer/interface'
import { Creator, Matrix, TaskProcessor, FileHelper, Bounds, Platform } from '@leafer/core'
import { Creator, Matrix, TaskProcessor, FileHelper, Bounds, Platform, MathHelper } from '@leafer/core'

@@ -15,2 +15,3 @@ import { IExportModule, IExportOptions, IExportResult, IExportResultFunction, IUI } from '@leafer-ui/interface'

const fileType = FileHelper.fileType(filename)
const isDownload = filename.includes('.')
options = FileHelper.getExportOptions(options)

@@ -31,14 +32,11 @@

if (filename === 'json') {
return over({ data: leaf.toJSON(options.json) })
} else if (fileType === 'json') {
download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename)
return over({ data: true })
if (fileType === 'json') {
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename)
return over({ data: isDownload ? true : leaf.toJSON(options.json) })
}
if (filename === 'svg') {
return over({ data: leaf.toSVG() })
} else if (fileType === 'svg') {
download(toURL(leaf.toSVG(), 'svg'), filename)
return over({ data: true })
if (fileType === 'svg') {
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename)
return over({ data: isDownload ? true : leaf.toSVG() })
}

@@ -57,12 +55,5 @@

const { slice, trim, onCanvas } = options
let scale = options.scale || 1
let pixelRatio = options.pixelRatio || 1
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth
const contextSettings = options.contextSettings || leafer.config.contextSettings
if (leaf.isApp) {
scale *= pixelRatio // app 只能以自身的pixelRatio导出,需转移到scale上
pixelRatio = leaf.app.pixelRatio
}
const screenshot = options.screenshot || leaf.isApp

@@ -72,2 +63,3 @@ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill // leafer use

// 获取元素大小
if (screenshot) {

@@ -106,6 +98,19 @@ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot

const { x, y, width, height } = new Bounds(renderBounds).scale(scale)
// 缩放元素
const scaleData = { scaleX: 1, scaleY: 1 }
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData)
let pixelRatio = options.pixelRatio || 1
if (leaf.isApp) {
scaleData.scaleX *= pixelRatio // app 只能以自身的pixelRatio导出,需转移到scale上
scaleData.scaleY *= pixelRatio
pixelRatio = leaf.app.pixelRatio
}
// 导出元素
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY)
const renderOptions: IRenderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) }
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings })
const renderOptions: IRenderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) }

@@ -112,0 +117,0 @@ let sliceLeaf: IUI