@leafer-draw/node 1.3.3 → 1.4.1

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.esm.js CHANGED
@@ -1,8 +1,8 @@
1
- import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4 } from '@leafer/core';
1
+ import { LeaferCanvasBase, Platform, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4 } from '@leafer/core';
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, Bounds as Bounds$1, TwoPointBoundsHelper, FileHelper as FileHelper$1, TaskProcessor, Platform as Platform$1, Matrix, MathHelper as MathHelper$1, Creator as Creator$1, LeaferCanvasBase as LeaferCanvasBase$1, Debug as Debug$1, Plugin, UI } from '@leafer-ui/draw';
5
+ import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect, TwoPointBoundsHelper, Bounds as Bounds$1, FileHelper as FileHelper$1, TaskProcessor, Platform as Platform$1, Matrix, MathHelper as MathHelper$1, Creator as Creator$1, 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
  /******************************************************************************
@@ -84,8 +84,8 @@ function useCanvas(canvasType, power) {
84
84
  Platform.origin = {
85
85
  createCanvas: (width, height, format) => new Canvas(width, height, format),
86
86
  canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
87
- canvasToBolb: (canvas, type, quality) => __awaiter(this, undefined, undefined, function* () { return canvas.toBuffer(mineType(type), quality); }),
88
- canvasSaveAs: (canvas, filename, quality) => __awaiter(this, undefined, undefined, function* () { return writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
87
+ canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function* () { return canvas.toBuffer(mineType(type), quality); }),
88
+ canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function* () { return writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
89
89
  download(_url, _filename) { return undefined; },
90
90
  loadImage(src) { return loadImage(Platform.image.getRealURL(src)); }
91
91
  };
@@ -360,7 +360,7 @@ class Layouter {
360
360
  }
361
361
  partLayout() {
362
362
  var _a;
363
- if (!((_a = this.__updatedList) === null || _a === undefined ? undefined : _a.length))
363
+ if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
364
364
  return;
365
365
  const t = Run.start('PartLayout');
366
366
  const { target, __updatedList: updateList } = this;
@@ -1050,7 +1050,7 @@ function getPatternData(paint, box, image) {
1050
1050
  box = tempBox.set(box).shrink(paint.padding);
1051
1051
  if (paint.mode === 'strench')
1052
1052
  paint.mode = 'stretch';
1053
- const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1053
+ const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
1054
1054
  const sameBox = box.width === width && box.height === height;
1055
1055
  const data = { mode };
1056
1056
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -1113,6 +1113,8 @@ function getPatternData(paint, box, image) {
1113
1113
  data.height = height;
1114
1114
  if (opacity)
1115
1115
  data.opacity = opacity;
1116
+ if (filters)
1117
+ data.filters = filters;
1116
1118
  if (repeat)
1117
1119
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1118
1120
  return data;
@@ -1215,7 +1217,7 @@ function createPattern(ui, paint, pixelRatio) {
1215
1217
  scaleX = abs$1(scaleX);
1216
1218
  scaleY = abs$1(scaleY);
1217
1219
  const { image, data } = paint;
1218
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
1220
+ let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1219
1221
  if (sx) {
1220
1222
  imageMatrix = get$1();
1221
1223
  copy$1(imageMatrix, transform);
@@ -1258,7 +1260,7 @@ function createPattern(ui, paint, pixelRatio) {
1258
1260
  }
1259
1261
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1260
1262
  }
1261
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, opacity);
1263
+ const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1262
1264
  const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1263
1265
  paint.style = pattern;
1264
1266
  paint.patternId = id;
@@ -1302,7 +1304,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1302
1304
  canvas.opacity *= data.opacity;
1303
1305
  if (data.transform)
1304
1306
  canvas.transform(data.transform);
1305
- canvas.drawImage(paint.image.view, 0, 0, data.width, data.height);
1307
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1306
1308
  canvas.restore();
1307
1309
  return true;
1308
1310
  }
@@ -1312,7 +1314,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1312
1314
  }
1313
1315
  else {
1314
1316
  if (!paint.patternTask) {
1315
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, undefined, undefined, function* () {
1317
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1316
1318
  paint.patternTask = null;
1317
1319
  if (canvas.bounds.hit(ui.__nowWorld))
1318
1320
  createPattern(ui, paint, pixelRatio);
@@ -1902,11 +1904,11 @@ const TextMode = 2;
1902
1904
  function layoutChar(drawData, style, width, _height) {
1903
1905
  const { rows } = drawData;
1904
1906
  const { textAlign, paraIndent, letterSpacing } = style;
1905
- let charX, addWordWidth, indentWidth, mode, wordChar;
1907
+ let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
1906
1908
  rows.forEach(row => {
1907
1909
  if (row.words) {
1908
- indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
1909
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
1910
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
1911
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
1910
1912
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
1911
1913
  if (row.isOverflow && !letterSpacing)
1912
1914
  row.textMode = true;
@@ -1918,7 +1920,7 @@ function layoutChar(drawData, style, width, _height) {
1918
1920
  row.x += indentWidth;
1919
1921
  charX = row.x;
1920
1922
  row.data = [];
1921
- row.words.forEach(word => {
1923
+ row.words.forEach((word, index) => {
1922
1924
  if (mode === WordMode) {
1923
1925
  wordChar = { char: '', x: charX };
1924
1926
  charX = toWordChar(word.data, charX, wordChar);
@@ -1928,7 +1930,7 @@ function layoutChar(drawData, style, width, _height) {
1928
1930
  else {
1929
1931
  charX = toChar(word.data, charX, row.data, row.isOverflow);
1930
1932
  }
1931
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
1933
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
1932
1934
  charX += addWordWidth;
1933
1935
  row.width += addWordWidth;
1934
1936
  }
@@ -2220,7 +2222,7 @@ const ExportModule = {
2220
2222
  const { leafer } = leaf;
2221
2223
  if (leafer) {
2222
2224
  checkLazy(leaf);
2223
- leafer.waitViewCompleted(() => __awaiter(this, undefined, undefined, function* () {
2225
+ leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
2224
2226
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2225
2227
  const { worldTransform, isLeafer, isFrame } = leaf;
2226
2228
  const { slice, trim, padding, onCanvas } = options;
@@ -2322,7 +2324,7 @@ function addTask(task) {
2322
2324
  if (!tasker)
2323
2325
  tasker = new TaskProcessor();
2324
2326
  return new Promise((resolve) => {
2325
- tasker.add(() => __awaiter(this, undefined, undefined, function* () { return yield task(resolve); }), { parallel: false });
2327
+ tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
2326
2328
  });
2327
2329
  }
2328
2330
  function checkLazy(leaf) {
@@ -2374,3 +2376,4 @@ UI.prototype.export = function (filename, options) {
2374
2376
  };
2375
2377
 
2376
2378
  export { Layouter, LeaferCanvas, Renderer, Watcher, useCanvas };
2379
+ //# sourceMappingURL=node.esm.js.map