@schukai/monster 3.119.0 → 3.120.0
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.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/source/components/accessibility/stylesheet/locale-picker.mjs +1 -1
- package/source/components/content/stylesheet/viewer.mjs +1 -1
- package/source/components/content/viewer.mjs +301 -311
- package/source/components/datatable/stylesheet/change-button.mjs +1 -1
- package/source/components/datatable/stylesheet/column-bar.mjs +1 -1
- package/source/components/datatable/stylesheet/dataset.mjs +1 -1
- package/source/components/datatable/stylesheet/datatable.mjs +1 -1
- package/source/components/datatable/stylesheet/filter-select.mjs +1 -1
- package/source/components/datatable/stylesheet/filter.mjs +1 -1
- package/source/components/datatable/stylesheet/pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/save-button.mjs +1 -1
- package/source/components/datatable/stylesheet/status.mjs +1 -1
- package/source/components/form/login.mjs +5 -0
- package/source/components/form/stylesheet/button-bar.mjs +1 -1
- package/source/components/form/stylesheet/button.mjs +1 -1
- package/source/components/form/stylesheet/popper-button.mjs +1 -1
- package/source/components/host/stylesheet/call-button.mjs +1 -1
- package/source/components/host/stylesheet/toggle-button.mjs +1 -1
- package/source/components/layout/stylesheet/collapse.mjs +1 -1
- package/source/components/layout/stylesheet/details.mjs +1 -1
- package/source/components/state/style/state.pcss +2 -0
- package/source/components/state/stylesheet/state.mjs +1 -1
- package/source/components/style/button.css +8 -16
- package/source/components/style/button.pcss +2 -0
- package/source/components/style/mixin/button.pcss +1 -6
- package/source/components/stylesheet/button.mjs +1 -1
- package/source/components/time/stylesheet/day.mjs +1 -1
- package/source/components/time/stylesheet/month-calendar.mjs +1 -1
- package/source/components/time/timeline/stylesheet/appointment.mjs +1 -1
- package/source/components/time/timeline/stylesheet/segment.mjs +1 -1
@@ -13,18 +13,18 @@
|
|
13
13
|
*/
|
14
14
|
|
15
15
|
import {
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
assembleMethodSymbol,
|
17
|
+
CustomElement,
|
18
|
+
registerCustomElement,
|
19
19
|
} from "../../dom/customelement.mjs";
|
20
20
|
import "../notify/notify.mjs";
|
21
|
-
import {ViewerStyleSheet} from "./stylesheet/viewer.mjs";
|
22
|
-
import {instanceSymbol} from "../../constants.mjs";
|
23
|
-
import {isString} from "../../types/is.mjs";
|
24
|
-
import {getGlobal} from "../../types/global.mjs";
|
25
|
-
import {MediaType, parseMediaType} from "../../types/mediatype.mjs";
|
21
|
+
import { ViewerStyleSheet } from "./stylesheet/viewer.mjs";
|
22
|
+
import { instanceSymbol } from "../../constants.mjs";
|
23
|
+
import { isString } from "../../types/is.mjs";
|
24
|
+
import { getGlobal } from "../../types/global.mjs";
|
25
|
+
import { MediaType, parseMediaType } from "../../types/mediatype.mjs";
|
26
26
|
|
27
|
-
export {Viewer};
|
27
|
+
export { Viewer };
|
28
28
|
|
29
29
|
/**
|
30
30
|
* @private
|
@@ -45,288 +45,278 @@ const viewerElementSymbol = Symbol("viewerElement");
|
|
45
45
|
* @summary A simple viewer component for PDF, HTML and images.
|
46
46
|
*/
|
47
47
|
class Viewer extends CustomElement {
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
static getTag() {
|
321
|
-
return "monster-viewer";
|
322
|
-
}
|
323
|
-
|
324
|
-
/**
|
325
|
-
* @return {CSSStyleSheet[]}
|
326
|
-
*/
|
327
|
-
static getCSSStyleSheet() {
|
328
|
-
return [ViewerStyleSheet];
|
329
|
-
}
|
48
|
+
/**
|
49
|
+
* This method is called by the `instanceof` operator.
|
50
|
+
* @return {symbol}
|
51
|
+
*/
|
52
|
+
static get [instanceSymbol]() {
|
53
|
+
return Symbol.for("@schukai/monster/components/content/viewer@@instance");
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
58
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
59
|
+
*
|
60
|
+
* The individual configuration values can be found in the table.
|
61
|
+
*
|
62
|
+
* @property {Object} templates Template definitions
|
63
|
+
* @property {string} templates.main Main template
|
64
|
+
* @property {string} content Content to be displayed in the viewer
|
65
|
+
* @property {Object} classes Css classes
|
66
|
+
* @property {string} classes.viewer Css class for the viewer
|
67
|
+
*/
|
68
|
+
get defaults() {
|
69
|
+
return Object.assign({}, super.defaults, {
|
70
|
+
templates: {
|
71
|
+
main: getTemplate(),
|
72
|
+
},
|
73
|
+
content: "<slot></slot>",
|
74
|
+
classes: {
|
75
|
+
viewer: "",
|
76
|
+
},
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Sets the content of an element based on the provided content and media type.
|
82
|
+
*
|
83
|
+
* @param {string} content - The content to be set.
|
84
|
+
* @param {string} [mediaType="text/plain"] - The media type of the content. Defaults to "text/plain" if not specified.
|
85
|
+
* @return {void} This method does not return a value.
|
86
|
+
* @throws {Error} Throws an error if shadowRoot is not defined.
|
87
|
+
*/
|
88
|
+
setContent(content, mediaType = "text/plain") {
|
89
|
+
if (!this.shadowRoot) {
|
90
|
+
throw new Error("no shadow-root is defined");
|
91
|
+
}
|
92
|
+
|
93
|
+
let type;
|
94
|
+
try {
|
95
|
+
const m = new parseMediaType(mediaType);
|
96
|
+
switch (m.type) {
|
97
|
+
case "image":
|
98
|
+
return this.setImage(content);
|
99
|
+
}
|
100
|
+
|
101
|
+
mediaType = m.toString();
|
102
|
+
} catch (error) {
|
103
|
+
type = null;
|
104
|
+
}
|
105
|
+
|
106
|
+
if (mediaType === undefined || mediaType === null || mediaType === "") {
|
107
|
+
mediaType = "text/plain";
|
108
|
+
}
|
109
|
+
|
110
|
+
switch (mediaType) {
|
111
|
+
case "text/html":
|
112
|
+
this.setHTML(content);
|
113
|
+
break;
|
114
|
+
case "text/plain":
|
115
|
+
this.setPlainText(content);
|
116
|
+
break;
|
117
|
+
case "application/pdf":
|
118
|
+
this.setPDF(content);
|
119
|
+
break;
|
120
|
+
case "image/png":
|
121
|
+
case "image/jpeg":
|
122
|
+
case "image/gif":
|
123
|
+
this.setImage(content);
|
124
|
+
break;
|
125
|
+
default:
|
126
|
+
this.setOption("content", content);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Configures and embeds a PDF document into the application with customizable display settings.
|
132
|
+
*
|
133
|
+
* @param {Blob|URL|string} data The PDF data to be embedded. Can be provided as a Blob, URL or base64 string.
|
134
|
+
* @param {boolean} [navigation=true] Determines whether the navigation pane is displayed in the PDF viewer.
|
135
|
+
* @param {boolean} [toolbar=true] Controls the visibility of the toolbar in the PDF viewer.
|
136
|
+
* @param {boolean} [scrollbar=false] Configures the display of the scrollbar in the PDF viewer.
|
137
|
+
* @return {void} This method returns nothing but sets the embedded PDF as the content.
|
138
|
+
*/
|
139
|
+
setPDF(data, navigation = true, toolbar = true, scrollbar = false) {
|
140
|
+
const hashes =
|
141
|
+
"#toolbar=" +
|
142
|
+
(toolbar ? "1" : "0") +
|
143
|
+
"&navpanes=" +
|
144
|
+
(navigation ? "1" : "0") +
|
145
|
+
"&scrollbar=" +
|
146
|
+
(scrollbar ? "1" : "0");
|
147
|
+
|
148
|
+
let pdfURL = "";
|
149
|
+
if (isBlob(data)) {
|
150
|
+
pdfURL = URL.createObjectURL(data);
|
151
|
+
pdfURL += hashes;
|
152
|
+
} else if (isURL(data)) {
|
153
|
+
// check if the url already contains the hashes
|
154
|
+
if (data?.hash?.indexOf("#") === -1) {
|
155
|
+
pdfURL = data.toString() + hashes;
|
156
|
+
} else {
|
157
|
+
pdfURL = data.toString();
|
158
|
+
}
|
159
|
+
} else if (isString(data)) {
|
160
|
+
//URL.createObjectURL(data);
|
161
|
+
const blobObj = new Blob([atob(data)], { type: "application/pdf" });
|
162
|
+
const url = window.URL.createObjectURL(blobObj);
|
163
|
+
|
164
|
+
pdfURL = data;
|
165
|
+
} else {
|
166
|
+
throw new Error("Blob or URL expected");
|
167
|
+
}
|
168
|
+
|
169
|
+
const html =
|
170
|
+
'<object data="' +
|
171
|
+
pdfURL +
|
172
|
+
'" width="100%" height="100%" type="application/pdf"></object>';
|
173
|
+
|
174
|
+
this.setOption("content", html);
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Sets an image for the target by accepting a blob, URL, or string representation of the image.
|
179
|
+
*
|
180
|
+
* @param {(Blob|string)} data - The image data, which can be a Blob, a valid URL, or a string representation of the image.
|
181
|
+
* @return {void} Does not return a value.
|
182
|
+
*/
|
183
|
+
setImage(data) {
|
184
|
+
if (isBlob(data)) {
|
185
|
+
data = URL.createObjectURL(data);
|
186
|
+
} else if (isURL(data)) {
|
187
|
+
// nothing to do
|
188
|
+
} else if (isString(data)) {
|
189
|
+
// nothing to do
|
190
|
+
} else {
|
191
|
+
throw new Error("Blob or URL expected");
|
192
|
+
}
|
193
|
+
|
194
|
+
this.setOption("content", '<img src="' + data + '" alt="image" />');
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
*
|
199
|
+
* if the data is a string, it is interpreted as HTML.
|
200
|
+
* if the data is an url, the HTML is loaded from the url and set as content.
|
201
|
+
* if the data is an HTMLElement, the outerHTML is used as content.
|
202
|
+
*
|
203
|
+
* @param {HTMLElement|URL|string|Blob} data
|
204
|
+
*/
|
205
|
+
setHTML(data) {
|
206
|
+
if (data instanceof Blob) {
|
207
|
+
blobToText(data)
|
208
|
+
.then((html) => {
|
209
|
+
this.setOption("content", html);
|
210
|
+
})
|
211
|
+
.catch((error) => {
|
212
|
+
throw new Error(error);
|
213
|
+
});
|
214
|
+
|
215
|
+
return;
|
216
|
+
} else if (data instanceof HTMLElement) {
|
217
|
+
data = data.outerHTML;
|
218
|
+
} else if (isString(data)) {
|
219
|
+
// nothing to do
|
220
|
+
} else if (isURL(data)) {
|
221
|
+
// fetch element
|
222
|
+
getGlobal()
|
223
|
+
.fetch(data)
|
224
|
+
.then((response) => {
|
225
|
+
return response.text();
|
226
|
+
})
|
227
|
+
.then((html) => {
|
228
|
+
this.setOption("content", html);
|
229
|
+
})
|
230
|
+
.catch((error) => {
|
231
|
+
throw new Error(error);
|
232
|
+
});
|
233
|
+
} else {
|
234
|
+
throw new Error("HTMLElement or string expected");
|
235
|
+
}
|
236
|
+
|
237
|
+
this.setOption("content", data);
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Sets the plain text content by processing the input data, which can be of various types, including Blob,
|
242
|
+
* HTMLElement, string, or a valid URL. The method extracts and sets the raw text content into a predefined option.
|
243
|
+
*
|
244
|
+
* @param {Blob|HTMLElement|string} data - The input data to be processed. It can be a Blob object, an HTMLElement,
|
245
|
+
* a plain string, or a string formatted as a valid URL. The method determines
|
246
|
+
* the data type and processes it accordingly.
|
247
|
+
* @return {void} - This method does not return any value. It processes the content and updates the relevant option
|
248
|
+
* property.
|
249
|
+
*/
|
250
|
+
setPlainText(data) {
|
251
|
+
if (data instanceof Blob) {
|
252
|
+
blobToText(data)
|
253
|
+
.then((html) => {
|
254
|
+
const div = document.createElement("div");
|
255
|
+
div.innerHTML = html;
|
256
|
+
html = div.innerText;
|
257
|
+
|
258
|
+
this.setOption("content", html);
|
259
|
+
})
|
260
|
+
.catch((error) => {
|
261
|
+
throw new Error(error);
|
262
|
+
});
|
263
|
+
|
264
|
+
return;
|
265
|
+
} else if (data instanceof HTMLElement) {
|
266
|
+
data = data.outerText;
|
267
|
+
} else if (isString(data)) {
|
268
|
+
const div = document.createElement("div");
|
269
|
+
div.innerHTML = data;
|
270
|
+
data = div.innerText;
|
271
|
+
} else if (isURL(data)) {
|
272
|
+
// fetch element
|
273
|
+
getGlobal()
|
274
|
+
.fetch(data)
|
275
|
+
.then((response) => {
|
276
|
+
return response.text();
|
277
|
+
})
|
278
|
+
.then((text) => {
|
279
|
+
const div = document.createElement("div");
|
280
|
+
div.innerHTML = text;
|
281
|
+
text = div.innerText;
|
282
|
+
|
283
|
+
this.setOption("content", text);
|
284
|
+
})
|
285
|
+
.catch((error) => {
|
286
|
+
throw new Error(error);
|
287
|
+
});
|
288
|
+
} else {
|
289
|
+
throw new Error("HTMLElement or string expected");
|
290
|
+
}
|
291
|
+
|
292
|
+
this.setOption("content", data);
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
*
|
297
|
+
* @return {Viewer}
|
298
|
+
*/
|
299
|
+
[assembleMethodSymbol]() {
|
300
|
+
super[assembleMethodSymbol]();
|
301
|
+
|
302
|
+
initControlReferences.call(this);
|
303
|
+
initEventHandler.call(this);
|
304
|
+
}
|
305
|
+
|
306
|
+
/**
|
307
|
+
*
|
308
|
+
* @return {string}
|
309
|
+
*/
|
310
|
+
static getTag() {
|
311
|
+
return "monster-viewer";
|
312
|
+
}
|
313
|
+
|
314
|
+
/**
|
315
|
+
* @return {CSSStyleSheet[]}
|
316
|
+
*/
|
317
|
+
static getCSSStyleSheet() {
|
318
|
+
return [ViewerStyleSheet];
|
319
|
+
}
|
330
320
|
}
|
331
321
|
|
332
322
|
/**
|
@@ -335,12 +325,12 @@ class Viewer extends CustomElement {
|
|
335
325
|
* @return {boolean}
|
336
326
|
*/
|
337
327
|
function isURL(variable) {
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
328
|
+
try {
|
329
|
+
new URL(variable);
|
330
|
+
return true;
|
331
|
+
} catch (error) {
|
332
|
+
return false;
|
333
|
+
}
|
344
334
|
}
|
345
335
|
|
346
336
|
/**
|
@@ -349,7 +339,7 @@ function isURL(variable) {
|
|
349
339
|
* @return {boolean}
|
350
340
|
*/
|
351
341
|
function isBlob(variable) {
|
352
|
-
|
342
|
+
return variable instanceof Blob;
|
353
343
|
}
|
354
344
|
|
355
345
|
/**
|
@@ -358,12 +348,12 @@ function isBlob(variable) {
|
|
358
348
|
* @return {Promise<unknown>}
|
359
349
|
*/
|
360
350
|
function blobToText(blob) {
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
351
|
+
return new Promise((resolve, reject) => {
|
352
|
+
const reader = new FileReader();
|
353
|
+
reader.onloadend = () => resolve(reader.result);
|
354
|
+
reader.onerror = reject;
|
355
|
+
reader.readAsText(blob);
|
356
|
+
});
|
367
357
|
}
|
368
358
|
|
369
359
|
/**
|
@@ -372,18 +362,18 @@ function blobToText(blob) {
|
|
372
362
|
* @throws {Error} no shadow-root is defined
|
373
363
|
*/
|
374
364
|
function initControlReferences() {
|
375
|
-
|
376
|
-
|
377
|
-
|
365
|
+
if (!this.shadowRoot) {
|
366
|
+
throw new Error("no shadow-root is defined");
|
367
|
+
}
|
378
368
|
|
379
|
-
|
369
|
+
this[viewerElementSymbol] = this.shadowRoot.getElementById("viewer");
|
380
370
|
}
|
381
371
|
|
382
372
|
/**
|
383
373
|
* @private
|
384
374
|
*/
|
385
375
|
function initEventHandler() {
|
386
|
-
|
376
|
+
return this;
|
387
377
|
}
|
388
378
|
|
389
379
|
/**
|
@@ -391,8 +381,8 @@ function initEventHandler() {
|
|
391
381
|
* @return {string}
|
392
382
|
*/
|
393
383
|
function getTemplate() {
|
394
|
-
|
395
|
-
|
384
|
+
// language=HTML
|
385
|
+
return `
|
396
386
|
<div id="viewer" data-monster-role="viewer" part="viewer"
|
397
387
|
data-monster-replace="path:content"
|
398
388
|
data-monster-attributes="class path:classes.viewer">
|