@pie-qti/qti-common 1.0.0-beta.4 → 1.0.0-beta.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"markup.js","sourceRoot":"","sources":["../../src/accessibility/markup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAoB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAsB,MAAM,0BAA0B,CAAC;AAGjF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,YAAY,EAAE,cAAc;IAC5B,qBAAqB,EACpB,6HAA6H;CACrH,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC3D,qCAAqC;IACrC,qCAAqC;CACrC,CAAC,CAAC;AA0DH,MAAM,sBAAsB,GAAG,OAAO,CAAC;AACvC,MAAM,oBAAoB,GACzB,gIAAgI,CAAC;AAClI,MAAM,aAAa,GAClB,sKAAsK,CAAC;AACxK,MAAM,yBAAyB,GAAG,wGAAwG,CAAC;AAC3I,MAAM,iBAAiB,GAAG,qDAAqD,CAAC;AAChF,MAAM,uBAAuB,GAAG,4DAA4D,CAAC;AAC7F,MAAM,mBAAmB,GAAG,wCAAwC,CAAC;AACrE,MAAM,aAAa,GAAG,2CAA2C,CAAC;AAClE,MAAM,kBAAkB,GAAG,wDAAwD,CAAC;AACpF,gGAAgG;AAChG,MAAM,iBAAiB,GAAG,8CAA8C,CAAC;AACzE,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,wEAAwE;AACxE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC/B,cAAc;IACd,wBAAwB;IACxB,cAAc;IACd,SAAS;IACT,mBAAmB;IACnB,8BAA8B;IAC9B,mBAAmB;IACnB,cAAc;CACd,CAAC,CAAC;AACH,MAAM,aAAa,GAA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,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC1D,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC;YAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,sFAAsF;AACtF,SAAS,gBAAgB,CAAC,KAAa,EAAE,IAAY;IACpD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,UAAgC,CAAC;IAC1E,OAAO,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,OAAO,CAAC,KAAyB;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjE,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACrC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * Accessibility markup\n *\n * The edits that prepare a QTI document's content for PIE conversion and for delivery, so what QTI\n * voices, hides or suppresses stays so for the PIE read-aloud tools. Each content root (`itemBody`,\n * `modalFeedback`, `stimulusBody`, in QTI 2 or QTI 3 spelling) is read as a token stream into an\n * element tree, and rebuilt with the edits applied; markup outside the roots, comments and\n * processing instructions are left as authored. CDATA is edited like the markup around it, since\n * the HTML it wraps is what converts.\n *\n * 1. `qti-hidden` and `qti-visually-hidden` get the inline style the class stands for, since the\n * shared-vocabulary stylesheet has no URL a PIE player can load and players strip `<style>`.\n * Delivery ships that stylesheet and turns this edit off with `hidingStyles: false`.\n * 2. `data-qti-suppress-tts` is restated as `data-tts-suppress`, the only spelling PIE reads.\n * 3. An element with `data-ssml` gets a generated `data-catalog-idref`, and the SSML becomes a\n * `spoken` card under it; an element that already names a catalog adds the card to that one.\n * 4. Each APIP content link docks its access element's idref: on the element whose `id` it names,\n * or on a span around the word or character range its `textLink` counts. Words are counted\n * from 1 over the element's text split on whitespace, punctuation kept with its word, as\n * 1EdTech's APIP-to-QTI 3 migration guide counts them; characters from 1 with whitespace runs\n * collapsed. A range that crosses markup or overlaps another range is not docked.\n * 5. Inline SSML elements are unwrapped with their text kept, and their nearest enclosing element\n * gets a `spoken` card holding its content as SSML: the shape `SSMLExtractor` in pie-players\n * produces from a `<speak>` element, so both reach `TTSService` alike.\n * 6. `xml:lang` is restated as `lang`, the attribute HTML reads for the language of content, and\n * gets the `dir` of that language where it differs from the surrounding content's: the nearest\n * ancestor's `dir` or language, else the document element's `xml:lang`, else left-to-right.\n * An authored `dir` stays as authored.\n *\n * Docking puts the idref on the element's start tag, with two exceptions that wrap the element's\n * content instead: a choice, whose attributes the transformers drop along with its tag, and an\n * element that names a catalog already. An idref that cannot dock is left out, and the\n * accessibility audit reports what it would have carried.\n */\n\nimport { type HTMLElement, parse } from 'node-html-parser';\nimport { languageDirection, type TextDirection } from '../language/direction.js';\nimport type { TextRange } from './catalog.js';\n\nexport const HIDING_STYLES = {\n\t'qti-hidden': 'display:none',\n\t'qti-visually-hidden':\n\t\t'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0',\n} as const;\n\nexport const SSML_NAMESPACES: ReadonlySet<string> = new Set([\n\t'http://www.w3.org/2001/10/synthesis',\n\t'http://www.w3.org/2010/10/synthesis',\n]);\n\n/** An idref to dock on the content element whose `id` is `target`, or on a range of its text. */\nexport interface ContentLink {\n\tidref: string;\n\ttarget: string;\n\trange?: TextRange;\n}\n\nexport interface PrepareContentMarkupOptions {\n\t/** Restate the hiding classes as inline style. Default true. */\n\thidingStyles?: boolean;\n}\n\nexport interface PreparedMarkup {\n\txml: string;\n\t/** The `spoken` cards the content's SSML makes, by the idref each docked under. */\n\tspoken: Array<{ identifier: string; content: string }>;\n}\n\ninterface Span {\n\tstart: number;\n\tend: number;\n}\n\ninterface ContentElement {\n\tkind: 'element';\n\tname: string;\n\tlocal: string;\n\tattrs: string;\n\tattributes: Map<string, string | undefined>;\n\t/** Written as `<name/>`; a void HTML element without the slash has no close tag either. */\n\tselfClosing: boolean;\n\topen: Span;\n\tclose?: Span;\n\tparent?: ContentElement;\n\tchildren: ContentNode[];\n\tssml: boolean;\n\t/** The element's start tag as edited: its authored attributes, then the added ones. */\n\teditedAttrs: string;\n\tadded: string[];\n\t/** The idref the element's content renders under: authored, or docked by the preparation. */\n\tidref?: string;\n}\n\ninterface ContentText extends Span {\n\tkind: 'text';\n\traw: string;\n}\n\ntype ContentNode = ContentElement | ContentText;\n\ninterface Wrap extends Span {\n\ttag: 'span' | 'div';\n\tidref: string;\n\tseq: number;\n}\n\nconst GENERATED_IDREF_PREFIX = 'ssml-';\nconst CONTENT_ROOT_PATTERN =\n\t/<((?:[\\w.-]+:)?(?:itemBody|modalFeedback|stimulusBody|qti-item-body|qti-modal-feedback|qti-stimulus-body))\\b[\\s\\S]*?<\\/\\1\\s*>/g;\nconst TOKEN_PATTERN =\n\t/<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<!\\[CDATA\\[|\\]\\]>|<\\/([A-Za-z][\\w.:-]*)\\s*>|<([A-Za-z][\\w.:-]*)((?:\\s+[^\\s=/>]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'>]+))?)*)\\s*(\\/?)>/g;\nconst DOCUMENT_LANGUAGE_PATTERN = /^(?:\\s*<(?:\\?[\\s\\S]*?\\?|!--[\\s\\S]*?--|![^>]*)>)*\\s*<[^\\s/>!?]+[^>]*?\\sxml:lang\\s*=\\s*(\"[^\"]*\"|'[^']*')/;\nconst ATTRIBUTE_PATTERN = /([^\\s=/>]+)(?:\\s*=\\s*(\"[^\"]*\"|'[^']*'|[^\\s\"'>]+))?/g;\nconst XMLNS_ATTRIBUTE_PATTERN = /\\s+xmlns(?::[\\w.-]+)?\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'>]+)/g;\nconst SSML_PREFIX_PATTERN = /\\bxmlns:([\\w.-]+)\\s*=\\s*([\"'])(.*?)\\2/g;\nconst IDREF_PATTERN = /\\bdata-catalog-idref\\s*=\\s*([\"'])(.*?)\\1/g;\nconst CATALOG_ID_PATTERN = /<(?:[\\w.-]+:)?catalog\\b[^>]*?\\bid\\s*=\\s*([\"'])(.*?)\\1/g;\n/** One character of text: an entity or character reference counts as the character it names. */\nconst TEXT_UNIT_PATTERN = /&(?:#\\d+|#x[\\da-f]+|[a-z][\\da-z]*);|[\\s\\S]/gi;\nconst XML_WHITESPACE = /^[ \\t\\r\\n]$/;\n/** Choices: the transformers read their content and drop their tags. */\nconst CONTENT_WRAPPED = new Set([\n\t'simpleChoice',\n\t'simpleAssociableChoice',\n\t'inlineChoice',\n\t'gapText',\n\t'qti-simple-choice',\n\t'qti-simple-associable-choice',\n\t'qti-inline-choice',\n\t'qti-gap-text',\n]);\nconst VOID_ELEMENTS = new Set([\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n]);\nconst BLOCK_ELEMENTS = new Set([\n\t'address',\n\t'blockquote',\n\t'div',\n\t'dl',\n\t'figure',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'hr',\n\t'ol',\n\t'p',\n\t'pre',\n\t'table',\n\t'ul',\n]);\n\n/** Apply the accessibility edits to a QTI document's content. */\nexport function prepareContentMarkup(\n\tqtiXml: string,\n\tlinks: ContentLink[] = [],\n\toptions: PrepareContentMarkupOptions = {}\n): PreparedMarkup {\n\tconst hidingStyles = options.hidingStyles ?? true;\n\tconst documentDirection = languageDirection(unquote(qtiXml.match(DOCUMENT_LANGUAGE_PATTERN)?.[1]));\n\tconst roots = [...qtiXml.matchAll(CONTENT_ROOT_PATTERN)].flatMap((match) => {\n\t\tconst root = contentTree(match[0], match.index, ssmlPrefixesOf(qtiXml));\n\t\treturn root ? [root] : [];\n\t});\n\tconst elements = roots.flatMap(descendants);\n\tconst spoken: PreparedMarkup['spoken'] = [];\n\tconst wraps: Wrap[] = [];\n\tconst taken = new Set([\n\t\t...[...qtiXml.matchAll(IDREF_PATTERN)].map((match) => match[2] as string),\n\t\t...[...qtiXml.matchAll(CATALOG_ID_PATTERN)].map((match) => match[2] as string),\n\t\t...links.map((link) => link.idref),\n\t]);\n\tlet generated = 0;\n\tconst nextIdref = (): string => {\n\t\tlet identifier: string;\n\t\tdo {\n\t\t\tgenerated += 1;\n\t\t\tidentifier = `${GENERATED_IDREF_PREFIX}${generated}`;\n\t\t} while (taken.has(identifier));\n\t\ttaken.add(identifier);\n\t\treturn identifier;\n\t};\n\n\tconst wrap = (span: Span, idref: string, tag: Wrap['tag']): void => {\n\t\twraps.push({ ...span, tag, idref, seq: wraps.length });\n\t};\n\tconst dock = (element: ContentElement, idref: string): boolean => {\n\t\tif (!element.parent) return false;\n\t\tif (element.idref === idref) return true;\n\t\tif (CONTENT_WRAPPED.has(element.local) || element.ssml || element.idref !== undefined) {\n\t\t\tif (!element.close) return false;\n\t\t\tconst block = element.children.some(\n\t\t\t\t(child) => child.kind === 'element' && BLOCK_ELEMENTS.has(child.local.toLowerCase())\n\t\t\t);\n\t\t\twrap({ start: element.open.end, end: element.close.start }, idref, block ? 'div' : 'span');\n\t\t} else {\n\t\t\telement.added.push(`data-catalog-idref=\"${escapeAttribute(idref)}\"`);\n\t\t}\n\t\telement.idref ??= idref;\n\t\treturn true;\n\t};\n\n\tfor (const element of elements) {\n\t\tif (element.ssml) continue;\n\t\teditStartTag(element, hidingStyles, documentDirection);\n\t\tconst authored = unquote(element.attributes.get('data-catalog-idref')).trim();\n\t\tif (authored) {\n\t\t\tif (CONTENT_WRAPPED.has(element.local)) dock(element, authored);\n\t\t\telement.idref = authored;\n\t\t}\n\t\tif (element.attributes.has('data-ssml')) {\n\t\t\tconst content = decodedAttribute(element.attrs, 'data-ssml')?.trim();\n\t\t\tif (content) {\n\t\t\t\tconst identifier = element.idref ?? nextIdref();\n\t\t\t\tif (element.idref !== undefined || dock(element, identifier)) {\n\t\t\t\t\tspoken.push({ identifier, content });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst ids = new Map<string, ContentElement>();\n\tfor (const element of elements) {\n\t\tconst id = unquote(element.attributes.get('id')).trim();\n\t\tif (id && !ids.has(id)) ids.set(id, element);\n\t}\n\tconst ranges = new Map<ContentText, Span[]>();\n\tfor (const link of links) {\n\t\tconst element = ids.get(link.target);\n\t\tif (!element) continue;\n\t\tif (!link.range) {\n\t\t\tdock(element, link.idref);\n\t\t\tcontinue;\n\t\t}\n\t\tconst located = locateRange(element, link.range);\n\t\tif (!located) continue;\n\t\tconst docked = ranges.get(located.text) ?? [];\n\t\tif (docked.some((span) => crosses(span, located))) continue;\n\t\tdocked.push(located);\n\t\tranges.set(located.text, docked);\n\t\twrap(located, link.idref, 'span');\n\t}\n\n\tconst hosts = new Map<ContentElement, ContentNode[]>();\n\tfor (const element of elements) {\n\t\tif (!element.ssml || element.parent?.ssml) continue;\n\t\tlet host = element.parent;\n\t\twhile (host?.ssml) host = host.parent;\n\t\t// SSML straight inside a content root speaks on its own: a root's tag does not reach PIE.\n\t\tif (!host?.parent) hosts.set(element, [element]);\n\t\telse hosts.set(host, host.children);\n\t}\n\tfor (const [host, nodes] of hosts) {\n\t\tconst markup = nodes.map(ssmlMarkup).join('').replace(/\\s+/g, ' ').trim();\n\t\tif (!markup) continue;\n\t\tconst identifier = host.idref ?? nextIdref();\n\t\tif (host.idref !== undefined || dock(host, identifier)) {\n\t\t\tspoken.push({ identifier, content: `<speak>${markup}</speak>` });\n\t\t}\n\t}\n\n\treturn { xml: rendered(qtiXml, elements, wraps), spoken };\n}\n\nfunction contentTree(\n\tmarkup: string,\n\toffset: number,\n\tssmlPrefixes: ReadonlySet<string>\n): ContentElement | undefined {\n\tlet root: ContentElement | undefined;\n\tconst stack: Array<ContentElement & { defaultSsml: boolean }> = [];\n\tlet cursor = 0;\n\tconst addText = (end: number): void => {\n\t\tconst parent = stack[stack.length - 1];\n\t\tif (parent && end > cursor) {\n\t\t\tparent.children.push({\n\t\t\t\tkind: 'text',\n\t\t\t\tstart: offset + cursor,\n\t\t\t\tend: offset + end,\n\t\t\t\traw: markup.slice(cursor, end),\n\t\t\t});\n\t\t}\n\t};\n\n\tfor (const match of markup.matchAll(TOKEN_PATTERN)) {\n\t\taddText(match.index);\n\t\tcursor = match.index + match[0].length;\n\t\tconst [, endName, startName, attrs = '', selfClosing] = match;\n\t\tif (endName) {\n\t\t\tlet at = stack.length - 1;\n\t\t\twhile (at >= 0 && stack[at]?.name !== endName) at -= 1;\n\t\t\tif (at === -1) continue;\n\t\t\tconst element = stack[at] as ContentElement;\n\t\t\telement.close = { start: offset + match.index, end: offset + cursor };\n\t\t\tstack.length = at;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!startName) continue;\n\n\t\tconst parent = stack[stack.length - 1];\n\t\tif (!parent && root) continue;\n\t\tconst colon = startName.indexOf(':');\n\t\tconst prefix = colon === -1 ? undefined : startName.slice(0, colon);\n\t\tconst local = startName.slice(colon + 1);\n\t\tconst attributes = new Map(\n\t\t\t[...attrs.matchAll(ATTRIBUTE_PATTERN)].map((attribute) => [\n\t\t\t\t(attribute[1] as string).toLowerCase(),\n\t\t\t\tattribute[2],\n\t\t\t])\n\t\t);\n\t\tconst xmlns = attributes.get('xmlns');\n\t\tconst defaultSsml =\n\t\t\txmlns === undefined ? (parent?.defaultSsml ?? false) : SSML_NAMESPACES.has(unquote(xmlns));\n\t\tconst element = {\n\t\t\tkind: 'element' as const,\n\t\t\tname: startName,\n\t\t\tlocal,\n\t\t\tattrs,\n\t\t\tattributes,\n\t\t\tselfClosing: Boolean(selfClosing),\n\t\t\topen: { start: offset + match.index, end: offset + cursor },\n\t\t\t...(parent ? { parent } : {}),\n\t\t\tchildren: [],\n\t\t\tssml: prefix === undefined ? defaultSsml : ssmlPrefixes.has(prefix),\n\t\t\teditedAttrs: attrs,\n\t\t\tadded: [],\n\t\t\tdefaultSsml,\n\t\t};\n\t\tif (parent) parent.children.push(element);\n\t\telse root = element;\n\t\tif (!element.selfClosing && !VOID_ELEMENTS.has(local.toLowerCase())) stack.push(element);\n\t}\n\treturn root;\n}\n\n/** Restate hiding classes, read-aloud suppression and content language in the start tag. */\nfunction editStartTag(\n\telement: ContentElement,\n\thidingStyles: boolean,\n\tdocumentDirection: TextDirection\n): void {\n\tconst { attributes } = element;\n\tconst classes = unquote(attributes.get('class')).split(/\\s+/);\n\tconst hiding = Object.entries(hidingStyles ? HIDING_STYLES : {})\n\t\t.filter(([hidingClass]) => classes.includes(hidingClass))\n\t\t.map(([, style]) => style);\n\tif (hiding.length > 0) {\n\t\tconst style = attributes.get('style');\n\t\tif (style === undefined) {\n\t\t\telement.added.push(`style=\"${hiding.join(';')}\"`);\n\t\t} else {\n\t\t\tconst quote = style.startsWith(\"'\") ? \"'\" : '\"';\n\t\t\tconst current = unquote(style).trim().replace(/;$/, '');\n\t\t\tconst merged = [current, ...hiding].filter(Boolean).join(';');\n\t\t\telement.editedAttrs = element.editedAttrs.replace(\n\t\t\t\t/(\\sstyle\\s*=\\s*)(\"[^\"]*\"|'[^']*'|[^\\s\"'>]+)/i,\n\t\t\t\t`$1${quote}${merged}${quote}`\n\t\t\t);\n\t\t}\n\t}\n\n\tconst language = attributes.get('xml:lang');\n\tif (language !== undefined) {\n\t\tif (!attributes.has('lang')) element.added.push(`lang=${quoted(language)}`);\n\t\tconst direction = languageDirection(unquote(language));\n\t\tif (!attributes.has('dir') && direction !== surroundingDirection(element, documentDirection)) {\n\t\t\telement.added.push(`dir=\"${direction}\"`);\n\t\t}\n\t}\n\n\tconst suppress = attributes.get('data-qti-suppress-tts');\n\tif (suppress !== undefined && !attributes.has('data-tts-suppress')) {\n\t\telement.added.push(`data-tts-suppress=${quoted(suppress)}`);\n\t}\n}\n\n/** The direction `element` inherits: its nearest ancestor's `dir` or language, else the document's. */\nfunction surroundingDirection(element: ContentElement, documentDirection: TextDirection): TextDirection {\n\tfor (let ancestor = element.parent; ancestor; ancestor = ancestor.parent) {\n\t\tconst dir = unquote(ancestor.attributes.get('dir')).trim().toLowerCase();\n\t\tif (dir === 'rtl' || dir === 'ltr') return dir;\n\t\tconst language = ancestor.attributes.get('xml:lang') ?? ancestor.attributes.get('lang');\n\t\tif (language !== undefined) return languageDirection(unquote(language));\n\t}\n\treturn documentDirection;\n}\n\n/**\n * The span of `element`'s text that `range` counts, when it lies inside one text node. Each\n * whitespace run counts as one character, and whitespace before the first word not at all.\n */\nfunction locateRange(\n\telement: ContentElement,\n\trange: TextRange\n): (Span & { text: ContentText }) | undefined {\n\tconst characters: Array<Span & { text: ContentText; space: boolean }> = [];\n\tlet space: (Span & { text: ContentText }) | undefined;\n\tfor (const text of textsOf(element)) {\n\t\tfor (const unit of text.raw.matchAll(TEXT_UNIT_PATTERN)) {\n\t\t\tconst start = text.start + unit.index;\n\t\t\tconst span = { text, start, end: start + unit[0].length };\n\t\t\tif (XML_WHITESPACE.test(unit[0])) {\n\t\t\t\tif (characters.length > 0) space ??= span;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (space) characters.push({ ...space, space: true });\n\t\t\tspace = undefined;\n\t\t\tcharacters.push({ ...span, space: false });\n\t\t}\n\t}\n\n\tlet first = range.start - 1;\n\tlet last = range.stop - 1;\n\tif (range.unit === 'word') {\n\t\tconst words: Array<[number, number]> = [];\n\t\tcharacters.forEach((character, index) => {\n\t\t\tif (character.space) return;\n\t\t\tconst word = words[words.length - 1];\n\t\t\tif (word && word[1] === index - 1) word[1] = index;\n\t\t\telse words.push([index, index]);\n\t\t});\n\t\tfirst = words[range.start - 1]?.[0] ?? Number.NaN;\n\t\tlast = words[range.stop - 1]?.[1] ?? Number.NaN;\n\t}\n\tconst from = characters[first];\n\tconst to = characters[last];\n\tif (!from || !to || last < first || from.text !== to.text) return undefined;\n\treturn { text: from.text, start: from.start, end: to.end };\n}\n\n/** Two ranges that overlap without one holding the other. */\nfunction crosses(a: Span, b: Span): boolean {\n\tconst overlap = a.start < b.end && b.start < a.end;\n\tconst nested = (a.start <= b.start && b.end <= a.end) || (b.start <= a.start && a.end <= b.end);\n\treturn overlap && !nested;\n}\n\n/** Content as SSML: its SSML elements without namespace prefixes, other markup reduced to text. */\nfunction ssmlMarkup(node: ContentNode): string {\n\tif (node.kind === 'text') return escapeText(parse(node.raw).textContent);\n\tconst classes = unquote(node.attributes.get('class')).split(/\\s+/);\n\tif (\n\t\tclasses.includes('qti-hidden') ||\n\t\tnode.attributes.has('data-qti-suppress-tts') ||\n\t\tnode.attributes.has('data-tts-suppress')\n\t) {\n\t\treturn '';\n\t}\n\tconst content = node.children.map(ssmlMarkup).join('');\n\tif (!node.ssml) return content;\n\tconst attrs = node.attrs.replace(XMLNS_ATTRIBUTE_PATTERN, '');\n\treturn node.selfClosing\n\t\t? `<${node.local}${attrs}/>`\n\t\t: `<${node.local}${attrs}>${content}</${node.local}>`;\n}\n\n/** The document with every edited tag replaced and every wrap inserted. */\nfunction rendered(qtiXml: string, elements: ContentElement[], wraps: Wrap[]): string {\n\tinterface Edit extends Span {\n\t\ttext: string;\n\t\t/** Same-position order: closing wraps, then opening ones, then tag replacements. */\n\t\tphase: 0 | 1 | 2;\n\t\twrap?: Wrap;\n\t}\n\tconst edits: Edit[] = [];\n\tfor (const element of elements) {\n\t\tif (element.ssml) {\n\t\t\tedits.push({ ...element.open, text: '', phase: 2 });\n\t\t\tif (element.close) edits.push({ ...element.close, text: '', phase: 2 });\n\t\t} else if (element.added.length > 0 || element.editedAttrs !== element.attrs) {\n\t\t\tconst added = element.added.map((attribute) => ` ${attribute}`).join('');\n\t\t\tconst end = element.selfClosing ? ' />' : '>';\n\t\t\tedits.push({\n\t\t\t\t...element.open,\n\t\t\t\ttext: `<${element.name}${element.editedAttrs}${added}${end}`,\n\t\t\t\tphase: 2,\n\t\t\t});\n\t\t}\n\t}\n\tfor (const wrap of wraps) {\n\t\tedits.push({\n\t\t\tstart: wrap.start,\n\t\t\tend: wrap.start,\n\t\t\ttext: `<${wrap.tag} data-catalog-idref=\"${escapeAttribute(wrap.idref)}\">`,\n\t\t\tphase: 1,\n\t\t\twrap,\n\t\t});\n\t\tedits.push({ start: wrap.end, end: wrap.end, text: `</${wrap.tag}>`, phase: 0, wrap });\n\t}\n\t// Wraps nest: at one position the innermost closes first and the outermost opens first.\n\tedits.sort((a, b) => {\n\t\tif (a.start !== b.start) return a.start - b.start;\n\t\tif (a.phase !== b.phase) return a.phase - b.phase;\n\t\tif (!a.wrap || !b.wrap) return 0;\n\t\tif (a.phase === 0) return b.wrap.start - a.wrap.start || b.wrap.seq - a.wrap.seq;\n\t\treturn b.wrap.end - a.wrap.end || a.wrap.seq - b.wrap.seq;\n\t});\n\n\tlet xml = '';\n\tlet cursor = 0;\n\tfor (const edit of edits) {\n\t\txml += qtiXml.slice(cursor, edit.start) + edit.text;\n\t\tcursor = edit.end;\n\t}\n\treturn xml + qtiXml.slice(cursor);\n}\n\nfunction descendants(element: ContentElement): ContentElement[] {\n\treturn [\n\t\telement,\n\t\t...element.children.flatMap((child) => (child.kind === 'element' ? descendants(child) : [])),\n\t];\n}\n\nfunction textsOf(element: ContentElement): ContentText[] {\n\treturn element.children.flatMap((child) => (child.kind === 'text' ? [child] : textsOf(child)));\n}\n\nfunction ssmlPrefixesOf(qtiXml: string): Set<string> {\n\tconst prefixes = new Set(['ssml']);\n\tfor (const match of qtiXml.matchAll(SSML_PREFIX_PATTERN)) {\n\t\tif (SSML_NAMESPACES.has(match[3] as string)) prefixes.add(match[1] as string);\n\t}\n\treturn prefixes;\n}\n\n/** An attribute's value with its entities decoded, as the markup's readers see it. */\nfunction decodedAttribute(attrs: string, name: string): string | undefined {\n\tconst element = parse(`<x${attrs}></x>`).firstChild as HTMLElement | null;\n\treturn element?.getAttribute(name);\n}\n\nfunction unquote(value: string | undefined): string {\n\tif (!value) return '';\n\treturn /^([\"']).*\\1$/s.test(value) ? value.slice(1, -1) : value;\n}\n\nfunction quoted(value: string): string {\n\treturn /^[\"']/.test(value) ? value : `\"${value}\"`;\n}\n\nexport function escapeText(text: string): string {\n\treturn text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\nfunction escapeAttribute(value: string): string {\n\treturn escapeText(value).replace(/\"/g, '&quot;');\n}\n"]}
1
+ {"version":3,"file":"markup.js","sourceRoot":"","sources":["../../src/accessibility/markup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAoB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAsB,MAAM,0BAA0B,CAAC;AAGjF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,YAAY,EAAE,cAAc;IAC5B,qBAAqB,EACpB,6HAA6H;CACrH,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC3D,qCAAqC;IACrC,qCAAqC;CACrC,CAAC,CA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EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,OAAO,CAAC,KAAyB;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjE,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC/C,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACrC,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC","sourcesContent":["/**\n * Accessibility markup\n *\n * The edits that prepare a QTI document's content for PIE conversion and for delivery, so what QTI\n * voices, hides or suppresses stays so for the PIE read-aloud tools. Each content root (`itemBody`,\n * `modalFeedback`, `stimulusBody`, in QTI 2 or QTI 3 spelling) is read as a token stream into an\n * element tree, and rebuilt with the edits applied; markup outside the roots, comments and\n * processing instructions are left as authored. CDATA is edited like the markup around it, since\n * the HTML it wraps is what converts.\n *\n * 1. `qti-hidden` and `qti-visually-hidden` get the inline style the class stands for, since the\n * shared-vocabulary stylesheet has no URL a PIE player can load and players strip `<style>`.\n * Delivery ships that stylesheet and turns this edit off with `hidingStyles: false`.\n * 2. `data-qti-suppress-tts` is restated as `data-tts-suppress`, the only spelling PIE reads.\n * 3. An element with `data-ssml` gets a generated `data-catalog-idref`, and the SSML becomes a\n * `spoken` card under it; an element that already names a catalog adds the card to that one.\n * 4. Each APIP content link docks its access element's idref: on the element whose `id` it names,\n * or on a span around the word or character range its `textLink` counts. Words are counted\n * from 1 over the element's text split on whitespace, punctuation kept with its word, as\n * 1EdTech's APIP-to-QTI 3 migration guide counts them; characters from 1 with whitespace runs\n * collapsed. A range that crosses markup or overlaps another range is not docked.\n * 5. Inline SSML elements are unwrapped with their text kept, and their nearest enclosing element\n * gets a `spoken` card holding its content as SSML: the shape `SSMLExtractor` in pie-players\n * produces from a `<speak>` element, so both reach `TTSService` alike.\n * 6. `xml:lang` is restated as `lang`, the attribute HTML reads for the language of content, and\n * gets the `dir` of that language where it differs from the surrounding content's: the nearest\n * ancestor's `dir` or language, else the document element's `xml:lang`, else left-to-right.\n * An authored `dir` stays as authored.\n *\n * Docking puts the idref on the element's start tag, with two exceptions that wrap the element's\n * content instead: a choice, whose attributes the transformers drop along with its tag, and an\n * element that names a catalog already. An idref that cannot dock is left out, and the\n * accessibility audit reports what it would have carried.\n */\n\nimport { type HTMLElement, parse } from 'node-html-parser';\nimport { languageDirection, type TextDirection } from '../language/direction.js';\nimport type { TextRange } from './catalog.js';\n\nexport const HIDING_STYLES = {\n\t'qti-hidden': 'display:none',\n\t'qti-visually-hidden':\n\t\t'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0',\n} as const;\n\nexport const SSML_NAMESPACES: ReadonlySet<string> = new Set([\n\t'http://www.w3.org/2001/10/synthesis',\n\t'http://www.w3.org/2010/10/synthesis',\n]);\n\n/** An idref to dock on the content element whose `id` is `target`, or on a range of its text. */\nexport interface ContentLink {\n\tidref: string;\n\ttarget: string;\n\trange?: TextRange;\n}\n\nexport interface PrepareContentMarkupOptions {\n\t/** Restate the hiding classes as inline style. Default true. */\n\thidingStyles?: boolean;\n}\n\nexport interface PreparedMarkup {\n\txml: string;\n\t/** The `spoken` cards the content's SSML makes, by the idref each docked under. */\n\tspoken: Array<{ identifier: string; content: string }>;\n}\n\ninterface Span {\n\tstart: number;\n\tend: number;\n}\n\ninterface ContentElement {\n\tkind: 'element';\n\tname: string;\n\tlocal: string;\n\tattrs: string;\n\tattributes: Map<string, string | undefined>;\n\t/** Written as `<name/>`; a void HTML element without the slash has no close tag either. */\n\tselfClosing: boolean;\n\topen: Span;\n\tclose?: Span;\n\tparent?: ContentElement;\n\tchildren: ContentNode[];\n\tssml: boolean;\n\t/** The element's start tag as edited: its authored attributes, then the added ones. */\n\teditedAttrs: string;\n\tadded: string[];\n\t/** The idref the element's content renders under: authored, or docked by the preparation. */\n\tidref?: string;\n}\n\ninterface ContentText extends Span {\n\tkind: 'text';\n\traw: string;\n}\n\ntype ContentNode = ContentElement | ContentText;\n\ninterface Wrap extends Span {\n\ttag: 'span' | 'div';\n\tidref: string;\n\tseq: number;\n}\n\nconst GENERATED_IDREF_PREFIX = 'ssml-';\nconst CONTENT_ROOT_PATTERN =\n\t/<((?:[\\w.-]+:)?(?:itemBody|modalFeedback|stimulusBody|qti-item-body|qti-modal-feedback|qti-stimulus-body))\\b[\\s\\S]*?<\\/\\1\\s*>/g;\nconst TOKEN_PATTERN =\n\t/<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<!\\[CDATA\\[|\\]\\]>|<\\/([A-Za-z][\\w.:-]*)\\s*>|<([A-Za-z][\\w.:-]*)((?:\\s+[^\\s=/>]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'>]+))?)*)\\s*(\\/?)>/g;\nconst DOCUMENT_LANGUAGE_PATTERN = /^(?:\\s*<(?:\\?[\\s\\S]*?\\?|!--[\\s\\S]*?--|![^>]*)>)*\\s*<[^\\s/>!?]+[^>]*?\\sxml:lang\\s*=\\s*(\"[^\"]*\"|'[^']*')/;\nconst ATTRIBUTE_PATTERN = /([^\\s=/>]+)(?:\\s*=\\s*(\"[^\"]*\"|'[^']*'|[^\\s\"'>]+))?/g;\nconst XMLNS_ATTRIBUTE_PATTERN = /\\s+xmlns(?::[\\w.-]+)?\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'>]+)/g;\nconst SSML_PREFIX_PATTERN = /\\bxmlns:([\\w.-]+)\\s*=\\s*([\"'])(.*?)\\2/g;\n/** Matches a data-catalog-idref attribute value, quoted (single/double) or bare. */\nexport const CATALOG_IDREF_PATTERN =\n\t/\\bdata-catalog-idref\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+))/g;\n\n/** Extracts the idref captured by a {@link CATALOG_IDREF_PATTERN} match. */\nexport function catalogIdrefFromMatch(match: RegExpMatchArray): string {\n\treturn (match[1] ?? match[2] ?? match[3]).trim();\n}\nconst CATALOG_ID_PATTERN = /<(?:[\\w.-]+:)?catalog\\b[^>]*?\\bid\\s*=\\s*([\"'])(.*?)\\1/g;\n/** One character of text: an entity or character reference counts as the character it names. */\nconst TEXT_UNIT_PATTERN = /&(?:#\\d+|#x[\\da-f]+|[a-z][\\da-z]*);|[\\s\\S]/gi;\nconst XML_WHITESPACE = /^[ \\t\\r\\n]$/;\n/** Choices: the transformers read their content and drop their tags. */\nconst CONTENT_WRAPPED = new Set([\n\t'simpleChoice',\n\t'simpleAssociableChoice',\n\t'inlineChoice',\n\t'gapText',\n\t'qti-simple-choice',\n\t'qti-simple-associable-choice',\n\t'qti-inline-choice',\n\t'qti-gap-text',\n]);\nconst VOID_ELEMENTS = new Set([\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n]);\nconst BLOCK_ELEMENTS = new Set([\n\t'address',\n\t'blockquote',\n\t'div',\n\t'dl',\n\t'figure',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'hr',\n\t'ol',\n\t'p',\n\t'pre',\n\t'table',\n\t'ul',\n]);\n\n/** Apply the accessibility edits to a QTI document's content. */\nexport function prepareContentMarkup(\n\tqtiXml: string,\n\tlinks: ContentLink[] = [],\n\toptions: PrepareContentMarkupOptions = {}\n): PreparedMarkup {\n\tconst hidingStyles = options.hidingStyles ?? true;\n\tconst documentDirection = languageDirection(unquote(qtiXml.match(DOCUMENT_LANGUAGE_PATTERN)?.[1]));\n\tconst roots = [...qtiXml.matchAll(CONTENT_ROOT_PATTERN)].flatMap((match) => {\n\t\tconst root = contentTree(match[0], match.index, ssmlPrefixesOf(qtiXml));\n\t\treturn root ? [root] : [];\n\t});\n\tconst elements = roots.flatMap(descendants);\n\tconst spoken: PreparedMarkup['spoken'] = [];\n\tconst wraps: Wrap[] = [];\n\tconst taken = new Set([\n\t\t...[...qtiXml.matchAll(CATALOG_IDREF_PATTERN)].map(catalogIdrefFromMatch),\n\t\t...[...qtiXml.matchAll(CATALOG_ID_PATTERN)].map((match) => match[2] as string),\n\t\t...links.map((link) => link.idref),\n\t]);\n\tlet generated = 0;\n\tconst nextIdref = (): string => {\n\t\tlet identifier: string;\n\t\tdo {\n\t\t\tgenerated += 1;\n\t\t\tidentifier = `${GENERATED_IDREF_PREFIX}${generated}`;\n\t\t} while (taken.has(identifier));\n\t\ttaken.add(identifier);\n\t\treturn identifier;\n\t};\n\n\tconst wrap = (span: Span, idref: string, tag: Wrap['tag']): void => {\n\t\twraps.push({ ...span, tag, idref, seq: wraps.length });\n\t};\n\tconst dock = (element: ContentElement, idref: string): boolean => {\n\t\tif (!element.parent) return false;\n\t\tif (element.idref === idref) return true;\n\t\tif (CONTENT_WRAPPED.has(element.local) || element.ssml || element.idref !== undefined) {\n\t\t\tif (!element.close) return false;\n\t\t\tconst block = element.children.some(\n\t\t\t\t(child) => child.kind === 'element' && BLOCK_ELEMENTS.has(child.local.toLowerCase())\n\t\t\t);\n\t\t\twrap({ start: element.open.end, end: element.close.start }, idref, block ? 'div' : 'span');\n\t\t} else {\n\t\t\telement.added.push(`data-catalog-idref=\"${escapeAttribute(idref)}\"`);\n\t\t}\n\t\telement.idref ??= idref;\n\t\treturn true;\n\t};\n\n\tfor (const element of elements) {\n\t\tif (element.ssml) continue;\n\t\teditStartTag(element, hidingStyles, documentDirection);\n\t\tconst authored = unquote(element.attributes.get('data-catalog-idref')).trim();\n\t\tif (authored) {\n\t\t\tif (CONTENT_WRAPPED.has(element.local)) dock(element, authored);\n\t\t\telement.idref = authored;\n\t\t}\n\t\tif (element.attributes.has('data-ssml')) {\n\t\t\tconst content = decodedAttribute(element.attrs, 'data-ssml')?.trim();\n\t\t\tif (content) {\n\t\t\t\tconst identifier = element.idref ?? nextIdref();\n\t\t\t\tif (element.idref !== undefined || dock(element, identifier)) {\n\t\t\t\t\tspoken.push({ identifier, content });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst ids = new Map<string, ContentElement>();\n\tfor (const element of elements) {\n\t\tconst id = unquote(element.attributes.get('id')).trim();\n\t\tif (id && !ids.has(id)) ids.set(id, element);\n\t}\n\tconst ranges = new Map<ContentText, Span[]>();\n\tfor (const link of links) {\n\t\tconst element = ids.get(link.target);\n\t\tif (!element) continue;\n\t\tif (!link.range) {\n\t\t\tdock(element, link.idref);\n\t\t\tcontinue;\n\t\t}\n\t\tconst located = locateRange(element, link.range);\n\t\tif (!located) continue;\n\t\tconst docked = ranges.get(located.text) ?? [];\n\t\tif (docked.some((span) => crosses(span, located))) continue;\n\t\tdocked.push(located);\n\t\tranges.set(located.text, docked);\n\t\twrap(located, link.idref, 'span');\n\t}\n\n\tconst hosts = new Map<ContentElement, ContentNode[]>();\n\tfor (const element of elements) {\n\t\tif (!element.ssml || element.parent?.ssml) continue;\n\t\tlet host = element.parent;\n\t\twhile (host?.ssml) host = host.parent;\n\t\t// SSML straight inside a content root speaks on its own: a root's tag does not reach PIE.\n\t\tif (!host?.parent) hosts.set(element, [element]);\n\t\telse hosts.set(host, host.children);\n\t}\n\tfor (const [host, nodes] of hosts) {\n\t\tconst markup = nodes.map(ssmlMarkup).join('').replace(/\\s+/g, ' ').trim();\n\t\tif (!markup) continue;\n\t\tconst identifier = host.idref ?? nextIdref();\n\t\tif (host.idref !== undefined || dock(host, identifier)) {\n\t\t\tspoken.push({ identifier, content: `<speak>${markup}</speak>` });\n\t\t}\n\t}\n\n\treturn { xml: rendered(qtiXml, elements, wraps), spoken };\n}\n\nfunction contentTree(\n\tmarkup: string,\n\toffset: number,\n\tssmlPrefixes: ReadonlySet<string>\n): ContentElement | undefined {\n\tlet root: ContentElement | undefined;\n\tconst stack: Array<ContentElement & { defaultSsml: boolean }> = [];\n\tlet cursor = 0;\n\tconst addText = (end: number): void => {\n\t\tconst parent = stack[stack.length - 1];\n\t\tif (parent && end > cursor) {\n\t\t\tparent.children.push({\n\t\t\t\tkind: 'text',\n\t\t\t\tstart: offset + cursor,\n\t\t\t\tend: offset + end,\n\t\t\t\traw: markup.slice(cursor, end),\n\t\t\t});\n\t\t}\n\t};\n\n\tfor (const match of markup.matchAll(TOKEN_PATTERN)) {\n\t\taddText(match.index);\n\t\tcursor = match.index + match[0].length;\n\t\tconst [, endName, startName, attrs = '', selfClosing] = match;\n\t\tif (endName) {\n\t\t\tlet at = stack.length - 1;\n\t\t\twhile (at >= 0 && stack[at]?.name !== endName) at -= 1;\n\t\t\tif (at === -1) continue;\n\t\t\tconst element = stack[at] as ContentElement;\n\t\t\telement.close = { start: offset + match.index, end: offset + cursor };\n\t\t\tstack.length = at;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!startName) continue;\n\n\t\tconst parent = stack[stack.length - 1];\n\t\tif (!parent && root) continue;\n\t\tconst colon = startName.indexOf(':');\n\t\tconst prefix = colon === -1 ? undefined : startName.slice(0, colon);\n\t\tconst local = startName.slice(colon + 1);\n\t\tconst attributes = new Map(\n\t\t\t[...attrs.matchAll(ATTRIBUTE_PATTERN)].map((attribute) => [\n\t\t\t\t(attribute[1] as string).toLowerCase(),\n\t\t\t\tattribute[2],\n\t\t\t])\n\t\t);\n\t\tconst xmlns = attributes.get('xmlns');\n\t\tconst defaultSsml =\n\t\t\txmlns === undefined ? (parent?.defaultSsml ?? false) : SSML_NAMESPACES.has(unquote(xmlns));\n\t\tconst element = {\n\t\t\tkind: 'element' as const,\n\t\t\tname: startName,\n\t\t\tlocal,\n\t\t\tattrs,\n\t\t\tattributes,\n\t\t\tselfClosing: Boolean(selfClosing),\n\t\t\topen: { start: offset + match.index, end: offset + cursor },\n\t\t\t...(parent ? { parent } : {}),\n\t\t\tchildren: [],\n\t\t\tssml: prefix === undefined ? defaultSsml : ssmlPrefixes.has(prefix),\n\t\t\teditedAttrs: attrs,\n\t\t\tadded: [],\n\t\t\tdefaultSsml,\n\t\t};\n\t\tif (parent) parent.children.push(element);\n\t\telse root = element;\n\t\tif (!element.selfClosing && !VOID_ELEMENTS.has(local.toLowerCase())) stack.push(element);\n\t}\n\treturn root;\n}\n\n/** Restate hiding classes, read-aloud suppression and content language in the start tag. */\nfunction editStartTag(\n\telement: ContentElement,\n\thidingStyles: boolean,\n\tdocumentDirection: TextDirection\n): void {\n\tconst { attributes } = element;\n\tconst classes = unquote(attributes.get('class')).split(/\\s+/);\n\tconst hiding = Object.entries(hidingStyles ? HIDING_STYLES : {})\n\t\t.filter(([hidingClass]) => classes.includes(hidingClass))\n\t\t.map(([, style]) => style);\n\tif (hiding.length > 0) {\n\t\tconst style = attributes.get('style');\n\t\tif (style === undefined) {\n\t\t\telement.added.push(`style=\"${hiding.join(';')}\"`);\n\t\t} else {\n\t\t\tconst quote = style.startsWith(\"'\") ? \"'\" : '\"';\n\t\t\tconst current = unquote(style).trim().replace(/;$/, '');\n\t\t\tconst merged = [current, ...hiding].filter(Boolean).join(';');\n\t\t\telement.editedAttrs = element.editedAttrs.replace(\n\t\t\t\t/(\\sstyle\\s*=\\s*)(\"[^\"]*\"|'[^']*'|[^\\s\"'>]+)/i,\n\t\t\t\t`$1${quote}${merged}${quote}`\n\t\t\t);\n\t\t}\n\t}\n\n\tconst language = attributes.get('xml:lang');\n\tif (language !== undefined) {\n\t\tif (!attributes.has('lang')) element.added.push(`lang=${quoted(language)}`);\n\t\tconst direction = languageDirection(unquote(language));\n\t\tif (!attributes.has('dir') && direction !== surroundingDirection(element, documentDirection)) {\n\t\t\telement.added.push(`dir=\"${direction}\"`);\n\t\t}\n\t}\n\n\tconst suppress = attributes.get('data-qti-suppress-tts');\n\tif (suppress !== undefined && !attributes.has('data-tts-suppress')) {\n\t\telement.added.push(`data-tts-suppress=${quoted(suppress)}`);\n\t}\n}\n\n/** The direction `element` inherits: its nearest ancestor's `dir` or language, else the document's. */\nfunction surroundingDirection(element: ContentElement, documentDirection: TextDirection): TextDirection {\n\tfor (let ancestor = element.parent; ancestor; ancestor = ancestor.parent) {\n\t\tconst dir = unquote(ancestor.attributes.get('dir')).trim().toLowerCase();\n\t\tif (dir === 'rtl' || dir === 'ltr') return dir;\n\t\tconst language = ancestor.attributes.get('xml:lang') ?? ancestor.attributes.get('lang');\n\t\tif (language !== undefined) return languageDirection(unquote(language));\n\t}\n\treturn documentDirection;\n}\n\n/**\n * The span of `element`'s text that `range` counts, when it lies inside one text node. Each\n * whitespace run counts as one character, and whitespace before the first word not at all.\n */\nfunction locateRange(\n\telement: ContentElement,\n\trange: TextRange\n): (Span & { text: ContentText }) | undefined {\n\tconst characters: Array<Span & { text: ContentText; space: boolean }> = [];\n\tlet space: (Span & { text: ContentText }) | undefined;\n\tfor (const text of textsOf(element)) {\n\t\tfor (const unit of text.raw.matchAll(TEXT_UNIT_PATTERN)) {\n\t\t\tconst start = text.start + unit.index;\n\t\t\tconst span = { text, start, end: start + unit[0].length };\n\t\t\tif (XML_WHITESPACE.test(unit[0])) {\n\t\t\t\tif (characters.length > 0) space ??= span;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (space) characters.push({ ...space, space: true });\n\t\t\tspace = undefined;\n\t\t\tcharacters.push({ ...span, space: false });\n\t\t}\n\t}\n\n\tlet first = range.start - 1;\n\tlet last = range.stop - 1;\n\tif (range.unit === 'word') {\n\t\tconst words: Array<[number, number]> = [];\n\t\tcharacters.forEach((character, index) => {\n\t\t\tif (character.space) return;\n\t\t\tconst word = words[words.length - 1];\n\t\t\tif (word && word[1] === index - 1) word[1] = index;\n\t\t\telse words.push([index, index]);\n\t\t});\n\t\tfirst = words[range.start - 1]?.[0] ?? Number.NaN;\n\t\tlast = words[range.stop - 1]?.[1] ?? Number.NaN;\n\t}\n\tconst from = characters[first];\n\tconst to = characters[last];\n\tif (!from || !to || last < first || from.text !== to.text) return undefined;\n\treturn { text: from.text, start: from.start, end: to.end };\n}\n\n/** Two ranges that overlap without one holding the other. */\nfunction crosses(a: Span, b: Span): boolean {\n\tconst overlap = a.start < b.end && b.start < a.end;\n\tconst nested = (a.start <= b.start && b.end <= a.end) || (b.start <= a.start && a.end <= b.end);\n\treturn overlap && !nested;\n}\n\n/** Content as SSML: its SSML elements without namespace prefixes, other markup reduced to text. */\nfunction ssmlMarkup(node: ContentNode): string {\n\tif (node.kind === 'text') return escapeText(parse(node.raw).textContent);\n\tconst classes = unquote(node.attributes.get('class')).split(/\\s+/);\n\tif (\n\t\tclasses.includes('qti-hidden') ||\n\t\tnode.attributes.has('data-qti-suppress-tts') ||\n\t\tnode.attributes.has('data-tts-suppress')\n\t) {\n\t\treturn '';\n\t}\n\tconst content = node.children.map(ssmlMarkup).join('');\n\tif (!node.ssml) return content;\n\tconst attrs = node.attrs.replace(XMLNS_ATTRIBUTE_PATTERN, '');\n\treturn node.selfClosing\n\t\t? `<${node.local}${attrs}/>`\n\t\t: `<${node.local}${attrs}>${content}</${node.local}>`;\n}\n\n/** The document with every edited tag replaced and every wrap inserted. */\nfunction rendered(qtiXml: string, elements: ContentElement[], wraps: Wrap[]): string {\n\tinterface Edit extends Span {\n\t\ttext: string;\n\t\t/** Same-position order: closing wraps, then opening ones, then tag replacements. */\n\t\tphase: 0 | 1 | 2;\n\t\twrap?: Wrap;\n\t}\n\tconst edits: Edit[] = [];\n\tfor (const element of elements) {\n\t\tif (element.ssml) {\n\t\t\tedits.push({ ...element.open, text: '', phase: 2 });\n\t\t\tif (element.close) edits.push({ ...element.close, text: '', phase: 2 });\n\t\t} else if (element.added.length > 0 || element.editedAttrs !== element.attrs) {\n\t\t\tconst added = element.added.map((attribute) => ` ${attribute}`).join('');\n\t\t\tconst end = element.selfClosing ? ' />' : '>';\n\t\t\tedits.push({\n\t\t\t\t...element.open,\n\t\t\t\ttext: `<${element.name}${element.editedAttrs}${added}${end}`,\n\t\t\t\tphase: 2,\n\t\t\t});\n\t\t}\n\t}\n\tfor (const wrap of wraps) {\n\t\tedits.push({\n\t\t\tstart: wrap.start,\n\t\t\tend: wrap.start,\n\t\t\ttext: `<${wrap.tag} data-catalog-idref=\"${escapeAttribute(wrap.idref)}\">`,\n\t\t\tphase: 1,\n\t\t\twrap,\n\t\t});\n\t\tedits.push({ start: wrap.end, end: wrap.end, text: `</${wrap.tag}>`, phase: 0, wrap });\n\t}\n\t// Wraps nest: at one position the innermost closes first and the outermost opens first.\n\tedits.sort((a, b) => {\n\t\tif (a.start !== b.start) return a.start - b.start;\n\t\tif (a.phase !== b.phase) return a.phase - b.phase;\n\t\tif (!a.wrap || !b.wrap) return 0;\n\t\tif (a.phase === 0) return b.wrap.start - a.wrap.start || b.wrap.seq - a.wrap.seq;\n\t\treturn b.wrap.end - a.wrap.end || a.wrap.seq - b.wrap.seq;\n\t});\n\n\tlet xml = '';\n\tlet cursor = 0;\n\tfor (const edit of edits) {\n\t\txml += qtiXml.slice(cursor, edit.start) + edit.text;\n\t\tcursor = edit.end;\n\t}\n\treturn xml + qtiXml.slice(cursor);\n}\n\nfunction descendants(element: ContentElement): ContentElement[] {\n\treturn [\n\t\telement,\n\t\t...element.children.flatMap((child) => (child.kind === 'element' ? descendants(child) : [])),\n\t];\n}\n\nfunction textsOf(element: ContentElement): ContentText[] {\n\treturn element.children.flatMap((child) => (child.kind === 'text' ? [child] : textsOf(child)));\n}\n\nfunction ssmlPrefixesOf(qtiXml: string): Set<string> {\n\tconst prefixes = new Set(['ssml']);\n\tfor (const match of qtiXml.matchAll(SSML_PREFIX_PATTERN)) {\n\t\tif (SSML_NAMESPACES.has(match[3] as string)) prefixes.add(match[1] as string);\n\t}\n\treturn prefixes;\n}\n\n/** An attribute's value with its entities decoded, as the markup's readers see it. */\nfunction decodedAttribute(attrs: string, name: string): string | undefined {\n\tconst element = parse(`<x${attrs}></x>`).firstChild as HTMLElement | null;\n\treturn element?.getAttribute(name);\n}\n\nfunction unquote(value: string | undefined): string {\n\tif (!value) return '';\n\treturn /^([\"']).*\\1$/s.test(value) ? value.slice(1, -1) : value;\n}\n\nfunction quoted(value: string): string {\n\treturn /^[\"']/.test(value) ? value : `\"${value}\"`;\n}\n\n/**\n * Escape a value for use inside XML text content: escapes `& < >`, quotes stay as authored.\n * The one text escaper of the accessibility module family; apip.ts and catalog-info.ts use it too.\n */\nexport function escapeText(text: string): string {\n\treturn text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/**\n * Escape a value for use inside an XML attribute delimited by either quote style:\n * escapes `& < > \" '` so the result is safe in `\"...\"` and `'...'` alike.\n */\nexport function escapeXmlAttribute(value: string): string {\n\treturn escapeText(value).replace(/\"/g, '&quot;').replace(/'/g, '&apos;');\n}\n\nfunction escapeAttribute(value: string): string {\n\treturn escapeXmlAttribute(value);\n}\n"]}
@@ -75,3 +75,5 @@ export interface ProcessFeedbackInlineOptions {
75
75
  * ```
76
76
  */
77
77
  export declare function processFeedbackInline(html: string, options: ProcessFeedbackInlineOptions): string;
78
+ /** An attribute in either QTI spelling, e.g. `outcomeIdentifier` or `outcome-identifier`. */
79
+ export declare function feedbackInlineAttr(attrs: string, name: string): string | null;
@@ -125,11 +125,27 @@ function feedbackElements(html) {
125
125
  // An unclosed element is left as written, with any feedback inside it.
126
126
  return roots;
127
127
  }
128
+ /**
129
+ * The attribute matchers for one attribute name, in both QTI spellings, compiled once and
130
+ * shared. Feedback runs on every keystroke of an interaction, and the set of attribute names is
131
+ * a handful, so the cache never grows meaningfully; past the bound it is cleared. The compiled
132
+ * RegExps carry no state: no `g`/`y` flag, so `lastIndex` is never used.
133
+ */
134
+ const FEEDBACK_ATTR_MATCHER_CACHE_LIMIT = 64;
135
+ const feedbackAttrMatchers = new Map();
128
136
  /** An attribute in either QTI spelling, e.g. `outcomeIdentifier` or `outcome-identifier`. */
129
- function feedbackInlineAttr(attrs, name) {
130
- const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
131
- for (const spelling of kebab === name ? [name] : [name, kebab]) {
132
- const match = new RegExp(`(?:^|\\s)${spelling}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, 'i').exec(attrs);
137
+ export function feedbackInlineAttr(attrs, name) {
138
+ let matchers = feedbackAttrMatchers.get(name);
139
+ if (!matchers) {
140
+ const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
141
+ const spellings = kebab === name ? [name] : [name, kebab];
142
+ matchers = spellings.map((spelling) => new RegExp(`(?:^|\\s)${spelling}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, 'i'));
143
+ if (feedbackAttrMatchers.size >= FEEDBACK_ATTR_MATCHER_CACHE_LIMIT)
144
+ feedbackAttrMatchers.clear();
145
+ feedbackAttrMatchers.set(name, matchers);
146
+ }
147
+ for (const matcher of matchers) {
148
+ const match = matcher.exec(attrs);
133
149
  if (match)
134
150
  return match[1] ?? match[2] ?? '';
135
151
  }
@@ -1 +1 @@
1
- {"version":3,"file":"feedback-text.js","sourceRoot":"","sources":["../../src/feedback/feedback-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAA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CAAC;;gBACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;IACD,uEAAuE;IACvE,OAAO,KAAK,CAAC;AACd,CAAC;AAED,6FAA6F;AAC7F,SAAS,kBAAkB,CAAC,KAAa,EAAE,IAAY;IACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC7E,KAAK,MAAM,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,YAAY,QAAQ,kCAAkC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClG,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * Feedback text utilities for QTI items\n *\n * NOTE: The cleanFeedbackText function contains vendor-specific transforms\n * for content that uses semicolons after \"Correct\" and \"Incorrect\" labels.\n * This is common in some QTI authoring tools but not part of the QTI specification.\n *\n * To customize this behavior for your vendor's content, you can:\n * 1. Modify the patterns in this file\n * 2. Create a vendor-specific transform plugin (see VENDOR-TRANSFORM-PLUGIN-GUIDE.md)\n * 3. Pass custom transforms via the feedbackTransforms option\n */\n\nimport { isShownByIdentifier } from './visibility.js';\n\n/**\n * Text pattern replacement for feedback content\n */\nexport interface FeedbackTransform {\n\t/** Regular expression to match the pattern */\n\tpattern: RegExp;\n\t/** Replacement string (can use capture groups like $1, $2) */\n\treplacement: string;\n}\n\n/**\n * Default feedback text transforms\n * These are vendor-specific patterns commonly found in certain QTI authoring tools\n */\nexport const DEFAULT_FEEDBACK_TRANSFORMS: FeedbackTransform[] = [\n\t// Remove semicolons after \"Incorrect\" (with or without <strong> tags)\n\t{ pattern: /<strong>Incorrect;<\\/strong>/gi, replacement: '<strong>Incorrect</strong> ' },\n\t{ pattern: /Incorrect;/gi, replacement: 'Incorrect ' },\n\n\t// Remove semicolons after \"Correct\" (with or without <strong> tags)\n\t{ pattern: /<strong>Correct;<\\/strong>/gi, replacement: '<strong>Correct</strong> ' },\n\t{ pattern: /Correct;/gi, replacement: 'Correct ' },\n];\n\n/**\n * Clean up feedback text formatting using configurable transforms\n *\n * @param content - The feedback content HTML string\n * @param transforms - Optional custom transforms (defaults to DEFAULT_FEEDBACK_TRANSFORMS)\n * @returns Cleaned feedback content\n */\nexport function cleanFeedbackText(\n\tcontent: string,\n\ttransforms: FeedbackTransform[] = DEFAULT_FEEDBACK_TRANSFORMS\n): string {\n\tif (!content) return content;\n\n\tlet result = content;\n\tfor (const transform of transforms) {\n\t\tresult = result.replace(transform.pattern, transform.replacement);\n\t}\n\n\treturn result;\n}\n\n/**\n * Default outcome identifier for feedback display\n * This can be overridden if your QTI content uses a different identifier\n */\nexport const DEFAULT_FEEDBACK_OUTCOME_ID = 'FEEDBACK';\n\n/**\n * Options for processing feedbackInline elements\n */\nexport interface ProcessFeedbackInlineOptions {\n\t/** Outcome values from response processing */\n\toutcomeValues: Record<string, any>;\n\t/** Whether to apply feedback text cleaning heuristics */\n\tapplyHeuristics?: boolean;\n\t/** Whether to wrap inline feedback content with qti-feedback-inline span */\n\twrapWithSpan?: boolean;\n\t/** Custom feedback transforms (defaults to DEFAULT_FEEDBACK_TRANSFORMS) */\n\ttransforms?: FeedbackTransform[];\n\t/** Drop every feedback element whatever the outcomes. */\n\thideAll?: boolean;\n}\n\n/**\n * Process feedbackInline and feedbackBlock elements in QTI content\n *\n * Shows or hides each `feedbackInline` and `feedbackBlock` (`qti-feedback-inline` and\n * `qti-feedback-block` in QTI 3) by the shared visibility rule: its `identifier` against the\n * outcome value, by membership for a container, inverted by `showHide=\"hide\"`. Nested feedback\n * resolves inside shown feedback; hidden feedback drops with everything inside it. Markup outside\n * feedback elements is left as it is.\n *\n * @param html - The HTML content containing feedbackInline elements\n * @param options - Processing options\n * @returns Modified HTML with processed feedbackInline elements\n *\n * @example\n * ```typescript\n * const html = processFeedbackInline(content, {\n * outcomeValues: { FEEDBACK: 'choiceA' },\n * applyHeuristics: true,\n * wrapWithSpan: true\n * });\n * ```\n */\nexport function processFeedbackInline(\n\thtml: string,\n\toptions: ProcessFeedbackInlineOptions\n): string {\n\tif (!html) return html;\n\tconst feedback = feedbackElements(html);\n\tif (feedback.length === 0) return html;\n\n\tconst { outcomeValues, applyHeuristics = false, wrapWithSpan = false, transforms, hideAll = false } = options;\n\tconst render = (start: number, end: number, elements: readonly FeedbackElement[]): string => {\n\t\tlet out = '';\n\t\tlet position = start;\n\t\tfor (const element of elements) {\n\t\t\tout += html.slice(position, element.openStart);\n\t\t\tposition = element.closeEnd;\n\t\t\tconst outcomeId = feedbackInlineAttr(element.attrs, 'outcomeIdentifier');\n\t\t\tconst feedbackId = feedbackInlineAttr(element.attrs, 'identifier');\n\t\t\tif (hideAll || outcomeId === null || feedbackId === null) continue;\n\t\t\tconst showHide = feedbackInlineAttr(element.attrs, 'showHide');\n\t\t\tif (!isShownByIdentifier(outcomeValues[outcomeId], feedbackId, showHide)) continue;\n\n\t\t\tlet content = render(element.openEnd, element.closeStart, element.children);\n\t\t\tif (applyHeuristics) content = cleanFeedbackText(content, transforms);\n\t\t\tout += wrapWithSpan && !element.block ? ` <span class=\"qti-feedback-inline\">${content}</span>` : content;\n\t\t}\n\t\treturn out + html.slice(position, end);\n\t};\n\treturn render(0, html.length, feedback);\n}\n\nconst FEEDBACK_TAG = /<(\\/?)(feedbackInline|qti-feedback-inline|feedbackBlock|qti-feedback-block)\\b([^>]*?)(\\/?)>/gi;\n\ninterface FeedbackElement {\n\treadonly block: boolean;\n\treadonly attrs: string;\n\treadonly openStart: number;\n\treadonly openEnd: number;\n\tcloseStart: number;\n\tcloseEnd: number;\n\treadonly children: FeedbackElement[];\n}\n\n/** The top-level feedback elements in `html`, each with the feedback nested inside it. */\nfunction feedbackElements(html: string): FeedbackElement[] {\n\tconst roots: FeedbackElement[] = [];\n\tconst open: FeedbackElement[] = [];\n\tconst add = (element: FeedbackElement) => (open[open.length - 1]?.children ?? roots).push(element);\n\tfor (const match of html.matchAll(FEEDBACK_TAG)) {\n\t\tconst [tag, closing, name = '', attrs = '', selfClosing] = match;\n\t\tconst start = match.index;\n\t\tconst end = start + tag.length;\n\t\tif (closing) {\n\t\t\tconst element = open.pop();\n\t\t\tif (!element) continue;\n\t\t\telement.closeStart = start;\n\t\t\telement.closeEnd = end;\n\t\t\tadd(element);\n\t\t} else {\n\t\t\tconst block = /block$/i.test(name);\n\t\t\tconst element: FeedbackElement = { block, attrs, openStart: start, openEnd: end, closeStart: end, closeEnd: end, children: [] };\n\t\t\tif (selfClosing) add(element);\n\t\t\telse open.push(element);\n\t\t}\n\t}\n\t// An unclosed element is left as written, with any feedback inside it.\n\treturn roots;\n}\n\n/** An attribute in either QTI spelling, e.g. `outcomeIdentifier` or `outcome-identifier`. */\nfunction feedbackInlineAttr(attrs: string, name: string): string | null {\n\tconst kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\tfor (const spelling of kebab === name ? [name] : [name, kebab]) {\n\t\tconst match = new RegExp(`(?:^|\\\\s)${spelling}\\\\s*=\\\\s*(?:\"([^\"]*)\"|'([^']*)')`, 'i').exec(attrs);\n\t\tif (match) return match[1] ?? match[2] ?? '';\n\t}\n\treturn null;\n}\n"]}
1
+ {"version":3,"file":"feedback-text.js","sourceRoot":"","sources":["../../src/feedback/feedback-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAYtD;;;GAGG;AACH,MAAM,CAAC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backText function contains vendor-specific transforms\n * for content that uses semicolons after \"Correct\" and \"Incorrect\" labels.\n * This is common in some QTI authoring tools but not part of the QTI specification.\n *\n * To customize this behavior for your vendor's content, you can:\n * 1. Modify the patterns in this file\n * 2. Create a vendor-specific transform plugin (see VENDOR-TRANSFORM-PLUGIN-GUIDE.md)\n * 3. Pass custom transforms via the feedbackTransforms option\n */\n\nimport { isShownByIdentifier } from './visibility.js';\n\n/**\n * Text pattern replacement for feedback content\n */\nexport interface FeedbackTransform {\n\t/** Regular expression to match the pattern */\n\tpattern: RegExp;\n\t/** Replacement string (can use capture groups like $1, $2) */\n\treplacement: string;\n}\n\n/**\n * Default feedback text transforms\n * These are vendor-specific patterns commonly found in certain QTI authoring tools\n */\nexport const DEFAULT_FEEDBACK_TRANSFORMS: FeedbackTransform[] = [\n\t// Remove semicolons after \"Incorrect\" (with or without <strong> tags)\n\t{ pattern: /<strong>Incorrect;<\\/strong>/gi, replacement: '<strong>Incorrect</strong> ' },\n\t{ pattern: /Incorrect;/gi, replacement: 'Incorrect ' },\n\n\t// Remove semicolons after \"Correct\" (with or without <strong> tags)\n\t{ pattern: /<strong>Correct;<\\/strong>/gi, replacement: '<strong>Correct</strong> ' },\n\t{ pattern: /Correct;/gi, replacement: 'Correct ' },\n];\n\n/**\n * Clean up feedback text formatting using configurable transforms\n *\n * @param content - The feedback content HTML string\n * @param transforms - Optional custom transforms (defaults to DEFAULT_FEEDBACK_TRANSFORMS)\n * @returns Cleaned feedback content\n */\nexport function cleanFeedbackText(\n\tcontent: string,\n\ttransforms: FeedbackTransform[] = DEFAULT_FEEDBACK_TRANSFORMS\n): string {\n\tif (!content) return content;\n\n\tlet result = content;\n\tfor (const transform of transforms) {\n\t\tresult = result.replace(transform.pattern, transform.replacement);\n\t}\n\n\treturn result;\n}\n\n/**\n * Default outcome identifier for feedback display\n * This can be overridden if your QTI content uses a different identifier\n */\nexport const DEFAULT_FEEDBACK_OUTCOME_ID = 'FEEDBACK';\n\n/**\n * Options for processing feedbackInline elements\n */\nexport interface ProcessFeedbackInlineOptions {\n\t/** Outcome values from response processing */\n\toutcomeValues: Record<string, any>;\n\t/** Whether to apply feedback text cleaning heuristics */\n\tapplyHeuristics?: boolean;\n\t/** Whether to wrap inline feedback content with qti-feedback-inline span */\n\twrapWithSpan?: boolean;\n\t/** Custom feedback transforms (defaults to DEFAULT_FEEDBACK_TRANSFORMS) */\n\ttransforms?: FeedbackTransform[];\n\t/** Drop every feedback element whatever the outcomes. */\n\thideAll?: boolean;\n}\n\n/**\n * Process feedbackInline and feedbackBlock elements in QTI content\n *\n * Shows or hides each `feedbackInline` and `feedbackBlock` (`qti-feedback-inline` and\n * `qti-feedback-block` in QTI 3) by the shared visibility rule: its `identifier` against the\n * outcome value, by membership for a container, inverted by `showHide=\"hide\"`. Nested feedback\n * resolves inside shown feedback; hidden feedback drops with everything inside it. Markup outside\n * feedback elements is left as it is.\n *\n * @param html - The HTML content containing feedbackInline elements\n * @param options - Processing options\n * @returns Modified HTML with processed feedbackInline elements\n *\n * @example\n * ```typescript\n * const html = processFeedbackInline(content, {\n * outcomeValues: { FEEDBACK: 'choiceA' },\n * applyHeuristics: true,\n * wrapWithSpan: true\n * });\n * ```\n */\nexport function processFeedbackInline(\n\thtml: string,\n\toptions: ProcessFeedbackInlineOptions\n): string {\n\tif (!html) return html;\n\tconst feedback = feedbackElements(html);\n\tif (feedback.length === 0) return html;\n\n\tconst { outcomeValues, applyHeuristics = false, wrapWithSpan = false, transforms, hideAll = false } = options;\n\tconst render = (start: number, end: number, elements: readonly FeedbackElement[]): string => {\n\t\tlet out = '';\n\t\tlet position = start;\n\t\tfor (const element of elements) {\n\t\t\tout += html.slice(position, element.openStart);\n\t\t\tposition = element.closeEnd;\n\t\t\tconst outcomeId = feedbackInlineAttr(element.attrs, 'outcomeIdentifier');\n\t\t\tconst feedbackId = feedbackInlineAttr(element.attrs, 'identifier');\n\t\t\tif (hideAll || outcomeId === null || feedbackId === null) continue;\n\t\t\tconst showHide = feedbackInlineAttr(element.attrs, 'showHide');\n\t\t\tif (!isShownByIdentifier(outcomeValues[outcomeId], feedbackId, showHide)) continue;\n\n\t\t\tlet content = render(element.openEnd, element.closeStart, element.children);\n\t\t\tif (applyHeuristics) content = cleanFeedbackText(content, transforms);\n\t\t\tout += wrapWithSpan && !element.block ? ` <span class=\"qti-feedback-inline\">${content}</span>` : content;\n\t\t}\n\t\treturn out + html.slice(position, end);\n\t};\n\treturn render(0, html.length, feedback);\n}\n\nconst FEEDBACK_TAG = /<(\\/?)(feedbackInline|qti-feedback-inline|feedbackBlock|qti-feedback-block)\\b([^>]*?)(\\/?)>/gi;\n\ninterface FeedbackElement {\n\treadonly block: boolean;\n\treadonly attrs: string;\n\treadonly openStart: number;\n\treadonly openEnd: number;\n\tcloseStart: number;\n\tcloseEnd: number;\n\treadonly children: FeedbackElement[];\n}\n\n/** The top-level feedback elements in `html`, each with the feedback nested inside it. */\nfunction feedbackElements(html: string): FeedbackElement[] {\n\tconst roots: FeedbackElement[] = [];\n\tconst open: FeedbackElement[] = [];\n\tconst add = (element: FeedbackElement) => (open[open.length - 1]?.children ?? roots).push(element);\n\tfor (const match of html.matchAll(FEEDBACK_TAG)) {\n\t\tconst [tag, closing, name = '', attrs = '', selfClosing] = match;\n\t\tconst start = match.index;\n\t\tconst end = start + tag.length;\n\t\tif (closing) {\n\t\t\tconst element = open.pop();\n\t\t\tif (!element) continue;\n\t\t\telement.closeStart = start;\n\t\t\telement.closeEnd = end;\n\t\t\tadd(element);\n\t\t} else {\n\t\t\tconst block = /block$/i.test(name);\n\t\t\tconst element: FeedbackElement = { block, attrs, openStart: start, openEnd: end, closeStart: end, closeEnd: end, children: [] };\n\t\t\tif (selfClosing) add(element);\n\t\t\telse open.push(element);\n\t\t}\n\t}\n\t// An unclosed element is left as written, with any feedback inside it.\n\treturn roots;\n}\n\n/**\n * The attribute matchers for one attribute name, in both QTI spellings, compiled once and\n * shared. Feedback runs on every keystroke of an interaction, and the set of attribute names is\n * a handful, so the cache never grows meaningfully; past the bound it is cleared. The compiled\n * RegExps carry no state: no `g`/`y` flag, so `lastIndex` is never used.\n */\nconst FEEDBACK_ATTR_MATCHER_CACHE_LIMIT = 64;\n\nconst feedbackAttrMatchers = new Map<string, RegExp[]>();\n\n/** An attribute in either QTI spelling, e.g. `outcomeIdentifier` or `outcome-identifier`. */\nexport function feedbackInlineAttr(attrs: string, name: string): string | null {\n\tlet matchers = feedbackAttrMatchers.get(name);\n\tif (!matchers) {\n\t\tconst kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\t\tconst spellings = kebab === name ? [name] : [name, kebab];\n\t\tmatchers = spellings.map((spelling) => new RegExp(`(?:^|\\\\s)${spelling}\\\\s*=\\\\s*(?:\"([^\"]*)\"|'([^']*)')`, 'i'));\n\t\tif (feedbackAttrMatchers.size >= FEEDBACK_ATTR_MATCHER_CACHE_LIMIT) feedbackAttrMatchers.clear();\n\t\tfeedbackAttrMatchers.set(name, matchers);\n\t}\n\tfor (const matcher of matchers) {\n\t\tconst match = matcher.exec(attrs);\n\t\tif (match) return match[1] ?? match[2] ?? '';\n\t}\n\treturn null;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -7,9 +7,10 @@ export { Qti3AttributeNameMapper } from './element-mapper/Qti3AttributeNameMappe
7
7
  export { QTI2_PROMPT_BEARING_INTERACTIONS, QTI3_ATTRIBUTE_TO_QTI2, } from './element-mapper/qti3-attribute-map.js';
8
8
  export { convertQti2ToQti3, QTI3_ASI_SCHEMA_LOCATION, QTI3_NAMESPACE, QTI3_RPTEMPLATE_BASE, } from './element-mapper/qti2-to-qti3.js';
9
9
  export { isShownByIdentifier, matchesIdentifier } from './feedback/visibility.js';
10
- export { cleanFeedbackText, processFeedbackInline, DEFAULT_FEEDBACK_OUTCOME_ID, DEFAULT_FEEDBACK_TRANSFORMS, type FeedbackTransform, type ProcessFeedbackInlineOptions, } from './feedback/feedback-text.js';
11
- export { detectQtiVersion } from './version-detection/detectQtiVersion.js';
12
- export type { QtiVersion } from './version-detection/detectQtiVersion.js';
10
+ export { cleanFeedbackText, feedbackInlineAttr, processFeedbackInline, DEFAULT_FEEDBACK_OUTCOME_ID, DEFAULT_FEEDBACK_TRANSFORMS, type FeedbackTransform, type ProcessFeedbackInlineOptions, } from './feedback/feedback-text.js';
11
+ export { detectQtiVersion, detectQtiVersionDetailed } from './version-detection/detectQtiVersion.js';
12
+ export type { QtiVersion, QtiVersionDetection, QtiVersionDetectionBasis, QtiVersionDetectionConfidence, } from './version-detection/detectQtiVersion.js';
13
+ export { isQtiVocabularyElement, QTI2_ELEMENTS, QTI2_XHTML_ELEMENTS, QTI3_ELEMENTS, type QtiVocabularyVersion, } from './version-detection/vocabulary.js';
13
14
  export { getAttribute, getBooleanAttribute, getNumberAttribute, hasAttribute, toCamelCase, toKebabCase, } from './xml/attributes.js';
14
15
  export { assignProps, type AssignPropsOptions } from './dom/assignProps.js';
15
16
  export { createSvelteMountController, type SvelteMountController, type SvelteMountControllerOptions, } from './dom/svelteMountController.js';
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@ export { QTI2_PROMPT_BEARING_INTERACTIONS, QTI3_ATTRIBUTE_TO_QTI2, } from './ele
6
6
  export { convertQti2ToQti3, QTI3_ASI_SCHEMA_LOCATION, QTI3_NAMESPACE, QTI3_RPTEMPLATE_BASE, } from './element-mapper/qti2-to-qti3.js';
7
7
  // Feedback and template visibility
8
8
  export { isShownByIdentifier, matchesIdentifier } from './feedback/visibility.js';
9
- export { cleanFeedbackText, processFeedbackInline, DEFAULT_FEEDBACK_OUTCOME_ID, DEFAULT_FEEDBACK_TRANSFORMS, } from './feedback/feedback-text.js';
9
+ export { cleanFeedbackText, feedbackInlineAttr, processFeedbackInline, DEFAULT_FEEDBACK_OUTCOME_ID, DEFAULT_FEEDBACK_TRANSFORMS, } from './feedback/feedback-text.js';
10
10
  // Version detection
11
- export { detectQtiVersion } from './version-detection/detectQtiVersion.js';
11
+ export { detectQtiVersion, detectQtiVersionDetailed } from './version-detection/detectQtiVersion.js';
12
+ export { isQtiVocabularyElement, QTI2_ELEMENTS, QTI2_XHTML_ELEMENTS, QTI3_ELEMENTS, } from './version-detection/vocabulary.js';
12
13
  // XML attribute utilities
13
14
  export { getAttribute, getBooleanAttribute, getNumberAttribute, hasAttribute, toCamelCase, toKebabCase, } from './xml/attributes.js';
14
15
  // DOM utility helpers shared across player packages
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAIlF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EACN,gCAAgC,EAChC,sBAAsB,GACtB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACN,iBAAiB,EACjB,wBAAwB,EACxB,cAAc,EACd,oBAAoB,GACpB,MAAM,kCAAkC,CAAC;AAE1C,mCAAmC;AACnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,GAG3B,MAAM,6BAA6B,CAAC;AAErC,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,0BAA0B;AAC1B,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,WAAW,GACX,MAAM,qBAAqB,CAAC;AAE7B,oDAAoD;AACpD,OAAO,EAAE,WAAW,EAA2B,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EACN,2BAA2B,GAG3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhE,oBAAoB;AACpB,OAAO,EAAE,iBAAiB,EAAsB,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,iBAAiB;AACjB,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,+BAA+B,EAC/B,MAAM,EACN,MAAM,GAGN,MAAM,qBAAqB,CAAC","sourcesContent":["// Element name mapping\nexport type { ElementNameMapper } from './element-mapper/ElementNameMapper.js';\nexport { Qti2xElementNameMapper } from './element-mapper/Qti2xElementNameMapper.js';\nexport { Qti3ElementNameMapper } from './element-mapper/Qti3ElementNameMapper.js';\n\n// Attribute name mapping\nexport type { AttributeNameMapper } from './element-mapper/AttributeNameMapper.js';\nexport { Qti2xAttributeNameMapper } from './element-mapper/Qti2xAttributeNameMapper.js';\nexport { Qti3AttributeNameMapper } from './element-mapper/Qti3AttributeNameMapper.js';\nexport {\n\tQTI2_PROMPT_BEARING_INTERACTIONS,\n\tQTI3_ATTRIBUTE_TO_QTI2,\n} from './element-mapper/qti3-attribute-map.js';\nexport {\n\tconvertQti2ToQti3,\n\tQTI3_ASI_SCHEMA_LOCATION,\n\tQTI3_NAMESPACE,\n\tQTI3_RPTEMPLATE_BASE,\n} from './element-mapper/qti2-to-qti3.js';\n\n// Feedback and template visibility\nexport { isShownByIdentifier, matchesIdentifier } from './feedback/visibility.js';\nexport {\n\tcleanFeedbackText,\n\tprocessFeedbackInline,\n\tDEFAULT_FEEDBACK_OUTCOME_ID,\n\tDEFAULT_FEEDBACK_TRANSFORMS,\n\ttype FeedbackTransform,\n\ttype ProcessFeedbackInlineOptions,\n} from './feedback/feedback-text.js';\n\n// Version detection\nexport { detectQtiVersion } from './version-detection/detectQtiVersion.js';\nexport type { QtiVersion } from './version-detection/detectQtiVersion.js';\n\n// XML attribute utilities\nexport {\n\tgetAttribute,\n\tgetBooleanAttribute,\n\tgetNumberAttribute,\n\thasAttribute,\n\ttoCamelCase,\n\ttoKebabCase,\n} from './xml/attributes.js';\n\n// DOM utility helpers shared across player packages\nexport { assignProps, type AssignPropsOptions } from './dom/assignProps.js';\nexport {\n\tcreateSvelteMountController,\n\ttype SvelteMountController,\n\ttype SvelteMountControllerOptions,\n} from './dom/svelteMountController.js';\nexport { touchDrag, touchDragStyles } from './dom/touchDrag.js';\n\n// Writing direction\nexport { languageDirection, type TextDirection } from './language/direction.js';\nexport { warnOnce } from './diagnostics/warn-once.js';\n\n// Parser factory\nexport {\n\tcreateQtiParser,\n\tcreateMapperForVersion,\n\tcreateAttributeMapperForVersion,\n\tisQti2,\n\tisQti3,\n\ttype QtiParserResult,\n\ttype CreateParserOptions,\n} from './parser-factory.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAIlF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EACN,gCAAgC,EAChC,sBAAsB,GACtB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACN,iBAAiB,EACjB,wBAAwB,EACxB,cAAc,EACd,oBAAoB,GACpB,MAAM,kCAAkC,CAAC;AAE1C,mCAAmC;AACnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,GAG3B,MAAM,6BAA6B,CAAC;AAErC,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAOrG,OAAO,EACN,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,aAAa,GAEb,MAAM,mCAAmC,CAAC;AAE3C,0BAA0B;AAC1B,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,WAAW,GACX,MAAM,qBAAqB,CAAC;AAE7B,oDAAoD;AACpD,OAAO,EAAE,WAAW,EAA2B,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EACN,2BAA2B,GAG3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhE,oBAAoB;AACpB,OAAO,EAAE,iBAAiB,EAAsB,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,iBAAiB;AACjB,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,+BAA+B,EAC/B,MAAM,EACN,MAAM,GAGN,MAAM,qBAAqB,CAAC","sourcesContent":["// Element name mapping\nexport type { ElementNameMapper } from './element-mapper/ElementNameMapper.js';\nexport { Qti2xElementNameMapper } from './element-mapper/Qti2xElementNameMapper.js';\nexport { Qti3ElementNameMapper } from './element-mapper/Qti3ElementNameMapper.js';\n\n// Attribute name mapping\nexport type { AttributeNameMapper } from './element-mapper/AttributeNameMapper.js';\nexport { Qti2xAttributeNameMapper } from './element-mapper/Qti2xAttributeNameMapper.js';\nexport { Qti3AttributeNameMapper } from './element-mapper/Qti3AttributeNameMapper.js';\nexport {\n\tQTI2_PROMPT_BEARING_INTERACTIONS,\n\tQTI3_ATTRIBUTE_TO_QTI2,\n} from './element-mapper/qti3-attribute-map.js';\nexport {\n\tconvertQti2ToQti3,\n\tQTI3_ASI_SCHEMA_LOCATION,\n\tQTI3_NAMESPACE,\n\tQTI3_RPTEMPLATE_BASE,\n} from './element-mapper/qti2-to-qti3.js';\n\n// Feedback and template visibility\nexport { isShownByIdentifier, matchesIdentifier } from './feedback/visibility.js';\nexport {\n\tcleanFeedbackText,\n\tfeedbackInlineAttr,\n\tprocessFeedbackInline,\n\tDEFAULT_FEEDBACK_OUTCOME_ID,\n\tDEFAULT_FEEDBACK_TRANSFORMS,\n\ttype FeedbackTransform,\n\ttype ProcessFeedbackInlineOptions,\n} from './feedback/feedback-text.js';\n\n// Version detection\nexport { detectQtiVersion, detectQtiVersionDetailed } from './version-detection/detectQtiVersion.js';\nexport type {\n\tQtiVersion,\n\tQtiVersionDetection,\n\tQtiVersionDetectionBasis,\n\tQtiVersionDetectionConfidence,\n} from './version-detection/detectQtiVersion.js';\nexport {\n\tisQtiVocabularyElement,\n\tQTI2_ELEMENTS,\n\tQTI2_XHTML_ELEMENTS,\n\tQTI3_ELEMENTS,\n\ttype QtiVocabularyVersion,\n} from './version-detection/vocabulary.js';\n\n// XML attribute utilities\nexport {\n\tgetAttribute,\n\tgetBooleanAttribute,\n\tgetNumberAttribute,\n\thasAttribute,\n\ttoCamelCase,\n\ttoKebabCase,\n} from './xml/attributes.js';\n\n// DOM utility helpers shared across player packages\nexport { assignProps, type AssignPropsOptions } from './dom/assignProps.js';\nexport {\n\tcreateSvelteMountController,\n\ttype SvelteMountController,\n\ttype SvelteMountControllerOptions,\n} from './dom/svelteMountController.js';\nexport { touchDrag, touchDragStyles } from './dom/touchDrag.js';\n\n// Writing direction\nexport { languageDirection, type TextDirection } from './language/direction.js';\nexport { warnOnce } from './diagnostics/warn-once.js';\n\n// Parser factory\nexport {\n\tcreateQtiParser,\n\tcreateMapperForVersion,\n\tcreateAttributeMapperForVersion,\n\tisQti2,\n\tisQti3,\n\ttype QtiParserResult,\n\ttype CreateParserOptions,\n} from './parser-factory.js';\n"]}
@@ -2,6 +2,30 @@
2
2
  * QTI version identifiers
3
3
  */
4
4
  export type QtiVersion = '2.0' | '2.1' | '2.2' | '3.0' | 'unknown';
5
+ /** What decided a detected QTI version. */
6
+ export type QtiVersionDetectionBasis =
7
+ /** The root element's namespace names a QTI version. */
8
+ 'namespace'
9
+ /** A QTI 3.0 `qti-` element name, without a QTI namespace. */
10
+ | 'root-element'
11
+ /** A `version` attribute on a camelCase root, without a QTI namespace. */
12
+ | 'version-attribute'
13
+ /** Nothing named a version; a camelCase `assessmentItem`/`assessmentTest` is assumed to be 2.2. */
14
+ | 'default'
15
+ /** Not recognizable as QTI. */
16
+ | 'none';
17
+ /**
18
+ * How far to trust a detected version: `high` when the root declares the version's QTI namespace,
19
+ * `medium` when another signal decided it, `low` when the version is an assumption.
20
+ */
21
+ export type QtiVersionDetectionConfidence = 'high' | 'medium' | 'low';
22
+ export interface QtiVersionDetection {
23
+ readonly version: QtiVersion;
24
+ readonly basis: QtiVersionDetectionBasis;
25
+ readonly confidence: QtiVersionDetectionConfidence;
26
+ /** Why the result may be wrong, for callers to surface. Empty when the namespace decided. */
27
+ readonly warnings: readonly string[];
28
+ }
5
29
  /**
6
30
  * Detect the QTI version from XML content.
7
31
  *
@@ -9,7 +33,9 @@ export type QtiVersion = '2.0' | '2.1' | '2.2' | '3.0' | 'unknown';
9
33
  * 1. Check XML namespace URI for version indicators (v2p0, v2p1, v2p2, v3p0)
10
34
  * 2. Check root element name (qti-assessment-item => 3.0, assessmentItem => 2.x)
11
35
  * 3. Check version attribute on root element
12
- * 4. Fall back to 'unknown'
36
+ * 4. Fall back to '2.2' for a camelCase assessmentItem/assessmentTest root, else 'unknown'
37
+ *
38
+ * Use {@link detectQtiVersionDetailed} to learn whether the result was assumed.
13
39
  *
14
40
  * @param xml - QTI XML content as string
15
41
  * @returns Detected QTI version or 'unknown'
@@ -21,3 +47,18 @@ export type QtiVersion = '2.0' | '2.1' | '2.2' | '3.0' | 'unknown';
21
47
  * ```
22
48
  */
23
49
  export declare function detectQtiVersion(xml: string): QtiVersion;
50
+ /**
51
+ * Detect the QTI version from XML content, with what decided it and how far to trust it.
52
+ *
53
+ * The version is the one {@link detectQtiVersion} returns. An unversioned or unknown-namespace
54
+ * camelCase root still reads as QTI 2.2, but with `basis: 'default'`, `confidence: 'low'` and a
55
+ * warning, so callers can tell an assumption from a declaration and surface it.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * detectQtiVersionDetailed('<assessmentItem identifier="a"/>');
60
+ * // => { version: '2.2', basis: 'default', confidence: 'low',
61
+ * // warnings: ['Root <assessmentItem> declares no QTI namespace; assuming QTI 2.2.'] }
62
+ * ```
63
+ */
64
+ export declare function detectQtiVersionDetailed(xml: string): QtiVersionDetection;