@vvfx/sdk 0.2.2-beta.12 → 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/config.d.ts +5 -0
- package/dist/html-overlay/manager.d.ts +12 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +170 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -27
- package/dist/index.mjs.map +1 -1
- package/dist/sdk.d.ts +24 -0
- package/dist/types.d.ts +48 -0
- package/package.json +1 -1
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.
|
|
6
|
+
* Version: v0.2.2-beta.13
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -91886,6 +91886,30 @@ var EDITING_VIEWPORT_PADDING = 48;
|
|
|
91886
91886
|
var EDITING_VIEWPORT_BOX_SCALE = 1.1;
|
|
91887
91887
|
var AUTO_HEIGHT_EPSILON = 0.5;
|
|
91888
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
|
+
};
|
|
91889
91913
|
var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
91890
91914
|
function HTMLOverlayManager(options) {
|
|
91891
91915
|
var _this = this;
|
|
@@ -91958,7 +91982,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
91958
91982
|
return;
|
|
91959
91983
|
}
|
|
91960
91984
|
if (_this.contentInteractionFrame !== undefined) {
|
|
91961
|
-
|
|
91985
|
+
cancelHTMLOverlayFrame(_this.contentInteractionFrame);
|
|
91962
91986
|
_this.contentInteractionFrame = undefined;
|
|
91963
91987
|
}
|
|
91964
91988
|
_this.pendingContentInteractionEvent = undefined;
|
|
@@ -92019,11 +92043,11 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92019
92043
|
_proto.dispose = function dispose() {
|
|
92020
92044
|
var _this_state_layer;
|
|
92021
92045
|
if (this.state.updateFrame !== undefined) {
|
|
92022
|
-
|
|
92046
|
+
cancelHTMLOverlayFrame(this.state.updateFrame);
|
|
92023
92047
|
this.state.updateFrame = undefined;
|
|
92024
92048
|
}
|
|
92025
92049
|
if (this.contentInteractionFrame !== undefined) {
|
|
92026
|
-
|
|
92050
|
+
cancelHTMLOverlayFrame(this.contentInteractionFrame);
|
|
92027
92051
|
this.contentInteractionFrame = undefined;
|
|
92028
92052
|
}
|
|
92029
92053
|
this.pendingContentInteractionEvent = undefined;
|
|
@@ -92053,7 +92077,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92053
92077
|
});
|
|
92054
92078
|
this.state.autoHeightCleanups.clear();
|
|
92055
92079
|
this.state.autoHeightFrames.forEach(function(frame) {
|
|
92056
|
-
|
|
92080
|
+
cancelHTMLOverlayFrame(frame);
|
|
92057
92081
|
});
|
|
92058
92082
|
this.state.autoHeightFrames.clear();
|
|
92059
92083
|
this.eventCleanups.forEach(function(cleanup) {
|
|
@@ -92072,9 +92096,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92072
92096
|
_proto.scheduleRender = function scheduleRender() {
|
|
92073
92097
|
var _this = this;
|
|
92074
92098
|
if (this.state.updateFrame !== undefined) {
|
|
92075
|
-
|
|
92099
|
+
cancelHTMLOverlayFrame(this.state.updateFrame);
|
|
92076
92100
|
}
|
|
92077
|
-
this.state.updateFrame =
|
|
92101
|
+
this.state.updateFrame = requestHTMLOverlayFrame(function() {
|
|
92078
92102
|
_this.state.updateFrame = undefined;
|
|
92079
92103
|
_this.render();
|
|
92080
92104
|
});
|
|
@@ -92083,6 +92107,40 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92083
92107
|
this.cleanupOverlayContent(id);
|
|
92084
92108
|
this.invalidateContentInteractionZones(id);
|
|
92085
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
|
+
};
|
|
92086
92144
|
_proto.rasterizeCard = function rasterizeCard(id, options) {
|
|
92087
92145
|
return _async_to_generator(function() {
|
|
92088
92146
|
var contentOverlay, capture, _ref, _options_pixelRatio, image, error;
|
|
@@ -92090,7 +92148,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92090
92148
|
switch(_state.label){
|
|
92091
92149
|
case 0:
|
|
92092
92150
|
if (this.state.updateFrame !== undefined) {
|
|
92093
|
-
|
|
92151
|
+
cancelHTMLOverlayFrame(this.state.updateFrame);
|
|
92094
92152
|
this.state.updateFrame = undefined;
|
|
92095
92153
|
}
|
|
92096
92154
|
this.render();
|
|
@@ -92257,13 +92315,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92257
92315
|
var overlay = _this.getOrCreateOverlay(item.id, parentOverlay, elements);
|
|
92258
92316
|
var contentOverlay = _this.getOrCreateContentOverlay(item.id, overlay);
|
|
92259
92317
|
var selectionOverlay = _this.getOrCreateSelectionOverlay(item.id, selectionLayer);
|
|
92260
|
-
if (!_this.state.contents.has(item.id)) {
|
|
92261
|
-
_this.renderOverlayHTML(item.id, contentOverlay, html);
|
|
92262
|
-
}
|
|
92263
|
-
_this.applyHTMLRootConfig(overlay, html);
|
|
92264
92318
|
var offsetX = frameBox && !frameBox.isEmpty() ? frameBox.min.x : 0;
|
|
92265
92319
|
var offsetY = frameBox && !frameBox.isEmpty() ? frameBox.min.y : 0;
|
|
92266
92320
|
var boxStyle = getCardOverlayBoxStyle(itemBox, item.property.width, item.property.height, offsetX, offsetY, _this.isAutoScaleEnabled(item));
|
|
92321
|
+
_this.applyHTMLRootConfig(overlay, html);
|
|
92267
92322
|
overlay.style.left = boxStyle.left;
|
|
92268
92323
|
overlay.style.top = boxStyle.top;
|
|
92269
92324
|
overlay.style.width = boxStyle.width;
|
|
@@ -92278,8 +92333,12 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92278
92333
|
selectionOverlay.style.transform = selectionBoxStyle.transform;
|
|
92279
92334
|
selectionOverlay.style.transformOrigin = '0 0';
|
|
92280
92335
|
_this.applyHTMLRootConfig(selectionOverlay, html);
|
|
92336
|
+
_this.makeSelectionOverlayTransparent(selectionOverlay);
|
|
92281
92337
|
_this.syncOverlaySelection(item.id, overlay, selectionOverlay);
|
|
92282
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
|
+
}
|
|
92283
92342
|
_this.syncAutoHeight(item.id, _this.isAutoHeightEnabled(item));
|
|
92284
92343
|
_this.syncContentInteraction(item.id);
|
|
92285
92344
|
});
|
|
@@ -92519,14 +92578,20 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92519
92578
|
if (this.contentInteractionFrame !== undefined) {
|
|
92520
92579
|
return;
|
|
92521
92580
|
}
|
|
92522
|
-
|
|
92523
|
-
|
|
92524
|
-
|
|
92525
|
-
|
|
92526
|
-
|
|
92527
|
-
|
|
92528
|
-
|
|
92529
|
-
|
|
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
|
+
}
|
|
92530
92595
|
};
|
|
92531
92596
|
_proto.setActiveContentInteraction = function setActiveContentInteraction(zone) {
|
|
92532
92597
|
var _this = this;
|
|
@@ -92950,6 +93015,20 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92950
93015
|
});
|
|
92951
93016
|
this.state.contents.set(id, html);
|
|
92952
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
|
+
};
|
|
92953
93032
|
_proto.observeContentInteractionZones = function observeContentInteractionZones(id, contentContainer) {
|
|
92954
93033
|
var _this = this;
|
|
92955
93034
|
var _this_state_contentInteractionZoneCleanups_get;
|
|
@@ -93009,6 +93088,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
93009
93088
|
});
|
|
93010
93089
|
});
|
|
93011
93090
|
};
|
|
93091
|
+
_proto.makeSelectionOverlayTransparent = function makeSelectionOverlayTransparent(selectionOverlay) {
|
|
93092
|
+
selectionOverlay.style.background = 'transparent';
|
|
93093
|
+
selectionOverlay.style.backgroundColor = 'transparent';
|
|
93094
|
+
};
|
|
93012
93095
|
_proto.renderOverlayContent = function renderOverlayContent(overlay, content, options) {
|
|
93013
93096
|
var _this = this;
|
|
93014
93097
|
switch(content.kind){
|
|
@@ -93201,7 +93284,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
93201
93284
|
if (this.state.autoHeightFrames.has(id)) {
|
|
93202
93285
|
return;
|
|
93203
93286
|
}
|
|
93204
|
-
var frame =
|
|
93287
|
+
var frame = requestHTMLOverlayFrame(function() {
|
|
93205
93288
|
_this.state.autoHeightFrames.delete(id);
|
|
93206
93289
|
_this.measureAutoHeight(id);
|
|
93207
93290
|
});
|
|
@@ -93285,7 +93368,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
93285
93368
|
}
|
|
93286
93369
|
var frame = this.state.autoHeightFrames.get(id);
|
|
93287
93370
|
if (frame !== undefined) {
|
|
93288
|
-
|
|
93371
|
+
cancelHTMLOverlayFrame(frame);
|
|
93289
93372
|
this.state.autoHeightFrames.delete(id);
|
|
93290
93373
|
}
|
|
93291
93374
|
};
|
|
@@ -93303,7 +93386,18 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
93303
93386
|
if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
|
|
93304
93387
|
return;
|
|
93305
93388
|
}
|
|
93306
|
-
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';
|
|
93307
93401
|
};
|
|
93308
93402
|
_proto.getAutoHeightItemHeight = function getAutoHeightItemHeight(item, contentHeight) {
|
|
93309
93403
|
if (!isCardItem(item) || this.isAutoScaleEnabled(item)) {
|
|
@@ -93389,7 +93483,7 @@ function formatCssNumber(value) {
|
|
|
93389
93483
|
}
|
|
93390
93484
|
function nextAnimationFrame() {
|
|
93391
93485
|
return new Promise(function(resolve) {
|
|
93392
|
-
|
|
93486
|
+
requestHTMLOverlayFrame(function() {
|
|
93393
93487
|
resolve();
|
|
93394
93488
|
});
|
|
93395
93489
|
});
|
|
@@ -93958,12 +94052,29 @@ var SDK = /*#__PURE__*/ function() {
|
|
|
93958
94052
|
bottom: HTML_CARD_EDITING_VIEWPORT_PADDING
|
|
93959
94053
|
}, box);
|
|
93960
94054
|
},
|
|
93961
|
-
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;
|
|
93962
94068
|
void _this.setItemProperty({
|
|
93963
94069
|
itemId: id,
|
|
93964
94070
|
type: SDKItemType.CARD,
|
|
93965
|
-
|
|
93966
|
-
|
|
94071
|
+
property: {
|
|
94072
|
+
height: height,
|
|
94073
|
+
position: [
|
|
94074
|
+
x,
|
|
94075
|
+
y + deltaY
|
|
94076
|
+
]
|
|
94077
|
+
}
|
|
93967
94078
|
});
|
|
93968
94079
|
},
|
|
93969
94080
|
getSelectedItemIds: function getSelectedItemIds() {
|
|
@@ -96187,6 +96298,38 @@ var SDK = /*#__PURE__*/ function() {
|
|
|
96187
96298
|
return true;
|
|
96188
96299
|
};
|
|
96189
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
|
+
/**
|
|
96190
96333
|
* @description 创建卡片元素
|
|
96191
96334
|
* @description 底层以透明 SpriteItem 形式渲染,支持 cardType 属性
|
|
96192
96335
|
* @param createInfo 卡片创建信息
|