leafer-ui 1.3.3 → 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/web.esm.js CHANGED
@@ -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,7 +253,7 @@ 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;
@@ -1054,6 +1059,7 @@ class Interaction extends InteractionBase {
1054
1059
  'pointerdown': this.onPointerDown,
1055
1060
  'mousedown': this.onMouseDown,
1056
1061
  'touchstart': this.onTouchStart,
1062
+ 'pointerleave': this.onPointerLeave,
1057
1063
  'contextmenu': this.onContextMenu,
1058
1064
  'wheel': this.onWheel,
1059
1065
  'gesturestart': this.onGesturestart,
@@ -1136,11 +1142,15 @@ class Interaction extends InteractionBase {
1136
1142
  this.usePointer || (this.usePointer = true);
1137
1143
  this.pointerDown(PointerEventHelper.convert(e, this.getLocal(e)));
1138
1144
  }
1139
- onPointerMove(e) {
1145
+ onPointerMove(e, isLeave) {
1140
1146
  if (this.config.pointer.touch || this.useMultiTouch || this.preventWindowPointer(e))
1141
1147
  return;
1142
1148
  this.usePointer || (this.usePointer = true);
1143
- this.pointerMove(PointerEventHelper.convert(e, this.getLocal(e, true)));
1149
+ const data = PointerEventHelper.convert(e, this.getLocal(e, true));
1150
+ isLeave ? this.pointerHover(data) : this.pointerMove(data);
1151
+ }
1152
+ onPointerLeave(e) {
1153
+ this.onPointerMove(e, true);
1144
1154
  }
1145
1155
  onPointerUp(e) {
1146
1156
  if (this.downData)
@@ -2558,11 +2568,11 @@ const TextMode = 2;
2558
2568
  function layoutChar(drawData, style, width, _height) {
2559
2569
  const { rows } = drawData;
2560
2570
  const { textAlign, paraIndent, letterSpacing } = style;
2561
- let charX, addWordWidth, indentWidth, mode, wordChar;
2571
+ let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2562
2572
  rows.forEach(row => {
2563
2573
  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;
2574
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2575
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2566
2576
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2567
2577
  if (row.isOverflow && !letterSpacing)
2568
2578
  row.textMode = true;
@@ -2574,7 +2584,7 @@ function layoutChar(drawData, style, width, _height) {
2574
2584
  row.x += indentWidth;
2575
2585
  charX = row.x;
2576
2586
  row.data = [];
2577
- row.words.forEach(word => {
2587
+ row.words.forEach((word, index) => {
2578
2588
  if (mode === WordMode) {
2579
2589
  wordChar = { char: '', x: charX };
2580
2590
  charX = toWordChar(word.data, charX, wordChar);
@@ -2584,7 +2594,7 @@ function layoutChar(drawData, style, width, _height) {
2584
2594
  else {
2585
2595
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2586
2596
  }
2587
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
2597
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2588
2598
  charX += addWordWidth;
2589
2599
  row.width += addWordWidth;
2590
2600
  }
@@ -2841,3 +2851,4 @@ Object.assign(Creator, {
2841
2851
  useCanvas();
2842
2852
 
2843
2853
  export { Interaction, Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };
2854
+ //# sourceMappingURL=web.esm.js.map