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

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.13
6
+ * Version: v0.2.2-beta.16
7
7
  */
8
8
 
9
9
  'use strict';
@@ -60433,6 +60433,8 @@ var PageDataUtils = /*#__PURE__*/ function() {
60433
60433
  }
60434
60434
  }
60435
60435
  var isLocked = (_this_getSDKItem = this.getSDKItem(playerItem.getInstanceId())) == null ? void 0 : _this_getSDKItem.isLocked;
60436
+ // 优先通过 ID 查找现有 SDKItem,获取其 SDKItemType
60437
+ var existingSDKItem = this.getSDKItem(playerItem.getInstanceId());
60436
60438
  // 创建基础选项
60437
60439
  var baseOptions = {
60438
60440
  id: playerItem.getInstanceId(),
@@ -60444,12 +60446,11 @@ var PageDataUtils = /*#__PURE__*/ function() {
60444
60446
  endBehavior: playerItem.endBehavior,
60445
60447
  visible: isVisible,
60446
60448
  isLocked: isLocked,
60447
- isCoreEditable: isCoreEditable
60449
+ isCoreEditable: isCoreEditable,
60450
+ extension: existingSDKItem == null ? void 0 : existingSDKItem.extension
60448
60451
  };
60449
60452
  // 根据类型创建对应的 SDKItem 类实例
60450
60453
  var sdkItem;
60451
- // 优先通过 ID 查找现有 SDKItem,获取其 SDKItemType
60452
- var existingSDKItem = this.getSDKItem(playerItem.getInstanceId());
60453
60454
  // 如果找到了现有 SDKItem,根据 SDKItemType 创建
60454
60455
  // 将类型转换为 string 进行比较
60455
60456
  if ((existingSDKItem == null ? void 0 : existingSDKItem.type) === SDKItemType.GENERATOR) {
@@ -91886,30 +91887,6 @@ var EDITING_VIEWPORT_PADDING = 48;
91886
91887
  var EDITING_VIEWPORT_BOX_SCALE = 1.1;
91887
91888
  var AUTO_HEIGHT_EPSILON = 0.5;
91888
91889
  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
- };
91913
91890
  var HTMLOverlayManager = /*#__PURE__*/ function() {
91914
91891
  function HTMLOverlayManager(options) {
91915
91892
  var _this = this;
@@ -91982,7 +91959,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
91982
91959
  return;
91983
91960
  }
91984
91961
  if (_this.contentInteractionFrame !== undefined) {
91985
- cancelHTMLOverlayFrame(_this.contentInteractionFrame);
91962
+ cancelAnimationFrame(_this.contentInteractionFrame);
91986
91963
  _this.contentInteractionFrame = undefined;
91987
91964
  }
91988
91965
  _this.pendingContentInteractionEvent = undefined;
@@ -92043,11 +92020,11 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92043
92020
  _proto.dispose = function dispose() {
92044
92021
  var _this_state_layer;
92045
92022
  if (this.state.updateFrame !== undefined) {
92046
- cancelHTMLOverlayFrame(this.state.updateFrame);
92023
+ cancelAnimationFrame(this.state.updateFrame);
92047
92024
  this.state.updateFrame = undefined;
92048
92025
  }
92049
92026
  if (this.contentInteractionFrame !== undefined) {
92050
- cancelHTMLOverlayFrame(this.contentInteractionFrame);
92027
+ cancelAnimationFrame(this.contentInteractionFrame);
92051
92028
  this.contentInteractionFrame = undefined;
92052
92029
  }
92053
92030
  this.pendingContentInteractionEvent = undefined;
@@ -92077,7 +92054,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92077
92054
  });
92078
92055
  this.state.autoHeightCleanups.clear();
92079
92056
  this.state.autoHeightFrames.forEach(function(frame) {
92080
- cancelHTMLOverlayFrame(frame);
92057
+ cancelAnimationFrame(frame);
92081
92058
  });
92082
92059
  this.state.autoHeightFrames.clear();
92083
92060
  this.eventCleanups.forEach(function(cleanup) {
@@ -92096,9 +92073,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92096
92073
  _proto.scheduleRender = function scheduleRender() {
92097
92074
  var _this = this;
92098
92075
  if (this.state.updateFrame !== undefined) {
92099
- cancelHTMLOverlayFrame(this.state.updateFrame);
92076
+ cancelAnimationFrame(this.state.updateFrame);
92100
92077
  }
92101
- this.state.updateFrame = requestHTMLOverlayFrame(function() {
92078
+ this.state.updateFrame = requestAnimationFrame(function() {
92102
92079
  _this.state.updateFrame = undefined;
92103
92080
  _this.render();
92104
92081
  });
@@ -92107,40 +92084,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92107
92084
  this.cleanupOverlayContent(id);
92108
92085
  this.invalidateContentInteractionZones(id);
92109
92086
  };
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
- };
92144
92087
  _proto.rasterizeCard = function rasterizeCard(id, options) {
92145
92088
  return _async_to_generator(function() {
92146
92089
  var contentOverlay, capture, _ref, _options_pixelRatio, image, error;
@@ -92148,7 +92091,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92148
92091
  switch(_state.label){
92149
92092
  case 0:
92150
92093
  if (this.state.updateFrame !== undefined) {
92151
- cancelHTMLOverlayFrame(this.state.updateFrame);
92094
+ cancelAnimationFrame(this.state.updateFrame);
92152
92095
  this.state.updateFrame = undefined;
92153
92096
  }
92154
92097
  this.render();
@@ -92315,10 +92258,13 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92315
92258
  var overlay = _this.getOrCreateOverlay(item.id, parentOverlay, elements);
92316
92259
  var contentOverlay = _this.getOrCreateContentOverlay(item.id, overlay);
92317
92260
  var selectionOverlay = _this.getOrCreateSelectionOverlay(item.id, selectionLayer);
92261
+ if (!_this.state.contents.has(item.id)) {
92262
+ _this.renderOverlayHTML(item.id, contentOverlay, html);
92263
+ }
92264
+ _this.applyHTMLRootConfig(overlay, html);
92318
92265
  var offsetX = frameBox && !frameBox.isEmpty() ? frameBox.min.x : 0;
92319
92266
  var offsetY = frameBox && !frameBox.isEmpty() ? frameBox.min.y : 0;
92320
92267
  var boxStyle = getCardOverlayBoxStyle(itemBox, item.property.width, item.property.height, offsetX, offsetY, _this.isAutoScaleEnabled(item));
92321
- _this.applyHTMLRootConfig(overlay, html);
92322
92268
  overlay.style.left = boxStyle.left;
92323
92269
  overlay.style.top = boxStyle.top;
92324
92270
  overlay.style.width = boxStyle.width;
@@ -92333,12 +92279,8 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92333
92279
  selectionOverlay.style.transform = selectionBoxStyle.transform;
92334
92280
  selectionOverlay.style.transformOrigin = '0 0';
92335
92281
  _this.applyHTMLRootConfig(selectionOverlay, html);
92336
- _this.makeSelectionOverlayTransparent(selectionOverlay);
92337
92282
  _this.syncOverlaySelection(item.id, overlay, selectionOverlay);
92338
92283
  _this.syncContentScale(item.id, boxStyle.contentWidth, boxStyle.contentHeight);
92339
- if (!_this.state.contents.has(item.id)) {
92340
- _this.renderOverlayHTML(item.id, contentOverlay, html);
92341
- }
92342
92284
  _this.syncAutoHeight(item.id, _this.isAutoHeightEnabled(item));
92343
92285
  _this.syncContentInteraction(item.id);
92344
92286
  });
@@ -92578,20 +92520,14 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92578
92520
  if (this.contentInteractionFrame !== undefined) {
92579
92521
  return;
92580
92522
  }
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
- }
92523
+ this.contentInteractionFrame = requestAnimationFrame(function() {
92524
+ _this.contentInteractionFrame = undefined;
92525
+ var pendingEvent = _this.pendingContentInteractionEvent;
92526
+ _this.pendingContentInteractionEvent = undefined;
92527
+ if (pendingEvent) {
92528
+ _this.syncActiveContentInteraction(pendingEvent);
92529
+ }
92530
+ });
92595
92531
  };
92596
92532
  _proto.setActiveContentInteraction = function setActiveContentInteraction(zone) {
92597
92533
  var _this = this;
@@ -93015,20 +92951,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93015
92951
  });
93016
92952
  this.state.contents.set(id, html);
93017
92953
  };
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
- };
93032
92954
  _proto.observeContentInteractionZones = function observeContentInteractionZones(id, contentContainer) {
93033
92955
  var _this = this;
93034
92956
  var _this_state_contentInteractionZoneCleanups_get;
@@ -93088,10 +93010,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93088
93010
  });
93089
93011
  });
93090
93012
  };
93091
- _proto.makeSelectionOverlayTransparent = function makeSelectionOverlayTransparent(selectionOverlay) {
93092
- selectionOverlay.style.background = 'transparent';
93093
- selectionOverlay.style.backgroundColor = 'transparent';
93094
- };
93095
93013
  _proto.renderOverlayContent = function renderOverlayContent(overlay, content, options) {
93096
93014
  var _this = this;
93097
93015
  switch(content.kind){
@@ -93284,7 +93202,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93284
93202
  if (this.state.autoHeightFrames.has(id)) {
93285
93203
  return;
93286
93204
  }
93287
- var frame = requestHTMLOverlayFrame(function() {
93205
+ var frame = requestAnimationFrame(function() {
93288
93206
  _this.state.autoHeightFrames.delete(id);
93289
93207
  _this.measureAutoHeight(id);
93290
93208
  });
@@ -93368,7 +93286,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93368
93286
  }
93369
93287
  var frame = this.state.autoHeightFrames.get(id);
93370
93288
  if (frame !== undefined) {
93371
- cancelHTMLOverlayFrame(frame);
93289
+ cancelAnimationFrame(frame);
93372
93290
  this.state.autoHeightFrames.delete(id);
93373
93291
  }
93374
93292
  };
@@ -93386,18 +93304,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93386
93304
  if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
93387
93305
  return;
93388
93306
  }
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';
93307
+ this.options.setCardItemHeight(id, nextHeight);
93401
93308
  };
93402
93309
  _proto.getAutoHeightItemHeight = function getAutoHeightItemHeight(item, contentHeight) {
93403
93310
  if (!isCardItem(item) || this.isAutoScaleEnabled(item)) {
@@ -93483,7 +93390,7 @@ function formatCssNumber(value) {
93483
93390
  }
93484
93391
  function nextAnimationFrame() {
93485
93392
  return new Promise(function(resolve) {
93486
- requestHTMLOverlayFrame(function() {
93393
+ requestAnimationFrame(function() {
93487
93394
  resolve();
93488
93395
  });
93489
93396
  });
@@ -94052,29 +93959,12 @@ var SDK = /*#__PURE__*/ function() {
94052
93959
  bottom: HTML_CARD_EDITING_VIEWPORT_PADDING
94053
93960
  }, box);
94054
93961
  },
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;
93962
+ setCardItemHeight: function setCardItemHeight(id, height) {
94068
93963
  void _this.setItemProperty({
94069
93964
  itemId: id,
94070
93965
  type: SDKItemType.CARD,
94071
- property: {
94072
- height: height,
94073
- position: [
94074
- x,
94075
- y + deltaY
94076
- ]
94077
- }
93966
+ propertyName: 'height',
93967
+ propertyValue: height
94078
93968
  });
94079
93969
  },
94080
93970
  getSelectedItemIds: function getSelectedItemIds() {
@@ -94134,18 +94024,22 @@ var SDK = /*#__PURE__*/ function() {
94134
94024
  _proto.initPlayer = function initPlayer(mode) {
94135
94025
  var _this = this;
94136
94026
  var playerContainer = document.createElement('div');
94137
- var _ref = mode === 'editor' ? [
94138
- this._container.clientWidth,
94139
- this._container.clientHeight
94140
- ] : [
94027
+ var _ref = mode === 'template' ? [
94141
94028
  this._container.offsetWidth,
94142
94029
  this._container.offsetHeight
94030
+ ] : [
94031
+ document.documentElement.clientWidth,
94032
+ document.documentElement.clientHeight
94143
94033
  ], width = _ref[0], height = _ref[1];
94144
94034
  this._playerContainer = playerContainer;
94145
94035
  this._playerContainer.id = 'player-container';
94146
94036
  this._playerContainer.style.position = 'absolute';
94147
94037
  this._playerContainer.style.width = "" + width + "px";
94148
94038
  this._playerContainer.style.height = "" + height + "px";
94039
+ if (mode === 'editor') {
94040
+ this._playerContainer.style.left = '0px';
94041
+ this._playerContainer.style.top = '0px';
94042
+ }
94149
94043
  this._container.appendChild(playerContainer);
94150
94044
  this.player = new EFFECTS.Player({
94151
94045
  container: this._playerContainer,
@@ -94204,6 +94098,7 @@ var SDK = /*#__PURE__*/ function() {
94204
94098
  _this._gestureHandler.dispose();
94205
94099
  setTimeout(function() {
94206
94100
  return _async_to_generator(function() {
94101
+ var _this_pageData, _this_pageData1, itemExtension;
94207
94102
  return _ts_generator(this, function(_state) {
94208
94103
  switch(_state.label){
94209
94104
  case 0:
@@ -94211,12 +94106,22 @@ var SDK = /*#__PURE__*/ function() {
94211
94106
  this._pageDataUtils = new PageDataUtils(this.player, this._playerContainer, this._eventEmitter, this);
94212
94107
  this._gestureHandler = new GestureHandler(this._container);
94213
94108
  this.syncCanvasLayerOrder();
94109
+ itemExtension = {};
94110
+ (_this_pageData = this.pageData) == null ? void 0 : _this_pageData.items.forEach(function(item) {
94111
+ itemExtension[item.id] = item.getAllExtension();
94112
+ });
94214
94113
  return [
94215
94114
  4,
94216
94115
  this.runByPageData(this.pageData)
94217
94116
  ];
94218
94117
  case 1:
94219
94118
  _state.sent();
94119
+ (_this_pageData1 = this.pageData) == null ? void 0 : _this_pageData1.items.forEach(function(item) {
94120
+ var extension = itemExtension[item.id];
94121
+ if (extension) {
94122
+ item.setExtensions(extension);
94123
+ }
94124
+ });
94220
94125
  this._eventEmitter.emit('viewRebuildFinish');
94221
94126
  return [
94222
94127
  2
@@ -96298,38 +96203,6 @@ var SDK = /*#__PURE__*/ function() {
96298
96203
  return true;
96299
96204
  };
96300
96205
  /**
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
- /**
96333
96206
  * @description 创建卡片元素
96334
96207
  * @description 底层以透明 SpriteItem 形式渲染,支持 cardType 属性
96335
96208
  * @param createInfo 卡片创建信息