@vvfx/sdk 0.2.9 → 0.2.11

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.
@@ -0,0 +1,6 @@
1
+ export declare function resolveTopAnchoredCardPosition({ nextHeight, position, previousHeight, scaleY, }: {
2
+ nextHeight: number;
3
+ position: [number, number];
4
+ previousHeight: number;
5
+ scaleY: number;
6
+ }): [number, number];
@@ -0,0 +1,7 @@
1
+ export function resolveTopAnchoredCardPosition({ nextHeight, position, previousHeight, scaleY, }) {
2
+ const normalizedScaleY = Number.isFinite(scaleY) ? scaleY : 1;
3
+ return [
4
+ position[0],
5
+ position[1] + (nextHeight - previousHeight) * normalizedScaleY / 2,
6
+ ];
7
+ }
@@ -137,6 +137,7 @@ export declare class HTMLOverlayManager {
137
137
  private isAutoHeightStreamActive;
138
138
  private getAutoHeightAnchor;
139
139
  private getAutoHeightItemHeight;
140
+ private getAutoHeightLimit;
140
141
  private isAutoHeightEnabled;
141
142
  private isAutoScaleEnabled;
142
143
  }
@@ -34,6 +34,7 @@ const CONTENT_INTERACTION_NONE_SELECTOR = [
34
34
  const EDITING_VIEWPORT_PADDING = 48;
35
35
  const EDITING_VIEWPORT_BOX_SCALE = 1.1;
36
36
  const AUTO_HEIGHT_EPSILON = 0.5;
37
+ const AUTO_HEIGHT_MAX_MULTIPLIER = 32;
37
38
  const CARD_RASTERIZE_READY_TIMEOUT = 3000;
38
39
  const CARD_HTML_EVENT_MESSAGE_SOURCE = 'vvfx-card-html-event';
39
40
  const requestHTMLOverlayFrame = (callback) => {
@@ -82,6 +83,7 @@ export class HTMLOverlayManager {
82
83
  autoHeightModes: new Map(),
83
84
  autoHeightCleanups: new Map(),
84
85
  autoHeightFrames: new Map(),
86
+ autoHeightInitialHeights: new Map(),
85
87
  autoHeightStreamPhases: new Map(),
86
88
  };
87
89
  constructor(options) {
@@ -145,6 +147,7 @@ export class HTMLOverlayManager {
145
147
  cancelHTMLOverlayFrame(frame);
146
148
  });
147
149
  this.state.autoHeightFrames.clear();
150
+ this.state.autoHeightInitialHeights.clear();
148
151
  this.state.autoHeightStreamPhases.clear();
149
152
  this.eventCleanups.forEach(cleanup => {
150
153
  cleanup();
@@ -1249,6 +1252,7 @@ export class HTMLOverlayManager {
1249
1252
  }
1250
1253
  removeOverlay(id) {
1251
1254
  this.cleanupOverlayContent(id);
1255
+ this.state.autoHeightInitialHeights.delete(id);
1252
1256
  this.state.elements.get(id)?.remove();
1253
1257
  this.state.selectionElements.get(id)?.remove();
1254
1258
  this.state.elements.delete(id);
@@ -1426,7 +1430,8 @@ export class HTMLOverlayManager {
1426
1430
  if (!Number.isFinite(height) || height <= 0) {
1427
1431
  return;
1428
1432
  }
1429
- const nextHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
1433
+ const measuredHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
1434
+ const nextHeight = Math.min(measuredHeight, this.getAutoHeightLimit(item));
1430
1435
  if (this.isAutoHeightStreamActive(id) && nextHeight < item.property.height) {
1431
1436
  return;
1432
1437
  }
@@ -1465,6 +1470,15 @@ export class HTMLOverlayManager {
1465
1470
  }
1466
1471
  return contentHeight / displayedHeight * item.property.height;
1467
1472
  }
1473
+ getAutoHeightLimit(item) {
1474
+ const persistedInitialHeight = this.state.autoHeightInitialHeights.get(item.id);
1475
+ if (persistedInitialHeight !== undefined) {
1476
+ return persistedInitialHeight * AUTO_HEIGHT_MAX_MULTIPLIER;
1477
+ }
1478
+ const initialHeight = item.property.height;
1479
+ this.state.autoHeightInitialHeights.set(item.id, initialHeight);
1480
+ return initialHeight * AUTO_HEIGHT_MAX_MULTIPLIER;
1481
+ }
1468
1482
  isAutoHeightEnabled(item) {
1469
1483
  return isCardItem(item) && this.options.resolveCardTypeConfig(item)?.autoHeight === true;
1470
1484
  }
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: TODO
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 赤芍,何即,不择,意绮
6
- * Version: v0.2.9
6
+ * Version: v0.2.11
7
7
  */
8
8
 
9
9
  'use strict';
@@ -70484,6 +70484,7 @@ var CONTENT_INTERACTION_NONE_SELECTOR = [
70484
70484
  var EDITING_VIEWPORT_PADDING = 48;
70485
70485
  var EDITING_VIEWPORT_BOX_SCALE = 1.1;
70486
70486
  var AUTO_HEIGHT_EPSILON = 0.5;
70487
+ var AUTO_HEIGHT_MAX_MULTIPLIER = 32;
70487
70488
  var CARD_RASTERIZE_READY_TIMEOUT = 3000;
70488
70489
  var CARD_HTML_EVENT_MESSAGE_SOURCE = 'vvfx-card-html-event';
70489
70490
  var requestHTMLOverlayFrame = function requestHTMLOverlayFrame(callback) {
@@ -70530,6 +70531,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70530
70531
  autoHeightModes: new Map(),
70531
70532
  autoHeightCleanups: new Map(),
70532
70533
  autoHeightFrames: new Map(),
70534
+ autoHeightInitialHeights: new Map(),
70533
70535
  autoHeightStreamPhases: new Map()
70534
70536
  };
70535
70537
  this.handleContainerDoubleClick = function(event) {
@@ -70682,6 +70684,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70682
70684
  cancelHTMLOverlayFrame(frame);
70683
70685
  });
70684
70686
  this.state.autoHeightFrames.clear();
70687
+ this.state.autoHeightInitialHeights.clear();
70685
70688
  this.state.autoHeightStreamPhases.clear();
70686
70689
  this.eventCleanups.forEach(function(cleanup) {
70687
70690
  cleanup();
@@ -71796,6 +71799,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71796
71799
  _proto.removeOverlay = function removeOverlay(id) {
71797
71800
  var _this_state_elements_get, _this_state_selectionElements_get;
71798
71801
  this.cleanupOverlayContent(id);
71802
+ this.state.autoHeightInitialHeights.delete(id);
71799
71803
  (_this_state_elements_get = this.state.elements.get(id)) == null ? void 0 : _this_state_elements_get.remove();
71800
71804
  (_this_state_selectionElements_get = this.state.selectionElements.get(id)) == null ? void 0 : _this_state_selectionElements_get.remove();
71801
71805
  this.state.elements.delete(id);
@@ -71990,7 +71994,8 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71990
71994
  if (!Number.isFinite(height) || height <= 0) {
71991
71995
  return;
71992
71996
  }
71993
- var nextHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
71997
+ var measuredHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
71998
+ var nextHeight = Math.min(measuredHeight, this.getAutoHeightLimit(item));
71994
71999
  if (this.isAutoHeightStreamActive(id) && nextHeight < item.property.height) {
71995
72000
  return;
71996
72001
  }
@@ -72031,6 +72036,15 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
72031
72036
  }
72032
72037
  return contentHeight / displayedHeight * item.property.height;
72033
72038
  };
72039
+ _proto.getAutoHeightLimit = function getAutoHeightLimit(item) {
72040
+ var persistedInitialHeight = this.state.autoHeightInitialHeights.get(item.id);
72041
+ if (persistedInitialHeight !== undefined) {
72042
+ return persistedInitialHeight * AUTO_HEIGHT_MAX_MULTIPLIER;
72043
+ }
72044
+ var initialHeight = item.property.height;
72045
+ this.state.autoHeightInitialHeights.set(item.id, initialHeight);
72046
+ return initialHeight * AUTO_HEIGHT_MAX_MULTIPLIER;
72047
+ };
72034
72048
  _proto.isAutoHeightEnabled = function isAutoHeightEnabled(item) {
72035
72049
  var _this_options_resolveCardTypeConfig;
72036
72050
  return isCardItem(item) && ((_this_options_resolveCardTypeConfig = this.options.resolveCardTypeConfig(item)) == null ? void 0 : _this_options_resolveCardTypeConfig.autoHeight) === true;
@@ -72390,6 +72404,15 @@ function withTimeout(promise, timeout) {
72390
72404
  });
72391
72405
  }
72392
72406
 
72407
+ function resolveTopAnchoredCardPosition(param) {
72408
+ var nextHeight = param.nextHeight, position = param.position, previousHeight = param.previousHeight, scaleY = param.scaleY;
72409
+ var normalizedScaleY = Number.isFinite(scaleY) ? scaleY : 1;
72410
+ return [
72411
+ position[0],
72412
+ position[1] + (nextHeight - previousHeight) * normalizedScaleY / 2
72413
+ ];
72414
+ }
72415
+
72393
72416
  function orderSDKCanvasLayers(param) {
72394
72417
  var container = param.container, playerContainer = param.playerContainer, htmlOverlayLayer = param.htmlOverlayLayer, gestureCanvas = param.gestureCanvas;
72395
72418
  [
@@ -72502,6 +72525,8 @@ var SDK = /*#__PURE__*/ function() {
72502
72525
  }, box);
72503
72526
  },
72504
72527
  setCardItemHeight: function setCardItemHeight(id, height, options) {
72528
+ var _ref;
72529
+ var _item_property_scale;
72505
72530
  var item = _this.getSDKItem(id);
72506
72531
  if (!isCardItem(item) || options.anchor === 'center') {
72507
72532
  void _this.setItemProperty({
@@ -72512,17 +72537,18 @@ var SDK = /*#__PURE__*/ function() {
72512
72537
  });
72513
72538
  return;
72514
72539
  }
72515
- var _item_property_position = item.property.position, x = _item_property_position[0], y = _item_property_position[1];
72516
- var deltaY = (height - options.previousHeight) / 2;
72540
+ var position = resolveTopAnchoredCardPosition({
72541
+ nextHeight: height,
72542
+ position: item.property.position,
72543
+ previousHeight: options.previousHeight,
72544
+ scaleY: (_ref = (_item_property_scale = item.property.scale) == null ? void 0 : _item_property_scale[1]) != null ? _ref : 1
72545
+ });
72517
72546
  void _this.setItemProperty({
72518
72547
  itemId: id,
72519
72548
  type: SDKItemType.CARD,
72520
72549
  property: {
72521
72550
  height: height,
72522
- position: [
72523
- x,
72524
- y + deltaY
72525
- ]
72551
+ position: position
72526
72552
  }
72527
72553
  });
72528
72554
  },