@vvfx/sdk 0.2.5 → 0.2.7

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.7
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
  }
@@ -69927,6 +69952,442 @@ function syncElementStackOrder(_container, elements) {
69927
69952
  });
69928
69953
  }
69929
69954
 
69955
+ var CAPTURE_TIMEOUT = 5000;
69956
+ var MOTION_PROPERTIES = /^(animation|transition)(?:-|$)/i;
69957
+ var RUNTIME_SELECTOR = [
69958
+ '[data-hm-stream-runtime]',
69959
+ '[data-vvfx-card-html-auto-height]',
69960
+ '[data-vvfx-card-html-anchor-navigation-guard]',
69961
+ 'script',
69962
+ 'noscript',
69963
+ 'template'
69964
+ ].join(',');
69965
+ function captureViewportSize(logicalSize, _displayedBounds) {
69966
+ return {
69967
+ width: Math.max(1, logicalSize.width),
69968
+ height: Math.max(1, logicalSize.height)
69969
+ };
69970
+ }
69971
+ function serializeComputedCaptureStyle(style) {
69972
+ var declarations = [];
69973
+ for(var _iterator = _create_for_of_iterator_helper_loose(style), _step; !(_step = _iterator()).done;){
69974
+ var property = _step.value;
69975
+ if (MOTION_PROPERTIES.test(property)) {
69976
+ continue;
69977
+ }
69978
+ var value = style.getPropertyValue(property);
69979
+ if (!value) {
69980
+ continue;
69981
+ }
69982
+ var priority = style.getPropertyPriority(property);
69983
+ declarations.push(property + ":" + value + (priority ? "!" + priority : ''));
69984
+ }
69985
+ declarations.push('animation:none!important', 'transition:none!important');
69986
+ return declarations.join(';');
69987
+ }
69988
+ function createHTMLCaptureReplica(ownerDocument, html, logicalSize) {
69989
+ return _async_to_generator(function() {
69990
+ var size, iframe, loaded, sourceDocument, replica;
69991
+ return _ts_generator(this, function(_state) {
69992
+ switch(_state.label){
69993
+ case 0:
69994
+ size = captureViewportSize(logicalSize);
69995
+ iframe = ownerDocument.createElement('iframe');
69996
+ Object.assign(iframe.style, {
69997
+ position: 'fixed',
69998
+ left: '-100000px',
69999
+ top: '0',
70000
+ width: "" + size.width + "px",
70001
+ height: "" + size.height + "px",
70002
+ border: '0',
70003
+ pointerEvents: 'none',
70004
+ opacity: '1',
70005
+ zIndex: '-1'
70006
+ });
70007
+ iframe.srcdoc = html;
70008
+ loaded = waitForNextLoad(iframe);
70009
+ ownerDocument.body.appendChild(iframe);
70010
+ return [
70011
+ 4,
70012
+ withCaptureTimeout(loaded)
70013
+ ];
70014
+ case 1:
70015
+ _state.sent();
70016
+ sourceDocument = iframe.contentDocument;
70017
+ if (!(sourceDocument == null ? void 0 : sourceDocument.documentElement) || !sourceDocument.body) {
70018
+ iframe.remove();
70019
+ return [
70020
+ 2,
70021
+ undefined
70022
+ ];
70023
+ }
70024
+ return [
70025
+ 4,
70026
+ createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, size)
70027
+ ];
70028
+ case 2:
70029
+ replica = _state.sent();
70030
+ if (!replica) {
70031
+ iframe.remove();
70032
+ return [
70033
+ 2,
70034
+ undefined
70035
+ ];
70036
+ }
70037
+ return [
70038
+ 2,
70039
+ {
70040
+ target: replica.target,
70041
+ cleanup: function cleanup() {
70042
+ replica.cleanup();
70043
+ iframe.remove();
70044
+ }
70045
+ }
70046
+ ];
70047
+ }
70048
+ });
70049
+ })();
70050
+ }
70051
+ function createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, logicalSize) {
70052
+ return _async_to_generator(function() {
70053
+ var target;
70054
+ return _ts_generator(this, function(_state) {
70055
+ switch(_state.label){
70056
+ case 0:
70057
+ if (!sourceDocument.documentElement || !sourceDocument.body || !sourceDocument.defaultView) {
70058
+ return [
70059
+ 2,
70060
+ undefined
70061
+ ];
70062
+ }
70063
+ return [
70064
+ 4,
70065
+ withCaptureTimeout(waitForCaptureReady(sourceDocument))
70066
+ ];
70067
+ case 1:
70068
+ _state.sent();
70069
+ target = createComputedCaptureTarget(ownerDocument, sourceDocument, captureViewportSize(logicalSize));
70070
+ return [
70071
+ 2,
70072
+ {
70073
+ target: target,
70074
+ cleanup: function cleanup() {
70075
+ target.remove();
70076
+ }
70077
+ }
70078
+ ];
70079
+ }
70080
+ });
70081
+ })();
70082
+ }
70083
+ function createComputedCaptureTarget(ownerDocument, sourceDocument, size) {
70084
+ var sourceWindow = sourceDocument.defaultView;
70085
+ if (!sourceWindow) {
70086
+ throw new Error('HTML capture replica has no window');
70087
+ }
70088
+ var frame = ownerDocument.createElement('div');
70089
+ frame.setAttribute('data-vvfx-html-capture-replica', 'true');
70090
+ frame.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(sourceDocument.documentElement));
70091
+ Object.assign(frame.style, {
70092
+ position: 'fixed',
70093
+ left: '-100000px',
70094
+ top: '0',
70095
+ width: "" + size.width + "px",
70096
+ height: "" + size.height + "px",
70097
+ overflow: 'hidden',
70098
+ pointerEvents: 'none',
70099
+ opacity: '1',
70100
+ zIndex: '-1',
70101
+ transform: 'none'
70102
+ });
70103
+ appendDocumentFontSurface(frame, sourceDocument, ownerDocument);
70104
+ var sourceBody = sourceDocument.body;
70105
+ var bodyClone = sourceBody.cloneNode(true);
70106
+ bodyClone.querySelectorAll(RUNTIME_SELECTOR).forEach(function(node) {
70107
+ node.remove();
70108
+ });
70109
+ if (bodyClone.matches(RUNTIME_SELECTOR)) {
70110
+ bodyClone.replaceChildren();
70111
+ }
70112
+ frame.appendChild(bodyClone);
70113
+ ownerDocument.body.appendChild(frame);
70114
+ var sources = [].concat([
70115
+ sourceBody
70116
+ ], Array.from(sourceBody.querySelectorAll('*'))).filter(isStylableElement).filter(function(node) {
70117
+ return !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR);
70118
+ });
70119
+ var clones = [].concat([
70120
+ bodyClone
70121
+ ], Array.from(bodyClone.querySelectorAll('*'))).filter(isStylableElement).filter(function(node) {
70122
+ return !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR);
70123
+ });
70124
+ var pseudoRules = [];
70125
+ sources.forEach(function(source, index) {
70126
+ var clone = clones[index];
70127
+ if (!clone) {
70128
+ return;
70129
+ }
70130
+ clone.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(source));
70131
+ freezeViewportPosition(source, clone, sourceWindow);
70132
+ preserveLiveElementState(source, clone, ownerDocument);
70133
+ appendPseudoRule(source, clone, sourceWindow, pseudoRules, index);
70134
+ });
70135
+ if (pseudoRules.length) {
70136
+ var style = ownerDocument.createElement('style');
70137
+ style.setAttribute('data-vvfx-html-capture-pseudo', 'true');
70138
+ style.textContent = pseudoRules.join('\n');
70139
+ frame.prepend(style);
70140
+ }
70141
+ return frame;
70142
+ }
70143
+ function appendDocumentFontSurface(frame, sourceDocument, ownerDocument) {
70144
+ var _sourceDocument_defaultView;
70145
+ var fontRules = [];
70146
+ var SourceCSSFontFaceRule = (_sourceDocument_defaultView = sourceDocument.defaultView) == null ? void 0 : _sourceDocument_defaultView.CSSFontFaceRule;
70147
+ Array.from(sourceDocument.styleSheets).forEach(function(sheet) {
70148
+ try {
70149
+ Array.from(sheet.cssRules).forEach(function(rule) {
70150
+ if (SourceCSSFontFaceRule && _instanceof(rule, SourceCSSFontFaceRule)) {
70151
+ fontRules.push(rule.cssText);
70152
+ }
70153
+ });
70154
+ } catch (unused) {
70155
+ // Cross-origin font stylesheets are already loaded in the replica but cannot be read.
70156
+ }
70157
+ });
70158
+ if (!fontRules.length) {
70159
+ return;
70160
+ }
70161
+ var style = ownerDocument.createElement('style');
70162
+ style.setAttribute('data-vvfx-html-capture-fonts', 'true');
70163
+ style.textContent = fontRules.join('\n');
70164
+ frame.appendChild(style);
70165
+ }
70166
+ function isStylableElement(element) {
70167
+ return 'style' in element;
70168
+ }
70169
+ function freezeViewportPosition(source, clone, sourceWindow) {
70170
+ if (sourceWindow.getComputedStyle(source).position !== 'fixed') {
70171
+ return;
70172
+ }
70173
+ var rect = source.getBoundingClientRect();
70174
+ Object.assign(clone.style, {
70175
+ position: 'absolute',
70176
+ left: "" + rect.left + "px",
70177
+ top: "" + rect.top + "px",
70178
+ right: 'auto',
70179
+ bottom: 'auto',
70180
+ width: "" + rect.width + "px",
70181
+ height: "" + rect.height + "px"
70182
+ });
70183
+ }
70184
+ function preserveLiveElementState(source, clone, ownerDocument) {
70185
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLImageElement) && _instanceof(clone, ownerDocument.defaultView.HTMLImageElement)) {
70186
+ clone.src = source.currentSrc || source.src;
70187
+ }
70188
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLInputElement) && _instanceof(clone, ownerDocument.defaultView.HTMLInputElement)) {
70189
+ clone.value = source.value;
70190
+ clone.checked = source.checked;
70191
+ }
70192
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLTextAreaElement) && _instanceof(clone, ownerDocument.defaultView.HTMLTextAreaElement)) {
70193
+ clone.value = source.value;
70194
+ clone.textContent = source.value;
70195
+ }
70196
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLCanvasElement) && _instanceof(clone, ownerDocument.defaultView.HTMLCanvasElement)) {
70197
+ clone.width = source.width;
70198
+ clone.height = source.height;
70199
+ try {
70200
+ var _clone_getContext;
70201
+ (_clone_getContext = clone.getContext('2d')) == null ? void 0 : _clone_getContext.drawImage(source, 0, 0);
70202
+ } catch (unused) {
70203
+ // Tainted canvases remain empty; snapdom cannot legally read them either.
70204
+ }
70205
+ }
70206
+ }
70207
+ function appendPseudoRule(source, clone, sourceWindow, rules, index) {
70208
+ var attribute = "capture-" + index;
70209
+ clone.setAttribute('data-vvfx-capture-node', attribute);
70210
+ [
70211
+ '::before',
70212
+ '::after'
70213
+ ].forEach(function(pseudo) {
70214
+ var style = sourceWindow.getComputedStyle(source, pseudo);
70215
+ if (!style.content || style.content === 'none' || style.content === 'normal') {
70216
+ return;
70217
+ }
70218
+ rules.push('[data-vvfx-capture-node="' + attribute + '"]' + pseudo + "{" + serializeComputedCaptureStyle(style) + "}");
70219
+ });
70220
+ }
70221
+ function waitForCaptureReady(document) {
70222
+ return _async_to_generator(function() {
70223
+ var _document_fonts;
70224
+ return _ts_generator(this, function(_state) {
70225
+ switch(_state.label){
70226
+ case 0:
70227
+ return [
70228
+ 4,
70229
+ (_document_fonts = document.fonts) == null ? void 0 : _document_fonts.ready
70230
+ ];
70231
+ case 1:
70232
+ _state.sent();
70233
+ return [
70234
+ 4,
70235
+ Promise.all(Array.from(document.images).map(function(image) {
70236
+ return _async_to_generator(function() {
70237
+ return _ts_generator(this, function(_state) {
70238
+ switch(_state.label){
70239
+ case 0:
70240
+ _state.trys.push([
70241
+ 0,
70242
+ 4,
70243
+ ,
70244
+ 5
70245
+ ]);
70246
+ if (!!image.complete) return [
70247
+ 3,
70248
+ 2
70249
+ ];
70250
+ return [
70251
+ 4,
70252
+ new Promise(function(resolve) {
70253
+ image.addEventListener('load', function() {
70254
+ resolve();
70255
+ }, {
70256
+ once: true
70257
+ });
70258
+ image.addEventListener('error', function() {
70259
+ resolve();
70260
+ }, {
70261
+ once: true
70262
+ });
70263
+ })
70264
+ ];
70265
+ case 1:
70266
+ _state.sent();
70267
+ _state.label = 2;
70268
+ case 2:
70269
+ return [
70270
+ 4,
70271
+ image.decode == null ? void 0 : image.decode.call(image)
70272
+ ];
70273
+ case 3:
70274
+ _state.sent();
70275
+ return [
70276
+ 3,
70277
+ 5
70278
+ ];
70279
+ case 4:
70280
+ _state.sent();
70281
+ return [
70282
+ 3,
70283
+ 5
70284
+ ];
70285
+ case 5:
70286
+ return [
70287
+ 2
70288
+ ];
70289
+ }
70290
+ });
70291
+ })();
70292
+ }))
70293
+ ];
70294
+ case 2:
70295
+ _state.sent();
70296
+ return [
70297
+ 4,
70298
+ waitForStableLayout(document)
70299
+ ];
70300
+ case 3:
70301
+ _state.sent();
70302
+ return [
70303
+ 2
70304
+ ];
70305
+ }
70306
+ });
70307
+ })();
70308
+ }
70309
+ function waitForStableLayout(document) {
70310
+ return _async_to_generator(function() {
70311
+ var view, startedAt, previous, stableFrames, _ref, _ref1, _document_body, _document_body1, current;
70312
+ return _ts_generator(this, function(_state) {
70313
+ switch(_state.label){
70314
+ case 0:
70315
+ view = document.defaultView;
70316
+ if (!view) {
70317
+ return [
70318
+ 2
70319
+ ];
70320
+ }
70321
+ startedAt = performance.now();
70322
+ previous = '';
70323
+ stableFrames = 0;
70324
+ _state.label = 1;
70325
+ case 1:
70326
+ if (!(performance.now() - startedAt < CAPTURE_TIMEOUT && stableFrames < 3)) return [
70327
+ 3,
70328
+ 3
70329
+ ];
70330
+ return [
70331
+ 4,
70332
+ new Promise(function(resolve) {
70333
+ return view.requestAnimationFrame(function() {
70334
+ resolve();
70335
+ });
70336
+ })
70337
+ ];
70338
+ case 2:
70339
+ _state.sent();
70340
+ current = [
70341
+ document.documentElement.scrollWidth,
70342
+ document.documentElement.scrollHeight,
70343
+ (_ref = (_document_body = document.body) == null ? void 0 : _document_body.scrollWidth) != null ? _ref : 0,
70344
+ (_ref1 = (_document_body1 = document.body) == null ? void 0 : _document_body1.scrollHeight) != null ? _ref1 : 0,
70345
+ document.styleSheets.length,
70346
+ document.querySelectorAll('style').length
70347
+ ].join(':');
70348
+ stableFrames = current === previous ? stableFrames + 1 : 0;
70349
+ previous = current;
70350
+ return [
70351
+ 3,
70352
+ 1
70353
+ ];
70354
+ case 3:
70355
+ return [
70356
+ 2
70357
+ ];
70358
+ }
70359
+ });
70360
+ })();
70361
+ }
70362
+ function waitForNextLoad(iframe) {
70363
+ return new Promise(function(resolve) {
70364
+ iframe.addEventListener('load', function() {
70365
+ resolve();
70366
+ }, {
70367
+ once: true
70368
+ });
70369
+ iframe.addEventListener('error', function() {
70370
+ resolve();
70371
+ }, {
70372
+ once: true
70373
+ });
70374
+ });
70375
+ }
70376
+ function withCaptureTimeout(promise) {
70377
+ return new Promise(function(resolve) {
70378
+ var timer = globalThis.setTimeout(function() {
70379
+ resolve(undefined);
70380
+ }, CAPTURE_TIMEOUT);
70381
+ promise.then(function(value) {
70382
+ globalThis.clearTimeout(timer);
70383
+ resolve(value);
70384
+ }, function() {
70385
+ globalThis.clearTimeout(timer);
70386
+ resolve(undefined);
70387
+ });
70388
+ });
70389
+ }
70390
+
69930
70391
  function getCardOverlayBoxStyle(box, width, height, offsetX, offsetY, _autoScale) {
69931
70392
  if (offsetX === void 0) offsetX = 0;
69932
70393
  if (offsetY === void 0) offsetY = 0;
@@ -70073,7 +70534,8 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70073
70534
  cleanups: new Map(),
70074
70535
  autoHeightModes: new Map(),
70075
70536
  autoHeightCleanups: new Map(),
70076
- autoHeightFrames: new Map()
70537
+ autoHeightFrames: new Map(),
70538
+ autoHeightStreamPhases: new Map()
70077
70539
  };
70078
70540
  this.handleContainerDoubleClick = function(event) {
70079
70541
  var _this_state_editing;
@@ -70167,7 +70629,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70167
70629
  metaKey: event.metaKey
70168
70630
  }));
70169
70631
  };
70170
- this.isAutoHeightMessage = isCardHTMLAutoHeightMessage;
70171
70632
  }
70172
70633
  var _proto = HTMLOverlayManager.prototype;
70173
70634
  _proto.attach = function attach() {
@@ -70226,6 +70687,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70226
70687
  cancelHTMLOverlayFrame(frame);
70227
70688
  });
70228
70689
  this.state.autoHeightFrames.clear();
70690
+ this.state.autoHeightStreamPhases.clear();
70229
70691
  this.eventCleanups.forEach(function(cleanup) {
70230
70692
  cleanup();
70231
70693
  });
@@ -70321,7 +70783,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70321
70783
  _state.sent();
70322
70784
  return [
70323
70785
  4,
70324
- createCardCaptureTarget(contentOverlay, this.state.contents.get(id))
70786
+ createCardCaptureTarget(contentOverlay, this.state.contents.get(id), {
70787
+ width: options.width,
70788
+ height: options.height
70789
+ })
70325
70790
  ];
70326
70791
  case 3:
70327
70792
  capture = _state.sent();
@@ -70338,9 +70803,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70338
70803
  I.toPng(capture.target, _extends({
70339
70804
  embedFonts: true,
70340
70805
  backgroundColor: 'transparent',
70341
- dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2,
70342
- width: options.width,
70343
- height: options.height
70806
+ dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2
70344
70807
  }, options.snapdomOptions))
70345
70808
  ];
70346
70809
  case 5:
@@ -71268,6 +71731,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71268
71731
  autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
71269
71732
  onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
71270
71733
  _this.applyAutoHeight(options.id, height);
71734
+ } : undefined,
71735
+ onStreamRuntimePhase: (options == null ? void 0 : options.autoHeight) ? function(phase) {
71736
+ _this.setAutoHeightStreamPhase(options.id, phase);
71271
71737
  } : undefined
71272
71738
  }));
71273
71739
  case 'dom':
@@ -71293,6 +71759,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71293
71759
  autoHeightId: (options == null ? void 0 : options.autoHeight) ? options.id : undefined,
71294
71760
  onAutoHeight: (options == null ? void 0 : options.autoHeight) ? function(height) {
71295
71761
  _this.applyAutoHeight(options.id, height);
71762
+ } : undefined,
71763
+ onStreamRuntimePhase: (options == null ? void 0 : options.autoHeight) ? function(phase) {
71764
+ _this.setAutoHeightStreamPhase(options.id, phase);
71296
71765
  } : undefined
71297
71766
  }));
71298
71767
  }
@@ -71323,6 +71792,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71323
71792
  this.state.contents.delete(id);
71324
71793
  this.state.contentMountElements.delete(id);
71325
71794
  this.state.autoHeightModes.delete(id);
71795
+ this.state.autoHeightStreamPhases.delete(id);
71326
71796
  this.invalidateContentInteractionZones(id);
71327
71797
  (_this_state_contentInteractionZoneCleanups_get = this.state.contentInteractionZoneCleanups.get(id)) == null ? void 0 : _this_state_contentInteractionZoneCleanups_get();
71328
71798
  this.state.contentInteractionZoneCleanups.delete(id);
@@ -71344,10 +71814,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71344
71814
  return;
71345
71815
  }
71346
71816
  this.ensureAutoHeightMode(id);
71347
- if (this.state.autoHeightModes.get(id) === 'message') {
71348
- this.cleanupAutoHeight(id);
71349
- return;
71350
- }
71351
71817
  if (!this.state.autoHeightCleanups.has(id)) {
71352
71818
  this.state.autoHeightCleanups.set(id, this.createAutoHeightObserver(id));
71353
71819
  }
@@ -71394,16 +71860,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71394
71860
  var mount = this.state.contentMountElements.get(id);
71395
71861
  observeElement(mount);
71396
71862
  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
71863
  var syncIframeDocument = function syncIframeDocument() {
71408
71864
  var doc = null;
71409
71865
  try {
@@ -71414,12 +71870,6 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71414
71870
  if (!doc) {
71415
71871
  return;
71416
71872
  }
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
71873
  observeElement(doc.documentElement);
71424
71874
  observeElement(doc.body);
71425
71875
  _this.scheduleAutoHeightMeasure(id);
@@ -71486,6 +71936,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71486
71936
  }
71487
71937
  var body = doc.body;
71488
71938
  var documentElement = doc.documentElement;
71939
+ if (!documentElement) {
71940
+ return undefined;
71941
+ }
71489
71942
  var childHeight = body ? this.getChildrenNaturalHeight(body) : 0;
71490
71943
  if (childHeight > 0) {
71491
71944
  return childHeight;
@@ -71502,6 +71955,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71502
71955
  if (!includeIframes && childElement.tagName === 'IFRAME') {
71503
71956
  return height;
71504
71957
  }
71958
+ if (globalThis.getComputedStyle(childElement).position === 'fixed') {
71959
+ return height;
71960
+ }
71505
71961
  return Math.max(height, childElement.offsetTop + childElement.offsetHeight);
71506
71962
  }
71507
71963
  if (child.nodeType === Node.TEXT_NODE && ((_child_textContent = child.textContent) == null ? void 0 : _child_textContent.trim())) {
@@ -71540,6 +71996,9 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71540
71996
  return;
71541
71997
  }
71542
71998
  var nextHeight = Math.ceil(this.getAutoHeightItemHeight(item, height));
71999
+ if (this.isAutoHeightStreamActive(id) && nextHeight < item.property.height) {
72000
+ return;
72001
+ }
71543
72002
  if (Math.abs(nextHeight - item.property.height) <= AUTO_HEIGHT_EPSILON) {
71544
72003
  return;
71545
72004
  }
@@ -71548,6 +72007,16 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
71548
72007
  previousHeight: item.property.height
71549
72008
  });
71550
72009
  };
72010
+ _proto.setAutoHeightStreamPhase = function setAutoHeightStreamPhase(id, phase) {
72011
+ if (phase === 'parsing' || phase === 'draining' || phase === 'finalizing') {
72012
+ this.state.autoHeightStreamPhases.set(id, phase);
72013
+ return;
72014
+ }
72015
+ this.state.autoHeightStreamPhases.delete(id);
72016
+ };
72017
+ _proto.isAutoHeightStreamActive = function isAutoHeightStreamActive(id) {
72018
+ return this.state.autoHeightStreamPhases.has(id);
72019
+ };
71551
72020
  _proto.getAutoHeightAnchor = function getAutoHeightAnchor(item) {
71552
72021
  var _ref;
71553
72022
  var _this_options_resolveCardTypeConfig;
@@ -71777,52 +72246,56 @@ function waitForIframeLoad(iframe) {
71777
72246
  });
71778
72247
  });
71779
72248
  }
71780
- function createCardCaptureTarget(root, html) {
72249
+ function createCardCaptureTarget(root, html, logicalSize) {
71781
72250
  return _async_to_generator(function() {
71782
- var previewHTML, preview, isDirectIframe, directTarget, shellTarget, flattenedTarget;
72251
+ var _root_querySelector, liveDocument, liveReplica, previewHTML, preview, flattenedTarget;
71783
72252
  return _ts_generator(this, function(_state) {
71784
72253
  switch(_state.label){
71785
72254
  case 0:
71786
- previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
71787
- if (!previewHTML) return [
72255
+ liveDocument = (_root_querySelector = root.querySelector('iframe')) == null ? void 0 : _root_querySelector.contentDocument;
72256
+ if (!liveDocument) return [
71788
72257
  3,
71789
72258
  2
71790
72259
  ];
71791
72260
  return [
71792
72261
  4,
71793
- createPreviewDocumentCaptureTarget(root, previewHTML)
72262
+ createHTMLCaptureReplicaFromDocument(root.ownerDocument, liveDocument, logicalSize)
71794
72263
  ];
71795
72264
  case 1:
71796
- preview = _state.sent();
71797
- if (preview) {
71798
- isDirectIframe = root.children.length === 1 && _instanceof(root.children[0], HTMLIFrameElement);
71799
- if (isDirectIframe) {
71800
- directTarget = createDirectCaptureTarget(root, preview.target);
71801
- return [
71802
- 2,
71803
- {
71804
- target: directTarget,
71805
- cleanup: function cleanup() {
71806
- directTarget.remove();
71807
- preview.cleanup();
71808
- }
71809
- }
71810
- ];
71811
- }
71812
- shellTarget = createShellCaptureTarget(root, preview.target);
72265
+ liveReplica = _state.sent();
72266
+ if (liveReplica) {
71813
72267
  return [
71814
72268
  2,
71815
72269
  {
71816
- target: shellTarget,
71817
- cleanup: function cleanup() {
71818
- shellTarget.remove();
71819
- preview.cleanup();
71820
- }
72270
+ target: liveReplica.target,
72271
+ cleanup: liveReplica.cleanup
71821
72272
  }
71822
72273
  ];
71823
72274
  }
71824
72275
  _state.label = 2;
71825
72276
  case 2:
72277
+ previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
72278
+ if (!previewHTML) return [
72279
+ 3,
72280
+ 4
72281
+ ];
72282
+ return [
72283
+ 4,
72284
+ createHTMLCaptureReplica(root.ownerDocument, previewHTML, logicalSize)
72285
+ ];
72286
+ case 3:
72287
+ preview = _state.sent();
72288
+ if (preview) {
72289
+ return [
72290
+ 2,
72291
+ {
72292
+ target: preview.target,
72293
+ cleanup: preview.cleanup
72294
+ }
72295
+ ];
72296
+ }
72297
+ _state.label = 4;
72298
+ case 4:
71826
72299
  flattenedTarget = createFlattenedExistingIframeTarget(root);
71827
72300
  return [
71828
72301
  2,
@@ -71880,182 +72353,6 @@ function createCardPreviewHTML(content) {
71880
72353
  }
71881
72354
  return undefined;
71882
72355
  }
71883
- function createPreviewDocumentCaptureTarget(root, html) {
71884
- return _async_to_generator(function() {
71885
- var _ref, iframe, rect, loadPromise, doc, target;
71886
- return _ts_generator(this, function(_state) {
71887
- switch(_state.label){
71888
- case 0:
71889
- iframe = root.ownerDocument.createElement('iframe');
71890
- rect = root.getBoundingClientRect();
71891
- iframe.style.position = 'fixed';
71892
- iframe.style.left = '-100000px';
71893
- iframe.style.top = '0';
71894
- iframe.style.width = "" + Math.max(1, rect.width) + "px";
71895
- iframe.style.height = "" + Math.max(1, rect.height) + "px";
71896
- iframe.style.border = '0';
71897
- iframe.style.pointerEvents = 'none';
71898
- iframe.style.opacity = '1';
71899
- iframe.style.zIndex = '-1';
71900
- loadPromise = waitForNextIframeLoad(iframe);
71901
- root.ownerDocument.body.appendChild(iframe);
71902
- iframe.srcdoc = html;
71903
- return [
71904
- 4,
71905
- loadPromise
71906
- ];
71907
- case 1:
71908
- _state.sent();
71909
- return [
71910
- 4,
71911
- waitForIframeContent(iframe)
71912
- ];
71913
- case 2:
71914
- _state.sent();
71915
- doc = iframe.contentDocument;
71916
- target = (_ref = doc == null ? void 0 : doc.body) != null ? _ref : doc == null ? void 0 : doc.documentElement;
71917
- if (!target) {
71918
- iframe.remove();
71919
- return [
71920
- 2,
71921
- undefined
71922
- ];
71923
- }
71924
- return [
71925
- 4,
71926
- waitForDocumentFonts(target.ownerDocument)
71927
- ];
71928
- case 3:
71929
- _state.sent();
71930
- return [
71931
- 4,
71932
- waitForImages(target)
71933
- ];
71934
- case 4:
71935
- _state.sent();
71936
- return [
71937
- 4,
71938
- nextAnimationFrame()
71939
- ];
71940
- case 5:
71941
- _state.sent();
71942
- return [
71943
- 2,
71944
- {
71945
- target: target,
71946
- cleanup: function cleanup() {
71947
- iframe.remove();
71948
- }
71949
- }
71950
- ];
71951
- }
71952
- });
71953
- })();
71954
- }
71955
- function waitForNextIframeLoad(iframe) {
71956
- return new Promise(function(resolve) {
71957
- iframe.addEventListener('load', function() {
71958
- resolve();
71959
- }, {
71960
- once: true
71961
- });
71962
- iframe.addEventListener('error', function() {
71963
- resolve();
71964
- }, {
71965
- once: true
71966
- });
71967
- });
71968
- }
71969
- function waitForIframeContent(iframe) {
71970
- return _async_to_generator(function() {
71971
- var start, doc;
71972
- return _ts_generator(this, function(_state) {
71973
- switch(_state.label){
71974
- case 0:
71975
- start = performance.now();
71976
- _state.label = 1;
71977
- case 1:
71978
- if (!(performance.now() - start < CARD_RASTERIZE_READY_TIMEOUT)) return [
71979
- 3,
71980
- 3
71981
- ];
71982
- doc = iframe.contentDocument;
71983
- if ((doc == null ? void 0 : doc.body) && doc.body.children.length > 0) {
71984
- return [
71985
- 2
71986
- ];
71987
- }
71988
- return [
71989
- 4,
71990
- nextAnimationFrame()
71991
- ];
71992
- case 2:
71993
- _state.sent();
71994
- return [
71995
- 3,
71996
- 1
71997
- ];
71998
- case 3:
71999
- return [
72000
- 2
72001
- ];
72002
- }
72003
- });
72004
- })();
72005
- }
72006
- function createShellCaptureTarget(root, contentTarget) {
72007
- var clone = root.cloneNode(true);
72008
- clone.style.position = 'fixed';
72009
- clone.style.left = '-100000px';
72010
- clone.style.top = '0';
72011
- clone.style.pointerEvents = 'none';
72012
- clone.style.opacity = '1';
72013
- clone.style.zIndex = '-1';
72014
- var clonedIframe = clone.querySelector('iframe');
72015
- if (clonedIframe) {
72016
- clonedIframe.replaceWith(createFlattenedContent(contentTarget, getComputedStyle(clonedIframe), root.ownerDocument));
72017
- }
72018
- root.ownerDocument.body.appendChild(clone);
72019
- return clone;
72020
- }
72021
- function createDirectCaptureTarget(root, contentTarget) {
72022
- var rect = root.getBoundingClientRect();
72023
- var frame = root.ownerDocument.createElement('div');
72024
- frame.style.position = 'fixed';
72025
- frame.style.left = '-100000px';
72026
- frame.style.top = '0';
72027
- frame.style.width = "" + Math.max(1, rect.width) + "px";
72028
- frame.style.height = "" + Math.max(1, rect.height) + "px";
72029
- frame.style.pointerEvents = 'none';
72030
- frame.style.opacity = '1';
72031
- frame.style.zIndex = '-1';
72032
- frame.style.overflow = 'hidden';
72033
- var flattenedContent = createFlattenedContent(contentTarget, getComputedStyle(contentTarget), root.ownerDocument);
72034
- flattenedContent.style.width = '100%';
72035
- flattenedContent.style.height = '100%';
72036
- frame.appendChild(flattenedContent);
72037
- root.ownerDocument.body.appendChild(frame);
72038
- return frame;
72039
- }
72040
- function createFlattenedContent(target, frameStyle, ownerDocument) {
72041
- var replacement = ownerDocument.createElement('div');
72042
- Object.assign(replacement.style, {
72043
- width: frameStyle.width,
72044
- height: frameStyle.height,
72045
- display: frameStyle.display === 'none' ? 'block' : frameStyle.display,
72046
- overflow: 'hidden',
72047
- border: frameStyle.border,
72048
- boxSizing: frameStyle.boxSizing,
72049
- background: frameStyle.background
72050
- });
72051
- Array.from(target.ownerDocument.head.children).forEach(function(child) {
72052
- replacement.appendChild(child.cloneNode(true));
72053
- });
72054
- Array.from(target.children).forEach(function(child) {
72055
- replacement.appendChild(child.cloneNode(true));
72056
- });
72057
- return replacement;
72058
- }
72059
72356
  function isMouseEventInsideRect(event, rect) {
72060
72357
  return event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
72061
72358
  }