box-content-preview 3.94.0 → 3.96.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Mergify Status](https://img.shields.io/endpoint.svg?url=https://gh.mergify.io/badges/box/box-content-preview&style=flat)](https://mergify.io)
3
3
  [![Styled With Prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
4
4
  [![build status](https://img.shields.io/travis/box/box-content-preview/master.svg?style=flat-square)](https://travis-ci.org/box/box-content-preview)
5
- [![version](https://img.shields.io/badge/version-v3.94.0-blue.svg?style=flat-square)](https://github.com/box/box-content-preview)
5
+ [![version](https://img.shields.io/badge/version-v3.96.0-blue.svg?style=flat-square)](https://github.com/box/box-content-preview)
6
6
  [![npm version](https://img.shields.io/npm/v/box-ui-elements.svg?style=flat-square)](https://www.npmjs.com/package/box-ui-elements)
7
7
 
8
8
  # [Box Content Preview](https://developer.box.com/docs/box-content-preview)
@@ -22,11 +22,11 @@ We encourage all users to update their applications to utilize modern browsers f
22
22
 
23
23
  ## Current Version
24
24
 
25
- - Version: v3.94.0
25
+ - Version: v3.96.0
26
26
  - Locale: en-US
27
27
 
28
- https://cdn01.boxcdn.net/platform/preview/3.94.0/en-US/preview.js
29
- https://cdn01.boxcdn.net/platform/preview/3.94.0/en-US/preview.css
28
+ https://cdn01.boxcdn.net/platform/preview/3.96.0/en-US/preview.js
29
+ https://cdn01.boxcdn.net/platform/preview/3.96.0/en-US/preview.css
30
30
 
31
31
  ## Supported Locales
32
32
 
@@ -52,10 +52,10 @@ You can self-host the Box Content Preview library or reference the versions avai
52
52
  <title>Box Content Preview Demo</title>
53
53
 
54
54
  <!-- Latest version of Preview SDK for your locale -->
55
- <script src="https://cdn01.boxcdn.net/platform/preview/3.94.0/en-US/preview.js"></script>
55
+ <script src="https://cdn01.boxcdn.net/platform/preview/3.96.0/en-US/preview.js"></script>
56
56
  <link
57
57
  rel="stylesheet"
58
- href="https://cdn01.boxcdn.net/platform/preview/3.94.0/en-US/preview.css"
58
+ href="https://cdn01.boxcdn.net/platform/preview/3.96.0/en-US/preview.css"
59
59
  />
60
60
  </head>
61
61
  <body>
@@ -76,7 +76,7 @@ To self-host the Box Content Preview library, follow these steps:
76
76
 
77
77
  1. Either fork the repo and check out the version you want to host or download the specific version as a zip:
78
78
 
79
- - Check out a specific version with `git checkout v3.94.0`
79
+ - Check out a specific version with `git checkout v3.96.0`
80
80
  - Download a specific version as a zip from https://github.com/box/box-content-preview/releases
81
81
 
82
82
  2. Install dependencies and build the library with `yarn install && yarn build:i18n && yarn build:prod`
package/dist/lib/index.js CHANGED
@@ -314,6 +314,7 @@ class PreviewError extends Error {
314
314
  /* harmony export */ Ci: () => (/* binding */ CLASS_BOX_PREVIEW_VIDEO_PRELOAD_PLAY_OVERLAY),
315
315
  /* harmony export */ D4: () => (/* binding */ CLASS_ANNOTATIONS_VIDEO_FTUX_CURSOR_SEEN),
316
316
  /* harmony export */ EP: () => (/* binding */ ORIGINAL_REP_NAME),
317
+ /* harmony export */ Ed: () => (/* binding */ BLUEPRINT_MIGRATION_SUPPORTING_UI),
317
318
  /* harmony export */ Ev: () => (/* binding */ BROWSERS),
318
319
  /* harmony export */ FD: () => (/* binding */ SELECTOR_BOX_PREVIEW_LOGO_DEFAULT),
319
320
  /* harmony export */ GA: () => (/* binding */ ANNOTATOR_EVENT),
@@ -337,6 +338,7 @@ class PreviewError extends Error {
337
338
  /* harmony export */ Mi: () => (/* binding */ PDFJS_CSS_UNITS),
338
339
  /* harmony export */ Mj: () => (/* binding */ CLASS_BOX_PREVIEW_THUMBNAILS_CLOSE_ACTIVE),
339
340
  /* harmony export */ N7: () => (/* binding */ DISCOVERABILITY_ATTRIBUTE),
341
+ /* harmony export */ OQ: () => (/* binding */ BLUEPRINT_MIGRATION_CONTROLS_BAR),
340
342
  /* harmony export */ OW: () => (/* binding */ PRELOAD_REP_NAME),
341
343
  /* harmony export */ Oo: () => (/* binding */ CLASS_ANNOTATIONS_CREATE_REGION),
342
344
  /* harmony export */ P8: () => (/* binding */ CLASS_BOX_PREVIEW_HAS_HEADER),
@@ -367,9 +369,11 @@ class PreviewError extends Error {
367
369
  /* harmony export */ bE: () => (/* binding */ SELECTOR_BOX_PREVIEW_CONTENT),
368
370
  /* harmony export */ br: () => (/* binding */ FILE_OPTION_FILE_VERSION_ID),
369
371
  /* harmony export */ c6: () => (/* binding */ PRELOAD_PAGED_REP_NAME),
372
+ /* harmony export */ cA: () => (/* binding */ BLUEPRINT_MIGRATION_ARCHIVE),
370
373
  /* harmony export */ cP: () => (/* binding */ CLASS_BOX_PREVIEW_PRELOAD_WRAPPER_VIDEO),
371
374
  /* harmony export */ cR: () => (/* binding */ TEXT_STATIC_ASSETS_VERSION),
372
375
  /* harmony export */ cZ: () => (/* binding */ CLASS_ANNOTATIONS_DISCOVERABLE),
376
+ /* harmony export */ dR: () => (/* binding */ BLUEPRINT_MIGRATION_MEDIA_CONTROLS),
373
377
  /* harmony export */ eA: () => (/* binding */ SUBTITLES_OFF),
374
378
  /* harmony export */ eF: () => (/* binding */ CLASS_BOX_PREVIEW_PRELOAD_CONTENT),
375
379
  /* harmony export */ eM: () => (/* binding */ CLASS_BOX_PREVIEW_HAS_NAVIGATION),
@@ -525,6 +529,13 @@ const X_REP_HINT_VIDEO_MP4 = '[mp4]';
525
529
  const X_REP_HINT_WAVEFORM = '[waveform]';
526
530
  const AI_TRANSCRIPTION_FOR_VIDEO_SUBTITLES = 'aiTranscriptionForVideoSubtitles';
527
531
  const AUDIO_PLAYER_V2 = 'audioPlayerV2.enabled';
532
+
533
+ // One per wave of the Blueprint migration. Each is reported as its own metric dimension so a
534
+ // dashboard can compare a wave's timings with its flag on against the same wave with it off.
535
+ const BLUEPRINT_MIGRATION_ARCHIVE = 'blueprintMigrationArchive.enabled';
536
+ const BLUEPRINT_MIGRATION_CONTROLS_BAR = 'blueprintMigrationControlsBar.enabled';
537
+ const BLUEPRINT_MIGRATION_MEDIA_CONTROLS = 'blueprintMigrationMediaControls.enabled';
538
+ const BLUEPRINT_MIGRATION_SUPPORTING_UI = 'blueprintMigrationSupportingUi.enabled';
528
539
  const PDFJS_CSS_UNITS = 96.0 / 72.0; // Should match CSS_UNITS in pdf_viewer.js
529
540
  const PDFJS_MAX_AUTO_SCALE = 1.25; // Should match MAX_AUTO_SCALE in pdf_viewer.js
530
541
  const PDFJS_WIDTH_PADDING_PX = 40; // Should match SCROLLBAR_PADDING in pdf_viewer.js
@@ -1018,7 +1029,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
1018
1029
  const CLIENT_NAME = "box-content-preview"; // eslint-disable-line no-undef
1019
1030
  const CLIENT_NAME_KEY = 'box_client_name';
1020
1031
  const CLIENT_VERSION_KEY = 'box_client_version';
1021
- const CLIENT_VERSION = "3.94.0"; // eslint-disable-line no-undef
1032
+ const CLIENT_VERSION = "3.96.0"; // eslint-disable-line no-undef
1022
1033
  const HEADER_CLIENT_NAME = 'X-Box-Client-Name';
1023
1034
  const HEADER_CLIENT_VERSION = 'X-Box-Client-Version';
1024
1035
  const PROMISE_MAP = {};
@@ -24650,7 +24661,7 @@ class Browser {
24650
24661
  ;// ./src/lib/Logger.js
24651
24662
  /* eslint-disable no-undef */
24652
24663
  const CLIENT_NAME = "box-content-preview";
24653
- const CLIENT_VERSION = "3.94.0";
24664
+ const CLIENT_VERSION = "3.96.0";
24654
24665
  /* eslint-enable no-undef */
24655
24666
 
24656
24667
  class Logger {
@@ -55034,18 +55045,15 @@ const LOG_RETRY_COUNT = 3; // number of times to retry logging preview event
55034
55045
  const MS_IN_S = 1000; // ms in a sec
55035
55046
  const SUPPORT_URL = 'https://support.box.com';
55036
55047
 
55037
- // All preview assets are relative to preview.js. Here we create a location
55038
- // object that mimics the window location object and points to where
55039
- // preview.js is loaded from by the browser. This needs to be done statically
55040
- // outside the class so that location is found while this script is executing
55041
- // and not when preview is instantiated, which is too late.
55042
- // findScriptLocation throws when there is no preview.js <script> tag in the DOM;
55043
- // npm consumers have no such tag and populate this via Preview.show({ location }).
55044
- let PREVIEW_LOCATION;
55045
- try {
55046
- PREVIEW_LOCATION = (0,util/* findScriptLocation */.Is)(constants/* PREVIEW_SCRIPT_NAME */.Lq, document.currentScript);
55047
- } catch (e) {
55048
- PREVIEW_LOCATION = {};
55048
+ // document.currentScript is this file only while it evaluates.
55049
+ const IS_NPM_BUILD = true && true;
55050
+ let PREVIEW_LOCATION = {};
55051
+ if (!IS_NPM_BUILD) {
55052
+ try {
55053
+ PREVIEW_LOCATION = (0,util/* findScriptLocation */.Is)(constants/* PREVIEW_SCRIPT_NAME */.Lq, document.currentScript);
55054
+ } catch (e) {
55055
+ PREVIEW_LOCATION = {};
55056
+ }
55049
55057
  }
55050
55058
  class Preview extends (events_default()) {
55051
55059
  //--------------------------------------------------------------------------
@@ -55116,10 +55124,6 @@ class Preview extends (events_default()) {
55116
55124
  DEFAULT_DISABLED_VIEWERS.forEach(viewerName => {
55117
55125
  this.disabledViewers[viewerName] = 1;
55118
55126
  });
55119
-
55120
- // All preview assets are relative to preview.js. Here we create a location
55121
- // object that mimics the window location object and points to where
55122
- // preview.js is loaded from by the browser.
55123
55127
  this.location = PREVIEW_LOCATION;
55124
55128
  this.cache = new lib_Cache();
55125
55129
  this.ui = new lib_PreviewUI();
@@ -55188,11 +55192,11 @@ class Preview extends (events_default()) {
55188
55192
  // But it cannot be a random object.
55189
55193
  if (token === null || typeof token !== 'object') {
55190
55194
  // npm consumers have no CDN-served pdfjs at runtime; force the bundled npm pdfjs path.
55191
- const finalOptions = true ? Preview_objectSpread(Preview_objectSpread({}, options), {}, {
55195
+ const finalOptions = IS_NPM_BUILD ? Preview_objectSpread(Preview_objectSpread({}, options), {}, {
55192
55196
  features: Preview_objectSpread({
55193
55197
  useNpmPdfjs: true
55194
55198
  }, options.features || {})
55195
- }) : 0;
55199
+ }) : options;
55196
55200
  this.previewOptions = Preview_objectSpread(Preview_objectSpread({}, finalOptions), {}, {
55197
55201
  token
55198
55202
  });
@@ -55210,6 +55214,11 @@ class Preview extends (events_default()) {
55210
55214
  // Parse the preview options
55211
55215
  this.parseOptions(this.previewOptions);
55212
55216
 
55217
+ // /preview.js parses to locale ''. Throw only when locale is absent.
55218
+ if ((0,util/* getProp */.GT)(this.location, 'locale') == null) {
55219
+ throw new Error('Missing preview location. Load preview.js, or pass location to show().');
55220
+ }
55221
+
55213
55222
  // Load the preview
55214
55223
  this.load(fileIdOrFile);
55215
55224
  }
@@ -56123,11 +56132,18 @@ class Preview extends (events_default()) {
56123
56132
  loadFromCache() {
56124
56133
  // Log cache hit
56125
56134
  this.logger.setCached();
56126
-
56127
- // Finally load the viewer
56128
- this.loadViewer();
56129
56135
  const needsVideoReps = this.isVideoFileByExtension() && !this.hasPlayableVideoReps(this.file);
56130
- if (!this.options.skipServerUpdate || needsVideoReps) {
56136
+ const needsTranscriptionRep = isFeatureEnabled(this.options.features, constants/* AI_TRANSCRIPTION_FOR_VIDEO_SUBTITLES */.Iu) && this.isVideoFileByExtension() && !this.hasTranscriptionRep(this.file);
56137
+ // Captions are optional — do not treat a missing extracted_text rep like missing
56138
+ // dash/mp4. skipServerUpdate still skips this refresh; default reopen already
56139
+ // calls loadFromServer() because skipServerUpdate is false.
56140
+ const needsServerRefresh = !this.options.skipServerUpdate || needsVideoReps || needsTranscriptionRep;
56141
+
56142
+ // Play from cache immediately. Default reopen still refreshes file info in the
56143
+ // background; handleFileInfoResponse then updates the live viewer if extracted_text
56144
+ // arrived. A failed captions-only refresh must not uncache or destroy playback.
56145
+ this.loadViewer();
56146
+ if (needsServerRefresh) {
56131
56147
  this.loadFromServer();
56132
56148
  }
56133
56149
  }
@@ -56158,7 +56174,14 @@ class Preview extends (events_default()) {
56158
56174
  const fileInfoUrl = (0,util/* appendQueryParams */.Ne)(getURL(this.file.id, fileVersionId, apiHost), params);
56159
56175
  this.api.get(fileInfoUrl, {
56160
56176
  headers: this.getRequestHeaders()
56161
- }).then(this.handleFileInfoResponse).catch(this.handleFetchError);
56177
+ }).then(this.handleFileInfoResponse).catch(err => {
56178
+ // Captions are optional. If a cache-hit viewer is already playing dash/mp4,
56179
+ // a failed background file-info refresh must not uncache or triggerError.
56180
+ if (this.viewer && this.hasPlayableVideoReps(this.file)) {
56181
+ return;
56182
+ }
56183
+ this.handleFetchError(err);
56184
+ });
56162
56185
  }
56163
56186
 
56164
56187
  /**
@@ -56249,6 +56272,7 @@ class Preview extends (events_default()) {
56249
56272
  if (this.isVideoFileByExtension() && !this.hasPlayableVideoReps(file)) {
56250
56273
  throw new PreviewError/* default */.A(lib_events/* ERROR_CODE */.bo.ACCOUNT, "This preview didn’t load because your account is unable to preview this file type. Please try to open or download the file to view.");
56251
56274
  }
56275
+ const needsTranscriptionReload = this.canUseDash() && isFeatureEnabled(this.options.features, constants/* AI_TRANSCRIPTION_FOR_VIDEO_SUBTITLES */.Iu) && this.isVideoFileByExtension() && !this.hasTranscriptionRep(cachedFile) && this.hasTranscriptionRep(file);
56252
56276
 
56253
56277
  // Should load viewer for first time if:
56254
56278
  // - File isn't cached OR
@@ -56262,6 +56286,18 @@ class Preview extends (events_default()) {
56262
56286
  } else if (cachedFile.file_version.sha1 !== file.file_version.sha1 || isFileWatermarked) {
56263
56287
  this.logger.setCacheStale(); // Log that cache is stale
56264
56288
  this.reload(true); // Reload viewer without fetching updated file info from server
56289
+ } else if (needsTranscriptionReload) {
56290
+ // Cache was valid but lacked extracted_text (e.g. prefetch without the hint).
56291
+ // Server refresh now has the rep — update the already-playing viewer so
56292
+ // loadTranscription can attach captions. Only call it after loadeddata;
56293
+ // calling earlier duplicates the Auto-generated Shaka track and can throw
56294
+ // if UI is not ready. If loadeddata has not fired, the handler uses this file.
56295
+ if (this.viewer) {
56296
+ this.viewer.options.file = this.file;
56297
+ if (this.viewer.isLoaded() && typeof this.viewer.loadTranscription === 'function') {
56298
+ this.viewer.loadTranscription();
56299
+ }
56300
+ }
56265
56301
  }
56266
56302
  } catch (err) {
56267
56303
  const error = err instanceof PreviewError/* default */.A ? err : new PreviewError/* default */.A(lib_events/* ERROR_CODE */.bo.LOAD_VIEWER, "This preview didn’t load. Please try to open or download the file to view.", {}, err.message);
@@ -56382,6 +56418,31 @@ class Preview extends (events_default()) {
56382
56418
  });
56383
56419
  }
56384
56420
 
56421
+ /**
56422
+ * Returns true if file has an extracted_text transcription rep with a content URL.
56423
+ *
56424
+ * @private
56425
+ * @param {Object} file - File object
56426
+ * @return {boolean}
56427
+ */
56428
+ hasTranscriptionRep(file) {
56429
+ if (!file?.representations?.entries) {
56430
+ return false;
56431
+ }
56432
+ const extractedText = getRepresentation(file, 'extracted_text');
56433
+ return !!extractedText?.content?.url_template;
56434
+ }
56435
+
56436
+ /**
56437
+ * Returns true when Dash playback is available and not disabled.
56438
+ *
56439
+ * @private
56440
+ * @return {boolean}
56441
+ */
56442
+ canUseDash() {
56443
+ return lib_Browser.canPlayDash() && !this.disabledViewers.Dash;
56444
+ }
56445
+
56385
56446
  /**
56386
56447
  * Returns true if file has playable video representations (dash or mp4).
56387
56448
  *
@@ -56836,7 +56897,7 @@ class Preview extends (events_default()) {
56836
56897
  previewMode,
56837
56898
  sharedLinkAuth
56838
56899
  } = this.options || {};
56839
- this.emit(name, Preview_objectSpread(Preview_objectSpread({}, payload), {}, {
56900
+ this.emit(name, Preview_objectSpread(Preview_objectSpread(Preview_objectSpread({}, payload), this.getBlueprintMigrationTags()), {}, {
56840
56901
  access_pattern: accessPattern,
56841
56902
  client_name: clientName,
56842
56903
  content_type: (0,util/* getProp */.GT)(this.viewer, 'options.viewer.NAME', ''),
@@ -56854,6 +56915,26 @@ class Preview extends (events_default()) {
56854
56915
  }, getClientLogDetails()));
56855
56916
  }
56856
56917
 
56918
+ /**
56919
+ * Returns the state of each Blueprint migration wave for this preview session. Every metric
56920
+ * and error carries all four, including the waves that are off, so the flag-off side of a
56921
+ * rollout is measured the same way as the flag-on side rather than inferred from its absence.
56922
+ *
56923
+ * @private
56924
+ * @return {Object} Blueprint migration dimensions
56925
+ */
56926
+ getBlueprintMigrationTags() {
56927
+ const {
56928
+ features
56929
+ } = this.options || {};
56930
+ return {
56931
+ blueprint_archive: isFeatureEnabled(features, constants/* BLUEPRINT_MIGRATION_ARCHIVE */.cA),
56932
+ blueprint_controls_bar: isFeatureEnabled(features, constants/* BLUEPRINT_MIGRATION_CONTROLS_BAR */.OQ),
56933
+ blueprint_media_controls: isFeatureEnabled(features, constants/* BLUEPRINT_MIGRATION_MEDIA_CONTROLS */.dR),
56934
+ blueprint_supporting_ui: isFeatureEnabled(features, constants/* BLUEPRINT_MIGRATION_SUPPORTING_UI */.Ed)
56935
+ };
56936
+ }
56937
+
56857
56938
  /**
56858
56939
  * Returns the prefetch/preload dimensions for this preview session. Only attached to
56859
56940
  * the load event, preview_preload_outcome counter, and preview_error — exactly one
@@ -56877,7 +56958,7 @@ class Preview extends (events_default()) {
56877
56958
  * @return {Object} Headers
56878
56959
  */
56879
56960
  getRequestHeaders(token) {
56880
- const isDash = lib_Browser.canPlayDash() && !this.disabledViewers.Dash;
56961
+ const isDash = this.canUseDash();
56881
56962
  let videoHint = isDash ? constants/* X_REP_HINT_VIDEO_DASH */.yF : constants/* X_REP_HINT_VIDEO_MP4 */.Zg;
56882
56963
  if (isDash && isFeatureEnabled(this.options.features, constants/* AI_TRANSCRIPTION_FOR_VIDEO_SUBTITLES */.Iu)) {
56883
56964
  videoHint += constants/* X_REP_HINT_VIDEO_DASH_EXTRACTED_TEXT */.xU;
@@ -57155,8 +57236,10 @@ class Preview extends (events_default()) {
57155
57236
  return (0,util/* getProp */.GT)(this.previewOptions, `fileOptions.${fileId}.${optionName}`);
57156
57237
  }
57157
57238
  }
57158
- globalThis.Box = globalThis.Box || {};
57159
- globalThis.Box.Preview = Preview;
57239
+ if (!IS_NPM_BUILD) {
57240
+ globalThis.Box = globalThis.Box || {};
57241
+ globalThis.Box.Preview = Preview;
57242
+ }
57160
57243
  /* harmony default export */ const lib_Preview = (Preview);
57161
57244
  ;// ./src/index.ts
57162
57245
  // useNpmPdfjs is auto-injected by Preview.show() under __BCP_NPM_BUILD__.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "box-content-preview",
3
- "version": "3.94.0",
3
+ "version": "3.96.0",
4
4
  "description": "Box Content Preview UI Element",
5
5
  "author": "Box (https://www.box.com/)",
6
6
  "license": "SEE LICENSE IN LICENSE",