@file-viewer/web 3.0.0 → 3.0.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.
@@ -0,0 +1,4 @@
1
+ export type FileViewerCustomEventOwner = {
2
+ ownerDocument?: Document | null;
3
+ };
4
+ export declare function createFileViewerCustomEvent<Detail>(owner: FileViewerCustomEventOwner, name: string, detail: Detail): CustomEvent<Detail>;
@@ -0,0 +1,45 @@
1
+ export function createFileViewerCustomEvent(owner, name, detail) {
2
+ var _a;
3
+ const init = {
4
+ bubbles: true,
5
+ composed: true,
6
+ detail,
7
+ };
8
+ const ownerWindow = (_a = owner.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
9
+ const ownerCustomEvent = ownerWindow === null || ownerWindow === void 0 ? void 0 : ownerWindow.CustomEvent;
10
+ const CustomEventConstructor = typeof ownerCustomEvent === 'function'
11
+ ? ownerCustomEvent
12
+ : typeof globalThis.CustomEvent === 'function'
13
+ ? globalThis.CustomEvent
14
+ : undefined;
15
+ if (CustomEventConstructor) {
16
+ return new CustomEventConstructor(name, init);
17
+ }
18
+ const ownerDocument = owner.ownerDocument;
19
+ if (ownerDocument && typeof ownerDocument.createEvent === 'function') {
20
+ try {
21
+ const legacyEvent = ownerDocument.createEvent('CustomEvent');
22
+ legacyEvent.initCustomEvent(name, true, false, detail);
23
+ return legacyEvent;
24
+ }
25
+ catch {
26
+ // Fall through to the standard Event constructor for partial DOM shims.
27
+ }
28
+ }
29
+ const ownerEvent = ownerWindow === null || ownerWindow === void 0 ? void 0 : ownerWindow.Event;
30
+ const EventConstructor = typeof ownerEvent === 'function'
31
+ ? ownerEvent
32
+ : typeof globalThis.Event === 'function'
33
+ ? globalThis.Event
34
+ : undefined;
35
+ if (!EventConstructor) {
36
+ throw new Error(`Cannot dispatch ${name}: this runtime does not provide an Event constructor.`);
37
+ }
38
+ const event = new EventConstructor(name, { bubbles: true, composed: true });
39
+ Object.defineProperty(event, 'detail', {
40
+ configurable: false,
41
+ enumerable: true,
42
+ value: detail,
43
+ });
44
+ return event;
45
+ }
package/dist/element.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { fileViewerCoreRendererRegistry, } from '@file-viewer/core';
2
+ import { createFileViewerCustomEvent } from './custom-event.js';
2
3
  import { mountViewer as mountCoreViewer, } from './controller.js';
3
4
  export const FILE_VIEWER_ELEMENT_TAG = 'flyfish-file-viewer';
4
5
  const ElementBase = (typeof HTMLElement === 'undefined'
@@ -591,11 +592,7 @@ export class FileViewerElement extends ElementBase {
591
592
  this.dispatchTypedEvent('viewer-error', { error });
592
593
  }
593
594
  dispatchTypedEvent(name, detail) {
594
- this.dispatchEvent(new CustomEvent(name, {
595
- bubbles: true,
596
- composed: true,
597
- detail,
598
- }));
595
+ this.dispatchEvent(createFileViewerCustomEvent(this, name, detail));
599
596
  }
600
597
  }
601
598
  export const defineFileViewerElement = (tagName = FILE_VIEWER_ELEMENT_TAG) => {