@file-viewer/web 2.1.15 → 2.1.17

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.
@@ -211,8 +211,8 @@ const DEFAULT_TOOLBAR_ZOOM_STATE = {
211
211
  canReset: false,
212
212
  };
213
213
  const WEB_VIEWER_STYLE = `
214
- .file-viewer-web-shell{position:relative;width:100%;height:100%;min-height:0;display:flex;flex-direction:column;background:transparent}
215
- .file-viewer-web-content{position:relative;flex:1 1 auto;min-height:0;min-width:0}
214
+ .file-viewer-web-shell{position:relative;width:100%;height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden;background:transparent;box-sizing:border-box}
215
+ .file-viewer-web-content{position:relative;flex:1 1 auto;min-height:0;min-width:0;overflow:auto;overscroll-behavior:contain}
216
216
  .file-viewer-web-toolbar{flex:0 0 auto;min-height:45px;display:inline-flex;align-items:center;justify-content:flex-end;gap:6px;padding:6px 10px;border-bottom:1px solid rgba(20,35,53,.06);background:rgba(255,255,255,.92);box-sizing:border-box;z-index:20}
217
217
  .file-viewer-web-toolbar[hidden]{display:none!important}
218
218
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"]{position:absolute;right:calc(16px + env(safe-area-inset-right,0px));bottom:calc(16px + env(safe-area-inset-bottom,0px));min-height:42px;padding:6px;border:1px solid rgba(20,35,53,.1);border-radius:999px;background:rgba(255,255,255,.94);box-shadow:0 18px 44px rgba(15,23,42,.16);backdrop-filter:blur(16px)}
@@ -223,12 +223,22 @@ const WEB_VIEWER_STYLE = `
223
223
  .file-viewer-web-toolbar .file-viewer-web-icon-button{width:30px;min-width:30px;padding:0;display:inline-flex;align-items:center;justify-content:center}
224
224
  .file-viewer-web-toolbar .file-viewer-web-zoom-meter{min-width:48px;height:30px;padding:0 8px;display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;color:#23465e}
225
225
  .file-viewer-web-toolbar .file-viewer-web-zoom-meter--readonly{font-size:12px;font-weight:800;line-height:1;white-space:nowrap}
226
+ .file-viewer-web-search{gap:4px}
227
+ .file-viewer-web-search input{width:clamp(128px,18vw,220px);height:30px;box-sizing:border-box;border:0;border-radius:999px;padding:0 10px;background:#fff;color:#172033;font:inherit;font-size:12px;line-height:30px;outline:0}
228
+ .file-viewer-web-search input:focus{box-shadow:0 0 0 2px rgba(31,157,103,.22)}
229
+ .file-viewer-web-search button{min-width:32px;height:30px;padding:0 8px;border-radius:999px}
230
+ .file-viewer-web-search-count{min-width:42px;text-align:center;color:#607282;font-size:12px;font-weight:800;line-height:30px;white-space:nowrap}
226
231
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] button{min-width:48px;height:32px;border-radius:999px}
227
232
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-icon-button{width:32px;min-width:32px}
228
233
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-zoom-meter{min-width:54px;height:32px}
234
+ .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-search button{min-width:32px;height:32px}
235
+ .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-search input{height:32px;line-height:32px;width:clamp(120px,18vw,190px)}
229
236
  .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}
230
237
  .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-toolbar button{color:#d7dee8}
231
- @media (prefers-color-scheme:dark){.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar button{color:#d7dee8}}
238
+ .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-search input{background:rgba(15,23,42,.78);color:#f8fafc}
239
+ .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-search-count{color:#cbd5e1}
240
+ @media (prefers-color-scheme:dark){.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar button{color:#d7dee8}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-search input{background:rgba(15,23,42,.78);color:#f8fafc}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-search-count{color:#cbd5e1}}
241
+ @media (max-width:640px){.file-viewer-web-toolbar{max-width:100%;overflow-x:auto}.file-viewer-web-toolbar[data-toolbar-position="bottom-right"]{max-width:calc(100% - 32px)}.file-viewer-web-search input{width:120px}}
232
242
  `;
233
243
  const createButton = (documentRef, label, className, onClick) => {
234
244
  const button = documentRef.createElement('button');
@@ -263,6 +273,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
263
273
  toolbarEl.className = 'file-viewer-web-toolbar';
264
274
  const contentEl = documentRef.createElement('div');
265
275
  contentEl.className = 'file-viewer-web-content';
276
+ contentEl.dataset.viewerScrollContainer = 'true';
266
277
  shell.append(toolbarEl, contentEl);
267
278
  container.replaceChildren(styleEl, shell);
268
279
  let disposed = false;
@@ -317,7 +328,20 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
317
328
  shell.dataset.viewerTheme = ((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme) || 'light';
318
329
  };
319
330
  let controller = null;
331
+ let searchDraft = '';
332
+ const isSearchToolbarVisible = (toolbar, options) => {
333
+ var _a;
334
+ if (toolbar.search === false || options.search === false || !state.ready || state.loading || state.error) {
335
+ return false;
336
+ }
337
+ if (contentEl.querySelector('.file-viewer-missing-renderer')) {
338
+ return false;
339
+ }
340
+ const renderer = instance.getRenderer(getCurrentExtension());
341
+ return !!((_a = renderer === null || renderer === void 0 ? void 0 : renderer.capabilities) === null || _a === void 0 ? void 0 : _a.search);
342
+ };
320
343
  const renderToolbar = () => {
344
+ var _a, _b;
321
345
  if (disposed) {
322
346
  return;
323
347
  }
@@ -326,7 +350,8 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
326
350
  const toolbar = normalizeFileViewerToolbar(options);
327
351
  const availability = getToolbarAvailability();
328
352
  const visibleToolbar = resolveVisibleFileViewerToolbar(toolbar, availability);
329
- const showToolbar = hasVisibleFileViewerToolbarActions(visibleToolbar);
353
+ const showSearchToolbar = isSearchToolbarVisible(toolbar, options);
354
+ const showToolbar = hasVisibleFileViewerToolbarActions(visibleToolbar) || showSearchToolbar;
330
355
  const toolbarPosition = resolveFileViewerToolbarPosition(options, getCurrentExtension());
331
356
  const toolbarDisabled = state.loading || !!state.error;
332
357
  const zoomState = getToolbarZoomState();
@@ -337,6 +362,58 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
337
362
  if (!showToolbar) {
338
363
  return;
339
364
  }
365
+ if (showSearchToolbar) {
366
+ const searchState = state.search;
367
+ const searchTotal = (_a = searchState === null || searchState === void 0 ? void 0 : searchState.total) !== null && _a !== void 0 ? _a : 0;
368
+ const currentIndex = searchTotal > 0 ? ((_b = searchState === null || searchState === void 0 ? void 0 : searchState.currentIndex) !== null && _b !== void 0 ? _b : -1) + 1 : 0;
369
+ const group = documentRef.createElement('form');
370
+ group.className = 'file-viewer-web-toolbar-group file-viewer-web-search';
371
+ group.setAttribute('role', 'search');
372
+ group.setAttribute('aria-label', t('toolbar.search'));
373
+ const input = documentRef.createElement('input');
374
+ input.type = 'search';
375
+ input.value = searchDraft;
376
+ input.placeholder = t('toolbar.searchPlaceholder');
377
+ input.title = t('toolbar.searchPlaceholder');
378
+ input.setAttribute('aria-label', t('toolbar.searchPlaceholder'));
379
+ input.disabled = toolbarDisabled;
380
+ input.addEventListener('input', () => {
381
+ searchDraft = input.value;
382
+ });
383
+ const searchButton = documentRef.createElement('button');
384
+ searchButton.type = 'submit';
385
+ searchButton.textContent = t('toolbar.search');
386
+ searchButton.title = t('toolbar.search');
387
+ searchButton.setAttribute('aria-label', t('toolbar.search'));
388
+ searchButton.disabled = toolbarDisabled;
389
+ const previousButton = createButton(documentRef, '<', 'file-viewer-web-icon-button', () => controller === null || controller === void 0 ? void 0 : controller.previousSearchResult());
390
+ previousButton.title = t('toolbar.searchPrevious');
391
+ previousButton.setAttribute('aria-label', t('toolbar.searchPrevious'));
392
+ previousButton.disabled = toolbarDisabled || searchTotal < 1;
393
+ const nextButton = createButton(documentRef, '>', 'file-viewer-web-icon-button', () => controller === null || controller === void 0 ? void 0 : controller.nextSearchResult());
394
+ nextButton.title = t('toolbar.searchNext');
395
+ nextButton.setAttribute('aria-label', t('toolbar.searchNext'));
396
+ nextButton.disabled = toolbarDisabled || searchTotal < 1;
397
+ const clearButton = createButton(documentRef, 'x', 'file-viewer-web-icon-button', async () => {
398
+ searchDraft = '';
399
+ await (controller === null || controller === void 0 ? void 0 : controller.clearDocumentSearch());
400
+ });
401
+ clearButton.title = t('toolbar.searchClear');
402
+ clearButton.setAttribute('aria-label', t('toolbar.searchClear'));
403
+ clearButton.disabled = toolbarDisabled || (!searchDraft && !(searchState === null || searchState === void 0 ? void 0 : searchState.query));
404
+ const count = documentRef.createElement('span');
405
+ count.className = 'file-viewer-web-search-count';
406
+ count.textContent = `${currentIndex}/${searchTotal}`;
407
+ count.setAttribute('aria-live', 'polite');
408
+ group.addEventListener('submit', event => {
409
+ event.preventDefault();
410
+ searchDraft = input.value;
411
+ const query = searchDraft.trim();
412
+ void (query ? controller === null || controller === void 0 ? void 0 : controller.searchDocument(query) : controller === null || controller === void 0 ? void 0 : controller.clearDocumentSearch());
413
+ });
414
+ group.append(input, searchButton, previousButton, nextButton, clearButton, count);
415
+ toolbarEl.appendChild(group);
416
+ }
340
417
  if (visibleToolbar.zoom) {
341
418
  const group = documentRef.createElement('div');
342
419
  group.className = 'file-viewer-web-toolbar-group';
@@ -429,6 +506,8 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
429
506
  state.ready = false;
430
507
  state.error = null;
431
508
  state.lifecycle = event.payload;
509
+ state.search = null;
510
+ searchDraft = '';
432
511
  }
433
512
  else if (event.type === 'load-complete') {
434
513
  state.loading = false;
@@ -450,6 +529,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
450
529
  }
451
530
  else if (event.type === 'search-change') {
452
531
  state.search = event.payload;
532
+ searchDraft = event.payload.query;
453
533
  }
454
534
  else if (event.type === 'location-change') {
455
535
  state.location = event.payload;
@@ -487,6 +567,9 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
487
567
  fetchFile: coreOptions.fetchFile,
488
568
  signal: controller === null || controller === void 0 ? void 0 : controller.signal,
489
569
  });
570
+ if (disposed || (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) || abortController !== controller) {
571
+ return null;
572
+ }
490
573
  return await instance.load(resolvedSource);
491
574
  }
492
575
  catch (error) {