@pie-qti/default-components 0.1.1

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 (146) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +9 -0
  3. package/STYLING.md +226 -0
  4. package/dist/index.d.ts +35 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +190 -0
  7. package/dist/plugins/associate/index.d.ts +8 -0
  8. package/dist/plugins/associate/index.d.ts.map +1 -0
  9. package/dist/plugins/associate/index.js +8 -0
  10. package/dist/plugins/choice/index.d.ts +8 -0
  11. package/dist/plugins/choice/index.d.ts.map +1 -0
  12. package/dist/plugins/choice/index.js +8 -0
  13. package/dist/plugins/custom/index.d.ts +8 -0
  14. package/dist/plugins/custom/index.d.ts.map +1 -0
  15. package/dist/plugins/custom/index.js +8 -0
  16. package/dist/plugins/end-attempt/index.d.ts +8 -0
  17. package/dist/plugins/end-attempt/index.d.ts.map +1 -0
  18. package/dist/plugins/end-attempt/index.js +8 -0
  19. package/dist/plugins/extended-text/index.d.ts +8 -0
  20. package/dist/plugins/extended-text/index.d.ts.map +1 -0
  21. package/dist/plugins/extended-text/index.js +8 -0
  22. package/dist/plugins/gap-match/index.d.ts +8 -0
  23. package/dist/plugins/gap-match/index.d.ts.map +1 -0
  24. package/dist/plugins/gap-match/index.js +8 -0
  25. package/dist/plugins/graphic-associate/index.d.ts +8 -0
  26. package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
  27. package/dist/plugins/graphic-associate/index.js +8 -0
  28. package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.js +8 -0
  31. package/dist/plugins/graphic-order/index.d.ts +8 -0
  32. package/dist/plugins/graphic-order/index.d.ts.map +1 -0
  33. package/dist/plugins/graphic-order/index.js +8 -0
  34. package/dist/plugins/hotspot/index.d.ts +8 -0
  35. package/dist/plugins/hotspot/index.d.ts.map +1 -0
  36. package/dist/plugins/hotspot/index.js +8 -0
  37. package/dist/plugins/hottext/index.d.ts +8 -0
  38. package/dist/plugins/hottext/index.d.ts.map +1 -0
  39. package/dist/plugins/hottext/index.js +8 -0
  40. package/dist/plugins/index.d.ts +30 -0
  41. package/dist/plugins/index.d.ts.map +1 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/match/index.d.ts +8 -0
  44. package/dist/plugins/match/index.d.ts.map +1 -0
  45. package/dist/plugins/match/index.js +8 -0
  46. package/dist/plugins/media/index.d.ts +8 -0
  47. package/dist/plugins/media/index.d.ts.map +1 -0
  48. package/dist/plugins/media/index.js +8 -0
  49. package/dist/plugins/order/index.d.ts +8 -0
  50. package/dist/plugins/order/index.d.ts.map +1 -0
  51. package/dist/plugins/order/index.js +8 -0
  52. package/dist/plugins/position-object/index.d.ts +8 -0
  53. package/dist/plugins/position-object/index.d.ts.map +1 -0
  54. package/dist/plugins/position-object/index.js +8 -0
  55. package/dist/plugins/select-point/index.d.ts +8 -0
  56. package/dist/plugins/select-point/index.d.ts.map +1 -0
  57. package/dist/plugins/select-point/index.js +8 -0
  58. package/dist/plugins/slider/index.d.ts +8 -0
  59. package/dist/plugins/slider/index.d.ts.map +1 -0
  60. package/dist/plugins/slider/index.js +8 -0
  61. package/dist/shared/actions/typesetAction.d.ts +26 -0
  62. package/dist/shared/actions/typesetAction.d.ts.map +1 -0
  63. package/dist/shared/actions/typesetAction.js +70 -0
  64. package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
  65. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
  66. package/dist/shared/extensions/MathLiveEditor.js +239 -0
  67. package/dist/shared/index.d.ts +11 -0
  68. package/dist/shared/index.d.ts.map +1 -0
  69. package/dist/shared/index.js +15 -0
  70. package/dist/shared/utils/eventHelpers.d.ts +18 -0
  71. package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
  72. package/dist/shared/utils/eventHelpers.js +30 -0
  73. package/dist/shared/utils/pairHelpers.d.ts +55 -0
  74. package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
  75. package/dist/shared/utils/pairHelpers.js +76 -0
  76. package/dist/shared/utils/touchDragHelper.d.ts +33 -0
  77. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
  78. package/dist/shared/utils/touchDragHelper.js +168 -0
  79. package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
  80. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
  81. package/dist/shared/utils/webComponentHelpers.js +26 -0
  82. package/package.json +93 -0
  83. package/src/index.ts +213 -0
  84. package/src/plugins/associate/AssociateInteraction.svelte +273 -0
  85. package/src/plugins/associate/index.ts +9 -0
  86. package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
  87. package/src/plugins/choice/index.ts +9 -0
  88. package/src/plugins/custom/CustomInteraction.svelte +61 -0
  89. package/src/plugins/custom/index.ts +9 -0
  90. package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
  91. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
  92. package/src/plugins/end-attempt/index.ts +9 -0
  93. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
  94. package/src/plugins/extended-text/index.ts +9 -0
  95. package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
  96. package/src/plugins/gap-match/index.ts +9 -0
  97. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
  98. package/src/plugins/graphic-associate/index.ts +9 -0
  99. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
  100. package/src/plugins/graphic-gap-match/index.ts +9 -0
  101. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
  102. package/src/plugins/graphic-order/index.ts +9 -0
  103. package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
  104. package/src/plugins/hotspot/index.ts +9 -0
  105. package/src/plugins/hottext/HottextInteraction.svelte +296 -0
  106. package/src/plugins/hottext/index.ts +9 -0
  107. package/src/plugins/index.ts +31 -0
  108. package/src/plugins/match/MatchInteraction.svelte +70 -0
  109. package/src/plugins/match/index.ts +9 -0
  110. package/src/plugins/media/MediaInteraction.svelte +213 -0
  111. package/src/plugins/media/index.ts +9 -0
  112. package/src/plugins/order/OrderInteraction.svelte +159 -0
  113. package/src/plugins/order/index.ts +9 -0
  114. package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
  115. package/src/plugins/position-object/README.md +130 -0
  116. package/src/plugins/position-object/index.ts +9 -0
  117. package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
  118. package/src/plugins/select-point/index.ts +9 -0
  119. package/src/plugins/slider/SliderInteraction.svelte +141 -0
  120. package/src/plugins/slider/index.ts +9 -0
  121. package/src/plugins/upload/UploadInteraction.svelte +59 -0
  122. package/src/shared/actions/typesetAction.ts +87 -0
  123. package/src/shared/components/CustomInteractionFallback.svelte +153 -0
  124. package/src/shared/components/DragHandle.svelte +44 -0
  125. package/src/shared/components/DrawingCanvas.svelte +243 -0
  126. package/src/shared/components/FileUpload.svelte +153 -0
  127. package/src/shared/components/GraphicGapMatch.svelte +316 -0
  128. package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
  129. package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
  130. package/src/shared/components/MatchDragDrop.svelte +434 -0
  131. package/src/shared/components/MathContent.svelte +18 -0
  132. package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
  133. package/src/shared/components/RichTextEditor.svelte +316 -0
  134. package/src/shared/components/ShadowBaseStyles.svelte +391 -0
  135. package/src/shared/components/SortableList.svelte +297 -0
  136. package/src/shared/extensions/MathLiveEditor.ts +304 -0
  137. package/src/shared/index.ts +17 -0
  138. package/src/shared/styles/shared.css +16 -0
  139. package/src/shared/utils/eventHelpers.ts +36 -0
  140. package/src/shared/utils/pairHelpers.ts +86 -0
  141. package/src/shared/utils/touchDragHelper.ts +211 -0
  142. package/src/shared/utils/webComponentHelpers.ts +27 -0
  143. package/src/svelte-shims.d.ts +9 -0
  144. package/svelte.config.js +9 -0
  145. package/tests/index.test.ts +8 -0
  146. package/tsconfig.json +20 -0
@@ -0,0 +1,212 @@
1
+ <svelte:options customElement="pie-qti-choice" />
2
+
3
+ <script lang="ts">
4
+ import type { ChoiceInteractionData } from '@pie-qti/item-player';
5
+ import type { I18nProvider } from '@pie-qti/i18n';
6
+ import { normalizeHeuristicsConfig, type QtiHeuristicsConfig } from '@pie-qti/item-player';
7
+ import { processFeedbackInline } from '@pie-qti/item-player/components/utils';
8
+ import { typesetAction } from '../../shared/actions/typesetAction';
9
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
10
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
11
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
12
+
13
+ interface Props {
14
+ interaction?: ChoiceInteractionData | string;
15
+ response?: string | string[] | null;
16
+ correctResponse?: string | string[] | null;
17
+ disabled?: boolean;
18
+ role?: string;
19
+ i18n?: I18nProvider;
20
+ typeset?: (element: HTMLElement) => void;
21
+ onChange?: (value: string | string[]) => void;
22
+ outcomeValues?: Record<string, any>;
23
+ heuristicsConfig?: QtiHeuristicsConfig;
24
+ }
25
+
26
+ let {
27
+ interaction = $bindable(),
28
+ response = $bindable(),
29
+ correctResponse = $bindable(),
30
+ disabled = false,
31
+ role = 'candidate',
32
+ i18n = $bindable(),
33
+ typeset,
34
+ onChange,
35
+ outcomeValues = {},
36
+ heuristicsConfig
37
+ }: Props = $props();
38
+
39
+ // Normalize heuristics configuration with defaults
40
+ const heuristics = $derived(normalizeHeuristicsConfig(heuristicsConfig));
41
+
42
+ // Translation helper:
43
+ // The default i18n provider returns the key itself when a translation is missing.
44
+ // We treat that as "missing" so we can safely fall back to the provided string.
45
+ const t = $derived((key: string, fallback: string) => {
46
+ const v = i18n?.t(key);
47
+ return !v || v === key ? fallback : v;
48
+ });
49
+
50
+ // Parse props that may be JSON strings (web component usage)
51
+ const parsedInteraction = $derived(parseJsonProp<ChoiceInteractionData>(interaction));
52
+ const parsedResponse = $derived(parseJsonProp<string | string[]>(response));
53
+ const parsedCorrectResponse = $derived(parseJsonProp<string | string[]>(correctResponse));
54
+ const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
55
+
56
+ // Helper function to check if a choice is correct
57
+ function isCorrectChoice(identifier: string): boolean {
58
+ if (!isShowingCorrect) return false;
59
+ if (Array.isArray(parsedCorrectResponse)) {
60
+ return parsedCorrectResponse.includes(identifier);
61
+ }
62
+ return parsedCorrectResponse === identifier;
63
+ }
64
+
65
+ // Helper function to filter feedbackInline from choice text based on outcome values
66
+ function filterFeedbackInline(text: string): string {
67
+ return processFeedbackInline(text, {
68
+ outcomeValues,
69
+ applyHeuristics: heuristics.feedbackTextFormatting,
70
+ wrapWithSpan: true
71
+ });
72
+ }
73
+
74
+ // Get reference to the root element for event dispatching
75
+ let rootElement: HTMLDivElement | undefined = $state();
76
+
77
+ function handleRadioChange(identifier: string) {
78
+ response = identifier;
79
+ // Call onChange callback if provided (for Svelte component usage)
80
+ onChange?.(identifier);
81
+ // Dispatch event for web component usage - event will bubble up to the host element
82
+ if (rootElement) {
83
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, identifier));
84
+ }
85
+ }
86
+
87
+ function handleCheckboxChange(identifier: string, checked: boolean) {
88
+ const currentValues = Array.isArray(parsedResponse) ? parsedResponse : [];
89
+ let newValues = [...currentValues];
90
+
91
+ if (checked) {
92
+ newValues.push(identifier);
93
+ } else {
94
+ newValues = newValues.filter((v) => v !== identifier);
95
+ }
96
+
97
+ response = newValues;
98
+ // Call onChange callback if provided (for Svelte component usage)
99
+ onChange?.(newValues);
100
+ // Dispatch event for web component usage - event will bubble up to the host element
101
+ if (rootElement) {
102
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newValues));
103
+ }
104
+ }
105
+ </script>
106
+
107
+ <ShadowBaseStyles />
108
+
109
+ <div bind:this={rootElement} part="root" class="qti-choice-interaction space-y-2" use:typesetAction={{ typeset }}>
110
+ {#if !parsedInteraction}
111
+ <div class="alert alert-error">{i18n?.t('common.errorNoData') ?? 'No interaction data provided'}</div>
112
+ {:else if parsedInteraction.maxChoices === 1}
113
+ <!-- Single choice (radio buttons) -->
114
+ {#each parsedInteraction.choices as choice}
115
+ <div part="option" class="qti-choice-option form-control">
116
+ <label
117
+ part="label"
118
+ class="qti-choice-label label cursor-pointer justify-start gap-4"
119
+ class:qti-choice-correct={isCorrectChoice(choice.identifier)}
120
+ >
121
+ <input
122
+ part="input"
123
+ type="radio"
124
+ name={parsedInteraction.responseId}
125
+ class="radio radio-primary"
126
+ class:radio-success={isCorrectChoice(choice.identifier)}
127
+ value={choice.identifier}
128
+ checked={parsedResponse === choice.identifier}
129
+ onchange={() => handleRadioChange(choice.identifier)}
130
+ {disabled}
131
+ />
132
+ <span part="text" class="qti-choice-text label-text">
133
+ {@html choice.text}
134
+ </span>
135
+ {#if isCorrectChoice(choice.identifier)}
136
+ <span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
137
+ {/if}
138
+ </label>
139
+ </div>
140
+ {/each}
141
+ {:else}
142
+ <!-- Multiple choice (checkboxes) -->
143
+ {@const currentValues = Array.isArray(parsedResponse) ? parsedResponse : []}
144
+ {#each parsedInteraction.choices as choice}
145
+ <div part="option" class="qti-choice-option form-control">
146
+ <label
147
+ part="label"
148
+ class="qti-choice-label label cursor-pointer justify-start gap-4"
149
+ class:qti-choice-correct={isCorrectChoice(choice.identifier)}
150
+ >
151
+ <input
152
+ part="input"
153
+ type="checkbox"
154
+ class="checkbox checkbox-primary"
155
+ class:checkbox-success={isCorrectChoice(choice.identifier)}
156
+ value={choice.identifier}
157
+ checked={currentValues.includes(choice.identifier)}
158
+ onchange={(e: Event) => {
159
+ const checked = (e.currentTarget as HTMLInputElement).checked;
160
+ handleCheckboxChange(choice.identifier, checked);
161
+ }}
162
+ {disabled}
163
+ />
164
+ <span part="text" class="qti-choice-text label-text">
165
+ {@html choice.text}
166
+ </span>
167
+ {#if isCorrectChoice(choice.identifier)}
168
+ <span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
169
+ {/if}
170
+ </label>
171
+ </div>
172
+ {/each}
173
+ {/if}
174
+ </div>
175
+
176
+ <style>
177
+ /* Minimal layout so this works without Tailwind/DaisyUI */
178
+ .qti-choice-interaction {
179
+ display: grid;
180
+ gap: 0.5rem;
181
+ }
182
+ .qti-choice-option {
183
+ display: block;
184
+ }
185
+ .qti-choice-label {
186
+ display: flex;
187
+ align-items: flex-start;
188
+ gap: 0.75rem;
189
+ cursor: pointer;
190
+ }
191
+ .qti-choice-text {
192
+ display: inline-block;
193
+ line-height: 1.35;
194
+ }
195
+ .qti-choice-interaction input[type='radio'],
196
+ .qti-choice-interaction input[type='checkbox'] {
197
+ margin-top: 0.15rem;
198
+ }
199
+
200
+ /* Correct answer highlighting */
201
+ .qti-choice-correct {
202
+ background-color: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
203
+ border-radius: 0.5rem;
204
+ padding: 0.25rem 0.5rem;
205
+ margin: -0.25rem -0.5rem;
206
+ }
207
+
208
+ .radio-success,
209
+ .checkbox-success {
210
+ accent-color: var(--color-success, oklch(76% 0.177 163.223));
211
+ }
212
+ </style>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'choiceInteraction',
5
+ tagName: 'pie-qti-choice',
6
+ name: 'default-choice',
7
+ description: 'Default Svelte-based choice interaction',
8
+ priority: 0,
9
+ };
@@ -0,0 +1,61 @@
1
+ <svelte:options customElement="pie-qti-custom" />
2
+
3
+ <script lang="ts">
4
+ import type { CustomInteractionData, InteractionData } from '@pie-qti/item-player';
5
+ import type { I18nProvider } from '@pie-qti/i18n';
6
+ import CustomInteractionFallback from '../../shared/components/CustomInteractionFallback.svelte';
7
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
8
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
10
+
11
+ interface Props {
12
+ interaction?: InteractionData | string;
13
+ response?: string | null;
14
+ disabled?: boolean;
15
+ i18n?: I18nProvider;
16
+ typeset?: (element: HTMLElement) => void;
17
+ onChange?: (value: string | null) => void;
18
+ }
19
+
20
+ let { interaction = $bindable(), response = $bindable(), disabled = false, i18n = $bindable(), typeset, onChange }: Props = $props();
21
+
22
+ // Parse props that may be JSON strings (web component usage)
23
+ const parsedInteraction = $derived(parseJsonProp<InteractionData>(interaction));
24
+ const parsedResponse = $derived(parseJsonProp<string>(response));
25
+
26
+ // Get reference to the root element for event dispatching
27
+ let rootElement: HTMLDivElement | undefined = $state();
28
+
29
+ // Type assertion for custom interaction data
30
+ const customInteraction = $derived(parsedInteraction as CustomInteractionData | undefined);
31
+
32
+ function handleChange(value: string | null) {
33
+ response = value;
34
+ // Call onChange callback if provided (for Svelte component usage)
35
+ onChange?.(value);
36
+ // Dispatch custom event for web component usage - event will bubble up to the host element
37
+ if (rootElement) {
38
+ rootElement.dispatchEvent(createQtiChangeEvent(customInteraction?.responseId, value));
39
+ }
40
+ }
41
+ </script>
42
+
43
+ <ShadowBaseStyles />
44
+
45
+ <div bind:this={rootElement} part="root" class="qti-custom-interaction">
46
+ {#if !customInteraction}
47
+ <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
48
+ {:else}
49
+ <!-- @ts-expect-error - CustomInteractionFallback has stricter prop types -->
50
+ <CustomInteractionFallback
51
+ responseId={customInteraction.responseId}
52
+ prompt={customInteraction.prompt}
53
+ rawAttributes={customInteraction.rawAttributes}
54
+ xml={customInteraction.xml}
55
+ {disabled}
56
+ value={parsedResponse}
57
+ onChange={handleChange}
58
+ testIdInput={`custom-input-${customInteraction.responseId}`}
59
+ />
60
+ {/if}
61
+ </div>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'customInteraction',
5
+ tagName: 'pie-qti-custom',
6
+ name: 'default-custom',
7
+ description: 'Default Svelte-based custom interaction',
8
+ priority: 0,
9
+ };
@@ -0,0 +1,90 @@
1
+ <svelte:options customElement="pie-qti-drawing" />
2
+
3
+ <script lang="ts">
4
+ import type { DrawingInteractionData, QTIFileResponse } from '@pie-qti/item-player';
5
+ import type { I18nProvider } from '@pie-qti/i18n';
6
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
+ import DrawingCanvas from '../../shared/components/DrawingCanvas.svelte';
8
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
9
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
10
+ import { typesetAction } from '../../shared/actions/typesetAction';
11
+
12
+ interface Props {
13
+ interaction?: DrawingInteractionData | string;
14
+ response?: QTIFileResponse | string | null;
15
+ disabled?: boolean;
16
+ i18n?: I18nProvider;
17
+ typeset?: (element: HTMLElement) => void;
18
+ onChange?: (value: QTIFileResponse | null) => void;
19
+ }
20
+
21
+ let { interaction = $bindable(), response = $bindable(), disabled = false, i18n = $bindable(), typeset, onChange }: Props = $props();
22
+
23
+ // Parse props that may be JSON strings (web component usage)
24
+ const parsedInteraction = $derived(parseJsonProp<DrawingInteractionData>(interaction));
25
+ const parsedResponse = $derived(parseJsonProp<QTIFileResponse>(response));
26
+
27
+ // Get reference to the root element for event dispatching
28
+ let rootElement: HTMLDivElement | undefined = $state();
29
+
30
+ function handleChange(value: QTIFileResponse | null) {
31
+ response = value;
32
+ // Call onChange callback if provided (for Svelte component usage)
33
+ onChange?.(value);
34
+ // Dispatch event for web component usage - event will bubble up to the host element
35
+ if (rootElement && parsedInteraction) {
36
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, value));
37
+ }
38
+ }
39
+
40
+ // Extract drawing configuration from rawAttributes
41
+ const strokeColor = $derived(parsedInteraction?.rawAttributes?.['data-stroke-color'] ?? '#111827');
42
+ const lineWidth = $derived(
43
+ parsedInteraction?.rawAttributes?.['data-line-width']
44
+ ? Number(parsedInteraction.rawAttributes['data-line-width'])
45
+ : 3
46
+ );
47
+ const lineCap = $derived(
48
+ (parsedInteraction?.rawAttributes?.['data-line-cap'] as 'butt' | 'round' | 'square') ?? 'round'
49
+ );
50
+ const lineJoin = $derived(
51
+ (parsedInteraction?.rawAttributes?.['data-line-join'] as 'bevel' | 'round' | 'miter') ?? 'round'
52
+ );
53
+ </script>
54
+
55
+ <ShadowBaseStyles />
56
+
57
+ <div bind:this={rootElement} part="root" class="qti-drawing-interaction" use:typesetAction={{ typeset }}>
58
+ {#if !parsedInteraction}
59
+ <div class="alert alert-error">
60
+ <span>{i18n?.t('common.error', 'Error')}: {i18n?.t('common.errorNoData', 'No interaction data provided')}</span>
61
+ </div>
62
+ {:else}
63
+ {#if parsedInteraction.prompt}
64
+ <p class="font-semibold mb-2">{parsedInteraction.prompt}</p>
65
+ {/if}
66
+ <DrawingCanvas
67
+ responseId={parsedInteraction.responseId}
68
+ imageData={parsedInteraction.imageData}
69
+ {disabled}
70
+ {i18n}
71
+ value={parsedResponse}
72
+ onChange={handleChange}
73
+ {strokeColor}
74
+ {lineWidth}
75
+ {lineCap}
76
+ {lineJoin}
77
+ />
78
+ {/if}
79
+ </div>
80
+
81
+ <style>
82
+ /* Ensure pointer events work in Shadow DOM */
83
+ :global(canvas) {
84
+ pointer-events: auto !important;
85
+ }
86
+
87
+ :global(.touch-none) {
88
+ touch-action: none;
89
+ }
90
+ </style>
@@ -0,0 +1,142 @@
1
+ <svelte:options customElement="pie-qti-end-attempt" />
2
+
3
+ <script lang="ts">
4
+ import type { EndAttemptInteractionData } from '@pie-qti/item-player';
5
+ import type { I18nProvider } from '@pie-qti/i18n';
6
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
8
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
+
10
+ interface Props {
11
+ interaction?: EndAttemptInteractionData | string;
12
+ response?: boolean | null;
13
+ disabled?: boolean;
14
+ i18n?: I18nProvider;
15
+ onChange?: (value: boolean) => void;
16
+ }
17
+
18
+ let { interaction = $bindable(), response = $bindable(), disabled = false, i18n = $bindable(), onChange }: Props = $props();
19
+
20
+ // Parse props that may be JSON strings (web component usage)
21
+ const parsedInteraction = $derived(parseJsonProp<EndAttemptInteractionData>(interaction));
22
+ const parsedResponse = $derived(parseJsonProp<boolean>(response));
23
+
24
+ // Get reference to the root element for event dispatching
25
+ let rootElement: HTMLDivElement | undefined = $state();
26
+
27
+ // Track if button has been clicked
28
+ let hasEnded = $state(false);
29
+
30
+ const canInteract = $derived(!disabled);
31
+
32
+ $effect(() => {
33
+ // Sync with parent response changes
34
+ hasEnded = parsedResponse ?? false;
35
+ });
36
+
37
+ function handleEndAttempt() {
38
+ if (!canInteract || hasEnded) return;
39
+ hasEnded = true;
40
+ response = true;
41
+ // Call onChange callback if provided (for Svelte component usage)
42
+ onChange?.(true);
43
+ // Dispatch event for web component usage - event will bubble up to the host element
44
+ if (rootElement) {
45
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, true));
46
+ }
47
+ }
48
+ </script>
49
+
50
+ <ShadowBaseStyles />
51
+
52
+ <div bind:this={rootElement} class="qti-end-attempt-interaction">
53
+ {#if !parsedInteraction}
54
+ <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
55
+ {:else}
56
+ {#if parsedInteraction.prompt}
57
+ <p class="font-semibold mb-3">{@html parsedInteraction.prompt}</p>
58
+ {/if}
59
+
60
+ <div class="qti-end-row flex items-center gap-4">
61
+ <button
62
+ part="button"
63
+ class="btn btn-error btn-lg {hasEnded ? 'btn-disabled' : ''}"
64
+ onclick={handleEndAttempt}
65
+ disabled={!canInteract || hasEnded}
66
+ aria-label={parsedInteraction.title}
67
+ >
68
+ {#if hasEnded}
69
+ <svg
70
+ xmlns="http://www.w3.org/2000/svg"
71
+ part="icon"
72
+ class="qti-icon h-6 w-6 mr-2"
73
+ fill="none"
74
+ viewBox="0 0 24 24"
75
+ stroke="currentColor"
76
+ >
77
+ <path
78
+ stroke-linecap="round"
79
+ stroke-linejoin="round"
80
+ stroke-width="2"
81
+ d="M5 13l4 4L19 7"
82
+ />
83
+ </svg>
84
+ {parsedInteraction.countAttempt ? (i18n?.t('interactions.endAttempt.ended') ?? 'Attempt Ended') : (i18n?.t('interactions.endAttempt.requested') ?? 'Requested')}
85
+ {:else}
86
+ <svg
87
+ xmlns="http://www.w3.org/2000/svg"
88
+ part="icon"
89
+ class="qti-icon h-6 w-6 mr-2"
90
+ fill="none"
91
+ viewBox="0 0 24 24"
92
+ stroke="currentColor"
93
+ >
94
+ <path
95
+ stroke-linecap="round"
96
+ stroke-linejoin="round"
97
+ stroke-width="2"
98
+ d="M6 18L18 6M6 6l12 12"
99
+ />
100
+ </svg>
101
+ {parsedInteraction.title}
102
+ {/if}
103
+ </button>
104
+
105
+ {#if hasEnded && parsedInteraction.countAttempt}
106
+ <div part="ended-message" class="alert alert-warning inline-flex items-center gap-2 w-auto">
107
+ <svg
108
+ xmlns="http://www.w3.org/2000/svg"
109
+ part="ended-icon"
110
+ class="qti-icon stroke-current shrink-0 h-6 w-6"
111
+ fill="none"
112
+ viewBox="0 0 24 24"
113
+ >
114
+ <path
115
+ stroke-linecap="round"
116
+ stroke-linejoin="round"
117
+ stroke-width="2"
118
+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
119
+ />
120
+ </svg>
121
+ <span>Your attempt has been ended and can no longer be modified.</span>
122
+ </div>
123
+ {/if}
124
+ </div>
125
+ {/if}
126
+ </div>
127
+
128
+ <style>
129
+ /* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
130
+ .qti-icon {
131
+ width: 1.5rem;
132
+ height: 1.5rem;
133
+ flex: 0 0 auto;
134
+ }
135
+ /* Minimal layout if host doesn't provide utility classes */
136
+ .qti-end-row {
137
+ display: flex;
138
+ align-items: center;
139
+ gap: 1rem;
140
+ flex-wrap: wrap;
141
+ }
142
+ </style>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'endAttemptInteraction',
5
+ tagName: 'pie-qti-end-attempt',
6
+ name: 'default-end-attempt',
7
+ description: 'Default Svelte-based end attempt interaction',
8
+ priority: 0,
9
+ };
@@ -0,0 +1,77 @@
1
+ <svelte:options customElement="pie-qti-extended-text" />
2
+
3
+ <script lang="ts">
4
+ import type { ExtendedTextInteractionData } from '@pie-qti/item-player';
5
+ import type { I18nProvider } from '@pie-qti/i18n';
6
+ import RichTextEditor from '../../shared/components/RichTextEditor.svelte';
7
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
8
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
9
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
10
+
11
+ interface Props {
12
+ interaction?: ExtendedTextInteractionData | string;
13
+ response?: string | null;
14
+ correctResponse?: string | null;
15
+ disabled?: boolean;
16
+ role?: string;
17
+ i18n?: I18nProvider;
18
+ typeset?: (element: HTMLElement) => void;
19
+ onChange?: (value: string) => void;
20
+ }
21
+
22
+ let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange }: Props = $props();
23
+
24
+ // Parse props that may be JSON strings (web component usage)
25
+ const parsedInteraction = $derived(parseJsonProp<ExtendedTextInteractionData>(interaction));
26
+ const parsedResponse = $derived(parseJsonProp<string>(response));
27
+ const parsedCorrectResponse = $derived(parseJsonProp<string>(correctResponse));
28
+ const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
29
+
30
+ // Get reference to the root element for event dispatching
31
+ let rootElement: HTMLDivElement | undefined = $state();
32
+
33
+ function handleChange(html: string) {
34
+ response = html;
35
+ // Call onChange callback if provided (for Svelte component usage)
36
+ onChange?.(html);
37
+ // Dispatch event for web component usage - event will bubble up to the host element
38
+ if (rootElement) {
39
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, html));
40
+ }
41
+ }
42
+ </script>
43
+
44
+ <ShadowBaseStyles />
45
+
46
+ <div bind:this={rootElement} part="root" class="qti-extended-text-interaction">
47
+ {#if !parsedInteraction}
48
+ <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
49
+ {:else}
50
+ <div part="editor">
51
+ <RichTextEditor
52
+ value={parsedResponse || ''}
53
+ editable={!disabled}
54
+ placeholder={parsedInteraction.placeholderText || 'Enter your response...'}
55
+ minHeight={parsedInteraction.expectedLines ? parsedInteraction.expectedLines * 24 : 200}
56
+ {i18n}
57
+ onChange={handleChange}
58
+ />
59
+ </div>
60
+ {#if isShowingCorrect && parsedCorrectResponse}
61
+ <div part="correct-answer" class="mt-3 p-3 bg-success bg-opacity-10 border border-success rounded">
62
+ <div class="text-sm font-semibold text-success mb-2">
63
+ {i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'} Answer:
64
+ </div>
65
+ <div class="text-sm">{parsedCorrectResponse}</div>
66
+ </div>
67
+ {/if}
68
+ {/if}
69
+ </div>
70
+
71
+ <style>
72
+ /* Minimal layout so this works without Tailwind/DaisyUI */
73
+ .qti-extended-text-interaction {
74
+ display: grid;
75
+ gap: 0.75rem;
76
+ }
77
+ </style>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'extendedTextInteraction',
5
+ tagName: 'pie-qti-extended-text',
6
+ name: 'default-extended-text',
7
+ description: 'Default Svelte-based extended text interaction',
8
+ priority: 0,
9
+ };