@sparkvault/sdk-js 15.1.0 → 15.1.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.
package/dist/index.cjs CHANGED
@@ -18504,8 +18504,8 @@ function createSecuritySidebar(branding) {
18504
18504
  *
18505
18505
  * SparkVault design system, product register, as the identity modal: slate
18506
18506
  * neutrals with Action Blue carrying interactivity, on a light card that turns
18507
- * to the dark surface for the upload and security ceremony. Every color is the
18508
- * design system's (ui/ds-tokens).
18507
+ * to the dark surface while the upload runs. Every color is the design
18508
+ * system's (ui/ds-tokens).
18509
18509
  */
18510
18510
  const STYLE_ID = 'sparkvault-upload-styles';
18511
18511
  /**
@@ -18531,7 +18531,6 @@ function getUploadStyles() {
18531
18531
  error: DS.error,
18532
18532
  errorLight: DS.errorBg,
18533
18533
  errorBorder: withAlpha(DS.error500, 0.35),
18534
- errorText: DS.errorText,
18535
18534
  success: DS.success,
18536
18535
  successOnDark: DS.success500,
18537
18536
  // Backgrounds
@@ -18555,6 +18554,7 @@ function getUploadStyles() {
18555
18554
  // Shadows
18556
18555
  shadowSm: DS.shadowSm,
18557
18556
  shadowLg: DS.shadowPopover,
18557
+ shadowPress: `inset 0 1px 2px ${withAlpha(DS.slate900, 0.2)}`,
18558
18558
  };
18559
18559
  return `
18560
18560
  /* ========================================
@@ -18620,7 +18620,7 @@ function getUploadStyles() {
18620
18620
  min-width: 0;
18621
18621
  }
18622
18622
 
18623
- /* Dark card variant for uploading/ceremony states */
18623
+ /* Dark card variant while the upload runs */
18624
18624
  .svu-modal.svu-dark {
18625
18625
  background: ${tokens.bgDark};
18626
18626
  color: ${tokens.textOnDark};
@@ -18670,10 +18670,13 @@ function getUploadStyles() {
18670
18670
  text-overflow: ellipsis;
18671
18671
  }
18672
18672
 
18673
+ /* A 44px target around an 18px glyph; the negative margin keeps the
18674
+ header its height and the glyph where it sits. */
18673
18675
  .svu-close-btn {
18674
18676
  flex-shrink: 0;
18675
- width: 32px;
18676
- height: 32px;
18677
+ width: 44px;
18678
+ height: 44px;
18679
+ margin: -6px -6px -6px 0;
18677
18680
  display: flex;
18678
18681
  align-items: center;
18679
18682
  justify-content: center;
@@ -18690,6 +18693,23 @@ function getUploadStyles() {
18690
18693
  color: ${tokens.textPrimary};
18691
18694
  }
18692
18695
 
18696
+ /* One focus ring for every control the widget draws, as the help desk
18697
+ widget's: Action Blue, clear of the control. A view's heading takes
18698
+ focus as the view shows (the renderer's focusView), and the keyboard's
18699
+ ring marks it the same way. */
18700
+ .svu-close-btn:focus-visible,
18701
+ .svu-footer-link:focus-visible,
18702
+ .svu-drop-target:focus-visible,
18703
+ .svu-remove-file:focus-visible,
18704
+ .svu-btn:focus-visible,
18705
+ .svu-copy-btn:focus-visible,
18706
+ .svu-title:focus-visible,
18707
+ .svu-success-title:focus-visible,
18708
+ .svu-error-title:focus-visible {
18709
+ outline: 3px solid ${tokens.primary};
18710
+ outline-offset: 2px;
18711
+ }
18712
+
18693
18713
  .svu-dark .svu-close-btn {
18694
18714
  color: ${tokens.textMutedOnDark};
18695
18715
  }
@@ -18751,6 +18771,7 @@ function getUploadStyles() {
18751
18771
  LOADING STATE
18752
18772
  ======================================== */
18753
18773
 
18774
+ /* A load that answers within 200ms shows no spinner at all. */
18754
18775
  .svu-loading {
18755
18776
  display: flex;
18756
18777
  flex-direction: column;
@@ -18758,6 +18779,12 @@ function getUploadStyles() {
18758
18779
  justify-content: center;
18759
18780
  padding: 48px 24px;
18760
18781
  gap: 16px;
18782
+ animation: svu-appear 150ms ease-out 200ms both;
18783
+ }
18784
+
18785
+ @keyframes svu-appear {
18786
+ from { opacity: 0; }
18787
+ to { opacity: 1; }
18761
18788
  }
18762
18789
 
18763
18790
  .svu-spinner {
@@ -18817,19 +18844,18 @@ function getUploadStyles() {
18817
18844
  font-weight: 500;
18818
18845
  }
18819
18846
 
18820
- /* Drop Zone */
18847
+ /* Drop Zone: takes a dropped file anywhere on it; its button chooses one */
18821
18848
  .svu-drop-zone {
18822
18849
  width: 100%;
18850
+ box-sizing: border-box;
18823
18851
  border: 2px dashed ${tokens.border};
18824
18852
  border-radius: 12px;
18825
- padding: 32px 24px;
18826
18853
  text-align: center;
18827
- cursor: pointer;
18828
18854
  transition: border-color 0.15s ease, background 0.15s ease;
18829
18855
  margin-bottom: 16px;
18830
18856
  }
18831
18857
 
18832
- .svu-drop-zone:hover {
18858
+ .svu-drop-zone:not(.svu-has-file):hover {
18833
18859
  border-color: ${tokens.borderHover};
18834
18860
  background: ${tokens.bgSubtle};
18835
18861
  }
@@ -18843,7 +18869,22 @@ function getUploadStyles() {
18843
18869
  border-style: solid;
18844
18870
  border-color: ${tokens.primary};
18845
18871
  background: ${tokens.primaryLight};
18846
- cursor: default;
18872
+ padding: 16px 12px 16px 20px;
18873
+ }
18874
+
18875
+ .svu-drop-target {
18876
+ display: flex;
18877
+ flex-direction: column;
18878
+ align-items: center;
18879
+ width: 100%;
18880
+ padding: 32px 24px;
18881
+ background: transparent;
18882
+ border: 0;
18883
+ border-radius: 10px;
18884
+ color: inherit;
18885
+ font: inherit;
18886
+ text-align: center;
18887
+ cursor: pointer;
18847
18888
  }
18848
18889
 
18849
18890
  .svu-drop-icon {
@@ -18854,22 +18895,36 @@ function getUploadStyles() {
18854
18895
  }
18855
18896
 
18856
18897
  .svu-drop-text {
18898
+ display: block;
18857
18899
  font-size: 14px;
18858
18900
  font-weight: 500;
18859
- color: ${tokens.textPrimary};
18860
- margin: 0 0 4px 0;
18901
+ color: ${tokens.primary};
18902
+ }
18903
+
18904
+ /* Dragging and pasting take a fine pointer and a keyboard: a phone or
18905
+ tablet reads the action alone. */
18906
+ .svu-drop-subtext,
18907
+ .svu-drop-hint {
18908
+ display: none;
18909
+ }
18910
+
18911
+ @media (hover: hover) and (pointer: fine) {
18912
+ .svu-drop-subtext,
18913
+ .svu-drop-hint {
18914
+ display: block;
18915
+ }
18861
18916
  }
18862
18917
 
18863
18918
  .svu-drop-subtext {
18864
18919
  font-size: 13px;
18865
18920
  color: ${tokens.textSecondary};
18866
- margin: 0 0 8px 0;
18921
+ margin-top: 4px;
18867
18922
  }
18868
18923
 
18869
18924
  .svu-drop-hint {
18870
18925
  font-size: 12px;
18871
18926
  color: ${tokens.textMuted};
18872
- margin: 0;
18927
+ margin-top: 8px;
18873
18928
  }
18874
18929
 
18875
18930
  /* Selected File */
@@ -18909,8 +18964,8 @@ function getUploadStyles() {
18909
18964
 
18910
18965
  .svu-remove-file {
18911
18966
  flex-shrink: 0;
18912
- width: 24px;
18913
- height: 24px;
18967
+ width: 44px;
18968
+ height: 44px;
18914
18969
  display: flex;
18915
18970
  align-items: center;
18916
18971
  justify-content: center;
@@ -18935,13 +18990,15 @@ function getUploadStyles() {
18935
18990
  margin: 0 0 16px 0;
18936
18991
  }
18937
18992
 
18938
- /* Upload Button */
18993
+ /* Upload Button: its padding and line come a fraction short of the
18994
+ 44px target, which min-height makes up. */
18939
18995
  .svu-btn {
18940
18996
  display: inline-flex;
18941
18997
  align-items: center;
18942
18998
  justify-content: center;
18943
18999
  gap: 8px;
18944
19000
  width: 100%;
19001
+ min-height: 44px;
18945
19002
  padding: 12px 20px;
18946
19003
  font-size: 14px;
18947
19004
  font-weight: 500;
@@ -18950,7 +19007,7 @@ function getUploadStyles() {
18950
19007
  border: none;
18951
19008
  border-radius: 8px;
18952
19009
  cursor: pointer;
18953
- transition: background 0.15s ease, transform 0.1s ease;
19010
+ transition: background 0.15s ease;
18954
19011
  box-sizing: border-box;
18955
19012
  }
18956
19013
 
@@ -18959,8 +19016,9 @@ function getUploadStyles() {
18959
19016
  cursor: not-allowed;
18960
19017
  }
18961
19018
 
19019
+ /* A press compresses the button visually; nothing scales. */
18962
19020
  .svu-btn:active:not(:disabled) {
18963
- transform: scale(0.98);
19021
+ box-shadow: ${tokens.shadowPress};
18964
19022
  }
18965
19023
 
18966
19024
  .svu-btn-primary {
@@ -18983,6 +19041,16 @@ function getUploadStyles() {
18983
19041
  background: ${tokens.bgHover};
18984
19042
  }
18985
19043
 
19044
+ .svu-dark .svu-btn-secondary {
19045
+ background: transparent;
19046
+ color: ${tokens.textOnDark};
19047
+ border-color: ${tokens.borderDark};
19048
+ }
19049
+
19050
+ .svu-dark .svu-btn-secondary:hover:not(:disabled) {
19051
+ background: ${tokens.bgDarkSubtle};
19052
+ }
19053
+
18986
19054
  /* Error Alert */
18987
19055
  .svu-error-alert {
18988
19056
  background: ${tokens.errorLight};
@@ -19004,7 +19072,7 @@ function getUploadStyles() {
19004
19072
  border-top: 1px solid ${tokens.border};
19005
19073
  }
19006
19074
 
19007
- .svu-metadata h4 {
19075
+ .svu-metadata h3 {
19008
19076
  font-size: 12px;
19009
19077
  font-weight: 600;
19010
19078
  color: ${tokens.textSecondary};
@@ -19097,15 +19165,17 @@ function getUploadStyles() {
19097
19165
  position: absolute;
19098
19166
  left: 0;
19099
19167
  top: 0;
19168
+ width: 100%;
19100
19169
  height: 100%;
19101
19170
  background: ${tokens.primary};
19102
- animation: svu-arrow-flow 1s ease-in-out infinite;
19171
+ transform-origin: left center;
19172
+ animation: svu-arrow-flow 1s ease-out infinite;
19103
19173
  }
19104
19174
 
19105
19175
  @keyframes svu-arrow-flow {
19106
- 0% { width: 0; }
19107
- 50% { width: 100%; }
19108
- 100% { width: 100%; }
19176
+ 0% { transform: scaleX(0); }
19177
+ 50% { transform: scaleX(1); }
19178
+ 100% { transform: scaleX(1); }
19109
19179
  }
19110
19180
 
19111
19181
  /* Progress Bar */
@@ -19159,57 +19229,11 @@ function getUploadStyles() {
19159
19229
  .svu-mono {
19160
19230
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, monospace;
19161
19231
  color: ${tokens.textOnDark};
19232
+ overflow-wrap: anywhere;
19162
19233
  }
19163
19234
 
19164
- /* ========================================
19165
- CEREMONY VIEW
19166
- ======================================== */
19167
-
19168
- .svu-ceremony-view {
19169
- display: flex;
19170
- flex-direction: column;
19171
- align-items: center;
19172
- }
19173
-
19174
- .svu-ceremony-steps {
19175
- width: 100%;
19176
- margin: 20px 0;
19177
- }
19178
-
19179
- .svu-ceremony-step {
19180
- display: flex;
19181
- align-items: center;
19182
- gap: 12px;
19183
- padding: 10px 0;
19184
- opacity: 0.4;
19185
- transition: opacity 0.3s ease;
19186
- }
19187
-
19188
- .svu-ceremony-step.svu-active {
19189
- opacity: 1;
19190
- }
19191
-
19192
- .svu-ceremony-step.svu-complete {
19193
- opacity: 0.7;
19194
- }
19195
-
19196
- .svu-step-icon {
19197
- width: 20px;
19198
- height: 20px;
19199
- display: flex;
19200
- align-items: center;
19201
- justify-content: center;
19202
- color: ${tokens.primary};
19203
- }
19204
-
19205
- .svu-step-text {
19206
- font-size: 13px;
19207
- color: ${tokens.textOnDark};
19208
- }
19209
-
19210
- /* Spinning loader */
19211
- .svu-step-icon .svu-spin {
19212
- animation: svu-spin 0.7s linear infinite;
19235
+ .svu-cancel-upload {
19236
+ margin-top: 20px;
19213
19237
  }
19214
19238
 
19215
19239
  /* ========================================
@@ -19259,6 +19283,7 @@ function getUploadStyles() {
19259
19283
  display: flex;
19260
19284
  justify-content: space-between;
19261
19285
  align-items: center;
19286
+ gap: 12px;
19262
19287
  padding: 8px 0;
19263
19288
  font-size: 13px;
19264
19289
  border-bottom: 1px solid ${tokens.border};
@@ -19273,16 +19298,22 @@ function getUploadStyles() {
19273
19298
  }
19274
19299
 
19275
19300
  .svu-success-value {
19301
+ min-width: 0;
19276
19302
  color: ${tokens.textPrimary};
19277
19303
  font-weight: 500;
19278
19304
  display: flex;
19279
19305
  align-items: center;
19280
19306
  gap: 8px;
19307
+ text-align: right;
19281
19308
  }
19282
19309
 
19310
+ /* A 44px target around a 14px glyph; the negative margin keeps the row
19311
+ its text's height. */
19283
19312
  .svu-copy-btn {
19284
- width: 24px;
19285
- height: 24px;
19313
+ flex-shrink: 0;
19314
+ width: 44px;
19315
+ height: 44px;
19316
+ margin: -10px -12px -10px 0;
19286
19317
  display: flex;
19287
19318
  align-items: center;
19288
19319
  justify-content: center;
@@ -19299,6 +19330,13 @@ function getUploadStyles() {
19299
19330
  color: ${tokens.primary};
19300
19331
  }
19301
19332
 
19333
+ .svu-copy-status {
19334
+ margin: 0;
19335
+ font-size: 12px;
19336
+ color: ${tokens.textSecondary};
19337
+ text-align: right;
19338
+ }
19339
+
19302
19340
  .svu-success-guidance {
19303
19341
  font-size: 13px;
19304
19342
  color: ${tokens.textSecondary};
@@ -19337,32 +19375,6 @@ function getUploadStyles() {
19337
19375
  line-height: 1.5;
19338
19376
  }
19339
19377
 
19340
- .svu-error-code {
19341
- display: inline-flex;
19342
- align-items: center;
19343
- gap: 6px;
19344
- padding: 6px 10px;
19345
- background: ${tokens.errorLight};
19346
- border: 1px solid ${tokens.errorBorder};
19347
- border-radius: 6px;
19348
- margin-bottom: 20px;
19349
- }
19350
-
19351
- .svu-error-code-label {
19352
- font-size: 10px;
19353
- font-weight: 600;
19354
- color: ${tokens.errorText};
19355
- text-transform: uppercase;
19356
- letter-spacing: 0.05em;
19357
- }
19358
-
19359
- .svu-error-code-value {
19360
- font-size: 11px;
19361
- font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, monospace;
19362
- color: ${tokens.error};
19363
- font-weight: 500;
19364
- }
19365
-
19366
19378
  /* ========================================
19367
19379
  SECURITY SIDEBAR
19368
19380
  ======================================== */
@@ -19574,6 +19586,35 @@ function getUploadStyles() {
19574
19586
  ACCESSIBILITY
19575
19587
  ======================================== */
19576
19588
 
19589
+ /* Reduced motion shows each view's end state, still. The loading view
19590
+ keeps its 200ms wait, so a fast load still shows nothing, then appears
19591
+ at once. */
19592
+ @media (prefers-reduced-motion: reduce) {
19593
+ .svu-loading {
19594
+ animation: svu-appear 0s linear 200ms both;
19595
+ }
19596
+
19597
+ .svu-spinner {
19598
+ animation: none;
19599
+ }
19600
+
19601
+ .svu-stage-arrow.svu-active::after {
19602
+ animation: none;
19603
+ }
19604
+
19605
+ .svu-stage {
19606
+ transition: none;
19607
+ }
19608
+
19609
+ .svu-progress-fill {
19610
+ transition: none;
19611
+ }
19612
+
19613
+ .svu-complete-view {
19614
+ animation: none;
19615
+ }
19616
+ }
19617
+
19577
19618
  .svu-sr-only {
19578
19619
  position: absolute;
19579
19620
  width: 1px;
@@ -19792,38 +19833,26 @@ class UploadInlineContainer {
19792
19833
  * Upload Renderer
19793
19834
  *
19794
19835
  * Orchestrates view state and rendering for vault upload flows.
19795
- * Manages the complete upload lifecycle: form, uploading, ceremony, completion.
19836
+ * Manages the complete upload lifecycle: form, uploading (the bytes moving,
19837
+ * then SparkVault securing the file until it confirms the save), completion.
19796
19838
  */
19797
19839
  /**
19798
19840
  * What an outside uploader reads when the vault is scheduled for deletion:
19799
19841
  * the vault takes no files now. Core's own sentence, which tells the vault's
19800
19842
  * admin how to cancel the deletion, is the console's, never this page's.
19801
19843
  */
19802
- const VAULT_NOT_ACCEPTING_MESSAGE = 'This vault isn\'t accepting files right now, so your file was not saved. Please contact the person who shared this upload page with you.';
19844
+ const VAULT_NOT_ACCEPTING_MESSAGE = 'This vault isn\'t accepting files right now, so your file was not saved. Contact the person who shared this upload page with you.';
19803
19845
  /**
19804
19846
  * What an uploader reads for a file of no bytes, which Core never stores: said
19805
19847
  * on the form, where another file can be chosen, as the size limit is.
19806
19848
  */
19807
19849
  const EMPTY_FILE_MESSAGE = 'This file is empty, so there is nothing to upload. Choose another file.';
19850
+ /** How long "Copied" shows beside the Ingot ID once the copy landed. */
19851
+ const COPIED_SHOWS_MS = 2000;
19852
+ /** What the person reads when the browser refused to copy the Ingot ID. */
19853
+ const COPY_REFUSED_MESSAGE = 'Could not copy. Select the ID instead.';
19808
19854
  /**
19809
- * Ceremony steps for the cryptographic visualization.
19810
- */
19811
- const CEREMONY_STEPS = [
19812
- { text: 'File received by Forge', duration: 600 },
19813
- { text: 'Deriving Triple Zero-Trust encryption keys', duration: 800 },
19814
- { text: 'Encrypting with AES-256-GCM', duration: 900 },
19815
- { text: 'Generating cryptographic signatures', duration: 700 },
19816
- { text: 'Storing in post-quantum protected vault', duration: 600 },
19817
- { text: 'Verifying integrity', duration: 400 },
19818
- ];
19819
- /**
19820
- * Convert hex string to base64url for display.
19821
- */
19822
- function hexToBase64url(hex) {
19823
- return bytesToBase64url(new Uint8Array(hex.match(/.{2}/g).map(byte => parseInt(byte, 16))));
19824
- }
19825
- /**
19826
- * The "Secure Transfer Channel" line: the id Core gave the request that opened
19855
+ * The "Secure transfer channel" line: the id Core gave the request that opened
19827
19856
  * the upload, shown as text (it arrives from the server and lands on the host
19828
19857
  * page, so it is escaped like every server value the widget renders). A
19829
19858
  * response that names no id shows no line.
@@ -19831,7 +19860,7 @@ function hexToBase64url(hex) {
19831
19860
  function transferChannelLine(requestId) {
19832
19861
  return requestId === null
19833
19862
  ? ''
19834
- : `<p class="svu-forging-line">Secure Transfer Channel: <span class="svu-mono">${escapeHtml(requestId)}</span></p>`;
19863
+ : `<p class="svu-forging-line">Secure transfer channel: <span class="svu-mono">${escapeHtml(requestId)}</span></p>`;
19835
19864
  }
19836
19865
  /**
19837
19866
  * Refusals that say the vault takes no upload now, whichever file is chosen:
@@ -19854,14 +19883,60 @@ function vaultTakesNoUpload(error) {
19854
19883
  */
19855
19884
  function recoveryAfterUpload(error) {
19856
19885
  if (!(error instanceof UploadApiError))
19857
- return { label: 'Try Again', keepFile: true };
19886
+ return { label: 'Try again', keepFile: true };
19858
19887
  if (vaultTakesNoUpload(error))
19859
19888
  return null;
19860
19889
  if (error.code === RECEIVED_STILL_SAVING)
19861
- return { label: 'Upload Another File', keepFile: false };
19890
+ return { label: 'Upload another file', keepFile: false };
19862
19891
  const status = error.statusCode ?? 0;
19863
19892
  const mayPass = status === 0 || status === 429 || status >= 500;
19864
- return mayPass ? { label: 'Try Again', keepFile: true } : { label: 'Choose Another File', keepFile: false };
19893
+ return mayPass ? { label: 'Try again', keepFile: true } : { label: 'Choose another file', keepFile: false };
19894
+ }
19895
+ /**
19896
+ * What the error view says of a failed upload: a title, and the cause in the
19897
+ * uploader's terms. The error's code is the host's (onError), never shown: an
19898
+ * outside uploader cannot act on it.
19899
+ */
19900
+ function describeFailure(error) {
19901
+ if (!(error instanceof UploadApiError))
19902
+ return { title: 'Upload failed', message: error.message };
19903
+ if (error.code === 'UPLOAD_SOURCE_DISABLED') {
19904
+ // The vault exists but the embedded widget isn't enabled. This is almost
19905
+ // always a developer or admin oversight, so the message points at the
19906
+ // dashboard rather than the end user.
19907
+ return {
19908
+ title: 'Upload widget not enabled',
19909
+ message: 'This vault has not enabled the embedded upload widget. Enable it on the vault\'s settings page in the SparkVault dashboard to start accepting uploads here.',
19910
+ };
19911
+ }
19912
+ if (error.code === VAULT_DELETION_SCHEDULED || error.details?.coreCode === VAULT_DELETION_SCHEDULED) {
19913
+ // The vault is scheduled for deletion, refused at the upload's start or
19914
+ // while its bytes moved. Core's sentence tells the vault's admin how to
19915
+ // cancel the deletion; the person on this page is an outside uploader,
19916
+ // told only that the vault takes no files now.
19917
+ return { title: 'Uploads paused', message: VAULT_NOT_ACCEPTING_MESSAGE };
19918
+ }
19919
+ if (error.code === 'upload_refused') {
19920
+ // Core refused the upload, in its own words (whom to contact about a full
19921
+ // storage pool, or the later upload that replaced this one): a sentence
19922
+ // that never asks for the file again.
19923
+ return { title: 'Upload not saved', message: error.message };
19924
+ }
19925
+ if (error.statusCode === 404 && error.code !== 'session_gone') {
19926
+ // A vault or upload route that does not exist. A gone upload session can
19927
+ // answer 404 too, and its own sentence says what became of the file.
19928
+ return {
19929
+ title: 'Upload page not found',
19930
+ message: 'This upload page does not exist. The link may have expired or been mistyped.',
19931
+ };
19932
+ }
19933
+ if (error.statusCode === 402) {
19934
+ return {
19935
+ title: 'Upload unavailable',
19936
+ message: 'This upload page is unavailable because of a billing issue on the organization\'s account. Contact the organization that shared it with you.',
19937
+ };
19938
+ }
19939
+ return { title: 'Upload failed', message: error.message };
19865
19940
  }
19866
19941
  /**
19867
19942
  * Whether an error represents a deliberate cancellation (user close,
@@ -19878,7 +19953,7 @@ class UploadRenderer {
19878
19953
  this.selectedFile = null;
19879
19954
  // File input element for selection
19880
19955
  this.fileInputElement = null;
19881
- // Hybrid mode: modal overlay for upload/ceremony in inline mode
19956
+ // Hybrid mode: modal overlay for the uploading state in inline mode
19882
19957
  this.uploadModal = null;
19883
19958
  this.isInlineMode = false;
19884
19959
  this.hybridModalInitialized = false;
@@ -19887,6 +19962,29 @@ class UploadRenderer {
19887
19962
  // onError — see cancel()/handleApiError).
19888
19963
  this.closed = false;
19889
19964
  this.cancelled = false;
19965
+ // Counts the uploads this renderer started; an upload whose number is no
19966
+ // longer current (one the person cancelled) renders nothing and tells the
19967
+ // host nothing, whatever its transfer still reports.
19968
+ this.uploadGeneration = 0;
19969
+ // An upload runs from its start until it ends or is cancelled, and only
19970
+ // one at a time: each start stages a file Core names, so a second start
19971
+ // for the same file is a second file left pending beside the first. While
19972
+ // one runs, the form takes no other file (formTakesFile).
19973
+ this.uploadInFlight = false;
19974
+ // Set once the widget is ready (onReady). Every view drawn after it answers
19975
+ // the person's action, or the upload they started, so it takes focus
19976
+ // (focusView); the views before it leave focus where the host page has it.
19977
+ this.ready = false;
19978
+ /**
19979
+ * A browser tab closed or reloaded mid-transfer loses the upload, so the
19980
+ * tab asks first while one runs (holdPage). Each renderer holds the page
19981
+ * with its own listener, so one ending never releases another's hold.
19982
+ */
19983
+ this.warnBeforeLeaving = (event) => {
19984
+ event.preventDefault();
19985
+ // A browser that reads only returnValue asks for it set.
19986
+ event.returnValue = '';
19987
+ };
19890
19988
  this.pasteHandler = null;
19891
19989
  this.container = container;
19892
19990
  this.api = api;
@@ -19902,11 +20000,7 @@ class UploadRenderer {
19902
20000
  this.container.createLoading({ backdropBlur: this.options.backdropBlur }, () => this.handleClose());
19903
20001
  this.setState({ view: 'loading' });
19904
20002
  try {
19905
- // Minimum delay for UX
19906
- const [config] = await Promise.all([
19907
- this.api.getVaultUploadInfo(this.options.vaultId),
19908
- new Promise(resolve => setTimeout(resolve, 1000)),
19909
- ]);
20003
+ const config = await this.api.getVaultUploadInfo(this.options.vaultId);
19910
20004
  this.config = config;
19911
20005
  // Update branding
19912
20006
  this.container.updateBranding(config.branding);
@@ -19915,12 +20009,14 @@ class UploadRenderer {
19915
20009
  // (its own button, picker, or drop target) and hand the File to the SDK.
19916
20010
  if (this.options.file) {
19917
20011
  this.selectedFile = this.options.file;
20012
+ this.ready = true;
19918
20013
  this.callbacks.onReady?.();
19919
20014
  await this.startUpload(config);
19920
20015
  return;
19921
20016
  }
19922
20017
  // Show form
19923
20018
  this.setState({ view: 'form', config });
20019
+ this.ready = true;
19924
20020
  this.callbacks.onReady?.();
19925
20021
  }
19926
20022
  catch (error) {
@@ -19936,6 +20032,7 @@ class UploadRenderer {
19936
20032
  this.closed = true;
19937
20033
  // Cancel all pending API requests and the active TUS transfer
19938
20034
  this.api.abort();
20035
+ this.holdPage(false);
19939
20036
  this.cleanupFileInput();
19940
20037
  this.cleanupPasteHandler();
19941
20038
  // Clean up modal if open (hybrid mode)
@@ -19959,7 +20056,16 @@ class UploadRenderer {
19959
20056
  this.close();
19960
20057
  this.callbacks.onCancel();
19961
20058
  }
20059
+ /**
20060
+ * The dialog's dismissals: Escape, a tap on its backdrop, and its close
20061
+ * button, which the uploading view hides. While an upload runs, Escape and
20062
+ * a tap are too easy to do by accident to end it, as in the dialog inline
20063
+ * mode runs the upload in (renderInModal): the view's Cancel upload stops
20064
+ * it, and once SparkVault secures the file nothing does.
20065
+ */
19962
20066
  handleClose() {
20067
+ if (this.viewState.view === 'uploading')
20068
+ return;
19963
20069
  this.cancel();
19964
20070
  }
19965
20071
  setState(state) {
@@ -19967,15 +20073,18 @@ class UploadRenderer {
19967
20073
  // teardown must not resurrect the hybrid-mode modal or touch the DOM.
19968
20074
  if (this.closed)
19969
20075
  return;
19970
- const previousView = this.viewState.view;
20076
+ const previous = this.viewState;
19971
20077
  this.viewState = state;
19972
20078
  // Progress events fire many times per second for the whole transfer.
19973
20079
  // While the uploading view is already on screen, mutate its progress
19974
20080
  // nodes in place instead of tearing down and rebuilding the subtree —
19975
20081
  // a full rebuild per event thrashes the DOM and restarts the progress
19976
- // bar's CSS transition and the stage-arrow animation on every tick.
19977
- if (previousView === 'uploading' &&
20082
+ // bar's CSS transition and the stage-arrow animation on every tick. The
20083
+ // view re-renders once, when every byte is sent and SparkVault is
20084
+ // securing the file.
20085
+ if (previous.view === 'uploading' &&
19978
20086
  state.view === 'uploading' &&
20087
+ previous.securing === state.securing &&
19979
20088
  this.updateUploadProgress(state)) {
19980
20089
  return;
19981
20090
  }
@@ -20005,14 +20114,15 @@ class UploadRenderer {
20005
20114
  return true;
20006
20115
  }
20007
20116
  render() {
20008
- const isDarkState = this.viewState.view === 'uploading' || this.viewState.view === 'ceremony';
20009
- // Hybrid mode: For inline containers, use a modal popup for upload/ceremony
20010
- // This gives the polished full experience, then returns to inline for success
20117
+ const isDarkState = this.viewState.view === 'uploading';
20118
+ // Hybrid mode: For inline containers, use a modal popup while the upload
20119
+ // runs. This gives the polished full experience, then returns to inline
20120
+ // for its outcome
20011
20121
  if (this.isInlineMode && isDarkState) {
20012
20122
  this.renderInModal();
20013
20123
  return;
20014
20124
  }
20015
- // Close modal if we're leaving upload/ceremony states (hybrid mode complete)
20125
+ // Close modal if we're leaving the uploading state (hybrid mode complete)
20016
20126
  if (this.uploadModal) {
20017
20127
  this.uploadModal.destroy();
20018
20128
  this.uploadModal = null;
@@ -20044,27 +20154,61 @@ class UploadRenderer {
20044
20154
  case 'uploading':
20045
20155
  body.appendChild(this.renderUploading(this.viewState));
20046
20156
  break;
20047
- case 'ceremony':
20048
- body.appendChild(this.renderCeremony(this.viewState));
20049
- break;
20050
20157
  case 'complete':
20051
20158
  body.appendChild(this.renderComplete(this.viewState.result, this.viewState.config));
20052
20159
  break;
20160
+ case 'received':
20161
+ body.appendChild(this.renderReceived(this.viewState.message, this.viewState.action));
20162
+ break;
20053
20163
  case 'error':
20054
20164
  body.appendChild(this.renderError(this.viewState));
20055
20165
  break;
20056
20166
  }
20167
+ this.focusView(body);
20168
+ }
20169
+ /**
20170
+ * A redraw replaces the control the person just used, so once the widget is
20171
+ * ready (this.ready) focus never drops to the page: it lands on Upload
20172
+ * securely once a file is chosen, on the drop target before one is, and on
20173
+ * the heading every other view leads with (tabindex -1: it takes focus
20174
+ * without joining the Tab order). The loading view has nothing to focus.
20175
+ */
20176
+ focusView(body) {
20177
+ if (!this.ready)
20178
+ return;
20179
+ let target = null;
20180
+ switch (this.viewState.view) {
20181
+ case 'form':
20182
+ target = this.selectedFile ? '.svu-upload-btn' : '.svu-drop-target';
20183
+ break;
20184
+ case 'uploading':
20185
+ target = '.svu-title';
20186
+ break;
20187
+ case 'complete':
20188
+ case 'received':
20189
+ target = '.svu-success-title';
20190
+ break;
20191
+ case 'error':
20192
+ target = '.svu-error-title';
20193
+ break;
20194
+ }
20195
+ if (target)
20196
+ body.querySelector(target)?.focus();
20057
20197
  }
20058
20198
  /**
20059
- * Render uploading/ceremony states in a modal overlay (for inline mode).
20199
+ * Render the uploading state in a modal overlay (for inline mode).
20060
20200
  * This provides the full polished experience during upload.
20061
20201
  */
20062
20202
  renderInModal() {
20063
20203
  // Create and initialize modal only once
20064
20204
  if (!this.uploadModal) {
20065
20205
  this.uploadModal = new UploadModalContainer();
20066
- this.uploadModal.createLoading({ backdropBlur: this.options.backdropBlur ?? true }, () => { } // No close callback - user can't cancel during upload
20067
- );
20206
+ this.uploadModal.createLoading({ backdropBlur: this.options.backdropBlur ?? true },
20207
+ // An embedded widget has no close (UploadInlineContainer), and this
20208
+ // dialog shows only while an upload runs, which Escape and a tap on
20209
+ // the backdrop are too easy to do by accident to end: the view's own
20210
+ // Cancel upload button stops it.
20211
+ () => { });
20068
20212
  if (this.config) {
20069
20213
  this.uploadModal.updateBranding(this.config.branding);
20070
20214
  }
@@ -20089,9 +20233,7 @@ class UploadRenderer {
20089
20233
  body.innerHTML = '';
20090
20234
  if (this.viewState.view === 'uploading') {
20091
20235
  body.appendChild(this.renderUploading(this.viewState));
20092
- }
20093
- else if (this.viewState.view === 'ceremony') {
20094
- body.appendChild(this.renderCeremony(this.viewState));
20236
+ this.focusView(body);
20095
20237
  }
20096
20238
  }
20097
20239
  renderLoading() {
@@ -20109,28 +20251,30 @@ class UploadRenderer {
20109
20251
  // Title
20110
20252
  const title = document.createElement('h2');
20111
20253
  title.className = 'svu-title';
20112
- title.textContent = 'Cryptographically Secure File Transfer';
20254
+ title.textContent = 'Cryptographically secure file transfer';
20113
20255
  div.appendChild(title);
20114
20256
  // Subtitle with vault name
20115
20257
  const subtitle = document.createElement('p');
20116
20258
  subtitle.className = 'svu-subtitle';
20117
- subtitle.innerHTML = `Destination Vault: <strong>${escapeHtml(config.vaultName)}</strong>`;
20259
+ subtitle.innerHTML = `Destination vault: <strong>${escapeHtml(config.vaultName)}</strong>`;
20118
20260
  div.appendChild(subtitle);
20119
20261
  // Error message
20120
20262
  if (error) {
20121
20263
  const alert = document.createElement('div');
20122
20264
  alert.className = 'svu-error-alert';
20265
+ alert.setAttribute('role', 'alert');
20123
20266
  alert.textContent = error;
20124
20267
  div.appendChild(alert);
20125
20268
  }
20126
- // Drop zone
20269
+ // Drop zone: the whole zone takes a dropped file; choosing one is a
20270
+ // native button, so a keyboard, switch or screen reader reaches it.
20127
20271
  const dropZone = document.createElement('div');
20128
20272
  dropZone.className = `svu-drop-zone${this.selectedFile ? ' svu-has-file' : ''}`;
20129
20273
  if (this.selectedFile) {
20130
20274
  dropZone.innerHTML = `
20131
20275
  <div class="svu-selected-file">
20132
20276
  <div class="svu-file-icon">
20133
- <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20277
+ <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
20134
20278
  <path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
20135
20279
  <path d="M14 2v6h6"/>
20136
20280
  </svg>
@@ -20139,31 +20283,36 @@ class UploadRenderer {
20139
20283
  <span class="svu-file-name">${escapeHtml(this.selectedFile.name)}</span>
20140
20284
  <span class="svu-file-size">${formatBytes(this.selectedFile.size)}</span>
20141
20285
  </div>
20142
- <button class="svu-remove-file" aria-label="Remove file">&times;</button>
20286
+ <button type="button" class="svu-remove-file" aria-label="Remove file">&times;</button>
20143
20287
  </div>
20144
20288
  `;
20145
- const removeBtn = dropZone.querySelector('.svu-remove-file');
20146
- if (removeBtn) {
20147
- removeBtn.addEventListener('click', (e) => {
20148
- e.stopPropagation();
20149
- this.selectedFile = null;
20150
- this.render();
20151
- });
20152
- }
20289
+ dropZone.querySelector('.svu-remove-file')?.addEventListener('click', () => {
20290
+ if (!this.formTakesFile())
20291
+ return;
20292
+ this.selectedFile = null;
20293
+ this.render();
20294
+ });
20153
20295
  }
20154
20296
  else {
20297
+ // The drag and paste hints show only where a fine pointer can drag
20298
+ // (styles.ts); a phone reads the action alone.
20155
20299
  dropZone.innerHTML = `
20156
- <div class="svu-drop-icon">
20157
- <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20158
- <path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/>
20159
- <path d="M17 8l-5-5-5 5"/>
20160
- <path d="M12 3v12"/>
20161
- </svg>
20162
- </div>
20163
- <p class="svu-drop-text">Drag & drop a file here</p>
20164
- <p class="svu-drop-subtext">or click to select</p>
20165
- <p class="svu-drop-hint">Paste from clipboard also supported (Ctrl+V)</p>
20300
+ <button type="button" class="svu-drop-target">
20301
+ <span class="svu-drop-icon" aria-hidden="true">
20302
+ <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20303
+ <path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/>
20304
+ <path d="M17 8l-5-5-5 5"/>
20305
+ <path d="M12 3v12"/>
20306
+ </svg>
20307
+ </span>
20308
+ <span class="svu-drop-text">Choose a file</span>
20309
+ <span class="svu-drop-subtext">or drag it here</span>
20310
+ <span class="svu-drop-hint">You can also paste a file</span>
20311
+ </button>
20166
20312
  `;
20313
+ dropZone.querySelector('.svu-drop-target')?.addEventListener('click', () => {
20314
+ this.openFileSelector(config);
20315
+ });
20167
20316
  }
20168
20317
  // Drop zone events
20169
20318
  dropZone.addEventListener('dragover', (e) => {
@@ -20182,30 +20331,30 @@ class UploadRenderer {
20182
20331
  this.handleFileSelect(file, config);
20183
20332
  }
20184
20333
  });
20185
- dropZone.addEventListener('click', () => {
20186
- if (!this.selectedFile) {
20187
- this.openFileSelector(config);
20188
- }
20189
- });
20190
20334
  div.appendChild(dropZone);
20191
20335
  // Max size
20192
20336
  const maxSize = document.createElement('p');
20193
20337
  maxSize.className = 'svu-max-size';
20194
20338
  maxSize.textContent = `Max upload size: ${formatBytes(config.maxSizeBytes)}`;
20195
20339
  div.appendChild(maxSize);
20196
- // Upload button
20340
+ // Upload button: it goes unavailable on the press that starts the upload,
20341
+ // so a double click starts one.
20197
20342
  if (this.selectedFile) {
20198
20343
  const uploadBtn = document.createElement('button');
20199
- uploadBtn.className = 'svu-btn svu-btn-primary';
20200
- uploadBtn.textContent = 'Upload Securely';
20201
- uploadBtn.onclick = () => this.startUpload(config);
20344
+ uploadBtn.type = 'button';
20345
+ uploadBtn.className = 'svu-btn svu-btn-primary svu-upload-btn';
20346
+ uploadBtn.textContent = 'Upload securely';
20347
+ uploadBtn.addEventListener('click', () => {
20348
+ uploadBtn.disabled = true;
20349
+ void this.startUpload(config);
20350
+ });
20202
20351
  div.appendChild(uploadBtn);
20203
20352
  }
20204
20353
  // Metadata section
20205
20354
  const metadata = document.createElement('div');
20206
20355
  metadata.className = 'svu-metadata';
20207
20356
  metadata.innerHTML = `
20208
- <h4>Transfer Details</h4>
20357
+ <h3>Transfer details</h3>
20209
20358
  <div class="svu-metadata-grid">
20210
20359
  <div class="svu-metadata-item">
20211
20360
  <span class="svu-metadata-label">Recipient</span>
@@ -20224,15 +20373,15 @@ class UploadRenderer {
20224
20373
  <span class="svu-metadata-value">${escapeHtml(config.encryption.algorithm)}</span>
20225
20374
  </div>
20226
20375
  <div class="svu-metadata-item">
20227
- <span class="svu-metadata-label">Key Derivation</span>
20376
+ <span class="svu-metadata-label">Key derivation</span>
20228
20377
  <span class="svu-metadata-value">${escapeHtml(config.encryption.keyDerivation)}</span>
20229
20378
  </div>
20230
20379
  <div class="svu-metadata-item">
20231
- <span class="svu-metadata-label">Post-Quantum</span>
20380
+ <span class="svu-metadata-label">Post-quantum</span>
20232
20381
  <span class="svu-metadata-value">${escapeHtml(config.encryption.postQuantum)}</span>
20233
20382
  </div>
20234
20383
  <div class="svu-metadata-item">
20235
- <span class="svu-metadata-label">Forge Status</span>
20384
+ <span class="svu-metadata-label">Forge status</span>
20236
20385
  <span class="svu-metadata-value ${config.forgeStatus === 'active' ? 'svu-status-active' : ''}">
20237
20386
  ${config.forgeStatus === 'active' ? '● Active' : '○ Inactive'}
20238
20387
  </span>
@@ -20247,23 +20396,24 @@ class UploadRenderer {
20247
20396
  renderUploading(state) {
20248
20397
  const div = document.createElement('div');
20249
20398
  div.className = 'svu-uploading-view';
20250
- const displayIngotId = hexToBase64url(state.ingotId.replace('ing_', ''));
20399
+ // Once every byte is sent, SparkVault encrypts and stores the last of them
20400
+ // and saves the file; the transfer ends only once it confirms the save.
20251
20401
  div.innerHTML = `
20252
- <h2 class="svu-title">Streaming & Encrypting</h2>
20402
+ <h2 class="svu-title" tabindex="-1">${state.securing ? 'Securing your file' : 'Streaming and encrypting'}</h2>
20253
20403
 
20254
20404
  <div class="svu-stages">
20255
20405
  <div class="svu-stage svu-active">
20256
- <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20406
+ <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
20257
20407
  <rect x="2" y="3" width="20" height="18" rx="2"/>
20258
20408
  <path d="M2 9h20"/>
20259
20409
  <circle cx="6" cy="6" r="1" fill="currentColor"/>
20260
20410
  <circle cx="10" cy="6" r="1" fill="currentColor"/>
20261
20411
  </svg>
20262
- <span>Your Browser</span>
20412
+ <span>Your browser</span>
20263
20413
  </div>
20264
20414
  <div class="svu-stage-arrow svu-active"></div>
20265
20415
  <div class="svu-stage svu-active">
20266
- <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20416
+ <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
20267
20417
  <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
20268
20418
  </svg>
20269
20419
  <span>SparkVault</span>
@@ -20271,7 +20421,7 @@ class UploadRenderer {
20271
20421
  </div>
20272
20422
  <div class="svu-stage-arrow"></div>
20273
20423
  <div class="svu-stage">
20274
- <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20424
+ <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
20275
20425
  <rect x="3" y="3" width="18" height="18" rx="2"/>
20276
20426
  <circle cx="12" cy="12" r="3"/>
20277
20427
  <path d="M12 9V6M12 18v-3M9 12H6M18 12h-3"/>
@@ -20291,73 +20441,50 @@ class UploadRenderer {
20291
20441
  </div>
20292
20442
 
20293
20443
  <div class="svu-forging-info">
20294
- <p class="svu-forging-line">Forging Ingot ID: <span class="svu-mono">${displayIngotId}</span></p>
20295
- ${transferChannelLine(state.requestId)}
20296
- </div>
20297
- `;
20298
- return div;
20299
- }
20300
- renderCeremony(state) {
20301
- const div = document.createElement('div');
20302
- div.className = 'svu-ceremony-view';
20303
- const displayIngotId = hexToBase64url(state.ingotId.replace('ing_', ''));
20304
- let stepsHtml = '';
20305
- CEREMONY_STEPS.forEach((step, index) => {
20306
- const isComplete = index < state.step;
20307
- const isActive = index === state.step;
20308
- stepsHtml += `
20309
- <div class="svu-ceremony-step ${isComplete ? 'svu-complete' : ''} ${isActive ? 'svu-active' : ''}">
20310
- <span class="svu-step-icon">
20311
- ${isComplete
20312
- ? '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 6L9 17l-5-5"/></svg>'
20313
- : isActive
20314
- ? '<svg class="svu-spin" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"/></svg>'
20315
- : ''}
20316
- </span>
20317
- <span class="svu-step-text">${step.text}</span>
20318
- </div>
20319
- `;
20320
- });
20321
- div.innerHTML = `
20322
- <h2 class="svu-title">Securing Your File</h2>
20323
-
20324
- <div class="svu-ceremony-steps">
20325
- ${stepsHtml}
20326
- </div>
20327
-
20328
- <div class="svu-forging-info">
20329
- <p class="svu-forging-line">Forging Ingot ID: <span class="svu-mono">${displayIngotId}</span></p>
20444
+ <p class="svu-forging-line">Forging Ingot ID: <span class="svu-mono">${escapeHtml(state.ingotId)}</span></p>
20330
20445
  ${transferChannelLine(state.requestId)}
20331
20446
  </div>
20332
20447
  `;
20448
+ // Stopping is offered while the bytes move. Once every byte is sent the
20449
+ // save is SparkVault's to finish, so a cancel could not promise the file
20450
+ // was not kept.
20451
+ if (!state.securing) {
20452
+ const cancel = document.createElement('button');
20453
+ cancel.type = 'button';
20454
+ cancel.className = 'svu-btn svu-btn-secondary svu-cancel-upload';
20455
+ cancel.textContent = 'Cancel upload';
20456
+ cancel.addEventListener('click', () => this.cancelUpload());
20457
+ div.appendChild(cancel);
20458
+ }
20333
20459
  return div;
20334
20460
  }
20335
20461
  renderComplete(result, config) {
20336
20462
  const div = document.createElement('div');
20337
20463
  div.className = 'svu-complete-view';
20338
20464
  div.innerHTML = `
20339
- <div class="svu-success-icon">
20465
+ <div class="svu-success-icon" aria-hidden="true">
20340
20466
  <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20341
20467
  <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
20342
20468
  <path d="M22 4L12 14.01l-3-3"/>
20343
20469
  </svg>
20344
20470
  </div>
20345
20471
 
20346
- <h2 class="svu-success-title">Your file has been securely sent!</h2>
20472
+ <h2 class="svu-success-title" tabindex="-1">File sent securely</h2>
20347
20473
 
20348
20474
  <div class="svu-success-details">
20349
20475
  <div class="svu-success-row">
20350
20476
  <span class="svu-success-label">Ingot ID</span>
20351
20477
  <span class="svu-success-value svu-mono">
20352
20478
  ${escapeHtml(result.ingotId)}
20353
- <button class="svu-copy-btn" aria-label="Copy Ingot ID">
20354
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
20479
+ <button type="button" class="svu-copy-btn" aria-label="Copy Ingot ID">
20480
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
20355
20481
  <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
20356
20482
  <path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
20357
20483
  </svg>
20358
20484
  </button>
20359
20485
  </span>
20360
20486
  </div>
20487
+ <p class="svu-copy-status" role="status"></p>
20361
20488
  <div class="svu-success-row">
20362
20489
  <span class="svu-success-label">File</span>
20363
20490
  <span class="svu-success-value">${escapeHtml(result.filename)}</span>
@@ -20377,34 +20504,62 @@ class UploadRenderer {
20377
20504
  </div>
20378
20505
 
20379
20506
  <p class="svu-success-guidance">
20380
- ${escapeHtml(config.branding.organizationName)} has been notified and can access this file
20381
- from their SparkVault dashboard. Save the Ingot ID above for your records.
20507
+ ${escapeHtml(config.branding.organizationName)} can open this file in SparkVault.
20508
+ Save the Ingot ID above for your records.
20382
20509
  </p>
20383
-
20384
- ${this.options.hideUploadAnother ? '' : `
20385
- <button class="svu-btn svu-btn-secondary">
20386
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
20387
- <path d="M1 4v6h6M23 20v-6h-6"/>
20388
- <path d="M20.49 9A9 9 0 005.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 013.51 15"/>
20389
- </svg>
20390
- Upload Another File
20391
- </button>
20392
- `}
20393
20510
  `;
20394
- // Copy button handler
20395
20511
  const copyBtn = div.querySelector('.svu-copy-btn');
20396
- if (copyBtn) {
20397
- copyBtn.addEventListener('click', () => {
20398
- navigator.clipboard.writeText(result.ingotId);
20399
- });
20512
+ const copyStatus = div.querySelector('.svu-copy-status');
20513
+ if (copyBtn && copyStatus) {
20514
+ copyBtn.addEventListener('click', () => this.copyIngotId(result.ingotId, copyStatus));
20400
20515
  }
20401
- // Upload another handler (only if button exists)
20402
- const uploadAnotherBtn = div.querySelector('.svu-btn-secondary');
20403
- if (uploadAnotherBtn) {
20404
- uploadAnotherBtn.addEventListener('click', () => {
20405
- this.selectedFile = null;
20406
- this.setState({ view: 'form', config });
20407
- });
20516
+ if (!this.options.hideUploadAnother) {
20517
+ div.appendChild(this.recoveryButton({ label: 'Upload another file', keepFile: false }, config, 'svu-btn-secondary'));
20518
+ }
20519
+ return div;
20520
+ }
20521
+ /**
20522
+ * Copy the Ingot ID, saying beside it that it landed ("Copied", for
20523
+ * COPIED_SHOWS_MS) or that the browser refused it, and how to take the ID
20524
+ * instead. A browser without the clipboard API refuses like one that denies
20525
+ * it.
20526
+ */
20527
+ async copyIngotId(ingotId, status) {
20528
+ try {
20529
+ await navigator.clipboard.writeText(ingotId);
20530
+ }
20531
+ catch {
20532
+ status.textContent = COPY_REFUSED_MESSAGE;
20533
+ return;
20534
+ }
20535
+ status.textContent = 'Copied';
20536
+ setTimeout(() => {
20537
+ if (status.textContent === 'Copied')
20538
+ status.textContent = '';
20539
+ }, COPIED_SHOWS_MS);
20540
+ }
20541
+ /**
20542
+ * A file whose every byte reached SparkVault, which is still saving it and
20543
+ * finishes on its own: received, never failed, so it reads as an outcome,
20544
+ * with the way on to another file.
20545
+ */
20546
+ renderReceived(message, action) {
20547
+ const div = document.createElement('div');
20548
+ div.className = 'svu-complete-view';
20549
+ div.innerHTML = `
20550
+ <div class="svu-success-icon" aria-hidden="true">
20551
+ <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20552
+ <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
20553
+ <path d="M22 4L12 14.01l-3-3"/>
20554
+ </svg>
20555
+ </div>
20556
+
20557
+ <h2 class="svu-success-title" tabindex="-1">File received</h2>
20558
+
20559
+ <p class="svu-success-guidance">${escapeHtml(message)}</p>
20560
+ `;
20561
+ if (action && this.config && !this.options.hideUploadAnother) {
20562
+ div.appendChild(this.recoveryButton(action, this.config, 'svu-btn-secondary'));
20408
20563
  }
20409
20564
  return div;
20410
20565
  }
@@ -20412,38 +20567,47 @@ class UploadRenderer {
20412
20567
  const div = document.createElement('div');
20413
20568
  div.className = 'svu-error-view';
20414
20569
  div.innerHTML = `
20415
- <div class="svu-error-icon">
20570
+ <div class="svu-error-icon" aria-hidden="true">
20416
20571
  <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
20417
20572
  <circle cx="12" cy="12" r="10"/>
20418
20573
  <path d="M12 8v4M12 16h.01"/>
20419
20574
  </svg>
20420
20575
  </div>
20421
20576
 
20422
- <h2 class="svu-error-title">${escapeHtml(state.title)}</h2>
20577
+ <h2 class="svu-error-title" tabindex="-1">${escapeHtml(state.title)}</h2>
20423
20578
 
20424
20579
  <p class="svu-error-message">${escapeHtml(state.message)}</p>
20425
-
20426
- <div class="svu-error-code">
20427
- <span class="svu-error-code-label">Code</span>
20428
- <span class="svu-error-code-value">${escapeHtml(state.code)}</span>
20429
- </div>
20430
20580
  `;
20431
- const { action } = state;
20432
- if (action && this.config) {
20433
- const config = this.config;
20434
- const recover = document.createElement('button');
20435
- recover.className = 'svu-btn svu-btn-primary';
20436
- recover.textContent = action.label;
20437
- recover.addEventListener('click', () => {
20438
- if (!action.keepFile)
20439
- this.selectedFile = null;
20440
- this.setState({ view: 'form', config });
20441
- });
20442
- div.appendChild(recover);
20581
+ if (state.action && this.config) {
20582
+ div.appendChild(this.recoveryButton(state.action, this.config, 'svu-btn-primary'));
20443
20583
  }
20444
20584
  return div;
20445
20585
  }
20586
+ /** The button that takes the person back to the form, with or without the chosen file. */
20587
+ recoveryButton(action, config, variant) {
20588
+ const button = document.createElement('button');
20589
+ button.type = 'button';
20590
+ button.className = `svu-btn ${variant}`;
20591
+ button.textContent = action.label;
20592
+ button.addEventListener('click', () => {
20593
+ if (!action.keepFile)
20594
+ this.selectedFile = null;
20595
+ this.setState({ view: 'form', config });
20596
+ });
20597
+ return button;
20598
+ }
20599
+ /**
20600
+ * Whether a file the person drops, picks, pastes or removes counts: only on
20601
+ * the form, and only while no upload runs (uploadInFlight). The paste
20602
+ * listener hears the whole page in every view, and a file it took mid-upload
20603
+ * would start a second upload beside the first.
20604
+ */
20605
+ formTakesFile() {
20606
+ return this.viewState.view === 'form' && !this.uploadInFlight;
20607
+ }
20446
20608
  handleFileSelect(file, config) {
20609
+ if (!this.formTakesFile())
20610
+ return;
20447
20611
  if (file.size === 0) {
20448
20612
  this.setState({ view: 'form', config, error: EMPTY_FILE_MESSAGE });
20449
20613
  return;
@@ -20483,6 +20647,8 @@ class UploadRenderer {
20483
20647
  setupPasteHandler(config) {
20484
20648
  // Remove any existing handler first
20485
20649
  this.cleanupPasteHandler();
20650
+ // It hears the page's every paste, in every view: handleFileSelect takes
20651
+ // the file only where the form does (formTakesFile).
20486
20652
  this.pasteHandler = (e) => {
20487
20653
  const items = e.clipboardData?.items;
20488
20654
  if (!items)
@@ -20506,12 +20672,18 @@ class UploadRenderer {
20506
20672
  }
20507
20673
  }
20508
20674
  async startUpload(config) {
20509
- if (!this.selectedFile)
20675
+ if (!this.selectedFile || this.uploadInFlight)
20510
20676
  return;
20511
20677
  const file = this.selectedFile;
20678
+ const generation = ++this.uploadGeneration;
20679
+ const current = () => generation === this.uploadGeneration;
20680
+ this.uploadInFlight = true;
20681
+ this.holdPage(true);
20512
20682
  try {
20513
20683
  // Initiate upload. Its Core request id names the transfer channel shown.
20514
20684
  const { forgeUrl, ingotId, requestId } = await this.api.initiateUpload(config.vaultId, file.name, file.size, file.type || 'application/octet-stream', this.options.token, this.options.folder);
20685
+ if (!current())
20686
+ return;
20515
20687
  // Show uploading state
20516
20688
  this.setState({
20517
20689
  view: 'uploading',
@@ -20520,12 +20692,20 @@ class UploadRenderer {
20520
20692
  requestId,
20521
20693
  progress: 0,
20522
20694
  bytesUploaded: 0,
20695
+ securing: false,
20523
20696
  });
20524
20697
  // Upload file over the canonical TUS transfer path. It resolves only
20525
20698
  // once the server has confirmed finalization, so a non-finalized upload
20526
- // throws here and never reaches the success ceremony.
20699
+ // throws here and never reaches the success view.
20527
20700
  await this.api.uploadFileToForge(file, forgeUrl, (bytesUploaded, bytesTotal) => {
20701
+ if (!current())
20702
+ return;
20528
20703
  const progress = Math.round((bytesUploaded / bytesTotal) * 100);
20704
+ // Every byte sent: the server may hold, and publish, the whole file
20705
+ // now, so a cancel could no longer promise it was not kept. The count
20706
+ // is the transfer's high-water mark, which never runs backwards, so a
20707
+ // last chunk resent after its answer was lost still reads as sent.
20708
+ const securing = bytesUploaded >= bytesTotal;
20529
20709
  this.setState({
20530
20710
  view: 'uploading',
20531
20711
  file,
@@ -20533,7 +20713,9 @@ class UploadRenderer {
20533
20713
  requestId,
20534
20714
  progress,
20535
20715
  bytesUploaded,
20716
+ securing,
20536
20717
  });
20718
+ // The phase stays 'uploading' until SparkVault confirms the save.
20537
20719
  this.callbacks.onProgress?.({
20538
20720
  bytesUploaded,
20539
20721
  bytesTotal,
@@ -20541,8 +20723,9 @@ class UploadRenderer {
20541
20723
  phase: 'uploading',
20542
20724
  });
20543
20725
  });
20544
- // Run ceremony animation
20545
- await this.runCeremony(file, ingotId, requestId);
20726
+ if (!current())
20727
+ return;
20728
+ this.holdPage(false);
20546
20729
  // Complete
20547
20730
  const now = new Date();
20548
20731
  const uploadTime = `${now.getUTCFullYear()}-${String(now.getUTCMonth() + 1).padStart(2, '0')}-${String(now.getUTCDate()).padStart(2, '0')} ${String(now.getUTCHours()).padStart(2, '0')}:${String(now.getUTCMinutes()).padStart(2, '0')}:${String(now.getUTCSeconds()).padStart(2, '0')} UTC`;
@@ -20553,13 +20736,11 @@ class UploadRenderer {
20553
20736
  sizeBytes: file.size,
20554
20737
  uploadTime,
20555
20738
  };
20556
- // Notify complete phase
20557
- this.callbacks.onProgress?.({
20558
- bytesUploaded: file.size,
20559
- bytesTotal: file.size,
20560
- percentage: 100,
20561
- phase: 'complete',
20562
- });
20739
+ // SparkVault confirmed the save: a host reads 'ceremony' as that
20740
+ // confirmation, then 'complete' as the upload's end (UploadProgress).
20741
+ const sent = { bytesUploaded: file.size, bytesTotal: file.size, percentage: 100 };
20742
+ this.callbacks.onProgress?.({ ...sent, phase: 'ceremony' });
20743
+ this.callbacks.onProgress?.({ ...sent, phase: 'complete' });
20563
20744
  // Silent mode: skip the success screen — fire onSuccess and close so
20564
20745
  // the host site can render its own post-upload UI.
20565
20746
  if (this.options.hideSuccessScreen) {
@@ -20572,43 +20753,65 @@ class UploadRenderer {
20572
20753
  this.callbacks.onSuccess(result);
20573
20754
  }
20574
20755
  catch (error) {
20756
+ if (!current())
20757
+ return;
20758
+ this.holdPage(false);
20575
20759
  // A host that chose the file itself offers its own way on; the
20576
20760
  // widget's form is the way on only for a file chosen on it.
20577
20761
  this.handleApiError(error, this.options.file ? null : recoveryAfterUpload(error));
20578
20762
  }
20763
+ finally {
20764
+ // A cancelled upload's number is no longer current: cancelUpload ended
20765
+ // it, and another may already run.
20766
+ if (current())
20767
+ this.uploadInFlight = false;
20768
+ }
20579
20769
  }
20580
- async runCeremony(file, ingotId, requestId) {
20581
- for (let i = 0; i < CEREMONY_STEPS.length; i++) {
20582
- this.setState({
20583
- view: 'ceremony',
20584
- file,
20585
- ingotId,
20586
- requestId,
20587
- step: i,
20588
- complete: false,
20589
- });
20590
- this.callbacks.onProgress?.({
20591
- bytesUploaded: file.size,
20592
- bytesTotal: file.size,
20593
- percentage: 100,
20594
- phase: 'ceremony',
20595
- });
20596
- await new Promise(resolve => setTimeout(resolve, CEREMONY_STEPS[i].duration));
20770
+ /**
20771
+ * Stop the upload whose bytes are moving. The stopped upload's late events
20772
+ * render nothing and tell the host nothing (uploadGeneration).
20773
+ *
20774
+ * A file the host chose itself skipped the form, so its upload ends the
20775
+ * widget through the cancel contract (cancel(): the transfer aborted with
20776
+ * the session, onCancel, UserCancelledError), and the host offers its own
20777
+ * way on. A file chosen on the widget returns to the form, still chosen, so
20778
+ * a wrong or slow pick costs one tap: the transfer is aborted with the
20779
+ * session's signal, a fresh session serves the next upload, and neither
20780
+ * callback fires, since the widget stays open and the host hears of the
20781
+ * next upload.
20782
+ */
20783
+ cancelUpload() {
20784
+ if (this.viewState.view !== 'uploading' || this.viewState.securing || !this.config)
20785
+ return;
20786
+ this.uploadGeneration += 1;
20787
+ this.uploadInFlight = false;
20788
+ if (this.options.file) {
20789
+ this.cancel();
20790
+ return;
20597
20791
  }
20598
- // Mark complete
20599
- this.setState({
20600
- view: 'ceremony',
20601
- file,
20602
- ingotId,
20603
- requestId,
20604
- step: CEREMONY_STEPS.length,
20605
- complete: true,
20606
- });
20607
- await new Promise(resolve => setTimeout(resolve, 500));
20792
+ this.api.abort();
20793
+ this.api.resetSession();
20794
+ this.holdPage(false);
20795
+ this.setState({ view: 'form', config: this.config });
20608
20796
  }
20609
20797
  /**
20610
- * Show a failure in the error view, with the way on it offers (`action`:
20611
- * none for a page that could not load), and tell the host through onError.
20798
+ * Ask before the page is closed or reloaded while an upload runs
20799
+ * (this.warnBeforeLeaving), or stop asking.
20800
+ */
20801
+ holdPage(hold) {
20802
+ if (hold) {
20803
+ window.addEventListener('beforeunload', this.warnBeforeLeaving);
20804
+ }
20805
+ else {
20806
+ window.removeEventListener('beforeunload', this.warnBeforeLeaving);
20807
+ }
20808
+ }
20809
+ /**
20810
+ * Show a failure (`action`: the way on it offers, none for a page that
20811
+ * could not load), and tell the host through onError. A file received whole
20812
+ * and still being saved reads as received, never as a failure; the host
20813
+ * still hears it through onError, with its code, which tells it never to
20814
+ * upload the file again.
20612
20815
  */
20613
20816
  handleApiError(error, action = null) {
20614
20817
  // A closed renderer must not surface errors: cancelling mid-transfer
@@ -20619,116 +20822,14 @@ class UploadRenderer {
20619
20822
  if (this.closed || isCancellationError(error)) {
20620
20823
  return;
20621
20824
  }
20622
- if (error instanceof UploadApiError) {
20623
- if (error.code === 'UPLOAD_SOURCE_DISABLED') {
20624
- // The vault exists but the embedded widget isn't enabled.
20625
- // This is almost always a developer/admin oversight, so the message
20626
- // points at the dashboard rather than the end user.
20627
- this.setState({
20628
- view: 'error',
20629
- action,
20630
- title: 'Upload Widget Not Enabled',
20631
- message: 'This vault has not enabled the embedded upload widget. Enable it on the vault\'s settings page in the SparkVault dashboard to start accepting uploads here.',
20632
- code: 'UPLOAD_SOURCE_DISABLED',
20633
- statusCode: error.statusCode,
20634
- });
20635
- }
20636
- else if (error.code === RECEIVED_STILL_SAVING) {
20637
- // Every byte reached the server, which is still saving the file and
20638
- // finishes it on its own: nothing failed, and nothing is left to do.
20639
- // The host still hears it through onError, with this code, which
20640
- // tells it never to upload the file again.
20641
- this.setState({
20642
- view: 'error',
20643
- action,
20644
- title: 'Upload Received',
20645
- message: error.message,
20646
- code: error.code,
20647
- statusCode: error.statusCode,
20648
- });
20649
- }
20650
- else if (error.code === VAULT_DELETION_SCHEDULED || error.details?.coreCode === VAULT_DELETION_SCHEDULED) {
20651
- // The vault is scheduled for deletion, refused at the upload's start
20652
- // or while its bytes moved. Core's sentence tells the vault's admin
20653
- // how to cancel the deletion; the person on this page is an outside
20654
- // uploader, told only that the vault takes no files now.
20655
- this.setState({
20656
- view: 'error',
20657
- action,
20658
- title: 'Uploads Paused',
20659
- message: VAULT_NOT_ACCEPTING_MESSAGE,
20660
- code: error.code,
20661
- statusCode: error.statusCode,
20662
- });
20663
- }
20664
- else if (error.code === 'upload_refused') {
20665
- // Core refused the upload, in its own words (whom to contact about a
20666
- // full storage pool, or the later upload that replaced this one): a
20667
- // sentence that never asks for the file again.
20668
- this.setState({
20669
- view: 'error',
20670
- action,
20671
- title: 'Upload Not Saved',
20672
- message: error.message,
20673
- code: error.code,
20674
- statusCode: error.statusCode,
20675
- });
20676
- }
20677
- else if (error.statusCode === 404 && error.code !== 'session_gone') {
20678
- // A vault or upload route that does not exist. A gone upload session
20679
- // can answer 404 too, and its own sentence says what became of the file.
20680
- this.setState({
20681
- view: 'error',
20682
- action,
20683
- title: 'Upload Page Not Found',
20684
- message: 'The requested upload endpoint could not be located. This may occur if the upload link has expired or was entered incorrectly.',
20685
- code: 'NOT_FOUND',
20686
- statusCode: 404,
20687
- });
20688
- }
20689
- else if (error.statusCode === 402) {
20690
- this.setState({
20691
- view: 'error',
20692
- action,
20693
- title: 'Service Unavailable',
20694
- message: 'This upload endpoint has been temporarily disabled due to an account billing issue. Please contact the organization\'s administrator.',
20695
- code: 'PAYMENT_REQUIRED',
20696
- statusCode: 402,
20697
- });
20698
- }
20699
- else {
20700
- this.setState({
20701
- view: 'error',
20702
- action,
20703
- title: 'Upload Failed',
20704
- message: error.message,
20705
- code: error.code,
20706
- statusCode: error.statusCode,
20707
- });
20708
- }
20709
- this.callbacks.onError(error);
20710
- }
20711
- else if (error instanceof Error) {
20712
- this.setState({
20713
- view: 'error',
20714
- action,
20715
- title: 'Upload Failed',
20716
- message: error.message,
20717
- code: 'UNKNOWN_ERROR',
20718
- });
20719
- this.callbacks.onError(error);
20825
+ const failure = error instanceof Error ? error : new Error('An unexpected error occurred');
20826
+ if (failure instanceof UploadApiError && failure.code === RECEIVED_STILL_SAVING) {
20827
+ this.setState({ view: 'received', message: failure.message, action });
20720
20828
  }
20721
20829
  else {
20722
- const err = new Error('An unexpected error occurred');
20723
- this.setState({
20724
- view: 'error',
20725
- action,
20726
- title: 'Upload Failed',
20727
- message: err.message,
20728
- code: 'UNKNOWN_ERROR',
20729
- });
20730
- this.callbacks.onError(err);
20830
+ this.setState({ view: 'error', action, ...describeFailure(failure) });
20731
20831
  }
20832
+ this.callbacks.onError(failure);
20732
20833
  }
20733
20834
  }
20734
20835
 
@@ -22105,7 +22206,7 @@ class SparkVault {
22105
22206
  }
22106
22207
  /** Get the SDK version */
22107
22208
  static get version() {
22108
- return '15.1.0';
22209
+ return '15.1.1';
22109
22210
  }
22110
22211
  }
22111
22212
  if (typeof window !== 'undefined') {