forked from stenciljs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-window.ts
More file actions
72 lines (60 loc) · 2.23 KB
/
Copy pathclient-window.ts
File metadata and controls
72 lines (60 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { BUILD } from '@app-data';
import type * as d from '../declarations';
interface StencilWindow extends Omit<Window, 'document'> {
document?: Document;
}
export const win = (typeof window !== 'undefined' ? window : ({} as StencilWindow)) as StencilWindow;
export const H = ((win as any).HTMLElement || (class {} as any)) as HTMLElement;
export const plt: d.PlatformRuntime = {
$flags$: 0,
$resourcesUrl$: '',
jmp: (h) => h(),
raf: (h) => requestAnimationFrame(h),
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
ce: (eventName, opts) => new CustomEvent(eventName, opts),
};
export const setPlatformHelpers = (helpers: {
jmp?: (c: any) => any;
raf?: (c: any) => number;
ael?: (el: any, eventName: string, listener: any, options: any) => void;
rel?: (el: any, eventName: string, listener: any, options: any) => void;
ce?: (eventName: string, opts?: any) => any;
}) => {
Object.assign(plt, helpers);
};
export const supportsShadow = BUILD.shadowDom;
export const supportsListenerOptions = /*@__PURE__*/ (() => {
let supportsListenerOptions = false;
try {
win.document?.addEventListener(
'e',
null,
Object.defineProperty({}, 'passive', {
get() {
supportsListenerOptions = true;
},
}),
);
} catch (e) {}
return supportsListenerOptions;
})();
export const promiseResolve = (v?: any) => Promise.resolve(v);
export const supportsConstructableStylesheets = BUILD.constructableCSS
? /*@__PURE__*/ (() => {
try {
if (!win.document.adoptedStyleSheets) {
return false;
}
new CSSStyleSheet();
return typeof new CSSStyleSheet().replaceSync === 'function';
} catch (e) {}
return false;
})()
: false;
// https://github.com/salesforce/lwc/blob/5af18fdd904bc6cfcf7b76f3c539490ff11515b2/packages/%40lwc/engine-dom/src/renderer.ts#L41-L43
export const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets
? /*@__PURE__*/ (() =>
!!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, 'length')!.writable)()
: false;
export { H as HTMLElement };