Refaktorisierte 'UI'-Funktionen zu statischen Methoden

This commit is contained in:
Developer 02
2024-06-18 19:01:40 +02:00
parent 39cc257466
commit 95958f2a1d
2 changed files with 11 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
class UI {
allowedToolbarItems = [
static allowedToolbarItems = [
'sidebar-thumbnails',
'sidebar-document-ouline',
'sidebar-bookmarks',
@@ -14,7 +14,7 @@
// Load the PSPDFKit UI by setting a target element as the container to render in
// and a arraybuffer which represents the document that should be displayed.
loadPSPDFKit(arrayBuffer, container, licenseKey, locale) {
static loadPSPDFKit(arrayBuffer, container, licenseKey, locale) {
return PSPDFKit.load({
locale: locale,
licenseKey: licenseKey,
@@ -45,30 +45,30 @@
})
}
configurePSPDFKit(instance, handler) {
static configurePSPDFKit(instance, handler) {
const toolbarItems = this.getToolbarItems(instance, handler)
instance.setToolbarItems(toolbarItems)
}
annotationRenderer(data) {
static annotationRenderer(data) {
// leave everything as is
return null
}
getToolbarItems(instance, handler) {
static getToolbarItems(instance, handler) {
const customItems = this.getCustomItems(handler)
const defaultItems = this.getDefaultItems(instance.toolbarItems)
return defaultItems.concat(customItems)
}
createElementFromHTML(html) {
static createElementFromHTML(html) {
const el = document.createElement('div')
el.innerHTML = html.trim()
return el.firstChild
}
getCustomItems = function (callback) {
static getCustomItems = function (callback) {
return []
return [
{
@@ -108,11 +108,11 @@
]
}
getDefaultItems(items) {
static getDefaultItems(items) {
return items.filter((item) => this.allowedToolbarItems.includes(item.type))
}
getPresets() {
static getPresets() {
const annotationPresets = PSPDFKit.defaultAnnotationPresets
annotationPresets.ink = {
lineWidth: 10,