@vvfx/sdk 0.2.2-beta.3 → 0.2.2-beta.4
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 +8 -0
- package/dist/html-overlay/manager.d.ts +5 -0
- package/dist/index.js +62 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -22
- package/dist/index.mjs.map +1 -1
- package/dist/sdk.d.ts +13 -0
- package/dist/types.d.ts +0 -16
- package/package.json +2 -2
- package/dist/html-overlay/auto-height-runtime.test.d.ts +0 -1
- package/dist/html-overlay/manager.test.d.ts +0 -1
- package/dist/html-overlay/overlay-transform.test.d.ts +0 -1
package/dist/config.d.ts
CHANGED
|
@@ -143,6 +143,14 @@ export type CardTypeConfig = {
|
|
|
143
143
|
* @description 卡片类型对应的运行时 HTML 渲染配置;函数不会进入序列化数据,恢复时由 cardType 动态解析。
|
|
144
144
|
*/
|
|
145
145
|
html?: CardTypeHTMLResolver;
|
|
146
|
+
/**
|
|
147
|
+
* @description 是否根据 HTML 挂载内容的自然高度自动更新卡片高度
|
|
148
|
+
*/
|
|
149
|
+
autoHeight?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* @description HTML 内容是否跟随卡片 scale 缩放,关闭后 HTML 按最终显示尺寸重新布局
|
|
152
|
+
*/
|
|
153
|
+
autoScale?: boolean;
|
|
146
154
|
};
|
|
147
155
|
/**
|
|
148
156
|
* @description 卡片元素参数配置
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Box2 } from '../math';
|
|
2
2
|
import { type SnapdomOptions } from '@zumer/snapdom';
|
|
3
|
+
import type { CardTypeConfig } from '../config';
|
|
3
4
|
import type { EventEmitter } from '../shared';
|
|
4
5
|
import type { SDKEvents } from '../sdk';
|
|
5
6
|
import { type SDKItem } from '../sdk-item';
|
|
@@ -26,6 +27,7 @@ type HTMLOverlayManagerOptions = {
|
|
|
26
27
|
viewportFit: (box: Box2) => void;
|
|
27
28
|
setCardItemHeight: (id: string, height: number) => void;
|
|
28
29
|
resolveCardHTML: (item: SDKItem) => CardHTML | undefined;
|
|
30
|
+
resolveCardTypeConfig: (item: SDKItem) => CardTypeConfig | undefined;
|
|
29
31
|
};
|
|
30
32
|
export declare class HTMLOverlayManager {
|
|
31
33
|
private options;
|
|
@@ -35,6 +37,7 @@ export declare class HTMLOverlayManager {
|
|
|
35
37
|
attach(): void;
|
|
36
38
|
dispose(): void;
|
|
37
39
|
scheduleRender(): void;
|
|
40
|
+
invalidateCardHTML(id: string): void;
|
|
38
41
|
rasterizeCard(id: string, options: CardRasterizeOptions): Promise<string | undefined>;
|
|
39
42
|
private initEvents;
|
|
40
43
|
private initDOMEvents;
|
|
@@ -78,5 +81,7 @@ export declare class HTMLOverlayManager {
|
|
|
78
81
|
private applyAutoHeight;
|
|
79
82
|
private getAutoHeightItemHeight;
|
|
80
83
|
private isAutoHeightMessage;
|
|
84
|
+
private isAutoHeightEnabled;
|
|
85
|
+
private isAutoScaleEnabled;
|
|
81
86
|
}
|
|
82
87
|
export {};
|
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.
|
|
6
|
+
* Version: v0.2.2-beta.4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
@@ -25162,7 +25162,7 @@ var ItemOrderAction = /*#__PURE__*/ function(ItemOrderAction) {
|
|
|
25162
25162
|
function CardItem(options) {
|
|
25163
25163
|
var _this;
|
|
25164
25164
|
var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
25165
|
-
var _options_property, _options_property1, _options_property2, _options_property3, _options_property4, _options_property5
|
|
25165
|
+
var _options_property, _options_property1, _options_property2, _options_property3, _options_property4, _options_property5;
|
|
25166
25166
|
_this = BaseItem.call(this, options) || this, /**
|
|
25167
25167
|
* @description 元素类型
|
|
25168
25168
|
*/ _this.type = SDKItemType.CARD;
|
|
@@ -25183,9 +25183,7 @@ var ItemOrderAction = /*#__PURE__*/ function(ItemOrderAction) {
|
|
|
25183
25183
|
1,
|
|
25184
25184
|
1
|
|
25185
25185
|
],
|
|
25186
|
-
cardType: (_ref5 = (_options_property5 = options.property) == null ? void 0 : _options_property5.cardType) != null ? _ref5 : 'unknown'
|
|
25187
|
-
autoHeight: (_options_property6 = options.property) == null ? void 0 : _options_property6.autoHeight,
|
|
25188
|
-
autoScale: (_options_property7 = options.property) == null ? void 0 : _options_property7.autoScale
|
|
25186
|
+
cardType: (_ref5 = (_options_property5 = options.property) == null ? void 0 : _options_property5.cardType) != null ? _ref5 : 'unknown'
|
|
25189
25187
|
};
|
|
25190
25188
|
return _this;
|
|
25191
25189
|
}
|
|
@@ -63165,7 +63163,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
|
|
|
63165
63163
|
var _cardInfo_name = cardInfo.name, name = _cardInfo_name === void 0 ? '卡片' : _cardInfo_name, _cardInfo_property = cardInfo.property, width = _cardInfo_property.width, height = _cardInfo_property.height, _cardInfo_property_scale = _cardInfo_property.scale, scale = _cardInfo_property_scale === void 0 ? [
|
|
63166
63164
|
1,
|
|
63167
63165
|
1
|
|
63168
|
-
] : _cardInfo_property_scale, cardType = _cardInfo_property.cardType, tmp = _cardInfo_property.rotation, sourceRotation = tmp === void 0 ? 0 : tmp, sourcePosition = _cardInfo_property.position,
|
|
63166
|
+
] : _cardInfo_property_scale, cardType = _cardInfo_property.cardType, tmp = _cardInfo_property.rotation, sourceRotation = tmp === void 0 ? 0 : tmp, sourcePosition = _cardInfo_property.position, parentId = cardInfo.parentId, _cardInfo_id = cardInfo.id, id = _cardInfo_id === void 0 ? generateGUID() : _cardInfo_id, extension = cardInfo.extension;
|
|
63169
63167
|
// 校验 cardType 是否已在配置中注册
|
|
63170
63168
|
var registeredTypes = SDK.config.itemConfig.cardConfig.cardTypes.map(function(t) {
|
|
63171
63169
|
return t.type;
|
|
@@ -63214,9 +63212,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
|
|
|
63214
63212
|
width: width,
|
|
63215
63213
|
height: height,
|
|
63216
63214
|
scale: [].concat(scale),
|
|
63217
|
-
cardType: cardType
|
|
63218
|
-
autoHeight: autoHeight,
|
|
63219
|
-
autoScale: autoScale
|
|
63215
|
+
cardType: cardType
|
|
63220
63216
|
},
|
|
63221
63217
|
extension: extension
|
|
63222
63218
|
});
|
|
@@ -83204,10 +83200,10 @@ var BaseConfig = {
|
|
|
83204
83200
|
},
|
|
83205
83201
|
cardConfig: {
|
|
83206
83202
|
backgroundColor: [
|
|
83207
|
-
|
|
83208
|
-
|
|
83209
|
-
|
|
83210
|
-
0
|
|
83203
|
+
1,
|
|
83204
|
+
1,
|
|
83205
|
+
1,
|
|
83206
|
+
0
|
|
83211
83207
|
],
|
|
83212
83208
|
cardTypes: []
|
|
83213
83209
|
}
|
|
@@ -92037,6 +92033,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92037
92033
|
_this.render();
|
|
92038
92034
|
});
|
|
92039
92035
|
};
|
|
92036
|
+
_proto.invalidateCardHTML = function invalidateCardHTML(id) {
|
|
92037
|
+
this.cleanupOverlayContent(id);
|
|
92038
|
+
};
|
|
92040
92039
|
_proto.rasterizeCard = function rasterizeCard(id, options) {
|
|
92041
92040
|
return _async_to_generator(function() {
|
|
92042
92041
|
var contentOverlay, capture, _ref, _options_pixelRatio, image, error;
|
|
@@ -92189,12 +92188,12 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92189
92188
|
var frameBox = frameId ? _this.options.getViewBoxById(frameId) : undefined;
|
|
92190
92189
|
var overlay = _this.getOrCreateOverlay(item.id, parentOverlay, elements);
|
|
92191
92190
|
var contentOverlay = _this.getOrCreateContentOverlay(item.id, overlay);
|
|
92192
|
-
if (
|
|
92191
|
+
if (!_this.state.contents.has(item.id)) {
|
|
92193
92192
|
_this.renderOverlayHTML(item.id, contentOverlay, html);
|
|
92194
92193
|
}
|
|
92195
92194
|
var offsetX = frameBox && !frameBox.isEmpty() ? frameBox.min.x : 0;
|
|
92196
92195
|
var offsetY = frameBox && !frameBox.isEmpty() ? frameBox.min.y : 0;
|
|
92197
|
-
var boxStyle = getCardOverlayBoxStyle(itemBox, item.property.width, item.property.height, offsetX, offsetY, item
|
|
92196
|
+
var boxStyle = getCardOverlayBoxStyle(itemBox, item.property.width, item.property.height, offsetX, offsetY, _this.isAutoScaleEnabled(item));
|
|
92198
92197
|
overlay.style.left = boxStyle.left;
|
|
92199
92198
|
overlay.style.top = boxStyle.top;
|
|
92200
92199
|
overlay.style.width = boxStyle.width;
|
|
@@ -92202,7 +92201,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92202
92201
|
overlay.style.transform = boxStyle.transform;
|
|
92203
92202
|
overlay.style.transformOrigin = '0 0';
|
|
92204
92203
|
_this.syncContentScale(item.id, boxStyle.contentWidth, boxStyle.contentHeight);
|
|
92205
|
-
_this.syncAutoHeight(item.id, item
|
|
92204
|
+
_this.syncAutoHeight(item.id, _this.isAutoHeightEnabled(item));
|
|
92206
92205
|
_this.syncContentInteraction(item.id);
|
|
92207
92206
|
});
|
|
92208
92207
|
elements.forEach(function(_overlay, id) {
|
|
@@ -92566,7 +92565,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92566
92565
|
});
|
|
92567
92566
|
var contentCleanup = this.renderOverlayContent(shell.contentContainer, html.content, {
|
|
92568
92567
|
id: id,
|
|
92569
|
-
autoHeight:
|
|
92568
|
+
autoHeight: this.isAutoHeightEnabled(item)
|
|
92570
92569
|
});
|
|
92571
92570
|
this.state.cleanups.set(id, function() {
|
|
92572
92571
|
contentCleanup == null ? void 0 : contentCleanup();
|
|
@@ -92770,7 +92769,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92770
92769
|
var item = this.options.getItems().find(function(candidate) {
|
|
92771
92770
|
return candidate.id === id;
|
|
92772
92771
|
});
|
|
92773
|
-
if (!
|
|
92772
|
+
if (!this.isAutoHeightEnabled(item)) {
|
|
92774
92773
|
this.cleanupAutoHeight(id);
|
|
92775
92774
|
return;
|
|
92776
92775
|
}
|
|
@@ -92852,7 +92851,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92852
92851
|
var item = this.options.getItems().find(function(candidate) {
|
|
92853
92852
|
return candidate.id === id;
|
|
92854
92853
|
});
|
|
92855
|
-
if (!isCardItem(item) || item
|
|
92854
|
+
if (!isCardItem(item) || !this.isAutoHeightEnabled(item)) {
|
|
92856
92855
|
return;
|
|
92857
92856
|
}
|
|
92858
92857
|
if (!Number.isFinite(height) || height <= 0) {
|
|
@@ -92865,7 +92864,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92865
92864
|
this.options.setCardItemHeight(id, nextHeight);
|
|
92866
92865
|
};
|
|
92867
92866
|
_proto.getAutoHeightItemHeight = function getAutoHeightItemHeight(item, contentHeight) {
|
|
92868
|
-
if (!isCardItem(item) || item
|
|
92867
|
+
if (!isCardItem(item) || this.isAutoScaleEnabled(item)) {
|
|
92869
92868
|
return contentHeight;
|
|
92870
92869
|
}
|
|
92871
92870
|
var scaleOverlay = this.state.contentScaleElements.get(item.id);
|
|
@@ -92875,6 +92874,17 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
92875
92874
|
}
|
|
92876
92875
|
return contentHeight / displayedHeight * item.property.height;
|
|
92877
92876
|
};
|
|
92877
|
+
_proto.isAutoHeightEnabled = function isAutoHeightEnabled(item) {
|
|
92878
|
+
var _this_options_resolveCardTypeConfig;
|
|
92879
|
+
return isCardItem(item) && ((_this_options_resolveCardTypeConfig = this.options.resolveCardTypeConfig(item)) == null ? void 0 : _this_options_resolveCardTypeConfig.autoHeight) === true;
|
|
92880
|
+
};
|
|
92881
|
+
_proto.isAutoScaleEnabled = function isAutoScaleEnabled(item) {
|
|
92882
|
+
var _this_options_resolveCardTypeConfig;
|
|
92883
|
+
if (!isCardItem(item)) {
|
|
92884
|
+
return true;
|
|
92885
|
+
}
|
|
92886
|
+
return ((_this_options_resolveCardTypeConfig = this.options.resolveCardTypeConfig(item)) == null ? void 0 : _this_options_resolveCardTypeConfig.autoScale) !== false;
|
|
92887
|
+
};
|
|
92878
92888
|
return HTMLOverlayManager;
|
|
92879
92889
|
}();
|
|
92880
92890
|
function waitForCardCaptureReady(root) {
|
|
@@ -93481,6 +93491,9 @@ var SDK = /*#__PURE__*/ function() {
|
|
|
93481
93491
|
},
|
|
93482
93492
|
resolveCardHTML: function resolveCardHTML(item) {
|
|
93483
93493
|
return isCardItem(item) ? _this.resolveCardHTML(item) : undefined;
|
|
93494
|
+
},
|
|
93495
|
+
resolveCardTypeConfig: function resolveCardTypeConfig(item) {
|
|
93496
|
+
return isCardItem(item) ? _this.resolveCardTypeConfig(item) : undefined;
|
|
93484
93497
|
}
|
|
93485
93498
|
});
|
|
93486
93499
|
this._htmlOverlayManager.attach();
|
|
@@ -95624,10 +95637,37 @@ var SDK = /*#__PURE__*/ function() {
|
|
|
95624
95637
|
* @returns HTML 渲染配置
|
|
95625
95638
|
*/ _proto.resolveCardHTML = function resolveCardHTML(item) {
|
|
95626
95639
|
var _cardTypeConfig_html;
|
|
95627
|
-
var cardTypeConfig =
|
|
95640
|
+
var cardTypeConfig = this.resolveCardTypeConfig(item);
|
|
95641
|
+
return cardTypeConfig == null ? void 0 : (_cardTypeConfig_html = cardTypeConfig.html) == null ? void 0 : _cardTypeConfig_html.call(cardTypeConfig, item);
|
|
95642
|
+
};
|
|
95643
|
+
/**
|
|
95644
|
+
* @description 按 cardType 从注册表解析卡片类型配置。
|
|
95645
|
+
* @param item 卡片元素
|
|
95646
|
+
* @returns 卡片类型配置
|
|
95647
|
+
*/ _proto.resolveCardTypeConfig = function resolveCardTypeConfig(item) {
|
|
95648
|
+
return SDK.config.itemConfig.cardConfig.cardTypes.find(function(t) {
|
|
95628
95649
|
return t.type === item.cardType;
|
|
95629
95650
|
});
|
|
95630
|
-
|
|
95651
|
+
};
|
|
95652
|
+
/**
|
|
95653
|
+
* @description 重新解析并挂载指定卡片的 HTML 内容。
|
|
95654
|
+
* @description 当 inline/document 内容依赖 extension 或外部状态变化时,可调用此方法刷新 DOM。
|
|
95655
|
+
* @param id 卡片元素 ID
|
|
95656
|
+
* @returns 是否成功触发刷新
|
|
95657
|
+
*/ _proto.refreshCardHTML = function refreshCardHTML(id) {
|
|
95658
|
+
var _this__htmlOverlayManager, _this__htmlOverlayManager1;
|
|
95659
|
+
var item = this.getSDKItem(id);
|
|
95660
|
+
if (!isCardItem(item)) {
|
|
95661
|
+
console.warn('CardItem "' + id + '" not found.');
|
|
95662
|
+
return false;
|
|
95663
|
+
}
|
|
95664
|
+
if (!this.resolveCardHTML(item)) {
|
|
95665
|
+
console.warn('CardItem "' + id + '" has no registered HTML renderer.');
|
|
95666
|
+
return false;
|
|
95667
|
+
}
|
|
95668
|
+
(_this__htmlOverlayManager = this._htmlOverlayManager) == null ? void 0 : _this__htmlOverlayManager.invalidateCardHTML(id);
|
|
95669
|
+
(_this__htmlOverlayManager1 = this._htmlOverlayManager) == null ? void 0 : _this__htmlOverlayManager1.scheduleRender();
|
|
95670
|
+
return true;
|
|
95631
95671
|
};
|
|
95632
95672
|
/**
|
|
95633
95673
|
* @description 创建卡片元素
|