@sparkvault/sdk-js 2.2.0 → 2.2.1

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.
@@ -6893,7 +6893,7 @@ class IdentityRenderer {
6893
6893
  }
6894
6894
  }
6895
6895
 
6896
- /* global HTMLIFrameElement */
6896
+ /* global HTMLIFrameElement requestAnimationFrame */
6897
6897
  /**
6898
6898
  * Widget Embedder
6899
6899
  *
@@ -6941,6 +6941,7 @@ class WidgetEmbedder {
6941
6941
  // against — never the broader sparkvault.com family.
6942
6942
  this.trustedOrigin = new URL(this.config.identityBaseUrl).origin;
6943
6943
  this.boundHandleMessage = (event) => this.handleMessage(event);
6944
+ this.boundHandleCspViolation = (event) => this.handleCspViolation(event);
6944
6945
  }
6945
6946
  start() {
6946
6947
  const iframe = document.createElement('iframe');
@@ -6960,6 +6961,12 @@ class WidgetEmbedder {
6960
6961
  'background:transparent',
6961
6962
  'z-index:2147483647',
6962
6963
  ].join(';');
6964
+ // Promote to its own compositing layer up front. iOS Safari can otherwise
6965
+ // leave a freshly-inserted fixed, full-viewport iframe loaded but UNPAINTED
6966
+ // until the next composite (a scroll, resize, or app foreground) — the
6967
+ // frame even runs, but the dialog only appears after an app switch.
6968
+ iframe.style.transform = 'translateZ(0)';
6969
+ iframe.style.willChange = 'transform';
6963
6970
  // A network-level load failure (DNS, connection reset) fires onerror; an
6964
6971
  // HTTP error body or a frame blocked from framing does not, which is what
6965
6972
  // the readiness timeout below covers.
@@ -6969,9 +6976,36 @@ class WidgetEmbedder {
6969
6976
  this.previousBodyOverflow = document.body.style.overflow;
6970
6977
  document.body.style.overflow = 'hidden';
6971
6978
  window.addEventListener('message', this.boundHandleMessage);
6979
+ // A host-page CSP whose frame-src/child-src omits the Identity origin blocks
6980
+ // the iframe before it can load and fires no `onerror`. Catch the violation
6981
+ // so we fail over to the in-page flow at once instead of after the timeout.
6982
+ document.addEventListener('securitypolicyviolation', this.boundHandleCspViolation);
6972
6983
  document.body.appendChild(iframe);
6984
+ // Force the composite the iframe insertion may not have triggered on iOS,
6985
+ // so the dialog paints on the click rather than only after an app switch.
6986
+ this.forceComposite(iframe);
6973
6987
  this.readyTimer = setTimeout(() => this.handleFrameUnavailable(), FRAME_READY_TIMEOUT_MS);
6974
6988
  }
6989
+ /**
6990
+ * Nudge the browser to paint the just-inserted iframe on the next frame.
6991
+ * Reading layout forces a reflow; toggling a transform forces the compositor
6992
+ * to flush the new layer — the workaround for iOS Safari leaving a fixed
6993
+ * full-viewport iframe invisible until an unrelated repaint.
6994
+ */
6995
+ forceComposite(iframe) {
6996
+ const paint = () => {
6997
+ if (!this.iframe)
6998
+ return;
6999
+ void iframe.offsetHeight;
7000
+ iframe.style.transform = 'translateZ(0) scale(1)';
7001
+ };
7002
+ if (typeof requestAnimationFrame === 'function') {
7003
+ requestAnimationFrame(paint);
7004
+ }
7005
+ else {
7006
+ setTimeout(paint, 16);
7007
+ }
7008
+ }
6975
7009
  close() {
6976
7010
  this.clearReadyTimer();
6977
7011
  if (this.iframe?.parentNode) {
@@ -6979,8 +7013,22 @@ class WidgetEmbedder {
6979
7013
  }
6980
7014
  this.iframe = null;
6981
7015
  window.removeEventListener('message', this.boundHandleMessage);
7016
+ document.removeEventListener('securitypolicyviolation', this.boundHandleCspViolation);
6982
7017
  document.body.style.overflow = this.previousBodyOverflow;
6983
7018
  }
7019
+ /**
7020
+ * Host CSP blocked the widget iframe (frame-src/child-src). The frame can
7021
+ * never load, so fail over to the in-page flow immediately.
7022
+ */
7023
+ handleCspViolation(event) {
7024
+ const directive = event.effectiveDirective || event.violatedDirective;
7025
+ if (directive !== 'frame-src' && directive !== 'child-src')
7026
+ return;
7027
+ // blockedURI is the framed URL (sometimes just its origin); match either.
7028
+ if (typeof event.blockedURI === 'string' && event.blockedURI.startsWith(this.trustedOrigin)) {
7029
+ this.handleFrameUnavailable();
7030
+ }
7031
+ }
6984
7032
  clearReadyTimer() {
6985
7033
  if (this.readyTimer !== null) {
6986
7034
  clearTimeout(this.readyTimer);