qti3-item-player-vue3 0.2.4 → 0.2.5

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.
@@ -127,6 +127,8 @@ const QTI_PCI_API = {
127
127
  properties: null,
128
128
  contextVariables: null,
129
129
  templateVariables: null,
130
+ stylesheets: null,
131
+ catalogInfo: null,
130
132
  moduleResolution: null,
131
133
  instance: null,
132
134
  response: null,
@@ -137,107 +139,125 @@ const QTI_PCI_API = {
137
139
  height: 0,
138
140
  onQtiInteractionChanged: null,
139
141
 
140
- getInstance: function () {
142
+ getInstance () {
141
143
  return this.instance;
142
144
  },
143
145
 
144
- setInstance: function (instance) {
146
+ setInstance (instance) {
145
147
  this.instance = instance;
146
148
  },
147
149
 
148
- getTypeIdentifier: function () {
150
+ getTypeIdentifier () {
149
151
  return this.typeIdentifier;
150
152
  },
151
153
 
152
- setTypeIdentifier: function (typeIdentifier) {
154
+ setTypeIdentifier (typeIdentifier) {
153
155
  this.typeIdentifier = typeIdentifier;
154
156
  },
155
157
 
156
- getResponseIdentifier: function () {
158
+ getResponseIdentifier () {
157
159
  return this.responseIdentifier;
158
160
  },
159
161
 
160
- setResponseIdentifier: function (responseIdentifier) {
162
+ setResponseIdentifier (responseIdentifier) {
161
163
  this.responseIdentifier = responseIdentifier;
162
164
  },
163
165
 
164
- getPci: function () {
166
+ getPci () {
165
167
  return this.pci;
166
168
  },
167
169
 
168
- setPci: function (pci) {
170
+ setPci (pci) {
169
171
  this.pci = pci;
170
172
  },
171
173
 
172
- getDom: function () {
174
+ getDom () {
173
175
  return this.dom;
174
176
  },
175
177
 
176
- setDom: function (dom) {
178
+ setDom (dom) {
177
179
  this.dom = dom;
178
180
  },
179
181
 
180
- getProperties: function () {
182
+ getProperties () {
181
183
  return this.properties;
182
184
  },
183
185
 
184
- setProperties: function (properties) {
186
+ setProperties (properties) {
185
187
  this.properties = properties;
186
188
  },
187
189
 
188
- getContextVariables: function () {
190
+ getContextVariables () {
189
191
  return this.contextVariables;
190
192
  },
191
193
 
192
- setContextVariables: function (contextVariables) {
194
+ setContextVariables (contextVariables) {
193
195
  this.contextVariables = contextVariables;
194
196
  },
195
197
 
196
- getTemplateVariables: function () {
198
+ getTemplateVariables () {
197
199
  return this.templateVariables;
198
200
  },
199
201
 
200
- setTemplateVariables: function (templateVariables) {
202
+ setTemplateVariables (templateVariables) {
201
203
  this.templateVariables = templateVariables;
202
204
  },
203
205
 
204
- getBoundTo: function () {
206
+ getStylesheets () {
207
+ return this.stylesheets;
208
+ },
209
+
210
+ setStylesheets (stylesheets) {
211
+ if (typeof stylesheets === 'undefined') return;
212
+ this.stylesheets = stylesheets;
213
+ },
214
+
215
+ getCatalogInfo () {
216
+ return this.catalogInfo;
217
+ },
218
+
219
+ setCatalogInfo (catalogInfo) {
220
+ if (typeof catalogInfo === 'undefined') return;
221
+ this.catalogInfo = catalogInfo;
222
+ },
223
+
224
+ getBoundTo () {
205
225
  return this.boundTo;
206
226
  },
207
227
 
208
- setBoundTo: function (boundTo) {
228
+ setBoundTo (boundTo) {
209
229
  this.boundTo = boundTo;
210
230
  },
211
231
 
212
- getStatus: function () {
232
+ getStatus () {
213
233
  return this.status;
214
234
  },
215
235
 
216
- setStatus: function (status) {
236
+ setStatus (status) {
217
237
  this.status = status;
218
238
  },
219
239
 
220
- getModuleResolution: function () {
240
+ getModuleResolution () {
221
241
  return this.moduleResolution;
222
242
  },
223
243
 
224
- setModuleResolution: function (moduleResolution) {
244
+ setModuleResolution (moduleResolution) {
225
245
  this.moduleResolution = moduleResolution;
226
246
  },
227
247
 
228
- getState: function () {
248
+ getState () {
229
249
  return this.state;
230
250
  },
231
251
 
232
- setState: function (state) {
252
+ setState (state) {
233
253
  this.state = (typeof state === 'undefined') ? null : JSON.parse(state);
234
254
  },
235
255
 
236
- getStateFromState: function () {
256
+ getStateFromState () {
237
257
  return (this.state === null) ? null : this.state.state;
238
258
  },
239
259
 
240
- getResponseFromState: function () {
260
+ getResponseFromState () {
241
261
  return (this.state === null) ? undefined : this.state.response;
242
262
  },
243
263
 
@@ -246,7 +266,7 @@ const QTI_PCI_API = {
246
266
  * Upon completion, call NotifyPciStateReady, passing the
247
267
  * stringified response and state as parameters.
248
268
  */
249
- getInteractionState: function () {
269
+ getInteractionState () {
250
270
  const obj = {
251
271
  response: null,
252
272
  state: null
@@ -265,7 +285,7 @@ const QTI_PCI_API = {
265
285
  this.NotifyPciStateReady(JSON.stringify(obj));
266
286
  },
267
287
 
268
- initialize: function (pci) {
288
+ initialize (pci) {
269
289
  this.setDom(document.getElementById('qti3-player-pci-element'));
270
290
  this.setPci(pci);
271
291
  this.setTypeIdentifier(pci.typeIdentifier);
@@ -273,13 +293,16 @@ const QTI_PCI_API = {
273
293
  this.setModuleResolution(pci.moduleResolution);
274
294
  this.setContextVariables(pci.contextVariables);
275
295
  this.setTemplateVariables(pci.templateVariables);
296
+ this.setStylesheets(pci.stylesheets);
297
+ this.setCatalogInfo(pci.catalogInfo);
276
298
  this.setBoundTo(pci.boundTo);
277
299
  this.setStatus(pci.status)
278
300
 
279
301
  this.trackResize(this.getDom());
280
302
  this.trackQtiInteractionChanged(this.getDom());
303
+ this.injectStylesheets();
281
304
  this.injectClassAttribute();
282
- this.injectMarkup();
305
+ this.injectMarkup();
283
306
  this.launchPci(
284
307
  this.getTypeIdentifier(),
285
308
  this.getDom(),
@@ -293,13 +316,13 @@ const QTI_PCI_API = {
293
316
  );
294
317
  },
295
318
 
296
- injectClassAttribute: function () {
319
+ injectClassAttribute () {
297
320
  if (this.getPci().classAttribute.length == 0) return
298
321
  let wrapperEl = document.getElementById('qti3-player-pci-wrapper');
299
322
  wrapperEl.classList.add(this.getPci().classAttribute);
300
323
  },
301
324
 
302
- injectMarkup: function () {
325
+ injectMarkup () {
303
326
  this.getDom().innerHTML =
304
327
  `<div
305
328
  id="qti3-player-pci-markup"
@@ -307,7 +330,21 @@ const QTI_PCI_API = {
307
330
  >${this.getPci().markup}</div>`;
308
331
  },
309
332
 
310
- getModuleDependencies: function () {
333
+ injectStylesheets () {
334
+ const stylesheets = this.getStylesheets();
335
+ if (stylesheets === null) return;
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
+ });
345
+ },
346
+
347
+ getModuleDependencies () {
311
348
  // Init qtiCustomInteractionContext as the first dependency
312
349
  let dependencies = ['qtiCustomInteractionContext'];
313
350
 
@@ -333,7 +370,7 @@ const QTI_PCI_API = {
333
370
  * @param {Object} boundTo The response variable this PCI is bound to and its value
334
371
  * @param {String} status Item lifecycle status; e.g., 'interacting'
335
372
  */
336
- launchPci: function (
373
+ launchPci (
337
374
  typeIdentifier,
338
375
  dom,
339
376
  responseIdentifier,
@@ -374,7 +411,7 @@ const QTI_PCI_API = {
374
411
  });
375
412
  },
376
413
 
377
- NotifyPciChildLoaded: function () {
414
+ NotifyPciChildLoaded () {
378
415
  if (self == top) return;
379
416
 
380
417
  // Extract the identifier qs param
@@ -384,7 +421,7 @@ const QTI_PCI_API = {
384
421
  window.parent.postMessage({ message: 'PciChildLoaded', identifier: this.getResponseIdentifier(), success: true },'*');
385
422
  },
386
423
 
387
- NotifyPciReady: function (instance, state) {
424
+ NotifyPciReady (instance, state) {
388
425
  this.setInstance(instance);
389
426
 
390
427
  if (self == top) return;
@@ -397,7 +434,7 @@ const QTI_PCI_API = {
397
434
  window.parent.postMessage({ message: 'PciReady', identifier: this.getResponseIdentifier(), width: computedWidth, height: computedHeight, success: true },'*');
398
435
  },
399
436
 
400
- NotifyPciDone: function (instance, response, state, status) {
437
+ NotifyPciDone (instance, response, state, status) {
401
438
  if (self == top) return;
402
439
 
403
440
  const stringifiedState = JSON.stringify({
@@ -408,12 +445,12 @@ const QTI_PCI_API = {
408
445
  window.parent.postMessage({ message: 'PciDone', identifier: this.getResponseIdentifier(), state: stringifiedStateObject, status: status, success: true },'*');
409
446
  },
410
447
 
411
- NotifyPciStateReady: function(stringifiedStateObject) {
448
+ NotifyPciStateReady (stringifiedStateObject) {
412
449
  if (self == top) return;
413
450
  window.parent.postMessage({ message: 'PciGetState_Reply', identifier: this.getResponseIdentifier(), state: stringifiedStateObject, success: true },'*');
414
451
  },
415
452
 
416
- NotifyPciInteractionChanged: function(valid, value) {
453
+ NotifyPciInteractionChanged (valid, value) {
417
454
  if (self == top) return;
418
455
 
419
456
  const stringifiedState = JSON.stringify({
@@ -430,7 +467,7 @@ const QTI_PCI_API = {
430
467
  * @method getQueryParameterByName
431
468
  * @param {String} name The name of the paramter to get from the URL.
432
469
  */
433
- getQueryParameterByName: function (name) {
470
+ getQueryParameterByName (name) {
434
471
  let regex = new RegExp("[\\?&]" + name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]') + '=([^&#]*)');
435
472
  let results = regex.exec(window.location.search);
436
473
 
@@ -439,7 +476,7 @@ const QTI_PCI_API = {
439
476
  return decodeURIComponent(results[1].replace(/\+/g, " "));
440
477
  },
441
478
 
442
- bindWindowEventListener: function (element, eventName, eventHandler) {
479
+ bindWindowEventListener (element, eventName, eventHandler) {
443
480
  if (element.addEventListener) {
444
481
  element.addEventListener(eventName, eventHandler, false);
445
482
  } else if (element.attachEvent) {
@@ -448,7 +485,7 @@ const QTI_PCI_API = {
448
485
  }
449
486
  },
450
487
 
451
- trackResize: function (element) {
488
+ trackResize (element) {
452
489
  // create a mutation observer instance
453
490
  let observer = new MutationObserver(function(mutations) {
454
491
  mutations.forEach(function(mutation) {
@@ -475,12 +512,12 @@ const QTI_PCI_API = {
475
512
  });
476
513
  },
477
514
 
478
- trackQtiInteractionChanged: function (domElement) {
515
+ trackQtiInteractionChanged (domElement) {
479
516
  this.onQtiInteractionChanged = this.onQtiInteractionChangedHandler.bind(this);
480
517
  domElement.addEventListener('qti-interaction-changed', this.onQtiInteractionChanged);
481
518
  },
482
519
 
483
- onQtiInteractionChangedHandler: function(event) {
520
+ onQtiInteractionChangedHandler (event) {
484
521
  event.preventDefault();
485
522
 
486
523
  if (typeof event.detail === 'undefined') {
@@ -1557,6 +1557,34 @@ class re {
1557
1557
  computeNodeContext(t) {
1558
1558
  return t === null || t.$options.name === "QtiAssessmentItem" ? "ITEM" : t.$options.name === "QtiAssessmentTest" ? "TEST" : this.computeNodeContext(t.$parent);
1559
1559
  }
1560
+ base64ToBytes(t) {
1561
+ const i = atob(t);
1562
+ return Uint8Array.from(i, (s) => s.codePointAt(0));
1563
+ }
1564
+ bytesToBase64(t) {
1565
+ const i = Array.from(
1566
+ t,
1567
+ (s) => String.fromCodePoint(s)
1568
+ ).join("");
1569
+ return btoa(i);
1570
+ }
1571
+ /**
1572
+ * @description Utility method to base64-encode arbitrary bytes.
1573
+ * @param {*} bytes
1574
+ * @returns base64-encoded string
1575
+ */
1576
+ encodeBytesToBase64(t) {
1577
+ const i = new TextEncoder();
1578
+ return this.bytesToBase64(i.encode(t));
1579
+ }
1580
+ /**
1581
+ * @description Utility method to decode base64 bytes.
1582
+ * @param {*} base64
1583
+ * @returns decoded string
1584
+ */
1585
+ decodeBase64ToBytes(t) {
1586
+ return new TextDecoder().decode(this.base64ToBytes(t));
1587
+ }
1560
1588
  }
1561
1589
  const yv = new re(), S = {
1562
1590
  player: null,
@@ -9026,6 +9054,12 @@ const J1 = {
9026
9054
  };
9027
9055
  },
9028
9056
  methods: {
9057
+ getHref() {
9058
+ return this.href;
9059
+ },
9060
+ getType() {
9061
+ return this.type;
9062
+ },
9029
9063
  /**
9030
9064
  * @description Pull the stylesheet from the Href URI.
9031
9065
  * Wrap stylesheet contents in a style element, then inject into the
@@ -28837,6 +28871,8 @@ const ah = new j(), Nm = new re(), NO = {
28837
28871
  configuration: null,
28838
28872
  templateVariables: [],
28839
28873
  contextVariables: [],
28874
+ stylesheets: [],
28875
+ catalogInfoNode: null,
28840
28876
  uniqueId: null,
28841
28877
  pciIframe: null,
28842
28878
  isReady: !1,
@@ -28995,36 +29031,47 @@ const ah = new j(), Nm = new re(), NO = {
28995
29031
  */
28996
29032
  validateChildren() {
28997
29033
  if (!this.$slots.default) return;
28998
- let e = !1, t = !1, i = !1, s = !1, n = !1;
28999
- this.$slots.default().forEach((r) => {
29000
- if (ah.isValidSlot(r)) {
29001
- if (r.type.name === "QtiPrompt") {
29002
- if (t || i || s || n)
29034
+ let e = !1, t = !1, i = !1, s = !1, n = !1, r = !1, a = !1;
29035
+ this.$slots.default().forEach((o) => {
29036
+ if (ah.isValidSlot(o)) {
29037
+ if (o.type.name === "QtiPrompt") {
29038
+ if (t || i || s || n || r || a)
29003
29039
  throw new l("Invalid element order. qti-prompt must be the first element");
29004
29040
  if (!e) return e = !0;
29005
29041
  throw new l("Maximum of 1 qti-prompt element permitted");
29006
29042
  }
29007
- if (r.type.name === "QtiInteractionModules") {
29008
- if (t || s || n)
29043
+ if (o.type.name === "QtiInteractionModules") {
29044
+ if (t || s || n || r || a)
29009
29045
  throw new l("Invalid element order: qti-interaction-modules");
29010
29046
  if (!i) return i = !0;
29011
29047
  throw new l("Maximum of 1 qti-interaction-modules element permitted");
29012
29048
  }
29013
- if (r.type.name === "QtiInteractionMarkup") {
29014
- if (s || n)
29049
+ if (o.type.name === "QtiInteractionMarkup") {
29050
+ if (s || n || r || a)
29015
29051
  throw new l("Invalid element order: qti-interaction-markup");
29016
29052
  if (!t) return t = !0;
29017
29053
  throw new l("Maximum of 1 qti-interaction-markup element permitted");
29018
29054
  }
29019
- if (r.type.name === "QtiTemplateVariable") {
29020
- if (s)
29055
+ if (o.type.name === "QtiTemplateVariable") {
29056
+ if (s || r || a)
29021
29057
  throw new l("Invalid element order: qti-template-variable");
29022
- if (!n) return n = !0;
29023
- throw new l("Maximum of 1 qti-interaction-markup element permitted");
29058
+ return n = !0;
29059
+ }
29060
+ if (o.type.name === "QtiContextVariable") {
29061
+ if (r || a)
29062
+ throw new l("Invalid element order: qti-context-variable");
29063
+ return s = !0;
29064
+ }
29065
+ if (o.type.name === "QtiStylesheet") {
29066
+ if (a)
29067
+ throw new l("Invalid element order: qti-stylesheet");
29068
+ return r = !0;
29024
29069
  }
29025
- if (r.type.name === "QtiContextVariable") return s = !0;
29026
- if (r.type.name === "QtiStylesheet") return !0;
29027
- throw new l('Node is not permitted inside QtiPortableCustomInteraction: "' + r.type.name + '"');
29070
+ if (o.type.name === "QtiCatalogInfo") {
29071
+ if (!a) return a = !0;
29072
+ throw new l("Maximum of 1 qti-catalog-info element permitted");
29073
+ }
29074
+ throw new l('Node is not permitted inside QtiPortableCustomInteraction: "' + o.type.name + '"');
29028
29075
  }
29029
29076
  });
29030
29077
  },
@@ -29046,6 +29093,12 @@ const ah = new j(), Nm = new re(), NO = {
29046
29093
  case "QtiContextVariable":
29047
29094
  this.contextVariables.push(i);
29048
29095
  break;
29096
+ case "QtiStylesheet":
29097
+ this.stylesheets.push(i);
29098
+ break;
29099
+ case "QtiCatalogInfo":
29100
+ this.catalogInfoNode = i;
29101
+ break;
29049
29102
  }
29050
29103
  }), this.priorState !== null && this.restoreValue(this.priorState.value, this.priorState.state), this.initialWidth = this.$refs.root.clientWidth);
29051
29104
  },
@@ -29116,6 +29169,17 @@ const ah = new j(), Nm = new re(), NO = {
29116
29169
  e[this.templateVariables[t].getIdentifier()] = this.templateVariables[t].evaluate();
29117
29170
  return e;
29118
29171
  },
29172
+ getStylesheets() {
29173
+ let e = [];
29174
+ for (let t = 0; t < this.stylesheets.length; t++) {
29175
+ const i = this.stylesheets[t];
29176
+ e.push({ href: i.getHref(), type: i.getType() });
29177
+ }
29178
+ return e;
29179
+ },
29180
+ getCatalogInfo() {
29181
+ return this.catalogInfoNode;
29182
+ },
29119
29183
  getModules() {
29120
29184
  return this.modules;
29121
29185
  },
@@ -29158,6 +29222,8 @@ const ah = new j(), Nm = new re(), NO = {
29158
29222
  boundTo: this.getResponseVariable(),
29159
29223
  templateVariables: this.getTemplateVariables(),
29160
29224
  contextVariables: this.getContextVariables(),
29225
+ stylesheets: this.getStylesheets(),
29226
+ catalogInfo: this.getCatalogInfo(),
29161
29227
  module: this.module,
29162
29228
  modules: this.getModules(),
29163
29229
  moduleResolution: this.getConfiguration(),