@leafer-ui/miniapp 1.0.0-rc.2 → 1.0.0-rc.4

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.
@@ -647,7 +647,7 @@ const BoundsHelper = {
647
647
  },
648
648
  getFitMatrix(t, put) {
649
649
  const scale = Math.min(1, Math.min(t.width / put.width, t.height / put.height));
650
- return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
650
+ return new Matrix(scale, 0, 0, scale, -Math.ceil(put.x * scale), -Math.ceil(put.y * scale));
651
651
  },
652
652
  getSpread(t, spreadX, spreadY) {
653
653
  const n = {};
@@ -1048,6 +1048,9 @@ const EventCreator = {
1048
1048
  }
1049
1049
  }
1050
1050
  },
1051
+ has(type) {
1052
+ return !!this.nameList[type];
1053
+ },
1051
1054
  get(type, ...params) {
1052
1055
  return new nameList[type](...params);
1053
1056
  }
@@ -4588,7 +4591,8 @@ class InteractionBase {
4588
4591
  dragDistance: 2,
4589
4592
  swipeDistance: 20,
4590
4593
  ignoreMove: false
4591
- }
4594
+ },
4595
+ cursor: {}
4592
4596
  };
4593
4597
  this.tapCount = 0;
4594
4598
  this.downKeyMap = {};
@@ -4814,6 +4818,8 @@ class InteractionBase {
4814
4818
  this.hoverData = data;
4815
4819
  }
4816
4820
  updateCursor(data) {
4821
+ if (this.config.cursor.stop)
4822
+ return;
4817
4823
  if (!data) {
4818
4824
  this.updateHoverData();
4819
4825
  data = this.hoverData;
@@ -4826,17 +4832,16 @@ class InteractionBase {
4826
4832
  }
4827
4833
  else if (!data || this.dragger.dragging)
4828
4834
  return;
4829
- const path = data.path;
4830
4835
  let leaf;
4836
+ let cursor;
4837
+ const { path } = data;
4831
4838
  for (let i = 0, len = path.length; i < len; i++) {
4832
4839
  leaf = path.list[i];
4833
- if (leaf.cursor) {
4834
- const { cursor } = leaf;
4835
- this.setCursor(cursor === 'grab' ? (this.downData ? 'grabbing' : cursor) : cursor);
4836
- return;
4837
- }
4840
+ cursor = leaf.cursor;
4841
+ if (cursor)
4842
+ break;
4838
4843
  }
4839
- this.setCursor('default');
4844
+ this.setCursor(cursor);
4840
4845
  }
4841
4846
  setCursor(cursor) {
4842
4847
  this.cursor = cursor;
@@ -5158,6 +5163,8 @@ const LeafEventer = {
5158
5163
  this.on(type, listener, { once: true, capture });
5159
5164
  },
5160
5165
  emit(type, event, capture) {
5166
+ if (!event && EventCreator.has(type))
5167
+ event = EventCreator.get(type, { type, target: this, current: this });
5161
5168
  const map = __getListenerMap(this, capture);
5162
5169
  const list = map[type];
5163
5170
  if (list) {
@@ -5452,7 +5459,7 @@ const LeafRender = {
5452
5459
  const tempCanvas = canvas.getSameCanvas(true);
5453
5460
  this.__draw(tempCanvas, options);
5454
5461
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode;
5455
- if (options.matrix || this.__hasMirror) {
5462
+ if (this.__hasMirror || options.matrix) {
5456
5463
  canvas.copyWorldByReset(tempCanvas, null, null, blendMode);
5457
5464
  }
5458
5465
  else {
@@ -5521,7 +5528,12 @@ const BranchRender = {
5521
5528
  this.__renderBranch(tempCanvas, options);
5522
5529
  canvas.opacity = this.__worldOpacity;
5523
5530
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode;
5524
- options.matrix ? canvas.copyWorld(tempCanvas, null, null, blendMode) : canvas.copyWorld(tempCanvas, this.__world, this.__world, blendMode);
5531
+ if (this.__hasMirror || options.matrix) {
5532
+ canvas.copyWorld(tempCanvas, null, null, blendMode);
5533
+ }
5534
+ else {
5535
+ canvas.copyWorld(tempCanvas, this.__world, this.__world, blendMode);
5536
+ }
5525
5537
  tempCanvas.recycle();
5526
5538
  }
5527
5539
  else {
@@ -7181,7 +7193,7 @@ class UIData extends LeafData {
7181
7193
  if (typeof value === 'string' || !value) {
7182
7194
  if (this.__isFills) {
7183
7195
  this.__removeInput('fill');
7184
- Paint.recycleImage(this, 'fill');
7196
+ Paint.recycleImage('fill', this);
7185
7197
  this.__isFills = false;
7186
7198
  }
7187
7199
  this._fill = value;
@@ -7197,7 +7209,7 @@ class UIData extends LeafData {
7197
7209
  if (typeof value === 'string' || !value) {
7198
7210
  if (this.__isStrokes) {
7199
7211
  this.__removeInput('stroke');
7200
- Paint.recycleImage(this, 'stroke');
7212
+ Paint.recycleImage('stroke', this);
7201
7213
  this.__isStrokes = false;
7202
7214
  }
7203
7215
  this._stroke = value;
@@ -7449,11 +7461,11 @@ const UIRender = {
7449
7461
  const { fill, stroke, __drawAfterFill } = this.__;
7450
7462
  this.__drawRenderPath(canvas);
7451
7463
  if (fill)
7452
- Paint.fill(this, canvas, fill);
7464
+ Paint.fill(fill, this, canvas);
7453
7465
  if (__drawAfterFill)
7454
7466
  this.__drawAfterFill(canvas, options);
7455
7467
  if (stroke)
7456
- Paint.stroke(this, canvas, stroke);
7468
+ Paint.stroke(stroke, this, canvas, options);
7457
7469
  },
7458
7470
  __draw(canvas, options) {
7459
7471
  if (this.__.__complex) {
@@ -7465,40 +7477,40 @@ const UIRender = {
7465
7477
  if (shadow)
7466
7478
  Effect.shadow(this, canvas, shape, options);
7467
7479
  if (fill)
7468
- this.__.__isFills ? Paint.fills(this, canvas, fill) : Paint.fill(this, canvas, fill);
7480
+ this.__.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
7469
7481
  if (__drawAfterFill)
7470
7482
  this.__drawAfterFill(canvas, options);
7471
7483
  if (innerShadow)
7472
7484
  Effect.innerShadow(this, canvas, shape, options);
7473
7485
  if (stroke)
7474
- this.__.__isStrokes ? Paint.strokes(this, canvas, stroke) : Paint.stroke(this, canvas, stroke);
7486
+ this.__.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7475
7487
  if (shape.worldCanvas)
7476
7488
  shape.worldCanvas.recycle();
7477
7489
  shape.canvas.recycle();
7478
7490
  }
7479
7491
  else {
7480
7492
  if (fill)
7481
- this.__.__isFills ? Paint.fills(this, canvas, fill) : Paint.fill(this, canvas, fill);
7493
+ this.__.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
7482
7494
  if (__drawAfterFill)
7483
7495
  this.__drawAfterFill(canvas, options);
7484
7496
  if (stroke)
7485
- this.__.__isStrokes ? Paint.strokes(this, canvas, stroke) : Paint.stroke(this, canvas, stroke);
7497
+ this.__.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7486
7498
  }
7487
7499
  }
7488
7500
  else {
7489
7501
  this.__drawFast(canvas, options);
7490
7502
  }
7491
7503
  },
7492
- __renderShape(canvas, options) {
7504
+ __renderShape(canvas, renderOptions) {
7493
7505
  if (!this.__worldOpacity)
7494
7506
  return;
7495
- canvas.setWorld(this.__world, options.matrix);
7507
+ canvas.setWorld(this.__world, renderOptions.matrix);
7496
7508
  const { fill, stroke } = this.__;
7497
7509
  this.__drawRenderPath(canvas);
7498
7510
  if (fill)
7499
- Paint.fill(this, canvas, '#000000');
7511
+ Paint.fill('#000000', this, canvas);
7500
7512
  if (stroke)
7501
- Paint.stroke(this, canvas, '#000000');
7513
+ Paint.stroke('#000000', this, canvas, renderOptions);
7502
7514
  }
7503
7515
  };
7504
7516
 
@@ -7567,9 +7579,9 @@ let UI = UI_1 = class UI extends Leaf {
7567
7579
  if (this.__.__input) {
7568
7580
  const { fill, stroke } = this.__.__input;
7569
7581
  if (fill)
7570
- Paint.compute(this, 'fill');
7582
+ Paint.compute('fill', this);
7571
7583
  if (stroke)
7572
- Paint.compute(this, 'stroke');
7584
+ Paint.compute('stroke', this);
7573
7585
  }
7574
7586
  }
7575
7587
  __updateRenderPath() {
@@ -7686,7 +7698,7 @@ __decorate([
7686
7698
  hitType()
7687
7699
  ], UI.prototype, "hitRadius", void 0);
7688
7700
  __decorate([
7689
- cursorType('default')
7701
+ cursorType('')
7690
7702
  ], UI.prototype, "cursor", void 0);
7691
7703
  __decorate([
7692
7704
  surfaceType()
@@ -8033,14 +8045,19 @@ let Polygon = class Polygon extends UI {
8033
8045
  __updateRenderPath() {
8034
8046
  if (this.__.points && this.__.curve) {
8035
8047
  drawPoints$1(this.__.__pathForRender = [], this.__.points, this.__.curve, true);
8036
- this.__updateNaturalSize();
8037
8048
  }
8038
8049
  else {
8039
8050
  super.__updateRenderPath();
8040
8051
  }
8041
8052
  }
8042
8053
  __updateBoxBounds() {
8043
- this.__.points ? toBounds$2(this.__.path, this.__layout.boxBounds) : super.__updateBoxBounds();
8054
+ if (this.__.points) {
8055
+ toBounds$2(this.__.__pathForRender, this.__layout.boxBounds);
8056
+ this.__updateNaturalSize();
8057
+ }
8058
+ else {
8059
+ super.__updateBoxBounds();
8060
+ }
8044
8061
  }
8045
8062
  };
8046
8063
  __decorate([
@@ -8134,7 +8151,7 @@ let Line = class Line extends UI {
8134
8151
  }
8135
8152
  __updateBoxBounds() {
8136
8153
  if (this.points) {
8137
- toBounds$1(this.__.path, this.__layout.boxBounds);
8154
+ toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8138
8155
  this.__updateNaturalSize();
8139
8156
  }
8140
8157
  else {
@@ -9144,7 +9161,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9144
9161
  }
9145
9162
  }
9146
9163
 
9147
- function recycleImage(data, attrName) {
9164
+ function recycleImage(attrName, data) {
9148
9165
  const paints = (attrName === 'fill' ? data._fill : data._stroke);
9149
9166
  if (paints instanceof Array) {
9150
9167
  let image, recycleMap, input, url;
@@ -9189,11 +9206,11 @@ function fillText(ui, canvas) {
9189
9206
  }
9190
9207
  }
9191
9208
 
9192
- function fill(ui, canvas, fill) {
9209
+ function fill(fill, ui, canvas) {
9193
9210
  canvas.fillStyle = fill;
9194
9211
  ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
9195
9212
  }
9196
- function fills(ui, canvas, fills) {
9213
+ function fills(fills, ui, canvas) {
9197
9214
  let item;
9198
9215
  const { windingRule, __font } = ui.__;
9199
9216
  for (let i = 0, len = fills.length; i < len; i++) {
@@ -9224,32 +9241,37 @@ function fills(ui, canvas, fills) {
9224
9241
  }
9225
9242
  }
9226
9243
 
9227
- function strokeText(ui, canvas, stroke) {
9244
+ function strokeText(stroke, ui, canvas, renderOptions) {
9228
9245
  const { strokeAlign } = ui.__;
9229
9246
  const isStrokes = typeof stroke !== 'string';
9230
9247
  switch (strokeAlign) {
9231
9248
  case 'center':
9232
9249
  canvas.setStroke(isStrokes ? undefined : stroke, ui.__.strokeWidth, ui.__);
9233
- isStrokes ? drawStrokesStyle(ui, stroke, canvas, true) : drawTextStroke(ui, canvas);
9250
+ isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
9234
9251
  break;
9235
9252
  case 'inside':
9236
- drawAlignStroke(ui, canvas, stroke, 'inside', isStrokes);
9253
+ drawAlignStroke('inside', stroke, isStrokes, ui, canvas, renderOptions);
9237
9254
  break;
9238
9255
  case 'outside':
9239
- drawAlignStroke(ui, canvas, stroke, 'outside', isStrokes);
9256
+ drawAlignStroke('outside', stroke, isStrokes, ui, canvas, renderOptions);
9240
9257
  break;
9241
9258
  }
9242
9259
  }
9243
- function drawAlignStroke(ui, canvas, stroke, align, isStrokes) {
9260
+ function drawAlignStroke(align, stroke, isStrokes, ui, canvas, renderOptions) {
9244
9261
  const { strokeWidth, __font } = ui.__;
9245
9262
  const out = canvas.getSameCanvas(true);
9246
9263
  out.setStroke(isStrokes ? undefined : stroke, strokeWidth * 2, ui.__);
9247
9264
  out.font = __font;
9248
- isStrokes ? drawStrokesStyle(ui, stroke, out, true) : drawTextStroke(ui, out);
9265
+ isStrokes ? drawStrokesStyle(stroke, true, ui, out) : drawTextStroke(ui, out);
9249
9266
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
9250
9267
  fillText(ui, out);
9251
9268
  out.blendMode = 'normal';
9252
- canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9269
+ if (ui.__hasMirror || renderOptions.matrix) {
9270
+ canvas.copyWorldByReset(out);
9271
+ }
9272
+ else {
9273
+ canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9274
+ }
9253
9275
  out.recycle();
9254
9276
  }
9255
9277
  function drawTextStroke(ui, canvas) {
@@ -9269,7 +9291,7 @@ function drawTextStroke(ui, canvas) {
9269
9291
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
9270
9292
  }
9271
9293
  }
9272
- function drawStrokesStyle(ui, strokes, canvas, isText) {
9294
+ function drawStrokesStyle(strokes, isText, ui, canvas) {
9273
9295
  let item;
9274
9296
  for (let i = 0, len = strokes.length; i < len; i++) {
9275
9297
  item = strokes[i];
@@ -9289,13 +9311,13 @@ function drawStrokesStyle(ui, strokes, canvas, isText) {
9289
9311
  }
9290
9312
  }
9291
9313
 
9292
- function stroke(ui, canvas, stroke) {
9314
+ function stroke(stroke, ui, canvas, renderOptions) {
9293
9315
  const options = ui.__;
9294
9316
  const { strokeWidth, strokeAlign, __font } = options;
9295
9317
  if (!strokeWidth)
9296
9318
  return;
9297
9319
  if (__font) {
9298
- strokeText(ui, canvas, stroke);
9320
+ strokeText(stroke, ui, canvas, renderOptions);
9299
9321
  }
9300
9322
  else {
9301
9323
  switch (strokeAlign) {
@@ -9317,31 +9339,36 @@ function stroke(ui, canvas, stroke) {
9317
9339
  out.stroke();
9318
9340
  options.windingRule ? out.clip(options.windingRule) : out.clip();
9319
9341
  out.clearWorld(ui.__layout.renderBounds);
9320
- canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9342
+ if (ui.__hasMirror || renderOptions.matrix) {
9343
+ canvas.copyWorldByReset(out);
9344
+ }
9345
+ else {
9346
+ canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9347
+ }
9321
9348
  out.recycle();
9322
9349
  break;
9323
9350
  }
9324
9351
  }
9325
9352
  }
9326
- function strokes(ui, canvas, strokes) {
9353
+ function strokes(strokes, ui, canvas, renderOptions) {
9327
9354
  const options = ui.__;
9328
9355
  const { strokeWidth, strokeAlign, __font } = options;
9329
9356
  if (!strokeWidth)
9330
9357
  return;
9331
9358
  if (__font) {
9332
- strokeText(ui, canvas, strokes);
9359
+ strokeText(strokes, ui, canvas, renderOptions);
9333
9360
  }
9334
9361
  else {
9335
9362
  switch (strokeAlign) {
9336
9363
  case 'center':
9337
9364
  canvas.setStroke(undefined, strokeWidth, options);
9338
- drawStrokesStyle(ui, strokes, canvas);
9365
+ drawStrokesStyle(strokes, false, ui, canvas);
9339
9366
  break;
9340
9367
  case 'inside':
9341
9368
  canvas.save();
9342
9369
  canvas.setStroke(undefined, strokeWidth * 2, options);
9343
9370
  options.windingRule ? canvas.clip(options.windingRule) : canvas.clip();
9344
- drawStrokesStyle(ui, strokes, canvas);
9371
+ drawStrokesStyle(strokes, false, ui, canvas);
9345
9372
  canvas.restore();
9346
9373
  break;
9347
9374
  case 'outside':
@@ -9349,10 +9376,15 @@ function strokes(ui, canvas, strokes) {
9349
9376
  const out = canvas.getSameCanvas(true);
9350
9377
  ui.__drawRenderPath(out);
9351
9378
  out.setStroke(undefined, strokeWidth * 2, ui.__);
9352
- drawStrokesStyle(ui, strokes, out);
9379
+ drawStrokesStyle(strokes, false, ui, out);
9353
9380
  options.windingRule ? out.clip(options.windingRule) : out.clip();
9354
9381
  out.clearWorld(renderBounds);
9355
- canvas.copyWorldToInner(out, ui.__world, renderBounds);
9382
+ if (ui.__hasMirror || renderOptions.matrix) {
9383
+ canvas.copyWorldByReset(out);
9384
+ }
9385
+ else {
9386
+ canvas.copyWorldToInner(out, ui.__world, renderBounds);
9387
+ }
9356
9388
  out.recycle();
9357
9389
  break;
9358
9390
  }
@@ -9484,21 +9516,21 @@ function conicGradient(paint, box) {
9484
9516
  }
9485
9517
 
9486
9518
  let recycleMap;
9487
- function compute(ui, attrName) {
9519
+ function compute(attrName, ui) {
9488
9520
  const value = [];
9489
9521
  let item;
9490
9522
  let paints = ui.__.__input[attrName];
9491
9523
  if (!(paints instanceof Array))
9492
9524
  paints = [paints];
9493
- recycleMap = recycleImage(ui.__, attrName);
9525
+ recycleMap = recycleImage(attrName, ui.__);
9494
9526
  for (let i = 0, len = paints.length; i < len; i++) {
9495
- item = getLeafPaint(ui, paints[i], attrName);
9527
+ item = getLeafPaint(attrName, paints[i], ui);
9496
9528
  if (item)
9497
9529
  value.push(item);
9498
9530
  }
9499
9531
  ui.__['_' + attrName] = value.length ? value : undefined;
9500
9532
  }
9501
- function getLeafPaint(ui, paint, attrName) {
9533
+ function getLeafPaint(attrName, paint, ui) {
9502
9534
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
9503
9535
  return undefined;
9504
9536
  const { boxBounds } = ui.__layout;
@@ -9536,7 +9568,7 @@ var UIPaint = /*#__PURE__*/Object.freeze({
9536
9568
  const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
9537
9569
  const tempBounds = {};
9538
9570
  const offsetOutBounds$1 = {};
9539
- function shadow(ui, current, shape, _options) {
9571
+ function shadow(ui, current, shape, renderOptions) {
9540
9572
  let copyBounds, spreadScale;
9541
9573
  const { __world, __layout } = ui;
9542
9574
  const { shadow } = ui.__;
@@ -9558,7 +9590,7 @@ function shadow(ui, current, shape, _options) {
9558
9590
  }
9559
9591
  worldCanvas ? other.copyWorld(worldCanvas, __world, __world, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
9560
9592
  }
9561
- if (ui.__hasMirror) {
9593
+ if (ui.__hasMirror || renderOptions.matrix) {
9562
9594
  current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
9563
9595
  }
9564
9596
  else {
@@ -9598,7 +9630,7 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
9598
9630
 
9599
9631
  const { toOffsetOutBounds } = BoundsHelper;
9600
9632
  const offsetOutBounds = {};
9601
- function innerShadow(ui, current, shape, _options) {
9633
+ function innerShadow(ui, current, shape, renderOptions) {
9602
9634
  let copyBounds, spreadScale;
9603
9635
  const { __world, __layout: __layout } = ui;
9604
9636
  const { innerShadow } = ui.__;
@@ -9622,7 +9654,7 @@ function innerShadow(ui, current, shape, _options) {
9622
9654
  copyBounds = bounds;
9623
9655
  }
9624
9656
  other.fillWorld(copyBounds, item.color, 'source-in');
9625
- if (ui.__hasMirror) {
9657
+ if (ui.__hasMirror || renderOptions.matrix) {
9626
9658
  current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
9627
9659
  }
9628
9660
  else {
@@ -9760,7 +9792,7 @@ function getTextCase(char, textCase, firstChar) {
9760
9792
  const { trimRight } = TextRowHelper;
9761
9793
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9762
9794
  let word, row, wordWidth, rowWidth, realWidth;
9763
- let char, charWidth, charType, lastCharType, langBreak, afterBreak, paraStart;
9795
+ let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9764
9796
  let textDrawData, rows = [], bounds;
9765
9797
  function createRows(drawData, content, style) {
9766
9798
  textDrawData = drawData;
@@ -9773,7 +9805,7 @@ function createRows(drawData, content, style) {
9773
9805
  if (charMode) {
9774
9806
  paraStart = true;
9775
9807
  lastCharType = null;
9776
- wordWidth = rowWidth = 0;
9808
+ startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
9777
9809
  word = { data: [] }, row = { words: [] };
9778
9810
  for (let i = 0, len = content.length; i < len; i++) {
9779
9811
  char = content[i];
@@ -9789,8 +9821,11 @@ function createRows(drawData, content, style) {
9789
9821
  if (charType === Letter && textCase !== 'none')
9790
9822
  char = getTextCase(char, textCase, !wordWidth);
9791
9823
  charWidth = canvas.measureText(char).width;
9792
- if (__letterSpacing)
9824
+ if (__letterSpacing) {
9825
+ if (__letterSpacing < 0)
9826
+ charSize = charWidth;
9793
9827
  charWidth += __letterSpacing;
9828
+ }
9794
9829
  langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
9795
9830
  afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
9796
9831
  realWidth = paraStart && paraIndent ? width - paraIndent : width;
@@ -9840,6 +9875,8 @@ function createRows(drawData, content, style) {
9840
9875
  }
9841
9876
  }
9842
9877
  function addChar(char, width) {
9878
+ if (charSize && !startCharSize)
9879
+ startCharSize = charSize;
9843
9880
  word.data.push({ char, width });
9844
9881
  wordWidth += width;
9845
9882
  }
@@ -9856,6 +9893,11 @@ function addRow() {
9856
9893
  row.paraStart = true;
9857
9894
  paraStart = false;
9858
9895
  }
9896
+ if (charSize) {
9897
+ row.startCharSize = startCharSize;
9898
+ row.endCharSize = charSize;
9899
+ startCharSize = 0;
9900
+ }
9859
9901
  row.width = rowWidth;
9860
9902
  if (bounds.width)
9861
9903
  trimRight(row);
@@ -9929,7 +9971,7 @@ function toChar(data, charX, rowData) {
9929
9971
 
9930
9972
  function layoutText(drawData, style) {
9931
9973
  const { rows, bounds } = drawData;
9932
- const { __lineHeight, __baseLine, textAlign, verticalAlign, paraSpacing, textOverflow } = style;
9974
+ const { __lineHeight, __baseLine, __letterSpacing, textAlign, verticalAlign, paraSpacing, textOverflow } = style;
9933
9975
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9934
9976
  let starY = __baseLine;
9935
9977
  if (textOverflow !== 'show' && realHeight > height) {
@@ -9946,7 +9988,7 @@ function layoutText(drawData, style) {
9946
9988
  }
9947
9989
  }
9948
9990
  starY += y;
9949
- let row;
9991
+ let row, rowX, rowWidth;
9950
9992
  for (let i = 0, len = rows.length; i < len; i++) {
9951
9993
  row = rows[i];
9952
9994
  row.x = x;
@@ -9965,20 +10007,22 @@ function layoutText(drawData, style) {
9965
10007
  row.isOverflow = true;
9966
10008
  drawData.overflow = i + 1;
9967
10009
  }
9968
- if (row.width < 0) {
9969
- const charWidth = row.words[0].data[0].width;
9970
- const rowX = row.x + row.width;
9971
- if (rowX < bounds.x)
9972
- bounds.x = rowX - charWidth;
9973
- if (-row.width > bounds.width)
9974
- bounds.width = -row.width + style.fontSize + charWidth;
9975
- }
9976
- else {
9977
- if (row.x < bounds.x)
9978
- bounds.x = row.x;
9979
- if (row.width > bounds.width)
9980
- bounds.width = row.width;
10010
+ rowX = row.x;
10011
+ rowWidth = row.width;
10012
+ if (__letterSpacing < 0) {
10013
+ if (row.width < 0) {
10014
+ rowWidth = -row.width + style.fontSize + __letterSpacing;
10015
+ rowX -= rowWidth;
10016
+ rowWidth += style.fontSize;
10017
+ }
10018
+ else {
10019
+ rowWidth -= __letterSpacing;
10020
+ }
9981
10021
  }
10022
+ if (rowX < bounds.x)
10023
+ bounds.x = rowX;
10024
+ if (rowWidth > bounds.width)
10025
+ bounds.width = rowWidth;
9982
10026
  }
9983
10027
  bounds.y = y;
9984
10028
  bounds.height = realHeight;
@@ -10030,10 +10074,9 @@ const TextConvert = {
10030
10074
  if (typeof content !== 'string')
10031
10075
  content = String(content);
10032
10076
  let x = 0, y = 0;
10033
- let { width, height, padding } = style;
10034
- const { textDecoration, textOverflow, __font } = style;
10035
- if (!width)
10036
- width = 0;
10077
+ let width = style.__getInput('width') || 0;
10078
+ let height = style.__getInput('height') || 0;
10079
+ const { textDecoration, textOverflow, __font, padding } = style;
10037
10080
  if (padding) {
10038
10081
  const [top, right, bottom, left] = MathHelper.fourNumber(padding);
10039
10082
  if (width) {
@@ -10148,14 +10191,9 @@ LeaferCanvas.prototype.__createContext = function () {
10148
10191
  if (this.viewSelect) {
10149
10192
  const offscreenView = Platform.origin.createCanvas(1, 1);
10150
10193
  const context = this.view.getContext('2d');
10151
- try {
10152
- context.drawImage(offscreenView, 0, 0);
10153
- }
10154
- catch (e) {
10155
- this.testView = this.view;
10156
- this.testContext = context;
10157
- this.view = offscreenView;
10158
- }
10194
+ this.testView = this.view;
10195
+ this.testContext = context;
10196
+ this.view = offscreenView;
10159
10197
  }
10160
10198
  this.context = this.view.getContext('2d');
10161
10199
  this.__bindContext();