@pie-qti/qti-common 1.0.0-beta.0 → 1.0.0-beta.2

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.
Files changed (76) hide show
  1. package/dist/accessibility/apip.d.ts +66 -0
  2. package/dist/accessibility/apip.js +576 -0
  3. package/dist/accessibility/apip.js.map +1 -0
  4. package/dist/accessibility/catalog-info.d.ts +17 -0
  5. package/dist/accessibility/catalog-info.js +60 -0
  6. package/dist/accessibility/catalog-info.js.map +1 -0
  7. package/dist/accessibility/catalog.d.ts +53 -0
  8. package/dist/accessibility/catalog.js +68 -0
  9. package/dist/accessibility/catalog.js.map +1 -0
  10. package/dist/accessibility/index.d.ts +4 -0
  11. package/dist/accessibility/index.js +5 -0
  12. package/dist/accessibility/index.js.map +1 -0
  13. package/dist/accessibility/markup.d.ts +61 -0
  14. package/dist/accessibility/markup.js +484 -0
  15. package/dist/accessibility/markup.js.map +1 -0
  16. package/dist/dom/assignProps.d.ts +4 -0
  17. package/dist/dom/assignProps.js +9 -0
  18. package/dist/dom/assignProps.js.map +1 -0
  19. package/dist/dom/svelteMountController.d.ts +25 -0
  20. package/dist/dom/svelteMountController.js +131 -0
  21. package/dist/dom/svelteMountController.js.map +1 -0
  22. package/dist/dom/touchDrag.d.ts +10 -0
  23. package/dist/dom/touchDrag.js +141 -0
  24. package/dist/dom/touchDrag.js.map +1 -0
  25. package/dist/element-mapper/AttributeNameMapper.d.ts +66 -0
  26. package/dist/element-mapper/AttributeNameMapper.js +2 -0
  27. package/dist/element-mapper/AttributeNameMapper.js.map +1 -0
  28. package/dist/element-mapper/ElementNameMapper.d.ts +66 -0
  29. package/dist/element-mapper/ElementNameMapper.js +2 -0
  30. package/dist/element-mapper/ElementNameMapper.js.map +1 -0
  31. package/dist/element-mapper/Qti2xAttributeNameMapper.d.ts +27 -0
  32. package/dist/element-mapper/Qti2xAttributeNameMapper.js +38 -0
  33. package/dist/element-mapper/Qti2xAttributeNameMapper.js.map +1 -0
  34. package/dist/element-mapper/Qti2xElementNameMapper.d.ts +37 -0
  35. package/dist/element-mapper/Qti2xElementNameMapper.js +47 -0
  36. package/dist/element-mapper/Qti2xElementNameMapper.js.map +1 -0
  37. package/dist/element-mapper/Qti3AttributeNameMapper.d.ts +40 -0
  38. package/dist/element-mapper/Qti3AttributeNameMapper.js +87 -0
  39. package/dist/element-mapper/Qti3AttributeNameMapper.js.map +1 -0
  40. package/dist/element-mapper/Qti3ElementNameMapper.d.ts +14 -0
  41. package/dist/element-mapper/Qti3ElementNameMapper.js +39 -0
  42. package/dist/element-mapper/Qti3ElementNameMapper.js.map +1 -0
  43. package/dist/element-mapper/index.d.ts +8 -0
  44. package/dist/element-mapper/index.js +7 -0
  45. package/dist/element-mapper/index.js.map +1 -0
  46. package/dist/element-mapper/qti2-to-qti3.d.ts +36 -0
  47. package/dist/element-mapper/qti2-to-qti3.js +228 -0
  48. package/dist/element-mapper/qti2-to-qti3.js.map +1 -0
  49. package/dist/element-mapper/qti3-attribute-map.d.ts +8 -0
  50. package/dist/element-mapper/qti3-attribute-map.js +115 -0
  51. package/dist/element-mapper/qti3-attribute-map.js.map +1 -0
  52. package/dist/element-mapper/qti3-element-mappings.d.ts +538 -0
  53. package/dist/element-mapper/qti3-element-mappings.js +381 -0
  54. package/dist/element-mapper/qti3-element-mappings.js.map +1 -0
  55. package/dist/feedback/visibility.d.ts +12 -0
  56. package/dist/feedback/visibility.js +22 -0
  57. package/dist/feedback/visibility.js.map +1 -0
  58. package/dist/index.d.ts +17 -0
  59. package/dist/index.js +21 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/language/direction.d.ts +10 -0
  62. package/dist/language/direction.js +42 -0
  63. package/dist/language/direction.js.map +1 -0
  64. package/dist/parser-factory.d.ts +137 -0
  65. package/dist/parser-factory.js +146 -0
  66. package/dist/parser-factory.js.map +1 -0
  67. package/dist/version-detection/detectQtiVersion.d.ts +23 -0
  68. package/dist/version-detection/detectQtiVersion.js +129 -0
  69. package/dist/version-detection/detectQtiVersion.js.map +1 -0
  70. package/dist/version-detection/index.d.ts +2 -0
  71. package/dist/version-detection/index.js +2 -0
  72. package/dist/version-detection/index.js.map +1 -0
  73. package/dist/xml/attributes.d.ts +77 -0
  74. package/dist/xml/attributes.js +120 -0
  75. package/dist/xml/attributes.js.map +1 -0
  76. package/package.json +2 -2
@@ -0,0 +1,484 @@
1
+ /**
2
+ * Accessibility markup
3
+ *
4
+ * The edits that prepare a QTI document's content for PIE conversion and for delivery, so what QTI
5
+ * voices, hides or suppresses stays so for the PIE read-aloud tools. Each content root (`itemBody`,
6
+ * `modalFeedback`, `stimulusBody`, in QTI 2 or QTI 3 spelling) is read as a token stream into an
7
+ * element tree, and rebuilt with the edits applied; markup outside the roots, comments and
8
+ * processing instructions are left as authored. CDATA is edited like the markup around it, since
9
+ * the HTML it wraps is what converts.
10
+ *
11
+ * 1. `qti-hidden` and `qti-visually-hidden` get the inline style the class stands for, since the
12
+ * shared-vocabulary stylesheet has no URL a PIE player can load and players strip `<style>`.
13
+ * Delivery ships that stylesheet and turns this edit off with `hidingStyles: false`.
14
+ * 2. `data-qti-suppress-tts` is restated as `data-tts-suppress`, the only spelling PIE reads.
15
+ * 3. An element with `data-ssml` gets a generated `data-catalog-idref`, and the SSML becomes a
16
+ * `spoken` card under it; an element that already names a catalog adds the card to that one.
17
+ * 4. Each APIP content link docks its access element's idref: on the element whose `id` it names,
18
+ * or on a span around the word or character range its `textLink` counts. Words are counted
19
+ * from 1 over the element's text split on whitespace, punctuation kept with its word, as
20
+ * 1EdTech's APIP-to-QTI 3 migration guide counts them; characters from 1 with whitespace runs
21
+ * collapsed. A range that crosses markup or overlaps another range is not docked.
22
+ * 5. Inline SSML elements are unwrapped with their text kept, and their nearest enclosing element
23
+ * gets a `spoken` card holding its content as SSML: the shape `SSMLExtractor` in pie-players
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, 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.
29
+ *
30
+ * Docking puts the idref on the element's start tag, with two exceptions that wrap the element's
31
+ * content instead: a choice, whose attributes the transformers drop along with its tag, and an
32
+ * element that names a catalog already. An idref that cannot dock is left out, and the
33
+ * accessibility audit reports what it would have carried.
34
+ */
35
+ import { parse } from 'node-html-parser';
36
+ import { languageDirection } from '../language/direction.js';
37
+ export const HIDING_STYLES = {
38
+ 'qti-hidden': 'display:none',
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',
40
+ };
41
+ export const SSML_NAMESPACES = new Set([
42
+ 'http://www.w3.org/2001/10/synthesis',
43
+ 'http://www.w3.org/2010/10/synthesis',
44
+ ]);
45
+ const GENERATED_IDREF_PREFIX = 'ssml-';
46
+ const CONTENT_ROOT_PATTERN = /<((?:[\w.-]+:)?(?:itemBody|modalFeedback|stimulusBody|qti-item-body|qti-modal-feedback|qti-stimulus-body))\b[\s\S]*?<\/\1\s*>/g;
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*("[^"]*"|'[^']*')/;
49
+ const ATTRIBUTE_PATTERN = /([^\s=/>]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s"'>]+))?/g;
50
+ const XMLNS_ATTRIBUTE_PATTERN = /\s+xmlns(?::[\w.-]+)?\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+)/g;
51
+ const SSML_PREFIX_PATTERN = /\bxmlns:([\w.-]+)\s*=\s*(["'])(.*?)\2/g;
52
+ const IDREF_PATTERN = /\bdata-catalog-idref\s*=\s*(["'])(.*?)\1/g;
53
+ const CATALOG_ID_PATTERN = /<(?:[\w.-]+:)?catalog\b[^>]*?\bid\s*=\s*(["'])(.*?)\1/g;
54
+ /** One character of text: an entity or character reference counts as the character it names. */
55
+ const TEXT_UNIT_PATTERN = /&(?:#\d+|#x[\da-f]+|[a-z][\da-z]*);|[\s\S]/gi;
56
+ const XML_WHITESPACE = /^[ \t\r\n]$/;
57
+ /** Choices: the transformers read their content and drop their tags. */
58
+ const CONTENT_WRAPPED = new Set([
59
+ 'simpleChoice',
60
+ 'simpleAssociableChoice',
61
+ 'inlineChoice',
62
+ 'gapText',
63
+ 'qti-simple-choice',
64
+ 'qti-simple-associable-choice',
65
+ 'qti-inline-choice',
66
+ 'qti-gap-text',
67
+ ]);
68
+ const VOID_ELEMENTS = new Set([
69
+ 'area',
70
+ 'base',
71
+ 'br',
72
+ 'col',
73
+ 'embed',
74
+ 'hr',
75
+ 'img',
76
+ 'input',
77
+ 'link',
78
+ 'meta',
79
+ 'param',
80
+ 'source',
81
+ 'track',
82
+ 'wbr',
83
+ ]);
84
+ const BLOCK_ELEMENTS = new Set([
85
+ 'address',
86
+ 'blockquote',
87
+ 'div',
88
+ 'dl',
89
+ 'figure',
90
+ 'h1',
91
+ 'h2',
92
+ 'h3',
93
+ 'h4',
94
+ 'h5',
95
+ 'h6',
96
+ 'hr',
97
+ 'ol',
98
+ 'p',
99
+ 'pre',
100
+ 'table',
101
+ 'ul',
102
+ ]);
103
+ /** Apply the accessibility edits to a QTI document's content. */
104
+ export function prepareContentMarkup(qtiXml, links = [], options = {}) {
105
+ const hidingStyles = options.hidingStyles ?? true;
106
+ const documentDirection = languageDirection(unquote(qtiXml.match(DOCUMENT_LANGUAGE_PATTERN)?.[1]));
107
+ const roots = [...qtiXml.matchAll(CONTENT_ROOT_PATTERN)].flatMap((match) => {
108
+ const root = contentTree(match[0], match.index, ssmlPrefixesOf(qtiXml));
109
+ return root ? [root] : [];
110
+ });
111
+ const elements = roots.flatMap(descendants);
112
+ const spoken = [];
113
+ const wraps = [];
114
+ const taken = new Set([
115
+ ...[...qtiXml.matchAll(IDREF_PATTERN)].map((match) => match[2]),
116
+ ...[...qtiXml.matchAll(CATALOG_ID_PATTERN)].map((match) => match[2]),
117
+ ...links.map((link) => link.idref),
118
+ ]);
119
+ let generated = 0;
120
+ const nextIdref = () => {
121
+ let identifier;
122
+ do {
123
+ generated += 1;
124
+ identifier = `${GENERATED_IDREF_PREFIX}${generated}`;
125
+ } while (taken.has(identifier));
126
+ taken.add(identifier);
127
+ return identifier;
128
+ };
129
+ const wrap = (span, idref, tag) => {
130
+ wraps.push({ ...span, tag, idref, seq: wraps.length });
131
+ };
132
+ const dock = (element, idref) => {
133
+ if (!element.parent)
134
+ return false;
135
+ if (element.idref === idref)
136
+ return true;
137
+ if (CONTENT_WRAPPED.has(element.local) || element.ssml || element.idref !== undefined) {
138
+ if (!element.close)
139
+ return false;
140
+ const block = element.children.some((child) => child.kind === 'element' && BLOCK_ELEMENTS.has(child.local.toLowerCase()));
141
+ wrap({ start: element.open.end, end: element.close.start }, idref, block ? 'div' : 'span');
142
+ }
143
+ else {
144
+ element.added.push(`data-catalog-idref="${escapeAttribute(idref)}"`);
145
+ }
146
+ element.idref ??= idref;
147
+ return true;
148
+ };
149
+ for (const element of elements) {
150
+ if (element.ssml)
151
+ continue;
152
+ editStartTag(element, hidingStyles, documentDirection);
153
+ const authored = unquote(element.attributes.get('data-catalog-idref')).trim();
154
+ if (authored) {
155
+ if (CONTENT_WRAPPED.has(element.local))
156
+ dock(element, authored);
157
+ element.idref = authored;
158
+ }
159
+ if (element.attributes.has('data-ssml')) {
160
+ const content = decodedAttribute(element.attrs, 'data-ssml')?.trim();
161
+ if (content) {
162
+ const identifier = element.idref ?? nextIdref();
163
+ if (element.idref !== undefined || dock(element, identifier)) {
164
+ spoken.push({ identifier, content });
165
+ }
166
+ }
167
+ }
168
+ }
169
+ const ids = new Map();
170
+ for (const element of elements) {
171
+ const id = unquote(element.attributes.get('id')).trim();
172
+ if (id && !ids.has(id))
173
+ ids.set(id, element);
174
+ }
175
+ const ranges = new Map();
176
+ for (const link of links) {
177
+ const element = ids.get(link.target);
178
+ if (!element)
179
+ continue;
180
+ if (!link.range) {
181
+ dock(element, link.idref);
182
+ continue;
183
+ }
184
+ const located = locateRange(element, link.range);
185
+ if (!located)
186
+ continue;
187
+ const docked = ranges.get(located.text) ?? [];
188
+ if (docked.some((span) => crosses(span, located)))
189
+ continue;
190
+ docked.push(located);
191
+ ranges.set(located.text, docked);
192
+ wrap(located, link.idref, 'span');
193
+ }
194
+ const hosts = new Map();
195
+ for (const element of elements) {
196
+ if (!element.ssml || element.parent?.ssml)
197
+ continue;
198
+ let host = element.parent;
199
+ while (host?.ssml)
200
+ host = host.parent;
201
+ // SSML straight inside a content root speaks on its own: a root's tag does not reach PIE.
202
+ if (!host?.parent)
203
+ hosts.set(element, [element]);
204
+ else
205
+ hosts.set(host, host.children);
206
+ }
207
+ for (const [host, nodes] of hosts) {
208
+ const markup = nodes.map(ssmlMarkup).join('').replace(/\s+/g, ' ').trim();
209
+ if (!markup)
210
+ continue;
211
+ const identifier = host.idref ?? nextIdref();
212
+ if (host.idref !== undefined || dock(host, identifier)) {
213
+ spoken.push({ identifier, content: `<speak>${markup}</speak>` });
214
+ }
215
+ }
216
+ return { xml: rendered(qtiXml, elements, wraps), spoken };
217
+ }
218
+ function contentTree(markup, offset, ssmlPrefixes) {
219
+ let root;
220
+ const stack = [];
221
+ let cursor = 0;
222
+ const addText = (end) => {
223
+ const parent = stack[stack.length - 1];
224
+ if (parent && end > cursor) {
225
+ parent.children.push({
226
+ kind: 'text',
227
+ start: offset + cursor,
228
+ end: offset + end,
229
+ raw: markup.slice(cursor, end),
230
+ });
231
+ }
232
+ };
233
+ for (const match of markup.matchAll(TOKEN_PATTERN)) {
234
+ addText(match.index);
235
+ cursor = match.index + match[0].length;
236
+ const [, endName, startName, attrs = '', selfClosing] = match;
237
+ if (endName) {
238
+ let at = stack.length - 1;
239
+ while (at >= 0 && stack[at]?.name !== endName)
240
+ at -= 1;
241
+ if (at === -1)
242
+ continue;
243
+ const element = stack[at];
244
+ element.close = { start: offset + match.index, end: offset + cursor };
245
+ stack.length = at;
246
+ continue;
247
+ }
248
+ if (!startName)
249
+ continue;
250
+ const parent = stack[stack.length - 1];
251
+ if (!parent && root)
252
+ continue;
253
+ const colon = startName.indexOf(':');
254
+ const prefix = colon === -1 ? undefined : startName.slice(0, colon);
255
+ const local = startName.slice(colon + 1);
256
+ const attributes = new Map([...attrs.matchAll(ATTRIBUTE_PATTERN)].map((attribute) => [
257
+ attribute[1].toLowerCase(),
258
+ attribute[2],
259
+ ]));
260
+ const xmlns = attributes.get('xmlns');
261
+ const defaultSsml = xmlns === undefined ? (parent?.defaultSsml ?? false) : SSML_NAMESPACES.has(unquote(xmlns));
262
+ const element = {
263
+ kind: 'element',
264
+ name: startName,
265
+ local,
266
+ attrs,
267
+ attributes,
268
+ selfClosing: Boolean(selfClosing),
269
+ open: { start: offset + match.index, end: offset + cursor },
270
+ ...(parent ? { parent } : {}),
271
+ children: [],
272
+ ssml: prefix === undefined ? defaultSsml : ssmlPrefixes.has(prefix),
273
+ editedAttrs: attrs,
274
+ added: [],
275
+ defaultSsml,
276
+ };
277
+ if (parent)
278
+ parent.children.push(element);
279
+ else
280
+ root = element;
281
+ if (!element.selfClosing && !VOID_ELEMENTS.has(local.toLowerCase()))
282
+ stack.push(element);
283
+ }
284
+ return root;
285
+ }
286
+ /** Restate hiding classes, read-aloud suppression and content language in the start tag. */
287
+ function editStartTag(element, hidingStyles, documentDirection) {
288
+ const { attributes } = element;
289
+ const classes = unquote(attributes.get('class')).split(/\s+/);
290
+ const hiding = Object.entries(hidingStyles ? HIDING_STYLES : {})
291
+ .filter(([hidingClass]) => classes.includes(hidingClass))
292
+ .map(([, style]) => style);
293
+ if (hiding.length > 0) {
294
+ const style = attributes.get('style');
295
+ if (style === undefined) {
296
+ element.added.push(`style="${hiding.join(';')}"`);
297
+ }
298
+ else {
299
+ const quote = style.startsWith("'") ? "'" : '"';
300
+ const current = unquote(style).trim().replace(/;$/, '');
301
+ const merged = [current, ...hiding].filter(Boolean).join(';');
302
+ element.editedAttrs = element.editedAttrs.replace(/(\sstyle\s*=\s*)("[^"]*"|'[^']*'|[^\s"'>]+)/i, `$1${quote}${merged}${quote}`);
303
+ }
304
+ }
305
+ const language = attributes.get('xml:lang');
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
+ }
313
+ }
314
+ const suppress = attributes.get('data-qti-suppress-tts');
315
+ if (suppress !== undefined && !attributes.has('data-tts-suppress')) {
316
+ element.added.push(`data-tts-suppress=${quoted(suppress)}`);
317
+ }
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
+ }
331
+ /**
332
+ * The span of `element`'s text that `range` counts, when it lies inside one text node. Each
333
+ * whitespace run counts as one character, and whitespace before the first word not at all.
334
+ */
335
+ function locateRange(element, range) {
336
+ const characters = [];
337
+ let space;
338
+ for (const text of textsOf(element)) {
339
+ for (const unit of text.raw.matchAll(TEXT_UNIT_PATTERN)) {
340
+ const start = text.start + unit.index;
341
+ const span = { text, start, end: start + unit[0].length };
342
+ if (XML_WHITESPACE.test(unit[0])) {
343
+ if (characters.length > 0)
344
+ space ??= span;
345
+ continue;
346
+ }
347
+ if (space)
348
+ characters.push({ ...space, space: true });
349
+ space = undefined;
350
+ characters.push({ ...span, space: false });
351
+ }
352
+ }
353
+ let first = range.start - 1;
354
+ let last = range.stop - 1;
355
+ if (range.unit === 'word') {
356
+ const words = [];
357
+ characters.forEach((character, index) => {
358
+ if (character.space)
359
+ return;
360
+ const word = words[words.length - 1];
361
+ if (word && word[1] === index - 1)
362
+ word[1] = index;
363
+ else
364
+ words.push([index, index]);
365
+ });
366
+ first = words[range.start - 1]?.[0] ?? Number.NaN;
367
+ last = words[range.stop - 1]?.[1] ?? Number.NaN;
368
+ }
369
+ const from = characters[first];
370
+ const to = characters[last];
371
+ if (!from || !to || last < first || from.text !== to.text)
372
+ return undefined;
373
+ return { text: from.text, start: from.start, end: to.end };
374
+ }
375
+ /** Two ranges that overlap without one holding the other. */
376
+ function crosses(a, b) {
377
+ const overlap = a.start < b.end && b.start < a.end;
378
+ const nested = (a.start <= b.start && b.end <= a.end) || (b.start <= a.start && a.end <= b.end);
379
+ return overlap && !nested;
380
+ }
381
+ /** Content as SSML: its SSML elements without namespace prefixes, other markup reduced to text. */
382
+ function ssmlMarkup(node) {
383
+ if (node.kind === 'text')
384
+ return escapeText(parse(node.raw).textContent);
385
+ const classes = unquote(node.attributes.get('class')).split(/\s+/);
386
+ if (classes.includes('qti-hidden') ||
387
+ node.attributes.has('data-qti-suppress-tts') ||
388
+ node.attributes.has('data-tts-suppress')) {
389
+ return '';
390
+ }
391
+ const content = node.children.map(ssmlMarkup).join('');
392
+ if (!node.ssml)
393
+ return content;
394
+ const attrs = node.attrs.replace(XMLNS_ATTRIBUTE_PATTERN, '');
395
+ return node.selfClosing
396
+ ? `<${node.local}${attrs}/>`
397
+ : `<${node.local}${attrs}>${content}</${node.local}>`;
398
+ }
399
+ /** The document with every edited tag replaced and every wrap inserted. */
400
+ function rendered(qtiXml, elements, wraps) {
401
+ const edits = [];
402
+ for (const element of elements) {
403
+ if (element.ssml) {
404
+ edits.push({ ...element.open, text: '', phase: 2 });
405
+ if (element.close)
406
+ edits.push({ ...element.close, text: '', phase: 2 });
407
+ }
408
+ else if (element.added.length > 0 || element.editedAttrs !== element.attrs) {
409
+ const added = element.added.map((attribute) => ` ${attribute}`).join('');
410
+ const end = element.selfClosing ? ' />' : '>';
411
+ edits.push({
412
+ ...element.open,
413
+ text: `<${element.name}${element.editedAttrs}${added}${end}`,
414
+ phase: 2,
415
+ });
416
+ }
417
+ }
418
+ for (const wrap of wraps) {
419
+ edits.push({
420
+ start: wrap.start,
421
+ end: wrap.start,
422
+ text: `<${wrap.tag} data-catalog-idref="${escapeAttribute(wrap.idref)}">`,
423
+ phase: 1,
424
+ wrap,
425
+ });
426
+ edits.push({ start: wrap.end, end: wrap.end, text: `</${wrap.tag}>`, phase: 0, wrap });
427
+ }
428
+ // Wraps nest: at one position the innermost closes first and the outermost opens first.
429
+ edits.sort((a, b) => {
430
+ if (a.start !== b.start)
431
+ return a.start - b.start;
432
+ if (a.phase !== b.phase)
433
+ return a.phase - b.phase;
434
+ if (!a.wrap || !b.wrap)
435
+ return 0;
436
+ if (a.phase === 0)
437
+ return b.wrap.start - a.wrap.start || b.wrap.seq - a.wrap.seq;
438
+ return b.wrap.end - a.wrap.end || a.wrap.seq - b.wrap.seq;
439
+ });
440
+ let xml = '';
441
+ let cursor = 0;
442
+ for (const edit of edits) {
443
+ xml += qtiXml.slice(cursor, edit.start) + edit.text;
444
+ cursor = edit.end;
445
+ }
446
+ return xml + qtiXml.slice(cursor);
447
+ }
448
+ function descendants(element) {
449
+ return [
450
+ element,
451
+ ...element.children.flatMap((child) => (child.kind === 'element' ? descendants(child) : [])),
452
+ ];
453
+ }
454
+ function textsOf(element) {
455
+ return element.children.flatMap((child) => (child.kind === 'text' ? [child] : textsOf(child)));
456
+ }
457
+ function ssmlPrefixesOf(qtiXml) {
458
+ const prefixes = new Set(['ssml']);
459
+ for (const match of qtiXml.matchAll(SSML_PREFIX_PATTERN)) {
460
+ if (SSML_NAMESPACES.has(match[3]))
461
+ prefixes.add(match[1]);
462
+ }
463
+ return prefixes;
464
+ }
465
+ /** An attribute's value with its entities decoded, as the markup's readers see it. */
466
+ function decodedAttribute(attrs, name) {
467
+ const element = parse(`<x${attrs}></x>`).firstChild;
468
+ return element?.getAttribute(name);
469
+ }
470
+ function unquote(value) {
471
+ if (!value)
472
+ return '';
473
+ return /^(["']).*\1$/s.test(value) ? value.slice(1, -1) : value;
474
+ }
475
+ function quoted(value) {
476
+ return /^["']/.test(value) ? value : `"${value}"`;
477
+ }
478
+ export function escapeText(text) {
479
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
480
+ }
481
+ function escapeAttribute(value) {
482
+ return escapeText(value).replace(/"/g, '&quot;');
483
+ }
484
+ //# sourceMappingURL=markup.js.map
@@ -0,0 +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,CAA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AAC,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"]}
@@ -0,0 +1,4 @@
1
+ export type AssignPropsOptions = {
2
+ skipUndefined?: boolean;
3
+ };
4
+ export declare function assignProps(node: HTMLElement, props: Record<string, unknown>, options?: AssignPropsOptions): void;
@@ -0,0 +1,9 @@
1
+ export function assignProps(node, props, options = {}) {
2
+ const { skipUndefined = true } = options;
3
+ for (const [key, value] of Object.entries(props)) {
4
+ if (skipUndefined && value === undefined)
5
+ continue;
6
+ node[key] = value;
7
+ }
8
+ }
9
+ //# sourceMappingURL=assignProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignProps.js","sourceRoot":"","sources":["../../src/dom/assignProps.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,WAAW,CAAC,IAAiB,EAAE,KAA8B,EAAE,UAA8B,EAAE;IAC9G,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,aAAa,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClD,IAA2C,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC3D,CAAC;AACF,CAAC","sourcesContent":["export type AssignPropsOptions = {\n\tskipUndefined?: boolean;\n};\n\nexport function assignProps(node: HTMLElement, props: Record<string, unknown>, options: AssignPropsOptions = {}) {\n\tconst { skipUndefined = true } = options;\n\tfor (const [key, value] of Object.entries(props)) {\n\t\tif (skipUndefined && value === undefined) continue;\n\t\t(node as unknown as Record<string, unknown>)[key] = value;\n\t}\n}\n"]}
@@ -0,0 +1,25 @@
1
+ export interface SvelteMountControllerOptions<TProps, TInstance> {
2
+ host: HTMLElement;
3
+ mount: (target: HTMLElement, props: TProps) => TInstance;
4
+ /** Svelte 5's createSubscriber, supplied by the browser adapter's runtime. */
5
+ createSubscriber?: (start: (update: () => void) => () => void) => () => void;
6
+ unmount: (instance: TInstance) => void | Promise<void>;
7
+ createContainer?: () => HTMLElement;
8
+ }
9
+ export interface SvelteMountController<TProps, TInstance> {
10
+ readonly instance: TInstance | null;
11
+ readonly mounted: boolean;
12
+ mountOrUpdate(props: TProps): TInstance | null;
13
+ update(props: TProps): void;
14
+ teardown(options?: {
15
+ removeContainer?: boolean;
16
+ }): void;
17
+ }
18
+ /**
19
+ * Owns Svelte custom-element mount policy in one place.
20
+ *
21
+ * Svelte 5 adapters supply createSubscriber to track shallow reactive props so a
22
+ * response update preserves the component, input focus, and local state.
23
+ * The $set/remount fallback remains for existing callers without that bridge.
24
+ */
25
+ export declare function createSvelteMountController<TProps, TInstance>({ host, mount, createSubscriber, unmount, createContainer, }: SvelteMountControllerOptions<TProps, TInstance>): SvelteMountController<TProps, TInstance>;