@visactor/vrender-core 0.16.12 → 0.16.14-alpha.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/index.js CHANGED
@@ -4294,7 +4294,10 @@
4294
4294
  direction: 'horizontal',
4295
4295
  wordBreak: 'break-all',
4296
4296
  ignoreBuf: false,
4297
- verticalMode: 0
4297
+ verticalMode: 0,
4298
+ whiteSpace: 'no-wrap',
4299
+ heightLimit: Infinity,
4300
+ lineClamp: Infinity
4298
4301
  };
4299
4302
  const DefaultStyle = Object.assign(Object.assign(Object.assign({ opacity: 1, background: null, texture: null, textureColor: 'black', textureSize: 10, texturePadding: 2, backgroundMode: 0, blur: 0, cursor: null, html: null }, DefaultFillStyle), DefaultStrokeStyle), DefaultLayout);
4300
4303
  const DefaultConnectAttribute = {
@@ -9013,6 +9016,13 @@
9013
9016
  }
9014
9017
  RafBasedSTO.TimeOut = 1000 / 60;
9015
9018
  const rafBasedSto = new RafBasedSTO();
9019
+ const calculateLineHeight = (lineHeight, fontSize) => {
9020
+ if (vutils.isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {
9021
+ const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
9022
+ return fontSize * scale;
9023
+ }
9024
+ return lineHeight;
9025
+ };
9016
9026
 
9017
9027
  class IncreaseCount extends ACustomAnimate {
9018
9028
  constructor(from, to, duration, easing, params) {
@@ -14314,6 +14324,8 @@
14314
14324
  const TEXT_UPDATE_TAG_KEY = [
14315
14325
  'text',
14316
14326
  'maxLineWidth',
14327
+ 'heightLimit',
14328
+ 'lineClamp',
14317
14329
  'fontSize',
14318
14330
  'fontFamily',
14319
14331
  'fontWeight',
@@ -14398,6 +14410,112 @@
14398
14410
  this.clearUpdateBoundTag();
14399
14411
  return bounds;
14400
14412
  }
14413
+ updateWrapAABBBounds(text) {
14414
+ var _a, _b, _c;
14415
+ const textTheme = getTheme(this).text;
14416
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, lineHeight = calculateLineHeight(this.attribute.lineHeight || this.attribute.fontSize || textTheme.fontSize, this.attribute.fontSize || textTheme.fontSize), ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
14417
+ const buf = ignoreBuf ? 0 : 2;
14418
+ if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
14419
+ const bbox = this.cache.layoutData.bbox;
14420
+ this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
14421
+ if (stroke) {
14422
+ this._AABBBounds.expand(lineWidth / 2);
14423
+ }
14424
+ return this._AABBBounds;
14425
+ }
14426
+ const textMeasure = application.graphicUtil.textMeasure;
14427
+ const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
14428
+ const lines = vutils.isArray(text) ? text.map(l => l.toString()) : [text.toString()];
14429
+ const linesLayout = [];
14430
+ const bboxWH = [0, 0];
14431
+ let lineCountLimit = Infinity;
14432
+ if (heightLimit > 0) {
14433
+ lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1);
14434
+ }
14435
+ if (lineClamp) {
14436
+ lineCountLimit = Math.min(lineCountLimit, lineClamp);
14437
+ }
14438
+ if (typeof maxLineWidth === 'number' && maxLineWidth !== Infinity) {
14439
+ if (maxLineWidth > 0) {
14440
+ for (let i = 0; i < lines.length; i++) {
14441
+ const str = lines[i];
14442
+ let needCut = true;
14443
+ if (i === lineCountLimit - 1) {
14444
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
14445
+ linesLayout.push({
14446
+ str: clip.str,
14447
+ width: clip.width
14448
+ });
14449
+ break;
14450
+ }
14451
+ const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, wordBreak === 'break-word');
14452
+ if (str !== '' && clip.str === '') {
14453
+ if (ellipsis) {
14454
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
14455
+ clip.str = (_b = clipEllipsis.str) !== null && _b !== void 0 ? _b : '';
14456
+ clip.width = (_c = clipEllipsis.width) !== null && _c !== void 0 ? _c : 0;
14457
+ }
14458
+ else {
14459
+ clip.str = '';
14460
+ clip.width = 0;
14461
+ }
14462
+ needCut = false;
14463
+ }
14464
+ linesLayout.push({
14465
+ str: clip.str,
14466
+ width: clip.width
14467
+ });
14468
+ if (clip.str.length === str.length) ;
14469
+ else if (needCut) {
14470
+ const newStr = str.substring(clip.str.length);
14471
+ lines.splice(i + 1, 0, newStr);
14472
+ }
14473
+ }
14474
+ }
14475
+ let maxWidth = 0;
14476
+ linesLayout.forEach(layout => {
14477
+ maxWidth = Math.max(maxWidth, layout.width);
14478
+ });
14479
+ bboxWH[0] = maxWidth;
14480
+ }
14481
+ else {
14482
+ let lineWidth = 0;
14483
+ let width;
14484
+ let text;
14485
+ for (let i = 0, len = lines.length; i < len; i++) {
14486
+ if (i === lineCountLimit - 1) {
14487
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, false);
14488
+ linesLayout.push({
14489
+ str: clip.str,
14490
+ width: clip.width
14491
+ });
14492
+ lineWidth = Math.max(lineWidth, clip.width);
14493
+ break;
14494
+ }
14495
+ text = lines[i];
14496
+ width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, wordBreak === 'break-word');
14497
+ lineWidth = Math.max(lineWidth, width);
14498
+ linesLayout.push({ str: text, width });
14499
+ }
14500
+ bboxWH[0] = lineWidth;
14501
+ }
14502
+ bboxWH[1] = linesLayout.length * (lineHeight + buf);
14503
+ const bbox = {
14504
+ xOffset: 0,
14505
+ yOffset: 0,
14506
+ width: bboxWH[0],
14507
+ height: bboxWH[1]
14508
+ };
14509
+ layoutObj.LayoutBBox(bbox, textAlign, textBaseline);
14510
+ const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
14511
+ this.cache.layoutData = layoutData;
14512
+ this.clearUpdateShapeTag();
14513
+ this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
14514
+ if (stroke) {
14515
+ this._AABBBounds.expand(lineWidth / 2);
14516
+ }
14517
+ return this._AABBBounds;
14518
+ }
14401
14519
  updateSingallineAABBBounds(text) {
14402
14520
  const textTheme = getTheme(this).text;
14403
14521
  const { direction = textTheme.direction } = this.attribute;
@@ -14419,9 +14537,13 @@
14419
14537
  let width;
14420
14538
  let str;
14421
14539
  const attribute = this.attribute;
14422
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, ignoreBuf = textTheme.ignoreBuf } = attribute;
14540
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, ignoreBuf = textTheme.ignoreBuf, whiteSpace = textTheme.whiteSpace } = attribute;
14541
+ if (whiteSpace === 'normal') {
14542
+ return this.updateWrapAABBBounds(text);
14543
+ }
14423
14544
  const buf = ignoreBuf ? 0 : Math.max(2, fontSize * 0.075);
14424
- const { lineHeight = (_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf } = attribute;
14545
+ const textFontSize = attribute.fontSize || textTheme.fontSize;
14546
+ const { lineHeight = calculateLineHeight((_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : textFontSize, textFontSize) + buf } = attribute;
14425
14547
  if (!this.shouldUpdateShape() && this.cache) {
14426
14548
  width = (_b = this.cache.clipedWidth) !== null && _b !== void 0 ? _b : 0;
14427
14549
  const dx = textDrawOffsetX(textAlign, width);
@@ -14479,7 +14601,7 @@
14479
14601
  const attribute = this.attribute;
14480
14602
  const { ignoreBuf = textTheme.ignoreBuf } = attribute;
14481
14603
  const buf = ignoreBuf ? 0 : 2;
14482
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke, lineHeight = (_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
14604
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke, lineHeight = calculateLineHeight((_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize), attribute.fontSize || textTheme.fontSize) + buf, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
14483
14605
  let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
14484
14606
  if (!verticalMode) {
14485
14607
  const t = textAlign;
@@ -14539,7 +14661,10 @@
14539
14661
  var _a;
14540
14662
  const textTheme = getTheme(this).text;
14541
14663
  const attribute = this.attribute;
14542
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, lineHeight = attribute.lineHeight || attribute.fontSize || textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak } = attribute;
14664
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, lineHeight = calculateLineHeight(attribute.lineHeight || attribute.fontSize || textTheme.fontSize, attribute.fontSize || textTheme.fontSize), ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace } = attribute;
14665
+ if (whiteSpace === 'normal') {
14666
+ return this.updateWrapAABBBounds(text);
14667
+ }
14543
14668
  if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
14544
14669
  const bbox = this.cache.layoutData.bbox;
14545
14670
  this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
@@ -14568,7 +14693,7 @@
14568
14693
  const attribute = this.attribute;
14569
14694
  const { ignoreBuf = textTheme.ignoreBuf } = attribute;
14570
14695
  const buf = ignoreBuf ? 0 : 2;
14571
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineHeight = (_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
14696
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineHeight = calculateLineHeight((_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize), attribute.fontSize || textTheme.fontSize) + buf, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
14572
14697
  let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
14573
14698
  if (!verticalMode) {
14574
14699
  const t = textAlign;
@@ -14677,7 +14802,7 @@
14677
14802
  updateMultilineAABBBounds(text) {
14678
14803
  var _a, _b, _c;
14679
14804
  const textTheme = getTheme(this).text;
14680
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, lineHeight = this.attribute.lineHeight || this.attribute.fontSize || textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
14805
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, lineHeight = calculateLineHeight(this.attribute.lineHeight || this.attribute.fontSize || textTheme.fontSize, this.attribute.fontSize || textTheme.fontSize), ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
14681
14806
  const buf = ignoreBuf ? 0 : 2;
14682
14807
  if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
14683
14808
  const bbox = this.cache.layoutData.bbox;
@@ -26124,6 +26249,19 @@
26124
26249
  this.setAttributes({ background: this._background });
26125
26250
  }
26126
26251
  }
26252
+ preventRender(prevent) {
26253
+ if (prevent) {
26254
+ this._skipRender = -Infinity;
26255
+ }
26256
+ else {
26257
+ if (this.params && this.params.optimize && this.params.optimize.skipRenderWithOutRange !== false) {
26258
+ this._skipRender = this.window.isVisible() ? 0 : 1;
26259
+ }
26260
+ else {
26261
+ this._skipRender = 0;
26262
+ }
26263
+ }
26264
+ }
26127
26265
  optmize(params) {
26128
26266
  this.optmizeRender(params === null || params === void 0 ? void 0 : params.skipRenderWithOutRange);
26129
26267
  }
@@ -26131,8 +26269,11 @@
26131
26269
  if (!skipRenderWithOutRange) {
26132
26270
  return;
26133
26271
  }
26134
- this._skipRender = this.window.isVisible() ? 0 : 1;
26272
+ this._skipRender = this._skipRender < 0 ? this._skipRender : this.window.isVisible() ? 0 : 1;
26135
26273
  this.window.onVisibleChange(visible => {
26274
+ if (this._skipRender < 0) {
26275
+ return;
26276
+ }
26136
26277
  if (visible) {
26137
26278
  if (this.dirtyBounds) {
26138
26279
  this.dirtyBounds.setValue(0, 0, this._viewBox.width(), this._viewBox.height());
@@ -27500,6 +27641,7 @@
27500
27641
  exports.builtinSymbols = builtinSymbols;
27501
27642
  exports.builtinSymbolsMap = builtinSymbolsMap;
27502
27643
  exports.calcLineCache = calcLineCache$1;
27644
+ exports.calculateLineHeight = calculateLineHeight;
27503
27645
  exports.centroidOfSubpath = centroidOfSubpath;
27504
27646
  exports.circleBounds = circleBounds;
27505
27647
  exports.clock = clock;