Blame Raw
Cohee · 51ad27fb · · 138 lines (3.0 KB)
1 contributor
1/**
2 * Add all the libraries that you want to expose to the client here.
3 * They are bundled and exposed by Webpack in the /lib.js file.
4 */
5import lodash from 'lodash';
6import Fuse from 'fuse.js';
7import DOMPurify from 'dompurify';
8import hljs from 'highlight.js';
9import localforage from 'localforage';
10import Handlebars from 'handlebars';
11import css from '@adobe/css-tools';
12import Bowser from 'bowser';
13import DiffMatchPatch from 'diff-match-patch';
14import { isProbablyReaderable, Readability } from '@mozilla/readability';
15import SVGInject from '@iconfu/svg-inject';
16import showdown from 'showdown';
17import moment from 'moment';
18import seedrandom from 'seedrandom';
19import * as Popper from '@popperjs/core';
20import droll from 'droll';
21import morphdom from 'morphdom';
22import { toggle as slideToggle } from 'slidetoggle';
23import chalk from 'chalk';
24import yaml from 'yaml';
25import * as chevrotain from 'chevrotain';
26import { gzipSync, gzip } from 'fflate';
27import { sha256 } from 'js-sha256';
28
29/**
30 * Expose the libraries to the 'window' object.
31 * Needed for compatibility with old extensions.
32 * Note: New extensions are encouraged to import the libraries directly from lib.js.
33 */
34export function initLibraryShims() {
35 if (!window) {
36 return;
37 }
38 if (!('Fuse' in window)) {
39 // @ts-ignore
40 window.Fuse = Fuse;
41 }
42 if (!('DOMPurify' in window)) {
43 // @ts-ignore
44 window.DOMPurify = DOMPurify;
45 }
46 if (!('hljs' in window)) {
47 // @ts-ignore
48 window.hljs = hljs;
49 }
50 if (!('localforage' in window)) {
51 // @ts-ignore
52 window.localforage = localforage;
53 }
54 if (!('Handlebars' in window)) {
55 // @ts-ignore
56 window.Handlebars = Handlebars;
57 }
58 if (!('diff_match_patch' in window)) {
59 // @ts-ignore
60 window.diff_match_patch = DiffMatchPatch;
61 }
62 if (!('SVGInject' in window)) {
63 // @ts-ignore
64 window.SVGInject = SVGInject;
65 }
66 if (!('showdown' in window)) {
67 // @ts-ignore
68 window.showdown = showdown;
69 }
70 if (!('moment' in window)) {
71 // @ts-ignore
72 window.moment = moment;
73 }
74 if (!('Popper' in window)) {
75 // @ts-ignore
76 window.Popper = Popper;
77 }
78 if (!('droll' in window)) {
79 // @ts-ignore
80 window.droll = droll;
81 }
82}
83
84export default {
85 lodash,
86 Fuse,
87 DOMPurify,
88 hljs,
89 localforage,
90 Handlebars,
91 css,
92 Bowser,
93 DiffMatchPatch,
94 Readability,
95 isProbablyReaderable,
96 SVGInject,
97 showdown,
98 moment,
99 seedrandom,
100 Popper,
101 droll,
102 morphdom,
103 slideToggle,
104 chalk,
105 yaml,
106 chevrotain,
107 gzipSync,
108 gzip,
109 sha256,
110};
111
112export {
113 lodash,
114 Fuse,
115 DOMPurify,
116 hljs,
117 localforage,
118 Handlebars,
119 css,
120 Bowser,
121 DiffMatchPatch,
122 Readability,
123 isProbablyReaderable,
124 SVGInject,
125 showdown,
126 moment,
127 seedrandom,
128 Popper,
129 droll,
130 morphdom,
131 slideToggle,
132 chalk,
133 yaml,
134 chevrotain,
135 gzipSync,
136 gzip,
137 sha256,
138};