@schukai/monster 4.120.0 → 4.120.1
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/viewer.mjs +113 -9
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +14 -6
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.120.
|
|
1
|
+
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.120.1"}
|
|
@@ -138,7 +138,14 @@ class Viewer extends CustomElement {
|
|
|
138
138
|
/**
|
|
139
139
|
* Sets the content of an element based on the provided content and media type.
|
|
140
140
|
*
|
|
141
|
-
*
|
|
141
|
+
* Supported forms:
|
|
142
|
+
* - setContent(contentString, mediaType)
|
|
143
|
+
* - setContent({ mediaType, data, encoding })
|
|
144
|
+
*
|
|
145
|
+
* The declarative form requires an explicit `encoding` when `data` is a string.
|
|
146
|
+
* Use `encoding: "url"` for URLs and `encoding: "base64"` for base64 payloads.
|
|
147
|
+
*
|
|
148
|
+
* @param {string|object} content - The content to be set or a declarative payload.
|
|
142
149
|
* @param {string} [mediaType="text/plain"] - The media type of the content. Defaults to "text/plain" if not specified.
|
|
143
150
|
* @return {void} This method does not return a value.
|
|
144
151
|
* @throws {Error} Throws an error if shadowRoot is not defined.
|
|
@@ -148,6 +155,44 @@ class Viewer extends CustomElement {
|
|
|
148
155
|
throw new Error("no shadow-root is defined");
|
|
149
156
|
}
|
|
150
157
|
|
|
158
|
+
let declarativePayload = null;
|
|
159
|
+
// Declarative form: { mediaType, data, encoding }
|
|
160
|
+
if (
|
|
161
|
+
content &&
|
|
162
|
+
typeof content === "object" &&
|
|
163
|
+
!isBlob(content) &&
|
|
164
|
+
!(content instanceof URL)
|
|
165
|
+
) {
|
|
166
|
+
const { mediaType: mt, data, encoding } = content;
|
|
167
|
+
mediaType = mt ?? mediaType ?? "text/plain";
|
|
168
|
+
declarativePayload = { data, encoding };
|
|
169
|
+
|
|
170
|
+
if (isString(data)) {
|
|
171
|
+
if (!encoding) {
|
|
172
|
+
this.dispatchEvent(
|
|
173
|
+
new CustomEvent("viewer-error", {
|
|
174
|
+
detail: "String content requires explicit encoding",
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (encoding === "base64") {
|
|
180
|
+
content = data;
|
|
181
|
+
} else if (encoding === "url") {
|
|
182
|
+
content = data;
|
|
183
|
+
} else {
|
|
184
|
+
this.dispatchEvent(
|
|
185
|
+
new CustomEvent("viewer-error", {
|
|
186
|
+
detail: "Invalid encoding",
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
content = data;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
151
196
|
const renderers = this.getOption("renderers");
|
|
152
197
|
|
|
153
198
|
const isDataURL = (value) => {
|
|
@@ -235,7 +280,10 @@ class Viewer extends CustomElement {
|
|
|
235
280
|
switch (mediaTypeObject.subtype) {
|
|
236
281
|
case "pdf":
|
|
237
282
|
if (checkRenderer("pdf", mediaTypeObject.toString())) {
|
|
238
|
-
renderers.pdf.call(
|
|
283
|
+
renderers.pdf.call(
|
|
284
|
+
this,
|
|
285
|
+
declarativePayload ? declarativePayload : content,
|
|
286
|
+
);
|
|
239
287
|
}
|
|
240
288
|
break;
|
|
241
289
|
|
|
@@ -426,13 +474,63 @@ class Viewer extends CustomElement {
|
|
|
426
474
|
/**
|
|
427
475
|
* Configures and embeds a PDF document into the application with customizable display settings.
|
|
428
476
|
*
|
|
429
|
-
*
|
|
477
|
+
* Supported forms:
|
|
478
|
+
* - setPDF(blobOrUrlOrBase64String, navigation, toolbar, scrollbar)
|
|
479
|
+
* - setPDF({ data, encoding, navigation, toolbar, scrollbar })
|
|
480
|
+
*
|
|
481
|
+
* The declarative form requires an explicit `encoding` when `data` is a string.
|
|
482
|
+
* Use `encoding: "url"` for URLs and `encoding: "base64"` for base64 payloads.
|
|
483
|
+
*
|
|
484
|
+
* @param {Blob|URL|string|object} data The PDF data to be embedded. Can be provided as a Blob, URL, or base64 string,
|
|
485
|
+
* or a declarative payload: { data, encoding, navigation, toolbar, scrollbar }.
|
|
430
486
|
* @param {boolean} [navigation=true] Determines whether the navigation pane is displayed in the PDF viewer.
|
|
431
487
|
* @param {boolean} [toolbar=true] Controls the visibility of the toolbar in the PDF viewer.
|
|
432
488
|
* @param {boolean} [scrollbar=false] Configures the display of the scrollbar in the PDF viewer.
|
|
433
489
|
* @return {void} This method returns nothing but sets the embedded PDF as the content.
|
|
434
490
|
*/
|
|
435
491
|
setPDF(data, navigation = true, toolbar = true, scrollbar = false) {
|
|
492
|
+
let stringEncoding = null;
|
|
493
|
+
// Declarative form: { data, encoding, navigation, toolbar, scrollbar }
|
|
494
|
+
if (
|
|
495
|
+
data &&
|
|
496
|
+
typeof data === "object" &&
|
|
497
|
+
!isBlob(data) &&
|
|
498
|
+
!(data instanceof URL)
|
|
499
|
+
) {
|
|
500
|
+
const payload = data;
|
|
501
|
+
data = payload.data;
|
|
502
|
+
stringEncoding = payload.encoding ?? null;
|
|
503
|
+
if (typeof payload.navigation === "boolean") {
|
|
504
|
+
navigation = payload.navigation;
|
|
505
|
+
}
|
|
506
|
+
if (typeof payload.toolbar === "boolean") {
|
|
507
|
+
toolbar = payload.toolbar;
|
|
508
|
+
}
|
|
509
|
+
if (typeof payload.scrollbar === "boolean") {
|
|
510
|
+
scrollbar = payload.scrollbar;
|
|
511
|
+
}
|
|
512
|
+
if (isString(data)) {
|
|
513
|
+
if (!payload.encoding) {
|
|
514
|
+
this.dispatchEvent(
|
|
515
|
+
new CustomEvent("viewer-error", {
|
|
516
|
+
detail: "String PDF data requires explicit encoding",
|
|
517
|
+
}),
|
|
518
|
+
);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (payload.encoding === "base64") {
|
|
522
|
+
// handled below as string/base64
|
|
523
|
+
} else if (payload.encoding === "url") {
|
|
524
|
+
// handled below as string/url
|
|
525
|
+
} else {
|
|
526
|
+
this.dispatchEvent(
|
|
527
|
+
new CustomEvent("viewer-error", { detail: "Invalid encoding" }),
|
|
528
|
+
);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
436
534
|
const hashes =
|
|
437
535
|
"#toolbar=" +
|
|
438
536
|
(toolbar ? "1" : "0") +
|
|
@@ -440,7 +538,6 @@ class Viewer extends CustomElement {
|
|
|
440
538
|
(navigation ? "1" : "0") +
|
|
441
539
|
"&scrollbar=" +
|
|
442
540
|
(scrollbar ? "1" : "0");
|
|
443
|
-
|
|
444
541
|
let pdfURL = "";
|
|
445
542
|
if (isBlob(data)) {
|
|
446
543
|
pdfURL = URL.createObjectURL(data);
|
|
@@ -453,11 +550,18 @@ class Viewer extends CustomElement {
|
|
|
453
550
|
pdfURL = data.toString();
|
|
454
551
|
}
|
|
455
552
|
} else if (isString(data)) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
553
|
+
if (stringEncoding === "url") {
|
|
554
|
+
if (data.indexOf("#") === -1) {
|
|
555
|
+
pdfURL = data + hashes;
|
|
556
|
+
} else {
|
|
557
|
+
pdfURL = data;
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
// Default legacy behavior: treat string as base64
|
|
561
|
+
const blobObj = new Blob([atob(data)], { type: "application/pdf" });
|
|
562
|
+
const url = window.URL.createObjectURL(blobObj);
|
|
563
|
+
pdfURL = url + hashes;
|
|
564
|
+
}
|
|
461
565
|
} else {
|
|
462
566
|
this.dispatchEvent(
|
|
463
567
|
new CustomEvent("viewer-error", { detail: "Blob or URL expected" }),
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED
package/test/web/test.html
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
|
|
12
|
-
<h1 style='margin-bottom: 0.1em;'>Monster 4.
|
|
13
|
-
<div id="lastupdate" style='font-size:0.7em'>last update
|
|
12
|
+
<h1 style='margin-bottom: 0.1em;'>Monster 4.120.0</h1>
|
|
13
|
+
<div id="lastupdate" style='font-size:0.7em'>last update Do 12. Feb 21:50:57 CET 2026</div>
|
|
14
14
|
</div>
|
|
15
15
|
<div id="mocha-errors"
|
|
16
16
|
style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div>
|