@schukai/monster 4.22.1 → 4.22.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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
 
4
4
 
5
+ ## [4.22.2] - 2025-06-22
6
+
7
+ ### Bug Fixes
8
+
9
+ - Add audio and video support to the viewer [#309](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/309)
10
+
11
+
12
+
5
13
  ## [4.22.1] - 2025-06-22
6
14
 
7
15
  ### Bug Fixes
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.1","@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.22.1"}
1
+ {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.1","@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.22.2"}
@@ -87,6 +87,8 @@ class Viewer extends CustomElement {
87
87
  pdf: this.setPDF,
88
88
  plaintext: this.setPlainText,
89
89
  markdown: this.setMarkdown,
90
+ audio: this.setAudio,
91
+ video: this.setVideo,
90
92
  }
91
93
  });
92
94
  }
@@ -189,6 +191,18 @@ class Viewer extends CustomElement {
189
191
  }
190
192
  break;
191
193
 
194
+ case "audio":
195
+ if (checkRenderer(mediaTypeObject.type, mediaTypeObject.toString())) {
196
+ renderers[mediaTypeObject.type].call(this, content);
197
+ }
198
+ break;
199
+
200
+ case "video":
201
+ if (checkRenderer(mediaTypeObject.type, mediaTypeObject.toString())) {
202
+ renderers[mediaTypeObject.type].call(this, content);
203
+ }
204
+ break;
205
+
192
206
  case "image":
193
207
  if (checkRenderer("image", mediaTypeObject.toString())) {
194
208
  renderers.image.call(this, content);
@@ -202,6 +216,63 @@ class Viewer extends CustomElement {
202
216
  }
203
217
  }
204
218
 
219
+ /**
220
+ * Sets the audio content for the viewer. Accepts a Blob, URL, or string and processes it
221
+ * to configure audio playback within the viewer. Throws an error if the input type is invalid.
222
+ *
223
+ * @param {Blob|string} data - The audio content. This can be a Blob, a URL, or a string.
224
+ * @return {void} No return value.
225
+ */
226
+ setAudio(data) {
227
+ if (isBlob(data)) {
228
+ data = URL.createObjectURL(data);
229
+ } else if (isURL(data)) {
230
+ // nothing to do
231
+ } else if (isString(data)) {
232
+ // nothing to do
233
+ } else {
234
+ this.dispatchEvent(new CustomEvent("viewer-error", {detail: "Blob or URL expected"}));
235
+ throw new Error("Blob or URL expected");
236
+ }
237
+
238
+ this.setOption(
239
+ "content",
240
+ `
241
+ <audio controls part="audio">
242
+ <source src="${data}">
243
+ </audio>`
244
+ );
245
+ }
246
+
247
+ /**
248
+ * Sets the video content for the viewer. The method accepts a Blob, URL, or string,
249
+ * verifies its type, and updates the viewer's content accordingly.
250
+ *
251
+ * @param {Blob|string} data - The video data to set. It can be a Blob, URL, or string.
252
+ * @return {void} This method does not return a value. It updates the viewer's state.
253
+ * @throws {Error} Throws an error if the provided data is not a Blob or URL.
254
+ */
255
+ setVideo(data) {
256
+ if (isBlob(data)) {
257
+ data = URL.createObjectURL(data);
258
+ } else if (isURL(data)) {
259
+ // nothing to do
260
+ } else if (isString(data)) {
261
+ // nothing to do
262
+ } else {
263
+ this.dispatchEvent(new CustomEvent("viewer-error", {detail: "Blob or URL expected"}));
264
+ throw new Error("Blob or URL expected");
265
+ }
266
+
267
+ this.setOption(
268
+ "content",
269
+ `
270
+ <video controls part="video">
271
+ <source src="${data}">
272
+ </video>`
273
+ );
274
+ }
275
+
205
276
  /**
206
277
  * Renders Markdown content using built-in or custom Markdown parser.
207
278
  * Overrideable via `customRenderers['text/markdown']`.