qti3-item-player-vue3 0.2.5 → 0.2.7

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.
@@ -289,7 +289,7 @@ const QTI_PCI_API = {
289
289
  this.setDom(document.getElementById('qti3-player-pci-element'));
290
290
  this.setPci(pci);
291
291
  this.setTypeIdentifier(pci.typeIdentifier);
292
- this.setProperties(pci.properties);
292
+ this.setProperties(this.transformProperties(pci.properties));
293
293
  this.setModuleResolution(pci.moduleResolution);
294
294
  this.setContextVariables(pci.contextVariables);
295
295
  this.setTemplateVariables(pci.templateVariables);
@@ -331,29 +331,52 @@ const QTI_PCI_API = {
331
331
  },
332
332
 
333
333
  injectStylesheets () {
334
- const stylesheets = this.getStylesheets();
335
- if (stylesheets === null) return;
334
+ const stylesheets = this.getStylesheets()
335
+ if (stylesheets === null) return
336
336
  stylesheets.forEach((stylesheet) => {
337
- // Get the head element
338
- const head = document.head;
339
- const link = document.createElement('link');
340
- link.rel = 'stylesheet';
341
- link.href = stylesheet.href;
342
- link.type = stylesheet.type;
343
- head.appendChild(link);
344
- });
337
+ if (!stylesheet.hasOwnProperty('css')) return
338
+ // Stylesheet css property is base64. Decode it.
339
+ const cssText = this.decodeBase64ToBytes(stylesheet.css)
340
+ const style = document.createElement('style')
341
+ style.innerHTML = `${cssText}`
342
+ document.head.appendChild(style)
343
+ })
344
+ },
345
+
346
+ /**
347
+ * @description Transform the given properties object into a new object
348
+ * containing the same keys, but with base64-decoded values.
349
+ * @param {Object} properties
350
+ * @return {Object} transformed properties object with decoded values
351
+ */
352
+ transformProperties (properties) {
353
+ const props = {}
354
+ for (const [key, value] of Object.entries(properties)) {
355
+ props[`${key}`] = `${this.decodeBase64ToBytes(value)}`
356
+ }
357
+ return props
358
+ },
359
+
360
+ decodeBase64ToBytes (base64) {
361
+ const textDecoder = new TextDecoder()
362
+ return textDecoder.decode(this.base64ToBytes(base64))
363
+ },
364
+
365
+ base64ToBytes (base64) {
366
+ const binString = atob(base64)
367
+ return Uint8Array.from(binString, (m) => m.codePointAt(0))
345
368
  },
346
369
 
347
370
  getModuleDependencies () {
348
371
  // Init qtiCustomInteractionContext as the first dependency
349
- let dependencies = ['qtiCustomInteractionContext'];
372
+ let dependencies = ['qtiCustomInteractionContext']
350
373
 
351
- const paths = this.getModuleResolution().paths;
374
+ const paths = this.getModuleResolution().paths
352
375
  for (let property in paths) {
353
- dependencies.push(property);
354
- };
376
+ dependencies.push(property)
377
+ }
355
378
 
356
- return dependencies;
379
+ return dependencies
357
380
  },
358
381
 
359
382
  /**