@leafer-draw/node 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node.cjs +128 -114
- package/dist/node.cjs.map +1 -1
- package/dist/node.esm.js +129 -115
- package/dist/node.esm.js.map +1 -1
- package/dist/node.esm.min.js +1 -1
- package/dist/node.esm.min.js.map +1 -1
- package/dist/node.min.cjs +1 -1
- package/dist/node.min.cjs.map +1 -1
- package/package.json +8 -8
package/dist/node.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { LeaferCanvasBase, Platform, canvasPatch, FileHelper, Creator, LeaferIma
|
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
4
|
import { writeFileSync } from 'fs';
|
|
5
|
-
import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect, TwoPointBoundsHelper, Bounds as Bounds$1, FileHelper as FileHelper$1,
|
|
5
|
+
import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect, TwoPointBoundsHelper, Bounds as Bounds$1, FileHelper as FileHelper$1, Platform as Platform$1, Matrix, MathHelper as MathHelper$1, Creator as Creator$1, TaskProcessor, Resource, LeaferCanvasBase as LeaferCanvasBase$1, Debug as Debug$1, Plugin, UI } from '@leafer-ui/draw';
|
|
6
6
|
export * from '@leafer-ui/draw';
|
|
7
7
|
|
|
8
8
|
/******************************************************************************
|
|
@@ -1967,13 +1967,14 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
1967
1967
|
}
|
|
1968
1968
|
|
|
1969
1969
|
function layoutText(drawData, style) {
|
|
1970
|
-
const { rows, bounds } = drawData;
|
|
1970
|
+
const { rows, bounds } = drawData, countRows = rows.length;
|
|
1971
1971
|
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
|
|
1972
|
-
let { x, y, width, height } = bounds, realHeight = __lineHeight *
|
|
1972
|
+
let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
1973
1973
|
let starY = __baseLine;
|
|
1974
1974
|
if (__clipText && realHeight > height) {
|
|
1975
1975
|
realHeight = Math.max(height, __lineHeight);
|
|
1976
|
-
|
|
1976
|
+
if (countRows > 1)
|
|
1977
|
+
drawData.overflow = countRows;
|
|
1977
1978
|
}
|
|
1978
1979
|
else if (height || autoSizeAlign) {
|
|
1979
1980
|
switch (verticalAlign) {
|
|
@@ -1985,7 +1986,7 @@ function layoutText(drawData, style) {
|
|
|
1985
1986
|
}
|
|
1986
1987
|
starY += y;
|
|
1987
1988
|
let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
|
|
1988
|
-
for (let i = 0, len =
|
|
1989
|
+
for (let i = 0, len = countRows; i < len; i++) {
|
|
1989
1990
|
row = rows[i];
|
|
1990
1991
|
row.x = x;
|
|
1991
1992
|
if (row.width < width || (row.width > width && !__clipText)) {
|
|
@@ -2054,7 +2055,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2054
2055
|
if (i === end && charRight < right) {
|
|
2055
2056
|
break;
|
|
2056
2057
|
}
|
|
2057
|
-
else if (charRight < right && char.char !== ' ') {
|
|
2058
|
+
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2058
2059
|
row.data.splice(i + 1);
|
|
2059
2060
|
row.width -= char.width;
|
|
2060
2061
|
break;
|
|
@@ -2198,124 +2199,134 @@ function getTrimBounds(canvas) {
|
|
|
2198
2199
|
}
|
|
2199
2200
|
|
|
2200
2201
|
const ExportModule = {
|
|
2201
|
-
|
|
2202
|
+
syncExport(leaf, filename, options) {
|
|
2202
2203
|
this.running = true;
|
|
2204
|
+
let result;
|
|
2203
2205
|
const fileType = FileHelper$1.fileType(filename);
|
|
2204
2206
|
const isDownload = filename.includes('.');
|
|
2205
2207
|
options = FileHelper$1.getExportOptions(options);
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2208
|
+
const { toURL } = Platform$1;
|
|
2209
|
+
const { download } = Platform$1.origin;
|
|
2210
|
+
if (fileType === 'json') {
|
|
2211
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2212
|
+
result = { data: isDownload ? true : leaf.toJSON(options.json) };
|
|
2213
|
+
}
|
|
2214
|
+
else if (fileType === 'svg') {
|
|
2215
|
+
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2216
|
+
result = { data: isDownload ? true : leaf.toSVG() };
|
|
2217
|
+
}
|
|
2218
|
+
else {
|
|
2219
|
+
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2220
|
+
const { worldTransform, isLeafer, leafer, isFrame } = leaf;
|
|
2221
|
+
const { slice, trim, padding, onCanvas } = options;
|
|
2222
|
+
const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
|
|
2223
|
+
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2224
|
+
const screenshot = options.screenshot || leaf.isApp;
|
|
2225
|
+
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2226
|
+
const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
2227
|
+
if (screenshot) {
|
|
2228
|
+
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2217
2229
|
}
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2230
|
+
else {
|
|
2231
|
+
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2232
|
+
scaleX = worldTransform.scaleX;
|
|
2233
|
+
scaleY = worldTransform.scaleY;
|
|
2234
|
+
switch (relative) {
|
|
2235
|
+
case 'inner':
|
|
2236
|
+
matrix.set(worldTransform);
|
|
2237
|
+
break;
|
|
2238
|
+
case 'local':
|
|
2239
|
+
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2240
|
+
scaleX /= leaf.scaleX;
|
|
2241
|
+
scaleY /= leaf.scaleY;
|
|
2242
|
+
break;
|
|
2243
|
+
case 'world':
|
|
2244
|
+
scaleX = 1;
|
|
2245
|
+
scaleY = 1;
|
|
2246
|
+
break;
|
|
2247
|
+
case 'page':
|
|
2248
|
+
relative = leafer || leaf;
|
|
2249
|
+
default:
|
|
2250
|
+
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2251
|
+
const l = relative.worldTransform;
|
|
2252
|
+
scaleX /= scaleX / l.scaleX;
|
|
2253
|
+
scaleY /= scaleY / l.scaleY;
|
|
2254
|
+
}
|
|
2255
|
+
renderBounds = leaf.getBounds('render', relative);
|
|
2221
2256
|
}
|
|
2222
|
-
const {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2247
|
-
scaleX /= leaf.scaleX;
|
|
2248
|
-
scaleY /= leaf.scaleY;
|
|
2249
|
-
break;
|
|
2250
|
-
case 'world':
|
|
2251
|
-
scaleX = 1;
|
|
2252
|
-
scaleY = 1;
|
|
2253
|
-
break;
|
|
2254
|
-
case 'page':
|
|
2255
|
-
relative = leaf.leafer;
|
|
2256
|
-
default:
|
|
2257
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2258
|
-
const l = relative.worldTransform;
|
|
2259
|
-
scaleX /= scaleX / l.scaleX;
|
|
2260
|
-
scaleY /= scaleY / l.scaleY;
|
|
2261
|
-
}
|
|
2262
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
2263
|
-
}
|
|
2264
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2265
|
-
MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2266
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2267
|
-
if (leaf.isApp) {
|
|
2268
|
-
scaleData.scaleX *= pixelRatio;
|
|
2269
|
-
scaleData.scaleY *= pixelRatio;
|
|
2270
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
2271
|
-
}
|
|
2272
|
-
const { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2273
|
-
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2274
|
-
let canvas = Creator$1.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
2275
|
-
let sliceLeaf;
|
|
2276
|
-
if (slice) {
|
|
2277
|
-
sliceLeaf = leaf;
|
|
2278
|
-
sliceLeaf.__worldOpacity = 0;
|
|
2279
|
-
leaf = leafer;
|
|
2280
|
-
renderOptions.bounds = canvas.bounds;
|
|
2281
|
-
}
|
|
2282
|
-
canvas.save();
|
|
2283
|
-
if (isFrame && fill !== undefined) {
|
|
2284
|
-
const oldFill = leaf.get('fill');
|
|
2285
|
-
leaf.fill = '';
|
|
2286
|
-
leaf.__render(canvas, renderOptions);
|
|
2287
|
-
leaf.fill = oldFill;
|
|
2288
|
-
}
|
|
2289
|
-
else {
|
|
2290
|
-
leaf.__render(canvas, renderOptions);
|
|
2291
|
-
}
|
|
2292
|
-
canvas.restore();
|
|
2293
|
-
if (sliceLeaf)
|
|
2294
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2295
|
-
if (trim) {
|
|
2296
|
-
trimBounds = getTrimBounds(canvas);
|
|
2297
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2298
|
-
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
2299
|
-
canvas = Creator$1.canvas(config);
|
|
2300
|
-
canvas.copyWorld(old, trimBounds, config);
|
|
2301
|
-
}
|
|
2302
|
-
if (padding) {
|
|
2303
|
-
const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
|
|
2304
|
-
const old = canvas, { width, height } = old;
|
|
2305
|
-
canvas = Creator$1.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
|
|
2306
|
-
canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
|
|
2307
|
-
}
|
|
2308
|
-
if (needFill)
|
|
2309
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2310
|
-
if (onCanvas)
|
|
2311
|
-
onCanvas(canvas);
|
|
2312
|
-
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
2313
|
-
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
2314
|
-
}));
|
|
2257
|
+
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2258
|
+
MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2259
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
2260
|
+
if (leaf.isApp) {
|
|
2261
|
+
scaleData.scaleX *= pixelRatio;
|
|
2262
|
+
scaleData.scaleY *= pixelRatio;
|
|
2263
|
+
pixelRatio = leaf.app.pixelRatio;
|
|
2264
|
+
}
|
|
2265
|
+
const { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2266
|
+
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2267
|
+
let canvas = Creator$1.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
|
|
2268
|
+
let sliceLeaf;
|
|
2269
|
+
if (slice) {
|
|
2270
|
+
sliceLeaf = leaf;
|
|
2271
|
+
sliceLeaf.__worldOpacity = 0;
|
|
2272
|
+
leaf = leafer || leaf;
|
|
2273
|
+
renderOptions.bounds = canvas.bounds;
|
|
2274
|
+
}
|
|
2275
|
+
canvas.save();
|
|
2276
|
+
if (isFrame && fill !== undefined) {
|
|
2277
|
+
const oldFill = leaf.get('fill');
|
|
2278
|
+
leaf.fill = '';
|
|
2279
|
+
leaf.__render(canvas, renderOptions);
|
|
2280
|
+
leaf.fill = oldFill;
|
|
2315
2281
|
}
|
|
2316
2282
|
else {
|
|
2317
|
-
|
|
2283
|
+
leaf.__render(canvas, renderOptions);
|
|
2284
|
+
}
|
|
2285
|
+
canvas.restore();
|
|
2286
|
+
if (sliceLeaf)
|
|
2287
|
+
sliceLeaf.__updateWorldOpacity();
|
|
2288
|
+
if (trim) {
|
|
2289
|
+
trimBounds = getTrimBounds(canvas);
|
|
2290
|
+
const old = canvas, { width, height } = trimBounds;
|
|
2291
|
+
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
2292
|
+
canvas = Creator$1.canvas(config);
|
|
2293
|
+
canvas.copyWorld(old, trimBounds, config);
|
|
2294
|
+
}
|
|
2295
|
+
if (padding) {
|
|
2296
|
+
const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
|
|
2297
|
+
const old = canvas, { width, height } = old;
|
|
2298
|
+
canvas = Creator$1.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
|
|
2299
|
+
canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
|
|
2318
2300
|
}
|
|
2301
|
+
if (needFill)
|
|
2302
|
+
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2303
|
+
if (onCanvas)
|
|
2304
|
+
onCanvas(canvas);
|
|
2305
|
+
const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
|
|
2306
|
+
result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
|
|
2307
|
+
}
|
|
2308
|
+
this.running = false;
|
|
2309
|
+
return result;
|
|
2310
|
+
},
|
|
2311
|
+
export(leaf, filename, options) {
|
|
2312
|
+
this.running = true;
|
|
2313
|
+
return addTask((success) => new Promise((resolve) => {
|
|
2314
|
+
const getResult = () => __awaiter(this, void 0, void 0, function* () {
|
|
2315
|
+
if (!Resource.isComplete)
|
|
2316
|
+
return Platform$1.requestRender(getResult);
|
|
2317
|
+
const result = ExportModule.syncExport(leaf, filename, options);
|
|
2318
|
+
if (result.data instanceof Promise)
|
|
2319
|
+
result.data = yield result.data;
|
|
2320
|
+
success(result);
|
|
2321
|
+
resolve();
|
|
2322
|
+
});
|
|
2323
|
+
leaf.updateLayout();
|
|
2324
|
+
checkLazy(leaf);
|
|
2325
|
+
const { leafer } = leaf;
|
|
2326
|
+
if (leafer)
|
|
2327
|
+
leafer.waitViewCompleted(getResult);
|
|
2328
|
+
else
|
|
2329
|
+
getResult();
|
|
2319
2330
|
}));
|
|
2320
2331
|
}
|
|
2321
2332
|
};
|
|
@@ -2374,6 +2385,9 @@ Object.assign(Export, ExportModule);
|
|
|
2374
2385
|
UI.prototype.export = function (filename, options) {
|
|
2375
2386
|
return Export.export(this, filename, options);
|
|
2376
2387
|
};
|
|
2388
|
+
UI.prototype.syncExport = function (filename, options) {
|
|
2389
|
+
return Export.syncExport(this, filename, options);
|
|
2390
|
+
};
|
|
2377
2391
|
|
|
2378
2392
|
export { Layouter, LeaferCanvas, Renderer, Watcher, useCanvas };
|
|
2379
2393
|
//# sourceMappingURL=node.esm.js.map
|