@vvfx/sdk 0.2.5 → 0.2.6
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 +3 -0
- package/dist/html-overlay/manager.d.ts +2 -1
- package/dist/index.cjs +58 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,8 +11,11 @@ export type CardHTMLAutoHeightRequest = {
|
|
|
11
11
|
export type CardHTMLAutoHeightOptions = {
|
|
12
12
|
autoHeightId?: string;
|
|
13
13
|
onAutoHeight?: (height: number) => void;
|
|
14
|
+
onStreamRuntimePhase?: (phase: CardHTMLStreamRuntimePhase) => void;
|
|
14
15
|
};
|
|
16
|
+
export type CardHTMLStreamRuntimePhase = 'parsing' | 'draining' | 'complete' | 'finalizing' | 'disposed' | 'error';
|
|
15
17
|
export declare function createAutoHeightMessageListener(iframe: HTMLIFrameElement, options?: CardHTMLAutoHeightOptions): CardHTMLRenderCleanup;
|
|
18
|
+
export declare function getCardHTMLStreamRuntimePhase(data: unknown): CardHTMLStreamRuntimePhase | undefined;
|
|
16
19
|
export declare function isCardHTMLAutoHeightMessage(data: unknown, id: string): data is CardHTMLAutoHeightMessage;
|
|
17
20
|
export declare function requestCardHTMLAutoHeight(iframe: HTMLIFrameElement, id: string): void;
|
|
18
21
|
export declare function withCardHTMLAutoHeightBridge(html: string, id?: string): string;
|
|
@@ -133,9 +133,10 @@ export declare class HTMLOverlayManager {
|
|
|
133
133
|
private getChildrenNaturalHeight;
|
|
134
134
|
private cleanupAutoHeight;
|
|
135
135
|
private applyAutoHeight;
|
|
136
|
+
private setAutoHeightStreamPhase;
|
|
137
|
+
private isAutoHeightStreamActive;
|
|
136
138
|
private getAutoHeightAnchor;
|
|
137
139
|
private getAutoHeightItemHeight;
|
|
138
|
-
private isAutoHeightMessage;
|
|
139
140
|
private isAutoHeightEnabled;
|
|
140
141
|
private isAutoScaleEnabled;
|
|
141
142
|
}
|
package/dist/index.cjs
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.6
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -69616,16 +69616,41 @@ function createAutoHeightMessageListener(iframe, options) {
|
|
|
69616
69616
|
};
|
|
69617
69617
|
}
|
|
69618
69618
|
var handleMessage = function handleMessage(event) {
|
|
69619
|
-
if (event.source !== iframe.contentWindow
|
|
69619
|
+
if (event.source !== iframe.contentWindow) {
|
|
69620
69620
|
return;
|
|
69621
69621
|
}
|
|
69622
|
-
|
|
69622
|
+
if (isCardHTMLAutoHeightMessage(event.data, options.autoHeightId)) {
|
|
69623
|
+
options.onAutoHeight == null ? void 0 : options.onAutoHeight.call(options, event.data.height);
|
|
69624
|
+
return;
|
|
69625
|
+
}
|
|
69626
|
+
var phase = getCardHTMLStreamRuntimePhase(event.data);
|
|
69627
|
+
if (phase) {
|
|
69628
|
+
options.onStreamRuntimePhase == null ? void 0 : options.onStreamRuntimePhase.call(options, phase);
|
|
69629
|
+
}
|
|
69623
69630
|
};
|
|
69624
69631
|
window.addEventListener('message', handleMessage);
|
|
69625
69632
|
return function() {
|
|
69626
69633
|
window.removeEventListener('message', handleMessage);
|
|
69627
69634
|
};
|
|
69628
69635
|
}
|
|
69636
|
+
function getCardHTMLStreamRuntimePhase(data) {
|
|
69637
|
+
if ((typeof data === "undefined" ? "undefined" : _type_of(data)) !== 'object' || data === null) {
|
|
69638
|
+
return undefined;
|
|
69639
|
+
}
|
|
69640
|
+
var message = data;
|
|
69641
|
+
if (message.type !== 'huamei:html-stream-runtime-status' || _type_of(message.payload) !== 'object' || message.payload === null) {
|
|
69642
|
+
return undefined;
|
|
69643
|
+
}
|
|
69644
|
+
var phase = message.payload.phase;
|
|
69645
|
+
return [
|
|
69646
|
+
'parsing',
|
|
69647
|
+
'draining',
|
|
69648
|
+
'complete',
|
|
69649
|
+
'finalizing',
|
|
69650
|
+
'disposed',
|
|
69651
|
+
'error'
|
|
69652
|
+
].includes(String(phase)) ? phase : undefined;
|
|
69653
|
+
}
|
|
69629
69654
|
function isCardHTMLAutoHeightMessage(data, id) {
|
|
69630
69655
|
if ((typeof data === "undefined" ? "undefined" : _type_of(data)) !== 'object' || data === null) {
|
|
69631
69656
|
return false;
|
|
@@ -69644,7 +69669,7 @@ function withCardHTMLAutoHeightBridge(html, id) {
|
|
|
69644
69669
|
if (!id) {
|
|
69645
69670
|
return html;
|
|
69646
69671
|
}
|
|
69647
|
-
var script = "\n<script data-vvfx-card-html-auto-height>\n(() => {\n const id = " + JSON.stringify(id) + ";\n let frame = 0;\n const getNodeHeight = (node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\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>";
|
|
69672
|
+
var script = "\n<script data-vvfx-card-html-auto-height>\n(() => {\n const id = " + JSON.stringify(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>";
|
|
69648
69673
|
if (/<\/body>/i.test(html)) {
|
|
69649
69674
|
return html.replace(/<\/body>/i, "" + script + "</body>");
|
|
69650
69675
|
}
|
|
@@ -70074,7 +70099,8 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
70074
70099
|
cleanups: new Map(),
|
|
70075
70100
|
autoHeightModes: new Map(),
|
|
70076
70101
|
autoHeightCleanups: new Map(),
|
|
70077
|
-
autoHeightFrames: new Map()
|
|
70102
|
+
autoHeightFrames: new Map(),
|
|
70103
|
+
autoHeightStreamPhases: new Map()
|
|
70078
70104
|
};
|
|
70079
70105
|
this.handleContainerDoubleClick = function(event) {
|
|
70080
70106
|
var _this_state_editing;
|
|
@@ -70168,7 +70194,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
70168
70194
|
metaKey: event.metaKey
|
|
70169
70195
|
}));
|
|
70170
70196
|
};
|
|
70171
|
-
this.isAutoHeightMessage = isCardHTMLAutoHeightMessage;
|
|
70172
70197
|
}
|
|
70173
70198
|
var _proto = HTMLOverlayManager.prototype;
|
|
70174
70199
|
_proto.attach = function attach() {
|
|
@@ -70227,6 +70252,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
70227
70252
|
cancelHTMLOverlayFrame(frame);
|
|
70228
70253
|
});
|
|
70229
70254
|
this.state.autoHeightFrames.clear();
|
|
70255
|
+
this.state.autoHeightStreamPhases.clear();
|
|
70230
70256
|
this.eventCleanups.forEach(function(cleanup) {
|
|
70231
70257
|
cleanup();
|
|
70232
70258
|
});
|
|
@@ -71269,6 +71295,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71269
71295
|
autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
|
|
71270
71296
|
onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
|
|
71271
71297
|
_this.applyAutoHeight(options.id, height);
|
|
71298
|
+
} : undefined,
|
|
71299
|
+
onStreamRuntimePhase: (options == null ? void 0 : options.autoHeight) ? function(phase) {
|
|
71300
|
+
_this.setAutoHeightStreamPhase(options.id, phase);
|
|
71272
71301
|
} : undefined
|
|
71273
71302
|
}));
|
|
71274
71303
|
case 'dom':
|
|
@@ -71294,6 +71323,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71294
71323
|
autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
|
|
71295
71324
|
onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
|
|
71296
71325
|
_this.applyAutoHeight(options.id, height);
|
|
71326
|
+
} : undefined,
|
|
71327
|
+
onStreamRuntimePhase: (options == null ? void 0 : options.autoHeight) ? function(phase) {
|
|
71328
|
+
_this.setAutoHeightStreamPhase(options.id, phase);
|
|
71297
71329
|
} : undefined
|
|
71298
71330
|
}));
|
|
71299
71331
|
}
|
|
@@ -71324,6 +71356,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71324
71356
|
this.state.contents.delete(id);
|
|
71325
71357
|
this.state.contentMountElements.delete(id);
|
|
71326
71358
|
this.state.autoHeightModes.delete(id);
|
|
71359
|
+
this.state.autoHeightStreamPhases.delete(id);
|
|
71327
71360
|
this.invalidateContentInteractionZones(id);
|
|
71328
71361
|
(_this_state_contentInteractionZoneCleanups_get = this.state.contentInteractionZoneCleanups.get(id)) == null ? void 0 : _this_state_contentInteractionZoneCleanups_get();
|
|
71329
71362
|
this.state.contentInteractionZoneCleanups.delete(id);
|
|
@@ -71345,10 +71378,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71345
71378
|
return;
|
|
71346
71379
|
}
|
|
71347
71380
|
this.ensureAutoHeightMode(id);
|
|
71348
|
-
if (this.state.autoHeightModes.get(id) === 'message') {
|
|
71349
|
-
this.cleanupAutoHeight(id);
|
|
71350
|
-
return;
|
|
71351
|
-
}
|
|
71352
71381
|
if (!this.state.autoHeightCleanups.has(id)) {
|
|
71353
71382
|
this.state.autoHeightCleanups.set(id, this.createAutoHeightObserver(id));
|
|
71354
71383
|
}
|
|
@@ -71395,16 +71424,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71395
71424
|
var mount = this.state.contentMountElements.get(id);
|
|
71396
71425
|
observeElement(mount);
|
|
71397
71426
|
mount == null ? void 0 : mount.querySelectorAll('iframe').forEach(function(iframe) {
|
|
71398
|
-
var handleAutoHeightMessage = function handleAutoHeightMessage(event) {
|
|
71399
|
-
if (event.source !== iframe.contentWindow || !_this.isAutoHeightMessage(event.data, id)) {
|
|
71400
|
-
return;
|
|
71401
|
-
}
|
|
71402
|
-
_this.applyAutoHeight(id, event.data.height);
|
|
71403
|
-
};
|
|
71404
|
-
window.addEventListener('message', handleAutoHeightMessage);
|
|
71405
|
-
cleanupFns.push(function() {
|
|
71406
|
-
window.removeEventListener('message', handleAutoHeightMessage);
|
|
71407
|
-
});
|
|
71408
71427
|
var syncIframeDocument = function syncIframeDocument() {
|
|
71409
71428
|
var doc = null;
|
|
71410
71429
|
try {
|
|
@@ -71415,12 +71434,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71415
71434
|
if (!doc) {
|
|
71416
71435
|
return;
|
|
71417
71436
|
}
|
|
71418
|
-
doc.documentElement.style.height = 'auto';
|
|
71419
|
-
doc.documentElement.style.minHeight = '0';
|
|
71420
|
-
if (doc.body) {
|
|
71421
|
-
doc.body.style.height = 'auto';
|
|
71422
|
-
doc.body.style.minHeight = '0';
|
|
71423
|
-
}
|
|
71424
71437
|
observeElement(doc.documentElement);
|
|
71425
71438
|
observeElement(doc.body);
|
|
71426
71439
|
_this.scheduleAutoHeightMeasure(id);
|
|
@@ -71487,6 +71500,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71487
71500
|
}
|
|
71488
71501
|
var body = doc.body;
|
|
71489
71502
|
var documentElement = doc.documentElement;
|
|
71503
|
+
if (!documentElement) {
|
|
71504
|
+
return undefined;
|
|
71505
|
+
}
|
|
71490
71506
|
var childHeight = body ? this.getChildrenNaturalHeight(body) : 0;
|
|
71491
71507
|
if (childHeight > 0) {
|
|
71492
71508
|
return childHeight;
|
|
@@ -71503,6 +71519,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71503
71519
|
if (!includeIframes && childElement.tagName === 'IFRAME') {
|
|
71504
71520
|
return height;
|
|
71505
71521
|
}
|
|
71522
|
+
if (globalThis.getComputedStyle(childElement).position === 'fixed') {
|
|
71523
|
+
return height;
|
|
71524
|
+
}
|
|
71506
71525
|
return Math.max(height, childElement.offsetTop + childElement.offsetHeight);
|
|
71507
71526
|
}
|
|
71508
71527
|
if (child.nodeType === Node.TEXT_NODE && ((_child_textContent = child.textContent) == null ? void 0 : _child_textContent.trim())) {
|
|
@@ -71541,6 +71560,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71541
71560
|
return;
|
|
71542
71561
|
}
|
|
71543
71562
|
var nextHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
|
|
71563
|
+
if (this.isAutoHeightStreamActive(id) && nextHeight < item.property.height) {
|
|
71564
|
+
return;
|
|
71565
|
+
}
|
|
71544
71566
|
if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
|
|
71545
71567
|
return;
|
|
71546
71568
|
}
|
|
@@ -71549,6 +71571,16 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
|
|
|
71549
71571
|
previousHeight: item.property.height
|
|
71550
71572
|
});
|
|
71551
71573
|
};
|
|
71574
|
+
_proto.setAutoHeightStreamPhase = function setAutoHeightStreamPhase(id, phase) {
|
|
71575
|
+
if (phase === 'parsing' || phase === 'draining' || phase === 'finalizing') {
|
|
71576
|
+
this.state.autoHeightStreamPhases.set(id, phase);
|
|
71577
|
+
return;
|
|
71578
|
+
}
|
|
71579
|
+
this.state.autoHeightStreamPhases.delete(id);
|
|
71580
|
+
};
|
|
71581
|
+
_proto.isAutoHeightStreamActive = function isAutoHeightStreamActive(id) {
|
|
71582
|
+
return this.state.autoHeightStreamPhases.has(id);
|
|
71583
|
+
};
|
|
71552
71584
|
_proto.getAutoHeightAnchor = function getAutoHeightAnchor(item) {
|
|
71553
71585
|
var _ref;
|
|
71554
71586
|
var _this_options_resolveCardTypeConfig;
|