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

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 @@
1
+ export declare function withCardHTMLAnchorNavigationGuard(html: string, allowAnchorNavigation?: boolean): string;
package/dist/index.js 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.17
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -60414,6 +60414,8 @@ var PageDataUtils = /*#__PURE__*/ function() {
60414
60414
  }
60415
60415
  }
60416
60416
  var isLocked = (_this_getSDKItem = this.getSDKItem(playerItem.getInstanceId())) == null ? void 0 : _this_getSDKItem.isLocked;
60417
+ // 优先通过 ID 查找现有 SDKItem,获取其 SDKItemType
60418
+ var existingSDKItem = this.getSDKItem(playerItem.getInstanceId());
60417
60419
  // 创建基础选项
60418
60420
  var baseOptions = {
60419
60421
  id: playerItem.getInstanceId(),
@@ -60425,12 +60427,11 @@ var PageDataUtils = /*#__PURE__*/ function() {
60425
60427
  endBehavior: playerItem.endBehavior,
60426
60428
  visible: isVisible,
60427
60429
  isLocked: isLocked,
60428
- isCoreEditable: isCoreEditable
60430
+ isCoreEditable: isCoreEditable,
60431
+ extension: existingSDKItem == null ? void 0 : existingSDKItem.extension
60429
60432
  };
60430
60433
  // 根据类型创建对应的 SDKItem 类实例
60431
60434
  var sdkItem;
60432
- // 优先通过 ID 查找现有 SDKItem,获取其 SDKItemType
60433
- var existingSDKItem = this.getSDKItem(playerItem.getInstanceId());
60434
60435
  // 如果找到了现有 SDKItem,根据 SDKItemType 创建
60435
60436
  // 将类型转换为 string 进行比较
60436
60437
  if ((existingSDKItem == null ? void 0 : existingSDKItem.type) === SDKItemType.GENERATOR) {
@@ -91690,6 +91691,17 @@ function withCardHTMLViewportStyle(html) {
91690
91691
  return "<!doctype html><html><head>" + viewportStyle + "</head><body>" + html + "</body></html>";
91691
91692
  }
91692
91693
 
91694
+ function withCardHTMLAnchorNavigationGuard(html, allowAnchorNavigation) {
91695
+ if (allowAnchorNavigation === true) {
91696
+ return html;
91697
+ }
91698
+ var script = "\n<script data-vvfx-card-html-anchor-navigation-guard>\n(() => {\n document.addEventListener('click', event => {\n const target = event.target;\n if (!(target instanceof Element)) {\n return;\n }\n\n const anchor = target.closest('a[href]');\n if (!anchor) {\n return;\n }\n\n event.preventDefault();\n }, true);\n})();\n</script>";
91699
+ if (/<\/body>/i.test(html)) {
91700
+ return html.replace(/<\/body>/i, "" + script + "</body>");
91701
+ }
91702
+ return "" + html + script;
91703
+ }
91704
+
91693
91705
  function renderDocumentContent(overlay, content, options) {
91694
91706
  var _files_get;
91695
91707
  var iframe = document.createElement('iframe');
@@ -91708,7 +91720,7 @@ function renderDocumentContent(overlay, content, options) {
91708
91720
  iframe.setAttribute('sandbox', content.sandbox);
91709
91721
  }
91710
91722
  var entryHtml = (_files_get = files.get(entry)) != null ? _files_get : '';
91711
- iframe.srcdoc = withCardHTMLAutoHeightBridge(withCardHTMLViewportStyle(transformHTMLDocument(entry, entryHtml, createFileUrl)), options == null ? void 0 : options.autoHeightId);
91723
+ iframe.srcdoc = withCardHTMLAutoHeightBridge(withCardHTMLAnchorNavigationGuard(withCardHTMLViewportStyle(transformHTMLDocument(entry, entryHtml, createFileUrl)), content.allowAnchorNavigation), options == null ? void 0 : options.autoHeightId);
91712
91724
  overlay.appendChild(iframe);
91713
91725
  return function() {
91714
91726
  messageCleanup();
@@ -93087,7 +93099,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
93087
93099
  entry: 'index.html',
93088
93100
  files: {
93089
93101
  'index.html': content.html
93090
- }
93102
+ },
93103
+ allowAnchorNavigation: content.allowAnchorNavigation,
93104
+ sandbox: content.sandbox
93091
93105
  }, {
93092
93106
  autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
93093
93107
  onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
@@ -94115,18 +94129,22 @@ var SDK = /*#__PURE__*/ function() {
94115
94129
  _proto.initPlayer = function initPlayer(mode) {
94116
94130
  var _this = this;
94117
94131
  var playerContainer = document.createElement('div');
94118
- var _ref = mode === 'editor' ? [
94119
- this._container.clientWidth,
94120
- this._container.clientHeight
94121
- ] : [
94132
+ var _ref = mode === 'template' ? [
94122
94133
  this._container.offsetWidth,
94123
94134
  this._container.offsetHeight
94135
+ ] : [
94136
+ document.documentElement.clientWidth,
94137
+ document.documentElement.clientHeight
94124
94138
  ], width = _ref[0], height = _ref[1];
94125
94139
  this._playerContainer = playerContainer;
94126
94140
  this._playerContainer.id = 'player-container';
94127
94141
  this._playerContainer.style.position = 'absolute';
94128
94142
  this._playerContainer.style.width = "" + width + "px";
94129
94143
  this._playerContainer.style.height = "" + height + "px";
94144
+ if (mode === 'editor') {
94145
+ this._playerContainer.style.left = '0px';
94146
+ this._playerContainer.style.top = '0px';
94147
+ }
94130
94148
  this._container.appendChild(playerContainer);
94131
94149
  this.player = new Player({
94132
94150
  container: this._playerContainer,
@@ -94185,6 +94203,7 @@ var SDK = /*#__PURE__*/ function() {
94185
94203
  _this._gestureHandler.dispose();
94186
94204
  setTimeout(function() {
94187
94205
  return _async_to_generator(function() {
94206
+ var itemExtension, _this_pageData, _this_pageData1, createInfos;
94188
94207
  return _ts_generator(this, function(_state) {
94189
94208
  switch(_state.label){
94190
94209
  case 0:
@@ -94192,12 +94211,40 @@ var SDK = /*#__PURE__*/ function() {
94192
94211
  this._pageDataUtils = new PageDataUtils(this.player, this._playerContainer, this._eventEmitter, this);
94193
94212
  this._gestureHandler = new GestureHandler(this._container);
94194
94213
  this.syncCanvasLayerOrder();
94214
+ itemExtension = {};
94215
+ if (!(SDK.config.mode === 'template')) return [
94216
+ 3,
94217
+ 2
94218
+ ];
94219
+ (_this_pageData = this.pageData) == null ? void 0 : _this_pageData.items.forEach(function(item) {
94220
+ itemExtension[item.id] = item.getAllExtension();
94221
+ });
94195
94222
  return [
94196
94223
  4,
94197
94224
  this.runByPageData(this.pageData)
94198
94225
  ];
94199
94226
  case 1:
94200
94227
  _state.sent();
94228
+ (_this_pageData1 = this.pageData) == null ? void 0 : _this_pageData1.items.forEach(function(item) {
94229
+ var extension = itemExtension[item.id];
94230
+ if (extension) {
94231
+ item.setExtensions(extension);
94232
+ }
94233
+ });
94234
+ return [
94235
+ 3,
94236
+ 4
94237
+ ];
94238
+ case 2:
94239
+ createInfos = this.getItemCreateInfos();
94240
+ return [
94241
+ 4,
94242
+ this.runByCreateInfos(createInfos)
94243
+ ];
94244
+ case 3:
94245
+ _state.sent();
94246
+ _state.label = 4;
94247
+ case 4:
94201
94248
  this._eventEmitter.emit('viewRebuildFinish');
94202
94249
  return [
94203
94250
  2
@@ -95047,6 +95094,55 @@ var SDK = /*#__PURE__*/ function() {
95047
95094
  });
95048
95095
  }).call(this);
95049
95096
  };
95097
+ _proto.runByCreateInfos = function runByCreateInfos(createInfos) {
95098
+ return _async_to_generator(function() {
95099
+ var _this__pageData_activeData_view, _this__pageData_activeData_view1, viewSize, scene, targetViewProperty;
95100
+ return _ts_generator(this, function(_state) {
95101
+ switch(_state.label){
95102
+ case 0:
95103
+ assertExist$1(this._pageData, 'You must call SDK#run() first');
95104
+ this._pageData.property.zoom = 1;
95105
+ this._pageData.property.translation = [
95106
+ 0,
95107
+ 0
95108
+ ];
95109
+ this._pageDataUtils.init();
95110
+ return [
95111
+ 4,
95112
+ this._gestureHandler.init(this._pageDataUtils, this._eventEmitter)
95113
+ ];
95114
+ case 1:
95115
+ _state.sent();
95116
+ viewSize = [
95117
+ this._playerContainer.offsetWidth,
95118
+ this._playerContainer.offsetHeight
95119
+ ];
95120
+ scene = getBasicScene(viewSize);
95121
+ targetViewProperty = this.getViewProperty((_this__pageData_activeData_view = this._pageData.activeData.view) != null ? _this__pageData_activeData_view : 0);
95122
+ if (targetViewProperty) {
95123
+ targetViewProperty.scene = scene;
95124
+ }
95125
+ return [
95126
+ 4,
95127
+ this._pageDataUtils.loadScene((_this__pageData_activeData_view1 = this._pageData.activeData.view) != null ? _this__pageData_activeData_view1 : 0)
95128
+ ];
95129
+ case 2:
95130
+ _state.sent();
95131
+ return [
95132
+ 4,
95133
+ this.addItemByCreateInfos(createInfos)
95134
+ ];
95135
+ case 3:
95136
+ _state.sent();
95137
+ this._pageDataUtils.refreshPageTime(this._pageData.time);
95138
+ this._eventEmitter.emit('pageDataChange', this.pageData);
95139
+ return [
95140
+ 2
95141
+ ];
95142
+ }
95143
+ });
95144
+ }).call(this);
95145
+ };
95050
95146
  _proto.reloadPageDataByScene = function reloadPageDataByScene(scene) {
95051
95147
  return _async_to_generator(function() {
95052
95148
  var _ref, _this__pageData_activeData_view, _ref1, _ref2, _loadScene_compositions_find, _this_player_getCompositions_, _this_player_getCompositions_1, loadScene, response, error;
@@ -95741,7 +95837,11 @@ var SDK = /*#__PURE__*/ function() {
95741
95837
  return item.id;
95742
95838
  })) != null ? _ref : [];
95743
95839
  ids.forEach(function(id) {
95744
- var createInfo = _this._pageDataUtils.getItemCreateInfo(id, true);
95840
+ var _this__pageDataUtils_getItemCreateInfo;
95841
+ var _this_pageData_items_find, _this_pageData;
95842
+ var createInfo = (_this__pageDataUtils_getItemCreateInfo = _this._pageDataUtils.getItemCreateInfo(id, true)) != null ? _this__pageDataUtils_getItemCreateInfo : (_this_pageData = _this.pageData) == null ? void 0 : (_this_pageData_items_find = _this_pageData.items.find(function(item) {
95843
+ return item.id === id;
95844
+ })) == null ? void 0 : _this_pageData_items_find.toCreateInfo(true);
95745
95845
  if (createInfo) {
95746
95846
  createInfos.push(createInfo);
95747
95847
  }