@file-viewer/web 2.1.17 → 2.1.19

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/element.js CHANGED
@@ -18,6 +18,8 @@ const observedAttributes = [
18
18
  'toolbar-position',
19
19
  'watermark',
20
20
  'search',
21
+ 'fit',
22
+ 'style-isolation',
21
23
  'options',
22
24
  ];
23
25
  const parseBooleanLike = (value) => {
@@ -76,6 +78,18 @@ const callUnique = (callbacks, argument) => {
76
78
  }
77
79
  };
78
80
  const toKebabEventName = (event) => `viewer-${event.type}`;
81
+ const addPart = (element, ...parts) => {
82
+ const partList = element.part;
83
+ if (partList === null || partList === void 0 ? void 0 : partList.add) {
84
+ partList.add(...parts);
85
+ return;
86
+ }
87
+ const nextParts = new Set([
88
+ ...(element.getAttribute('part') || '').split(/\s+/).filter(Boolean),
89
+ ...parts,
90
+ ]);
91
+ element.setAttribute('part', [...nextParts].join(' '));
92
+ };
79
93
  export class FileViewerElement extends ElementBase {
80
94
  constructor() {
81
95
  super(...arguments);
@@ -155,6 +169,34 @@ export class FileViewerElement extends ElementBase {
155
169
  },
156
170
  });
157
171
  }
172
+ get fit() {
173
+ var _a;
174
+ return ((_a = this.mountOptions.options) === null || _a === void 0 ? void 0 : _a.fit) ||
175
+ this.getAttribute('fit') ||
176
+ undefined;
177
+ }
178
+ set fit(value) {
179
+ this.setMountOptions({
180
+ options: {
181
+ ...(this.mountOptions.options || {}),
182
+ fit: value,
183
+ },
184
+ });
185
+ }
186
+ get styleIsolation() {
187
+ var _a;
188
+ return ((_a = this.mountOptions.options) === null || _a === void 0 ? void 0 : _a.styleIsolation) ||
189
+ this.getAttribute('style-isolation') ||
190
+ undefined;
191
+ }
192
+ set styleIsolation(value) {
193
+ this.setMountOptions({
194
+ options: {
195
+ ...(this.mountOptions.options || {}),
196
+ styleIsolation: value,
197
+ },
198
+ });
199
+ }
158
200
  get source() {
159
201
  return {
160
202
  ...this.mountOptions,
@@ -246,6 +288,10 @@ export class FileViewerElement extends ElementBase {
246
288
  var _a, _b;
247
289
  return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.resetZoom()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
248
290
  }
291
+ fitToView(fit) {
292
+ var _a, _b;
293
+ return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.fitToView(fit)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
294
+ }
249
295
  getViewState() {
250
296
  var _a, _b;
251
297
  return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.getViewState()) !== null && _b !== void 0 ? _b : null;
@@ -350,17 +396,31 @@ export class FileViewerElement extends ElementBase {
350
396
  }
351
397
  const node = document.createElement('div');
352
398
  node.className = 'file-viewer-web-host';
399
+ addPart(node, 'host');
353
400
  node.style.width = '100%';
354
401
  node.style.height = '100%';
355
402
  node.style.minWidth = '0';
356
403
  node.style.minHeight = '0';
357
404
  this.mountNode = node;
358
- this.appendChild(node);
405
+ const root = this.resolveElementRenderRoot();
406
+ root.appendChild(node);
359
407
  if (!this.style.display) {
360
408
  this.style.display = 'block';
361
409
  }
362
410
  return node;
363
411
  }
412
+ resolveElementRenderRoot() {
413
+ if (this.shadowRoot) {
414
+ return this.shadowRoot;
415
+ }
416
+ const isolation = this.styleIsolation;
417
+ if (isolation !== 'none' &&
418
+ isolation !== 'scoped' &&
419
+ typeof this.attachShadow === 'function') {
420
+ return this.attachShadow({ mode: 'open', delegatesFocus: true });
421
+ }
422
+ return this;
423
+ }
364
424
  createEffectiveMountOptions() {
365
425
  const attributeOptions = this.readAttributeMountOptions();
366
426
  const propertyOptions = this.mountOptions;
@@ -446,6 +506,18 @@ export class FileViewerElement extends ElementBase {
446
506
  else if (searchBoolean !== undefined) {
447
507
  options.search = searchBoolean;
448
508
  }
509
+ const fit = this.getAttribute('fit');
510
+ const fitJson = parseJsonObject(fit);
511
+ if (fitJson !== undefined) {
512
+ options.fit = fitJson;
513
+ }
514
+ else if (fit) {
515
+ options.fit = fit;
516
+ }
517
+ const styleIsolation = this.getAttribute('style-isolation');
518
+ if (styleIsolation) {
519
+ options.styleIsolation = styleIsolation;
520
+ }
449
521
  return Object.keys(options).length ? options : undefined;
450
522
  }
451
523
  scheduleUpdate() {