@vvfx/sdk 0.2.12 → 0.2.14
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/runtime-context.d.ts +2 -0
- package/dist/html-overlay/runtime-context.js +16 -0
- package/dist/index.cjs +39 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +39 -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.14
|
|
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();
|