|
| 1 | +<script lang="ts"> |
| 2 | + // @ts-expect-error - Svelte-check can't resolve workspace subpath exports, but runtime works correctly |
| 3 | + import { ItemBody } from '@pie-qti/item-player/components'; |
| 4 | + import { Player, type PnpProfile } from '@pie-qti/item-player'; |
| 5 | + import type { InteractionResponseValue } from '@pie-qti/item-player/web-components'; |
| 6 | + import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core'; |
| 7 | + import { registerDefaultComponents } from '@pie-qti/default-components'; |
| 8 | + import { onMount } from 'svelte'; |
| 9 | +
|
| 10 | + type FixtureResponseValue = InteractionResponseValue | null; |
| 11 | +
|
| 12 | + // Clean-room QTI 3 fixture authored for Stage 5 public accessibility evidence. |
| 13 | + // It exercises shared stimulus, scoped catalog lookup, PNP rebinding, and |
| 14 | + // answer-key non-disclosure without using official/private conformance assets. |
| 15 | + const qtiXml = `<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0" |
| 16 | + identifier="pnp-catalog-stimulus-a11y" title="PNP Catalog Stimulus A11y Fixture" |
| 17 | + adaptive="false" time-dependent="false"> |
| 18 | + <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string"> |
| 19 | + <qti-correct-response> |
| 20 | + <qti-value>braided delta</qti-value> |
| 21 | + </qti-correct-response> |
| 22 | + </qti-response-declaration> |
| 23 | + <qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float"/> |
| 24 | + <qti-assessment-stimulus-ref identifier="passage_1" href="../stimuli/river.xml" title="River passage"/> |
| 25 | + <qti-item-body> |
| 26 | + <p class="item-note" data-catalog-idref="item_term">Use the shared passage to answer the question.</p> |
| 27 | + <p> |
| 28 | + Name the river feature: |
| 29 | + <qti-text-entry-interaction response-identifier="RESPONSE" expected-length="16"/> |
| 30 | + </p> |
| 31 | + </qti-item-body> |
| 32 | + <qti-catalog-info> |
| 33 | + <qti-card identifier="item_term"> |
| 34 | + <qti-card-entry usage="glossary-on-screen"> |
| 35 | + <qti-html-content>Question instructions.</qti-html-content> |
| 36 | + </qti-card-entry> |
| 37 | + </qti-card> |
| 38 | + <qti-card identifier="term_delta"> |
| 39 | + <qti-card-entry usage="glossary-on-screen"> |
| 40 | + <qti-html-content>Item-local fallback definition.</qti-html-content> |
| 41 | + </qti-card-entry> |
| 42 | + </qti-card> |
| 43 | + </qti-catalog-info> |
| 44 | + </qti-assessment-item>`; |
| 45 | +
|
| 46 | + const deliveryContext: ResolvedItemDeliveryContext = { |
| 47 | + itemHref: 'items/item.xml', |
| 48 | + stimuli: { |
| 49 | + passage_1: { |
| 50 | + identifier: 'passage_1', |
| 51 | + href: '../stimuli/river.xml', |
| 52 | + resolvedHref: 'stimuli/river.xml', |
| 53 | + title: 'River passage', |
| 54 | + bodyHtml: `<section aria-label="Shared river passage"> |
| 55 | + <p> |
| 56 | + A <span class="stimulus-term" data-catalog-idref="term_delta">delta</span> |
| 57 | + forms where a river drops sediment. |
| 58 | + </p> |
| 59 | + </section>`, |
| 60 | + stylesheets: [], |
| 61 | + validationMessages: [], |
| 62 | + }, |
| 63 | + }, |
| 64 | + stylesheets: [ |
| 65 | + { |
| 66 | + href: 'item.css', |
| 67 | + xml: '<qti-stylesheet href="item.css"/>', |
| 68 | + resolvedHref: 'items/item.css', |
| 69 | + source: 'item', |
| 70 | + cssText: '.item-note { border-left: 4px solid currentColor; padding-left: 0.5rem; }', |
| 71 | + }, |
| 72 | + { |
| 73 | + href: 'stimulus.css', |
| 74 | + xml: '<qti-stylesheet href="stimulus.css"/>', |
| 75 | + resolvedHref: 'stimuli/stimulus.css', |
| 76 | + source: 'stimulus', |
| 77 | + stimulusIdentifier: 'passage_1', |
| 78 | + cssText: '.stimulus-term { text-decoration: underline; }', |
| 79 | + }, |
| 80 | + ], |
| 81 | + catalogSources: [ |
| 82 | + { |
| 83 | + scope: 'stimulus', |
| 84 | + baseHref: 'stimuli/river.xml', |
| 85 | + stimulusIdentifier: 'passage_1', |
| 86 | + xml: `<qti-catalog-info> |
| 87 | + <qti-card identifier="term_delta"> |
| 88 | + <qti-card-entry usage="glossary-on-screen"> |
| 89 | + <qti-html-content>Stimulus-scoped delta definition.</qti-html-content> |
| 90 | + </qti-card-entry> |
| 91 | + <qti-card-entry usage="tts-pronunciation" xml:lang="en"> |
| 92 | + <qti-html-content>DEL-tuh</qti-html-content> |
| 93 | + </qti-card-entry> |
| 94 | + </qti-card> |
| 95 | + </qti-catalog-info>`, |
| 96 | + }, |
| 97 | + ], |
| 98 | + validationMessages: [], |
| 99 | + }; |
| 100 | +
|
| 101 | + const initialPnp: PnpProfile = { |
| 102 | + content: { |
| 103 | + glossaryOnScreen: true, |
| 104 | + catalogSupports: { ttsPronunciation: { active: true, languageCode: 'en' } }, |
| 105 | + }, |
| 106 | + }; |
| 107 | +
|
| 108 | + let player = $state<Player | null>(null); |
| 109 | + let responses = $state<Record<string, FixtureResponseValue>>({ RESPONSE: null }); |
| 110 | + let glossaryEnabled = $state(true); |
| 111 | + let lastCatalogEvent = $state<string>('none'); |
| 112 | + let mounted = $state(false); |
| 113 | + let fixtureRoot: HTMLDivElement | null = $state(null); |
| 114 | +
|
| 115 | + onMount(() => { |
| 116 | + const newPlayer = new Player({ |
| 117 | + itemXml: qtiXml, |
| 118 | + role: 'candidate', |
| 119 | + pnp: initialPnp, |
| 120 | + deliveryContext, |
| 121 | + }); |
| 122 | + registerDefaultComponents(newPlayer.getComponentRegistry()); |
| 123 | + player = newPlayer; |
| 124 | + mounted = true; |
| 125 | + }); |
| 126 | +
|
| 127 | + function toggleGlossary() { |
| 128 | + glossaryEnabled = !glossaryEnabled; |
| 129 | + player?.updatePnp({ content: { glossaryOnScreen: glossaryEnabled } }); |
| 130 | + } |
| 131 | +
|
| 132 | + $effect(() => { |
| 133 | + if (!fixtureRoot) return; |
| 134 | + const handler = (event: Event) => handleCatalogLookup(event as CustomEvent); |
| 135 | + const el = fixtureRoot; |
| 136 | + el.addEventListener('qti-catalog-lookup', handler); |
| 137 | + return () => el.removeEventListener('qti-catalog-lookup', handler); |
| 138 | + }); |
| 139 | +
|
| 140 | + function handleCatalogLookup(event: CustomEvent) { |
| 141 | + const detail = event.detail ?? {}; |
| 142 | + lastCatalogEvent = `${detail.usage ?? 'unknown'}:${detail.html ?? ''}`; |
| 143 | + } |
| 144 | +</script> |
| 145 | + |
| 146 | +<div bind:this={fixtureRoot} class="space-y-4"> |
| 147 | + <p class="text-sm text-base-content/70"> |
| 148 | + Fixture for shared stimulus rendering, dynamic PNP catalog supports, keyboard focus behavior, |
| 149 | + host catalog events, and scoped stylesheet isolation. |
| 150 | + </p> |
| 151 | + |
| 152 | + <div class="flex flex-wrap gap-2"> |
| 153 | + <button type="button" class="btn btn-sm" onclick={toggleGlossary}> |
| 154 | + {glossaryEnabled ? 'Disable glossary support' : 'Enable glossary support'} |
| 155 | + </button> |
| 156 | + <div role="status" aria-live="polite" data-testid="catalog-event-status"> |
| 157 | + Last catalog event: {lastCatalogEvent} |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + |
| 161 | + {#if mounted && player} |
| 162 | + <div class="qti-item-player"> |
| 163 | + <ItemBody |
| 164 | + {player} |
| 165 | + {responses} |
| 166 | + disabled={false} |
| 167 | + onResponseChange={(id: string, value: FixtureResponseValue) => (responses = { ...responses, [id]: value })} |
| 168 | + /> |
| 169 | + </div> |
| 170 | + {/if} |
| 171 | +</div> |
0 commit comments