@vvfx/sdk 0.2.2-beta.11 → 0.2.2-beta.13

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.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: TODO
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 赤芍,何即,不择,意绮
6
- * Version: v0.2.2-beta.11
6
+ * Version: v0.2.2-beta.13
7
7
  */
8
8
 
9
9
  'use strict';
@@ -55360,8 +55360,8 @@ var TransformGizmo = /*#__PURE__*/ function(Gizmo) {
55360
55360
  }
55361
55361
  var selectedItem = (_selectedItems_ = selectedItems[0]) != null ? _selectedItems_ : undefined;
55362
55362
  // html卡片内容在非自动缩放的情况下,拖动的时候内容自适应,因此与智能画板一样,需要默认是自由缩放(即自由改大小)
55363
- var isAutoFitContentCardItem = selectedItem && isCardItem(selectedItem) && !selectedItem.isAutoScale;
55364
- var isShiftLockScale = selectedItem && selectedItems.length === 1 && (isFrameItem(selectedItem) || isAutoFitContentCardItem) ? !this.isShiftDown : this.isShiftDown;
55363
+ var isSingleAutoFitContentCardItem = selectedItems.length === 1 && selectedItem && isCardItem(selectedItem) && !selectedItem.isAutoScale;
55364
+ var isShiftLockScale = selectedItem && selectedItems.length === 1 && (isFrameItem(selectedItem) || isSingleAutoFitContentCardItem) ? !this.isShiftDown : this.isShiftDown;
55365
55365
  var farthestCorner = this.scaleParam.farthestCorner;
55366
55366
  var isValidScale = (scaleCorner.x - farthestCorner.x) * (this.cursorPoint.x - farthestCorner.x) > 0 && (scaleCorner.y - farthestCorner.y) * (this.cursorPoint.y - farthestCorner.y) > 0;
55367
55367
  if (!isValidScale && this.isLockScale && !this.isShiftDown) {
@@ -55435,7 +55435,7 @@ var TransformGizmo = /*#__PURE__*/ function(Gizmo) {
55435
55435
  newWidth,
55436
55436
  newHeight
55437
55437
  ], translation1);
55438
- } else if (isAutoFitContentCardItem) {
55438
+ } else if (isSingleAutoFitContentCardItem && selectedItem && isCardItem(selectedItem)) {
55439
55439
  var currentWidth1 = selectedItem.pixelWidth;
55440
55440
  var currentHeight1 = selectedItem.pixelHeight;
55441
55441
  var newWidth1 = currentWidth1 * resultScalar1.x;
@@ -55452,16 +55452,6 @@ var TransformGizmo = /*#__PURE__*/ function(Gizmo) {
55452
55452
  height: newHeight1
55453
55453
  }
55454
55454
  });
55455
- } else if (selectedItem && selectedItems.length === 1 && isCardItem(selectedItem)) {
55456
- void this._pageDataUtils.setItemProperty({
55457
- itemId: selectedItem.id,
55458
- type: SDKItemType.CARD,
55459
- property: {
55460
- width: selectedItem.width * resultScalar1.x,
55461
- height: selectedItem.height * resultScalar1.y
55462
- }
55463
- });
55464
- this._pageDataUtils.moveItem(selectedItem.id, translation1);
55465
55455
  } else {
55466
55456
  // 普通元素的缩放逻辑
55467
55457
  selectedItems.forEach(function(item) {
@@ -91896,6 +91886,30 @@ var EDITING_VIEWPORT_PADDING = 48;
91896
91886
  var EDITING_VIEWPORT_BOX_SCALE = 1.1;
91897
91887
  var AUTO_HEIGHT_EPSILON = 0.5;
91898
91888
  var CARD_RASTERIZE_READY_TIMEOUT = 3000;
91889
+ var CARD_HTML_EVENT_MESSAGE_SOURCE = 'vvfx-card-html-event';
91890
+ var requestHTMLOverlayFrame = function requestHTMLOverlayFrame(callback) {
91891
+ if (typeof requestAnimationFrame === 'function') {
91892
+ try {
91893
+ return requestAnimationFrame(callback);
91894
+ } catch (unused) {
91895
+ // Some non-browser test runtimes install a RAF polyfill that depends on window.
91896
+ }
91897
+ }
91898
+ return setTimeout(function() {
91899
+ callback(Date.now());
91900
+ }, 16);
91901
+ };
91902
+ var cancelHTMLOverlayFrame = function cancelHTMLOverlayFrame(frame) {
91903
+ if (typeof cancelAnimationFrame === 'function') {
91904
+ try {
91905
+ cancelAnimationFrame(frame);
91906
+ return;
91907
+ } catch (unused) {
91908
+ // Fall back to clearTimeout for frames created by requestHTMLOverlayFrame.
91909
+ }
91910
+ }
91911
+ clearTimeout(frame);
91912
+ };
91899
91913
  var HTMLOverlayManager = /*#__PURE__*/ function() {
91900
91914
  function HTMLOverlayManager(options) {
91901
91915
  var _this = this;
@@ -91968,7 +91982,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
91968
91982
  return;
91969
91983
  }
91970
91984
  if (_this.contentInteractionFrame !== undefined) {
91971
- cancelAnimationFrame(_this.contentInteractionFrame);
91985
+ cancelHTMLOverlayFrame(_this.contentInteractionFrame);
91972
91986
  _this.contentInteractionFrame = undefined;
91973
91987
  }
91974
91988
  _this.pendingContentInteractionEvent = undefined;
@@ -92029,11 +92043,11 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92029
92043
  _proto.dispose = function dispose() {
92030
92044
  var _this_state_layer;
92031
92045
  if (this.state.updateFrame !== undefined) {
92032
- cancelAnimationFrame(this.state.updateFrame);
92046
+ cancelHTMLOverlayFrame(this.state.updateFrame);
92033
92047
  this.state.updateFrame = undefined;
92034
92048
  }
92035
92049
  if (this.contentInteractionFrame !== undefined) {
92036
- cancelAnimationFrame(this.contentInteractionFrame);
92050
+ cancelHTMLOverlayFrame(this.contentInteractionFrame);
92037
92051
  this.contentInteractionFrame = undefined;
92038
92052
  }
92039
92053
  this.pendingContentInteractionEvent = undefined;
@@ -92063,7 +92077,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92063
92077
  });
92064
92078
  this.state.autoHeightCleanups.clear();
92065
92079
  this.state.autoHeightFrames.forEach(function(frame) {
92066
- cancelAnimationFrame(frame);
92080
+ cancelHTMLOverlayFrame(frame);
92067
92081
  });
92068
92082
  this.state.autoHeightFrames.clear();
92069
92083
  this.eventCleanups.forEach(function(cleanup) {
@@ -92082,9 +92096,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92082
92096
  _proto.scheduleRender = function scheduleRender() {
92083
92097
  var _this = this;
92084
92098
  if (this.state.updateFrame !== undefined) {
92085
- cancelAnimationFrame(this.state.updateFrame);
92099
+ cancelHTMLOverlayFrame(this.state.updateFrame);
92086
92100
  }
92087
- this.state.updateFrame = requestAnimationFrame(function() {
92101
+ this.state.updateFrame = requestHTMLOverlayFrame(function() {
92088
92102
  _this.state.updateFrame = undefined;
92089
92103
  _this.render();
92090
92104
  });
@@ -92093,6 +92107,40 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92093
92107
  this.cleanupOverlayContent(id);
92094
92108
  this.invalidateContentInteractionZones(id);
92095
92109
  };
92110
+ _proto.getHtmlCardWindow = function getHtmlCardWindow(id) {
92111
+ var contentOverlay = this.state.contentElements.get(id);
92112
+ var iframe = contentOverlay == null ? void 0 : contentOverlay.querySelector('iframe');
92113
+ return iframe == null ? void 0 : iframe.contentWindow;
92114
+ };
92115
+ _proto.patchCardHTML = function patchCardHTML(id, patch) {
92116
+ var html = this.state.contents.get(id);
92117
+ if (!html) {
92118
+ return false;
92119
+ }
92120
+ var patchHandler = html.content.patch;
92121
+ if (!patchHandler) {
92122
+ return false;
92123
+ }
92124
+ var context = this.createPatchContext(id, html);
92125
+ return patchHandler(patch, context) !== false;
92126
+ };
92127
+ _proto.dispatchHtmlCardEvent = function dispatchHtmlCardEvent(id, type, detail) {
92128
+ var targetWindow = this.getHtmlCardWindow(id);
92129
+ try {
92130
+ if (!targetWindow || typeof targetWindow.postMessage !== 'function') {
92131
+ return false;
92132
+ }
92133
+ targetWindow.postMessage({
92134
+ detail: detail,
92135
+ payload: detail,
92136
+ source: CARD_HTML_EVENT_MESSAGE_SOURCE,
92137
+ type: type
92138
+ }, '*');
92139
+ return true;
92140
+ } catch (unused) {
92141
+ return false;
92142
+ }
92143
+ };
92096
92144
  _proto.rasterizeCard = function rasterizeCard(id, options) {
92097
92145
  return _async_to_generator(function() {
92098
92146
  var contentOverlay, capture, _ref, _options_pixelRatio, image, error;
@@ -92100,7 +92148,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92100
92148
  switch(_state.label){
92101
92149
  case 0:
92102
92150
  if (this.state.updateFrame !== undefined) {
92103
- cancelAnimationFrame(this.state.updateFrame);
92151
+ cancelHTMLOverlayFrame(this.state.updateFrame);
92104
92152
  this.state.updateFrame = undefined;
92105
92153
  }
92106
92154
  this.render();
@@ -92267,13 +92315,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92267
92315
  var overlay = _this.getOrCreateOverlay(item.id, parentOverlay, elements);
92268
92316
  var contentOverlay = _this.getOrCreateContentOverlay(item.id, overlay);
92269
92317
  var selectionOverlay = _this.getOrCreateSelectionOverlay(item.id, selectionLayer);
92270
- if (!_this.state.contents.has(item.id)) {
92271
- _this.renderOverlayHTML(item.id, contentOverlay, html);
92272
- }
92273
- _this.applyHTMLRootConfig(overlay, html);
92274
92318
  var offsetX = frameBox && !frameBox.isEmpty() ? frameBox.min.x : 0;
92275
92319
  var offsetY = frameBox && !frameBox.isEmpty() ? frameBox.min.y : 0;
92276
92320
  var boxStyle = getCardOverlayBoxStyle(itemBox, item.property.width, item.property.height, offsetX, offsetY, _this.isAutoScaleEnabled(item));
92321
+ _this.applyHTMLRootConfig(overlay, html);
92277
92322
  overlay.style.left = boxStyle.left;
92278
92323
  overlay.style.top = boxStyle.top;
92279
92324
  overlay.style.width = boxStyle.width;
@@ -92288,8 +92333,12 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92288
92333
  selectionOverlay.style.transform = selectionBoxStyle.transform;
92289
92334
  selectionOverlay.style.transformOrigin = '0 0';
92290
92335
  _this.applyHTMLRootConfig(selectionOverlay, html);
92336
+ _this.makeSelectionOverlayTransparent(selectionOverlay);
92291
92337
  _this.syncOverlaySelection(item.id, overlay, selectionOverlay);
92292
92338
  _this.syncContentScale(item.id, boxStyle.contentWidth, boxStyle.contentHeight);
92339
+ if (!_this.state.contents.has(item.id)) {
92340
+ _this.renderOverlayHTML(item.id, contentOverlay, html);
92341
+ }
92293
92342
  _this.syncAutoHeight(item.id, _this.isAutoHeightEnabled(item));
92294
92343
  _this.syncContentInteraction(item.id);
92295
92344
  });
@@ -92529,14 +92578,20 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92529
92578
  if (this.contentInteractionFrame !== undefined) {
92530
92579
  return;
92531
92580
  }
92532
- this.contentInteractionFrame = requestAnimationFrame(function() {
92533
- _this.contentInteractionFrame = undefined;
92534
- var pendingEvent = _this.pendingContentInteractionEvent;
92535
- _this.pendingContentInteractionEvent = undefined;
92536
- if (pendingEvent) {
92537
- _this.syncActiveContentInteraction(pendingEvent);
92538
- }
92539
- });
92581
+ try {
92582
+ this.contentInteractionFrame = requestAnimationFrame(function() {
92583
+ _this.contentInteractionFrame = undefined;
92584
+ var pendingEvent = _this.pendingContentInteractionEvent;
92585
+ _this.pendingContentInteractionEvent = undefined;
92586
+ if (pendingEvent) {
92587
+ _this.syncActiveContentInteraction(pendingEvent);
92588
+ }
92589
+ });
92590
+ } catch (unused) {
92591
+ this.contentInteractionFrame = undefined;
92592
+ this.pendingContentInteractionEvent = undefined;
92593
+ this.syncActiveContentInteraction(event);
92594
+ }
92540
92595
  };
92541
92596
  _proto.setActiveContentInteraction = function setActiveContentInteraction(zone) {
92542
92597
  var _this = this;
@@ -92960,6 +93015,20 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92960
93015
  });
92961
93016
  this.state.contents.set(id, html);
92962
93017
  };
93018
+ _proto.createPatchContext = function createPatchContext(id, html) {
93019
+ var _this = this;
93020
+ return {
93021
+ id: id,
93022
+ html: html,
93023
+ content: html.content,
93024
+ container: this.state.contentMountElements.get(id),
93025
+ contentWindow: this.getHtmlCardWindow(id),
93026
+ refresh: function refresh() {
93027
+ _this.invalidateCardHTML(id);
93028
+ _this.scheduleRender();
93029
+ }
93030
+ };
93031
+ };
92963
93032
  _proto.observeContentInteractionZones = function observeContentInteractionZones(id, contentContainer) {
92964
93033
  var _this = this;
92965
93034
  var _this_state_contentInteractionZoneCleanups_get;
@@ -93019,6 +93088,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93019
93088
  });
93020
93089
  });
93021
93090
  };
93091
+ _proto.makeSelectionOverlayTransparent = function makeSelectionOverlayTransparent(selectionOverlay) {
93092
+ selectionOverlay.style.background = 'transparent';
93093
+ selectionOverlay.style.backgroundColor = 'transparent';
93094
+ };
93022
93095
  _proto.renderOverlayContent = function renderOverlayContent(overlay, content, options) {
93023
93096
  var _this = this;
93024
93097
  switch(content.kind){
@@ -93211,7 +93284,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93211
93284
  if (this.state.autoHeightFrames.has(id)) {
93212
93285
  return;
93213
93286
  }
93214
- var frame = requestAnimationFrame(function() {
93287
+ var frame = requestHTMLOverlayFrame(function() {
93215
93288
  _this.state.autoHeightFrames.delete(id);
93216
93289
  _this.measureAutoHeight(id);
93217
93290
  });
@@ -93295,7 +93368,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93295
93368
  }
93296
93369
  var frame = this.state.autoHeightFrames.get(id);
93297
93370
  if (frame !== undefined) {
93298
- cancelAnimationFrame(frame);
93371
+ cancelHTMLOverlayFrame(frame);
93299
93372
  this.state.autoHeightFrames.delete(id);
93300
93373
  }
93301
93374
  };
@@ -93313,7 +93386,18 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93313
93386
  if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
93314
93387
  return;
93315
93388
  }
93316
- this.options.setCardItemHeight(id, nextHeight);
93389
+ this.options.setCardItemHeight(id, nextHeight, {
93390
+ anchor: this.getAutoHeightAnchor(item),
93391
+ previousHeight: item.property.height
93392
+ });
93393
+ };
93394
+ _proto.getAutoHeightAnchor = function getAutoHeightAnchor(item) {
93395
+ var _ref;
93396
+ var _this_options_resolveCardTypeConfig;
93397
+ if (!isCardItem(item)) {
93398
+ return 'top';
93399
+ }
93400
+ return (_ref = (_this_options_resolveCardTypeConfig = this.options.resolveCardTypeConfig(item)) == null ? void 0 : _this_options_resolveCardTypeConfig.autoHeightAnchor) != null ? _ref : 'top';
93317
93401
  };
93318
93402
  _proto.getAutoHeightItemHeight = function getAutoHeightItemHeight(item, contentHeight) {
93319
93403
  if (!isCardItem(item) || this.isAutoScaleEnabled(item)) {
@@ -93399,7 +93483,7 @@ function formatCssNumber(value) {
93399
93483
  }
93400
93484
  function nextAnimationFrame() {
93401
93485
  return new Promise(function(resolve) {
93402
- requestAnimationFrame(function() {
93486
+ requestHTMLOverlayFrame(function() {
93403
93487
  resolve();
93404
93488
  });
93405
93489
  });
@@ -93968,12 +94052,29 @@ var SDK = /*#__PURE__*/ function() {
93968
94052
  bottom: HTML_CARD_EDITING_VIEWPORT_PADDING
93969
94053
  }, box);
93970
94054
  },
93971
- setCardItemHeight: function setCardItemHeight(id, height) {
94055
+ setCardItemHeight: function setCardItemHeight(id, height, options) {
94056
+ var item = _this.getSDKItem(id);
94057
+ if (!isCardItem(item) || options.anchor === 'center') {
94058
+ void _this.setItemProperty({
94059
+ itemId: id,
94060
+ type: SDKItemType.CARD,
94061
+ propertyName: 'height',
94062
+ propertyValue: height
94063
+ });
94064
+ return;
94065
+ }
94066
+ var _item_property_position = item.property.position, x = _item_property_position[0], y = _item_property_position[1];
94067
+ var deltaY = (height - options.previousHeight) / 2;
93972
94068
  void _this.setItemProperty({
93973
94069
  itemId: id,
93974
94070
  type: SDKItemType.CARD,
93975
- propertyName: 'height',
93976
- propertyValue: height
94071
+ property: {
94072
+ height: height,
94073
+ position: [
94074
+ x,
94075
+ y + deltaY
94076
+ ]
94077
+ }
93977
94078
  });
93978
94079
  },
93979
94080
  getSelectedItemIds: function getSelectedItemIds() {
@@ -96197,6 +96298,38 @@ var SDK = /*#__PURE__*/ function() {
96197
96298
  return true;
96198
96299
  };
96199
96300
  /**
96301
+ * @description 获取指定 HTML 卡片当前 iframe 的 window。
96302
+ * @description 仅 inline/document 或自行渲染 iframe 的 DOM 内容会返回 window。
96303
+ * @param id 卡片元素 ID
96304
+ * @returns HTML iframe window
96305
+ */ _proto.getHtmlCardWindow = function getHtmlCardWindow(id) {
96306
+ var _this__htmlOverlayManager;
96307
+ return (_this__htmlOverlayManager = this._htmlOverlayManager) == null ? void 0 : _this__htmlOverlayManager.getHtmlCardWindow(id);
96308
+ };
96309
+ /**
96310
+ * @description 向指定 HTML 卡片发送增量 patch。
96311
+ * @description 当卡片内容配置了 CardHTMLPatchHandler 时,可用于局部更新 HTML,而不必整卡 refresh。
96312
+ * @param id 卡片元素 ID
96313
+ * @param patch patch 负载,由卡片内容自己的 patch handler 解释
96314
+ * @returns 是否被 patch handler 处理
96315
+ */ _proto.patchCardHTML = function patchCardHTML(id, patch) {
96316
+ var _ref;
96317
+ var _this__htmlOverlayManager;
96318
+ return (_ref = (_this__htmlOverlayManager = this._htmlOverlayManager) == null ? void 0 : _this__htmlOverlayManager.patchCardHTML(id, patch)) != null ? _ref : false;
96319
+ };
96320
+ /**
96321
+ * @description 向指定 HTML 卡片 iframe 派发事件。
96322
+ * @description 通过 postMessage 投递事件,跨源/同源行为一致,消息 source 为 vvfx-card-html-event。
96323
+ * @param id 卡片元素 ID
96324
+ * @param type 事件名称
96325
+ * @param detail 事件 detail
96326
+ * @returns 是否成功派发或投递
96327
+ */ _proto.dispatchHtmlCardEvent = function dispatchHtmlCardEvent(id, type, detail) {
96328
+ var _ref;
96329
+ var _this__htmlOverlayManager;
96330
+ return (_ref = (_this__htmlOverlayManager = this._htmlOverlayManager) == null ? void 0 : _this__htmlOverlayManager.dispatchHtmlCardEvent(id, type, detail)) != null ? _ref : false;
96331
+ };
96332
+ /**
96200
96333
  * @description 创建卡片元素
96201
96334
  * @description 底层以透明 SpriteItem 形式渲染,支持 cardType 属性
96202
96335
  * @param createInfo 卡片创建信息
@@ -96581,7 +96714,7 @@ SDK.config = BaseConfig;
96581
96714
  var config = SDK.config.itemConfig.cardConfig.cardTypes.find(function(t) {
96582
96715
  return t.type === _this.cardType;
96583
96716
  });
96584
- return !!(config == null ? void 0 : config.autoScale);
96717
+ return (config == null ? void 0 : config.autoScale) !== false;
96585
96718
  }
96586
96719
  },
96587
96720
  {