@pie-qti/default-components 0.1.1 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
- package/dist/shared/extensions/MathLiveEditor.js +3 -7
- package/dist/shared/utils/eventHelpers.d.ts +3 -11
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
- package/dist/shared/utils/eventHelpers.js +7 -1
- package/dist/shared/utils/matchGroupUtils.d.ts +8 -0
- package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
- package/dist/shared/utils/matchGroupUtils.js +13 -0
- package/dist/shared/utils/pairHelpers.d.ts +15 -2
- package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
- package/dist/shared/utils/pairHelpers.js +30 -8
- package/dist/shared/utils/touchDragHelper.d.ts +1 -32
- package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
- package/dist/shared/utils/touchDragHelper.js +1 -168
- package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
- package/dist/shared/utils/webComponentHelpers.js +3 -3
- package/package.json +117 -91
- package/src/catalog/CatalogPopup.svelte +162 -0
- package/src/index.ts +10 -1
- package/src/plugins/associate/AssociateInteraction.svelte +18 -1
- package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
- package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
- package/src/plugins/gap-match/GapMatchInteraction.svelte +199 -22
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +230 -145
- package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
- package/src/plugins/hottext/HottextInteraction.svelte +33 -4
- package/src/plugins/index.ts +1 -0
- package/src/plugins/match/MatchInteraction.svelte +13 -1
- package/src/plugins/media/MediaInteraction.svelte +2 -2
- package/src/plugins/order/OrderInteraction.svelte +132 -11
- package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -15
- package/src/plugins/select-point/SelectPointInteraction.svelte +139 -21
- package/src/shared/components/DrawingCanvas.svelte +17 -1
- package/src/shared/components/GraphicGapMatch.svelte +5 -3
- package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
- package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
- package/src/shared/components/MatchDragDrop.svelte +72 -25
- package/src/shared/components/ShadowBaseStyles.svelte +1 -2
- package/src/shared/extensions/MathLiveEditor.ts +3 -8
- package/src/shared/styles/qti-shared-vocabulary.css +320 -0
- package/src/shared/utils/eventHelpers.ts +12 -3
- package/src/shared/utils/matchGroupUtils.ts +14 -0
- package/src/shared/utils/pairHelpers.ts +32 -9
- package/src/shared/utils/touchDragHelper.ts +1 -211
- package/src/shared/utils/webComponentHelpers.ts +5 -5
- package/.turbo/turbo-build.log +0 -1
- package/CHANGELOG.md +0 -9
- package/STYLING.md +0 -226
- package/svelte.config.js +0 -9
- package/tests/index.test.ts +0 -8
- package/tsconfig.json +0 -20
|
@@ -77,8 +77,16 @@
|
|
|
77
77
|
let positions = $state<Position[]>([]);
|
|
78
78
|
let draggedStageId: string | null = $state(null);
|
|
79
79
|
let draggedPositionIndex: number | null = $state(null);
|
|
80
|
+
// imageContainer / imageContainer are the same element — one binding covers both roles
|
|
80
81
|
let imageContainer: HTMLDivElement | null = $state(null);
|
|
81
82
|
|
|
83
|
+
// Keyboard accessibility state (K-04)
|
|
84
|
+
let selectedStageId: string | null = $state(null); // stage currently being keyboard-positioned
|
|
85
|
+
let crosshairX = $state(0.5); // normalized [0,1] x position on background image
|
|
86
|
+
let crosshairY = $state(0.5); // normalized [0,1] y position on background image
|
|
87
|
+
let crosshairActive = $state(false); // whether the crosshair is visible/active
|
|
88
|
+
let liveMessage = $state(''); // message for aria-live region
|
|
89
|
+
|
|
82
90
|
const canInteract = $derived(!disabled);
|
|
83
91
|
const canAddMore = $derived(
|
|
84
92
|
!parsedInteraction || parsedInteraction.maxChoices === 0 || positions.length < parsedInteraction.maxChoices
|
|
@@ -109,6 +117,7 @@
|
|
|
109
117
|
|
|
110
118
|
for (let i = 0; i < parsedResponse.length; i++) {
|
|
111
119
|
const pointStr = parsedResponse[i];
|
|
120
|
+
if (typeof pointStr !== 'string') continue;
|
|
112
121
|
const parts = pointStr.trim().split(/\s+/);
|
|
113
122
|
if (parts.length >= 2) {
|
|
114
123
|
const x = parseFloat(parts[0]);
|
|
@@ -234,12 +243,6 @@
|
|
|
234
243
|
// QTI baseType="point" expects array of strings like ["158 168", "250 200"]
|
|
235
244
|
const responseValue = positions.map(pos => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
|
|
236
245
|
|
|
237
|
-
console.log('[PositionObject] Emitting response:', {
|
|
238
|
-
responseId: parsedInteraction?.responseId,
|
|
239
|
-
value: responseValue,
|
|
240
|
-
positions: positions
|
|
241
|
-
});
|
|
242
|
-
|
|
243
246
|
response = responseValue;
|
|
244
247
|
// Call onChange callback if provided (for Svelte component usage)
|
|
245
248
|
onChange?.(responseValue);
|
|
@@ -302,6 +305,7 @@
|
|
|
302
305
|
|
|
303
306
|
for (let i = 0; i < value.length; i++) {
|
|
304
307
|
const pointStr = value[i];
|
|
308
|
+
if (typeof pointStr !== 'string') continue;
|
|
305
309
|
const parts = pointStr.trim().split(/\s+/);
|
|
306
310
|
if (parts.length >= 2) {
|
|
307
311
|
const x = parseFloat(parts[0]);
|
|
@@ -359,6 +363,140 @@
|
|
|
359
363
|
Math.abs(pos.y - correctPos.y) < 5
|
|
360
364
|
);
|
|
361
365
|
}
|
|
366
|
+
|
|
367
|
+
// ---------------------------------------------------------------------------
|
|
368
|
+
// Keyboard accessibility (K-04) — two-phase: palette select → canvas place
|
|
369
|
+
// ---------------------------------------------------------------------------
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Activate keyboard placement mode for a palette stage.
|
|
373
|
+
* Phase 1: user presses Enter/Space on a palette item.
|
|
374
|
+
*/
|
|
375
|
+
function activateKeyboardPlacement(stageId: string) {
|
|
376
|
+
if (!canInteract) return;
|
|
377
|
+
const stage = getStageById(stageId);
|
|
378
|
+
if (!stage || !canDragStage(stageId)) return;
|
|
379
|
+
|
|
380
|
+
selectedStageId = stageId;
|
|
381
|
+
crosshairActive = true;
|
|
382
|
+
|
|
383
|
+
// Initialise crosshair to the stage's last placed position, or centre
|
|
384
|
+
const existing = [...positions].reverse().find((p: Position) => p.stageId === stageId);
|
|
385
|
+
if (existing && parsedInteraction?.imageData) {
|
|
386
|
+
const imgW = Number(parsedInteraction.imageData.width) || 1;
|
|
387
|
+
const imgH = Number(parsedInteraction.imageData.height) || 1;
|
|
388
|
+
crosshairX = Math.max(0, Math.min(1, existing.x / imgW));
|
|
389
|
+
crosshairY = Math.max(0, Math.min(1, existing.y / imgH));
|
|
390
|
+
} else {
|
|
391
|
+
crosshairX = 0.5;
|
|
392
|
+
crosshairY = 0.5;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
liveMessage = `${stage.label} selected. Tab to canvas, then use arrow keys to position. Press Enter to place, Escape to cancel.`;
|
|
396
|
+
|
|
397
|
+
// Move focus to the canvas so arrow keys work immediately
|
|
398
|
+
requestAnimationFrame(() => imageContainer?.focus());
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Handle keydown on a palette item.
|
|
403
|
+
*/
|
|
404
|
+
function handlePaletteKeydown(event: KeyboardEvent, stageId: string) {
|
|
405
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
406
|
+
event.preventDefault();
|
|
407
|
+
activateKeyboardPlacement(stageId);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Place the currently selected stage at the crosshair position.
|
|
413
|
+
*/
|
|
414
|
+
function placeAtCrosshair() {
|
|
415
|
+
if (!selectedStageId || !parsedInteraction?.imageData) return;
|
|
416
|
+
|
|
417
|
+
const imgW = Number(parsedInteraction.imageData.width) || 800;
|
|
418
|
+
const imgH = Number(parsedInteraction.imageData.height) || 600;
|
|
419
|
+
|
|
420
|
+
let x = crosshairX * imgW;
|
|
421
|
+
let y = crosshairY * imgH;
|
|
422
|
+
|
|
423
|
+
// Apply centerPoint adjustment (same logic as mouse drop)
|
|
424
|
+
if (parsedInteraction.centerPoint) {
|
|
425
|
+
const stage = getStageById(selectedStageId);
|
|
426
|
+
if (stage?.objectData) {
|
|
427
|
+
x -= parseInt(stage.objectData.width || '50') / 2;
|
|
428
|
+
y -= parseInt(stage.objectData.height || '50') / 2;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const stage = getStageById(selectedStageId);
|
|
433
|
+
if (!stage) return;
|
|
434
|
+
|
|
435
|
+
// Check stage capacity
|
|
436
|
+
const usageCount = getStageUsageCount(selectedStageId);
|
|
437
|
+
if (usageCount >= stage.matchMax) return;
|
|
438
|
+
if (!canAddMore) return;
|
|
439
|
+
|
|
440
|
+
positions = [...positions, { stageId: selectedStageId, x, y }];
|
|
441
|
+
|
|
442
|
+
const responseValue = positions.map((pos) => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
|
|
443
|
+
response = responseValue;
|
|
444
|
+
onChange?.(responseValue);
|
|
445
|
+
if (rootElement) {
|
|
446
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, responseValue));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const pct = (v: number) => Math.round(v * 100);
|
|
450
|
+
liveMessage = `${stage.label} placed at ${pct(crosshairX)}%, ${pct(crosshairY)}%.`;
|
|
451
|
+
|
|
452
|
+
selectedStageId = null;
|
|
453
|
+
crosshairActive = false;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Handle keydown on the canvas when in keyboard placement mode.
|
|
458
|
+
*/
|
|
459
|
+
function handleCanvasKeydown(event: KeyboardEvent) {
|
|
460
|
+
if (!crosshairActive || !selectedStageId) return;
|
|
461
|
+
|
|
462
|
+
const step = event.shiftKey ? 0.01 : 0.05;
|
|
463
|
+
|
|
464
|
+
switch (event.key) {
|
|
465
|
+
case 'ArrowLeft':
|
|
466
|
+
event.preventDefault();
|
|
467
|
+
crosshairX = Math.max(0, crosshairX - step);
|
|
468
|
+
break;
|
|
469
|
+
case 'ArrowRight':
|
|
470
|
+
event.preventDefault();
|
|
471
|
+
crosshairX = Math.min(1, crosshairX + step);
|
|
472
|
+
break;
|
|
473
|
+
case 'ArrowUp':
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
crosshairY = Math.max(0, crosshairY - step);
|
|
476
|
+
break;
|
|
477
|
+
case 'ArrowDown':
|
|
478
|
+
event.preventDefault();
|
|
479
|
+
crosshairY = Math.min(1, crosshairY + step);
|
|
480
|
+
break;
|
|
481
|
+
case 'Enter':
|
|
482
|
+
case ' ':
|
|
483
|
+
event.preventDefault();
|
|
484
|
+
placeAtCrosshair();
|
|
485
|
+
return;
|
|
486
|
+
case 'Escape':
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
selectedStageId = null;
|
|
489
|
+
crosshairActive = false;
|
|
490
|
+
liveMessage = 'Placement cancelled.';
|
|
491
|
+
return;
|
|
492
|
+
default:
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Announce updated position after arrow movement
|
|
497
|
+
const pct = (v: number) => Math.round(v * 100);
|
|
498
|
+
liveMessage = `Position: ${pct(crosshairX)}%, ${pct(crosshairY)}%.`;
|
|
499
|
+
}
|
|
362
500
|
</script>
|
|
363
501
|
|
|
364
502
|
<ShadowBaseStyles />
|
|
@@ -374,15 +512,21 @@
|
|
|
374
512
|
<div part="layout" class="qti-po-layout flex flex-col lg:flex-row gap-4 items-start">
|
|
375
513
|
<!-- Canvas Area with Background Image -->
|
|
376
514
|
<div part="canvas-area" class="qti-po-canvas-area flex-1 min-w-0">
|
|
515
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
516
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
377
517
|
<div
|
|
378
518
|
bind:this={imageContainer}
|
|
379
519
|
part="canvas"
|
|
380
|
-
class="qti-po-canvas relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200"
|
|
520
|
+
class="qti-po-canvas relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200 {crosshairActive ? 'qti-po-canvas-active' : ''}"
|
|
381
521
|
style="width: 100%; aspect-ratio: {parsedInteraction.imageData?.width || 800} / {parsedInteraction.imageData?.height || 600}; box-sizing: border-box;"
|
|
382
522
|
ondrop={handleDrop}
|
|
383
523
|
ondragover={handleDragOver}
|
|
384
|
-
|
|
385
|
-
|
|
524
|
+
onkeydown={handleCanvasKeydown}
|
|
525
|
+
role="application"
|
|
526
|
+
tabindex={crosshairActive ? 0 : -1}
|
|
527
|
+
aria-label={crosshairActive
|
|
528
|
+
? (i18n?.t('interactions.positionObject.canvasActiveLabel') ?? `Positioning canvas – use arrow keys to move crosshair, Enter to place, Escape to cancel`)
|
|
529
|
+
: (i18n?.t('interactions.positionObject.canvasLabel') ?? 'Positioning canvas')}
|
|
386
530
|
>
|
|
387
531
|
<!-- Background Image -->
|
|
388
532
|
{#if parsedInteraction.imageData}
|
|
@@ -514,6 +658,39 @@
|
|
|
514
658
|
{/if}
|
|
515
659
|
{/each}
|
|
516
660
|
{/if}
|
|
661
|
+
|
|
662
|
+
<!-- Keyboard crosshair overlay (K-04) -->
|
|
663
|
+
{#if crosshairActive}
|
|
664
|
+
<svg
|
|
665
|
+
class="qti-po-crosshair-overlay"
|
|
666
|
+
aria-hidden="true"
|
|
667
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
668
|
+
>
|
|
669
|
+
<!-- vertical line -->
|
|
670
|
+
<line
|
|
671
|
+
x1="{crosshairX * 100}%"
|
|
672
|
+
y1="0"
|
|
673
|
+
x2="{crosshairX * 100}%"
|
|
674
|
+
y2="100%"
|
|
675
|
+
class="qti-po-crosshair-line"
|
|
676
|
+
/>
|
|
677
|
+
<!-- horizontal line -->
|
|
678
|
+
<line
|
|
679
|
+
x1="0"
|
|
680
|
+
y1="{crosshairY * 100}%"
|
|
681
|
+
x2="100%"
|
|
682
|
+
y2="{crosshairY * 100}%"
|
|
683
|
+
class="qti-po-crosshair-line"
|
|
684
|
+
/>
|
|
685
|
+
<!-- centre dot -->
|
|
686
|
+
<circle
|
|
687
|
+
cx="{crosshairX * 100}%"
|
|
688
|
+
cy="{crosshairY * 100}%"
|
|
689
|
+
r="6"
|
|
690
|
+
class="qti-po-crosshair-dot"
|
|
691
|
+
/>
|
|
692
|
+
</svg>
|
|
693
|
+
{/if}
|
|
517
694
|
</div>
|
|
518
695
|
|
|
519
696
|
{#if parsedInteraction.minChoices > 0}
|
|
@@ -533,7 +710,7 @@
|
|
|
533
710
|
Available Objects ({positions.length}{#if parsedInteraction.maxChoices > 0}/{parsedInteraction.maxChoices}{/if})
|
|
534
711
|
</h3>
|
|
535
712
|
|
|
536
|
-
<p class="text-xs text-base-content/60 mb-2">Drag objects onto the canvas to position
|
|
713
|
+
<p class="text-xs text-base-content/60 mb-2">Drag objects onto the canvas, or press Enter/Space on an object then use arrow keys to position it on the canvas.</p>
|
|
537
714
|
|
|
538
715
|
<div class="space-y-2">
|
|
539
716
|
{#each parsedInteraction.positionObjectStages as stage}
|
|
@@ -541,17 +718,16 @@
|
|
|
541
718
|
{@const canDrag = canDragStage(stage.identifier)}
|
|
542
719
|
<div
|
|
543
720
|
part="palette-item"
|
|
544
|
-
class="qti-po-palette-item flex items-center gap-3 p-3 rounded-lg bg-base-200 border border-base-300 {canInteract &&
|
|
545
|
-
canDrag
|
|
546
|
-
? 'cursor-move hover:border-primary'
|
|
547
|
-
: 'opacity-50 cursor-not-allowed'}"
|
|
721
|
+
class="qti-po-palette-item flex items-center gap-3 p-3 rounded-lg bg-base-200 border border-base-300 {canInteract && canDrag ? 'cursor-move hover:border-primary' : 'opacity-50 cursor-not-allowed'} {selectedStageId === stage.identifier ? 'qti-po-palette-item-selected' : ''}"
|
|
548
722
|
draggable={canInteract && canDrag}
|
|
549
723
|
ondragstart={(e) => {
|
|
550
724
|
if (canDrag) handleDragStart(e, stage.identifier);
|
|
551
725
|
}}
|
|
726
|
+
onkeydown={(e) => handlePaletteKeydown(e, stage.identifier)}
|
|
552
727
|
role="button"
|
|
553
728
|
tabindex={canInteract && canDrag ? 0 : -1}
|
|
554
|
-
aria-label="{stage.label} ({usageCount}/{stage.matchMax} used)"
|
|
729
|
+
aria-label="{stage.label} ({usageCount}/{stage.matchMax} used){selectedStageId === stage.identifier ? '. Selected for placement' : ''}"
|
|
730
|
+
aria-pressed={selectedStageId === stage.identifier}
|
|
555
731
|
>
|
|
556
732
|
<!-- Object Preview -->
|
|
557
733
|
<div class="qti-po-preview flex-shrink-0">
|
|
@@ -595,6 +771,9 @@
|
|
|
595
771
|
</div>
|
|
596
772
|
</div>
|
|
597
773
|
{/if}
|
|
774
|
+
|
|
775
|
+
<!-- Visually-hidden live region for keyboard placement announcements (K-04) -->
|
|
776
|
+
<div aria-live="polite" aria-atomic="true" class="qti-po-sr-only">{liveMessage}</div>
|
|
598
777
|
</div>
|
|
599
778
|
|
|
600
779
|
<style>
|
|
@@ -668,4 +847,57 @@
|
|
|
668
847
|
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
669
848
|
background: var(--color-base-200, oklch(98% 0 0));
|
|
670
849
|
}
|
|
850
|
+
|
|
851
|
+
/* Selected palette item (K-04) */
|
|
852
|
+
.qti-po-palette-item-selected {
|
|
853
|
+
border-color: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
854
|
+
background: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
855
|
+
color: var(--color-primary-content, oklch(89.824% 0.06192 275.75));
|
|
856
|
+
box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary, oklch(49.12% 0.3096 275.75)) 40%, transparent);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/* Canvas active state ring (K-04) */
|
|
860
|
+
.qti-po-canvas-active {
|
|
861
|
+
outline: 3px solid var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
862
|
+
outline-offset: 2px;
|
|
863
|
+
}
|
|
864
|
+
.qti-po-canvas-active:focus {
|
|
865
|
+
outline: 3px solid var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
866
|
+
outline-offset: 2px;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/* Crosshair SVG overlay (K-04) */
|
|
870
|
+
.qti-po-crosshair-overlay {
|
|
871
|
+
position: absolute;
|
|
872
|
+
inset: 0;
|
|
873
|
+
width: 100%;
|
|
874
|
+
height: 100%;
|
|
875
|
+
pointer-events: none;
|
|
876
|
+
z-index: 100;
|
|
877
|
+
}
|
|
878
|
+
.qti-po-crosshair-line {
|
|
879
|
+
stroke: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
880
|
+
stroke-width: 1.5;
|
|
881
|
+
stroke-dasharray: 6 4;
|
|
882
|
+
opacity: 0.85;
|
|
883
|
+
}
|
|
884
|
+
.qti-po-crosshair-dot {
|
|
885
|
+
fill: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
886
|
+
stroke: white;
|
|
887
|
+
stroke-width: 2;
|
|
888
|
+
opacity: 0.95;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/* Visually hidden live region (K-04) */
|
|
892
|
+
.qti-po-sr-only {
|
|
893
|
+
position: absolute;
|
|
894
|
+
width: 1px;
|
|
895
|
+
height: 1px;
|
|
896
|
+
padding: 0;
|
|
897
|
+
margin: -1px;
|
|
898
|
+
overflow: hidden;
|
|
899
|
+
clip: rect(0, 0, 0, 0);
|
|
900
|
+
white-space: nowrap;
|
|
901
|
+
border: 0;
|
|
902
|
+
}
|
|
671
903
|
</style>
|
|
@@ -37,6 +37,12 @@
|
|
|
37
37
|
let imageContainer: HTMLDivElement | null = $state(null);
|
|
38
38
|
let imageElement: HTMLElement | null = $state(null);
|
|
39
39
|
|
|
40
|
+
// Keyboard crosshair state (K-01)
|
|
41
|
+
let crosshairActive = $state(false);
|
|
42
|
+
let crosshairX = $state(0.5); // normalized 0-1
|
|
43
|
+
let crosshairY = $state(0.5); // normalized 0-1
|
|
44
|
+
let liveRegionText = $state('');
|
|
45
|
+
|
|
40
46
|
/**
|
|
41
47
|
* Parse correct response points (same format as user response)
|
|
42
48
|
*/
|
|
@@ -92,20 +98,6 @@
|
|
|
92
98
|
: []
|
|
93
99
|
);
|
|
94
100
|
|
|
95
|
-
// Debug logging
|
|
96
|
-
$effect(() => {
|
|
97
|
-
if (role === 'scorer') {
|
|
98
|
-
console.log('[SelectPoint] Role:', role);
|
|
99
|
-
console.log('[SelectPoint] parsedCorrectResponse:', parsedCorrectResponse);
|
|
100
|
-
console.log('[SelectPoint] correctPoints array:', JSON.stringify(correctPoints));
|
|
101
|
-
console.log('[SelectPoint] correctPoints.length:', correctPoints.length);
|
|
102
|
-
if (correctPoints.length > 0) {
|
|
103
|
-
console.log('[SelectPoint] First correct point x:', correctPoints[0].x, 'y:', correctPoints[0].y);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
|
|
109
101
|
$effect(() => {
|
|
110
102
|
// Sync with parent response changes
|
|
111
103
|
const r = parsedResponse;
|
|
@@ -140,7 +132,12 @@
|
|
|
140
132
|
/**
|
|
141
133
|
* Check if selection limit has been reached
|
|
142
134
|
*/
|
|
143
|
-
|
|
135
|
+
// maxChoices=0 means unlimited per QTI spec
|
|
136
|
+
const canSelectMore = $derived(
|
|
137
|
+
!parsedInteraction ||
|
|
138
|
+
parsedInteraction.maxChoices === 0 ||
|
|
139
|
+
selectedPoints.length < parsedInteraction.maxChoices
|
|
140
|
+
);
|
|
144
141
|
|
|
145
142
|
/**
|
|
146
143
|
* Check if minimum selection requirement has been met
|
|
@@ -225,6 +222,79 @@
|
|
|
225
222
|
}
|
|
226
223
|
}
|
|
227
224
|
});
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Place a point at the current crosshair position (K-01).
|
|
228
|
+
* Converts normalized crosshair coords to intrinsic pixel coords.
|
|
229
|
+
*/
|
|
230
|
+
function placePointAtCrosshair() {
|
|
231
|
+
if (!canSelectMore || !parsedInteraction?.imageData) return;
|
|
232
|
+
|
|
233
|
+
const intrinsicWidth = parseInt(parsedInteraction.imageData.width) || 500;
|
|
234
|
+
const intrinsicHeight = parseInt(parsedInteraction.imageData.height) || 300;
|
|
235
|
+
|
|
236
|
+
const x = Math.round(crosshairX * intrinsicWidth);
|
|
237
|
+
const y = Math.round(crosshairY * intrinsicHeight);
|
|
238
|
+
|
|
239
|
+
selectedPoints = [...selectedPoints, { x, y }];
|
|
240
|
+
|
|
241
|
+
const canonicalValue =
|
|
242
|
+
parsedInteraction.maxChoices === 1
|
|
243
|
+
? (selectedPoints[0] ? `${selectedPoints[0].x} ${selectedPoints[0].y}` : null)
|
|
244
|
+
: selectedPoints.map((p) => `${p.x} ${p.y}`);
|
|
245
|
+
response = canonicalValue;
|
|
246
|
+
onChange?.(canonicalValue);
|
|
247
|
+
rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Handle keyboard events on the image container (K-01).
|
|
252
|
+
* Arrow keys move the crosshair; Enter/Space place a point.
|
|
253
|
+
*/
|
|
254
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
255
|
+
if (disabled) return;
|
|
256
|
+
|
|
257
|
+
const LARGE_STEP = 0.05; // 5% per arrow key press
|
|
258
|
+
const SMALL_STEP = 0.01; // 1% with Shift for fine control
|
|
259
|
+
|
|
260
|
+
switch (e.key) {
|
|
261
|
+
case 'ArrowLeft':
|
|
262
|
+
case 'ArrowRight':
|
|
263
|
+
case 'ArrowUp':
|
|
264
|
+
case 'ArrowDown': {
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
const step = e.shiftKey ? SMALL_STEP : LARGE_STEP;
|
|
267
|
+
if (e.key === 'ArrowLeft') crosshairX = Math.max(0, crosshairX - step);
|
|
268
|
+
if (e.key === 'ArrowRight') crosshairX = Math.min(1, crosshairX + step);
|
|
269
|
+
if (e.key === 'ArrowUp') crosshairY = Math.max(0, crosshairY - step);
|
|
270
|
+
if (e.key === 'ArrowDown') crosshairY = Math.min(1, crosshairY + step);
|
|
271
|
+
|
|
272
|
+
const xPct = Math.round(crosshairX * 100);
|
|
273
|
+
const yPct = Math.round(crosshairY * 100);
|
|
274
|
+
liveRegionText = `Position: ${xPct}%, ${yPct}%`;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case 'Enter':
|
|
278
|
+
case ' ':
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
if (canSelectMore) {
|
|
281
|
+
placePointAtCrosshair();
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function handleFocus() {
|
|
288
|
+
crosshairActive = true;
|
|
289
|
+
crosshairX = 0.5;
|
|
290
|
+
crosshairY = 0.5;
|
|
291
|
+
liveRegionText = 'Position: 50%, 50%';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function handleBlur() {
|
|
295
|
+
crosshairActive = false;
|
|
296
|
+
liveRegionText = '';
|
|
297
|
+
}
|
|
228
298
|
</script>
|
|
229
299
|
|
|
230
300
|
<ShadowBaseStyles />
|
|
@@ -239,19 +309,24 @@
|
|
|
239
309
|
|
|
240
310
|
<div class="space-y-3">
|
|
241
311
|
|
|
312
|
+
<!-- Visually-hidden live region announces crosshair position to screen readers -->
|
|
313
|
+
<span
|
|
314
|
+
aria-live="polite"
|
|
315
|
+
aria-atomic="true"
|
|
316
|
+
style="position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;"
|
|
317
|
+
>{liveRegionText}</span>
|
|
318
|
+
|
|
242
319
|
<div
|
|
243
320
|
bind:this={imageContainer}
|
|
244
321
|
class="image-container relative inline-block"
|
|
245
322
|
style={disabled ? 'cursor: default;' : 'cursor: crosshair;'}
|
|
246
323
|
role="button"
|
|
247
324
|
tabindex={disabled ? -1 : 0}
|
|
248
|
-
aria-label={i18n?.t('interactions.selectPoint.instructionAria') ?? 'Click to select
|
|
325
|
+
aria-label={i18n?.t('interactions.selectPoint.instructionAria') ?? 'Click or use arrow keys to position crosshair, then press Enter or Space to select a point on the image'}
|
|
249
326
|
onclick={handleImageClick}
|
|
250
|
-
onkeydown={
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
}}
|
|
327
|
+
onkeydown={handleKeydown}
|
|
328
|
+
onfocus={handleFocus}
|
|
329
|
+
onblur={handleBlur}
|
|
255
330
|
>
|
|
256
331
|
{#if parsedInteraction.imageData}
|
|
257
332
|
{#if parsedInteraction.imageData.type === 'svg'}
|
|
@@ -320,6 +395,28 @@
|
|
|
320
395
|
<p class="text-base-content/50">{i18n?.t('interactions.selectPoint.noImage') ?? 'No image provided'}</p>
|
|
321
396
|
</div>
|
|
322
397
|
{/if}
|
|
398
|
+
|
|
399
|
+
<!-- Keyboard crosshair overlay (K-01) — visible only when container has focus -->
|
|
400
|
+
{#if crosshairActive && !disabled && parsedInteraction?.imageData}
|
|
401
|
+
{@const imgW = parseInt(parsedInteraction.imageData.width) || 500}
|
|
402
|
+
{@const imgH = parseInt(parsedInteraction.imageData.height) || 300}
|
|
403
|
+
{@const cx = crosshairX * imgW}
|
|
404
|
+
{@const cy = crosshairY * imgH}
|
|
405
|
+
<svg
|
|
406
|
+
aria-hidden="true"
|
|
407
|
+
class="crosshair-overlay"
|
|
408
|
+
style="width: {imgW}px; height: {imgH}px;"
|
|
409
|
+
viewBox="0 0 {imgW} {imgH}"
|
|
410
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
411
|
+
>
|
|
412
|
+
<!-- Horizontal line -->
|
|
413
|
+
<line x1="0" y1={cy} x2={imgW} y2={cy} class="crosshair-line" />
|
|
414
|
+
<!-- Vertical line -->
|
|
415
|
+
<line x1={cx} y1="0" x2={cx} y2={imgH} class="crosshair-line" />
|
|
416
|
+
<!-- Centre dot -->
|
|
417
|
+
<circle cx={cx} cy={cy} r="5" class="crosshair-dot" />
|
|
418
|
+
</svg>
|
|
419
|
+
{/if}
|
|
323
420
|
</div>
|
|
324
421
|
|
|
325
422
|
<div class="flex items-center justify-between text-sm text-base-content/70">
|
|
@@ -450,4 +547,25 @@
|
|
|
450
547
|
border: 2px dashed hsl(var(--bc) / 0.2);
|
|
451
548
|
border-radius: 8px;
|
|
452
549
|
}
|
|
550
|
+
|
|
551
|
+
/* K-01 keyboard crosshair overlay */
|
|
552
|
+
.crosshair-overlay {
|
|
553
|
+
position: absolute;
|
|
554
|
+
top: 0;
|
|
555
|
+
left: 0;
|
|
556
|
+
pointer-events: none;
|
|
557
|
+
z-index: 150;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
.crosshair-line {
|
|
561
|
+
stroke: #2563eb;
|
|
562
|
+
stroke-width: 1.5;
|
|
563
|
+
stroke-dasharray: 4 3;
|
|
564
|
+
opacity: 0.85;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
.crosshair-dot {
|
|
568
|
+
fill: #2563eb;
|
|
569
|
+
opacity: 0.9;
|
|
570
|
+
}
|
|
453
571
|
</style>
|
|
@@ -139,8 +139,18 @@
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
function commitValue() {
|
|
142
|
-
if (!canvasEl) return;
|
|
142
|
+
if (!canvasEl || !ctx) return;
|
|
143
143
|
const dataUrl = canvasEl.toDataURL('image/png');
|
|
144
|
+
|
|
145
|
+
// Extract ImageData synchronously from canvas and include it in the response
|
|
146
|
+
// This allows custom operators to analyze drawing content without async image loading
|
|
147
|
+
let canvasImageData: globalThis.ImageData | undefined;
|
|
148
|
+
try {
|
|
149
|
+
canvasImageData = ctx.getImageData(0, 0, canvasEl.width, canvasEl.height);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
console.warn('[DrawingCanvas] Failed to extract image data:', e);
|
|
152
|
+
}
|
|
153
|
+
|
|
144
154
|
const size = dataUrlSize(dataUrl);
|
|
145
155
|
const response: QTIFileResponse = {
|
|
146
156
|
name: `drawing-${responseId}.png`,
|
|
@@ -148,6 +158,12 @@
|
|
|
148
158
|
size,
|
|
149
159
|
lastModified: Date.now(),
|
|
150
160
|
dataUrl,
|
|
161
|
+
// Include ImageData if available (for drawing analysis in custom operators)
|
|
162
|
+
imageData: canvasImageData ? {
|
|
163
|
+
data: canvasImageData.data,
|
|
164
|
+
width: canvasImageData.width,
|
|
165
|
+
height: canvasImageData.height,
|
|
166
|
+
} : undefined,
|
|
151
167
|
};
|
|
152
168
|
onChange(response);
|
|
153
169
|
announceText = translations.updated;
|
|
@@ -149,8 +149,8 @@ function parseCoords(hotspot: Hotspot): { x: number; y: number; width: number; h
|
|
|
149
149
|
const [cx, cy, r] = coords;
|
|
150
150
|
return { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };
|
|
151
151
|
} else if (hotspot.shape === 'rect') {
|
|
152
|
-
const [x, y,
|
|
153
|
-
return { x, y, width, height };
|
|
152
|
+
const [x, y, right, bottom] = coords;
|
|
153
|
+
return { x, y, width: right - x, height: bottom - y };
|
|
154
154
|
}
|
|
155
155
|
// For poly, use bounding box (simplified)
|
|
156
156
|
return { x: coords[0], y: coords[1], width: 40, height: 40 };
|
|
@@ -256,7 +256,9 @@ function parseCoords(hotspot: Hotspot): { x: number; y: number; width: number; h
|
|
|
256
256
|
onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
|
|
257
257
|
/>
|
|
258
258
|
{:else if hotspot.shape === 'rect'}
|
|
259
|
-
{@const [x, y,
|
|
259
|
+
{@const [x, y, right, bottom] = hotspot.coords.split(',').map(Number)}
|
|
260
|
+
{@const width = right - x}
|
|
261
|
+
{@const height = bottom - y}
|
|
260
262
|
{@const hotspotIndex = hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
|
|
261
263
|
<rect
|
|
262
264
|
role="button"
|
|
@@ -19,6 +19,15 @@ const { interaction, response = null, disabled = false, typeset, onChange }: Pro
|
|
|
19
19
|
// Transform response format: string[] to the pairs format GraphicGapMatch expects
|
|
20
20
|
const pairs = $derived(response ?? []);
|
|
21
21
|
|
|
22
|
+
// Build imageData HTML string: inline SVG content or an <img> tag for raster images
|
|
23
|
+
const imageDataHtml = $derived.by(() => {
|
|
24
|
+
const img = interaction.imageData;
|
|
25
|
+
if (!img) return '';
|
|
26
|
+
if (img.content) return img.content as string;
|
|
27
|
+
if (img.src) return `<img src="${img.src}" alt="" style="width: 100%; height: 100%; display: block; position: absolute; top: 0; left: 0;" />`;
|
|
28
|
+
return '';
|
|
29
|
+
});
|
|
30
|
+
|
|
22
31
|
function handlePairsChange(newPairs: string[]) {
|
|
23
32
|
onChange(newPairs);
|
|
24
33
|
}
|
|
@@ -28,7 +37,7 @@ function handlePairsChange(newPairs: string[]) {
|
|
|
28
37
|
gapTexts={interaction.gapTexts}
|
|
29
38
|
hotspots={interaction.hotspots}
|
|
30
39
|
{pairs}
|
|
31
|
-
imageData={
|
|
40
|
+
imageData={imageDataHtml}
|
|
32
41
|
imageWidth={interaction.imageData?.width ?? '600'}
|
|
33
42
|
imageHeight={interaction.imageData?.height ?? '500'}
|
|
34
43
|
{disabled}
|
|
@@ -86,24 +86,29 @@ const segments = $derived.by(() => {
|
|
|
86
86
|
{#if segment.type === 'html'}
|
|
87
87
|
{@html segment.content}
|
|
88
88
|
{:else if segment.type === 'textEntry'}
|
|
89
|
+
{@const inputWidthClass = (segment.interaction.interactionClasses ?? []).find((c: string) => c.startsWith('qti-input-width-'))}
|
|
90
|
+
{@const inputWidthCh = inputWidthClass ? parseInt(inputWidthClass.replace('qti-input-width-', ''), 10) : null}
|
|
89
91
|
<input
|
|
90
92
|
type="text"
|
|
91
|
-
class=
|
|
92
|
-
style=
|
|
93
|
-
placeholder=
|
|
93
|
+
class={['input input-bordered input-sm inline-input', ...(segment.interaction.interactionClasses ?? [])].join(' ')}
|
|
94
|
+
style={inputWidthCh ? `width: ${inputWidthCh}ch; display: inline-block; margin: 0 4px;` : `width: ${(segment.interaction.expectedLength ?? 15) * 8}px; min-width: 100px; display: inline-block; margin: 0 4px;`}
|
|
95
|
+
placeholder={segment.interaction.placeholderText || ''}
|
|
94
96
|
aria-label={`Text entry ${segment.interaction.responseId}`}
|
|
95
97
|
value={responses[segment.interaction.responseId] || ''}
|
|
96
98
|
oninput={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
|
|
97
99
|
/>
|
|
98
100
|
{:else if segment.type === 'inlineChoice'}
|
|
101
|
+
{@const inputWidthClass = (segment.interaction.interactionClasses ?? []).find((c: string) => c.startsWith('qti-input-width-'))}
|
|
102
|
+
{@const inputWidthCh = inputWidthClass ? parseInt(inputWidthClass.replace('qti-input-width-', ''), 10) : null}
|
|
103
|
+
{@const placeholder = segment.interaction.dataPrompt ?? segment.interaction.label ?? 'Select...'}
|
|
99
104
|
<select
|
|
100
|
-
class=
|
|
101
|
-
style=
|
|
105
|
+
class={['select select-bordered select-sm inline-select', ...(segment.interaction.interactionClasses ?? [])].join(' ')}
|
|
106
|
+
style={inputWidthCh ? `width: ${inputWidthCh}ch; display: inline-block; margin: 0 4px;` : `display: inline-block; margin: 0 4px; width: auto; min-width: 120px;`}
|
|
102
107
|
aria-label={`Inline choice ${segment.interaction.responseId}`}
|
|
103
108
|
value={responses[segment.interaction.responseId] || ''}
|
|
104
109
|
onchange={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
|
|
105
110
|
>
|
|
106
|
-
<option value="">
|
|
111
|
+
<option value="" disabled>{placeholder}</option>
|
|
107
112
|
{#each segment.interaction.choices as choice}
|
|
108
113
|
<option value={choice.identifier}>{choice.text}</option>
|
|
109
114
|
{/each}
|