@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 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { qtiExtendedElements } from './elements.js';
2
+ for (const { tag, ctor } of qtiExtendedElements) {
3
+ if (!customElements.get(tag)) {
4
+ customElements.define(tag, ctor);
5
+ }
6
+ }
7
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,mBAAmB,EAAE,CAAC;IAChD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;AACH,CAAC","sourcesContent":["import { qtiExtendedElements } from './elements.js';\n\nfor (const { tag, ctor } of qtiExtendedElements) {\n if (!customElements.get(tag)) {\n customElements.define(tag, ctor);\n }\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import { LitElement } from 'lit';
2
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
3
+ /**
4
+ * The item-ref identifiers bookmarked so far, in the order they were marked: the plugin's entry in the
5
+ * test's state (`session.plugins.bookmarks`). For a host's own navigation: mark these.
6
+ */
7
+ export declare const bookmarkedItems: (context: Pick<ComputedContext, "plugins"> | undefined) => string[];
8
+ /**
9
+ * A toggle that marks the item on screen to come back to. The marks live in the test's state under
10
+ * `bookmarks` (`session.plugins.bookmarks`), so a host that stores `state` stores them, and a
11
+ * reloaded test shows them again.
12
+ *
13
+ * Put it inside `<test-navigation>`, either in the toolbar, where it marks the item on screen, or in
14
+ * the `<template item-ref>`, where each item gets its own and it marks that item. It is a button
15
+ * (`role="button"`, `aria-pressed`) and reflects `bookmarked` on the host for styling; its content is
16
+ * the label. In the toolbar it is `disabled` while no item is on screen. A host's own navigation reads
17
+ * the marks with `bookmarkedItems(computedContext)`.
18
+ *
19
+ * Give it an `item` (an item-ref identifier) to mark that item instead, wherever the button sits: in a
20
+ * stamp template that lists the items of a section, `<test-bookmark item="{{ item.identifier }}">`
21
+ * puts a button next to each one.
22
+ *
23
+ * @slot - The label.
24
+ * @attr item - The item-ref identifier this button marks; without it, the item it is stamped into, or else the one on screen.
25
+ * @attr bookmarked - Reflected: the item on screen is bookmarked.
26
+ * @attr disabled - Reflected: there is no item on screen.
27
+ */
28
+ export declare class TestBookmark extends LitElement {
29
+ #private;
30
+ protected computedContext?: ComputedContext;
31
+ item?: string;
32
+ bookmarked: boolean;
33
+ disabled: boolean;
34
+ static styles: import("lit").CSSResult[];
35
+ constructor();
36
+ connectedCallback(): void;
37
+ protected willUpdate(): void;
38
+ protected updated(): void;
39
+ render(): import("lit").TemplateResult<1>;
40
+ }
41
+ declare global {
42
+ interface HTMLElementTagNameMap {
43
+ 'test-bookmark': TestBookmark;
44
+ }
45
+ }
@@ -0,0 +1,136 @@
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 item-ref identifiers bookmarked so far, in the order they were marked: the plugin's entry in the
14
+ * test's state (`session.plugins.bookmarks`). For a host's own navigation: mark these.
15
+ */
16
+ export const bookmarkedItems = (context) => {
17
+ const marks = context?.plugins?.bookmarks;
18
+ return Array.isArray(marks) ? marks.filter((mark) => typeof mark === 'string') : [];
19
+ };
20
+ /** The identifier of the item-ref an element is stamped into (`<template item-ref>`), looking out through shadow roots. */
21
+ const itemRefOf = (element) => {
22
+ const itemRef = element.closest('qti-assessment-item-ref');
23
+ if (itemRef)
24
+ return itemRef.getAttribute('identifier') ?? undefined;
25
+ const root = element.getRootNode();
26
+ return root instanceof ShadowRoot ? itemRefOf(root.host) : undefined;
27
+ };
28
+ /**
29
+ * A toggle that marks the item on screen to come back to. The marks live in the test's state under
30
+ * `bookmarks` (`session.plugins.bookmarks`), so a host that stores `state` stores them, and a
31
+ * reloaded test shows them again.
32
+ *
33
+ * Put it inside `<test-navigation>`, either in the toolbar, where it marks the item on screen, or in
34
+ * the `<template item-ref>`, where each item gets its own and it marks that item. It is a button
35
+ * (`role="button"`, `aria-pressed`) and reflects `bookmarked` on the host for styling; its content is
36
+ * the label. In the toolbar it is `disabled` while no item is on screen. A host's own navigation reads
37
+ * the marks with `bookmarkedItems(computedContext)`.
38
+ *
39
+ * Give it an `item` (an item-ref identifier) to mark that item instead, wherever the button sits: in a
40
+ * stamp template that lists the items of a section, `<test-bookmark item="{{ item.identifier }}">`
41
+ * puts a button next to each one.
42
+ *
43
+ * @slot - The label.
44
+ * @attr item - The item-ref identifier this button marks; without it, the item it is stamped into, or else the one on screen.
45
+ * @attr bookmarked - Reflected: the item on screen is bookmarked.
46
+ * @attr disabled - Reflected: there is no item on screen.
47
+ */
48
+ export class TestBookmark extends LitElement {
49
+ static { this.styles = [
50
+ styles.button,
51
+ css `
52
+ svg {
53
+ width: 1.1em;
54
+ height: 1.1em;
55
+ flex: none;
56
+ fill: none;
57
+ stroke: currentColor;
58
+ stroke-width: 2;
59
+ stroke-linejoin: round;
60
+ }
61
+ :host([bookmarked]) {
62
+ color: var(--qti-bookmark-color, #b45309);
63
+ }
64
+ :host([bookmarked]) svg {
65
+ fill: currentColor;
66
+ }
67
+ `
68
+ ]; }
69
+ constructor() {
70
+ super();
71
+ this.bookmarked = false;
72
+ this.disabled = false;
73
+ this.addEventListener('click', () => this.#toggle());
74
+ this.addEventListener('keydown', event => {
75
+ if (event.key !== 'Enter' && event.key !== ' ')
76
+ return;
77
+ event.preventDefault();
78
+ this.#toggle();
79
+ });
80
+ }
81
+ connectedCallback() {
82
+ super.connectedCallback();
83
+ if (!this.hasAttribute('role'))
84
+ this.setAttribute('role', 'button');
85
+ if (!this.hasAttribute('tabindex'))
86
+ this.setAttribute('tabindex', '0');
87
+ }
88
+ /** The item this button marks: its own, or else the one on screen. */
89
+ get #activeItem() {
90
+ return (this.item ||
91
+ (itemRefOf(this) ??
92
+ this.computedContext?.testParts
93
+ ?.flatMap(part => part.sections.flatMap(section => section.items))
94
+ .find(item => item.active)?.identifier));
95
+ }
96
+ willUpdate() {
97
+ const active = this.#activeItem;
98
+ this.disabled = !active;
99
+ this.bookmarked = !!active && bookmarkedItems(this.computedContext).includes(active);
100
+ }
101
+ updated() {
102
+ this.setAttribute('aria-pressed', String(this.bookmarked));
103
+ this.setAttribute('aria-disabled', String(this.disabled));
104
+ }
105
+ #toggle() {
106
+ const active = this.#activeItem;
107
+ if (!active)
108
+ return;
109
+ const marked = bookmarkedItems(this.computedContext);
110
+ const next = marked.includes(active) ? marked.filter(id => id !== active) : [...marked, active];
111
+ // An empty list removes the entry, so a test nobody bookmarked keeps no trace in the state.
112
+ dispatchPublic(this, 'qc-test-update-plugin-state', {
113
+ plugin: 'bookmarks',
114
+ value: next.length > 0 ? next : null
115
+ });
116
+ }
117
+ render() {
118
+ return html `<span class="control" part="button"
119
+ ><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3h12v18l-6-4.5L6 21z" /></svg><slot></slot
120
+ ></span>`;
121
+ }
122
+ }
123
+ __decorate([
124
+ consume({ context: computedContext, subscribe: true }),
125
+ property({ attribute: false })
126
+ ], TestBookmark.prototype, "computedContext", void 0);
127
+ __decorate([
128
+ property({ reflect: true })
129
+ ], TestBookmark.prototype, "item", void 0);
130
+ __decorate([
131
+ property({ type: Boolean, reflect: true })
132
+ ], TestBookmark.prototype, "bookmarked", void 0);
133
+ __decorate([
134
+ property({ type: Boolean, reflect: true })
135
+ ], TestBookmark.prototype, "disabled", void 0);
136
+ //# sourceMappingURL=test-bookmark.js.map
@@ -0,0 +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,CAAC;qDACa;AAEf;IAA5B,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CAAe;AAEC;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDAAoB;AAEnB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8CAAkB","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 item-ref identifiers bookmarked so far, in the order they were marked: the plugin's entry in the\n * test's state (`session.plugins.bookmarks`). For a host's own navigation: mark these.\n */\nexport const bookmarkedItems = (context: Pick<ComputedContext, 'plugins'> | undefined): string[] => {\n const marks = context?.plugins?.bookmarks;\n return Array.isArray(marks) ? marks.filter((mark): mark is string => typeof mark === 'string') : [];\n};\n\n/** The identifier of the item-ref an element is stamped into (`<template item-ref>`), looking out through shadow roots. */\nconst itemRefOf = (element: Element): string | undefined => {\n const itemRef = element.closest('qti-assessment-item-ref');\n if (itemRef) return itemRef.getAttribute('identifier') ?? undefined;\n const root = element.getRootNode();\n return root instanceof ShadowRoot ? itemRefOf(root.host) : undefined;\n};\n\n/**\n * A toggle that marks the item on screen to come back to. The marks live in the test's state under\n * `bookmarks` (`session.plugins.bookmarks`), so a host that stores `state` stores them, and a\n * reloaded test shows them again.\n *\n * Put it inside `<test-navigation>`, either in the toolbar, where it marks the item on screen, or in\n * the `<template item-ref>`, where each item gets its own and it marks that item. It is a button\n * (`role=\"button\"`, `aria-pressed`) and reflects `bookmarked` on the host for styling; its content is\n * the label. In the toolbar it is `disabled` while no item is on screen. A host's own navigation reads\n * the marks with `bookmarkedItems(computedContext)`.\n *\n * Give it an `item` (an item-ref identifier) to mark that item instead, wherever the button sits: in a\n * stamp template that lists the items of a section, `<test-bookmark item=\"{{ item.identifier }}\">`\n * puts a button next to each one.\n *\n * @slot - The label.\n * @attr item - The item-ref identifier this button marks; without it, the item it is stamped into, or else the one on screen.\n * @attr bookmarked - Reflected: the item on screen is bookmarked.\n * @attr disabled - Reflected: there is no item on screen.\n */\nexport class TestBookmark extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n @property({ attribute: false })\n protected computedContext?: ComputedContext;\n\n @property({ reflect: true }) item?: string;\n\n @property({ type: Boolean, reflect: true }) bookmarked = false;\n\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n static override styles = [\n styles.button,\n css`\n svg {\n width: 1.1em;\n height: 1.1em;\n flex: none;\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n stroke-linejoin: round;\n }\n :host([bookmarked]) {\n color: var(--qti-bookmark-color, #b45309);\n }\n :host([bookmarked]) svg {\n fill: currentColor;\n }\n `\n ];\n\n constructor() {\n super();\n this.addEventListener('click', () => this.#toggle());\n this.addEventListener('keydown', event => {\n if (event.key !== 'Enter' && event.key !== ' ') return;\n event.preventDefault();\n this.#toggle();\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 /** The item this button marks: its own, or else the one on screen. */\n get #activeItem(): string | undefined {\n return (\n this.item ||\n (itemRefOf(this) ??\n this.computedContext?.testParts\n ?.flatMap(part => part.sections.flatMap(section => section.items))\n .find(item => item.active)?.identifier)\n );\n }\n\n protected override willUpdate(): void {\n const active = this.#activeItem;\n this.disabled = !active;\n this.bookmarked = !!active && bookmarkedItems(this.computedContext).includes(active);\n }\n\n protected override updated(): void {\n this.setAttribute('aria-pressed', String(this.bookmarked));\n this.setAttribute('aria-disabled', String(this.disabled));\n }\n\n #toggle(): void {\n const active = this.#activeItem;\n if (!active) return;\n const marked = bookmarkedItems(this.computedContext);\n const next = marked.includes(active) ? marked.filter(id => id !== active) : [...marked, active];\n // An empty list removes the entry, so a test nobody bookmarked keeps no trace in the state.\n dispatchPublic(this, 'qc-test-update-plugin-state', {\n plugin: 'bookmarks',\n value: next.length > 0 ? next : null\n });\n }\n\n override render() {\n return html`<span class=\"control\" part=\"button\"\n ><svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M6 3h12v18l-6-4.5L6 21z\" /></svg><slot></slot\n ></span>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-bookmark': TestBookmark;\n }\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { LitElement } from 'lit';
2
+ import type { ComputedContext } from '@citolab/qti-components/qti-base';
3
+ /**
4
+ * The character sheet plugin: a button that opens a sheet of characters that are not on the keyboard
5
+ * (`é`, `€`, `²`, …) and types the one the candidate picks into the answer field they were writing in.
6
+ *
7
+ * It follows the keyboard focus: the last text field or text area of a rendered item that had focus is
8
+ * the one it types into, so a candidate writes, opens the sheet, picks a character and goes on writing.
9
+ * Until an answer field has had focus it is `disabled`. A character goes in at the caret, replacing a
10
+ * selection, and the field gets a `change` event, so the interaction records the new answer.
11
+ *
12
+ * Put it inside `<test-navigation>`. It is a button (`role="button"`, `aria-expanded`) with its content
13
+ * as the label; `characters` is the sheet, as a string with the characters separated by spaces (the
14
+ * default is a Dutch set). The sheet opens in the top layer below the button, closes on Escape, on a
15
+ * click outside it, and when another item comes on screen. Style the sheet with `::part(sheet)` and its
16
+ * keys with `::part(key)`.
17
+ *
18
+ * @slot - The label of the button.
19
+ * @attr characters - The characters of the sheet, separated by spaces.
20
+ * @attr open - Reflected: the sheet is open.
21
+ * @attr disabled - Reflected: no answer field has had focus yet.
22
+ * @csspart button - The button.
23
+ * @csspart sheet - The sheet of characters.
24
+ * @csspart key - One character on the sheet.
25
+ */
26
+ export declare class TestCharacterSheet extends LitElement {
27
+ #private;
28
+ protected computedContext?: ComputedContext;
29
+ characters: string;
30
+ open: boolean;
31
+ disabled: boolean;
32
+ /** The answer field the sheet types into: the last one that had focus. */
33
+ private field;
34
+ static styles: import("lit").CSSResult[];
35
+ constructor();
36
+ connectedCallback(): void;
37
+ disconnectedCallback(): void;
38
+ protected willUpdate(): void;
39
+ protected updated(): void;
40
+ render(): import("lit").TemplateResult<1>;
41
+ }
42
+ declare global {
43
+ interface HTMLElementTagNameMap {
44
+ 'test-character-sheet': TestCharacterSheet;
45
+ }
46
+ }
@@ -0,0 +1,259 @@
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, state } from 'lit/decorators.js';
10
+ import { computedContext } from '@citolab/qti-components/qti-base';
11
+ import { controlStyles as styles } from '@citolab/qti-components/qti-test/plugin-api';
12
+ /** The characters a Dutch candidate reaches for that are not on the keyboard. */
13
+ const DEFAULT_CHARACTERS = 'é è ë ê ï ö ü à á ç ñ € £ § ± ° ² ³ × ÷ ≤ ≥ ≠ → ←';
14
+ /** Whether `element` is inside `ancestor`, also through shadow roots. */
15
+ const within = (element, ancestor) => {
16
+ let node = element;
17
+ while (node) {
18
+ if (ancestor.contains(node))
19
+ return true;
20
+ const root = node.getRootNode();
21
+ node = root instanceof ShadowRoot ? root.host : null;
22
+ }
23
+ return false;
24
+ };
25
+ const isField = (node) => node instanceof HTMLTextAreaElement ||
26
+ (node instanceof HTMLInputElement && /^(text|search|url|tel|email|)$/.test(node.type));
27
+ /**
28
+ * The character sheet plugin: a button that opens a sheet of characters that are not on the keyboard
29
+ * (`é`, `€`, `²`, …) and types the one the candidate picks into the answer field they were writing in.
30
+ *
31
+ * It follows the keyboard focus: the last text field or text area of a rendered item that had focus is
32
+ * the one it types into, so a candidate writes, opens the sheet, picks a character and goes on writing.
33
+ * Until an answer field has had focus it is `disabled`. A character goes in at the caret, replacing a
34
+ * selection, and the field gets a `change` event, so the interaction records the new answer.
35
+ *
36
+ * Put it inside `<test-navigation>`. It is a button (`role="button"`, `aria-expanded`) with its content
37
+ * as the label; `characters` is the sheet, as a string with the characters separated by spaces (the
38
+ * default is a Dutch set). The sheet opens in the top layer below the button, closes on Escape, on a
39
+ * click outside it, and when another item comes on screen. Style the sheet with `::part(sheet)` and its
40
+ * keys with `::part(key)`.
41
+ *
42
+ * @slot - The label of the button.
43
+ * @attr characters - The characters of the sheet, separated by spaces.
44
+ * @attr open - Reflected: the sheet is open.
45
+ * @attr disabled - Reflected: no answer field has had focus yet.
46
+ * @csspart button - The button.
47
+ * @csspart sheet - The sheet of characters.
48
+ * @csspart key - One character on the sheet.
49
+ */
50
+ export class TestCharacterSheet extends LitElement {
51
+ #activeItem;
52
+ static { this.styles = [
53
+ styles.button,
54
+ css `
55
+ :host {
56
+ position: relative;
57
+ }
58
+ :host([open]) .control {
59
+ ${styles.btnActive};
60
+ }
61
+ .sheet {
62
+ position: fixed;
63
+ inset: auto;
64
+ margin: 0;
65
+ padding: 0.375rem;
66
+ display: grid;
67
+ grid-template-columns: repeat(auto-fill, minmax(2.25rem, 1fr));
68
+ gap: 0.125rem;
69
+ width: var(--test-character-sheet-width, 20rem);
70
+ max-width: calc(100vw - 1rem);
71
+ border: var(--qti-border-width, var(--qc-border-width, var(--cito-border-width, 1px))) solid
72
+ var(--qti-border-color, color-mix(in oklab, CanvasText 45%, Canvas));
73
+ border-radius: var(--qti-radius-box, var(--qc-radius-box, var(--cito-radius-box, 0.5rem)));
74
+ background: var(--qti-color-base-100, var(--qc-color-base-100, var(--cito-color-base-100, Canvas)));
75
+ color: var(--qti-color-base-content, var(--qc-color-base-content, var(--cito-color-base-content, CanvasText)));
76
+ box-shadow: 0 8px 24px -8px rgb(0 0 0 / 0.35);
77
+ font: inherit;
78
+ }
79
+ .sheet:not(:popover-open) {
80
+ display: none;
81
+ }
82
+ .key {
83
+ ${styles.form};
84
+ padding: 0;
85
+ min-block-size: 2.25rem;
86
+ font-size: 1.125em;
87
+ background: transparent;
88
+ border: 0;
89
+ color: inherit;
90
+ }
91
+ @media (hover: hover) and (pointer: fine) {
92
+ .key:hover {
93
+ ${styles.btnInteractive};
94
+ }
95
+ }
96
+ .key:active {
97
+ ${styles.btnActive};
98
+ }
99
+ .key:focus-visible {
100
+ ${styles.focusRing};
101
+ outline-offset: -2px;
102
+ }
103
+ `
104
+ ]; }
105
+ #onFocusIn;
106
+ #onPointerDown;
107
+ #onKeyDown;
108
+ constructor() {
109
+ super();
110
+ this.characters = DEFAULT_CHARACTERS;
111
+ this.open = false;
112
+ this.disabled = true;
113
+ /** The answer field the sheet types into: the last one that had focus. */
114
+ this.field = null;
115
+ this.#onFocusIn = (event) => {
116
+ const target = event.composedPath()[0];
117
+ if (!isField(target) || !this.#inItem(target))
118
+ return;
119
+ this.field = target;
120
+ };
121
+ this.#onPointerDown = (event) => {
122
+ if (this.open && !event.composedPath().includes(this))
123
+ this.open = false;
124
+ };
125
+ this.#onKeyDown = (event) => {
126
+ if (event.key === 'Escape' && this.open) {
127
+ event.stopPropagation();
128
+ this.open = false;
129
+ this.focus();
130
+ }
131
+ };
132
+ this.addEventListener('click', event => {
133
+ // A key on the sheet is inside the host too; only a press on the button itself toggles.
134
+ if (!event.composedPath().some(node => node instanceof HTMLElement && node.classList.contains('key')))
135
+ this.#toggle();
136
+ });
137
+ this.addEventListener('keydown', event => {
138
+ if (event.key !== 'Enter' && event.key !== ' ')
139
+ return;
140
+ if (event.composedPath()[0] !== this)
141
+ return;
142
+ event.preventDefault();
143
+ this.#toggle();
144
+ });
145
+ }
146
+ connectedCallback() {
147
+ super.connectedCallback();
148
+ if (!this.hasAttribute('role'))
149
+ this.setAttribute('role', 'button');
150
+ if (!this.hasAttribute('tabindex'))
151
+ this.setAttribute('tabindex', '0');
152
+ document.addEventListener('focusin', this.#onFocusIn);
153
+ document.addEventListener('pointerdown', this.#onPointerDown);
154
+ document.addEventListener('keydown', this.#onKeyDown);
155
+ }
156
+ disconnectedCallback() {
157
+ super.disconnectedCallback();
158
+ document.removeEventListener('focusin', this.#onFocusIn);
159
+ document.removeEventListener('pointerdown', this.#onPointerDown);
160
+ document.removeEventListener('keydown', this.#onKeyDown);
161
+ }
162
+ /** The item on screen, or in a section the one the candidate is in. */
163
+ get #active() {
164
+ return this.computedContext?.testParts
165
+ ?.flatMap(part => part.sections.flatMap(section => section.items))
166
+ .find(item => item.active)?.identifier;
167
+ }
168
+ /** Whether a field belongs to an item the test has rendered. */
169
+ #inItem(field) {
170
+ const lookup = this.computedContext?.itemElement;
171
+ if (!lookup)
172
+ return false;
173
+ return (this.computedContext?.testParts ?? []).some(part => part.sections.some(section => section.items.some(item => {
174
+ const element = lookup(item.identifier);
175
+ return !!element && within(field, element);
176
+ })));
177
+ }
178
+ willUpdate() {
179
+ // Another item on screen: the field it typed into is gone with the old one.
180
+ const active = this.#active;
181
+ if (active !== this.#activeItem) {
182
+ this.#activeItem = active;
183
+ this.open = false;
184
+ }
185
+ if (this.field && !this.field.isConnected)
186
+ this.field = null;
187
+ this.disabled = !this.field;
188
+ }
189
+ updated() {
190
+ this.setAttribute('aria-disabled', String(this.disabled));
191
+ this.setAttribute('aria-expanded', String(this.open));
192
+ const sheet = this.renderRoot.querySelector('.sheet');
193
+ if (!sheet)
194
+ return;
195
+ if (this.open) {
196
+ if (!sheet.matches(':popover-open'))
197
+ sheet.showPopover?.();
198
+ // Below the button, kept on screen; measured once it shows.
199
+ const box = this.getBoundingClientRect();
200
+ sheet.style.top = `${box.bottom + 4}px`;
201
+ sheet.style.left = `${Math.max(8, Math.min(box.left, window.innerWidth - sheet.offsetWidth - 8))}px`;
202
+ }
203
+ else if (sheet.matches(':popover-open'))
204
+ sheet.hidePopover?.();
205
+ }
206
+ #toggle() {
207
+ if (this.disabled)
208
+ return;
209
+ this.open = !this.open;
210
+ }
211
+ #type(character) {
212
+ const field = this.field;
213
+ if (!field?.isConnected)
214
+ return;
215
+ const start = field.selectionStart ?? field.value.length;
216
+ const end = field.selectionEnd ?? start;
217
+ field.setRangeText(character, start, end, 'end');
218
+ field.focus();
219
+ // The interactions record a `change`; `input` is for anything else that watches the field.
220
+ field.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
221
+ field.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
222
+ }
223
+ render() {
224
+ const characters = this.characters.split(/\s+/).filter(Boolean);
225
+ // A press on the button must not take the focus from the field the sheet types into.
226
+ return html `<span class="control" part="button" @pointerdown=${(event) => event.preventDefault()}
227
+ ><slot>Ω</slot></span
228
+ >
229
+ <div class="sheet" part="sheet" popover="manual" role="group">
230
+ ${characters.map(character => html `<button
231
+ class="key"
232
+ part="key"
233
+ type="button"
234
+ tabindex="-1"
235
+ @pointerdown=${(event) => event.preventDefault()}
236
+ @click=${() => this.#type(character)}
237
+ >
238
+ ${character}
239
+ </button>`)}
240
+ </div>`;
241
+ }
242
+ }
243
+ __decorate([
244
+ consume({ context: computedContext, subscribe: true }),
245
+ property({ attribute: false })
246
+ ], TestCharacterSheet.prototype, "computedContext", void 0);
247
+ __decorate([
248
+ property()
249
+ ], TestCharacterSheet.prototype, "characters", void 0);
250
+ __decorate([
251
+ property({ type: Boolean, reflect: true })
252
+ ], TestCharacterSheet.prototype, "open", void 0);
253
+ __decorate([
254
+ property({ type: Boolean, reflect: true })
255
+ ], TestCharacterSheet.prototype, "disabled", void 0);
256
+ __decorate([
257
+ state()
258
+ ], TestCharacterSheet.prototype, "field", void 0);
259
+ //# sourceMappingURL=test-character-sheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACtD,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;2DACa;AAEhC;IAAX,QAAQ,EAAE;sDAAiC;AAEA;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDAAc;AAEb;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oDAAiB;AAG3C;IAAhB,KAAK,EAAE;iDAAoC","sourcesContent":["import { css, html, LitElement } 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 } from '@citolab/qti-components/qti-test/plugin-api';\n\nimport type { ComputedContext } from '@citolab/qti-components/qti-base';\n\n/** The characters a Dutch candidate reaches for that are not on the keyboard. */\nconst DEFAULT_CHARACTERS = 'é è ë ê ï ö ü à á ç ñ € £ § ± ° ² ³ × ÷ ≤ ≥ ≠ → ←';\n\ntype Field = HTMLInputElement | HTMLTextAreaElement;\n\n/** Whether `element` is inside `ancestor`, also through shadow roots. */\nconst within = (element: Node | null, ancestor: Element): boolean => {\n let node: Node | null = element;\n while (node) {\n if (ancestor.contains(node)) return true;\n const root = node.getRootNode();\n node = root instanceof ShadowRoot ? root.host : null;\n }\n return false;\n};\n\nconst isField = (node: unknown): node is Field =>\n node instanceof HTMLTextAreaElement ||\n (node instanceof HTMLInputElement && /^(text|search|url|tel|email|)$/.test(node.type));\n\n/**\n * The character sheet plugin: a button that opens a sheet of characters that are not on the keyboard\n * (`é`, `€`, `²`, …) and types the one the candidate picks into the answer field they were writing in.\n *\n * It follows the keyboard focus: the last text field or text area of a rendered item that had focus is\n * the one it types into, so a candidate writes, opens the sheet, picks a character and goes on writing.\n * Until an answer field has had focus it is `disabled`. A character goes in at the caret, replacing a\n * selection, and the field gets a `change` event, so the interaction records the new answer.\n *\n * Put it inside `<test-navigation>`. It is a button (`role=\"button\"`, `aria-expanded`) with its content\n * as the label; `characters` is the sheet, as a string with the characters separated by spaces (the\n * default is a Dutch set). The sheet opens in the top layer below the button, closes on Escape, on a\n * click outside it, and when another item comes on screen. Style the sheet with `::part(sheet)` and its\n * keys with `::part(key)`.\n *\n * @slot - The label of the button.\n * @attr characters - The characters of the sheet, separated by spaces.\n * @attr open - Reflected: the sheet is open.\n * @attr disabled - Reflected: no answer field has had focus yet.\n * @csspart button - The button.\n * @csspart sheet - The sheet of characters.\n * @csspart key - One character on the sheet.\n */\nexport class TestCharacterSheet extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n @property({ attribute: false })\n protected computedContext?: ComputedContext;\n\n @property() characters = DEFAULT_CHARACTERS;\n\n @property({ type: Boolean, reflect: true }) open = false;\n\n @property({ type: Boolean, reflect: true }) disabled = true;\n\n /** The answer field the sheet types into: the last one that had focus. */\n @state() private field: Field | null = null;\n\n #activeItem?: string;\n\n static override styles = [\n styles.button,\n css`\n :host {\n position: relative;\n }\n :host([open]) .control {\n ${styles.btnActive};\n }\n .sheet {\n position: fixed;\n inset: auto;\n margin: 0;\n padding: 0.375rem;\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(2.25rem, 1fr));\n gap: 0.125rem;\n width: var(--test-character-sheet-width, 20rem);\n max-width: calc(100vw - 1rem);\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 box-shadow: 0 8px 24px -8px rgb(0 0 0 / 0.35);\n font: inherit;\n }\n .sheet:not(:popover-open) {\n display: none;\n }\n .key {\n ${styles.form};\n padding: 0;\n min-block-size: 2.25rem;\n font-size: 1.125em;\n background: transparent;\n border: 0;\n color: inherit;\n }\n @media (hover: hover) and (pointer: fine) {\n .key:hover {\n ${styles.btnInteractive};\n }\n }\n .key:active {\n ${styles.btnActive};\n }\n .key:focus-visible {\n ${styles.focusRing};\n outline-offset: -2px;\n }\n `\n ];\n\n #onFocusIn = (event: FocusEvent) => {\n const target = event.composedPath()[0];\n if (!isField(target) || !this.#inItem(target)) return;\n this.field = target;\n };\n\n #onPointerDown = (event: PointerEvent) => {\n if (this.open && !event.composedPath().includes(this)) this.open = false;\n };\n\n #onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape' && this.open) {\n event.stopPropagation();\n this.open = false;\n this.focus();\n }\n };\n\n constructor() {\n super();\n this.addEventListener('click', event => {\n // A key on the sheet is inside the host too; only a press on the button itself toggles.\n if (!event.composedPath().some(node => node instanceof HTMLElement && node.classList.contains('key')))\n this.#toggle();\n });\n this.addEventListener('keydown', event => {\n if (event.key !== 'Enter' && event.key !== ' ') return;\n if (event.composedPath()[0] !== this) return;\n event.preventDefault();\n this.#toggle();\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 document.addEventListener('focusin', this.#onFocusIn);\n document.addEventListener('pointerdown', this.#onPointerDown);\n document.addEventListener('keydown', this.#onKeyDown);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener('focusin', this.#onFocusIn);\n document.removeEventListener('pointerdown', this.#onPointerDown);\n document.removeEventListener('keydown', this.#onKeyDown);\n }\n\n /** The item on screen, or in a section the one the candidate is in. */\n get #active(): string | undefined {\n return this.computedContext?.testParts\n ?.flatMap(part => part.sections.flatMap(section => section.items))\n .find(item => item.active)?.identifier;\n }\n\n /** Whether a field belongs to an item the test has rendered. */\n #inItem(field: Field): boolean {\n const lookup = this.computedContext?.itemElement;\n if (!lookup) return false;\n return (this.computedContext?.testParts ?? []).some(part =>\n part.sections.some(section =>\n section.items.some(item => {\n const element = lookup(item.identifier);\n return !!element && within(field, element);\n })\n )\n );\n }\n\n protected override willUpdate(): void {\n // Another item on screen: the field it typed into is gone with the old one.\n const active = this.#active;\n if (active !== this.#activeItem) {\n this.#activeItem = active;\n this.open = false;\n }\n if (this.field && !this.field.isConnected) this.field = null;\n this.disabled = !this.field;\n }\n\n protected override updated(): void {\n this.setAttribute('aria-disabled', String(this.disabled));\n this.setAttribute('aria-expanded', String(this.open));\n const sheet = this.renderRoot.querySelector<HTMLElement>('.sheet');\n if (!sheet) return;\n if (this.open) {\n if (!sheet.matches(':popover-open')) sheet.showPopover?.();\n // Below the button, kept on screen; measured once it shows.\n const box = this.getBoundingClientRect();\n sheet.style.top = `${box.bottom + 4}px`;\n sheet.style.left = `${Math.max(8, Math.min(box.left, window.innerWidth - sheet.offsetWidth - 8))}px`;\n } else if (sheet.matches(':popover-open')) sheet.hidePopover?.();\n }\n\n #toggle(): void {\n if (this.disabled) return;\n this.open = !this.open;\n }\n\n #type(character: string): void {\n const field = this.field;\n if (!field?.isConnected) return;\n const start = field.selectionStart ?? field.value.length;\n const end = field.selectionEnd ?? start;\n field.setRangeText(character, start, end, 'end');\n field.focus();\n // The interactions record a `change`; `input` is for anything else that watches the field.\n field.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n field.dispatchEvent(new Event('change', { bubbles: true, composed: true }));\n }\n\n override render() {\n const characters = this.characters.split(/\\s+/).filter(Boolean);\n // A press on the button must not take the focus from the field the sheet types into.\n return html`<span class=\"control\" part=\"button\" @pointerdown=${(event: Event) => event.preventDefault()}\n ><slot>Ω</slot></span\n >\n <div class=\"sheet\" part=\"sheet\" popover=\"manual\" role=\"group\">\n ${characters.map(\n character =>\n html`<button\n class=\"key\"\n part=\"key\"\n type=\"button\"\n tabindex=\"-1\"\n @pointerdown=${(event: Event) => event.preventDefault()}\n @click=${() => this.#type(character)}\n >\n ${character}\n </button>`\n )}\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-character-sheet': TestCharacterSheet;\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { LitElement } from 'lit';
2
+ export declare class TestItemLink extends LitElement {
3
+ static styles: import("lit").CSSResult;
4
+ private itemId;
5
+ constructor();
6
+ protected _requestItem(identifier: string): void;
7
+ render(): import("lit").TemplateResult<1>;
8
+ }
9
+ declare global {
10
+ interface HTMLElementTagNameMap {
11
+ 'test-item-link': TestItemLink;
12
+ }
13
+ }
@@ -0,0 +1,28 @@
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 { LitElement } from 'lit';
8
+ import { property } from 'lit/decorators.js';
9
+ import { controlStyles as styles } from '@citolab/qti-components/qti-test/plugin-api';
10
+ import { dispatchPublic } from '@citolab/qti-components/qti-test/plugin-api';
11
+ export class TestItemLink extends LitElement {
12
+ static { this.styles = styles.button; }
13
+ constructor() {
14
+ super();
15
+ this.itemId = null;
16
+ this.addEventListener('click', () => this._requestItem(this.itemId));
17
+ }
18
+ _requestItem(identifier) {
19
+ dispatchPublic(this, 'qc-test-navigate', { type: 'item', id: identifier });
20
+ }
21
+ render() {
22
+ return styles.control;
23
+ }
24
+ }
25
+ __decorate([
26
+ property({ type: String, attribute: 'item-id' })
27
+ ], TestItemLink.prototype, "itemId", void 0);
28
+ //# sourceMappingURL=test-item-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-item-link.js","sourceRoot":"","sources":["../../src/test-item-link/test-item-link.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAE7E,MAAM,OAAO,YAAa,SAAQ,UAAU;aAC1B,WAAM,GAAG,MAAM,CAAC,MAAM,AAAhB,CAAiB;IAKvC;QACE,KAAK,EAAE,CAAC;QAHF,WAAM,GAAW,IAAI,CAAC;QAI5B,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACvE,CAAC;IAES,YAAY,CAAC,UAAkB;QACvC,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7E,CAAC;IAEQ,MAAM;QACb,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;;AAbO;IADP,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;4CACnB","sourcesContent":["import { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { controlStyles as styles } from '@citolab/qti-components/qti-test/plugin-api';\nimport { dispatchPublic } from '@citolab/qti-components/qti-test/plugin-api';\n\nexport class TestItemLink extends LitElement {\n static override styles = styles.button;\n\n @property({ type: String, attribute: 'item-id' })\n private itemId: string = null;\n\n constructor() {\n super();\n this.addEventListener('click', () => this._requestItem(this.itemId));\n }\n\n protected _requestItem(identifier: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type: 'item', id: identifier });\n }\n\n override render() {\n return styles.control;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-item-link': TestItemLink;\n }\n}\n"]}