@vvfx/sdk 0.2.6 → 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.6
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';
@@ -69952,6 +69952,442 @@ function syncElementStackOrder(_container, elements) {
69952
69952
  });
69953
69953
  }
69954
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
+
69955
70391
  function getCardOverlayBoxStyle(box, width, height, offsetX, offsetY, _autoScale) {
69956
70392
  if (offsetX === void 0) offsetX = 0;
69957
70393
  if (offsetY === void 0) offsetY = 0;
@@ -70347,7 +70783,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70347
70783
  _state.sent();
70348
70784
  return [
70349
70785
  4,
70350
- createCardCaptureTarget(contentOverlay, this.state.contents.get(id))
70786
+ createCardCaptureTarget(contentOverlay, this.state.contents.get(id), {
70787
+ width: options.width,
70788
+ height: options.height
70789
+ })
70351
70790
  ];
70352
70791
  case 3:
70353
70792
  capture = _state.sent();
@@ -70364,9 +70803,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70364
70803
  I.toPng(capture.target, _extends({
70365
70804
  embedFonts: true,
70366
70805
  backgroundColor: 'transparent',
70367
- dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2,
70368
- width: options.width,
70369
- height: options.height
70806
+ dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2
70370
70807
  }, options.snapdomOptions))
70371
70808
  ];
70372
70809
  case 5:
@@ -71809,52 +72246,56 @@ function waitForIframeLoad(iframe) {
71809
72246
  });
71810
72247
  });
71811
72248
  }
71812
- function createCardCaptureTarget(root, html) {
72249
+ function createCardCaptureTarget(root, html, logicalSize) {
71813
72250
  return _async_to_generator(function() {
71814
- var previewHTML, preview, isDirectIframe, directTarget, shellTarget, flattenedTarget;
72251
+ var _root_querySelector, liveDocument, liveReplica, previewHTML, preview, flattenedTarget;
71815
72252
  return _ts_generator(this, function(_state) {
71816
72253
  switch(_state.label){
71817
72254
  case 0:
71818
- previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
71819
- if (!previewHTML) return [
72255
+ liveDocument = (_root_querySelector = root.querySelector('iframe')) == null ? void 0 : _root_querySelector.contentDocument;
72256
+ if (!liveDocument) return [
71820
72257
  3,
71821
72258
  2
71822
72259
  ];
71823
72260
  return [
71824
72261
  4,
71825
- createPreviewDocumentCaptureTarget(root, previewHTML)
72262
+ createHTMLCaptureReplicaFromDocument(root.ownerDocument, liveDocument, logicalSize)
71826
72263
  ];
71827
72264
  case 1:
71828
- preview = _state.sent();
71829
- if (preview) {
71830
- isDirectIframe = root.children.length === 1 && _instanceof(root.children[0], HTMLIFrameElement);
71831
- if (isDirectIframe) {
71832
- directTarget = createDirectCaptureTarget(root, preview.target);
71833
- return [
71834
- 2,
71835
- {
71836
- target: directTarget,
71837
- cleanup: function cleanup() {
71838
- directTarget.remove();
71839
- preview.cleanup();
71840
- }
71841
- }
71842
- ];
71843
- }
71844
- shellTarget = createShellCaptureTarget(root, preview.target);
72265
+ liveReplica = _state.sent();
72266
+ if (liveReplica) {
71845
72267
  return [
71846
72268
  2,
71847
72269
  {
71848
- target: shellTarget,
71849
- cleanup: function cleanup() {
71850
- shellTarget.remove();
71851
- preview.cleanup();
71852
- }
72270
+ target: liveReplica.target,
72271
+ cleanup: liveReplica.cleanup
71853
72272
  }
71854
72273
  ];
71855
72274
  }
71856
72275
  _state.label = 2;
71857
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:
71858
72299
  flattenedTarget = createFlattenedExistingIframeTarget(root);
71859
72300
  return [
71860
72301
  2,
@@ -71912,182 +72353,6 @@ function createCardPreviewHTML(content) {
71912
72353
  }
71913
72354
  return undefined;
71914
72355
  }
71915
- function createPreviewDocumentCaptureTarget(root, html) {
71916
- return _async_to_generator(function() {
71917
- var _ref, iframe, rect, loadPromise, doc, target;
71918
- return _ts_generator(this, function(_state) {
71919
- switch(_state.label){
71920
- case 0:
71921
- iframe = root.ownerDocument.createElement('iframe');
71922
- rect = root.getBoundingClientRect();
71923
- iframe.style.position = 'fixed';
71924
- iframe.style.left = '-100000px';
71925
- iframe.style.top = '0';
71926
- iframe.style.width = "" + Math.max(1, rect.width) + "px";
71927
- iframe.style.height = "" + Math.max(1, rect.height) + "px";
71928
- iframe.style.border = '0';
71929
- iframe.style.pointerEvents = 'none';
71930
- iframe.style.opacity = '1';
71931
- iframe.style.zIndex = '-1';
71932
- loadPromise = waitForNextIframeLoad(iframe);
71933
- root.ownerDocument.body.appendChild(iframe);
71934
- iframe.srcdoc = html;
71935
- return [
71936
- 4,
71937
- loadPromise
71938
- ];
71939
- case 1:
71940
- _state.sent();
71941
- return [
71942
- 4,
71943
- waitForIframeContent(iframe)
71944
- ];
71945
- case 2:
71946
- _state.sent();
71947
- doc = iframe.contentDocument;
71948
- target = (_ref = doc == null ? void 0 : doc.body) != null ? _ref : doc == null ? void 0 : doc.documentElement;
71949
- if (!target) {
71950
- iframe.remove();
71951
- return [
71952
- 2,
71953
- undefined
71954
- ];
71955
- }
71956
- return [
71957
- 4,
71958
- waitForDocumentFonts(target.ownerDocument)
71959
- ];
71960
- case 3:
71961
- _state.sent();
71962
- return [
71963
- 4,
71964
- waitForImages(target)
71965
- ];
71966
- case 4:
71967
- _state.sent();
71968
- return [
71969
- 4,
71970
- nextAnimationFrame()
71971
- ];
71972
- case 5:
71973
- _state.sent();
71974
- return [
71975
- 2,
71976
- {
71977
- target: target,
71978
- cleanup: function cleanup() {
71979
- iframe.remove();
71980
- }
71981
- }
71982
- ];
71983
- }
71984
- });
71985
- })();
71986
- }
71987
- function waitForNextIframeLoad(iframe) {
71988
- return new Promise(function(resolve) {
71989
- iframe.addEventListener('load', function() {
71990
- resolve();
71991
- }, {
71992
- once: true
71993
- });
71994
- iframe.addEventListener('error', function() {
71995
- resolve();
71996
- }, {
71997
- once: true
71998
- });
71999
- });
72000
- }
72001
- function waitForIframeContent(iframe) {
72002
- return _async_to_generator(function() {
72003
- var start, doc;
72004
- return _ts_generator(this, function(_state) {
72005
- switch(_state.label){
72006
- case 0:
72007
- start = performance.now();
72008
- _state.label = 1;
72009
- case 1:
72010
- if (!(performance.now() - start < CARD_RASTERIZE_READY_TIMEOUT)) return [
72011
- 3,
72012
- 3
72013
- ];
72014
- doc = iframe.contentDocument;
72015
- if ((doc == null ? void 0 : doc.body) && doc.body.children.length > 0) {
72016
- return [
72017
- 2
72018
- ];
72019
- }
72020
- return [
72021
- 4,
72022
- nextAnimationFrame()
72023
- ];
72024
- case 2:
72025
- _state.sent();
72026
- return [
72027
- 3,
72028
- 1
72029
- ];
72030
- case 3:
72031
- return [
72032
- 2
72033
- ];
72034
- }
72035
- });
72036
- })();
72037
- }
72038
- function createShellCaptureTarget(root, contentTarget) {
72039
- var clone = root.cloneNode(true);
72040
- clone.style.position = 'fixed';
72041
- clone.style.left = '-100000px';
72042
- clone.style.top = '0';
72043
- clone.style.pointerEvents = 'none';
72044
- clone.style.opacity = '1';
72045
- clone.style.zIndex = '-1';
72046
- var clonedIframe = clone.querySelector('iframe');
72047
- if (clonedIframe) {
72048
- clonedIframe.replaceWith(createFlattenedContent(contentTarget, getComputedStyle(clonedIframe), root.ownerDocument));
72049
- }
72050
- root.ownerDocument.body.appendChild(clone);
72051
- return clone;
72052
- }
72053
- function createDirectCaptureTarget(root, contentTarget) {
72054
- var rect = root.getBoundingClientRect();
72055
- var frame = root.ownerDocument.createElement('div');
72056
- frame.style.position = 'fixed';
72057
- frame.style.left = '-100000px';
72058
- frame.style.top = '0';
72059
- frame.style.width = "" + Math.max(1, rect.width) + "px";
72060
- frame.style.height = "" + Math.max(1, rect.height) + "px";
72061
- frame.style.pointerEvents = 'none';
72062
- frame.style.opacity = '1';
72063
- frame.style.zIndex = '-1';
72064
- frame.style.overflow = 'hidden';
72065
- var flattenedContent = createFlattenedContent(contentTarget, getComputedStyle(contentTarget), root.ownerDocument);
72066
- flattenedContent.style.width = '100%';
72067
- flattenedContent.style.height = '100%';
72068
- frame.appendChild(flattenedContent);
72069
- root.ownerDocument.body.appendChild(frame);
72070
- return frame;
72071
- }
72072
- function createFlattenedContent(target, frameStyle, ownerDocument) {
72073
- var replacement = ownerDocument.createElement('div');
72074
- Object.assign(replacement.style, {
72075
- width: frameStyle.width,
72076
- height: frameStyle.height,
72077
- display: frameStyle.display === 'none' ? 'block' : frameStyle.display,
72078
- overflow: 'hidden',
72079
- border: frameStyle.border,
72080
- boxSizing: frameStyle.boxSizing,
72081
- background: frameStyle.background
72082
- });
72083
- Array.from(target.ownerDocument.head.children).forEach(function(child) {
72084
- replacement.appendChild(child.cloneNode(true));
72085
- });
72086
- Array.from(target.children).forEach(function(child) {
72087
- replacement.appendChild(child.cloneNode(true));
72088
- });
72089
- return replacement;
72090
- }
72091
72356
  function isMouseEventInsideRect(event, rect) {
72092
72357
  return event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
72093
72358
  }