@qti-components/extended 0.0.0-stage → 0.0.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,75 @@
1
+ import { LitElement } from 'lit';
2
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
3
+ /**
4
+ * The zoom level of the items, 1 is 100%: the plugin's entry in the test's state
5
+ * (`session.plugins.zoom`, absent at 100%). For a host that shows it, or scales something of its own
6
+ * with it.
7
+ */
8
+ export declare const zoomLevel: (context: Pick<ComputedContext, "plugins"> | undefined) => number;
9
+ /**
10
+ * The zoom plugin: three buttons that scale the items (`zoom-in`, `zoom-out`, `zoom-reset`), for a
11
+ * candidate who wants the text and the pictures larger. The level lives in the test's state under `zoom`
12
+ * (`session.plugins.zoom`), so a host that stores `state` stores it and a reloaded test shows the items at
13
+ * the same size. At 100% the entry is removed.
14
+ *
15
+ * The items are scaled with the CSS `zoom` property on each rendered `qti-assessment-item`, so the layout
16
+ * of the page around them does not move. A host that wants to scale something of its own reads the level
17
+ * with `zoomLevel(computedContext)`, or as `test.plugins.zoom` in a stamp template.
18
+ *
19
+ * Put the buttons inside `<test-navigation>`. Each is a button (`role="button"`) with its content as the
20
+ * label; `test-zoom-reset` shows the level (`100%`) when it has no content of its own. `step`, `min` and
21
+ * `max` on a button set how far it goes (defaults 0.1, 0.5 and 2); it is `disabled` at its end.
22
+ */
23
+ declare abstract class TestZoomControl extends LitElement {
24
+ #private;
25
+ protected computedContext?: ComputedContext;
26
+ /** How much one press changes the level. */
27
+ step: number;
28
+ /** The smallest level `zoom-out` reaches. */
29
+ min: number;
30
+ /** The largest level `zoom-in` reaches. */
31
+ max: number;
32
+ disabled: boolean;
33
+ static styles: import("lit").CSSResult[];
34
+ constructor();
35
+ connectedCallback(): void;
36
+ protected get level(): number;
37
+ /** The level this button goes to, or `undefined` when it is at its end. */
38
+ protected abstract next(): number | undefined;
39
+ protected willUpdate(): void;
40
+ protected updated(): void;
41
+ render(): import("lit").TemplateResult<1>;
42
+ }
43
+ /** @attr step - How much one press adds to the level (default 0.1). @attr max - The largest level (default 2). */
44
+ export declare class TestZoomIn extends TestZoomControl {
45
+ protected next(): number | undefined;
46
+ }
47
+ /** @attr step - How much one press takes off the level (default 0.1). @attr min - The smallest level (default 0.5). */
48
+ export declare class TestZoomOut extends TestZoomControl {
49
+ protected next(): number | undefined;
50
+ }
51
+ /** Back to 100%. Shows the level when it has no content of its own; never disabled, so the level always reads well. */
52
+ export declare class TestZoomReset extends TestZoomControl {
53
+ static styles: import("lit").CSSResult[];
54
+ protected next(): number;
55
+ render(): import("lit").TemplateResult<1>;
56
+ }
57
+ /** The zoom elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */
58
+ export declare const zoomElements: readonly [{
59
+ readonly tag: "test-zoom-in";
60
+ readonly ctor: typeof TestZoomIn;
61
+ }, {
62
+ readonly tag: "test-zoom-out";
63
+ readonly ctor: typeof TestZoomOut;
64
+ }, {
65
+ readonly tag: "test-zoom-reset";
66
+ readonly ctor: typeof TestZoomReset;
67
+ }];
68
+ declare global {
69
+ interface HTMLElementTagNameMap {
70
+ 'test-zoom-in': TestZoomIn;
71
+ 'test-zoom-out': TestZoomOut;
72
+ 'test-zoom-reset': TestZoomReset;
73
+ }
74
+ }
75
+ export {};
@@ -0,0 +1,158 @@
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 } from 'lit';
8
+ import { consume } from '@lit/context';
9
+ import { property } 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 zoom level of the items, 1 is 100%: the plugin's entry in the test's state
14
+ * (`session.plugins.zoom`, absent at 100%). For a host that shows it, or scales something of its own
15
+ * with it.
16
+ */
17
+ export const zoomLevel = (context) => {
18
+ const level = context?.plugins?.zoom;
19
+ return typeof level === 'number' ? level : 1;
20
+ };
21
+ /** Rounded to a tenth, so a step up and a step down meet again. */
22
+ const round = (level) => Math.round(level * 100) / 100;
23
+ /**
24
+ * Scales the rendered items with the CSS `zoom` property. Every item the context knows and that is on the
25
+ * page gets the level, so it holds for one item at a time and for a whole section on screen; the item that is
26
+ * rendered next gets it too, because the context updates when it has rendered.
27
+ */
28
+ const applyZoom = (context) => {
29
+ if (!context?.itemElement)
30
+ return;
31
+ const level = zoomLevel(context);
32
+ for (const part of context.testParts ?? [])
33
+ for (const section of part.sections)
34
+ for (const item of section.items) {
35
+ const element = context.itemElement(item.identifier);
36
+ if (!element)
37
+ continue;
38
+ if (level === 1)
39
+ element.style.removeProperty('zoom');
40
+ else
41
+ element.style.setProperty('zoom', String(level));
42
+ }
43
+ };
44
+ /**
45
+ * The zoom plugin: three buttons that scale the items (`zoom-in`, `zoom-out`, `zoom-reset`), for a
46
+ * candidate who wants the text and the pictures larger. The level lives in the test's state under `zoom`
47
+ * (`session.plugins.zoom`), so a host that stores `state` stores it and a reloaded test shows the items at
48
+ * the same size. At 100% the entry is removed.
49
+ *
50
+ * The items are scaled with the CSS `zoom` property on each rendered `qti-assessment-item`, so the layout
51
+ * of the page around them does not move. A host that wants to scale something of its own reads the level
52
+ * with `zoomLevel(computedContext)`, or as `test.plugins.zoom` in a stamp template.
53
+ *
54
+ * Put the buttons inside `<test-navigation>`. Each is a button (`role="button"`) with its content as the
55
+ * label; `test-zoom-reset` shows the level (`100%`) when it has no content of its own. `step`, `min` and
56
+ * `max` on a button set how far it goes (defaults 0.1, 0.5 and 2); it is `disabled` at its end.
57
+ */
58
+ class TestZoomControl extends LitElement {
59
+ static { this.styles = [styles.button]; }
60
+ constructor() {
61
+ super();
62
+ /** How much one press changes the level. */
63
+ this.step = 0.1;
64
+ /** The smallest level `zoom-out` reaches. */
65
+ this.min = 0.5;
66
+ /** The largest level `zoom-in` reaches. */
67
+ this.max = 2;
68
+ this.disabled = false;
69
+ this.addEventListener('click', () => this.#press());
70
+ this.addEventListener('keydown', event => {
71
+ if (event.key !== 'Enter' && event.key !== ' ')
72
+ return;
73
+ event.preventDefault();
74
+ this.#press();
75
+ });
76
+ }
77
+ connectedCallback() {
78
+ super.connectedCallback();
79
+ if (!this.hasAttribute('role'))
80
+ this.setAttribute('role', 'button');
81
+ if (!this.hasAttribute('tabindex'))
82
+ this.setAttribute('tabindex', '0');
83
+ }
84
+ get level() {
85
+ return zoomLevel(this.computedContext);
86
+ }
87
+ willUpdate() {
88
+ this.disabled = this.next() === undefined;
89
+ }
90
+ updated() {
91
+ this.setAttribute('aria-disabled', String(this.disabled));
92
+ applyZoom(this.computedContext);
93
+ }
94
+ #press() {
95
+ const level = this.next();
96
+ if (level === undefined)
97
+ return;
98
+ // 100% is the default, so the state keeps no entry for it.
99
+ dispatchPublic(this, 'qc-test-update-plugin-state', { plugin: 'zoom', value: level === 1 ? null : level });
100
+ }
101
+ render() {
102
+ return styles.control;
103
+ }
104
+ }
105
+ __decorate([
106
+ consume({ context: computedContext, subscribe: true }),
107
+ property({ attribute: false })
108
+ ], TestZoomControl.prototype, "computedContext", void 0);
109
+ __decorate([
110
+ property({ type: Number })
111
+ ], TestZoomControl.prototype, "step", void 0);
112
+ __decorate([
113
+ property({ type: Number })
114
+ ], TestZoomControl.prototype, "min", void 0);
115
+ __decorate([
116
+ property({ type: Number })
117
+ ], TestZoomControl.prototype, "max", void 0);
118
+ __decorate([
119
+ property({ type: Boolean, reflect: true })
120
+ ], TestZoomControl.prototype, "disabled", void 0);
121
+ /** @attr step - How much one press adds to the level (default 0.1). @attr max - The largest level (default 2). */
122
+ export class TestZoomIn extends TestZoomControl {
123
+ next() {
124
+ const level = round(this.level + this.step);
125
+ return this.level < this.max ? Math.min(level, this.max) : undefined;
126
+ }
127
+ }
128
+ /** @attr step - How much one press takes off the level (default 0.1). @attr min - The smallest level (default 0.5). */
129
+ export class TestZoomOut extends TestZoomControl {
130
+ next() {
131
+ const level = round(this.level - this.step);
132
+ return this.level > this.min ? Math.max(level, this.min) : undefined;
133
+ }
134
+ }
135
+ /** Back to 100%. Shows the level when it has no content of its own; never disabled, so the level always reads well. */
136
+ export class TestZoomReset extends TestZoomControl {
137
+ static { this.styles = [
138
+ styles.button,
139
+ css `
140
+ .control {
141
+ font-variant-numeric: tabular-nums;
142
+ }
143
+ `
144
+ ]; }
145
+ next() {
146
+ return 1;
147
+ }
148
+ render() {
149
+ return html `<span class="control" part="button"><slot>${Math.round(this.level * 100)}%</slot></span>`;
150
+ }
151
+ }
152
+ /** The zoom elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */
153
+ export const zoomElements = [
154
+ { tag: 'test-zoom-in', ctor: TestZoomIn },
155
+ { tag: 'test-zoom-out', ctor: TestZoomOut },
156
+ { tag: 'test-zoom-reset', ctor: TestZoomReset }
157
+ ];
158
+ //# sourceMappingURL=test-zoom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-zoom.js","sourceRoot":"","sources":["../../src/test-zoom/test-zoom.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAItG;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAqD,EAAU,EAAE;IACzF,MAAM,KAAK,GAAG,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAE/D;;;;GAIG;AACH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I,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,iBAAiB,CAAC;IACxG,CAAC;;AAGH,qGAAqG;AACrG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE;IACzC,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE;CACvC,CAAC","sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { consume } from '@lit/context';\nimport { property } 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 { ComputedContext } from '@citolab/qti-components/qti-base';\n\n/**\n * The zoom level of the items, 1 is 100%: the plugin's entry in the test's state\n * (`session.plugins.zoom`, absent at 100%). For a host that shows it, or scales something of its own\n * with it.\n */\nexport const zoomLevel = (context: Pick<ComputedContext, 'plugins'> | undefined): number => {\n const level = context?.plugins?.zoom;\n return typeof level === 'number' ? level : 1;\n};\n\n/** Rounded to a tenth, so a step up and a step down meet again. */\nconst round = (level: number) => Math.round(level * 100) / 100;\n\n/**\n * Scales the rendered items with the CSS `zoom` property. Every item the context knows and that is on the\n * page gets the level, so it holds for one item at a time and for a whole section on screen; the item that is\n * rendered next gets it too, because the context updates when it has rendered.\n */\nconst applyZoom = (context: ComputedContext | undefined) => {\n if (!context?.itemElement) return;\n const level = zoomLevel(context);\n for (const part of context.testParts ?? [])\n for (const section of part.sections)\n for (const item of section.items) {\n const element = context.itemElement(item.identifier);\n if (!element) continue;\n if (level === 1) element.style.removeProperty('zoom');\n else element.style.setProperty('zoom', String(level));\n }\n};\n\n/**\n * The zoom plugin: three buttons that scale the items (`zoom-in`, `zoom-out`, `zoom-reset`), for a\n * candidate who wants the text and the pictures larger. The level lives in the test's state under `zoom`\n * (`session.plugins.zoom`), so a host that stores `state` stores it and a reloaded test shows the items at\n * the same size. At 100% the entry is removed.\n *\n * The items are scaled with the CSS `zoom` property on each rendered `qti-assessment-item`, so the layout\n * of the page around them does not move. A host that wants to scale something of its own reads the level\n * with `zoomLevel(computedContext)`, or as `test.plugins.zoom` in a stamp template.\n *\n * Put the buttons inside `<test-navigation>`. Each is a button (`role=\"button\"`) with its content as the\n * label; `test-zoom-reset` shows the level (`100%`) when it has no content of its own. `step`, `min` and\n * `max` on a button set how far it goes (defaults 0.1, 0.5 and 2); it is `disabled` at its end.\n */\nabstract class TestZoomControl extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n @property({ attribute: false })\n protected computedContext?: ComputedContext;\n\n /** How much one press changes the level. */\n @property({ type: Number }) step = 0.1;\n\n /** The smallest level `zoom-out` reaches. */\n @property({ type: Number }) min = 0.5;\n\n /** The largest level `zoom-in` reaches. */\n @property({ type: Number }) max = 2;\n\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n static override styles = [styles.button];\n\n constructor() {\n super();\n this.addEventListener('click', () => this.#press());\n this.addEventListener('keydown', event => {\n if (event.key !== 'Enter' && event.key !== ' ') return;\n event.preventDefault();\n this.#press();\n });\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (!this.hasAttribute('role')) this.setAttribute('role', 'button');\n if (!this.hasAttribute('tabindex')) this.setAttribute('tabindex', '0');\n }\n\n protected get level(): number {\n return zoomLevel(this.computedContext);\n }\n\n /** The level this button goes to, or `undefined` when it is at its end. */\n protected abstract next(): number | undefined;\n\n protected override willUpdate(): void {\n this.disabled = this.next() === undefined;\n }\n\n protected override updated(): void {\n this.setAttribute('aria-disabled', String(this.disabled));\n applyZoom(this.computedContext);\n }\n\n #press(): void {\n const level = this.next();\n if (level === undefined) return;\n // 100% is the default, so the state keeps no entry for it.\n dispatchPublic(this, 'qc-test-update-plugin-state', { plugin: 'zoom', value: level === 1 ? null : level });\n }\n\n override render() {\n return styles.control;\n }\n}\n\n/** @attr step - How much one press adds to the level (default 0.1). @attr max - The largest level (default 2). */\nexport class TestZoomIn extends TestZoomControl {\n protected next(): number | undefined {\n const level = round(this.level + this.step);\n return this.level < this.max ? Math.min(level, this.max) : undefined;\n }\n}\n\n/** @attr step - How much one press takes off the level (default 0.1). @attr min - The smallest level (default 0.5). */\nexport class TestZoomOut extends TestZoomControl {\n protected next(): number | undefined {\n const level = round(this.level - this.step);\n return this.level > this.min ? Math.max(level, this.min) : undefined;\n }\n}\n\n/** Back to 100%. Shows the level when it has no content of its own; never disabled, so the level always reads well. */\nexport class TestZoomReset extends TestZoomControl {\n static override styles = [\n styles.button,\n css`\n .control {\n font-variant-numeric: tabular-nums;\n }\n `\n ];\n\n protected next(): number {\n return 1;\n }\n\n override render() {\n return html`<span class=\"control\" part=\"button\"><slot>${Math.round(this.level * 100)}%</slot></span>`;\n }\n}\n\n/** The zoom elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */\nexport const zoomElements = [\n { tag: 'test-zoom-in', ctor: TestZoomIn },\n { tag: 'test-zoom-out', ctor: TestZoomOut },\n { tag: 'test-zoom-reset', ctor: TestZoomReset }\n] as const;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-zoom-in': TestZoomIn;\n 'test-zoom-out': TestZoomOut;\n 'test-zoom-reset': TestZoomReset;\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop } from './test-item-to-speech.js';
2
+ export { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop };
3
+ /** The text-to-speech elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */
4
+ export declare const ttsElements: readonly [{
5
+ readonly tag: "test-item-to-speech";
6
+ readonly ctor: typeof TestItemToSpeech;
7
+ }, {
8
+ readonly tag: "test-tts-next";
9
+ readonly ctor: typeof TestTtsNext;
10
+ }, {
11
+ readonly tag: "test-tts-pause";
12
+ readonly ctor: typeof TestTtsPause;
13
+ }, {
14
+ readonly tag: "test-tts-pick";
15
+ readonly ctor: typeof TestTtsPick;
16
+ }, {
17
+ readonly tag: "test-tts-play";
18
+ readonly ctor: typeof TestTtsPlay;
19
+ }, {
20
+ readonly tag: "test-tts-prev";
21
+ readonly ctor: typeof TestTtsPrev;
22
+ }, {
23
+ readonly tag: "test-tts-resume";
24
+ readonly ctor: typeof TestTtsResume;
25
+ }, {
26
+ readonly tag: "test-tts-stop";
27
+ readonly ctor: typeof TestTtsStop;
28
+ }];
@@ -0,0 +1,14 @@
1
+ import { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop } from './test-item-to-speech.js';
2
+ export { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop };
3
+ /** The text-to-speech elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */
4
+ export const ttsElements = [
5
+ { tag: 'test-item-to-speech', ctor: TestItemToSpeech },
6
+ { tag: 'test-tts-next', ctor: TestTtsNext },
7
+ { tag: 'test-tts-pause', ctor: TestTtsPause },
8
+ { tag: 'test-tts-pick', ctor: TestTtsPick },
9
+ { tag: 'test-tts-play', ctor: TestTtsPlay },
10
+ { tag: 'test-tts-prev', ctor: TestTtsPrev },
11
+ { tag: 'test-tts-resume', ctor: TestTtsResume },
12
+ { tag: 'test-tts-stop', ctor: TestTtsStop }
13
+ ];
14
+ //# sourceMappingURL=elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.js","sourceRoot":"","sources":["../../src/tts/elements.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACZ,CAAC;AAEF,+GAA+G;AAC/G,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,EAAE,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,gBAAgB,EAAE;IACtD,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,YAAY,EAAE;IAC7C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;CACnC,CAAC","sourcesContent":["import {\n TestItemToSpeech,\n TestTtsNext,\n TestTtsPause,\n TestTtsPick,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop\n} from './test-item-to-speech.js';\n\nexport {\n TestItemToSpeech,\n TestTtsNext,\n TestTtsPause,\n TestTtsPick,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop\n};\n\n/** The text-to-speech elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */\nexport const ttsElements = [\n { tag: 'test-item-to-speech', ctor: TestItemToSpeech },\n { tag: 'test-tts-next', ctor: TestTtsNext },\n { tag: 'test-tts-pause', ctor: TestTtsPause },\n { tag: 'test-tts-pick', ctor: TestTtsPick },\n { tag: 'test-tts-play', ctor: TestTtsPlay },\n { tag: 'test-tts-prev', ctor: TestTtsPrev },\n { tag: 'test-tts-resume', ctor: TestTtsResume },\n { tag: 'test-tts-stop', ctor: TestTtsStop }\n] as const;\n"]}
@@ -0,0 +1,260 @@
1
+ import { LitElement } from 'lit';
2
+ import type { PropertyValues } from 'lit';
3
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
4
+ type SpeechState = 'idle' | 'playing' | 'paused';
5
+ export interface TtsContext {
6
+ state: SpeechState;
7
+ /** True while every reading element is highlighted and a click on one starts reading there. */
8
+ picking: boolean;
9
+ /** Index of the currently highlighted reading element (0-based). */
10
+ currentElementIndex: number;
11
+ /** Total number of navigable reading elements in the current item. */
12
+ elementCount: number;
13
+ play(): void;
14
+ pause(): void;
15
+ resume(): void;
16
+ stop(): void;
17
+ prevElement(): void;
18
+ nextElement(): void;
19
+ /** Toggle pick mode: highlight all reading elements, then read from the one that is clicked. */
20
+ togglePick(): void;
21
+ }
22
+ export { SpeechState };
23
+ export declare const ttsContext: {
24
+ __context__: TtsContext;
25
+ };
26
+ /**
27
+ * Base class shared by all TTS control elements. Consumes `ttsContext` and
28
+ * mirrors the current speech state onto CSS custom states so each child can
29
+ * be styled with `:state(playing)`, `:state(paused)`, `:state(idle)`.
30
+ */
31
+ declare abstract class TtsButtonBase extends LitElement {
32
+ #private;
33
+ static styles: import("lit").CSSResult;
34
+ /**
35
+ * Accessible name of the button. Without it the default icon carries an English name, and
36
+ * slotted content names the button by its text; set it when you slot an icon of your own,
37
+ * which has no text to be named by.
38
+ */
39
+ label?: string;
40
+ protected _tts?: TtsContext;
41
+ /** Whether this control is a toggle that is on; mirrored as `:state(selected)`. A plain button never is. */
42
+ protected get selected(): boolean;
43
+ updated(_changed: PropertyValues): void;
44
+ }
45
+ /**
46
+ * `<test-item-to-speech>` is the controller and context provider. It manages
47
+ * speech synthesis, word highlighting, and item element lookup. Compose your
48
+ * own player by placing control elements as children.
49
+ *
50
+ * @example
51
+ * ```html
52
+ * <test-item-to-speech language="nl-NL">
53
+ * <test-tts-play></test-tts-play>
54
+ * <test-tts-prev></test-tts-prev>
55
+ * <test-tts-next></test-tts-next>
56
+ * <test-tts-stop></test-tts-stop>
57
+ * </test-item-to-speech>
58
+ * ```
59
+ *
60
+ * The controller lays its controls out as a wrapping row; each control draws an icon button,
61
+ * and slotted content replaces the icon — a slotted `<svg>` is sized like the default one. Give a
62
+ * control with a slotted icon a `label`, since an icon has no text to name the button by. Buttons read the qti-theme tokens (with the theme's
63
+ * defaults as fallbacks), are painted through the `--button-*` slots every button in the theme shares
64
+ * (`--test-button-*` still works as an alias), and can be sized with `--button-size` and
65
+ * `--test-tts-icon-size`.
66
+ *
67
+ * ### Language resolution
68
+ *
69
+ * Each reading element is spoken in the language of the nearest `lang` attribute:
70
+ *
71
+ * 1. `lang` (or `xml:lang`) on the element itself
72
+ * 2. `lang` on the closest ancestor — including `<qti-assessment-item xml:lang>` and, across
73
+ * shadow roots, anything wrapping the test
74
+ * 3. `lang` on the document's `<html>` element
75
+ * 4. the `language` attribute on `<test-item-to-speech>`
76
+ *
77
+ * The transformer copies `xml:lang` over as a plain `lang` attribute, so QTI authored with
78
+ * `xml:lang="en-GB"` on a `<p>` or on the item root is honoured without further work.
79
+ *
80
+ * ### What is read
81
+ *
82
+ * Decided once per connect, by where the player is placed. The first rule that matches wins:
83
+ *
84
+ * 1. **Next to a stimulus placeholder** — the player shares its parent with a
85
+ * `[data-stimulus-idref]` element, e.g. in a reading-text panel beside the questions: the
86
+ * player reads that stimulus (its `qti-stimulus-body`), and only that. Not inside the
87
+ * placeholder: loading a stimulus replaces the placeholder's content. Items and navigation
88
+ * are ignored; when the stimulus is (re)loaded or the placeholder swapped, the player starts
89
+ * over on the new content.
90
+ * 2. **Next to `[data-tts-content]`** — the player shares its parent with an element marked
91
+ * `data-tts-content`: any HTML, not QTI, e.g. a start screen rendered by React. The marker goes
92
+ * on one container; the player reads the readable elements inside it. Navigation is ignored.
93
+ * The reading list is rebuilt when the player starts from the top, and when an element in it
94
+ * has left the page — so a re-render of the content never interrupts speech.
95
+ * 3. **Inside a `qti-assessment-item-ref`** — e.g. in a `<template item-ref>` on `<qti-test>`,
96
+ * so every item gets a player of its own: the player reads that item, and only that item.
97
+ * The navigation cursor is ignored; speech stops when the player leaves the page with its item.
98
+ * 4. **Anywhere else inside `<test-navigation>`** — e.g. a toolbar: the player follows the
99
+ * navigation cursor and reads the active item of the computed context. Navigating stops
100
+ * speech and starts the next item from the top.
101
+ *
102
+ * ```html
103
+ * <!-- 1. a player for the shared reading text -->
104
+ * <aside>
105
+ * <test-item-to-speech>…</test-item-to-speech>
106
+ * <div data-stimulus-idref="Stimulus1"></div>
107
+ * </aside>
108
+ *
109
+ * <!-- 2. a player for any other HTML -->
110
+ * <div>
111
+ * <test-item-to-speech>…</test-item-to-speech>
112
+ * <section data-tts-content lang="nl-NL">…</section>
113
+ * </div>
114
+ *
115
+ * <!-- 3. one player per item -->
116
+ * <qti-test>
117
+ * <template item-ref>
118
+ * <test-item-to-speech>…</test-item-to-speech>
119
+ * {{ xmlDoc }}
120
+ * </template>
121
+ * …
122
+ * </qti-test>
123
+ *
124
+ * <!-- 4. one player in the toolbar, following navigation -->
125
+ * <test-navigation>
126
+ * <header><test-item-to-speech>…</test-item-to-speech></header>
127
+ * <test-container test-url="…"></test-container>
128
+ * </test-navigation>
129
+ * ```
130
+ *
131
+ * In modes 3 and 4 the item re-rendering (navigating to the item already shown) restarts the
132
+ * player on the fresh content. An item player reads the item body as rendered: a stimulus
133
+ * placed inside the item is read with it, one placed outside (mode 1) is not. Only one player
134
+ * can speak at a time; starting one stops any other.
135
+ *
136
+ * Read are `p`, `h1`–`h6`, `li`, `dt`, `dd`, `th`, `td`, `caption`, `blockquote`, `figcaption`,
137
+ * `qti-prompt` and `qti-simple-choice` — the innermost match only — unless hidden (`display: none`)
138
+ * or inside `aria-hidden="true"`.
139
+ *
140
+ * ### Starting somewhere in the middle
141
+ *
142
+ * `<test-tts-pick>` switches the player into pick mode: every reading element gets the blue
143
+ * cursor highlight, and the first click on one of them leaves pick mode and starts reading
144
+ * from that element. Pressing the button again leaves pick mode without reading.
145
+ *
146
+ * @cssstate idle - No speech active
147
+ * @cssstate picking - Pick mode: all reading elements highlighted, waiting for a click
148
+ * @cssstate playing - Speech is playing
149
+ * @cssstate paused - Speech is paused
150
+ */
151
+ export declare class TestItemToSpeech extends LitElement {
152
+ #private;
153
+ static styles: import("lit").CSSResult;
154
+ /** Fallback language when neither the item content nor the document declares one. */
155
+ language: string;
156
+ /**
157
+ * The test as `test-navigation` computes it: which item is active, and where it is rendered
158
+ * (`itemElement`). Updated on navigation and whenever an item is rendered.
159
+ */
160
+ protected _computedContext?: ComputedContext;
161
+ _ttsContext: TtsContext;
162
+ constructor();
163
+ willUpdate(changed: PropertyValues): void;
164
+ connectedCallback(): void;
165
+ disconnectedCallback(): void;
166
+ render(): import("lit").TemplateResult<1>;
167
+ }
168
+ /**
169
+ * Play/pause/resume toggle button — always enabled, cycles through states.
170
+ * Use named slots `play` and `pause` to customise the icons/labels independently; `label` and
171
+ * `pause-label` name the button in each state (set them when the slotted content is an icon).
172
+ *
173
+ * @example
174
+ * ```html
175
+ * <test-tts-play>
176
+ * <span slot="play">Voorlezen</span>
177
+ * <span slot="pause">Pauzeren</span>
178
+ * </test-tts-play>
179
+ * ```
180
+ *
181
+ * @cssstate idle / playing / paused
182
+ * @csspart button
183
+ */
184
+ export declare class TestTtsPlay extends TtsButtonBase {
185
+ #private;
186
+ /** Accessible name of the button while speech is playing; see `label`. */
187
+ pauseLabel?: string;
188
+ render(): import("lit").TemplateResult<1>;
189
+ }
190
+ /**
191
+ * Pause button — enabled only when playing.
192
+ * @cssstate idle / playing / paused
193
+ * @csspart button
194
+ */
195
+ export declare class TestTtsPause extends TtsButtonBase {
196
+ render(): import("lit").TemplateResult<1>;
197
+ }
198
+ /**
199
+ * Resume button — enabled only when paused.
200
+ * @cssstate idle / playing / paused
201
+ * @csspart button
202
+ */
203
+ export declare class TestTtsResume extends TtsButtonBase {
204
+ render(): import("lit").TemplateResult<1>;
205
+ }
206
+ /**
207
+ * Stop button — enabled when playing, paused, or in pick mode (where it leaves pick mode).
208
+ * @cssstate idle / playing / paused
209
+ * @csspart button
210
+ */
211
+ export declare class TestTtsStop extends TtsButtonBase {
212
+ render(): import("lit").TemplateResult<1>;
213
+ }
214
+ /**
215
+ * Prev-element button — moves cursor to the previous reading element and pauses.
216
+ * Disabled at the first element. Reading elements are collected lazily, so an element count
217
+ * of 0 means "not looked yet" rather than "nothing to read": the button stays enabled and the
218
+ * first click collects them.
219
+ * @cssstate idle / playing / paused
220
+ * @csspart button
221
+ */
222
+ export declare class TestTtsPrev extends TtsButtonBase {
223
+ render(): import("lit").TemplateResult<1>;
224
+ }
225
+ /**
226
+ * Next-element button — moves cursor to the next reading element and pauses.
227
+ * Disabled at the last element; enabled while the elements have not been collected yet
228
+ * (see `TestTtsPrev`).
229
+ * @cssstate idle / playing / paused
230
+ * @csspart button
231
+ */
232
+ export declare class TestTtsNext extends TtsButtonBase {
233
+ render(): import("lit").TemplateResult<1>;
234
+ }
235
+ /**
236
+ * Pick button — toggles pick mode on the controller: every reading element is highlighted and
237
+ * a click on one of them starts reading from there. Reflects the mode as `:state(picking)`, and,
238
+ * being the toggle that switched it on, as `:state(selected)`, painted through
239
+ * `--button-selected-background-color` / `--button-selected-color`.
240
+ * @cssstate idle / playing / paused
241
+ * @cssstate picking
242
+ * @cssstate selected - This toggle is on: pick mode is active
243
+ * @csspart button
244
+ */
245
+ export declare class TestTtsPick extends TtsButtonBase {
246
+ protected get selected(): boolean;
247
+ render(): import("lit").TemplateResult<1>;
248
+ }
249
+ declare global {
250
+ interface HTMLElementTagNameMap {
251
+ 'test-item-to-speech': TestItemToSpeech;
252
+ 'test-tts-play': TestTtsPlay;
253
+ 'test-tts-pause': TestTtsPause;
254
+ 'test-tts-resume': TestTtsResume;
255
+ 'test-tts-stop': TestTtsStop;
256
+ 'test-tts-prev': TestTtsPrev;
257
+ 'test-tts-next': TestTtsNext;
258
+ 'test-tts-pick': TestTtsPick;
259
+ }
260
+ }