@qti-components/extended 0.0.0-stage → 1.0.0-next.0

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.
Files changed (62) hide show
  1. package/LICENSE.md +674 -0
  2. package/dist/elements.d.ts +100 -0
  3. package/dist/elements.js +44 -0
  4. package/dist/elements.js.map +1 -0
  5. package/dist/index.d.ts +11 -0
  6. package/dist/index.js +12 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/qti-extended-jsx.d.ts +1894 -0
  9. package/dist/qti-extended-jsx.js +1 -0
  10. package/dist/register.d.ts +1 -0
  11. package/dist/register.js +7 -0
  12. package/dist/register.js.map +1 -0
  13. package/dist/test-bookmark/test-bookmark.d.ts +45 -0
  14. package/dist/test-bookmark/test-bookmark.js +136 -0
  15. package/dist/test-bookmark/test-bookmark.js.map +1 -0
  16. package/dist/test-character-sheet/test-character-sheet.d.ts +46 -0
  17. package/dist/test-character-sheet/test-character-sheet.js +259 -0
  18. package/dist/test-character-sheet/test-character-sheet.js.map +1 -0
  19. package/dist/test-item-link/test-item-link.d.ts +13 -0
  20. package/dist/test-item-link/test-item-link.js +28 -0
  21. package/dist/test-item-link/test-item-link.js.map +1 -0
  22. package/dist/test-lock/test-lock.d.ts +72 -0
  23. package/dist/test-lock/test-lock.js +242 -0
  24. package/dist/test-lock/test-lock.js.map +1 -0
  25. package/dist/test-print-context/test-print-context.d.ts +11 -0
  26. package/dist/test-print-context/test-print-context.js +20 -0
  27. package/dist/test-print-context/test-print-context.js.map +1 -0
  28. package/dist/test-print-item-variables/test-print-item-variables.d.ts +17 -0
  29. package/dist/test-print-item-variables/test-print-item-variables.js +95 -0
  30. package/dist/test-print-item-variables/test-print-item-variables.js.map +1 -0
  31. package/dist/test-print-state/test-print-state.d.ts +29 -0
  32. package/dist/test-print-state/test-print-state.js +101 -0
  33. package/dist/test-print-state/test-print-state.js.map +1 -0
  34. package/dist/test-scoring-buttons/test-scoring-buttons.d.ts +19 -0
  35. package/dist/test-scoring-buttons/test-scoring-buttons.js +95 -0
  36. package/dist/test-scoring-buttons/test-scoring-buttons.js.map +1 -0
  37. package/dist/test-scoring-feedback/test-scoring-feedback.d.ts +13 -0
  38. package/dist/test-scoring-feedback/test-scoring-feedback.js +54 -0
  39. package/dist/test-scoring-feedback/test-scoring-feedback.js.map +1 -0
  40. package/dist/test-section-link/test-section-link.d.ts +13 -0
  41. package/dist/test-section-link/test-section-link.js +28 -0
  42. package/dist/test-section-link/test-section-link.js.map +1 -0
  43. package/dist/test-stamp/test-stamp.d.ts +29 -0
  44. package/dist/test-stamp/test-stamp.js +105 -0
  45. package/dist/test-stamp/test-stamp.js.map +1 -0
  46. package/dist/test-view-toggle/test-view-toggle.d.ts +16 -0
  47. package/dist/test-view-toggle/test-view-toggle.js +49 -0
  48. package/dist/test-view-toggle/test-view-toggle.js.map +1 -0
  49. package/dist/test-view-toggle/test-view.d.ts +20 -0
  50. package/dist/test-view-toggle/test-view.js +73 -0
  51. package/dist/test-view-toggle/test-view.js.map +1 -0
  52. package/dist/test-zoom/test-zoom.d.ts +75 -0
  53. package/dist/test-zoom/test-zoom.js +158 -0
  54. package/dist/test-zoom/test-zoom.js.map +1 -0
  55. package/dist/tts/elements.d.ts +28 -0
  56. package/dist/tts/elements.js +14 -0
  57. package/dist/tts/elements.js.map +1 -0
  58. package/dist/tts/test-item-to-speech.d.ts +260 -0
  59. package/dist/tts/test-item-to-speech.js +1091 -0
  60. package/dist/tts/test-item-to-speech.js.map +1 -0
  61. package/package.json +65 -3
  62. package/README.md +0 -3
@@ -0,0 +1,72 @@
1
+ import { LitElement } from 'lit';
2
+ import type { PropertyValues } from 'lit';
3
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
4
+ /** The lock's entry in the test's state (`session.plugins.lock`). */
5
+ export interface LockState {
6
+ /** The test is locked: the candidate left the page and nobody has unlocked it yet. */
7
+ locked: boolean;
8
+ /** How often the test was locked during this session. */
9
+ times: number;
10
+ }
11
+ /**
12
+ * The lock state of a test: whether it is locked and how often it was. For a host that shows it to a
13
+ * proctor, or unlocks from its own screen.
14
+ */
15
+ export declare const lockState: (context: Pick<ComputedContext, "plugins"> | undefined) => LockState;
16
+ /**
17
+ * Locks the test when the candidate leaves the page: another tab or window, or the page hidden. A
18
+ * modal covers the test until it is unlocked, so the candidate cannot go on answering. It is a
19
+ * deterrent for a supervised session, not security: the page is the candidate's.
20
+ *
21
+ * The lock lives in the test's state under `lock` (`session.plugins.lock`, `{ locked, times }`), so a
22
+ * host that stores `state` stores it: reloading the page does not escape it, and `times` tells a
23
+ * proctor how often the candidate left. `lockState(computedContext)` reads it.
24
+ *
25
+ * Unlocking: with a `code`, the modal asks for it, and the right code unlocks. The code is in the page
26
+ * for anyone who opens the developer tools, so it keeps a candidate from simply carrying on, nothing
27
+ * more. Without a `code`, the modal only shows its message and the host unlocks, with `unlock()` (for
28
+ * example after a proctor's action on another screen).
29
+ *
30
+ * Focus moving into an iframe (a portable custom interaction, a video) is not leaving the page.
31
+ *
32
+ * Put it inside `<test-navigation>`; it shows nothing until the test is locked. The modal's message
33
+ * is the element's content.
34
+ *
35
+ * @slot - The message in the modal.
36
+ * @attr code - The code that unlocks the test; without it only `unlock()` does.
37
+ * @attr locked - Reflected: the test is locked.
38
+ * @attr code-label - The label of the code field.
39
+ * @attr unlock-label - The label of the unlock button.
40
+ * @attr wrong-code-label - The message for a wrong code.
41
+ * @fires lock - The test was locked (also when a restored state is locked).
42
+ * @fires unlock - The test was unlocked.
43
+ * @csspart dialog - The modal.
44
+ * @csspart notice - The message. (Not `message`: the theme paints that part as a validation message.)
45
+ * @csspart form - The code field and button.
46
+ * @csspart input - The code field.
47
+ * @csspart button - The unlock button.
48
+ * @csspart error - The message for a wrong code.
49
+ */
50
+ export declare class TestLock extends LitElement {
51
+ #private;
52
+ protected computedContext?: ComputedContext;
53
+ code?: string;
54
+ codeLabel: string;
55
+ unlockLabel: string;
56
+ wrongCodeLabel: string;
57
+ locked: boolean;
58
+ private wrongCode;
59
+ static styles: import("lit").CSSResult[];
60
+ connectedCallback(): void;
61
+ disconnectedCallback(): void;
62
+ /** Unlocks the test, whatever the code: for a host that unlocks from its own screen. */
63
+ unlock(): void;
64
+ protected willUpdate(changed: PropertyValues): void;
65
+ protected updated(changed: PropertyValues): void;
66
+ render(): import("lit").TemplateResult<1>;
67
+ }
68
+ declare global {
69
+ interface HTMLElementTagNameMap {
70
+ 'test-lock': TestLock;
71
+ }
72
+ }
@@ -0,0 +1,242 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { css, html, LitElement, nothing } from 'lit';
8
+ import { consume } from '@lit/context';
9
+ import { property, state } from 'lit/decorators.js';
10
+ import { computedContext } from '@citolab/qti-components/qti-base';
11
+ import { controlStyles as styles, dispatchPublic } from '@citolab/qti-components/qti-test/plugin-api';
12
+ /**
13
+ * The lock state of a test: whether it is locked and how often it was. For a host that shows it to a
14
+ * proctor, or unlocks from its own screen.
15
+ */
16
+ export const lockState = (context) => {
17
+ const entry = context?.plugins?.lock;
18
+ return {
19
+ locked: entry?.locked === true,
20
+ times: typeof entry?.times === 'number' ? entry.times : 0
21
+ };
22
+ };
23
+ /**
24
+ * Locks the test when the candidate leaves the page: another tab or window, or the page hidden. A
25
+ * modal covers the test until it is unlocked, so the candidate cannot go on answering. It is a
26
+ * deterrent for a supervised session, not security: the page is the candidate's.
27
+ *
28
+ * The lock lives in the test's state under `lock` (`session.plugins.lock`, `{ locked, times }`), so a
29
+ * host that stores `state` stores it: reloading the page does not escape it, and `times` tells a
30
+ * proctor how often the candidate left. `lockState(computedContext)` reads it.
31
+ *
32
+ * Unlocking: with a `code`, the modal asks for it, and the right code unlocks. The code is in the page
33
+ * for anyone who opens the developer tools, so it keeps a candidate from simply carrying on, nothing
34
+ * more. Without a `code`, the modal only shows its message and the host unlocks, with `unlock()` (for
35
+ * example after a proctor's action on another screen).
36
+ *
37
+ * Focus moving into an iframe (a portable custom interaction, a video) is not leaving the page.
38
+ *
39
+ * Put it inside `<test-navigation>`; it shows nothing until the test is locked. The modal's message
40
+ * is the element's content.
41
+ *
42
+ * @slot - The message in the modal.
43
+ * @attr code - The code that unlocks the test; without it only `unlock()` does.
44
+ * @attr locked - Reflected: the test is locked.
45
+ * @attr code-label - The label of the code field.
46
+ * @attr unlock-label - The label of the unlock button.
47
+ * @attr wrong-code-label - The message for a wrong code.
48
+ * @fires lock - The test was locked (also when a restored state is locked).
49
+ * @fires unlock - The test was unlocked.
50
+ * @csspart dialog - The modal.
51
+ * @csspart notice - The message. (Not `message`: the theme paints that part as a validation message.)
52
+ * @csspart form - The code field and button.
53
+ * @csspart input - The code field.
54
+ * @csspart button - The unlock button.
55
+ * @csspart error - The message for a wrong code.
56
+ */
57
+ export class TestLock extends LitElement {
58
+ constructor() {
59
+ super(...arguments);
60
+ this.codeLabel = 'Code';
61
+ this.unlockLabel = 'Ontgrendel';
62
+ this.wrongCodeLabel = 'Deze code klopt niet.';
63
+ this.locked = false;
64
+ this.wrongCode = false;
65
+ this.#onVisibilityChange = () => {
66
+ if (document.hidden)
67
+ this.#lock();
68
+ };
69
+ this.#onBlur = () => {
70
+ // Focus moving into an iframe of the test blurs the window too; that is not leaving the page.
71
+ // The iframe is the active element only after the blur, so look once the event is through.
72
+ setTimeout(() => {
73
+ if (document.activeElement instanceof HTMLIFrameElement)
74
+ return;
75
+ this.#lock();
76
+ });
77
+ };
78
+ }
79
+ static { this.styles = [
80
+ css `
81
+ :host {
82
+ display: contents;
83
+ }
84
+ dialog {
85
+ box-sizing: border-box;
86
+ max-width: min(28rem, calc(100vw - 2rem));
87
+ padding: 1.5rem;
88
+ border: var(--qti-border-width, var(--qc-border-width, var(--cito-border-width, 1px))) solid
89
+ var(--qti-border-color, color-mix(in oklab, CanvasText 45%, Canvas));
90
+ border-radius: var(--qti-radius-box, var(--qc-radius-box, var(--cito-radius-box, 0.5rem)));
91
+ background: var(--qti-color-base-100, var(--qc-color-base-100, var(--cito-color-base-100, Canvas)));
92
+ color: var(--qti-color-base-content, var(--qc-color-base-content, var(--cito-color-base-content, CanvasText)));
93
+ font: inherit;
94
+ }
95
+ dialog::backdrop {
96
+ background: rgb(0 0 0 / 0.4);
97
+ backdrop-filter: blur(4px);
98
+ }
99
+ form {
100
+ display: flex;
101
+ flex-wrap: wrap;
102
+ align-items: end;
103
+ gap: 0.5rem;
104
+ margin-block-start: 1rem;
105
+ }
106
+ label {
107
+ display: grid;
108
+ gap: 0.25rem;
109
+ flex: 1 1 10rem;
110
+ }
111
+ input {
112
+ ${styles.ind};
113
+ cursor: text;
114
+ justify-content: start;
115
+ background: transparent;
116
+ color: inherit;
117
+ }
118
+ button {
119
+ ${styles.btn};
120
+ }
121
+ @media (hover: hover) and (pointer: fine) {
122
+ button:hover {
123
+ ${styles.btnInteractive};
124
+ }
125
+ }
126
+ button:active {
127
+ ${styles.btnActive};
128
+ }
129
+ input:focus-visible,
130
+ button:focus-visible {
131
+ ${styles.focusRing};
132
+ }
133
+ [part='error'] {
134
+ flex-basis: 100%;
135
+ margin: 0;
136
+ }
137
+ `
138
+ ]; }
139
+ #onVisibilityChange;
140
+ #onBlur;
141
+ connectedCallback() {
142
+ super.connectedCallback();
143
+ document.addEventListener('visibilitychange', this.#onVisibilityChange);
144
+ window.addEventListener('blur', this.#onBlur);
145
+ }
146
+ disconnectedCallback() {
147
+ super.disconnectedCallback();
148
+ document.removeEventListener('visibilitychange', this.#onVisibilityChange);
149
+ window.removeEventListener('blur', this.#onBlur);
150
+ }
151
+ /** Unlocks the test, whatever the code: for a host that unlocks from its own screen. */
152
+ unlock() {
153
+ const current = lockState(this.computedContext);
154
+ if (!current.locked)
155
+ return;
156
+ this.#write({ locked: false, times: current.times });
157
+ }
158
+ #lock() {
159
+ // Only inside a test that is running: there is no state to keep the lock in otherwise.
160
+ if (!this.computedContext?.testParts?.length)
161
+ return;
162
+ const current = lockState(this.computedContext);
163
+ if (current.locked)
164
+ return;
165
+ this.#write({ locked: true, times: current.times + 1 });
166
+ }
167
+ #write(value) {
168
+ dispatchPublic(this, 'qc-test-update-plugin-state', { plugin: 'lock', value });
169
+ }
170
+ #submit(event) {
171
+ event.preventDefault();
172
+ const input = this.renderRoot.querySelector('input');
173
+ if (input.value === this.code) {
174
+ input.value = '';
175
+ this.wrongCode = false;
176
+ this.unlock();
177
+ }
178
+ else {
179
+ this.wrongCode = true;
180
+ input.select();
181
+ }
182
+ }
183
+ willUpdate(changed) {
184
+ if (changed.has('computedContext'))
185
+ this.locked = lockState(this.computedContext).locked;
186
+ }
187
+ updated(changed) {
188
+ if (!changed.has('locked'))
189
+ return;
190
+ const dialog = this.renderRoot.querySelector('dialog');
191
+ if (this.locked && !dialog.open) {
192
+ dialog.showModal();
193
+ this.dispatchEvent(new Event('lock', { bubbles: true, composed: true }));
194
+ }
195
+ else if (!this.locked && dialog.open) {
196
+ dialog.close();
197
+ this.wrongCode = false;
198
+ this.dispatchEvent(new Event('unlock', { bubbles: true, composed: true }));
199
+ }
200
+ }
201
+ render() {
202
+ // Escape closes a modal dialog; this one stays until it is unlocked.
203
+ return html `<dialog part="dialog" aria-labelledby="notice" @cancel=${(event) => event.preventDefault()}>
204
+ <div id="notice" part="notice">
205
+ <slot>De toets is vergrendeld. Vraag de toezichthouder om hem te openen.</slot>
206
+ </div>
207
+ ${this.code
208
+ ? html `<form part="form" @submit=${this.#submit}>
209
+ <label
210
+ >${this.codeLabel}
211
+ <input part="input" type="password" autocomplete="off" required aria-invalid=${this.wrongCode} />
212
+ </label>
213
+ <button part="button" type="submit">${this.unlockLabel}</button>
214
+ ${this.wrongCode ? html `<p part="error" role="alert">${this.wrongCodeLabel}</p>` : nothing}
215
+ </form>`
216
+ : nothing}
217
+ </dialog>`;
218
+ }
219
+ }
220
+ __decorate([
221
+ consume({ context: computedContext, subscribe: true }),
222
+ property({ attribute: false })
223
+ ], TestLock.prototype, "computedContext", void 0);
224
+ __decorate([
225
+ property()
226
+ ], TestLock.prototype, "code", void 0);
227
+ __decorate([
228
+ property({ attribute: 'code-label' })
229
+ ], TestLock.prototype, "codeLabel", void 0);
230
+ __decorate([
231
+ property({ attribute: 'unlock-label' })
232
+ ], TestLock.prototype, "unlockLabel", void 0);
233
+ __decorate([
234
+ property({ attribute: 'wrong-code-label' })
235
+ ], TestLock.prototype, "wrongCodeLabel", void 0);
236
+ __decorate([
237
+ property({ type: Boolean, reflect: true })
238
+ ], TestLock.prototype, "locked", void 0);
239
+ __decorate([
240
+ state()
241
+ ], TestLock.prototype, "wrongCode", void 0);
242
+ //# sourceMappingURL=test-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-lock.js","sourceRoot":"","sources":["../../src/test-lock/test-lock.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAatG;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAqD,EAAa,EAAE;IAC5F,MAAM,KAAK,GAAG,OAAO,EAAE,OAAO,EAAE,IAAyD,CAAC;IAC1F,OAAO;QACL,MAAM,EAAE,KAAK,EAAE,MAAM,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,CAAC,KAAK,CAAC,cAAc,EAAE;;;;QAIzG,IAAI,CAAC,IAAI;YACT,CAAC,CAAC,IAAI,CAAA,6BAA6B,IAAI,CAAC,OAAO;;iBAEtC,IAAI,CAAC,SAAS;6FAC8D,IAAI,CAAC,SAAS;;kDAEzD,IAAI,CAAC,WAAW;cACpD,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA,gCAAgC,IAAI,CAAC,cAAc,MAAM,CAAC,CAAC,CAAC,OAAO;kBACpF;YACV,CAAC,CAAC,OAAO;cACH,CAAC;IACb,CAAC;;AAtKS;IAFT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACtD,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;iDACa;AAEhC;IAAX,QAAQ,EAAE;sCAAe;AAEa;IAAtC,QAAQ,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;2CAAoB;AAEjB;IAAxC,QAAQ,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;6CAA4B;AAEvB;IAA5C,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;gDAA0C;AAE1C;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wCAAgB;AAE1C;IAAhB,KAAK,EAAE;2CAA2B","sourcesContent":["import { css, html, LitElement, nothing } from 'lit';\nimport { consume } from '@lit/context';\nimport { property, state } from 'lit/decorators.js';\nimport { computedContext } from '@citolab/qti-components/qti-base';\nimport { controlStyles as styles, dispatchPublic } from '@citolab/qti-components/qti-test/plugin-api';\n\nimport type { PropertyValues } from 'lit';\nimport type { ComputedContext } from '@citolab/qti-components/qti-base';\n\n/** The lock's entry in the test's state (`session.plugins.lock`). */\nexport interface LockState {\n /** The test is locked: the candidate left the page and nobody has unlocked it yet. */\n locked: boolean;\n /** How often the test was locked during this session. */\n times: number;\n}\n\n/**\n * The lock state of a test: whether it is locked and how often it was. For a host that shows it to a\n * proctor, or unlocks from its own screen.\n */\nexport const lockState = (context: Pick<ComputedContext, 'plugins'> | undefined): LockState => {\n const entry = context?.plugins?.lock as { locked?: unknown; times?: unknown } | undefined;\n return {\n locked: entry?.locked === true,\n times: typeof entry?.times === 'number' ? entry.times : 0\n };\n};\n\n/**\n * Locks the test when the candidate leaves the page: another tab or window, or the page hidden. A\n * modal covers the test until it is unlocked, so the candidate cannot go on answering. It is a\n * deterrent for a supervised session, not security: the page is the candidate's.\n *\n * The lock lives in the test's state under `lock` (`session.plugins.lock`, `{ locked, times }`), so a\n * host that stores `state` stores it: reloading the page does not escape it, and `times` tells a\n * proctor how often the candidate left. `lockState(computedContext)` reads it.\n *\n * Unlocking: with a `code`, the modal asks for it, and the right code unlocks. The code is in the page\n * for anyone who opens the developer tools, so it keeps a candidate from simply carrying on, nothing\n * more. Without a `code`, the modal only shows its message and the host unlocks, with `unlock()` (for\n * example after a proctor's action on another screen).\n *\n * Focus moving into an iframe (a portable custom interaction, a video) is not leaving the page.\n *\n * Put it inside `<test-navigation>`; it shows nothing until the test is locked. The modal's message\n * is the element's content.\n *\n * @slot - The message in the modal.\n * @attr code - The code that unlocks the test; without it only `unlock()` does.\n * @attr locked - Reflected: the test is locked.\n * @attr code-label - The label of the code field.\n * @attr unlock-label - The label of the unlock button.\n * @attr wrong-code-label - The message for a wrong code.\n * @fires lock - The test was locked (also when a restored state is locked).\n * @fires unlock - The test was unlocked.\n * @csspart dialog - The modal.\n * @csspart notice - The message. (Not `message`: the theme paints that part as a validation message.)\n * @csspart form - The code field and button.\n * @csspart input - The code field.\n * @csspart button - The unlock button.\n * @csspart error - The message for a wrong code.\n */\nexport class TestLock extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n @property({ attribute: false })\n protected computedContext?: ComputedContext;\n\n @property() code?: string;\n\n @property({ attribute: 'code-label' }) codeLabel = 'Code';\n\n @property({ attribute: 'unlock-label' }) unlockLabel = 'Ontgrendel';\n\n @property({ attribute: 'wrong-code-label' }) wrongCodeLabel = 'Deze code klopt niet.';\n\n @property({ type: Boolean, reflect: true }) locked = false;\n\n @state() private wrongCode = false;\n\n static override styles = [\n css`\n :host {\n display: contents;\n }\n dialog {\n box-sizing: border-box;\n max-width: min(28rem, calc(100vw - 2rem));\n padding: 1.5rem;\n border: var(--qti-border-width, var(--qc-border-width, var(--cito-border-width, 1px))) solid\n var(--qti-border-color, color-mix(in oklab, CanvasText 45%, Canvas));\n border-radius: var(--qti-radius-box, var(--qc-radius-box, var(--cito-radius-box, 0.5rem)));\n background: var(--qti-color-base-100, var(--qc-color-base-100, var(--cito-color-base-100, Canvas)));\n color: var(--qti-color-base-content, var(--qc-color-base-content, var(--cito-color-base-content, CanvasText)));\n font: inherit;\n }\n dialog::backdrop {\n background: rgb(0 0 0 / 0.4);\n backdrop-filter: blur(4px);\n }\n form {\n display: flex;\n flex-wrap: wrap;\n align-items: end;\n gap: 0.5rem;\n margin-block-start: 1rem;\n }\n label {\n display: grid;\n gap: 0.25rem;\n flex: 1 1 10rem;\n }\n input {\n ${styles.ind};\n cursor: text;\n justify-content: start;\n background: transparent;\n color: inherit;\n }\n button {\n ${styles.btn};\n }\n @media (hover: hover) and (pointer: fine) {\n button:hover {\n ${styles.btnInteractive};\n }\n }\n button:active {\n ${styles.btnActive};\n }\n input:focus-visible,\n button:focus-visible {\n ${styles.focusRing};\n }\n [part='error'] {\n flex-basis: 100%;\n margin: 0;\n }\n `\n ];\n\n #onVisibilityChange = () => {\n if (document.hidden) this.#lock();\n };\n\n #onBlur = () => {\n // Focus moving into an iframe of the test blurs the window too; that is not leaving the page.\n // The iframe is the active element only after the blur, so look once the event is through.\n setTimeout(() => {\n if (document.activeElement instanceof HTMLIFrameElement) return;\n this.#lock();\n });\n };\n\n override connectedCallback(): void {\n super.connectedCallback();\n document.addEventListener('visibilitychange', this.#onVisibilityChange);\n window.addEventListener('blur', this.#onBlur);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener('visibilitychange', this.#onVisibilityChange);\n window.removeEventListener('blur', this.#onBlur);\n }\n\n /** Unlocks the test, whatever the code: for a host that unlocks from its own screen. */\n unlock(): void {\n const current = lockState(this.computedContext);\n if (!current.locked) return;\n this.#write({ locked: false, times: current.times });\n }\n\n #lock(): void {\n // Only inside a test that is running: there is no state to keep the lock in otherwise.\n if (!this.computedContext?.testParts?.length) return;\n const current = lockState(this.computedContext);\n if (current.locked) return;\n this.#write({ locked: true, times: current.times + 1 });\n }\n\n #write(value: LockState): void {\n dispatchPublic(this, 'qc-test-update-plugin-state', { plugin: 'lock', value });\n }\n\n #submit(event: SubmitEvent): void {\n event.preventDefault();\n const input = this.renderRoot.querySelector('input')!;\n if (input.value === this.code) {\n input.value = '';\n this.wrongCode = false;\n this.unlock();\n } else {\n this.wrongCode = true;\n input.select();\n }\n }\n\n protected override willUpdate(changed: PropertyValues): void {\n if (changed.has('computedContext')) this.locked = lockState(this.computedContext).locked;\n }\n\n protected override updated(changed: PropertyValues): void {\n if (!changed.has('locked')) return;\n const dialog = this.renderRoot.querySelector('dialog')!;\n if (this.locked && !dialog.open) {\n dialog.showModal();\n this.dispatchEvent(new Event('lock', { bubbles: true, composed: true }));\n } else if (!this.locked && dialog.open) {\n dialog.close();\n this.wrongCode = false;\n this.dispatchEvent(new Event('unlock', { bubbles: true, composed: true }));\n }\n }\n\n override render() {\n // Escape closes a modal dialog; this one stays until it is unlocked.\n return html`<dialog part=\"dialog\" aria-labelledby=\"notice\" @cancel=${(event: Event) => event.preventDefault()}>\n <div id=\"notice\" part=\"notice\">\n <slot>De toets is vergrendeld. Vraag de toezichthouder om hem te openen.</slot>\n </div>\n ${this.code\n ? html`<form part=\"form\" @submit=${this.#submit}>\n <label\n >${this.codeLabel}\n <input part=\"input\" type=\"password\" autocomplete=\"off\" required aria-invalid=${this.wrongCode} />\n </label>\n <button part=\"button\" type=\"submit\">${this.unlockLabel}</button>\n ${this.wrongCode ? html`<p part=\"error\" role=\"alert\">${this.wrongCodeLabel}</p>` : nothing}\n </form>`\n : nothing}\n </dialog>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-lock': TestLock;\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { LitElement } from 'lit';
2
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
3
+ export declare class TestPrintContext extends LitElement {
4
+ computedContext?: ComputedContext;
5
+ render(): import("lit").TemplateResult<1>;
6
+ }
7
+ declare global {
8
+ interface HTMLElementTagNameMap {
9
+ 'test-print-context': TestPrintContext;
10
+ }
11
+ }
@@ -0,0 +1,20 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, LitElement } from 'lit';
8
+ import { consume } from '@lit/context';
9
+ import { state } from 'lit/decorators.js';
10
+ import { computedContext } from '@citolab/qti-components/qti-base';
11
+ export class TestPrintContext extends LitElement {
12
+ render() {
13
+ return html ` <small><pre>${JSON.stringify(this.computedContext, null, 2)}</pre></small> `;
14
+ }
15
+ }
16
+ __decorate([
17
+ state(),
18
+ consume({ context: computedContext, subscribe: true })
19
+ ], TestPrintContext.prototype, "computedContext", void 0);
20
+ //# sourceMappingURL=test-print-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-print-context.js","sourceRoot":"","sources":["../../src/test-print-context/test-print-context.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAInE,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAKrC,MAAM;QACb,OAAO,IAAI,CAAA,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,iBAAiB,CAAC;IAC5F,CAAC;CACF;AALQ;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;yDACd","sourcesContent":["import { html, LitElement } from 'lit';\nimport { consume } from '@lit/context';\nimport { state } from 'lit/decorators.js';\nimport { computedContext } from '@citolab/qti-components/qti-base';\n\nimport type { ComputedContext } from '@citolab/qti-components/qti-base';\n\nexport class TestPrintContext extends LitElement {\n @state()\n @consume({ context: computedContext, subscribe: true })\n public computedContext?: ComputedContext;\n\n override render() {\n return html` <small><pre>${JSON.stringify(this.computedContext, null, 2)}</pre></small> `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-print-context': TestPrintContext;\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { LitElement } from 'lit';
2
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
3
+ /**
4
+ * A variable value as text: a list as `a, b`, a record (e.g. the response of a PCI) as `time: 3.6, point: 455 250`.
5
+ * Without this a record printed as "[object Object]".
6
+ */
7
+ export declare const formatVariableValue: (value: unknown) => string;
8
+ export declare class TestPrintVariables extends LitElement {
9
+ computedContext?: ComputedContext;
10
+ static styles: import("lit").CSSResult;
11
+ render(): import("lit").TemplateResult<1>;
12
+ }
13
+ declare global {
14
+ interface HTMLElementTagNameMap {
15
+ 'test-print-item-variables': TestPrintVariables;
16
+ }
17
+ }
@@ -0,0 +1,95 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, css, LitElement } from 'lit';
8
+ import { consume } from '@lit/context';
9
+ import { computedContext, isRecordValue } from '@citolab/qti-components/qti-base';
10
+ /**
11
+ * A variable value as text: a list as `a, b`, a record (e.g. the response of a PCI) as `time: 3.6, point: 455 250`.
12
+ * Without this a record printed as "[object Object]".
13
+ */
14
+ export const formatVariableValue = (value) => {
15
+ if (value === null || value === undefined)
16
+ return '';
17
+ if (Array.isArray(value))
18
+ return value.map(formatVariableValue).join(', ');
19
+ if (isRecordValue(value)) {
20
+ return Object.entries(value)
21
+ .map(([field, fieldValue]) => `${field}: ${formatVariableValue(fieldValue)}`)
22
+ .join(', ');
23
+ }
24
+ return String(value);
25
+ };
26
+ export class TestPrintVariables extends LitElement {
27
+ static { this.styles = css `
28
+ table {
29
+ width: 100%;
30
+ border-collapse: collapse;
31
+ margin: 20px 0;
32
+ font-size: 14px;
33
+ text-align: left;
34
+ }
35
+ th,
36
+ td {
37
+ border: 1px solid #ddd;
38
+ padding: 8px;
39
+ }
40
+ th {
41
+ background-color: #f4f4f4;
42
+ font-weight: bold;
43
+ }
44
+ h3 {
45
+ margin-top: 20px;
46
+ font-size: 16px;
47
+ }
48
+ `; }
49
+ render() {
50
+ const activeItem = this.computedContext?.testParts
51
+ .flatMap(testPart => testPart.sections.flatMap(section => section.items))
52
+ .find(item => item.active);
53
+ if (!activeItem || !activeItem.variables)
54
+ return html ``;
55
+ const responseVariables = activeItem.variables.filter(v => v.type === 'response');
56
+ const outcomeVariables = activeItem.variables.filter(v => v.type === 'outcome');
57
+ const renderTable = (variables, title) => html `
58
+ <h3>${title}</h3>
59
+ <table>
60
+ <thead>
61
+ <tr>
62
+ <th>Identifier</th>
63
+ <th>Value</th>
64
+ <th>Cardinality</th>
65
+ <th>Base Type</th>
66
+ <th>Correct Response / Mappings</th>
67
+ </tr>
68
+ </thead>
69
+ <tbody>
70
+ ${variables.map(v => {
71
+ const correctResponse = formatVariableValue(v.correctResponse);
72
+ const mapEntries = v.mapping?.mapEntries?.map(m => `${m.mapKey}=${m.mappedValue}pt`).join(', ') || '';
73
+ const areaMapEntries = v.areaMapping?.areaMapEntries?.map(m => `${m.shape}(${m.coords})=${m.mappedValue}pt`).join(', ') || '';
74
+ return html `
75
+ <tr>
76
+ <td>${v.identifier}</td>
77
+ <td>${formatVariableValue(v.value)}</td>
78
+ <td>${v.cardinality}</td>
79
+ <td>${v.baseType}</td>
80
+ <td>${correctResponse || mapEntries || areaMapEntries}</td>
81
+ </tr>
82
+ `;
83
+ })}
84
+ </tbody>
85
+ </table>
86
+ `;
87
+ return html `
88
+ ${renderTable(responseVariables, 'Response Variables')} ${renderTable(outcomeVariables, 'Outcome Variables')}
89
+ `;
90
+ }
91
+ }
92
+ __decorate([
93
+ consume({ context: computedContext, subscribe: true })
94
+ ], TestPrintVariables.prototype, "computedContext", void 0);
95
+ //# sourceMappingURL=test-print-item-variables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-print-item-variables.js","sourceRoot":"","sources":["../../src/test-print-item-variables/test-print-item-variables.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAKlF;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAA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/context';\nimport { computedContext, isRecordValue } from '@citolab/qti-components/qti-base';\n\nimport type { ResponseVariable } from '@citolab/qti-components/qti-base';\nimport type { ComputedContext } from '@citolab/qti-components/qti-base';\n\n/**\n * A variable value as text: a list as `a, b`, a record (e.g. the response of a PCI) as `time: 3.6, point: 455 250`.\n * Without this a record printed as \"[object Object]\".\n */\nexport const formatVariableValue = (value: unknown): string => {\n if (value === null || value === undefined) return '';\n if (Array.isArray(value)) return value.map(formatVariableValue).join(', ');\n if (isRecordValue(value)) {\n return Object.entries(value)\n .map(([field, fieldValue]) => `${field}: ${formatVariableValue(fieldValue)}`)\n .join(', ');\n }\n return String(value);\n};\n\nexport class TestPrintVariables extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n public computedContext?: ComputedContext;\n\n static override styles = css`\n table {\n width: 100%;\n border-collapse: collapse;\n margin: 20px 0;\n font-size: 14px;\n text-align: left;\n }\n th,\n td {\n border: 1px solid #ddd;\n padding: 8px;\n }\n th {\n background-color: #f4f4f4;\n font-weight: bold;\n }\n h3 {\n margin-top: 20px;\n font-size: 16px;\n }\n `;\n\n override render() {\n const activeItem = this.computedContext?.testParts\n .flatMap(testPart => testPart.sections.flatMap(section => section.items))\n .find(item => item.active);\n\n if (!activeItem || !activeItem.variables) return html``;\n\n const responseVariables: ResponseVariable[] = activeItem.variables.filter(v => v.type === 'response');\n const outcomeVariables = activeItem.variables.filter(v => v.type === 'outcome');\n\n const renderTable = (variables: ResponseVariable[], title: string) => html`\n <h3>${title}</h3>\n <table>\n <thead>\n <tr>\n <th>Identifier</th>\n <th>Value</th>\n <th>Cardinality</th>\n <th>Base Type</th>\n <th>Correct Response / Mappings</th>\n </tr>\n </thead>\n <tbody>\n ${variables.map(v => {\n const correctResponse = formatVariableValue(v.correctResponse);\n\n const mapEntries = v.mapping?.mapEntries?.map(m => `${m.mapKey}=${m.mappedValue}pt`).join(', ') || '';\n\n const areaMapEntries =\n v.areaMapping?.areaMapEntries?.map(m => `${m.shape}(${m.coords})=${m.mappedValue}pt`).join(', ') || '';\n\n return html`\n <tr>\n <td>${v.identifier}</td>\n <td>${formatVariableValue(v.value)}</td>\n <td>${v.cardinality}</td>\n <td>${v.baseType}</td>\n <td>${correctResponse || mapEntries || areaMapEntries}</td>\n </tr>\n `;\n })}\n </tbody>\n </table>\n `;\n\n return html`\n ${renderTable(responseVariables, 'Response Variables')} ${renderTable(outcomeVariables, 'Outcome Variables')}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-print-item-variables': TestPrintVariables;\n }\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import { LitElement, nothing } from 'lit';
2
+ import type { TemplateResult } from 'lit';
3
+ /**
4
+ * Shows the test's state (`qtiTest.state`) as a tree you can fold open and shut. It shows the state
5
+ * each `qc-test-state-changed` of its own test carries: the test sends one once it is ready and one on
6
+ * every change, so place it in the page from the start. A debug helper: drop it anywhere inside
7
+ * `<qti-test>`.
8
+ *
9
+ * The first two levels start open. A list entry with an `identifier` (an item, a variable) is labelled
10
+ * by it. The element only lays out the tree; give it a font, colour and height from the page.
11
+ *
12
+ * @customElement test-print-state
13
+ * @csspart key - the name of a field, or the label of a list entry
14
+ * @csspart value - a value that is not an object or a list
15
+ * @csspart count - the number of entries of a folded object or list
16
+ */
17
+ export declare class TestPrintState extends LitElement {
18
+ #private;
19
+ private testState?;
20
+ static styles: import("lit").CSSResult;
21
+ connectedCallback(): void;
22
+ disconnectedCallback(): void;
23
+ render(): TemplateResult<1> | typeof nothing;
24
+ }
25
+ declare global {
26
+ interface HTMLElementTagNameMap {
27
+ 'test-print-state': TestPrintState;
28
+ }
29
+ }
@@ -0,0 +1,101 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { css, html, LitElement, nothing } from 'lit';
8
+ import { state } from 'lit/decorators.js';
9
+ /**
10
+ * Whether `node` sits inside `ancestor`, also through shadow roots: the test a notification comes
11
+ * from is this element's own test when the element is somewhere inside it.
12
+ */
13
+ const isInside = (node, ancestor) => {
14
+ for (let current = node; current;) {
15
+ if (current === ancestor)
16
+ return true;
17
+ current = current.parentNode ?? (current instanceof ShadowRoot ? current.host : null);
18
+ }
19
+ return false;
20
+ };
21
+ /**
22
+ * Shows the test's state (`qtiTest.state`) as a tree you can fold open and shut. It shows the state
23
+ * each `qc-test-state-changed` of its own test carries: the test sends one once it is ready and one on
24
+ * every change, so place it in the page from the start. A debug helper: drop it anywhere inside
25
+ * `<qti-test>`.
26
+ *
27
+ * The first two levels start open. A list entry with an `identifier` (an item, a variable) is labelled
28
+ * by it. The element only lays out the tree; give it a font, colour and height from the page.
29
+ *
30
+ * @customElement test-print-state
31
+ * @csspart key - the name of a field, or the label of a list entry
32
+ * @csspart value - a value that is not an object or a list
33
+ * @csspart count - the number of entries of a folded object or list
34
+ */
35
+ export class TestPrintState extends LitElement {
36
+ static { this.styles = css `
37
+ :host {
38
+ display: block;
39
+ }
40
+ ul {
41
+ list-style: none;
42
+ margin: 0;
43
+ padding-inline-start: 1rem;
44
+ }
45
+ summary {
46
+ cursor: pointer;
47
+ }
48
+ [part~='count'] {
49
+ opacity: 0.7;
50
+ }
51
+ `; }
52
+ /** A notification goes up from the test, so it is heard on the document; only its own test's counts. */
53
+ #onStateChanged = (event) => {
54
+ if (!isInside(this, event.composedPath()[0]))
55
+ return;
56
+ this.testState = event.detail;
57
+ };
58
+ connectedCallback() {
59
+ super.connectedCallback();
60
+ // Under the public name only: `cito-test-state-changed` carries the same state, once more.
61
+ this.ownerDocument.addEventListener('qc-test-state-changed', this.#onStateChanged);
62
+ }
63
+ disconnectedCallback() {
64
+ super.disconnectedCallback();
65
+ this.ownerDocument.removeEventListener('qc-test-state-changed', this.#onStateChanged);
66
+ }
67
+ render() {
68
+ if (!this.testState)
69
+ return nothing;
70
+ return html `<ul>
71
+ ${this.#renderNode('state', this.testState, 0)}
72
+ </ul>`;
73
+ }
74
+ #renderNode(label, value, depth) {
75
+ if (value === null || typeof value !== 'object') {
76
+ return html `<li><span part="key">${label}</span>: <span part="value">${JSON.stringify(value)}</span></li>`;
77
+ }
78
+ const entries = Array.isArray(value)
79
+ ? value.map((entry, index) => [entryLabel(entry, index), entry])
80
+ : Object.entries(value);
81
+ const count = Array.isArray(value) ? `[${entries.length}]` : `{${entries.length}}`;
82
+ // `open` is bound once per depth, so Lit leaves a node the reader folded alone on the next update.
83
+ return html `<li>
84
+ <details ?open=${depth < 2}>
85
+ <summary><span part="key">${label}</span> <span part="count">${count}</span></summary>
86
+ <ul>
87
+ ${entries.map(([key, entry]) => this.#renderNode(key, entry, depth + 1))}
88
+ </ul>
89
+ </details>
90
+ </li>`;
91
+ }
92
+ }
93
+ __decorate([
94
+ state()
95
+ ], TestPrintState.prototype, "testState", void 0);
96
+ /** An item or a variable is easier to find by its identifier than by its index. */
97
+ const entryLabel = (entry, index) => {
98
+ const identifier = entry?.identifier;
99
+ return typeof identifier === 'string' ? `${index} · ${identifier}` : String(index);
100
+ };
101
+ //# sourceMappingURL=test-print-state.js.map