@vvfx/sdk 0.2.11 → 0.2.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/html-overlay/auto-height-runtime.d.ts +2 -1
- package/dist/html-overlay/auto-height-runtime.js +14 -5
- package/dist/html-overlay/document-runtime.js +7 -2
- package/dist/html-overlay/inline-script-json.d.ts +1 -0
- package/dist/html-overlay/inline-script-json.js +8 -0
- package/dist/html-overlay/manager.d.ts +1 -0
- package/dist/html-overlay/manager.js +21 -0
- package/dist/html-overlay/runtime-context.d.ts +2 -0
- package/dist/html-overlay/runtime-context.js +16 -0
- package/dist/index.cjs +62 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +62 -8
- package/dist/index.mjs.map +1 -1
- 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.
|
|
6
|
+
* Version: v0.2.13
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { math, spec, generateGUID, SpriteComponent, TextComponent, assertExist as assertExist$1, version, VFXItem, PrecompositionManager, AssetManager, FrameComponent, glContext, CompositionComponent, Texture as Texture$1, getStandardJSON, EffectComponent, Geometry as Geometry$1, Material, Player, EventEmitter as EventEmitter$1 } from '@galacean/effects';
|
|
@@ -69602,6 +69602,10 @@ function vi(t) {
|
|
|
69602
69602
|
return false;
|
|
69603
69603
|
}
|
|
69604
69604
|
|
|
69605
|
+
function serializeInlineScriptJson(value) {
|
|
69606
|
+
return JSON.stringify(value).replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/&/g, '\\u0026').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
|
69607
|
+
}
|
|
69608
|
+
|
|
69605
69609
|
function createAutoHeightMessageListener(iframe, options) {
|
|
69606
69610
|
if (!(options == null ? void 0 : options.autoHeightId) || !options.onAutoHeight) {
|
|
69607
69611
|
return function() {
|
|
@@ -69616,7 +69620,7 @@ function createAutoHeightMessageListener(iframe, options) {
|
|
|
69616
69620
|
options.onAutoHeight == null ? void 0 : options.onAutoHeight.call(options, event.data.height);
|
|
69617
69621
|
return;
|
|
69618
69622
|
}
|
|
69619
|
-
var phase = getCardHTMLStreamRuntimePhase(event.data);
|
|
69623
|
+
var phase = options.streamRuntimeId ? getCardHTMLStreamRuntimePhase(event.data, options.streamRuntimeId) : undefined;
|
|
69620
69624
|
if (phase) {
|
|
69621
69625
|
options.onStreamRuntimePhase == null ? void 0 : options.onStreamRuntimePhase.call(options, phase);
|
|
69622
69626
|
}
|
|
@@ -69626,15 +69630,19 @@ function createAutoHeightMessageListener(iframe, options) {
|
|
|
69626
69630
|
window.removeEventListener('message', handleMessage);
|
|
69627
69631
|
};
|
|
69628
69632
|
}
|
|
69629
|
-
function getCardHTMLStreamRuntimePhase(data) {
|
|
69633
|
+
function getCardHTMLStreamRuntimePhase(data, expectedRuntimeId) {
|
|
69630
69634
|
if ((typeof data === "undefined" ? "undefined" : _type_of(data)) !== 'object' || data === null) {
|
|
69631
69635
|
return undefined;
|
|
69632
69636
|
}
|
|
69633
69637
|
var message = data;
|
|
69634
|
-
if (message.type !== 'huamei:html-stream-runtime-status' || _type_of(message.payload) !== 'object' || message.payload === null) {
|
|
69638
|
+
if (message.source !== 'vvfx-card-html-stream-runtime' || message.type !== 'huamei:html-stream-runtime-status' || _type_of(message.payload) !== 'object' || message.payload === null) {
|
|
69639
|
+
return undefined;
|
|
69640
|
+
}
|
|
69641
|
+
var payload = message.payload;
|
|
69642
|
+
if (payload.runtimeId !== expectedRuntimeId) {
|
|
69635
69643
|
return undefined;
|
|
69636
69644
|
}
|
|
69637
|
-
var phase =
|
|
69645
|
+
var phase = payload.phase;
|
|
69638
69646
|
return [
|
|
69639
69647
|
'parsing',
|
|
69640
69648
|
'draining',
|
|
@@ -69662,7 +69670,7 @@ function withCardHTMLAutoHeightBridge(html, id) {
|
|
|
69662
69670
|
if (!id) {
|
|
69663
69671
|
return html;
|
|
69664
69672
|
}
|
|
69665
|
-
var script = "\n<script data-vvfx-card-html-auto-height>\n(() => {\n const id = " +
|
|
69673
|
+
var script = "\n<script data-vvfx-card-html-auto-height>\n(() => {\n const id = " + serializeInlineScriptJson(id) + ";\n let frame = 0;\n const getNodeHeight = (node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n if (window.getComputedStyle(node).position === 'fixed') {\n return 0;\n }\n const rect = node.getBoundingClientRect();\n return rect.bottom + window.scrollY;\n }\n if (node.nodeType === Node.TEXT_NODE && node.textContent.trim()) {\n const range = document.createRange();\n range.selectNodeContents(node);\n const rects = Array.from(range.getClientRects());\n range.detach();\n return rects.reduce((height, rect) => Math.max(height, rect.bottom + window.scrollY), 0);\n }\n\n return 0;\n };\n const getContentHeight = (element) => {\n if (!element) return 0;\n return Array.from(element.childNodes).reduce((height, child) => {\n return Math.max(height, getNodeHeight(child));\n }, 0);\n };\n const getHeight = () => {\n const body = document.body;\n const root = document.documentElement;\n const contentHeight = getContentHeight(body);\n const scrollHeight = Math.max(root.scrollHeight, body ? body.scrollHeight : 0);\n return Math.ceil(contentHeight > 0 ? contentHeight : scrollHeight);\n };\n const postHeight = () => {\n frame = 0;\n window.parent.postMessage({\n source: 'vvfx-card-html-auto-height',\n id,\n height: getHeight(),\n }, '*');\n };\n const schedule = () => {\n if (frame) return;\n frame = requestAnimationFrame(postHeight);\n };\n window.addEventListener('message', (event) => {\n const message = event.data;\n if (!message || message.source !== 'vvfx-card-html-auto-height-request' || message.id !== id) {\n return;\n }\n\n schedule();\n });\n window.addEventListener('load', schedule);\n window.addEventListener('resize', schedule);\n new ResizeObserver(schedule).observe(document.documentElement);\n if (document.body) {\n new ResizeObserver(schedule).observe(document.body);\n new MutationObserver(schedule).observe(document.body, {\n attributes: true,\n childList: true,\n subtree: true,\n characterData: true,\n });\n }\n schedule();\n})();\n</script>";
|
|
69666
69674
|
if (/<\/body>/i.test(html)) {
|
|
69667
69675
|
return html.replace(/<\/body>/i, "" + script + "</body>");
|
|
69668
69676
|
}
|
|
@@ -69871,14 +69879,37 @@ function withCardHTMLAnchorNavigationGuard(html, allowAnchorNavigation) {
|
|
|
69871
69879
|
return "" + html + script;
|
|
69872
69880
|
}
|
|
69873
69881
|
|
|
69882
|
+
var runtimeSequence = 0;
|
|
69883
|
+
function createCardHTMLRuntimeId(cardId) {
|
|
69884
|
+
runtimeSequence += 1;
|
|
69885
|
+
return (cardId || 'card') + ":" + runtimeSequence;
|
|
69886
|
+
}
|
|
69887
|
+
function withCardHTMLRuntimeContext(html, runtimeId) {
|
|
69888
|
+
var script = "<script data-vvfx-card-html-runtime-context>window.__VVFX_CARD_HTML_RUNTIME_ID__=" + serializeInlineScriptJson(runtimeId) + ";</script>";
|
|
69889
|
+
if (/<head(?:\s[^>]*)?>/i.test(html)) {
|
|
69890
|
+
return html.replace(/<head(\s[^>]*)?>/i, function(match) {
|
|
69891
|
+
return "" + match + script;
|
|
69892
|
+
});
|
|
69893
|
+
}
|
|
69894
|
+
if (/<html(?:\s[^>]*)?>/i.test(html)) {
|
|
69895
|
+
return html.replace(/<html(\s[^>]*)?>/i, function(match) {
|
|
69896
|
+
return match + "<head>" + script + "</head>";
|
|
69897
|
+
});
|
|
69898
|
+
}
|
|
69899
|
+
return "<!doctype html><html><head>" + script + "</head><body>" + html + "</body></html>";
|
|
69900
|
+
}
|
|
69901
|
+
|
|
69874
69902
|
function renderDocumentContent(overlay, content, options) {
|
|
69875
69903
|
var _files_get;
|
|
69876
69904
|
var iframe = document.createElement('iframe');
|
|
69877
69905
|
var files = normalizeDocumentFiles(content.files);
|
|
69878
69906
|
var entry = normalizePath(content.entry);
|
|
69879
69907
|
var createFileUrl = createDocumentFileUrlFactory(files);
|
|
69908
|
+
var streamRuntimeId = createCardHTMLRuntimeId(options == null ? void 0 : options.autoHeightId);
|
|
69880
69909
|
var messageCleanup = createHostMessageListener(iframe, content);
|
|
69881
|
-
var autoHeightMessageCleanup = createAutoHeightMessageListener(iframe, options
|
|
69910
|
+
var autoHeightMessageCleanup = createAutoHeightMessageListener(iframe, _extends({}, options, {
|
|
69911
|
+
streamRuntimeId: streamRuntimeId
|
|
69912
|
+
}));
|
|
69882
69913
|
iframe.style.width = '100%';
|
|
69883
69914
|
iframe.style.height = '100%';
|
|
69884
69915
|
iframe.style.border = '0';
|
|
@@ -69889,7 +69920,7 @@ function renderDocumentContent(overlay, content, options) {
|
|
|
69889
69920
|
iframe.setAttribute('sandbox', content.sandbox);
|
|
69890
69921
|
}
|
|
69891
69922
|
var entryHtml = (_files_get = files.get(entry)) != null ? _files_get : '';
|
|
69892
|
-
iframe.srcdoc = withCardHTMLAutoHeightBridge(withCardHTMLAnchorNavigationGuard(withCardHTMLViewportStyle(transformHTMLDocument(entry, entryHtml, createFileUrl)), content.allowAnchorNavigation), options == null ? void 0 : options.autoHeightId);
|
|
69923
|
+
iframe.srcdoc = withCardHTMLAutoHeightBridge(withCardHTMLAnchorNavigationGuard(withCardHTMLRuntimeContext(withCardHTMLViewportStyle(transformHTMLDocument(entry, entryHtml, createFileUrl)), streamRuntimeId), content.allowAnchorNavigation), options == null ? void 0 : options.autoHeightId);
|
|
69893
69924
|
overlay.appendChild(iframe);
|
|
69894
69925
|
return function() {
|
|
69895
69926
|
messageCleanup();
|
|
@@ -70484,6 +70515,7 @@ var EDITING_VIEWPORT_PADDING = 48;
|
|
|
70484
70515
|
var EDITING_VIEWPORT_BOX_SCALE = 1.1;
|
|
70485
70516
|
var AUTO_HEIGHT_EPSILON = 0.5;
|
|
70486
70517
|
var AUTO_HEIGHT_MAX_MULTIPLIER = 32;
|
|
70518
|
+
var AUTO_HEIGHT_FEEDBACK_STEP_LIMIT = 2;
|
|
70487
70519
|
var CARD_RASTERIZE_READY_TIMEOUT = 3000;
|
|
70488
70520
|
var CARD_HTML_EVENT_MESSAGE_SOURCE = 'vvfx-card-html-event';
|
|
70489
70521
|
var requestHTMLOverlayFrame = function requestHTMLOverlayFrame(callback) {
|
|
@@ -70531,6 +70563,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
70531
70563
|
autoHeightCleanups: new Map(),
|
|
70532
70564
|
autoHeightFrames: new Map(),
|
|
70533
70565
|
autoHeightInitialHeights: new Map(),
|
|
70566
|
+
autoHeightFeedback: new Map(),
|
|
70534
70567
|
autoHeightStreamPhases: new Map()
|
|
70535
70568
|
};
|
|
70536
70569
|
this.handleContainerDoubleClick = function(event) {
|
|
@@ -70684,6 +70717,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
70684
70717
|
});
|
|
70685
70718
|
this.state.autoHeightFrames.clear();
|
|
70686
70719
|
this.state.autoHeightInitialHeights.clear();
|
|
70720
|
+
this.state.autoHeightFeedback.clear();
|
|
70687
70721
|
this.state.autoHeightStreamPhases.clear();
|
|
70688
70722
|
this.eventCleanups.forEach(function(cleanup) {
|
|
70689
70723
|
cleanup();
|
|
@@ -71982,6 +72016,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71982
72016
|
cancelHTMLOverlayFrame(frame);
|
|
71983
72017
|
this.state.autoHeightFrames.delete(id);
|
|
71984
72018
|
}
|
|
72019
|
+
this.state.autoHeightFeedback.delete(id);
|
|
71985
72020
|
};
|
|
71986
72021
|
_proto.applyAutoHeight = function applyAutoHeight(id, height) {
|
|
71987
72022
|
var item = this.options.getItems().find(function(candidate) {
|
|
@@ -72001,11 +72036,30 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
72001
72036
|
if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
|
|
72002
72037
|
return;
|
|
72003
72038
|
}
|
|
72039
|
+
if (this.isAutoHeightFeedbackLoop(id, item.property.height, nextHeight)) {
|
|
72040
|
+
return;
|
|
72041
|
+
}
|
|
72004
72042
|
this.options.setCardItemHeight(id, nextHeight, {
|
|
72005
72043
|
anchor: this.getAutoHeightAnchor(item),
|
|
72006
72044
|
previousHeight: item.property.height
|
|
72007
72045
|
});
|
|
72008
72046
|
};
|
|
72047
|
+
_proto.isAutoHeightFeedbackLoop = function isAutoHeightFeedbackLoop(id, currentHeight, nextHeight) {
|
|
72048
|
+
if (nextHeight <= currentHeight) {
|
|
72049
|
+
this.state.autoHeightFeedback.delete(id);
|
|
72050
|
+
return false;
|
|
72051
|
+
}
|
|
72052
|
+
var offset = nextHeight - currentHeight;
|
|
72053
|
+
var previous = this.state.autoHeightFeedback.get(id);
|
|
72054
|
+
var continues = previous !== undefined && Math.abs(previous.nextHeight - currentHeight) <= AUTO_HEIGHT_EPSILON && Math.abs(previous.offset - offset) <= AUTO_HEIGHT_EPSILON;
|
|
72055
|
+
var steps = continues ? previous.steps + 1 : 0;
|
|
72056
|
+
this.state.autoHeightFeedback.set(id, {
|
|
72057
|
+
nextHeight: nextHeight,
|
|
72058
|
+
offset: offset,
|
|
72059
|
+
steps: steps
|
|
72060
|
+
});
|
|
72061
|
+
return steps >= AUTO_HEIGHT_FEEDBACK_STEP_LIMIT;
|
|
72062
|
+
};
|
|
72009
72063
|
_proto.setAutoHeightStreamPhase = function setAutoHeightStreamPhase(id, phase) {
|
|
72010
72064
|
if (phase === 'parsing' || phase === 'draining' || phase === 'finalizing') {
|
|
72011
72065
|
this.state.autoHeightStreamPhases.set(id, phase);
|