@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.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
6
+ * Version: v0.2.7
7
7
  */
8
8
 
9
9
  'use strict';
@@ -69953,6 +69953,442 @@ function syncElementStackOrder(_container, elements) {
69953
69953
  });
69954
69954
  }
69955
69955
 
69956
+ var CAPTURE_TIMEOUT = 5000;
69957
+ var MOTION_PROPERTIES = /^(animation|transition)(?:-|$)/i;
69958
+ var RUNTIME_SELECTOR = [
69959
+ '[data-hm-stream-runtime]',
69960
+ '[data-vvfx-card-html-auto-height]',
69961
+ '[data-vvfx-card-html-anchor-navigation-guard]',
69962
+ 'script',
69963
+ 'noscript',
69964
+ 'template'
69965
+ ].join(',');
69966
+ function captureViewportSize(logicalSize, _displayedBounds) {
69967
+ return {
69968
+ width: Math.max(1, logicalSize.width),
69969
+ height: Math.max(1, logicalSize.height)
69970
+ };
69971
+ }
69972
+ function serializeComputedCaptureStyle(style) {
69973
+ var declarations = [];
69974
+ for(var _iterator = _create_for_of_iterator_helper_loose(style), _step; !(_step = _iterator()).done;){
69975
+ var property = _step.value;
69976
+ if (MOTION_PROPERTIES.test(property)) {
69977
+ continue;
69978
+ }
69979
+ var value = style.getPropertyValue(property);
69980
+ if (!value) {
69981
+ continue;
69982
+ }
69983
+ var priority = style.getPropertyPriority(property);
69984
+ declarations.push(property + ":" + value + (priority ? "!" + priority : ''));
69985
+ }
69986
+ declarations.push('animation:none!important', 'transition:none!important');
69987
+ return declarations.join(';');
69988
+ }
69989
+ function createHTMLCaptureReplica(ownerDocument, html, logicalSize) {
69990
+ return _async_to_generator(function() {
69991
+ var size, iframe, loaded, sourceDocument, replica;
69992
+ return _ts_generator(this, function(_state) {
69993
+ switch(_state.label){
69994
+ case 0:
69995
+ size = captureViewportSize(logicalSize);
69996
+ iframe = ownerDocument.createElement('iframe');
69997
+ Object.assign(iframe.style, {
69998
+ position: 'fixed',
69999
+ left: '-100000px',
70000
+ top: '0',
70001
+ width: "" + size.width + "px",
70002
+ height: "" + size.height + "px",
70003
+ border: '0',
70004
+ pointerEvents: 'none',
70005
+ opacity: '1',
70006
+ zIndex: '-1'
70007
+ });
70008
+ iframe.srcdoc = html;
70009
+ loaded = waitForNextLoad(iframe);
70010
+ ownerDocument.body.appendChild(iframe);
70011
+ return [
70012
+ 4,
70013
+ withCaptureTimeout(loaded)
70014
+ ];
70015
+ case 1:
70016
+ _state.sent();
70017
+ sourceDocument = iframe.contentDocument;
70018
+ if (!(sourceDocument == null ? void 0 : sourceDocument.documentElement) || !sourceDocument.body) {
70019
+ iframe.remove();
70020
+ return [
70021
+ 2,
70022
+ undefined
70023
+ ];
70024
+ }
70025
+ return [
70026
+ 4,
70027
+ createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, size)
70028
+ ];
70029
+ case 2:
70030
+ replica = _state.sent();
70031
+ if (!replica) {
70032
+ iframe.remove();
70033
+ return [
70034
+ 2,
70035
+ undefined
70036
+ ];
70037
+ }
70038
+ return [
70039
+ 2,
70040
+ {
70041
+ target: replica.target,
70042
+ cleanup: function cleanup() {
70043
+ replica.cleanup();
70044
+ iframe.remove();
70045
+ }
70046
+ }
70047
+ ];
70048
+ }
70049
+ });
70050
+ })();
70051
+ }
70052
+ function createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, logicalSize) {
70053
+ return _async_to_generator(function() {
70054
+ var target;
70055
+ return _ts_generator(this, function(_state) {
70056
+ switch(_state.label){
70057
+ case 0:
70058
+ if (!sourceDocument.documentElement || !sourceDocument.body || !sourceDocument.defaultView) {
70059
+ return [
70060
+ 2,
70061
+ undefined
70062
+ ];
70063
+ }
70064
+ return [
70065
+ 4,
70066
+ withCaptureTimeout(waitForCaptureReady(sourceDocument))
70067
+ ];
70068
+ case 1:
70069
+ _state.sent();
70070
+ target = createComputedCaptureTarget(ownerDocument, sourceDocument, captureViewportSize(logicalSize));
70071
+ return [
70072
+ 2,
70073
+ {
70074
+ target: target,
70075
+ cleanup: function cleanup() {
70076
+ target.remove();
70077
+ }
70078
+ }
70079
+ ];
70080
+ }
70081
+ });
70082
+ })();
70083
+ }
70084
+ function createComputedCaptureTarget(ownerDocument, sourceDocument, size) {
70085
+ var sourceWindow = sourceDocument.defaultView;
70086
+ if (!sourceWindow) {
70087
+ throw new Error('HTML capture replica has no window');
70088
+ }
70089
+ var frame = ownerDocument.createElement('div');
70090
+ frame.setAttribute('data-vvfx-html-capture-replica', 'true');
70091
+ frame.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(sourceDocument.documentElement));
70092
+ Object.assign(frame.style, {
70093
+ position: 'fixed',
70094
+ left: '-100000px',
70095
+ top: '0',
70096
+ width: "" + size.width + "px",
70097
+ height: "" + size.height + "px",
70098
+ overflow: 'hidden',
70099
+ pointerEvents: 'none',
70100
+ opacity: '1',
70101
+ zIndex: '-1',
70102
+ transform: 'none'
70103
+ });
70104
+ appendDocumentFontSurface(frame, sourceDocument, ownerDocument);
70105
+ var sourceBody = sourceDocument.body;
70106
+ var bodyClone = sourceBody.cloneNode(true);
70107
+ bodyClone.querySelectorAll(RUNTIME_SELECTOR).forEach(function(node) {
70108
+ node.remove();
70109
+ });
70110
+ if (bodyClone.matches(RUNTIME_SELECTOR)) {
70111
+ bodyClone.replaceChildren();
70112
+ }
70113
+ frame.appendChild(bodyClone);
70114
+ ownerDocument.body.appendChild(frame);
70115
+ var sources = [].concat([
70116
+ sourceBody
70117
+ ], Array.from(sourceBody.querySelectorAll('*'))).filter(isStylableElement).filter(function(node) {
70118
+ return !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR);
70119
+ });
70120
+ var clones = [].concat([
70121
+ bodyClone
70122
+ ], Array.from(bodyClone.querySelectorAll('*'))).filter(isStylableElement).filter(function(node) {
70123
+ return !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR);
70124
+ });
70125
+ var pseudoRules = [];
70126
+ sources.forEach(function(source, index) {
70127
+ var clone = clones[index];
70128
+ if (!clone) {
70129
+ return;
70130
+ }
70131
+ clone.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(source));
70132
+ freezeViewportPosition(source, clone, sourceWindow);
70133
+ preserveLiveElementState(source, clone, ownerDocument);
70134
+ appendPseudoRule(source, clone, sourceWindow, pseudoRules, index);
70135
+ });
70136
+ if (pseudoRules.length) {
70137
+ var style = ownerDocument.createElement('style');
70138
+ style.setAttribute('data-vvfx-html-capture-pseudo', 'true');
70139
+ style.textContent = pseudoRules.join('\n');
70140
+ frame.prepend(style);
70141
+ }
70142
+ return frame;
70143
+ }
70144
+ function appendDocumentFontSurface(frame, sourceDocument, ownerDocument) {
70145
+ var _sourceDocument_defaultView;
70146
+ var fontRules = [];
70147
+ var SourceCSSFontFaceRule = (_sourceDocument_defaultView = sourceDocument.defaultView) == null ? void 0 : _sourceDocument_defaultView.CSSFontFaceRule;
70148
+ Array.from(sourceDocument.styleSheets).forEach(function(sheet) {
70149
+ try {
70150
+ Array.from(sheet.cssRules).forEach(function(rule) {
70151
+ if (SourceCSSFontFaceRule && _instanceof(rule, SourceCSSFontFaceRule)) {
70152
+ fontRules.push(rule.cssText);
70153
+ }
70154
+ });
70155
+ } catch (unused) {
70156
+ // Cross-origin font stylesheets are already loaded in the replica but cannot be read.
70157
+ }
70158
+ });
70159
+ if (!fontRules.length) {
70160
+ return;
70161
+ }
70162
+ var style = ownerDocument.createElement('style');
70163
+ style.setAttribute('data-vvfx-html-capture-fonts', 'true');
70164
+ style.textContent = fontRules.join('\n');
70165
+ frame.appendChild(style);
70166
+ }
70167
+ function isStylableElement(element) {
70168
+ return 'style' in element;
70169
+ }
70170
+ function freezeViewportPosition(source, clone, sourceWindow) {
70171
+ if (sourceWindow.getComputedStyle(source).position !== 'fixed') {
70172
+ return;
70173
+ }
70174
+ var rect = source.getBoundingClientRect();
70175
+ Object.assign(clone.style, {
70176
+ position: 'absolute',
70177
+ left: "" + rect.left + "px",
70178
+ top: "" + rect.top + "px",
70179
+ right: 'auto',
70180
+ bottom: 'auto',
70181
+ width: "" + rect.width + "px",
70182
+ height: "" + rect.height + "px"
70183
+ });
70184
+ }
70185
+ function preserveLiveElementState(source, clone, ownerDocument) {
70186
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLImageElement) && _instanceof(clone, ownerDocument.defaultView.HTMLImageElement)) {
70187
+ clone.src = source.currentSrc || source.src;
70188
+ }
70189
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLInputElement) && _instanceof(clone, ownerDocument.defaultView.HTMLInputElement)) {
70190
+ clone.value = source.value;
70191
+ clone.checked = source.checked;
70192
+ }
70193
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLTextAreaElement) && _instanceof(clone, ownerDocument.defaultView.HTMLTextAreaElement)) {
70194
+ clone.value = source.value;
70195
+ clone.textContent = source.value;
70196
+ }
70197
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLCanvasElement) && _instanceof(clone, ownerDocument.defaultView.HTMLCanvasElement)) {
70198
+ clone.width = source.width;
70199
+ clone.height = source.height;
70200
+ try {
70201
+ var _clone_getContext;
70202
+ (_clone_getContext = clone.getContext('2d')) == null ? void 0 : _clone_getContext.drawImage(source, 0, 0);
70203
+ } catch (unused) {
70204
+ // Tainted canvases remain empty; snapdom cannot legally read them either.
70205
+ }
70206
+ }
70207
+ }
70208
+ function appendPseudoRule(source, clone, sourceWindow, rules, index) {
70209
+ var attribute = "capture-" + index;
70210
+ clone.setAttribute('data-vvfx-capture-node', attribute);
70211
+ [
70212
+ '::before',
70213
+ '::after'
70214
+ ].forEach(function(pseudo) {
70215
+ var style = sourceWindow.getComputedStyle(source, pseudo);
70216
+ if (!style.content || style.content === 'none' || style.content === 'normal') {
70217
+ return;
70218
+ }
70219
+ rules.push('[data-vvfx-capture-node="' + attribute + '"]' + pseudo + "{" + serializeComputedCaptureStyle(style) + "}");
70220
+ });
70221
+ }
70222
+ function waitForCaptureReady(document) {
70223
+ return _async_to_generator(function() {
70224
+ var _document_fonts;
70225
+ return _ts_generator(this, function(_state) {
70226
+ switch(_state.label){
70227
+ case 0:
70228
+ return [
70229
+ 4,
70230
+ (_document_fonts = document.fonts) == null ? void 0 : _document_fonts.ready
70231
+ ];
70232
+ case 1:
70233
+ _state.sent();
70234
+ return [
70235
+ 4,
70236
+ Promise.all(Array.from(document.images).map(function(image) {
70237
+ return _async_to_generator(function() {
70238
+ return _ts_generator(this, function(_state) {
70239
+ switch(_state.label){
70240
+ case 0:
70241
+ _state.trys.push([
70242
+ 0,
70243
+ 4,
70244
+ ,
70245
+ 5
70246
+ ]);
70247
+ if (!!image.complete) return [
70248
+ 3,
70249
+ 2
70250
+ ];
70251
+ return [
70252
+ 4,
70253
+ new Promise(function(resolve) {
70254
+ image.addEventListener('load', function() {
70255
+ resolve();
70256
+ }, {
70257
+ once: true
70258
+ });
70259
+ image.addEventListener('error', function() {
70260
+ resolve();
70261
+ }, {
70262
+ once: true
70263
+ });
70264
+ })
70265
+ ];
70266
+ case 1:
70267
+ _state.sent();
70268
+ _state.label = 2;
70269
+ case 2:
70270
+ return [
70271
+ 4,
70272
+ image.decode == null ? void 0 : image.decode.call(image)
70273
+ ];
70274
+ case 3:
70275
+ _state.sent();
70276
+ return [
70277
+ 3,
70278
+ 5
70279
+ ];
70280
+ case 4:
70281
+ _state.sent();
70282
+ return [
70283
+ 3,
70284
+ 5
70285
+ ];
70286
+ case 5:
70287
+ return [
70288
+ 2
70289
+ ];
70290
+ }
70291
+ });
70292
+ })();
70293
+ }))
70294
+ ];
70295
+ case 2:
70296
+ _state.sent();
70297
+ return [
70298
+ 4,
70299
+ waitForStableLayout(document)
70300
+ ];
70301
+ case 3:
70302
+ _state.sent();
70303
+ return [
70304
+ 2
70305
+ ];
70306
+ }
70307
+ });
70308
+ })();
70309
+ }
70310
+ function waitForStableLayout(document) {
70311
+ return _async_to_generator(function() {
70312
+ var view, startedAt, previous, stableFrames, _ref, _ref1, _document_body, _document_body1, current;
70313
+ return _ts_generator(this, function(_state) {
70314
+ switch(_state.label){
70315
+ case 0:
70316
+ view = document.defaultView;
70317
+ if (!view) {
70318
+ return [
70319
+ 2
70320
+ ];
70321
+ }
70322
+ startedAt = performance.now();
70323
+ previous = '';
70324
+ stableFrames = 0;
70325
+ _state.label = 1;
70326
+ case 1:
70327
+ if (!(performance.now() - startedAt < CAPTURE_TIMEOUT && stableFrames < 3)) return [
70328
+ 3,
70329
+ 3
70330
+ ];
70331
+ return [
70332
+ 4,
70333
+ new Promise(function(resolve) {
70334
+ return view.requestAnimationFrame(function() {
70335
+ resolve();
70336
+ });
70337
+ })
70338
+ ];
70339
+ case 2:
70340
+ _state.sent();
70341
+ current = [
70342
+ document.documentElement.scrollWidth,
70343
+ document.documentElement.scrollHeight,
70344
+ (_ref = (_document_body = document.body) == null ? void 0 : _document_body.scrollWidth) != null ? _ref : 0,
70345
+ (_ref1 = (_document_body1 = document.body) == null ? void 0 : _document_body1.scrollHeight) != null ? _ref1 : 0,
70346
+ document.styleSheets.length,
70347
+ document.querySelectorAll('style').length
70348
+ ].join(':');
70349
+ stableFrames = current === previous ? stableFrames + 1 : 0;
70350
+ previous = current;
70351
+ return [
70352
+ 3,
70353
+ 1
70354
+ ];
70355
+ case 3:
70356
+ return [
70357
+ 2
70358
+ ];
70359
+ }
70360
+ });
70361
+ })();
70362
+ }
70363
+ function waitForNextLoad(iframe) {
70364
+ return new Promise(function(resolve) {
70365
+ iframe.addEventListener('load', function() {
70366
+ resolve();
70367
+ }, {
70368
+ once: true
70369
+ });
70370
+ iframe.addEventListener('error', function() {
70371
+ resolve();
70372
+ }, {
70373
+ once: true
70374
+ });
70375
+ });
70376
+ }
70377
+ function withCaptureTimeout(promise) {
70378
+ return new Promise(function(resolve) {
70379
+ var timer = globalThis.setTimeout(function() {
70380
+ resolve(undefined);
70381
+ }, CAPTURE_TIMEOUT);
70382
+ promise.then(function(value) {
70383
+ globalThis.clearTimeout(timer);
70384
+ resolve(value);
70385
+ }, function() {
70386
+ globalThis.clearTimeout(timer);
70387
+ resolve(undefined);
70388
+ });
70389
+ });
70390
+ }
70391
+
69956
70392
  function getCardOverlayBoxStyle(box, width, height, offsetX, offsetY, _autoScale) {
69957
70393
  if (offsetX === void 0) offsetX = 0;
69958
70394
  if (offsetY === void 0) offsetY = 0;
@@ -70348,7 +70784,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70348
70784
  _state.sent();
70349
70785
  return [
70350
70786
  4,
70351
- createCardCaptureTarget(contentOverlay, this.state.contents.get(id))
70787
+ createCardCaptureTarget(contentOverlay, this.state.contents.get(id), {
70788
+ width: options.width,
70789
+ height: options.height
70790
+ })
70352
70791
  ];
70353
70792
  case 3:
70354
70793
  capture = _state.sent();
@@ -70365,9 +70804,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70365
70804
  I.toPng(capture.target, _extends({
70366
70805
  embedFonts: true,
70367
70806
  backgroundColor: 'transparent',
70368
- dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2,
70369
- width: options.width,
70370
- height: options.height
70807
+ dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2
70371
70808
  }, options.snapdomOptions))
70372
70809
  ];
70373
70810
  case 5:
@@ -71810,52 +72247,56 @@ function waitForIframeLoad(iframe) {
71810
72247
  });
71811
72248
  });
71812
72249
  }
71813
- function createCardCaptureTarget(root, html) {
72250
+ function createCardCaptureTarget(root, html, logicalSize) {
71814
72251
  return _async_to_generator(function() {
71815
- var previewHTML, preview, isDirectIframe, directTarget, shellTarget, flattenedTarget;
72252
+ var _root_querySelector, liveDocument, liveReplica, previewHTML, preview, flattenedTarget;
71816
72253
  return _ts_generator(this, function(_state) {
71817
72254
  switch(_state.label){
71818
72255
  case 0:
71819
- previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
71820
- if (!previewHTML) return [
72256
+ liveDocument = (_root_querySelector = root.querySelector('iframe')) == null ? void 0 : _root_querySelector.contentDocument;
72257
+ if (!liveDocument) return [
71821
72258
  3,
71822
72259
  2
71823
72260
  ];
71824
72261
  return [
71825
72262
  4,
71826
- createPreviewDocumentCaptureTarget(root, previewHTML)
72263
+ createHTMLCaptureReplicaFromDocument(root.ownerDocument, liveDocument, logicalSize)
71827
72264
  ];
71828
72265
  case 1:
71829
- preview = _state.sent();
71830
- if (preview) {
71831
- isDirectIframe = root.children.length === 1 && _instanceof(root.children[0], HTMLIFrameElement);
71832
- if (isDirectIframe) {
71833
- directTarget = createDirectCaptureTarget(root, preview.target);
71834
- return [
71835
- 2,
71836
- {
71837
- target: directTarget,
71838
- cleanup: function cleanup() {
71839
- directTarget.remove();
71840
- preview.cleanup();
71841
- }
71842
- }
71843
- ];
71844
- }
71845
- shellTarget = createShellCaptureTarget(root, preview.target);
72266
+ liveReplica = _state.sent();
72267
+ if (liveReplica) {
71846
72268
  return [
71847
72269
  2,
71848
72270
  {
71849
- target: shellTarget,
71850
- cleanup: function cleanup() {
71851
- shellTarget.remove();
71852
- preview.cleanup();
71853
- }
72271
+ target: liveReplica.target,
72272
+ cleanup: liveReplica.cleanup
71854
72273
  }
71855
72274
  ];
71856
72275
  }
71857
72276
  _state.label = 2;
71858
72277
  case 2:
72278
+ previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
72279
+ if (!previewHTML) return [
72280
+ 3,
72281
+ 4
72282
+ ];
72283
+ return [
72284
+ 4,
72285
+ createHTMLCaptureReplica(root.ownerDocument, previewHTML, logicalSize)
72286
+ ];
72287
+ case 3:
72288
+ preview = _state.sent();
72289
+ if (preview) {
72290
+ return [
72291
+ 2,
72292
+ {
72293
+ target: preview.target,
72294
+ cleanup: preview.cleanup
72295
+ }
72296
+ ];
72297
+ }
72298
+ _state.label = 4;
72299
+ case 4:
71859
72300
  flattenedTarget = createFlattenedExistingIframeTarget(root);
71860
72301
  return [
71861
72302
  2,
@@ -71913,182 +72354,6 @@ function createCardPreviewHTML(content) {
71913
72354
  }
71914
72355
  return undefined;
71915
72356
  }
71916
- function createPreviewDocumentCaptureTarget(root, html) {
71917
- return _async_to_generator(function() {
71918
- var _ref, iframe, rect, loadPromise, doc, target;
71919
- return _ts_generator(this, function(_state) {
71920
- switch(_state.label){
71921
- case 0:
71922
- iframe = root.ownerDocument.createElement('iframe');
71923
- rect = root.getBoundingClientRect();
71924
- iframe.style.position = 'fixed';
71925
- iframe.style.left = '-100000px';
71926
- iframe.style.top = '0';
71927
- iframe.style.width = "" + Math.max(1, rect.width) + "px";
71928
- iframe.style.height = "" + Math.max(1, rect.height) + "px";
71929
- iframe.style.border = '0';
71930
- iframe.style.pointerEvents = 'none';
71931
- iframe.style.opacity = '1';
71932
- iframe.style.zIndex = '-1';
71933
- loadPromise = waitForNextIframeLoad(iframe);
71934
- root.ownerDocument.body.appendChild(iframe);
71935
- iframe.srcdoc = html;
71936
- return [
71937
- 4,
71938
- loadPromise
71939
- ];
71940
- case 1:
71941
- _state.sent();
71942
- return [
71943
- 4,
71944
- waitForIframeContent(iframe)
71945
- ];
71946
- case 2:
71947
- _state.sent();
71948
- doc = iframe.contentDocument;
71949
- target = (_ref = doc == null ? void 0 : doc.body) != null ? _ref : doc == null ? void 0 : doc.documentElement;
71950
- if (!target) {
71951
- iframe.remove();
71952
- return [
71953
- 2,
71954
- undefined
71955
- ];
71956
- }
71957
- return [
71958
- 4,
71959
- waitForDocumentFonts(target.ownerDocument)
71960
- ];
71961
- case 3:
71962
- _state.sent();
71963
- return [
71964
- 4,
71965
- waitForImages(target)
71966
- ];
71967
- case 4:
71968
- _state.sent();
71969
- return [
71970
- 4,
71971
- nextAnimationFrame()
71972
- ];
71973
- case 5:
71974
- _state.sent();
71975
- return [
71976
- 2,
71977
- {
71978
- target: target,
71979
- cleanup: function cleanup() {
71980
- iframe.remove();
71981
- }
71982
- }
71983
- ];
71984
- }
71985
- });
71986
- })();
71987
- }
71988
- function waitForNextIframeLoad(iframe) {
71989
- return new Promise(function(resolve) {
71990
- iframe.addEventListener('load', function() {
71991
- resolve();
71992
- }, {
71993
- once: true
71994
- });
71995
- iframe.addEventListener('error', function() {
71996
- resolve();
71997
- }, {
71998
- once: true
71999
- });
72000
- });
72001
- }
72002
- function waitForIframeContent(iframe) {
72003
- return _async_to_generator(function() {
72004
- var start, doc;
72005
- return _ts_generator(this, function(_state) {
72006
- switch(_state.label){
72007
- case 0:
72008
- start = performance.now();
72009
- _state.label = 1;
72010
- case 1:
72011
- if (!(performance.now() - start < CARD_RASTERIZE_READY_TIMEOUT)) return [
72012
- 3,
72013
- 3
72014
- ];
72015
- doc = iframe.contentDocument;
72016
- if ((doc == null ? void 0 : doc.body) && doc.body.children.length > 0) {
72017
- return [
72018
- 2
72019
- ];
72020
- }
72021
- return [
72022
- 4,
72023
- nextAnimationFrame()
72024
- ];
72025
- case 2:
72026
- _state.sent();
72027
- return [
72028
- 3,
72029
- 1
72030
- ];
72031
- case 3:
72032
- return [
72033
- 2
72034
- ];
72035
- }
72036
- });
72037
- })();
72038
- }
72039
- function createShellCaptureTarget(root, contentTarget) {
72040
- var clone = root.cloneNode(true);
72041
- clone.style.position = 'fixed';
72042
- clone.style.left = '-100000px';
72043
- clone.style.top = '0';
72044
- clone.style.pointerEvents = 'none';
72045
- clone.style.opacity = '1';
72046
- clone.style.zIndex = '-1';
72047
- var clonedIframe = clone.querySelector('iframe');
72048
- if (clonedIframe) {
72049
- clonedIframe.replaceWith(createFlattenedContent(contentTarget, getComputedStyle(clonedIframe), root.ownerDocument));
72050
- }
72051
- root.ownerDocument.body.appendChild(clone);
72052
- return clone;
72053
- }
72054
- function createDirectCaptureTarget(root, contentTarget) {
72055
- var rect = root.getBoundingClientRect();
72056
- var frame = root.ownerDocument.createElement('div');
72057
- frame.style.position = 'fixed';
72058
- frame.style.left = '-100000px';
72059
- frame.style.top = '0';
72060
- frame.style.width = "" + Math.max(1, rect.width) + "px";
72061
- frame.style.height = "" + Math.max(1, rect.height) + "px";
72062
- frame.style.pointerEvents = 'none';
72063
- frame.style.opacity = '1';
72064
- frame.style.zIndex = '-1';
72065
- frame.style.overflow = 'hidden';
72066
- var flattenedContent = createFlattenedContent(contentTarget, getComputedStyle(contentTarget), root.ownerDocument);
72067
- flattenedContent.style.width = '100%';
72068
- flattenedContent.style.height = '100%';
72069
- frame.appendChild(flattenedContent);
72070
- root.ownerDocument.body.appendChild(frame);
72071
- return frame;
72072
- }
72073
- function createFlattenedContent(target, frameStyle, ownerDocument) {
72074
- var replacement = ownerDocument.createElement('div');
72075
- Object.assign(replacement.style, {
72076
- width: frameStyle.width,
72077
- height: frameStyle.height,
72078
- display: frameStyle.display === 'none' ? 'block' : frameStyle.display,
72079
- overflow: 'hidden',
72080
- border: frameStyle.border,
72081
- boxSizing: frameStyle.boxSizing,
72082
- background: frameStyle.background
72083
- });
72084
- Array.from(target.ownerDocument.head.children).forEach(function(child) {
72085
- replacement.appendChild(child.cloneNode(true));
72086
- });
72087
- Array.from(target.children).forEach(function(child) {
72088
- replacement.appendChild(child.cloneNode(true));
72089
- });
72090
- return replacement;
72091
- }
72092
72357
  function isMouseEventInsideRect(event, rect) {
72093
72358
  return event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
72094
72359
  }