SillyTavern/public/lib.js

119 lines
2.6 KiB
JavaScript
Raw Normal View History

/**
* Add all the libraries that you want to expose to the client here.
* They are bundled and exposed by Webpack in the /lib.js file.
*/
2024-10-17 00:32:13 +02:00
import lodash from 'lodash';
import Fuse from 'fuse.js';
2024-10-16 22:11:13 +02:00
import DOMPurify from 'dompurify';
2024-10-16 22:18:23 +02:00
import hljs from 'highlight.js';
2024-10-16 22:37:54 +02:00
import localforage from 'localforage';
2024-10-16 23:34:07 +02:00
import Handlebars from 'handlebars';
2024-10-16 23:40:11 +02:00
import css from '@adobe/css-tools';
2024-10-16 23:56:09 +02:00
import Bowser from 'bowser';
2024-10-17 00:23:22 +02:00
import DiffMatchPatch from 'diff-match-patch';
2024-10-17 00:30:04 +02:00
import { isProbablyReaderable, Readability } from '@mozilla/readability';
2024-10-17 00:39:15 +02:00
import SVGInject from '@iconfu/svg-inject';
2024-10-17 00:51:35 +02:00
import showdown from 'showdown';
2024-10-17 01:02:45 +02:00
import moment from 'moment';
2024-10-17 01:19:47 +02:00
import seedrandom from 'seedrandom';
2024-10-17 10:03:58 +02:00
import * as Popper from '@popperjs/core';
2024-10-17 10:12:28 +02:00
import droll from 'droll';
2024-10-17 13:12:22 +02:00
import morphdom from 'morphdom';
2024-10-16 22:11:13 +02:00
/**
* Expose the libraries to the 'window' object.
* Needed for compatibility with old extensions.
* Note: New extensions are encouraged to import the libraries directly from lib.js.
*/
export function initLibraryShims() {
if (!window) {
return;
}
if (!('Fuse' in window)) {
// @ts-ignore
window.Fuse = Fuse;
}
if (!('DOMPurify' in window)) {
// @ts-ignore
window.DOMPurify = DOMPurify;
}
2024-10-16 22:18:23 +02:00
if (!('hljs' in window)) {
// @ts-ignore
window.hljs = hljs;
}
2024-10-16 22:37:54 +02:00
if (!('localforage' in window)) {
// @ts-ignore
window.localforage = localforage;
}
2024-10-16 23:34:07 +02:00
if (!('Handlebars' in window)) {
// @ts-ignore
window.Handlebars = Handlebars;
}
2024-10-17 00:23:22 +02:00
if (!('diff_match_patch' in window)) {
// @ts-ignore
window.diff_match_patch = DiffMatchPatch;
}
2024-10-17 00:39:15 +02:00
if (!('SVGInject' in window)) {
// @ts-ignore
window.SVGInject = SVGInject;
}
2024-10-17 00:51:35 +02:00
if (!('showdown' in window)) {
// @ts-ignore
window.showdown = showdown;
}
2024-10-17 01:02:45 +02:00
if (!('moment' in window)) {
// @ts-ignore
window.moment = moment;
}
2024-10-17 10:03:58 +02:00
if (!('Popper' in window)) {
// @ts-ignore
window.Popper = Popper;
}
2024-10-17 10:12:28 +02:00
if (!('droll' in window)) {
// @ts-ignore
window.droll = droll;
}
2024-10-16 22:11:13 +02:00
}
export default {
2024-10-17 00:32:13 +02:00
lodash,
2024-10-16 22:11:13 +02:00
Fuse,
DOMPurify,
2024-10-16 22:18:23 +02:00
hljs,
2024-10-16 22:37:54 +02:00
localforage,
2024-10-16 23:34:07 +02:00
Handlebars,
2024-10-16 23:40:11 +02:00
css,
2024-10-16 23:56:09 +02:00
Bowser,
2024-10-17 00:23:22 +02:00
DiffMatchPatch,
2024-10-17 00:30:04 +02:00
Readability,
isProbablyReaderable,
2024-10-17 00:39:15 +02:00
SVGInject,
2024-10-17 00:51:35 +02:00
showdown,
2024-10-17 01:02:45 +02:00
moment,
2024-10-17 01:19:47 +02:00
seedrandom,
2024-10-17 10:03:58 +02:00
Popper,
2024-10-17 10:12:28 +02:00
droll,
2024-10-17 13:12:22 +02:00
morphdom,
2024-10-16 22:11:13 +02:00
};
export {
2024-10-17 00:32:13 +02:00
lodash,
Fuse,
2024-10-16 22:11:13 +02:00
DOMPurify,
2024-10-16 22:18:23 +02:00
hljs,
2024-10-16 22:37:54 +02:00
localforage,
2024-10-16 23:34:07 +02:00
Handlebars,
2024-10-16 23:40:11 +02:00
css,
2024-10-16 23:56:09 +02:00
Bowser,
2024-10-17 00:23:22 +02:00
DiffMatchPatch,
2024-10-17 00:30:04 +02:00
Readability,
isProbablyReaderable,
2024-10-17 00:39:15 +02:00
SVGInject,
2024-10-17 00:51:35 +02:00
showdown,
2024-10-17 01:02:45 +02:00
moment,
2024-10-17 01:19:47 +02:00
seedrandom,
2024-10-17 10:03:58 +02:00
Popper,
2024-10-17 10:12:28 +02:00
droll,
2024-10-17 13:12:22 +02:00
morphdom,
};