@pie-qti/item-player 0.1.9 → 0.1.10
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/README.md +17 -0
- package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
- package/dist/catalog/glossaryAction.d.ts +4 -2
- package/dist/catalog/glossaryAction.d.ts.map +1 -1
- package/dist/components/utils/index.d.ts +1 -2
- package/dist/components/utils/index.d.ts.map +1 -1
- package/dist/components/utils/index.js +1 -2
- package/dist/core/ComponentRegistry.d.ts +10 -1
- package/dist/core/ComponentRegistry.d.ts.map +1 -1
- package/dist/core/ComponentRegistry.js +42 -1
- package/dist/core/Player.d.ts +10 -2
- package/dist/core/Player.d.ts.map +1 -1
- package/dist/core/Player.js +54 -46
- package/dist/document/AssessmentItemDocument.d.ts +1 -1
- package/dist/element.d.ts +15 -0
- package/dist/element.js +1817 -1625
- package/dist/element.js.map +1 -1
- package/dist/extraction/ExtractionRegistry.d.ts +1 -1
- package/dist/extraction/createContext.d.ts +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
- package/dist/extraction/interactionSecurity.d.ts +1 -1
- package/dist/extraction/types.d.ts +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +54 -0
- package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
- package/dist/presentation/itemPresentationPlan.js +98 -0
- package/dist/types/index.d.ts +17 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -3
- package/dist/web-components/QTIInteractionBase.d.ts +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +1 -1
- package/package.json +7 -14
- package/src/__tests__/catalog.test.ts +0 -267
- package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
- package/src/__tests__/pci.test.ts +0 -353
- package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
- package/src/__tests__/qti3-debug.test.ts +0 -140
- package/src/__tests__/qti3-extraction.test.ts +0 -309
- package/src/catalog/applyGlossaryTriggers.ts +0 -372
- package/src/catalog/catalogExtractor.ts +0 -130
- package/src/catalog/catalogLookup.ts +0 -53
- package/src/catalog/glossaryAction.ts +0 -38
- package/src/catalog/types.ts +0 -37
- package/src/components/ItemBody.svelte +0 -363
- package/src/components/ItemPlayer.svelte +0 -163
- package/src/components/ModalFeedbackDisplay.svelte +0 -97
- package/src/components/actions/typesetAction.ts +0 -74
- package/src/components/index.ts +0 -22
- package/src/components/utils/assignProps.ts +0 -2
- package/src/components/utils/feedbackUtils.ts +0 -140
- package/src/components/utils/index.ts +0 -13
- package/src/components/utils/stimulusRender.ts +0 -93
- package/src/components/utils/stylesheetRender.ts +0 -58
- package/src/core/ComponentRegistry.ts +0 -248
- package/src/core/Player.ts +0 -1618
- package/src/core/Plugin.ts +0 -123
- package/src/core/PluginManager.ts +0 -182
- package/src/core/constants.ts +0 -117
- package/src/core/declarations.ts +0 -171
- package/src/core/parsingLimits.ts +0 -62
- package/src/core/random.ts +0 -24
- package/src/core/rolePolicy.ts +0 -34
- package/src/core/sanitizer.ts +0 -305
- package/src/core/trustedTypes.ts +0 -63
- package/src/core/urlPolicy.ts +0 -98
- package/src/document/AssessmentItemDocument.ts +0 -247
- package/src/element.ts +0 -128
- package/src/extensions/MathLiveEditor.ts +0 -313
- package/src/extraction/ExtractionRegistry.ts +0 -335
- package/src/extraction/createContext.ts +0 -52
- package/src/extraction/extractors/associateExtractor.ts +0 -1
- package/src/extraction/extractors/choiceExtractor.ts +0 -1
- package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
- package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
- package/src/extraction/extractors/conformance.test.ts +0 -208
- package/src/extraction/extractors/customExtractor.ts +0 -1
- package/src/extraction/extractors/drawingExtractor.ts +0 -1
- package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
- package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
- package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
- package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
- package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
- package/src/extraction/extractors/hotspotExtractor.ts +0 -1
- package/src/extraction/extractors/hottextExtractor.ts +0 -1
- package/src/extraction/extractors/index.ts +0 -9
- package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
- package/src/extraction/extractors/matchExtractor.ts +0 -1
- package/src/extraction/extractors/mediaExtractor.ts +0 -1
- package/src/extraction/extractors/orderExtractor.ts +0 -1
- package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
- package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
- package/src/extraction/extractors/selectPointExtractor.ts +0 -1
- package/src/extraction/extractors/sliderExtractor.ts +0 -1
- package/src/extraction/extractors/textEntryExtractor.ts +0 -1
- package/src/extraction/extractors/uploadExtractor.ts +0 -1
- package/src/extraction/index.ts +0 -108
- package/src/extraction/interactionExtractionPipeline.ts +0 -70
- package/src/extraction/interactionSecurity.ts +0 -60
- package/src/extraction/types.ts +0 -246
- package/src/extraction/utils.ts +0 -243
- package/src/iframe/IFramePlayerHost.ts +0 -265
- package/src/iframe/index.ts +0 -11
- package/src/iframe/protocol.ts +0 -137
- package/src/index.ts +0 -101
- package/src/interactions/associate/extractor.ts +0 -133
- package/src/interactions/associate/index.ts +0 -2
- package/src/interactions/associate/types.ts +0 -1
- package/src/interactions/choice/extractor.ts +0 -121
- package/src/interactions/choice/index.ts +0 -2
- package/src/interactions/choice/types.ts +0 -1
- package/src/interactions/custom/extractor.ts +0 -72
- package/src/interactions/custom/index.ts +0 -2
- package/src/interactions/custom/types.ts +0 -1
- package/src/interactions/drawing/extractor.ts +0 -113
- package/src/interactions/drawing/index.ts +0 -2
- package/src/interactions/drawing/types.ts +0 -1
- package/src/interactions/end-attempt/extractor.ts +0 -74
- package/src/interactions/end-attempt/index.ts +0 -2
- package/src/interactions/end-attempt/types.ts +0 -1
- package/src/interactions/extended-text/extractor.ts +0 -92
- package/src/interactions/extended-text/index.ts +0 -2
- package/src/interactions/extended-text/types.ts +0 -1
- package/src/interactions/gap-match/extractor.ts +0 -193
- package/src/interactions/gap-match/index.ts +0 -2
- package/src/interactions/gap-match/types.ts +0 -1
- package/src/interactions/graphic-associate/extractor.ts +0 -192
- package/src/interactions/graphic-associate/index.ts +0 -2
- package/src/interactions/graphic-associate/types.ts +0 -1
- package/src/interactions/graphic-gap-match/extractor.ts +0 -257
- package/src/interactions/graphic-gap-match/index.ts +0 -2
- package/src/interactions/graphic-gap-match/types.ts +0 -1
- package/src/interactions/graphic-order/extractor.ts +0 -162
- package/src/interactions/graphic-order/index.ts +0 -2
- package/src/interactions/graphic-order/types.ts +0 -1
- package/src/interactions/hotspot/extractor.ts +0 -208
- package/src/interactions/hotspot/index.ts +0 -2
- package/src/interactions/hotspot/types.ts +0 -1
- package/src/interactions/hottext/extractor.ts +0 -163
- package/src/interactions/hottext/index.ts +0 -2
- package/src/interactions/hottext/types.ts +0 -1
- package/src/interactions/index.ts +0 -52
- package/src/interactions/inline/index.ts +0 -1
- package/src/interactions/inline/render-plan.ts +0 -105
- package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
- package/src/interactions/inline-choice/extractor.ts +0 -105
- package/src/interactions/inline-choice/index.ts +0 -2
- package/src/interactions/inline-choice/types.ts +0 -1
- package/src/interactions/match/extractor.ts +0 -187
- package/src/interactions/match/index.ts +0 -2
- package/src/interactions/match/types.ts +0 -1
- package/src/interactions/media/extractor.ts +0 -168
- package/src/interactions/media/index.ts +0 -2
- package/src/interactions/media/types.ts +0 -1
- package/src/interactions/modules.ts +0 -111
- package/src/interactions/order/extractor.ts +0 -120
- package/src/interactions/order/index.ts +0 -2
- package/src/interactions/order/types.ts +0 -1
- package/src/interactions/portable-custom/extractor.ts +0 -122
- package/src/interactions/portable-custom/index.ts +0 -2
- package/src/interactions/portable-custom/types.ts +0 -1
- package/src/interactions/position-object/extractor.ts +0 -243
- package/src/interactions/position-object/index.ts +0 -2
- package/src/interactions/position-object/types.ts +0 -1
- package/src/interactions/select-point/extractor.ts +0 -143
- package/src/interactions/select-point/index.ts +0 -2
- package/src/interactions/select-point/types.ts +0 -1
- package/src/interactions/shared/index.ts +0 -1
- package/src/interactions/shared/types.ts +0 -430
- package/src/interactions/slider/extractor.ts +0 -102
- package/src/interactions/slider/index.ts +0 -2
- package/src/interactions/slider/types.ts +0 -1
- package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
- package/src/interactions/text-entry/extractor.ts +0 -79
- package/src/interactions/text-entry/index.ts +0 -2
- package/src/interactions/text-entry/types.ts +0 -1
- package/src/interactions/upload/extractor.ts +0 -81
- package/src/interactions/upload/index.ts +0 -2
- package/src/interactions/upload/types.ts +0 -1
- package/src/pci/PciHost.ts +0 -138
- package/src/pci/types.ts +0 -70
- package/src/pnp/applyPnp.ts +0 -29
- package/src/pnp/parsePnpXml.ts +0 -215
- package/src/pnp/types.ts +0 -75
- package/src/server.ts +0 -14
- package/src/types/index.ts +0 -388
- package/src/types/interactions.ts +0 -8
- package/src/types/responseValidation.ts +0 -29
- package/src/types/xmldom.d.ts +0 -12
- package/src/utils/PerformanceMonitor.ts +0 -335
- package/src/utils/drawingUtils.ts +0 -73
- package/src/utils/responseUtils.ts +0 -51
- package/src/utils/touchDragHelper.ts +0 -1
- package/src/web-components/QTIInteractionBase.ts +0 -303
- package/src/web-components/QTIInteractionElement.ts +0 -125
- package/src/web-components/index.ts +0 -22
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
let nextItemBodyScopeId = 0;
|
|
3
|
-
</script>
|
|
4
|
-
|
|
5
|
-
<script lang="ts">
|
|
6
|
-
import type { InteractionData } from '../types';
|
|
7
|
-
import type { Player } from '../core/Player';
|
|
8
|
-
import type { InteractionResponseValue, QTIChangeEventDetail } from '../web-components';
|
|
9
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
10
|
-
import {
|
|
11
|
-
normalizeHeuristicsConfig,
|
|
12
|
-
type QtiHeuristicsConfig,
|
|
13
|
-
type ResolvedItemDeliveryContext
|
|
14
|
-
} from '@pie-qti/ims-cp-core';
|
|
15
|
-
import { processFeedbackInline } from './utils/feedbackUtils';
|
|
16
|
-
import { typesetAction } from './actions/typesetAction';
|
|
17
|
-
import { glossaryAction } from '../catalog/glossaryAction';
|
|
18
|
-
import { assignProps } from './utils/assignProps';
|
|
19
|
-
import { buildScopedStylesheetCss } from './utils/stylesheetRender';
|
|
20
|
-
import { buildEffectiveStimulusContent, injectStimulusContent } from './utils/stimulusRender';
|
|
21
|
-
import { getRoleCapabilities } from '../core/rolePolicy';
|
|
22
|
-
import InlineChoice from '../interactions/inline-choice/InlineChoice.svelte';
|
|
23
|
-
import InlineTextEntry from '../interactions/text-entry/InlineTextEntry.svelte';
|
|
24
|
-
import { createInlineRenderPlan, isInlineInteractionTagName, isInlineInteractionType } from '../interactions/inline/render-plan';
|
|
25
|
-
|
|
26
|
-
type ItemResponseValue = InteractionResponseValue | null;
|
|
27
|
-
type ItemResponseMap = Record<string, ItemResponseValue>;
|
|
28
|
-
type QtiChangeDomEvent = CustomEvent<QTIChangeEventDetail<ItemResponseValue>>;
|
|
29
|
-
|
|
30
|
-
interface Props {
|
|
31
|
-
player: Player;
|
|
32
|
-
responses?: ItemResponseMap;
|
|
33
|
-
disabled?: boolean;
|
|
34
|
-
role?: 'candidate' | 'scorer' | 'author' | 'tutor' | 'proctor' | 'testConstructor';
|
|
35
|
-
i18n?: I18nProvider;
|
|
36
|
-
typeset?: (element: HTMLElement) => void;
|
|
37
|
-
onResponseChange?: (responseId: string, value: ItemResponseValue) => void;
|
|
38
|
-
outcomeValues?: Record<string, any>; // Needed for feedbackInline visibility
|
|
39
|
-
heuristicsConfig?: QtiHeuristicsConfig; // Optional heuristics configuration
|
|
40
|
-
/** QTI 3.0 shared stimulus content: map of stimulus identifier → HTML string */
|
|
41
|
-
stimulusContent?: Record<string, string>;
|
|
42
|
-
/** Package/assessment-resolved QTI 3 delivery context. */
|
|
43
|
-
deliveryContext?: ResolvedItemDeliveryContext;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let {
|
|
47
|
-
player,
|
|
48
|
-
responses = {},
|
|
49
|
-
disabled = false,
|
|
50
|
-
role = 'candidate',
|
|
51
|
-
i18n,
|
|
52
|
-
typeset,
|
|
53
|
-
onResponseChange = () => {},
|
|
54
|
-
outcomeValues = {},
|
|
55
|
-
heuristicsConfig,
|
|
56
|
-
stimulusContent = {},
|
|
57
|
-
deliveryContext,
|
|
58
|
-
}: Props = $props();
|
|
59
|
-
const itemBodyScope = `qti-item-body-${++nextItemBodyScopeId}`;
|
|
60
|
-
const itemBodyScopeSelector = `[data-qti-item-body-scope="${itemBodyScope}"]`;
|
|
61
|
-
|
|
62
|
-
// Normalize heuristics configuration with defaults
|
|
63
|
-
const heuristics = $derived(normalizeHeuristicsConfig(heuristicsConfig));
|
|
64
|
-
|
|
65
|
-
// Get the component registry from the player
|
|
66
|
-
const componentRegistry = $derived(player.getComponentRegistry());
|
|
67
|
-
const roleCapabilities = $derived(getRoleCapabilities(role));
|
|
68
|
-
const effectiveDisabled = $derived(disabled || roleCapabilities.isReadOnly);
|
|
69
|
-
|
|
70
|
-
// Process interactions
|
|
71
|
-
const interactions = $derived<InteractionData[]>(player.getInteractionData());
|
|
72
|
-
|
|
73
|
-
// Get correct responses for roles allowed by policy.
|
|
74
|
-
const correctResponses = $derived.by(() => {
|
|
75
|
-
return roleCapabilities.canViewCorrectResponses ? player.getCorrectResponses() : {};
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Get components for block-level interactions only (not inline interactions).
|
|
79
|
-
// Type is always normalized to QTI 2.x camelCase by Player (qti-text-entry-interaction → textEntryInteraction).
|
|
80
|
-
const interactionComponents = $derived(
|
|
81
|
-
interactions
|
|
82
|
-
.filter(
|
|
83
|
-
(interaction) =>
|
|
84
|
-
!isInlineInteractionType(interaction.type)
|
|
85
|
-
)
|
|
86
|
-
.map((interaction) => {
|
|
87
|
-
try {
|
|
88
|
-
// Get the web component tag name from the registry
|
|
89
|
-
const tagName = componentRegistry.getTagName(interaction);
|
|
90
|
-
return {
|
|
91
|
-
interaction,
|
|
92
|
-
tagName,
|
|
93
|
-
};
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.error(`Failed to get tag name for ${interaction.type}:`, error);
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.filter((item): item is NonNullable<typeof item> => item !== null)
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// Get item body HTML and process interactions
|
|
103
|
-
// Block interactions are kept in HTML but wrapped with a hidden marker (see styles below)
|
|
104
|
-
// Inline interactions are replaced with placeholders
|
|
105
|
-
const itemBodyHtml = $derived.by(() => {
|
|
106
|
-
let html = player.getItemBodyHtml();
|
|
107
|
-
const resolvedDeliveryContext = deliveryContext ?? player.getDeliveryContext();
|
|
108
|
-
const stylesheetCss = buildScopedStylesheetCss(resolvedDeliveryContext, itemBodyScopeSelector);
|
|
109
|
-
const effectiveStimulusContent = buildEffectiveStimulusContent(
|
|
110
|
-
resolvedDeliveryContext,
|
|
111
|
-
stimulusContent,
|
|
112
|
-
(content) => player.sanitizeHtmlContent(content)
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
html = injectStimulusContent(html, effectiveStimulusContent);
|
|
116
|
-
if (stylesheetCss) {
|
|
117
|
-
html = `<style data-qti-stylesheets="resolved">${stylesheetCss}</style>${html}`;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Process feedbackInline elements - conditionally show/hide based on outcome values
|
|
121
|
-
html = processFeedbackInline(html, {
|
|
122
|
-
outcomeValues,
|
|
123
|
-
applyHeuristics: heuristics.feedbackTextFormatting,
|
|
124
|
-
wrapWithSpan: false
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Wrap all block-level interaction elements with a hidden marker.
|
|
128
|
-
// Matches both QTI 2.x camelCase (*Interaction) and QTI 3.0 kebab-case (qti-*-interaction).
|
|
129
|
-
html = html.replace(
|
|
130
|
-
/<(\w+Interaction|qti-[\w-]+-interaction)(\s[^>]*)?>[\s\S]*?<\/\1>/gi,
|
|
131
|
-
(match, tagName) => {
|
|
132
|
-
const lower = tagName.toLowerCase();
|
|
133
|
-
// Inline interactions are rendered in-flow by the inline render plan.
|
|
134
|
-
if (isInlineInteractionTagName(lower)) {
|
|
135
|
-
return match;
|
|
136
|
-
}
|
|
137
|
-
// Wrap block interactions with a hidden span
|
|
138
|
-
return `<span class="qti-hidden-interaction">${match}</span>`;
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
return html;
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const inlineSegments = $derived(createInlineRenderPlan(itemBodyHtml, interactions));
|
|
146
|
-
|
|
147
|
-
function getStringResponse(responseId: string): string {
|
|
148
|
-
const response = responses[responseId];
|
|
149
|
-
return typeof response === 'string' ? response : '';
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function handleResponseChange(responseId: string, value: ItemResponseValue) {
|
|
153
|
-
onResponseChange(responseId, value);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Handle qti:change events from web components
|
|
157
|
-
function handleQtiChange(event: QtiChangeDomEvent) {
|
|
158
|
-
const { responseId, value } = event.detail;
|
|
159
|
-
handleResponseChange(responseId, value);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// In runes mode, prefer explicit DOM listener wiring to avoid edge cases with
|
|
163
|
-
// custom events bubbling out of shadow DOM (and to keep typing sane for dynamic elements).
|
|
164
|
-
let rootEl: HTMLDivElement | null = $state(null);
|
|
165
|
-
$effect(() => {
|
|
166
|
-
if (!rootEl) return;
|
|
167
|
-
player.applyPnp(rootEl);
|
|
168
|
-
const handler = (e: Event) => handleQtiChange(e as QtiChangeDomEvent);
|
|
169
|
-
const el = rootEl; // Capture reference for cleanup
|
|
170
|
-
el.addEventListener('qti-change', handler as EventListener);
|
|
171
|
-
return () => {
|
|
172
|
-
el.removeEventListener('qti-change', handler as EventListener);
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Ensure web-component instances are not accidentally reused across items when
|
|
177
|
-
// different items share the same responseId (common in QTI demos: "RESPONSE").
|
|
178
|
-
function interactionKey(interaction: InteractionData): string {
|
|
179
|
-
const anyInteraction = interaction as any;
|
|
180
|
-
const ids =
|
|
181
|
-
Array.isArray(anyInteraction?.choices) && anyInteraction.choices.length > 0
|
|
182
|
-
? anyInteraction.choices.map((c: any) => c?.identifier).filter(Boolean).join(',')
|
|
183
|
-
: '';
|
|
184
|
-
// Include prompt if present to further reduce accidental reuse.
|
|
185
|
-
const prompt = typeof anyInteraction?.prompt === 'string' ? anyInteraction.prompt : '';
|
|
186
|
-
return `${interaction.type}|${interaction.responseId}|${ids}|${prompt}`;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Action to set typeset and i18n on web components when they mount
|
|
190
|
-
function setWebComponentProps(
|
|
191
|
-
node: HTMLElement,
|
|
192
|
-
params: {
|
|
193
|
-
i18n?: I18nProvider;
|
|
194
|
-
typeset?: (el: HTMLElement) => void;
|
|
195
|
-
[key: string]: unknown;
|
|
196
|
-
}
|
|
197
|
-
) {
|
|
198
|
-
// Use microtask to ensure custom element is fully initialized
|
|
199
|
-
queueMicrotask(() => {
|
|
200
|
-
if (!node) return;
|
|
201
|
-
assignProps(node, params);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
update(
|
|
206
|
-
newParams: {
|
|
207
|
-
i18n?: I18nProvider;
|
|
208
|
-
typeset?: (el: HTMLElement) => void;
|
|
209
|
-
[key: string]: unknown;
|
|
210
|
-
}
|
|
211
|
-
) {
|
|
212
|
-
assignProps(node, newParams);
|
|
213
|
-
},
|
|
214
|
-
destroy() {}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
</script>
|
|
218
|
-
|
|
219
|
-
<div
|
|
220
|
-
bind:this={rootEl}
|
|
221
|
-
class="qti-item-body"
|
|
222
|
-
data-qti-item-body-scope={itemBodyScope}
|
|
223
|
-
use:typesetAction={{ typeset }}
|
|
224
|
-
use:glossaryAction={{ player }}
|
|
225
|
-
>
|
|
226
|
-
<!-- Item body with inline interactions -->
|
|
227
|
-
<div class="prose max-w-none mb-4">
|
|
228
|
-
<div class="inline-interaction-container">
|
|
229
|
-
{#each inlineSegments as segment}
|
|
230
|
-
{#if segment.type === 'html'}
|
|
231
|
-
{@html segment.content}
|
|
232
|
-
{:else if segment.type === 'textEntry'}
|
|
233
|
-
{@const correctAnswer = roleCapabilities.canViewCorrectResponses ? (correctResponses[segment.interaction.responseId] ?? null) : null}
|
|
234
|
-
<InlineTextEntry
|
|
235
|
-
interaction={segment.interaction}
|
|
236
|
-
response={getStringResponse(segment.interaction.responseId)}
|
|
237
|
-
correctAnswer={roleCapabilities.canViewCorrectResponses ? correctAnswer : null}
|
|
238
|
-
disabled={effectiveDisabled}
|
|
239
|
-
{i18n}
|
|
240
|
-
onResponseChange={handleResponseChange}
|
|
241
|
-
/>
|
|
242
|
-
{:else if segment.type === 'inlineChoice'}
|
|
243
|
-
{@const correctAnswer = roleCapabilities.canViewCorrectResponses ? (correctResponses[segment.interaction.responseId] ?? null) : null}
|
|
244
|
-
<InlineChoice
|
|
245
|
-
interaction={segment.interaction}
|
|
246
|
-
response={getStringResponse(segment.interaction.responseId)}
|
|
247
|
-
correctAnswer={roleCapabilities.canViewCorrectResponses ? correctAnswer : null}
|
|
248
|
-
disabled={effectiveDisabled}
|
|
249
|
-
{i18n}
|
|
250
|
-
onResponseChange={handleResponseChange}
|
|
251
|
-
/>
|
|
252
|
-
{/if}
|
|
253
|
-
{/each}
|
|
254
|
-
</div>
|
|
255
|
-
</div>
|
|
256
|
-
|
|
257
|
-
<!-- Block interactions rendered dynamically as web components -->
|
|
258
|
-
{#each interactionComponents as { interaction, tagName } (interactionKey(interaction))}
|
|
259
|
-
{@const correctRespForInteraction = correctResponses[interaction.responseId] ?? null}
|
|
260
|
-
<svelte:element
|
|
261
|
-
this={tagName}
|
|
262
|
-
use:setWebComponentProps={{
|
|
263
|
-
i18n,
|
|
264
|
-
typeset,
|
|
265
|
-
interaction,
|
|
266
|
-
response: responses[interaction.responseId] ?? null,
|
|
267
|
-
correctResponse: roleCapabilities.canViewCorrectResponses ? correctRespForInteraction : null,
|
|
268
|
-
pnp: player.getPnp(),
|
|
269
|
-
eliminationTool: player.getPnp()?.cognitive?.eliminationTool === true,
|
|
270
|
-
disabled: effectiveDisabled,
|
|
271
|
-
// Avoid invalid ARIA role values on custom-element hosts.
|
|
272
|
-
// Components default to candidate when role is omitted.
|
|
273
|
-
role: roleCapabilities.canViewCorrectResponses ? 'scorer' : undefined,
|
|
274
|
-
}}
|
|
275
|
-
/>
|
|
276
|
-
{/each}
|
|
277
|
-
</div>
|
|
278
|
-
|
|
279
|
-
<style>
|
|
280
|
-
/* Allow the whole item body to shrink inside flex/grid layouts (prevents overflow). */
|
|
281
|
-
.qti-item-body {
|
|
282
|
-
max-width: 100%;
|
|
283
|
-
min-width: 0;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/*
|
|
287
|
-
* Custom elements default to inline; force them to be block-level and width-contained.
|
|
288
|
-
* This prevents wide interactions (SVGs, tables, canvases) from spilling outside panels.
|
|
289
|
-
*/
|
|
290
|
-
:global(.qti-item-body :is(
|
|
291
|
-
pie-qti-choice,
|
|
292
|
-
pie-qti-slider,
|
|
293
|
-
pie-qti-order,
|
|
294
|
-
pie-qti-match,
|
|
295
|
-
pie-qti-associate,
|
|
296
|
-
pie-qti-gap-match,
|
|
297
|
-
pie-qti-hotspot,
|
|
298
|
-
pie-qti-hottext,
|
|
299
|
-
pie-qti-media,
|
|
300
|
-
pie-qti-custom,
|
|
301
|
-
pie-qti-end-attempt,
|
|
302
|
-
pie-qti-position-object,
|
|
303
|
-
pie-qti-graphic-gap-match,
|
|
304
|
-
pie-qti-graphic-order,
|
|
305
|
-
pie-qti-graphic-associate,
|
|
306
|
-
pie-qti-select-point,
|
|
307
|
-
pie-qti-extended-text
|
|
308
|
-
)) {
|
|
309
|
-
display: block;
|
|
310
|
-
max-width: 100%;
|
|
311
|
-
min-width: 0;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/* Keep inline interactions from breaking paragraph flow */
|
|
315
|
-
.inline-interaction-container :global(p) {
|
|
316
|
-
display: inline;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/*
|
|
320
|
-
* Hide all QTI interaction elements wrapped with qti-hidden-interaction.
|
|
321
|
-
* These are rendered separately as web components above.
|
|
322
|
-
* Keeping them in the HTML (but hidden) makes debugging easier and is fully extensible.
|
|
323
|
-
* Any *Interaction element will be automatically wrapped and hidden - no hardcoded list needed!
|
|
324
|
-
*/
|
|
325
|
-
:global(.qti-item-body .qti-hidden-interaction) {
|
|
326
|
-
display: none !important;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/*
|
|
330
|
-
* Style for inline feedback elements that appear within choice text or other content.
|
|
331
|
-
* Provides visual distinction and spacing for feedback that appears inline with content.
|
|
332
|
-
*/
|
|
333
|
-
:global(.qti-feedback-inline) {
|
|
334
|
-
display: inline-block;
|
|
335
|
-
margin-left: 0.5rem;
|
|
336
|
-
padding-left: 0.5rem;
|
|
337
|
-
border-left: 2px solid var(--color-base-content, currentColor);
|
|
338
|
-
opacity: 0.8;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/* QTI 3.0 Shared Stimulus: stimulus blocks that were prepended before the item body */
|
|
342
|
-
:global(.qti-stimulus-block) {
|
|
343
|
-
margin-bottom: 1rem;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/* QTI 3.0 Shared Vocabulary: qti-input-width-N sets minimum input width in character units. */
|
|
347
|
-
:global(.qti-input-width-1) { min-width: 1ch; }
|
|
348
|
-
:global(.qti-input-width-2) { min-width: 2ch; }
|
|
349
|
-
:global(.qti-input-width-3) { min-width: 3ch; }
|
|
350
|
-
:global(.qti-input-width-4) { min-width: 4ch; }
|
|
351
|
-
:global(.qti-input-width-5) { min-width: 5ch; }
|
|
352
|
-
:global(.qti-input-width-6) { min-width: 6ch; }
|
|
353
|
-
:global(.qti-input-width-10) { min-width: 10ch; }
|
|
354
|
-
:global(.qti-input-width-15) { min-width: 15ch; }
|
|
355
|
-
:global(.qti-input-width-20) { min-width: 20ch; }
|
|
356
|
-
:global(.qti-input-width-25) { min-width: 25ch; }
|
|
357
|
-
:global(.qti-input-width-30) { min-width: 30ch; }
|
|
358
|
-
:global(.qti-input-width-35) { min-width: 35ch; }
|
|
359
|
-
:global(.qti-input-width-40) { min-width: 40ch; }
|
|
360
|
-
:global(.qti-input-width-45) { min-width: 45ch; }
|
|
361
|
-
:global(.qti-input-width-50) { min-width: 50ch; }
|
|
362
|
-
:global(.qti-input-width-72) { min-width: 72ch; }
|
|
363
|
-
</style>
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { Player } from '../core/Player';
|
|
3
|
-
import type { AdaptiveAttemptResult, ModalFeedback, PlayerSecurityConfig, QTIRole, ScoringResult } from '../types';
|
|
4
|
-
import type { InteractionResponseValue } from '../web-components';
|
|
5
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
-
import { typesetMathInElement } from '@pie-qti/typeset-katex';
|
|
7
|
-
import ItemBody from './ItemBody.svelte';
|
|
8
|
-
import ModalFeedbackDisplay from './ModalFeedbackDisplay.svelte';
|
|
9
|
-
|
|
10
|
-
type ItemResponseValue = InteractionResponseValue | null;
|
|
11
|
-
type ItemResponseMap = Record<string, ItemResponseValue>;
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
itemXml: string;
|
|
15
|
-
role?: QTIRole;
|
|
16
|
-
/** Optional security config (URL policy, embed allowances, Trusted Types). */
|
|
17
|
-
security?: PlayerSecurityConfig;
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
typeset?: (element: HTMLElement) => void;
|
|
20
|
-
i18n?: I18nProvider;
|
|
21
|
-
onResponseChange?: (responseId: string, value: ItemResponseValue) => void;
|
|
22
|
-
onSubmit?: (responses: ItemResponseMap, scoringResult: ScoringResult) => void;
|
|
23
|
-
/** Called when adaptive item completes (all attempts exhausted) */
|
|
24
|
-
onComplete?: (finalResult: AdaptiveAttemptResult) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let {
|
|
28
|
-
itemXml,
|
|
29
|
-
role = 'candidate',
|
|
30
|
-
security,
|
|
31
|
-
disabled = false,
|
|
32
|
-
typeset,
|
|
33
|
-
i18n,
|
|
34
|
-
onResponseChange,
|
|
35
|
-
onSubmit,
|
|
36
|
-
onComplete,
|
|
37
|
-
}: Props = $props();
|
|
38
|
-
|
|
39
|
-
// Use host-provided typeset if given, otherwise fall back to the built-in KaTeX typesetter.
|
|
40
|
-
const effectiveTypeset = $derived(typeset ?? typesetMathInElement);
|
|
41
|
-
|
|
42
|
-
// Create player instance
|
|
43
|
-
let player = $state<Player | null>(null);
|
|
44
|
-
let responses = $state<ItemResponseMap>({});
|
|
45
|
-
let error = $state<string | null>(null);
|
|
46
|
-
let modalFeedback = $state<ModalFeedback[]>([]);
|
|
47
|
-
let outcomeValues = $state<Record<string, any>>({});
|
|
48
|
-
let isAdaptive = $state(false);
|
|
49
|
-
let isCompleted = $state(false);
|
|
50
|
-
let numAttempts = $state(0);
|
|
51
|
-
|
|
52
|
-
// Initialize player when XML changes
|
|
53
|
-
$effect(() => {
|
|
54
|
-
try {
|
|
55
|
-
player = new Player({ itemXml, role, security });
|
|
56
|
-
error = null;
|
|
57
|
-
// Reset state when XML changes
|
|
58
|
-
responses = {};
|
|
59
|
-
modalFeedback = [];
|
|
60
|
-
outcomeValues = {};
|
|
61
|
-
isAdaptive = player.isAdaptive();
|
|
62
|
-
isCompleted = player.isCompleted();
|
|
63
|
-
numAttempts = player.getNumAttempts();
|
|
64
|
-
} catch (e) {
|
|
65
|
-
error = e instanceof Error ? e.message : (i18n?.t('item.parsingError') ?? 'item.parsingError');
|
|
66
|
-
player = null;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
function handleResponseChange(responseId: string, value: ItemResponseValue) {
|
|
71
|
-
responses = { ...responses, [responseId]: value };
|
|
72
|
-
onResponseChange?.(responseId, value);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function handleSubmit(countAttempt: boolean = true) {
|
|
76
|
-
if (!player) return;
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
// Set responses in player
|
|
80
|
-
player.setResponses(responses);
|
|
81
|
-
|
|
82
|
-
// For adaptive items, use submitAttempt()
|
|
83
|
-
if (isAdaptive && !isCompleted) {
|
|
84
|
-
const result = player.submitAttempt(countAttempt);
|
|
85
|
-
|
|
86
|
-
// Update state
|
|
87
|
-
numAttempts = result.numAttempts;
|
|
88
|
-
isCompleted = result.completed;
|
|
89
|
-
modalFeedback = result.modalFeedback || [];
|
|
90
|
-
outcomeValues = result.outcomeValues || {};
|
|
91
|
-
|
|
92
|
-
// Notify parent
|
|
93
|
-
onSubmit?.(responses, result);
|
|
94
|
-
|
|
95
|
-
// If completed, notify parent
|
|
96
|
-
if (result.completed && onComplete) {
|
|
97
|
-
onComplete(result);
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
// Non-adaptive item: use standard processResponses()
|
|
101
|
-
const result = player.processResponses();
|
|
102
|
-
modalFeedback = result.modalFeedback || [];
|
|
103
|
-
outcomeValues = result.outcomeValues || {};
|
|
104
|
-
onSubmit?.(responses, result);
|
|
105
|
-
}
|
|
106
|
-
} catch (e) {
|
|
107
|
-
error = e instanceof Error ? e.message : (i18n?.t('item.processingError') ?? 'item.processingError');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function closeFeedback() {
|
|
112
|
-
modalFeedback = [];
|
|
113
|
-
}
|
|
114
|
-
</script>
|
|
115
|
-
|
|
116
|
-
<div class="qti-item-player">
|
|
117
|
-
{#if error}
|
|
118
|
-
<div class="alert alert-error">
|
|
119
|
-
<span>{error}</span>
|
|
120
|
-
</div>
|
|
121
|
-
{:else if player}
|
|
122
|
-
<ItemBody
|
|
123
|
-
{player}
|
|
124
|
-
{responses}
|
|
125
|
-
{disabled}
|
|
126
|
-
{role}
|
|
127
|
-
typeset={effectiveTypeset}
|
|
128
|
-
{i18n}
|
|
129
|
-
{outcomeValues}
|
|
130
|
-
onResponseChange={handleResponseChange}
|
|
131
|
-
/>
|
|
132
|
-
|
|
133
|
-
{#if role === 'candidate' && !disabled && onSubmit}
|
|
134
|
-
{@const canSubmit = player.canSubmitResponses(responses)}
|
|
135
|
-
<div class="mt-6 flex items-center gap-4">
|
|
136
|
-
<button
|
|
137
|
-
class="btn btn-primary"
|
|
138
|
-
onclick={() => handleSubmit(true)}
|
|
139
|
-
disabled={isCompleted || !canSubmit}
|
|
140
|
-
>
|
|
141
|
-
{isAdaptive && isCompleted ? (i18n?.t('item.completed') ?? 'item.completed') : (i18n?.t('item.submit') ?? 'item.submit')}
|
|
142
|
-
</button>
|
|
143
|
-
|
|
144
|
-
{#if isAdaptive}
|
|
145
|
-
<div class="text-sm text-base-content/70">
|
|
146
|
-
{#if isCompleted}
|
|
147
|
-
<span class="badge badge-success">{i18n?.t('item.complete') ?? 'item.complete'}</span>
|
|
148
|
-
{:else}
|
|
149
|
-
<span>{i18n?.t('item.attempt', { numAttempts: numAttempts + 1 }) ?? `item.attempt (${numAttempts + 1})`}</span>
|
|
150
|
-
{/if}
|
|
151
|
-
</div>
|
|
152
|
-
{/if}
|
|
153
|
-
</div>
|
|
154
|
-
{/if}
|
|
155
|
-
|
|
156
|
-
<!-- Modal feedback display -->
|
|
157
|
-
<ModalFeedbackDisplay feedback={modalFeedback} onClose={closeFeedback} typeset={effectiveTypeset} {i18n} />
|
|
158
|
-
{:else}
|
|
159
|
-
<div class="alert alert-info">
|
|
160
|
-
<span>{i18n?.t('item.loading') ?? 'item.loading'}</span>
|
|
161
|
-
</div>
|
|
162
|
-
{/if}
|
|
163
|
-
</div>
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { ModalFeedback } from '../types';
|
|
3
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
4
|
-
import { typesetAction } from './actions/typesetAction';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
feedback: ModalFeedback[];
|
|
8
|
-
onClose?: () => void;
|
|
9
|
-
typeset?: (element: HTMLElement) => void;
|
|
10
|
-
i18n?: I18nProvider;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let { feedback = [], onClose, typeset, i18n }: Props = $props();
|
|
14
|
-
|
|
15
|
-
// Show modal if there's feedback
|
|
16
|
-
const hasActiveFeedback = $derived(feedback.length > 0);
|
|
17
|
-
const modalTitleId = 'item-player-modal-feedback-title';
|
|
18
|
-
const firstTitle = $derived(feedback.find((item) => item.title)?.title);
|
|
19
|
-
|
|
20
|
-
function handleClose() {
|
|
21
|
-
onClose?.();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function handleBackdropClick(e: MouseEvent) {
|
|
25
|
-
// Close when clicking the backdrop (outside the modal content)
|
|
26
|
-
if (e.target === e.currentTarget) {
|
|
27
|
-
handleClose();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
</script>
|
|
31
|
-
|
|
32
|
-
{#if hasActiveFeedback}
|
|
33
|
-
<!-- DaisyUI Modal -->
|
|
34
|
-
<dialog
|
|
35
|
-
open
|
|
36
|
-
class="modal modal-open"
|
|
37
|
-
aria-modal="true"
|
|
38
|
-
aria-labelledby={firstTitle ? modalTitleId : undefined}
|
|
39
|
-
aria-label={firstTitle ? undefined : (i18n?.t('feedback.title') ?? 'Feedback')}
|
|
40
|
-
onclick={handleBackdropClick}
|
|
41
|
-
>
|
|
42
|
-
<div class="modal-box max-w-3xl">
|
|
43
|
-
<!-- Close button -->
|
|
44
|
-
<button
|
|
45
|
-
class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
|
|
46
|
-
type="button"
|
|
47
|
-
onclick={handleClose}
|
|
48
|
-
aria-label={i18n?.t('feedback.closeFeedback') ?? 'Close feedback'}
|
|
49
|
-
>
|
|
50
|
-
✕
|
|
51
|
-
</button>
|
|
52
|
-
|
|
53
|
-
<!-- Feedback content -->
|
|
54
|
-
{#each feedback as item, index}
|
|
55
|
-
<div class="mb-4 {index < feedback.length - 1 ? 'border-b pb-4' : ''}">
|
|
56
|
-
{#if item.title}
|
|
57
|
-
<h3 id={index === 0 ? modalTitleId : undefined} class="font-bold text-lg mb-2">{item.title}</h3>
|
|
58
|
-
{/if}
|
|
59
|
-
|
|
60
|
-
<!-- Render HTML content with MathJax support -->
|
|
61
|
-
{#if typeset}
|
|
62
|
-
<div
|
|
63
|
-
class="prose max-w-none"
|
|
64
|
-
use:typesetAction={{ typeset }}
|
|
65
|
-
>
|
|
66
|
-
{@html item.content}
|
|
67
|
-
</div>
|
|
68
|
-
{:else}
|
|
69
|
-
<div class="prose max-w-none">
|
|
70
|
-
{@html item.content}
|
|
71
|
-
</div>
|
|
72
|
-
{/if}
|
|
73
|
-
</div>
|
|
74
|
-
{/each}
|
|
75
|
-
|
|
76
|
-
<!-- Action buttons -->
|
|
77
|
-
<div class="modal-action">
|
|
78
|
-
<button class="btn btn-primary" type="button" onclick={handleClose}>
|
|
79
|
-
{i18n?.t('common.continue') ?? 'Continue'}
|
|
80
|
-
</button>
|
|
81
|
-
</div>
|
|
82
|
-
</div>
|
|
83
|
-
</dialog>
|
|
84
|
-
{/if}
|
|
85
|
-
|
|
86
|
-
<style>
|
|
87
|
-
/* Ensure modal is accessible */
|
|
88
|
-
dialog {
|
|
89
|
-
background-color: rgba(0, 0, 0, 0.5);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/* Ensure feedback content is readable */
|
|
93
|
-
.modal-box {
|
|
94
|
-
max-height: 80vh;
|
|
95
|
-
overflow-y: auto;
|
|
96
|
-
}
|
|
97
|
-
</style>
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
export interface TypesetActionParams {
|
|
2
|
-
/**
|
|
3
|
-
* Typeset function provided by the host app (KaTeX, MathJax, etc).
|
|
4
|
-
* It should be idempotent or at least safe to call repeatedly on updates.
|
|
5
|
-
* Optional - if not provided, the action is a no-op.
|
|
6
|
-
*/
|
|
7
|
-
typeset?: (root: HTMLElement) => void | Promise<void>;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Observe subtree changes and re-typeset automatically.
|
|
11
|
-
* Default: true
|
|
12
|
-
*/
|
|
13
|
-
observe?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Generic Svelte action that calls `params.typeset(node)` initially and on DOM updates.
|
|
18
|
-
*
|
|
19
|
-
* This is intentionally dependency-free so the player/components can be used
|
|
20
|
-
* outside the example app without pulling in a math engine.
|
|
21
|
-
*/
|
|
22
|
-
export function typesetAction(node: HTMLElement, params: TypesetActionParams) {
|
|
23
|
-
const isBrowser = typeof window !== 'undefined' && typeof MutationObserver !== 'undefined';
|
|
24
|
-
if (!isBrowser) return { update() {}, destroy() {} };
|
|
25
|
-
|
|
26
|
-
let disposed = false;
|
|
27
|
-
let scheduled = false;
|
|
28
|
-
let observer: MutationObserver | null = null;
|
|
29
|
-
let current = params;
|
|
30
|
-
|
|
31
|
-
const schedule = () => {
|
|
32
|
-
if (disposed || scheduled || !current.typeset) return;
|
|
33
|
-
scheduled = true;
|
|
34
|
-
requestAnimationFrame(async () => {
|
|
35
|
-
scheduled = false;
|
|
36
|
-
if (disposed || !current.typeset) return;
|
|
37
|
-
try {
|
|
38
|
-
await current.typeset(node);
|
|
39
|
-
} catch {
|
|
40
|
-
// ignore typesetting errors; keep raw text
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const startObserver = () => {
|
|
46
|
-
if (observer) return;
|
|
47
|
-
observer = new MutationObserver(() => schedule());
|
|
48
|
-
observer.observe(node, { childList: true, subtree: true, characterData: true });
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const stopObserver = () => {
|
|
52
|
-
observer?.disconnect();
|
|
53
|
-
observer = null;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// initial
|
|
57
|
-
schedule();
|
|
58
|
-
if (current.observe !== false) startObserver();
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
update(next: TypesetActionParams) {
|
|
62
|
-
current = next;
|
|
63
|
-
if (current.observe === false) stopObserver();
|
|
64
|
-
else startObserver();
|
|
65
|
-
schedule();
|
|
66
|
-
},
|
|
67
|
-
destroy() {
|
|
68
|
-
disposed = true;
|
|
69
|
-
stopObserver();
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|