@leafer-ui/export
Advanced tools
+4
-4
| { | ||
| "name": "@leafer-ui/export", | ||
| "version": "1.0.0-rc.12", | ||
| "version": "1.0.0-rc.16", | ||
| "description": "@leafer-ui/export", | ||
@@ -25,8 +25,8 @@ "author": "Chao (Leafer) Wan", | ||
| "dependencies": { | ||
| "@leafer/core": "1.0.0-rc.12" | ||
| "@leafer/core": "1.0.0-rc.16" | ||
| }, | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.0.0-rc.12", | ||
| "@leafer-ui/interface": "1.0.0-rc.12" | ||
| "@leafer/interface": "1.0.0-rc.16", | ||
| "@leafer-ui/interface": "1.0.0-rc.16" | ||
| } | ||
| } |
+45
-20
@@ -1,3 +0,3 @@ | ||
| import { IExportFileType, IFunction, IRenderOptions, IBoundsData, IBounds } from '@leafer/interface' | ||
| import { Creator, Matrix, TaskProcessor, FileHelper } from '@leafer/core' | ||
| import { IExportFileType, IFunction, IRenderOptions, IBoundsData, IBounds, ILocationType } from '@leafer/interface' | ||
| import { Creator, Matrix, TaskProcessor, FileHelper, Bounds } from '@leafer/core' | ||
@@ -28,31 +28,44 @@ import { IExportModule, IExportOptions, IExportResult, IExportResultFunction, IUI } from '@leafer-ui/interface' | ||
| options = FileHelper.getExportOptions(options) | ||
| let renderBounds: IBoundsData, trimBounds: IBounds, scaleX = 1, scaleY = 1 | ||
| options = FileHelper.getExportOptions(options) | ||
| const { scale, slice, trim } = options | ||
| const { worldTransform, isLeafer, isFrame } = leaf | ||
| const { slice, trim, onCanvas } = options | ||
| const scale = options.scale || 1 | ||
| const pixelRatio = options.pixelRatio || 1 | ||
| const screenshot = options.screenshot || leaf.isApp | ||
| const fill = options.fill === undefined ? ((leaf.isLeafer && screenshot) ? leaf.fill : '') : options.fill // leafer use | ||
| const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : undefined) : options.fill // leafer use | ||
| const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix() | ||
| if (screenshot) { | ||
| renderBounds = screenshot === true ? (leaf.isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot | ||
| renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot | ||
| } else { | ||
| const { localTransform, __world: world } = leaf | ||
| matrix.set(world).divide(localTransform).invert() | ||
| scaleX = 1 / (world.scaleX / leaf.scaleX) | ||
| scaleY = 1 / (world.scaleY / leaf.scaleY) | ||
| renderBounds = leaf.getBounds('render', 'local') | ||
| } | ||
| const location: ILocationType = options.location || ((isLeafer || isFrame) ? 'inner' : 'local') | ||
| let { x, y, width, height } = renderBounds | ||
| scaleX = worldTransform.scaleX | ||
| scaleY = worldTransform.scaleY | ||
| if (scale) { | ||
| matrix.scale(scale) | ||
| width *= scale, height *= scale | ||
| scaleX *= scale, scaleY *= scale | ||
| switch (location) { | ||
| case 'inner': | ||
| matrix.set(worldTransform).invert() | ||
| break | ||
| case 'local': | ||
| matrix.set(worldTransform).divide(leaf.localTransform).invert() | ||
| scaleX /= leaf.scaleX | ||
| scaleY /= leaf.scaleY | ||
| break | ||
| case 'world': | ||
| scaleX = 1 | ||
| scaleY = 1 | ||
| break | ||
| } | ||
| renderBounds = leaf.getBounds('render', location) | ||
| } | ||
| let canvas = Creator.canvas({ width: Math.ceil(width), height: Math.ceil(height), pixelRatio }) | ||
| const renderOptions: IRenderOptions = { matrix: matrix.translate(-x, -y).withScale(scaleX, scaleY) } | ||
| const { x, y, width, height } = new Bounds(renderBounds).scale(scale).ceil() | ||
| let canvas = Creator.canvas({ width, height, pixelRatio }) | ||
| const renderOptions: IRenderOptions = { matrix: matrix.scale(scale).translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) } | ||
| if (slice) { | ||
@@ -63,6 +76,17 @@ leaf = leafer // render all in bounds | ||
| canvas.save() | ||
| leaf.__render(canvas, renderOptions) | ||
| if (isFrame && fill !== undefined) { | ||
| const oldFill = leaf.get('fill') | ||
| leaf.fill = '' | ||
| leaf.__render(canvas, renderOptions) | ||
| leaf.fill = oldFill as string | ||
| } else { | ||
| leaf.__render(canvas, renderOptions) | ||
| } | ||
| canvas.restore() | ||
| if (trim) { | ||
@@ -78,2 +102,3 @@ trimBounds = getTrimBounds(canvas) | ||
| if (needFill) canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over') | ||
| if (onCanvas) onCanvas(canvas) | ||
@@ -80,0 +105,0 @@ const data = filename === 'canvas' ? canvas : await canvas.export(filename, options) |
8160
14.66%112
19.15%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated