@schukai/monster 4.10.1 → 4.10.2
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/content/camera-capture.mjs +345 -347
- package/source/components/content/style/camera-capture.pcss +4 -4
- package/source/components/content/stylesheet/camera-capture.mjs +14 -7
- package/source/components/content/viewer.mjs +307 -309
- package/source/components/form/login.mjs +3 -34
- package/source/components/form/select.mjs +2716 -2671
- package/source/components/form/stylesheet/select.mjs +13 -6
- package/source/components/layout/full-screen.mjs +115 -119
- package/source/components/layout/panel.mjs +1 -1
- package/source/components/layout/stylesheet/full-screen.mjs +13 -6
@@ -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,286 +45,284 @@ 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
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
return [ViewerStyleSheet];
|
327
|
-
}
|
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 part="pdf" 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
|
+
const mkPreSpan = (text) => {
|
252
|
+
const pre = document.createElement("pre");
|
253
|
+
pre.innerText = text;
|
254
|
+
pre.setAttribute("part", "text");
|
255
|
+
return pre.outerHTML;
|
256
|
+
};
|
257
|
+
|
258
|
+
if (data instanceof Blob) {
|
259
|
+
blobToText(data)
|
260
|
+
.then((text) => {
|
261
|
+
const div = document.createElement("div");
|
262
|
+
div.innerHTML = test;
|
263
|
+
text = div.innerText;
|
264
|
+
|
265
|
+
this.setOption("content", mkPreSpan(text));
|
266
|
+
})
|
267
|
+
.catch((error) => {
|
268
|
+
throw new Error(error);
|
269
|
+
});
|
270
|
+
|
271
|
+
return;
|
272
|
+
} else if (data instanceof HTMLElement) {
|
273
|
+
data = data.outerText;
|
274
|
+
} else if (isString(data)) {
|
275
|
+
const div = document.createElement("div");
|
276
|
+
div.innerHTML = data;
|
277
|
+
data = div.innerText;
|
278
|
+
} else if (isURL(data)) {
|
279
|
+
getGlobal()
|
280
|
+
.fetch(data)
|
281
|
+
.then((response) => {
|
282
|
+
return response.text();
|
283
|
+
})
|
284
|
+
.then((text) => {
|
285
|
+
const div = document.createElement("div");
|
286
|
+
div.innerHTML = text;
|
287
|
+
text = div.innerText;
|
288
|
+
|
289
|
+
this.setOption("content", mkPreSpan(text));
|
290
|
+
})
|
291
|
+
.catch((error) => {
|
292
|
+
throw new Error(error);
|
293
|
+
});
|
294
|
+
} else {
|
295
|
+
throw new Error("HTMLElement or string expected");
|
296
|
+
}
|
297
|
+
|
298
|
+
this.setOption("content", mkPreSpan(data));
|
299
|
+
}
|
300
|
+
|
301
|
+
/**
|
302
|
+
*
|
303
|
+
* @return {Viewer}
|
304
|
+
*/
|
305
|
+
[assembleMethodSymbol]() {
|
306
|
+
super[assembleMethodSymbol]();
|
307
|
+
|
308
|
+
initControlReferences.call(this);
|
309
|
+
initEventHandler.call(this);
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
*
|
314
|
+
* @return {string}
|
315
|
+
*/
|
316
|
+
static getTag() {
|
317
|
+
return "monster-viewer";
|
318
|
+
}
|
319
|
+
|
320
|
+
/**
|
321
|
+
* @return {CSSStyleSheet[]}
|
322
|
+
*/
|
323
|
+
static getCSSStyleSheet() {
|
324
|
+
return [ViewerStyleSheet];
|
325
|
+
}
|
328
326
|
}
|
329
327
|
|
330
328
|
/**
|
@@ -333,12 +331,12 @@ class Viewer extends CustomElement {
|
|
333
331
|
* @return {boolean}
|
334
332
|
*/
|
335
333
|
function isURL(variable) {
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
334
|
+
try {
|
335
|
+
new URL(variable);
|
336
|
+
return true;
|
337
|
+
} catch (error) {
|
338
|
+
return false;
|
339
|
+
}
|
342
340
|
}
|
343
341
|
|
344
342
|
/**
|
@@ -347,7 +345,7 @@ function isURL(variable) {
|
|
347
345
|
* @return {boolean}
|
348
346
|
*/
|
349
347
|
function isBlob(variable) {
|
350
|
-
|
348
|
+
return variable instanceof Blob;
|
351
349
|
}
|
352
350
|
|
353
351
|
/**
|
@@ -356,12 +354,12 @@ function isBlob(variable) {
|
|
356
354
|
* @return {Promise<unknown>}
|
357
355
|
*/
|
358
356
|
function blobToText(blob) {
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
357
|
+
return new Promise((resolve, reject) => {
|
358
|
+
const reader = new FileReader();
|
359
|
+
reader.onloadend = () => resolve(reader.result);
|
360
|
+
reader.onerror = reject;
|
361
|
+
reader.readAsText(blob);
|
362
|
+
});
|
365
363
|
}
|
366
364
|
|
367
365
|
/**
|
@@ -370,18 +368,18 @@ function blobToText(blob) {
|
|
370
368
|
* @throws {Error} no shadow-root is defined
|
371
369
|
*/
|
372
370
|
function initControlReferences() {
|
373
|
-
|
374
|
-
|
375
|
-
|
371
|
+
if (!this.shadowRoot) {
|
372
|
+
throw new Error("no shadow-root is defined");
|
373
|
+
}
|
376
374
|
|
377
|
-
|
375
|
+
this[viewerElementSymbol] = this.shadowRoot.getElementById("viewer");
|
378
376
|
}
|
379
377
|
|
380
378
|
/**
|
381
379
|
* @private
|
382
380
|
*/
|
383
381
|
function initEventHandler() {
|
384
|
-
|
382
|
+
return this;
|
385
383
|
}
|
386
384
|
|
387
385
|
/**
|
@@ -389,8 +387,8 @@ function initEventHandler() {
|
|
389
387
|
* @return {string}
|
390
388
|
*/
|
391
389
|
function getTemplate() {
|
392
|
-
|
393
|
-
|
390
|
+
// language=HTML
|
391
|
+
return `
|
394
392
|
<div id="viewer" data-monster-role="viewer" part="viewer"
|
395
393
|
data-monster-replace="path:content"
|
396
394
|
data-monster-attributes="class path:classes.viewer">
|