@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.cjs CHANGED
@@ -83,8 +83,8 @@ function useCanvas(canvasType, power) {
83
83
  core.Platform.origin = {
84
84
  createCanvas: (width, height, format) => new Canvas(width, height, format),
85
85
  canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
86
- canvasToBolb: (canvas, type, quality) => __awaiter(this, undefined, undefined, function* () { return canvas.toBuffer(mineType(type), quality); }),
87
- canvasSaveAs: (canvas, filename, quality) => __awaiter(this, undefined, undefined, function* () { return fs.writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
86
+ canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function* () { return canvas.toBuffer(mineType(type), quality); }),
87
+ canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function* () { return fs.writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
88
88
  download(_url, _filename) { return undefined; },
89
89
  loadImage(src) { return loadImage(core.Platform.image.getRealURL(src)); }
90
90
  };
@@ -359,7 +359,7 @@ class Layouter {
359
359
  }
360
360
  partLayout() {
361
361
  var _a;
362
- if (!((_a = this.__updatedList) === null || _a === undefined ? undefined : _a.length))
362
+ if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
363
363
  return;
364
364
  const t = core.Run.start('PartLayout');
365
365
  const { target, __updatedList: updateList } = this;
@@ -1049,7 +1049,7 @@ function getPatternData(paint, box, image) {
1049
1049
  box = tempBox.set(box).shrink(paint.padding);
1050
1050
  if (paint.mode === 'strench')
1051
1051
  paint.mode = 'stretch';
1052
- const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1052
+ const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
1053
1053
  const sameBox = box.width === width && box.height === height;
1054
1054
  const data = { mode };
1055
1055
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -1112,6 +1112,8 @@ function getPatternData(paint, box, image) {
1112
1112
  data.height = height;
1113
1113
  if (opacity)
1114
1114
  data.opacity = opacity;
1115
+ if (filters)
1116
+ data.filters = filters;
1115
1117
  if (repeat)
1116
1118
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1117
1119
  return data;
@@ -1214,7 +1216,7 @@ function createPattern(ui, paint, pixelRatio) {
1214
1216
  scaleX = abs$1(scaleX);
1215
1217
  scaleY = abs$1(scaleY);
1216
1218
  const { image, data } = paint;
1217
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
1219
+ let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1218
1220
  if (sx) {
1219
1221
  imageMatrix = get$1();
1220
1222
  copy$1(imageMatrix, transform);
@@ -1257,7 +1259,7 @@ function createPattern(ui, paint, pixelRatio) {
1257
1259
  }
1258
1260
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1259
1261
  }
1260
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, opacity);
1262
+ const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1261
1263
  const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1262
1264
  paint.style = pattern;
1263
1265
  paint.patternId = id;
@@ -1301,7 +1303,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1301
1303
  canvas.opacity *= data.opacity;
1302
1304
  if (data.transform)
1303
1305
  canvas.transform(data.transform);
1304
- canvas.drawImage(paint.image.view, 0, 0, data.width, data.height);
1306
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1305
1307
  canvas.restore();
1306
1308
  return true;
1307
1309
  }
@@ -1311,7 +1313,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1311
1313
  }
1312
1314
  else {
1313
1315
  if (!paint.patternTask) {
1314
- paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, undefined, undefined, function* () {
1316
+ paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1315
1317
  paint.patternTask = null;
1316
1318
  if (canvas.bounds.hit(ui.__nowWorld))
1317
1319
  createPattern(ui, paint, pixelRatio);
@@ -1901,11 +1903,11 @@ const TextMode = 2;
1901
1903
  function layoutChar(drawData, style, width, _height) {
1902
1904
  const { rows } = drawData;
1903
1905
  const { textAlign, paraIndent, letterSpacing } = style;
1904
- let charX, addWordWidth, indentWidth, mode, wordChar;
1906
+ let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
1905
1907
  rows.forEach(row => {
1906
1908
  if (row.words) {
1907
- indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
1908
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
1909
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
1910
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
1909
1911
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
1910
1912
  if (row.isOverflow && !letterSpacing)
1911
1913
  row.textMode = true;
@@ -1917,7 +1919,7 @@ function layoutChar(drawData, style, width, _height) {
1917
1919
  row.x += indentWidth;
1918
1920
  charX = row.x;
1919
1921
  row.data = [];
1920
- row.words.forEach(word => {
1922
+ row.words.forEach((word, index) => {
1921
1923
  if (mode === WordMode) {
1922
1924
  wordChar = { char: '', x: charX };
1923
1925
  charX = toWordChar(word.data, charX, wordChar);
@@ -1927,7 +1929,7 @@ function layoutChar(drawData, style, width, _height) {
1927
1929
  else {
1928
1930
  charX = toChar(word.data, charX, row.data, row.isOverflow);
1929
1931
  }
1930
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
1932
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
1931
1933
  charX += addWordWidth;
1932
1934
  row.width += addWordWidth;
1933
1935
  }
@@ -2219,7 +2221,7 @@ const ExportModule = {
2219
2221
  const { leafer } = leaf;
2220
2222
  if (leafer) {
2221
2223
  checkLazy(leaf);
2222
- leafer.waitViewCompleted(() => __awaiter(this, undefined, undefined, function* () {
2224
+ leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
2223
2225
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2224
2226
  const { worldTransform, isLeafer, isFrame } = leaf;
2225
2227
  const { slice, trim, padding, onCanvas } = options;
@@ -2321,7 +2323,7 @@ function addTask(task) {
2321
2323
  if (!tasker)
2322
2324
  tasker = new draw.TaskProcessor();
2323
2325
  return new Promise((resolve) => {
2324
- tasker.add(() => __awaiter(this, undefined, undefined, function* () { return yield task(resolve); }), { parallel: false });
2326
+ tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
2325
2327
  });
2326
2328
  }
2327
2329
  function checkLazy(leaf) {
@@ -2393,3 +2395,4 @@ Object.keys(draw).forEach(function (k) {
2393
2395
  get: function () { return draw[k]; }
2394
2396
  });
2395
2397
  });
2398
+ //# sourceMappingURL=node.cjs.map