leafer-ui 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, Plugin, MathHelper, MatrixHelper, 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, Plugin, MathHelper, MatrixHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4 } from '@leafer/core';
2
2
  export * from '@leafer/core';
3
3
  export { LeaferImage } from '@leafer/core';
4
4
  import { InteractionHelper, InteractionBase, Cursor, HitCanvasManager } from '@leafer-ui/core';
@@ -123,7 +123,7 @@ class LeaferCanvas extends LeaferCanvasBase {
123
123
  }
124
124
  }
125
125
  else {
126
- window.addEventListener('resize', () => {
126
+ window.addEventListener('resize', this.windowListener = () => {
127
127
  const pixelRatio = Platform.devicePixelRatio;
128
128
  if (this.pixelRatio !== pixelRatio) {
129
129
  const { width, height } = this;
@@ -152,11 +152,9 @@ class LeaferCanvas extends LeaferCanvasBase {
152
152
  }
153
153
  stopAutoLayout() {
154
154
  this.autoLayout = false;
155
- this.resizeListener = null;
156
- if (this.resizeObserver) {
155
+ if (this.resizeObserver)
157
156
  this.resizeObserver.disconnect();
158
- this.resizeObserver = null;
159
- }
157
+ this.resizeListener = this.resizeObserver = null;
160
158
  }
161
159
  emitResize(size) {
162
160
  const oldSize = {};
@@ -177,6 +175,10 @@ class LeaferCanvas extends LeaferCanvasBase {
177
175
  destroy() {
178
176
  if (this.view) {
179
177
  this.stopAutoLayout();
178
+ if (this.windowListener) {
179
+ window.removeEventListener('resize', this.windowListener);
180
+ this.windowListener = null;
181
+ }
180
182
  if (!this.unreal) {
181
183
  const view = this.view;
182
184
  if (view.parentElement)
@@ -203,7 +205,10 @@ function useCanvas(_canvasType, _power) {
203
205
  canvas.height = height;
204
206
  return canvas;
205
207
  },
206
- canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
208
+ canvasToDataURL: (canvas, type, quality) => {
209
+ const imageType = mineType(type), url = canvas.toDataURL(imageType, quality);
210
+ return imageType === 'image/bmp' ? url.replace('image/png;', 'image/bmp;') : url;
211
+ },
207
212
  canvasToBolb: (canvas, type, quality) => new Promise((resolve) => canvas.toBlob(resolve, mineType(type), quality)),
208
213
  canvasSaveAs: (canvas, filename, quality) => {
209
214
  const url = canvas.toDataURL(mineType(fileType(filename)), quality);
@@ -248,14 +253,14 @@ function useCanvas(_canvasType, _power) {
248
253
  Platform.name = 'web';
249
254
  Platform.isMobile = 'ontouchstart' in window;
250
255
  Platform.requestRender = function (render) { window.requestAnimationFrame(render); };
251
- defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, devicePixelRatio); } });
256
+ defineKey(Platform, 'devicePixelRatio', { get() { return devicePixelRatio; } });
252
257
  const { userAgent } = navigator;
253
258
  if (userAgent.indexOf("Firefox") > -1) {
254
259
  Platform.conicGradientRotate90 = true;
255
260
  Platform.intWheelDeltaY = true;
256
261
  Platform.syncDomFont = true;
257
262
  }
258
- else if (userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1) {
263
+ else if (userAgent.indexOf("AppleWebKit") > -1) {
259
264
  Platform.fullImageShadow = true;
260
265
  }
261
266
  if (userAgent.indexOf('Windows') > -1) {
@@ -524,7 +529,7 @@ class Layouter {
524
529
  }
525
530
  partLayout() {
526
531
  var _a;
527
- if (!((_a = this.__updatedList) === null || _a === undefined ? undefined : _a.length))
532
+ if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
528
533
  return;
529
534
  const t = Run.start('PartLayout');
530
535
  const { target, __updatedList: updateList } = this;
@@ -989,9 +994,10 @@ class Selector {
989
994
  this.finder = Creator.finder && Creator.finder();
990
995
  }
991
996
  getByPoint(hitPoint, hitRadius, options) {
992
- if (Platform.backgrounder && this.target)
993
- this.target.updateLayout();
994
- return this.picker.getByPoint(hitPoint, hitRadius, options);
997
+ const { target, picker } = this;
998
+ if (Platform.backgrounder)
999
+ target && target.updateLayout();
1000
+ return picker.getByPoint(hitPoint, hitRadius, options);
995
1001
  }
996
1002
  getBy(condition, branch, one, options) {
997
1003
  return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
@@ -1054,6 +1060,7 @@ class Interaction extends InteractionBase {
1054
1060
  'pointerdown': this.onPointerDown,
1055
1061
  'mousedown': this.onMouseDown,
1056
1062
  'touchstart': this.onTouchStart,
1063
+ 'pointerleave': this.onPointerLeave,
1057
1064
  'contextmenu': this.onContextMenu,
1058
1065
  'wheel': this.onWheel,
1059
1066
  'gesturestart': this.onGesturestart,
@@ -1136,11 +1143,15 @@ class Interaction extends InteractionBase {
1136
1143
  this.usePointer || (this.usePointer = true);
1137
1144
  this.pointerDown(PointerEventHelper.convert(e, this.getLocal(e)));
1138
1145
  }
1139
- onPointerMove(e) {
1146
+ onPointerMove(e, isLeave) {
1140
1147
  if (this.config.pointer.touch || this.useMultiTouch || this.preventWindowPointer(e))
1141
1148
  return;
1142
1149
  this.usePointer || (this.usePointer = true);
1143
- this.pointerMove(PointerEventHelper.convert(e, this.getLocal(e, true)));
1150
+ const data = PointerEventHelper.convert(e, this.getLocal(e, true));
1151
+ isLeave ? this.pointerHover(data) : this.pointerMove(data);
1152
+ }
1153
+ onPointerLeave(e) {
1154
+ this.onPointerMove(e, true);
1144
1155
  }
1145
1156
  onPointerUp(e) {
1146
1157
  if (this.downData)
@@ -1674,7 +1685,7 @@ function getPatternData(paint, box, image) {
1674
1685
  box = tempBox.set(box).shrink(paint.padding);
1675
1686
  if (paint.mode === 'strench')
1676
1687
  paint.mode = 'stretch';
1677
- const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1688
+ const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
1678
1689
  const sameBox = box.width === width && box.height === height;
1679
1690
  const data = { mode };
1680
1691
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -1737,6 +1748,8 @@ function getPatternData(paint, box, image) {
1737
1748
  data.height = height;
1738
1749
  if (opacity)
1739
1750
  data.opacity = opacity;
1751
+ if (filters)
1752
+ data.filters = filters;
1740
1753
  if (repeat)
1741
1754
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1742
1755
  return data;
@@ -1839,7 +1852,7 @@ function createPattern(ui, paint, pixelRatio) {
1839
1852
  scaleX = abs$1(scaleX);
1840
1853
  scaleY = abs$1(scaleY);
1841
1854
  const { image, data } = paint;
1842
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
1855
+ let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1843
1856
  if (sx) {
1844
1857
  imageMatrix = get$1();
1845
1858
  copy$1(imageMatrix, transform);
@@ -1882,7 +1895,7 @@ function createPattern(ui, paint, pixelRatio) {
1882
1895
  }
1883
1896
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1884
1897
  }
1885
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, opacity);
1898
+ const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1886
1899
  const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1887
1900
  paint.style = pattern;
1888
1901
  paint.patternId = id;
@@ -1958,7 +1971,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1958
1971
  canvas.opacity *= data.opacity;
1959
1972
  if (data.transform)
1960
1973
  canvas.transform(data.transform);
1961
- canvas.drawImage(paint.image.view, 0, 0, data.width, data.height);
1974
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1962
1975
  canvas.restore();
1963
1976
  return true;
1964
1977
  }
@@ -1968,7 +1981,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1968
1981
  }
1969
1982
  else {
1970
1983
  if (!paint.patternTask) {
1971
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, undefined, undefined, function* () {
1984
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1972
1985
  paint.patternTask = null;
1973
1986
  if (canvas.bounds.hit(ui.__nowWorld))
1974
1987
  createPattern(ui, paint, pixelRatio);
@@ -2558,11 +2571,11 @@ const TextMode = 2;
2558
2571
  function layoutChar(drawData, style, width, _height) {
2559
2572
  const { rows } = drawData;
2560
2573
  const { textAlign, paraIndent, letterSpacing } = style;
2561
- let charX, addWordWidth, indentWidth, mode, wordChar;
2574
+ let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2562
2575
  rows.forEach(row => {
2563
2576
  if (row.words) {
2564
- indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
2565
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
2577
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2578
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2566
2579
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2567
2580
  if (row.isOverflow && !letterSpacing)
2568
2581
  row.textMode = true;
@@ -2574,7 +2587,7 @@ function layoutChar(drawData, style, width, _height) {
2574
2587
  row.x += indentWidth;
2575
2588
  charX = row.x;
2576
2589
  row.data = [];
2577
- row.words.forEach(word => {
2590
+ row.words.forEach((word, index) => {
2578
2591
  if (mode === WordMode) {
2579
2592
  wordChar = { char: '', x: charX };
2580
2593
  charX = toWordChar(word.data, charX, wordChar);
@@ -2584,7 +2597,7 @@ function layoutChar(drawData, style, width, _height) {
2584
2597
  else {
2585
2598
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2586
2599
  }
2587
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
2600
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2588
2601
  charX += addWordWidth;
2589
2602
  row.width += addWordWidth;
2590
2603
  }
@@ -2841,3 +2854,4 @@ Object.assign(Creator, {
2841
2854
  useCanvas();
2842
2855
 
2843
2856
  export { Interaction, Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };
2857
+ //# sourceMappingURL=web.esm.js.map