@leafer-draw/node 1.3.2 → 1.4.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.esm.js CHANGED
@@ -19,7 +19,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
19
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
20
  PERFORMANCE OF THIS SOFTWARE.
21
21
  ***************************************************************************** */
22
- /* global Reflect, Promise, SuppressedError, Symbol */
22
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
23
23
 
24
24
 
25
25
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -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, 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)); }),
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)); }),
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 === void 0 ? void 0 : _a.length))
363
+ if (!((_a = this.__updatedList) === null || _a === undefined ? undefined : _a.length))
364
364
  return;
365
365
  const t = Run.start('PartLayout');
366
366
  const { target, __updatedList: updateList } = this;
@@ -1312,7 +1312,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1312
1312
  }
1313
1313
  else {
1314
1314
  if (!paint.patternTask) {
1315
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1315
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, undefined, undefined, function* () {
1316
1316
  paint.patternTask = null;
1317
1317
  if (canvas.bounds.hit(ui.__nowWorld))
1318
1318
  createPattern(ui, paint, pixelRatio);
@@ -1468,7 +1468,7 @@ function shadow(ui, current, shape) {
1468
1468
  const end = shadow.length - 1;
1469
1469
  toOffsetOutBounds$1(bounds, offsetOutBounds$1);
1470
1470
  shadow.forEach((item, index) => {
1471
- other.setWorldShadow((offsetOutBounds$1.offsetX + item.x * scaleX), (offsetOutBounds$1.offsetY + item.y * scaleY), item.blur * scaleX, item.color);
1471
+ other.setWorldShadow((offsetOutBounds$1.offsetX + item.x * scaleX), (offsetOutBounds$1.offsetY + item.y * scaleY), item.blur * scaleX, ColorConvert.string(item.color));
1472
1472
  spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1473
1473
  drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
1474
1474
  copyBounds = bounds;
@@ -1544,7 +1544,7 @@ function innerShadow(ui, current, shape) {
1544
1544
  other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
1545
1545
  copyBounds = bounds;
1546
1546
  }
1547
- other.fillWorld(copyBounds, item.color, 'source-in');
1547
+ other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
1548
1548
  if (ui.__worldFlipped) {
1549
1549
  current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1550
1550
  }
@@ -1902,11 +1902,11 @@ const TextMode = 2;
1902
1902
  function layoutChar(drawData, style, width, _height) {
1903
1903
  const { rows } = drawData;
1904
1904
  const { textAlign, paraIndent, letterSpacing } = style;
1905
- let charX, addWordWidth, indentWidth, mode, wordChar;
1905
+ let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
1906
1906
  rows.forEach(row => {
1907
1907
  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;
1908
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
1909
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
1910
1910
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
1911
1911
  if (row.isOverflow && !letterSpacing)
1912
1912
  row.textMode = true;
@@ -1918,7 +1918,7 @@ function layoutChar(drawData, style, width, _height) {
1918
1918
  row.x += indentWidth;
1919
1919
  charX = row.x;
1920
1920
  row.data = [];
1921
- row.words.forEach(word => {
1921
+ row.words.forEach((word, index) => {
1922
1922
  if (mode === WordMode) {
1923
1923
  wordChar = { char: '', x: charX };
1924
1924
  charX = toWordChar(word.data, charX, wordChar);
@@ -1928,7 +1928,7 @@ function layoutChar(drawData, style, width, _height) {
1928
1928
  else {
1929
1929
  charX = toChar(word.data, charX, row.data, row.isOverflow);
1930
1930
  }
1931
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
1931
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
1932
1932
  charX += addWordWidth;
1933
1933
  row.width += addWordWidth;
1934
1934
  }
@@ -2220,10 +2220,10 @@ const ExportModule = {
2220
2220
  const { leafer } = leaf;
2221
2221
  if (leafer) {
2222
2222
  checkLazy(leaf);
2223
- leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
2223
+ leafer.waitViewCompleted(() => __awaiter(this, undefined, undefined, function* () {
2224
2224
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2225
2225
  const { worldTransform, isLeafer, isFrame } = leaf;
2226
- const { slice, trim, onCanvas } = options;
2226
+ const { slice, trim, padding, onCanvas } = options;
2227
2227
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
2228
2228
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
2229
2229
  const screenshot = options.screenshot || leaf.isApp;
@@ -2297,6 +2297,12 @@ const ExportModule = {
2297
2297
  canvas = Creator$1.canvas(config);
2298
2298
  canvas.copyWorld(old, trimBounds, config);
2299
2299
  }
2300
+ if (padding) {
2301
+ const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
2302
+ const old = canvas, { width, height } = old;
2303
+ canvas = Creator$1.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
2304
+ canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
2305
+ }
2300
2306
  if (needFill)
2301
2307
  canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
2302
2308
  if (onCanvas)
@@ -2316,7 +2322,7 @@ function addTask(task) {
2316
2322
  if (!tasker)
2317
2323
  tasker = new TaskProcessor();
2318
2324
  return new Promise((resolve) => {
2319
- tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
2325
+ tasker.add(() => __awaiter(this, undefined, undefined, function* () { return yield task(resolve); }), { parallel: false });
2320
2326
  });
2321
2327
  }
2322
2328
  function checkLazy(leaf) {
@@ -2368,3 +2374,4 @@ UI.prototype.export = function (filename, options) {
2368
2374
  };
2369
2375
 
2370
2376
  export { Layouter, LeaferCanvas, Renderer, Watcher, useCanvas };
2377
+ //# sourceMappingURL=node.esm.js.map