@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/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.5
6
+ * Version: v0.2.6
7
7
  */
8
8
 
9
9
  import { spec, math, 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';
@@ -69615,16 +69615,41 @@ function createAutoHeightMessageListener(iframe, options) {
69615
69615
  };
69616
69616
  }
69617
69617
  var handleMessage = function handleMessage(event) {
69618
- if (event.source !== iframe.contentWindow || !isCardHTMLAutoHeightMessage(event.data, options.autoHeightId)) {
69618
+ if (event.source !== iframe.contentWindow) {
69619
69619
  return;
69620
69620
  }
69621
- options.onAutoHeight == null ? void 0 : options.onAutoHeight.call(options, event.data.height);
69621
+ if (isCardHTMLAutoHeightMessage(event.data, options.autoHeightId)) {
69622
+ options.onAutoHeight == null ? void 0 : options.onAutoHeight.call(options, event.data.height);
69623
+ return;
69624
+ }
69625
+ var phase = getCardHTMLStreamRuntimePhase(event.data);
69626
+ if (phase) {
69627
+ options.onStreamRuntimePhase == null ? void 0 : options.onStreamRuntimePhase.call(options, phase);
69628
+ }
69622
69629
  };
69623
69630
  window.addEventListener('message', handleMessage);
69624
69631
  return function() {
69625
69632
  window.removeEventListener('message', handleMessage);
69626
69633
  };
69627
69634
  }
69635
+ function getCardHTMLStreamRuntimePhase(data) {
69636
+ if ((typeof data === "undefined" ? "undefined" : _type_of(data)) !== 'object' || data === null) {
69637
+ return undefined;
69638
+ }
69639
+ var message = data;
69640
+ if (message.type !== 'huamei:html-stream-runtime-status' || _type_of(message.payload) !== 'object' || message.payload === null) {
69641
+ return undefined;
69642
+ }
69643
+ var phase = message.payload.phase;
69644
+ return [
69645
+ 'parsing',
69646
+ 'draining',
69647
+ 'complete',
69648
+ 'finalizing',
69649
+ 'disposed',
69650
+ 'error'
69651
+ ].includes(String(phase)) ? phase : undefined;
69652
+ }
69628
69653
  function isCardHTMLAutoHeightMessage(data, id) {
69629
69654
  if ((typeof data === "undefined" ? "undefined" : _type_of(data)) !== 'object' || data === null) {
69630
69655
  return false;
@@ -69643,7 +69668,7 @@ function withCardHTMLAutoHeightBridge(html, id) {
69643
69668
  if (!id) {
69644
69669
  return html;
69645
69670
  }
69646
- 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>";
69671
+ 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>";
69647
69672
  if (/<\/body>/i.test(html)) {
69648
69673
  return html.replace(/<\/body>/i, "" + script + "</body>");
69649
69674
  }
@@ -70073,7 +70098,8 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70073
70098
  cleanups: new Map(),
70074
70099
  autoHeightModes: new Map(),
70075
70100
  autoHeightCleanups: new Map(),
70076
- autoHeightFrames: new Map()
70101
+ autoHeightFrames: new Map(),
70102
+ autoHeightStreamPhases: new Map()
70077
70103
  };
70078
70104
  this.handleContainerDoubleClick = function(event) {
70079
70105
  var _this_state_editing;
@@ -70167,7 +70193,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70167
70193
  metaKey: event.metaKey
70168
70194
  }));
70169
70195
  };
70170
- this.isAutoHeightMessage = isCardHTMLAutoHeightMessage;
70171
70196
  }
70172
70197
  var _proto = HTMLOverlayManager.prototype;
70173
70198
  _proto.attach = function attach() {
@@ -70226,6 +70251,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70226
70251
  cancelHTMLOverlayFrame(frame);
70227
70252
  });
70228
70253
  this.state.autoHeightFrames.clear();
70254
+ this.state.autoHeightStreamPhases.clear();
70229
70255
  this.eventCleanups.forEach(function(cleanup) {
70230
70256
  cleanup();
70231
70257
  });
@@ -71268,6 +71294,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71268
71294
  autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
71269
71295
  onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
71270
71296
  _this.applyAutoHeight(options.id, height);
71297
+ } : undefined,
71298
+ onStreamRuntimePhase: (options == null ? void 0 : options.autoHeight) ? function(phase) {
71299
+ _this.setAutoHeightStreamPhase(options.id, phase);
71271
71300
  } : undefined
71272
71301
  }));
71273
71302
  case 'dom':
@@ -71293,6 +71322,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71293
71322
  autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
71294
71323
  onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
71295
71324
  _this.applyAutoHeight(options.id, height);
71325
+ } : undefined,
71326
+ onStreamRuntimePhase: (options == null ? void 0 : options.autoHeight) ? function(phase) {
71327
+ _this.setAutoHeightStreamPhase(options.id, phase);
71296
71328
  } : undefined
71297
71329
  }));
71298
71330
  }
@@ -71323,6 +71355,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71323
71355
  this.state.contents.delete(id);
71324
71356
  this.state.contentMountElements.delete(id);
71325
71357
  this.state.autoHeightModes.delete(id);
71358
+ this.state.autoHeightStreamPhases.delete(id);
71326
71359
  this.invalidateContentInteractionZones(id);
71327
71360
  (_this_state_contentInteractionZoneCleanups_get = this.state.contentInteractionZoneCleanups.get(id)) == null ? void 0 : _this_state_contentInteractionZoneCleanups_get();
71328
71361
  this.state.contentInteractionZoneCleanups.delete(id);
@@ -71344,10 +71377,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71344
71377
  return;
71345
71378
  }
71346
71379
  this.ensureAutoHeightMode(id);
71347
- if (this.state.autoHeightModes.get(id) === 'message') {
71348
- this.cleanupAutoHeight(id);
71349
- return;
71350
- }
71351
71380
  if (!this.state.autoHeightCleanups.has(id)) {
71352
71381
  this.state.autoHeightCleanups.set(id, this.createAutoHeightObserver(id));
71353
71382
  }
@@ -71394,16 +71423,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71394
71423
  var mount = this.state.contentMountElements.get(id);
71395
71424
  observeElement(mount);
71396
71425
  mount == null ? void 0 : mount.querySelectorAll('iframe').forEach(function(iframe) {
71397
- var handleAutoHeightMessage = function handleAutoHeightMessage(event) {
71398
- if (event.source !== iframe.contentWindow || !_this.isAutoHeightMessage(event.data, id)) {
71399
- return;
71400
- }
71401
- _this.applyAutoHeight(id, event.data.height);
71402
- };
71403
- window.addEventListener('message', handleAutoHeightMessage);
71404
- cleanupFns.push(function() {
71405
- window.removeEventListener('message', handleAutoHeightMessage);
71406
- });
71407
71426
  var syncIframeDocument = function syncIframeDocument() {
71408
71427
  var doc = null;
71409
71428
  try {
@@ -71414,12 +71433,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71414
71433
  if (!doc) {
71415
71434
  return;
71416
71435
  }
71417
- doc.documentElement.style.height = 'auto';
71418
- doc.documentElement.style.minHeight = '0';
71419
- if (doc.body) {
71420
- doc.body.style.height = 'auto';
71421
- doc.body.style.minHeight = '0';
71422
- }
71423
71436
  observeElement(doc.documentElement);
71424
71437
  observeElement(doc.body);
71425
71438
  _this.scheduleAutoHeightMeasure(id);
@@ -71486,6 +71499,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71486
71499
  }
71487
71500
  var body = doc.body;
71488
71501
  var documentElement = doc.documentElement;
71502
+ if (!documentElement) {
71503
+ return undefined;
71504
+ }
71489
71505
  var childHeight = body ? this.getChildrenNaturalHeight(body) : 0;
71490
71506
  if (childHeight > 0) {
71491
71507
  return childHeight;
@@ -71502,6 +71518,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71502
71518
  if (!includeIframes && childElement.tagName === 'IFRAME') {
71503
71519
  return height;
71504
71520
  }
71521
+ if (globalThis.getComputedStyle(childElement).position === 'fixed') {
71522
+ return height;
71523
+ }
71505
71524
  return Math.max(height, childElement.offsetTop + childElement.offsetHeight);
71506
71525
  }
71507
71526
  if (child.nodeType === Node.TEXT_NODE && ((_child_textContent = child.textContent) == null ? void 0 : _child_textContent.trim())) {
@@ -71540,6 +71559,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71540
71559
  return;
71541
71560
  }
71542
71561
  var nextHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
71562
+ if (this.isAutoHeightStreamActive(id) && nextHeight < item.property.height) {
71563
+ return;
71564
+ }
71543
71565
  if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
71544
71566
  return;
71545
71567
  }
@@ -71548,6 +71570,16 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71548
71570
  previousHeight: item.property.height
71549
71571
  });
71550
71572
  };
71573
+ _proto.setAutoHeightStreamPhase = function setAutoHeightStreamPhase(id, phase) {
71574
+ if (phase === 'parsing' || phase === 'draining' || phase === 'finalizing') {
71575
+ this.state.autoHeightStreamPhases.set(id, phase);
71576
+ return;
71577
+ }
71578
+ this.state.autoHeightStreamPhases.delete(id);
71579
+ };
71580
+ _proto.isAutoHeightStreamActive = function isAutoHeightStreamActive(id) {
71581
+ return this.state.autoHeightStreamPhases.has(id);
71582
+ };
71551
71583
  _proto.getAutoHeightAnchor = function getAutoHeightAnchor(item) {
71552
71584
  var _ref;
71553
71585
  var _this_options_resolveCardTypeConfig;