leafer-draw 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/web.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Debug, LeaferCanvasBase, Platform, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, LeafLevelList, LayoutEvent, Run, ImageManager, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4 } from '@leafer/core';
1
+ import { Debug, LeaferCanvasBase, Platform, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, LeafLevelList, LayoutEvent, Run, ImageManager, 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 { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect } from '@leafer-ui/draw';
@@ -122,7 +122,7 @@ class LeaferCanvas extends LeaferCanvasBase {
122
122
  }
123
123
  }
124
124
  else {
125
- window.addEventListener('resize', () => {
125
+ window.addEventListener('resize', this.windowListener = () => {
126
126
  const pixelRatio = Platform.devicePixelRatio;
127
127
  if (this.pixelRatio !== pixelRatio) {
128
128
  const { width, height } = this;
@@ -151,11 +151,9 @@ class LeaferCanvas extends LeaferCanvasBase {
151
151
  }
152
152
  stopAutoLayout() {
153
153
  this.autoLayout = false;
154
- this.resizeListener = null;
155
- if (this.resizeObserver) {
154
+ if (this.resizeObserver)
156
155
  this.resizeObserver.disconnect();
157
- this.resizeObserver = null;
158
- }
156
+ this.resizeListener = this.resizeObserver = null;
159
157
  }
160
158
  emitResize(size) {
161
159
  const oldSize = {};
@@ -176,6 +174,10 @@ class LeaferCanvas extends LeaferCanvasBase {
176
174
  destroy() {
177
175
  if (this.view) {
178
176
  this.stopAutoLayout();
177
+ if (this.windowListener) {
178
+ window.removeEventListener('resize', this.windowListener);
179
+ this.windowListener = null;
180
+ }
179
181
  if (!this.unreal) {
180
182
  const view = this.view;
181
183
  if (view.parentElement)
@@ -202,7 +204,10 @@ function useCanvas(_canvasType, _power) {
202
204
  canvas.height = height;
203
205
  return canvas;
204
206
  },
205
- canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
207
+ canvasToDataURL: (canvas, type, quality) => {
208
+ const imageType = mineType(type), url = canvas.toDataURL(imageType, quality);
209
+ return imageType === 'image/bmp' ? url.replace('image/png;', 'image/bmp;') : url;
210
+ },
206
211
  canvasToBolb: (canvas, type, quality) => new Promise((resolve) => canvas.toBlob(resolve, mineType(type), quality)),
207
212
  canvasSaveAs: (canvas, filename, quality) => {
208
213
  const url = canvas.toDataURL(mineType(fileType(filename)), quality);
@@ -247,14 +252,14 @@ function useCanvas(_canvasType, _power) {
247
252
  Platform.name = 'web';
248
253
  Platform.isMobile = 'ontouchstart' in window;
249
254
  Platform.requestRender = function (render) { window.requestAnimationFrame(render); };
250
- defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, devicePixelRatio); } });
255
+ defineKey(Platform, 'devicePixelRatio', { get() { return devicePixelRatio; } });
251
256
  const { userAgent } = navigator;
252
257
  if (userAgent.indexOf("Firefox") > -1) {
253
258
  Platform.conicGradientRotate90 = true;
254
259
  Platform.intWheelDeltaY = true;
255
260
  Platform.syncDomFont = true;
256
261
  }
257
- else if (userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1) {
262
+ else if (userAgent.indexOf("AppleWebKit") > -1) {
258
263
  Platform.fullImageShadow = true;
259
264
  }
260
265
  if (userAgent.indexOf('Windows') > -1) {
@@ -523,7 +528,7 @@ class Layouter {
523
528
  }
524
529
  partLayout() {
525
530
  var _a;
526
- if (!((_a = this.__updatedList) === null || _a === undefined ? undefined : _a.length))
531
+ if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
527
532
  return;
528
533
  const t = Run.start('PartLayout');
529
534
  const { target, __updatedList: updateList } = this;
@@ -1213,7 +1218,7 @@ function getPatternData(paint, box, image) {
1213
1218
  box = tempBox.set(box).shrink(paint.padding);
1214
1219
  if (paint.mode === 'strench')
1215
1220
  paint.mode = 'stretch';
1216
- const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1221
+ const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
1217
1222
  const sameBox = box.width === width && box.height === height;
1218
1223
  const data = { mode };
1219
1224
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -1276,6 +1281,8 @@ function getPatternData(paint, box, image) {
1276
1281
  data.height = height;
1277
1282
  if (opacity)
1278
1283
  data.opacity = opacity;
1284
+ if (filters)
1285
+ data.filters = filters;
1279
1286
  if (repeat)
1280
1287
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1281
1288
  return data;
@@ -1378,7 +1385,7 @@ function createPattern(ui, paint, pixelRatio) {
1378
1385
  scaleX = abs$1(scaleX);
1379
1386
  scaleY = abs$1(scaleY);
1380
1387
  const { image, data } = paint;
1381
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
1388
+ let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1382
1389
  if (sx) {
1383
1390
  imageMatrix = get$1();
1384
1391
  copy$1(imageMatrix, transform);
@@ -1421,7 +1428,7 @@ function createPattern(ui, paint, pixelRatio) {
1421
1428
  }
1422
1429
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1423
1430
  }
1424
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, opacity);
1431
+ const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1425
1432
  const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1426
1433
  paint.style = pattern;
1427
1434
  paint.patternId = id;
@@ -1497,7 +1504,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1497
1504
  canvas.opacity *= data.opacity;
1498
1505
  if (data.transform)
1499
1506
  canvas.transform(data.transform);
1500
- canvas.drawImage(paint.image.view, 0, 0, data.width, data.height);
1507
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1501
1508
  canvas.restore();
1502
1509
  return true;
1503
1510
  }
@@ -1507,7 +1514,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1507
1514
  }
1508
1515
  else {
1509
1516
  if (!paint.patternTask) {
1510
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, undefined, undefined, function* () {
1517
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1511
1518
  paint.patternTask = null;
1512
1519
  if (canvas.bounds.hit(ui.__nowWorld))
1513
1520
  createPattern(ui, paint, pixelRatio);
@@ -2097,11 +2104,11 @@ const TextMode = 2;
2097
2104
  function layoutChar(drawData, style, width, _height) {
2098
2105
  const { rows } = drawData;
2099
2106
  const { textAlign, paraIndent, letterSpacing } = style;
2100
- let charX, addWordWidth, indentWidth, mode, wordChar;
2107
+ let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2101
2108
  rows.forEach(row => {
2102
2109
  if (row.words) {
2103
- indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
2104
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
2110
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2111
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2105
2112
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2106
2113
  if (row.isOverflow && !letterSpacing)
2107
2114
  row.textMode = true;
@@ -2113,7 +2120,7 @@ function layoutChar(drawData, style, width, _height) {
2113
2120
  row.x += indentWidth;
2114
2121
  charX = row.x;
2115
2122
  row.data = [];
2116
- row.words.forEach(word => {
2123
+ row.words.forEach((word, index) => {
2117
2124
  if (mode === WordMode) {
2118
2125
  wordChar = { char: '', x: charX };
2119
2126
  charX = toWordChar(word.data, charX, wordChar);
@@ -2123,7 +2130,7 @@ function layoutChar(drawData, style, width, _height) {
2123
2130
  else {
2124
2131
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2125
2132
  }
2126
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
2133
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2127
2134
  charX += addWordWidth;
2128
2135
  row.width += addWordWidth;
2129
2136
  }
@@ -2375,3 +2382,4 @@ Object.assign(Effect, EffectModule);
2375
2382
  useCanvas();
2376
2383
 
2377
2384
  export { Layouter, LeaferCanvas, Renderer, Watcher, useCanvas };
2385
+ //# sourceMappingURL=web.esm.js.map