@pie-qti/qti-common 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accessibility/markup.d.ts +4 -1
- package/dist/accessibility/markup.js +28 -5
- package/dist/accessibility/markup.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/language/direction.d.ts +10 -0
- package/dist/language/direction.js +42 -0
- package/dist/language/direction.js.map +1 -0
- package/package.json +3 -3
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* 5. Inline SSML elements are unwrapped with their text kept, and their nearest enclosing element
|
|
23
23
|
* gets a `spoken` card holding its content as SSML: the shape `SSMLExtractor` in pie-players
|
|
24
24
|
* produces from a `<speak>` element, so both reach `TTSService` alike.
|
|
25
|
-
* 6. `xml:lang` is restated as `lang`, the attribute HTML reads for the language of content
|
|
25
|
+
* 6. `xml:lang` is restated as `lang`, the attribute HTML reads for the language of content, and
|
|
26
|
+
* gets the `dir` of that language where it differs from the surrounding content's: the nearest
|
|
27
|
+
* ancestor's `dir` or language, else the document element's `xml:lang`, else left-to-right.
|
|
28
|
+
* An authored `dir` stays as authored.
|
|
26
29
|
*
|
|
27
30
|
* Docking puts the idref on the element's start tag, with two exceptions that wrap the element's
|
|
28
31
|
* content instead: a choice, whose attributes the transformers drop along with its tag, and an
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* 5. Inline SSML elements are unwrapped with their text kept, and their nearest enclosing element
|
|
23
23
|
* gets a `spoken` card holding its content as SSML: the shape `SSMLExtractor` in pie-players
|
|
24
24
|
* produces from a `<speak>` element, so both reach `TTSService` alike.
|
|
25
|
-
* 6. `xml:lang` is restated as `lang`, the attribute HTML reads for the language of content
|
|
25
|
+
* 6. `xml:lang` is restated as `lang`, the attribute HTML reads for the language of content, and
|
|
26
|
+
* gets the `dir` of that language where it differs from the surrounding content's: the nearest
|
|
27
|
+
* ancestor's `dir` or language, else the document element's `xml:lang`, else left-to-right.
|
|
28
|
+
* An authored `dir` stays as authored.
|
|
26
29
|
*
|
|
27
30
|
* Docking puts the idref on the element's start tag, with two exceptions that wrap the element's
|
|
28
31
|
* content instead: a choice, whose attributes the transformers drop along with its tag, and an
|
|
@@ -30,6 +33,7 @@
|
|
|
30
33
|
* accessibility audit reports what it would have carried.
|
|
31
34
|
*/
|
|
32
35
|
import { parse } from 'node-html-parser';
|
|
36
|
+
import { languageDirection } from '../language/direction.js';
|
|
33
37
|
export const HIDING_STYLES = {
|
|
34
38
|
'qti-hidden': 'display:none',
|
|
35
39
|
'qti-visually-hidden': 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0',
|
|
@@ -41,6 +45,7 @@ export const SSML_NAMESPACES = new Set([
|
|
|
41
45
|
const GENERATED_IDREF_PREFIX = 'ssml-';
|
|
42
46
|
const CONTENT_ROOT_PATTERN = /<((?:[\w.-]+:)?(?:itemBody|modalFeedback|stimulusBody|qti-item-body|qti-modal-feedback|qti-stimulus-body))\b[\s\S]*?<\/\1\s*>/g;
|
|
43
47
|
const TOKEN_PATTERN = /<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!\[CDATA\[|\]\]>|<\/([A-Za-z][\w.:-]*)\s*>|<([A-Za-z][\w.:-]*)((?:\s+[^\s=/>]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+))?)*)\s*(\/?)>/g;
|
|
48
|
+
const DOCUMENT_LANGUAGE_PATTERN = /^(?:\s*<(?:\?[\s\S]*?\?|!--[\s\S]*?--|![^>]*)>)*\s*<[^\s/>!?]+[^>]*?\sxml:lang\s*=\s*("[^"]*"|'[^']*')/;
|
|
44
49
|
const ATTRIBUTE_PATTERN = /([^\s=/>]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s"'>]+))?/g;
|
|
45
50
|
const XMLNS_ATTRIBUTE_PATTERN = /\s+xmlns(?::[\w.-]+)?\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+)/g;
|
|
46
51
|
const SSML_PREFIX_PATTERN = /\bxmlns:([\w.-]+)\s*=\s*(["'])(.*?)\2/g;
|
|
@@ -98,6 +103,7 @@ const BLOCK_ELEMENTS = new Set([
|
|
|
98
103
|
/** Apply the accessibility edits to a QTI document's content. */
|
|
99
104
|
export function prepareContentMarkup(qtiXml, links = [], options = {}) {
|
|
100
105
|
const hidingStyles = options.hidingStyles ?? true;
|
|
106
|
+
const documentDirection = languageDirection(unquote(qtiXml.match(DOCUMENT_LANGUAGE_PATTERN)?.[1]));
|
|
101
107
|
const roots = [...qtiXml.matchAll(CONTENT_ROOT_PATTERN)].flatMap((match) => {
|
|
102
108
|
const root = contentTree(match[0], match.index, ssmlPrefixesOf(qtiXml));
|
|
103
109
|
return root ? [root] : [];
|
|
@@ -143,7 +149,7 @@ export function prepareContentMarkup(qtiXml, links = [], options = {}) {
|
|
|
143
149
|
for (const element of elements) {
|
|
144
150
|
if (element.ssml)
|
|
145
151
|
continue;
|
|
146
|
-
editStartTag(element, hidingStyles);
|
|
152
|
+
editStartTag(element, hidingStyles, documentDirection);
|
|
147
153
|
const authored = unquote(element.attributes.get('data-catalog-idref')).trim();
|
|
148
154
|
if (authored) {
|
|
149
155
|
if (CONTENT_WRAPPED.has(element.local))
|
|
@@ -278,7 +284,7 @@ function contentTree(markup, offset, ssmlPrefixes) {
|
|
|
278
284
|
return root;
|
|
279
285
|
}
|
|
280
286
|
/** Restate hiding classes, read-aloud suppression and content language in the start tag. */
|
|
281
|
-
function editStartTag(element, hidingStyles) {
|
|
287
|
+
function editStartTag(element, hidingStyles, documentDirection) {
|
|
282
288
|
const { attributes } = element;
|
|
283
289
|
const classes = unquote(attributes.get('class')).split(/\s+/);
|
|
284
290
|
const hiding = Object.entries(hidingStyles ? HIDING_STYLES : {})
|
|
@@ -297,14 +303,31 @@ function editStartTag(element, hidingStyles) {
|
|
|
297
303
|
}
|
|
298
304
|
}
|
|
299
305
|
const language = attributes.get('xml:lang');
|
|
300
|
-
if (language !== undefined
|
|
301
|
-
|
|
306
|
+
if (language !== undefined) {
|
|
307
|
+
if (!attributes.has('lang'))
|
|
308
|
+
element.added.push(`lang=${quoted(language)}`);
|
|
309
|
+
const direction = languageDirection(unquote(language));
|
|
310
|
+
if (!attributes.has('dir') && direction !== surroundingDirection(element, documentDirection)) {
|
|
311
|
+
element.added.push(`dir="${direction}"`);
|
|
312
|
+
}
|
|
302
313
|
}
|
|
303
314
|
const suppress = attributes.get('data-qti-suppress-tts');
|
|
304
315
|
if (suppress !== undefined && !attributes.has('data-tts-suppress')) {
|
|
305
316
|
element.added.push(`data-tts-suppress=${quoted(suppress)}`);
|
|
306
317
|
}
|
|
307
318
|
}
|
|
319
|
+
/** The direction `element` inherits: its nearest ancestor's `dir` or language, else the document's. */
|
|
320
|
+
function surroundingDirection(element, documentDirection) {
|
|
321
|
+
for (let ancestor = element.parent; ancestor; ancestor = ancestor.parent) {
|
|
322
|
+
const dir = unquote(ancestor.attributes.get('dir')).trim().toLowerCase();
|
|
323
|
+
if (dir === 'rtl' || dir === 'ltr')
|
|
324
|
+
return dir;
|
|
325
|
+
const language = ancestor.attributes.get('xml:lang') ?? ancestor.attributes.get('lang');
|
|
326
|
+
if (language !== undefined)
|
|
327
|
+
return languageDirection(unquote(language));
|
|
328
|
+
}
|
|
329
|
+
return documentDirection;
|
|
330
|
+
}
|
|
308
331
|
/**
|
|
309
332
|
* The span of `element`'s text that `range` counts, when it lies inside one text node. Each
|
|
310
333
|
* whitespace run counts as one character, and whitespace before the first word not at all.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markup.js","sourceRoot":"","sources":["../../src/accessibility/markup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAoB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG3D,MAAM,CAAC,M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,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.\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 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 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 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);\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(element: ContentElement, hidingStyles: boolean): 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 && !attributes.has('lang')) {\n\t\telement.added.push(`lang=${quoted(language)}`);\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/**\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, '&').replace(/</g, '<').replace(/>/g, '>');\n}\n\nfunction escapeAttribute(value: string): string {\n\treturn escapeText(value).replace(/\"/g, '"');\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,qCAA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I,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, '&').replace(/</g, '<').replace(/>/g, '>');\n}\n\nfunction escapeAttribute(value: string): string {\n\treturn escapeText(value).replace(/\"/g, '"');\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,5 @@ export { getAttribute, getBooleanAttribute, getNumberAttribute, hasAttribute, to
|
|
|
13
13
|
export { assignProps, type AssignPropsOptions } from './dom/assignProps.js';
|
|
14
14
|
export { createSvelteMountController, type SvelteMountController, type SvelteMountControllerOptions, } from './dom/svelteMountController.js';
|
|
15
15
|
export { touchDrag, touchDragStyles } from './dom/touchDrag.js';
|
|
16
|
+
export { languageDirection, type TextDirection } from './language/direction.js';
|
|
16
17
|
export { createQtiParser, createMapperForVersion, createAttributeMapperForVersion, isQti2, isQti3, type QtiParserResult, type CreateParserOptions, } from './parser-factory.js';
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ export { getAttribute, getBooleanAttribute, getNumberAttribute, hasAttribute, to
|
|
|
14
14
|
export { assignProps } from './dom/assignProps.js';
|
|
15
15
|
export { createSvelteMountController, } from './dom/svelteMountController.js';
|
|
16
16
|
export { touchDrag, touchDragStyles } from './dom/touchDrag.js';
|
|
17
|
+
// Writing direction
|
|
18
|
+
export { languageDirection } from './language/direction.js';
|
|
17
19
|
// Parser factory
|
|
18
20
|
export { createQtiParser, createMapperForVersion, createAttributeMapperForVersion, isQti2, isQti3, } from './parser-factory.js';
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
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;AAElF,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,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';\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// 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;AAElF,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;AAEhF,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';\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';\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"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing direction of a language tag.
|
|
3
|
+
*
|
|
4
|
+
* The same answer as `languageDirection` in `@pie-qti/i18n`, which this package
|
|
5
|
+
* does not depend on; item-player's `language-direction-parity.test.ts` holds
|
|
6
|
+
* the two to one table.
|
|
7
|
+
*/
|
|
8
|
+
export type TextDirection = 'ltr' | 'rtl';
|
|
9
|
+
/** Writing direction of a language tag; `ltr` for anything unrecognised. */
|
|
10
|
+
export declare function languageDirection(tag: string | null | undefined): TextDirection;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing direction of a language tag.
|
|
3
|
+
*
|
|
4
|
+
* The same answer as `languageDirection` in `@pie-qti/i18n`, which this package
|
|
5
|
+
* does not depend on; item-player's `language-direction-parity.test.ts` holds
|
|
6
|
+
* the two to one table.
|
|
7
|
+
*/
|
|
8
|
+
/** Right-to-left primary subtags, for engines whose `Intl.Locale` has no text info. */
|
|
9
|
+
const RTL_LANGUAGES = new Set([
|
|
10
|
+
'ar',
|
|
11
|
+
'ckb',
|
|
12
|
+
'dv',
|
|
13
|
+
'fa',
|
|
14
|
+
'he',
|
|
15
|
+
'iw',
|
|
16
|
+
'ks',
|
|
17
|
+
'ku',
|
|
18
|
+
'nqo',
|
|
19
|
+
'ps',
|
|
20
|
+
'sd',
|
|
21
|
+
'syr',
|
|
22
|
+
'ug',
|
|
23
|
+
'ur',
|
|
24
|
+
'yi',
|
|
25
|
+
]);
|
|
26
|
+
/** Writing direction of a language tag; `ltr` for anything unrecognised. */
|
|
27
|
+
export function languageDirection(tag) {
|
|
28
|
+
const normalized = (tag ?? '').trim().replace(/_/g, '-').split(/[.@]/)[0]?.toLowerCase() ?? '';
|
|
29
|
+
if (!normalized)
|
|
30
|
+
return 'ltr';
|
|
31
|
+
try {
|
|
32
|
+
const locale = new Intl.Locale(normalized);
|
|
33
|
+
const direction = (locale.getTextInfo?.() ?? locale.textInfo)?.direction;
|
|
34
|
+
if (direction === 'rtl' || direction === 'ltr')
|
|
35
|
+
return direction;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Not a tag Intl.Locale accepts; the subtag check below still answers.
|
|
39
|
+
}
|
|
40
|
+
return RTL_LANGUAGES.has(normalized.split('-')[0] ?? '') ? 'rtl' : 'ltr';
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=direction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../../src/language/direction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,uFAAuF;AACvF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC7B,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;CACJ,CAAC,CAAC;AAOH,4EAA4E;AAC5E,MAAM,UAAU,iBAAiB,CAAC,GAA8B;IAC/D,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC/F,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAmB,CAAC;QAC7D,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;QACzE,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;YAAE,OAAO,SAAS,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACR,uEAAuE;IACxE,CAAC;IACD,OAAO,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * Writing direction of a language tag.\n *\n * The same answer as `languageDirection` in `@pie-qti/i18n`, which this package\n * does not depend on; item-player's `language-direction-parity.test.ts` holds\n * the two to one table.\n */\n\nexport type TextDirection = 'ltr' | 'rtl';\n\n/** Right-to-left primary subtags, for engines whose `Intl.Locale` has no text info. */\nconst RTL_LANGUAGES = new Set([\n\t'ar',\n\t'ckb',\n\t'dv',\n\t'fa',\n\t'he',\n\t'iw',\n\t'ks',\n\t'ku',\n\t'nqo',\n\t'ps',\n\t'sd',\n\t'syr',\n\t'ug',\n\t'ur',\n\t'yi',\n]);\n\ntype TextInfoLocale = Intl.Locale & {\n\tgetTextInfo?: () => { direction?: string };\n\ttextInfo?: { direction?: string };\n};\n\n/** Writing direction of a language tag; `ltr` for anything unrecognised. */\nexport function languageDirection(tag: string | null | undefined): TextDirection {\n\tconst normalized = (tag ?? '').trim().replace(/_/g, '-').split(/[.@]/)[0]?.toLowerCase() ?? '';\n\tif (!normalized) return 'ltr';\n\ttry {\n\t\tconst locale = new Intl.Locale(normalized) as TextInfoLocale;\n\t\tconst direction = (locale.getTextInfo?.() ?? locale.textInfo)?.direction;\n\t\tif (direction === 'rtl' || direction === 'ltr') return direction;\n\t} catch {\n\t\t// Not a tag Intl.Locale accepts; the subtag check below still answers.\n\t}\n\treturn RTL_LANGUAGES.has(normalized.split('-')[0] ?? '') ? 'rtl' : 'ltr';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/qti-common",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"node-html-parser": "^9.0.
|
|
6
|
+
"node-html-parser": "^9.0.5"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@types/bun": "^1.4.
|
|
9
|
+
"@types/bun": "^1.4.4",
|
|
10
10
|
"@xmldom/xmldom": "^0.9.12",
|
|
11
11
|
"typescript": "^5.9.3"
|
|
12
12
|
},
|