@vvfx/sdk 0.2.6 → 0.2.8

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.8
7
7
  */
8
8
 
9
9
  'use strict';
@@ -30,12 +30,6 @@ var url$1 = require('url');
30
30
  SDKItemType["CARD"] = "card";
31
31
  return SDKItemType;
32
32
  }({});
33
- var _obj$2;
34
- /**
35
- * @description SDKItemType 与 spec.ItemType 的映射关系
36
- */ (_obj$2 = {}, _obj$2["sprite"] = effects.spec.ItemType.sprite, _obj$2["text"] = effects.spec.ItemType.text, _obj$2["video"] = effects.spec.ItemType.video, _obj$2["group"] = effects.spec.ItemType.null, _obj$2["effects"] = effects.spec.ItemType.composition, _obj$2["frame"] = effects.spec.ItemType.composition, // generator 在底层以 sprite 形式渲染
37
- _obj$2["generator"] = effects.spec.ItemType.sprite, // card 在底层以 sprite 形式渲染
38
- _obj$2["card"] = effects.spec.ItemType.sprite, _obj$2);
39
33
 
40
34
  function _defineProperties(target, props) {
41
35
  for(var i = 0; i < props.length; i++){
@@ -69953,6 +69947,442 @@ function syncElementStackOrder(_container, elements) {
69953
69947
  });
69954
69948
  }
69955
69949
 
69950
+ var CAPTURE_TIMEOUT = 5000;
69951
+ var MOTION_PROPERTIES = /^(animation|transition)(?:-|$)/i;
69952
+ var RUNTIME_SELECTOR = [
69953
+ '[data-hm-stream-runtime]',
69954
+ '[data-vvfx-card-html-auto-height]',
69955
+ '[data-vvfx-card-html-anchor-navigation-guard]',
69956
+ 'script',
69957
+ 'noscript',
69958
+ 'template'
69959
+ ].join(',');
69960
+ function captureViewportSize(logicalSize, _displayedBounds) {
69961
+ return {
69962
+ width: Math.max(1, logicalSize.width),
69963
+ height: Math.max(1, logicalSize.height)
69964
+ };
69965
+ }
69966
+ function serializeComputedCaptureStyle(style) {
69967
+ var declarations = [];
69968
+ for(var _iterator = _create_for_of_iterator_helper_loose(style), _step; !(_step = _iterator()).done;){
69969
+ var property = _step.value;
69970
+ if (MOTION_PROPERTIES.test(property)) {
69971
+ continue;
69972
+ }
69973
+ var value = style.getPropertyValue(property);
69974
+ if (!value) {
69975
+ continue;
69976
+ }
69977
+ var priority = style.getPropertyPriority(property);
69978
+ declarations.push(property + ":" + value + (priority ? "!" + priority : ''));
69979
+ }
69980
+ declarations.push('animation:none!important', 'transition:none!important');
69981
+ return declarations.join(';');
69982
+ }
69983
+ function createHTMLCaptureReplica(ownerDocument, html, logicalSize) {
69984
+ return _async_to_generator(function() {
69985
+ var size, iframe, loaded, sourceDocument, replica;
69986
+ return _ts_generator(this, function(_state) {
69987
+ switch(_state.label){
69988
+ case 0:
69989
+ size = captureViewportSize(logicalSize);
69990
+ iframe = ownerDocument.createElement('iframe');
69991
+ Object.assign(iframe.style, {
69992
+ position: 'fixed',
69993
+ left: '-100000px',
69994
+ top: '0',
69995
+ width: "" + size.width + "px",
69996
+ height: "" + size.height + "px",
69997
+ border: '0',
69998
+ pointerEvents: 'none',
69999
+ opacity: '1',
70000
+ zIndex: '-1'
70001
+ });
70002
+ iframe.srcdoc = html;
70003
+ loaded = waitForNextLoad(iframe);
70004
+ ownerDocument.body.appendChild(iframe);
70005
+ return [
70006
+ 4,
70007
+ withCaptureTimeout(loaded)
70008
+ ];
70009
+ case 1:
70010
+ _state.sent();
70011
+ sourceDocument = iframe.contentDocument;
70012
+ if (!(sourceDocument == null ? void 0 : sourceDocument.documentElement) || !sourceDocument.body) {
70013
+ iframe.remove();
70014
+ return [
70015
+ 2,
70016
+ undefined
70017
+ ];
70018
+ }
70019
+ return [
70020
+ 4,
70021
+ createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, size)
70022
+ ];
70023
+ case 2:
70024
+ replica = _state.sent();
70025
+ if (!replica) {
70026
+ iframe.remove();
70027
+ return [
70028
+ 2,
70029
+ undefined
70030
+ ];
70031
+ }
70032
+ return [
70033
+ 2,
70034
+ {
70035
+ target: replica.target,
70036
+ cleanup: function cleanup() {
70037
+ replica.cleanup();
70038
+ iframe.remove();
70039
+ }
70040
+ }
70041
+ ];
70042
+ }
70043
+ });
70044
+ })();
70045
+ }
70046
+ function createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, logicalSize) {
70047
+ return _async_to_generator(function() {
70048
+ var target;
70049
+ return _ts_generator(this, function(_state) {
70050
+ switch(_state.label){
70051
+ case 0:
70052
+ if (!sourceDocument.documentElement || !sourceDocument.body || !sourceDocument.defaultView) {
70053
+ return [
70054
+ 2,
70055
+ undefined
70056
+ ];
70057
+ }
70058
+ return [
70059
+ 4,
70060
+ withCaptureTimeout(waitForCaptureReady(sourceDocument))
70061
+ ];
70062
+ case 1:
70063
+ _state.sent();
70064
+ target = createComputedCaptureTarget(ownerDocument, sourceDocument, captureViewportSize(logicalSize));
70065
+ return [
70066
+ 2,
70067
+ {
70068
+ target: target,
70069
+ cleanup: function cleanup() {
70070
+ target.remove();
70071
+ }
70072
+ }
70073
+ ];
70074
+ }
70075
+ });
70076
+ })();
70077
+ }
70078
+ function createComputedCaptureTarget(ownerDocument, sourceDocument, size) {
70079
+ var sourceWindow = sourceDocument.defaultView;
70080
+ if (!sourceWindow) {
70081
+ throw new Error('HTML capture replica has no window');
70082
+ }
70083
+ var frame = ownerDocument.createElement('div');
70084
+ frame.setAttribute('data-vvfx-html-capture-replica', 'true');
70085
+ frame.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(sourceDocument.documentElement));
70086
+ Object.assign(frame.style, {
70087
+ position: 'fixed',
70088
+ left: '-100000px',
70089
+ top: '0',
70090
+ width: "" + size.width + "px",
70091
+ height: "" + size.height + "px",
70092
+ overflow: 'hidden',
70093
+ pointerEvents: 'none',
70094
+ opacity: '1',
70095
+ zIndex: '-1',
70096
+ transform: 'none'
70097
+ });
70098
+ appendDocumentFontSurface(frame, sourceDocument, ownerDocument);
70099
+ var sourceBody = sourceDocument.body;
70100
+ var bodyClone = sourceBody.cloneNode(true);
70101
+ bodyClone.querySelectorAll(RUNTIME_SELECTOR).forEach(function(node) {
70102
+ node.remove();
70103
+ });
70104
+ if (bodyClone.matches(RUNTIME_SELECTOR)) {
70105
+ bodyClone.replaceChildren();
70106
+ }
70107
+ frame.appendChild(bodyClone);
70108
+ ownerDocument.body.appendChild(frame);
70109
+ var sources = [].concat([
70110
+ sourceBody
70111
+ ], Array.from(sourceBody.querySelectorAll('*'))).filter(isStylableElement).filter(function(node) {
70112
+ return !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR);
70113
+ });
70114
+ var clones = [].concat([
70115
+ bodyClone
70116
+ ], Array.from(bodyClone.querySelectorAll('*'))).filter(isStylableElement).filter(function(node) {
70117
+ return !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR);
70118
+ });
70119
+ var pseudoRules = [];
70120
+ sources.forEach(function(source, index) {
70121
+ var clone = clones[index];
70122
+ if (!clone) {
70123
+ return;
70124
+ }
70125
+ clone.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(source));
70126
+ freezeViewportPosition(source, clone, sourceWindow);
70127
+ preserveLiveElementState(source, clone, ownerDocument);
70128
+ appendPseudoRule(source, clone, sourceWindow, pseudoRules, index);
70129
+ });
70130
+ if (pseudoRules.length) {
70131
+ var style = ownerDocument.createElement('style');
70132
+ style.setAttribute('data-vvfx-html-capture-pseudo', 'true');
70133
+ style.textContent = pseudoRules.join('\n');
70134
+ frame.prepend(style);
70135
+ }
70136
+ return frame;
70137
+ }
70138
+ function appendDocumentFontSurface(frame, sourceDocument, ownerDocument) {
70139
+ var _sourceDocument_defaultView;
70140
+ var fontRules = [];
70141
+ var SourceCSSFontFaceRule = (_sourceDocument_defaultView = sourceDocument.defaultView) == null ? void 0 : _sourceDocument_defaultView.CSSFontFaceRule;
70142
+ Array.from(sourceDocument.styleSheets).forEach(function(sheet) {
70143
+ try {
70144
+ Array.from(sheet.cssRules).forEach(function(rule) {
70145
+ if (SourceCSSFontFaceRule && _instanceof(rule, SourceCSSFontFaceRule)) {
70146
+ fontRules.push(rule.cssText);
70147
+ }
70148
+ });
70149
+ } catch (unused) {
70150
+ // Cross-origin font stylesheets are already loaded in the replica but cannot be read.
70151
+ }
70152
+ });
70153
+ if (!fontRules.length) {
70154
+ return;
70155
+ }
70156
+ var style = ownerDocument.createElement('style');
70157
+ style.setAttribute('data-vvfx-html-capture-fonts', 'true');
70158
+ style.textContent = fontRules.join('\n');
70159
+ frame.appendChild(style);
70160
+ }
70161
+ function isStylableElement(element) {
70162
+ return 'style' in element;
70163
+ }
70164
+ function freezeViewportPosition(source, clone, sourceWindow) {
70165
+ if (sourceWindow.getComputedStyle(source).position !== 'fixed') {
70166
+ return;
70167
+ }
70168
+ var rect = source.getBoundingClientRect();
70169
+ Object.assign(clone.style, {
70170
+ position: 'absolute',
70171
+ left: "" + rect.left + "px",
70172
+ top: "" + rect.top + "px",
70173
+ right: 'auto',
70174
+ bottom: 'auto',
70175
+ width: "" + rect.width + "px",
70176
+ height: "" + rect.height + "px"
70177
+ });
70178
+ }
70179
+ function preserveLiveElementState(source, clone, ownerDocument) {
70180
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLImageElement) && _instanceof(clone, ownerDocument.defaultView.HTMLImageElement)) {
70181
+ clone.src = source.currentSrc || source.src;
70182
+ }
70183
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLInputElement) && _instanceof(clone, ownerDocument.defaultView.HTMLInputElement)) {
70184
+ clone.value = source.value;
70185
+ clone.checked = source.checked;
70186
+ }
70187
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLTextAreaElement) && _instanceof(clone, ownerDocument.defaultView.HTMLTextAreaElement)) {
70188
+ clone.value = source.value;
70189
+ clone.textContent = source.value;
70190
+ }
70191
+ if (_instanceof(source, source.ownerDocument.defaultView.HTMLCanvasElement) && _instanceof(clone, ownerDocument.defaultView.HTMLCanvasElement)) {
70192
+ clone.width = source.width;
70193
+ clone.height = source.height;
70194
+ try {
70195
+ var _clone_getContext;
70196
+ (_clone_getContext = clone.getContext('2d')) == null ? void 0 : _clone_getContext.drawImage(source, 0, 0);
70197
+ } catch (unused) {
70198
+ // Tainted canvases remain empty; snapdom cannot legally read them either.
70199
+ }
70200
+ }
70201
+ }
70202
+ function appendPseudoRule(source, clone, sourceWindow, rules, index) {
70203
+ var attribute = "capture-" + index;
70204
+ clone.setAttribute('data-vvfx-capture-node', attribute);
70205
+ [
70206
+ '::before',
70207
+ '::after'
70208
+ ].forEach(function(pseudo) {
70209
+ var style = sourceWindow.getComputedStyle(source, pseudo);
70210
+ if (!style.content || style.content === 'none' || style.content === 'normal') {
70211
+ return;
70212
+ }
70213
+ rules.push('[data-vvfx-capture-node="' + attribute + '"]' + pseudo + "{" + serializeComputedCaptureStyle(style) + "}");
70214
+ });
70215
+ }
70216
+ function waitForCaptureReady(document) {
70217
+ return _async_to_generator(function() {
70218
+ var _document_fonts;
70219
+ return _ts_generator(this, function(_state) {
70220
+ switch(_state.label){
70221
+ case 0:
70222
+ return [
70223
+ 4,
70224
+ (_document_fonts = document.fonts) == null ? void 0 : _document_fonts.ready
70225
+ ];
70226
+ case 1:
70227
+ _state.sent();
70228
+ return [
70229
+ 4,
70230
+ Promise.all(Array.from(document.images).map(function(image) {
70231
+ return _async_to_generator(function() {
70232
+ return _ts_generator(this, function(_state) {
70233
+ switch(_state.label){
70234
+ case 0:
70235
+ _state.trys.push([
70236
+ 0,
70237
+ 4,
70238
+ ,
70239
+ 5
70240
+ ]);
70241
+ if (!!image.complete) return [
70242
+ 3,
70243
+ 2
70244
+ ];
70245
+ return [
70246
+ 4,
70247
+ new Promise(function(resolve) {
70248
+ image.addEventListener('load', function() {
70249
+ resolve();
70250
+ }, {
70251
+ once: true
70252
+ });
70253
+ image.addEventListener('error', function() {
70254
+ resolve();
70255
+ }, {
70256
+ once: true
70257
+ });
70258
+ })
70259
+ ];
70260
+ case 1:
70261
+ _state.sent();
70262
+ _state.label = 2;
70263
+ case 2:
70264
+ return [
70265
+ 4,
70266
+ image.decode == null ? void 0 : image.decode.call(image)
70267
+ ];
70268
+ case 3:
70269
+ _state.sent();
70270
+ return [
70271
+ 3,
70272
+ 5
70273
+ ];
70274
+ case 4:
70275
+ _state.sent();
70276
+ return [
70277
+ 3,
70278
+ 5
70279
+ ];
70280
+ case 5:
70281
+ return [
70282
+ 2
70283
+ ];
70284
+ }
70285
+ });
70286
+ })();
70287
+ }))
70288
+ ];
70289
+ case 2:
70290
+ _state.sent();
70291
+ return [
70292
+ 4,
70293
+ waitForStableLayout(document)
70294
+ ];
70295
+ case 3:
70296
+ _state.sent();
70297
+ return [
70298
+ 2
70299
+ ];
70300
+ }
70301
+ });
70302
+ })();
70303
+ }
70304
+ function waitForStableLayout(document) {
70305
+ return _async_to_generator(function() {
70306
+ var view, startedAt, previous, stableFrames, _ref, _ref1, _document_body, _document_body1, current;
70307
+ return _ts_generator(this, function(_state) {
70308
+ switch(_state.label){
70309
+ case 0:
70310
+ view = document.defaultView;
70311
+ if (!view) {
70312
+ return [
70313
+ 2
70314
+ ];
70315
+ }
70316
+ startedAt = performance.now();
70317
+ previous = '';
70318
+ stableFrames = 0;
70319
+ _state.label = 1;
70320
+ case 1:
70321
+ if (!(performance.now() - startedAt < CAPTURE_TIMEOUT && stableFrames < 3)) return [
70322
+ 3,
70323
+ 3
70324
+ ];
70325
+ return [
70326
+ 4,
70327
+ new Promise(function(resolve) {
70328
+ return view.requestAnimationFrame(function() {
70329
+ resolve();
70330
+ });
70331
+ })
70332
+ ];
70333
+ case 2:
70334
+ _state.sent();
70335
+ current = [
70336
+ document.documentElement.scrollWidth,
70337
+ document.documentElement.scrollHeight,
70338
+ (_ref = (_document_body = document.body) == null ? void 0 : _document_body.scrollWidth) != null ? _ref : 0,
70339
+ (_ref1 = (_document_body1 = document.body) == null ? void 0 : _document_body1.scrollHeight) != null ? _ref1 : 0,
70340
+ document.styleSheets.length,
70341
+ document.querySelectorAll('style').length
70342
+ ].join(':');
70343
+ stableFrames = current === previous ? stableFrames + 1 : 0;
70344
+ previous = current;
70345
+ return [
70346
+ 3,
70347
+ 1
70348
+ ];
70349
+ case 3:
70350
+ return [
70351
+ 2
70352
+ ];
70353
+ }
70354
+ });
70355
+ })();
70356
+ }
70357
+ function waitForNextLoad(iframe) {
70358
+ return new Promise(function(resolve) {
70359
+ iframe.addEventListener('load', function() {
70360
+ resolve();
70361
+ }, {
70362
+ once: true
70363
+ });
70364
+ iframe.addEventListener('error', function() {
70365
+ resolve();
70366
+ }, {
70367
+ once: true
70368
+ });
70369
+ });
70370
+ }
70371
+ function withCaptureTimeout(promise) {
70372
+ return new Promise(function(resolve) {
70373
+ var timer = globalThis.setTimeout(function() {
70374
+ resolve(undefined);
70375
+ }, CAPTURE_TIMEOUT);
70376
+ promise.then(function(value) {
70377
+ globalThis.clearTimeout(timer);
70378
+ resolve(value);
70379
+ }, function() {
70380
+ globalThis.clearTimeout(timer);
70381
+ resolve(undefined);
70382
+ });
70383
+ });
70384
+ }
70385
+
69956
70386
  function getCardOverlayBoxStyle(box, width, height, offsetX, offsetY, _autoScale) {
69957
70387
  if (offsetX === void 0) offsetX = 0;
69958
70388
  if (offsetY === void 0) offsetY = 0;
@@ -70348,7 +70778,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70348
70778
  _state.sent();
70349
70779
  return [
70350
70780
  4,
70351
- createCardCaptureTarget(contentOverlay, this.state.contents.get(id))
70781
+ createCardCaptureTarget(contentOverlay, this.state.contents.get(id), {
70782
+ width: options.width,
70783
+ height: options.height
70784
+ })
70352
70785
  ];
70353
70786
  case 3:
70354
70787
  capture = _state.sent();
@@ -70365,9 +70798,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
70365
70798
  I.toPng(capture.target, _extends({
70366
70799
  embedFonts: true,
70367
70800
  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
70801
+ dpr: (_ref = (_options_pixelRatio = options.pixelRatio) != null ? _options_pixelRatio : window.devicePixelRatio) != null ? _ref : 2
70371
70802
  }, options.snapdomOptions))
70372
70803
  ];
70373
70804
  case 5:
@@ -71810,52 +72241,56 @@ function waitForIframeLoad(iframe) {
71810
72241
  });
71811
72242
  });
71812
72243
  }
71813
- function createCardCaptureTarget(root, html) {
72244
+ function createCardCaptureTarget(root, html, logicalSize) {
71814
72245
  return _async_to_generator(function() {
71815
- var previewHTML, preview, isDirectIframe, directTarget, shellTarget, flattenedTarget;
72246
+ var _root_querySelector, liveDocument, liveReplica, previewHTML, preview, flattenedTarget;
71816
72247
  return _ts_generator(this, function(_state) {
71817
72248
  switch(_state.label){
71818
72249
  case 0:
71819
- previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
71820
- if (!previewHTML) return [
72250
+ liveDocument = (_root_querySelector = root.querySelector('iframe')) == null ? void 0 : _root_querySelector.contentDocument;
72251
+ if (!liveDocument) return [
71821
72252
  3,
71822
72253
  2
71823
72254
  ];
71824
72255
  return [
71825
72256
  4,
71826
- createPreviewDocumentCaptureTarget(root, previewHTML)
72257
+ createHTMLCaptureReplicaFromDocument(root.ownerDocument, liveDocument, logicalSize)
71827
72258
  ];
71828
72259
  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);
72260
+ liveReplica = _state.sent();
72261
+ if (liveReplica) {
71846
72262
  return [
71847
72263
  2,
71848
72264
  {
71849
- target: shellTarget,
71850
- cleanup: function cleanup() {
71851
- shellTarget.remove();
71852
- preview.cleanup();
71853
- }
72265
+ target: liveReplica.target,
72266
+ cleanup: liveReplica.cleanup
71854
72267
  }
71855
72268
  ];
71856
72269
  }
71857
72270
  _state.label = 2;
71858
72271
  case 2:
72272
+ previewHTML = createCardPreviewHTML(html == null ? void 0 : html.content);
72273
+ if (!previewHTML) return [
72274
+ 3,
72275
+ 4
72276
+ ];
72277
+ return [
72278
+ 4,
72279
+ createHTMLCaptureReplica(root.ownerDocument, previewHTML, logicalSize)
72280
+ ];
72281
+ case 3:
72282
+ preview = _state.sent();
72283
+ if (preview) {
72284
+ return [
72285
+ 2,
72286
+ {
72287
+ target: preview.target,
72288
+ cleanup: preview.cleanup
72289
+ }
72290
+ ];
72291
+ }
72292
+ _state.label = 4;
72293
+ case 4:
71859
72294
  flattenedTarget = createFlattenedExistingIframeTarget(root);
71860
72295
  return [
71861
72296
  2,
@@ -71913,182 +72348,6 @@ function createCardPreviewHTML(content) {
71913
72348
  }
71914
72349
  return undefined;
71915
72350
  }
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
72351
  function isMouseEventInsideRect(event, rect) {
72093
72352
  return event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
72094
72353
  }