@learnosity/lib-qti-converter 0.12.8 → 0.14.0
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/docs/EXAMPLES.md +46 -34
- package/docs/GETTING_STARTED.md +88 -31
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +24 -8
- package/package.json +1 -1
- package/packages/cli/dist/{batchProcessors-CUJoQD8a.js → batchProcessors-DWG8qk7G.js} +296 -80
- package/packages/cli/dist/batchProcessors-DWG8qk7G.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +1 -1
- package/packages/cli/dist/{learnosityToQti-CvfVQ6Kl.js → learnosityToQti-C7cTRTU2.js} +4 -4
- package/packages/cli/dist/{learnosityToQti-CvfVQ6Kl.js.map → learnosityToQti-C7cTRTU2.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQtiPackage-CXMsJNQD.js → learnosityToQtiPackage-C84dQKKi.js} +4 -4
- package/packages/cli/dist/{learnosityToQtiPackage-CXMsJNQD.js.map → learnosityToQtiPackage-C84dQKKi.js.map} +1 -1
- package/packages/cli/dist/main.js +4 -4
- package/packages/cli/dist/{pathUtils-DmtCfutO.js → pathUtils-Cr9IcK0n.js} +21 -6
- package/packages/cli/dist/{pathUtils-DmtCfutO.js.map → pathUtils-Cr9IcK0n.js.map} +1 -1
- package/packages/cli/dist/{qtiPackageToLearnosity-FhfNr7gf.js → qtiPackageToLearnosity-BBfZgWBh.js} +14 -8
- package/packages/cli/dist/qtiPackageToLearnosity-BBfZgWBh.js.map +1 -0
- package/packages/cli/dist/{qtiToLearnosity-5lQ5f3-t.js → qtiToLearnosity-C9OW_n7Z.js} +6 -5
- package/packages/cli/dist/qtiToLearnosity-C9OW_n7Z.js.map +1 -0
- package/packages/cli/dist/{resolveOptions-lHxSyq9F.js → resolveOptions-D_UECo_9.js} +22 -7
- package/packages/cli/dist/resolveOptions-D_UECo_9.js.map +1 -0
- package/packages/cli/dist/{table-7b-8MN2z.js → table-D1ydwhbX.js} +536 -175
- package/packages/cli/dist/table-D1ydwhbX.js.map +1 -0
- package/packages/core/dist/index.d.ts +20 -4
- package/packages/core/dist/index.js +802 -246
- package/packages/core/dist/node.d.ts +23 -5
- package/packages/core/dist/node.js +828 -251
- package/packages/cli/dist/batchProcessors-CUJoQD8a.js.map +0 -1
- package/packages/cli/dist/qtiPackageToLearnosity-FhfNr7gf.js.map +0 -1
- package/packages/cli/dist/qtiToLearnosity-5lQ5f3-t.js.map +0 -1
- package/packages/cli/dist/resolveOptions-lHxSyq9F.js.map +0 -1
- package/packages/cli/dist/table-7b-8MN2z.js.map +0 -1
|
@@ -181,6 +181,9 @@ const DiagnosticCode = {
|
|
|
181
181
|
QTI_PACKAGE_NO_CONTENT: "QTI_PACKAGE_NO_CONTENT",
|
|
182
182
|
QTI_PACKAGE_DUPLICATE_IDENTIFIER: "QTI_PACKAGE_DUPLICATE_IDENTIFIER",
|
|
183
183
|
QTI_ITEM_CONVERSION_FAILED: "QTI_ITEM_CONVERSION_FAILED",
|
|
184
|
+
QTI_ASSET_HREF_UNSAFE: "QTI_ASSET_HREF_UNSAFE",
|
|
185
|
+
QTI_ASSET_FILENAME_CONFLICT: "QTI_ASSET_FILENAME_CONFLICT",
|
|
186
|
+
QTI_ASSET_IDENTITY_BYTES_CONFLICT: "QTI_ASSET_IDENTITY_BYTES_CONFLICT",
|
|
184
187
|
LRN_BUNDLE_WRITTEN: "LRN_BUNDLE_WRITTEN",
|
|
185
188
|
QTI_DOWNGRADE_NAMESPACE: "QTI_DOWNGRADE_NAMESPACE",
|
|
186
189
|
QTI_DOWNGRADE_SCHEMA_LOCATION: "QTI_DOWNGRADE_SCHEMA_LOCATION",
|
|
@@ -22996,6 +22999,33 @@ function md5hex(input) {
|
|
|
22996
22999
|
return hex;
|
|
22997
23000
|
}
|
|
22998
23001
|
//#endregion
|
|
23002
|
+
//#region src/qti-to-learnosity/utils/mediaFeature.ts
|
|
23003
|
+
/**
|
|
23004
|
+
* Build a stable UUID-shaped identifier for a media feature.
|
|
23005
|
+
*
|
|
23006
|
+
* Feature output must remain identical for equivalent directory and ZIP
|
|
23007
|
+
* package conversions, so the identifier is derived from the final media URL
|
|
23008
|
+
* rather than generated randomly. The UUID version and variant bits are set
|
|
23009
|
+
* to keep the value compatible with consumers expecting a v4-shaped UUID.
|
|
23010
|
+
*/
|
|
23011
|
+
function buildMediaFeatureId(transformedUrl) {
|
|
23012
|
+
const hash = md5hex(transformedUrl).split("");
|
|
23013
|
+
const variant = [
|
|
23014
|
+
"8",
|
|
23015
|
+
"9",
|
|
23016
|
+
"a",
|
|
23017
|
+
"b"
|
|
23018
|
+
][parseInt(hash[16], 16) & 3];
|
|
23019
|
+
hash[12] = "4";
|
|
23020
|
+
hash[16] = variant;
|
|
23021
|
+
return `${hash.slice(0, 8).join("")}-${hash.slice(8, 12).join("")}-${hash.slice(12, 16).join("")}-${hash.slice(16, 20).join("")}-${hash.slice(20).join("")}`;
|
|
23022
|
+
}
|
|
23023
|
+
/** Build a Learnosity simple-feature span for audio or hosted video. */
|
|
23024
|
+
function buildMediaFeatureSpan(transformedUrl, kind, featureId = buildMediaFeatureId(transformedUrl)) {
|
|
23025
|
+
if (kind === "audio") return `<span class="learnosity-feature" data-player="button" data-simplefeature_id="${featureId}" data-src="${transformedUrl}" data-type="audioplayer"></span>`;
|
|
23026
|
+
return `<span class="learnosity-feature" data-player_type="hosted-video" data-simplefeature_id="${featureId}" data-src="${transformedUrl}" data-text_alternative.caption.src="" data-type="videoplayer"></span>`;
|
|
23027
|
+
}
|
|
23028
|
+
//#endregion
|
|
22999
23029
|
//#region src/qti-to-learnosity/utils/convertObjectElement.ts
|
|
23000
23030
|
/**
|
|
23001
23031
|
* Convert QTI <object> elements to appropriate Learnosity HTML elements
|
|
@@ -23047,7 +23077,7 @@ function buildDeterministicFeatureId(transformedUrl) {
|
|
|
23047
23077
|
* <object data="video.mp4" type="video/mp4"/>
|
|
23048
23078
|
* → <span class="learnosity-feature" data-player_type="hosted-video" data-simplefeature_id="..." data-src="[cdn-url]" data-text_alternative.caption.src="" data-type="videoplayer"></span>
|
|
23049
23079
|
*/
|
|
23050
|
-
function convertObjectToElement(objectTag, organisationId, mediaVault = false, customAssetUrl) {
|
|
23080
|
+
function convertObjectToElement(objectTag, organisationId, mediaVault = false, customAssetUrl, assetContext = {}) {
|
|
23051
23081
|
const dataMatch = objectTag.match(/data=["']([^"']+)["']/i);
|
|
23052
23082
|
const srcMatch = objectTag.match(/src=["']([^"']+)["']/i);
|
|
23053
23083
|
const typeMatch = objectTag.match(/type=["']([^"']+)["']/i);
|
|
@@ -23057,11 +23087,11 @@ function convertObjectToElement(objectTag, organisationId, mediaVault = false, c
|
|
|
23057
23087
|
if (!urlMatch) return objectTag;
|
|
23058
23088
|
const sourceUrl = urlMatch[1];
|
|
23059
23089
|
const category = getMimeTypeCategory(typeMatch ? typeMatch[1] : "");
|
|
23060
|
-
const transformedUrl = transformUrl(sourceUrl, organisationId, mediaVault, customAssetUrl);
|
|
23090
|
+
const transformedUrl = transformUrl(sourceUrl, organisationId, mediaVault, customAssetUrl, assetContext);
|
|
23061
23091
|
switch (category) {
|
|
23062
23092
|
case "image": return buildImageTag(transformedUrl, heightMatch, widthMatch);
|
|
23063
|
-
case "audio": return
|
|
23064
|
-
case "video": return
|
|
23093
|
+
case "audio": return buildMediaFeatureSpan(transformedUrl, "audio", buildDeterministicFeatureId(transformedUrl));
|
|
23094
|
+
case "video": return buildMediaFeatureSpan(transformedUrl, "video", buildDeterministicFeatureId(transformedUrl));
|
|
23065
23095
|
default: return objectTag.replace(sourceUrl, transformedUrl);
|
|
23066
23096
|
}
|
|
23067
23097
|
}
|
|
@@ -23105,55 +23135,139 @@ function normalizeTableClass(html) {
|
|
|
23105
23135
|
});
|
|
23106
23136
|
}
|
|
23107
23137
|
//#endregion
|
|
23108
|
-
//#region src/qti-to-learnosity/utils/
|
|
23138
|
+
//#region src/qti-to-learnosity/utils/assetIdentity.ts
|
|
23109
23139
|
/**
|
|
23110
|
-
*
|
|
23111
|
-
* TASK 030
|
|
23140
|
+
* Browser-safe helpers for identifying package-local QTI assets.
|
|
23112
23141
|
*
|
|
23113
|
-
*
|
|
23142
|
+
* QTI asset references are package-relative paths, not filesystem paths. Keeping
|
|
23143
|
+
* their canonical form here makes directory and ZIP inputs produce the same
|
|
23144
|
+
* identity while rejecting references that could escape the package root.
|
|
23114
23145
|
*/
|
|
23146
|
+
/** Asset extensions copied and rewritten by QTI → Learnosity conversion. */
|
|
23147
|
+
const QTI_ASSET_EXTENSIONS = [
|
|
23148
|
+
".png",
|
|
23149
|
+
".jpg",
|
|
23150
|
+
".jpeg",
|
|
23151
|
+
".gif",
|
|
23152
|
+
".svg",
|
|
23153
|
+
".webp",
|
|
23154
|
+
".bmp",
|
|
23155
|
+
".ico",
|
|
23156
|
+
".mp3",
|
|
23157
|
+
".mp4",
|
|
23158
|
+
".wav",
|
|
23159
|
+
".ogg",
|
|
23160
|
+
".webm",
|
|
23161
|
+
".ogv",
|
|
23162
|
+
".m4a",
|
|
23163
|
+
".m4v",
|
|
23164
|
+
".css",
|
|
23165
|
+
".woff",
|
|
23166
|
+
".woff2",
|
|
23167
|
+
".ttf",
|
|
23168
|
+
".eot",
|
|
23169
|
+
".pdf",
|
|
23170
|
+
".json"
|
|
23171
|
+
];
|
|
23172
|
+
function isSupportedQtiAssetPath(path) {
|
|
23173
|
+
const lowerPath = path.toLowerCase();
|
|
23174
|
+
return !lowerPath.endsWith(".html") && !lowerPath.endsWith(".htm") && QTI_ASSET_EXTENSIONS.some((extension) => lowerPath.endsWith(extension));
|
|
23175
|
+
}
|
|
23176
|
+
function isUnsafeQtiAssetHrefError(error) {
|
|
23177
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
23178
|
+
}
|
|
23115
23179
|
/**
|
|
23116
|
-
*
|
|
23117
|
-
|
|
23118
|
-
|
|
23119
|
-
|
|
23120
|
-
|
|
23121
|
-
|
|
23122
|
-
|
|
23123
|
-
|
|
23124
|
-
"
|
|
23125
|
-
|
|
23126
|
-
|
|
23127
|
-
"
|
|
23128
|
-
"
|
|
23129
|
-
"
|
|
23130
|
-
|
|
23131
|
-
|
|
23132
|
-
|
|
23133
|
-
|
|
23180
|
+
* Canonicalize a package-relative QTI asset href.
|
|
23181
|
+
*
|
|
23182
|
+
* Query strings and fragments are URL metadata and do not identify a different
|
|
23183
|
+
* package asset. Path separators are normalized to `/`, dot segments are
|
|
23184
|
+
* resolved, and traversal above the package root is rejected.
|
|
23185
|
+
*/
|
|
23186
|
+
function stripHrefMetadata(href) {
|
|
23187
|
+
const metadataStart = href.search(/[?#]/);
|
|
23188
|
+
return (metadataStart === -1 ? href : href.slice(0, metadataStart)).replaceAll("\\", "/");
|
|
23189
|
+
}
|
|
23190
|
+
function assertPackageRelativePath(path, href) {
|
|
23191
|
+
const isAbsolute = path.startsWith("/") || /^[A-Za-z]:/.test(path) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(path);
|
|
23192
|
+
if (!path || path.includes("\0") || isAbsolute) throw new Error(`Unsafe QTI asset href: ${href}`);
|
|
23193
|
+
if (path.endsWith("/")) throw new Error(`QTI asset href has no filename: ${href}`);
|
|
23194
|
+
}
|
|
23195
|
+
function normalizePathSegments(path, href) {
|
|
23196
|
+
const segments = [];
|
|
23197
|
+
for (const segment of path.split("/")) {
|
|
23198
|
+
if (!segment || segment === ".") continue;
|
|
23199
|
+
if (segment === "..") {
|
|
23200
|
+
if (segments.length === 0) throw new Error(`Unsafe QTI asset href: ${href}`);
|
|
23201
|
+
segments.pop();
|
|
23202
|
+
continue;
|
|
23203
|
+
}
|
|
23204
|
+
segments.push(segment);
|
|
23205
|
+
}
|
|
23206
|
+
if (segments.length === 0) throw new Error(`QTI asset href has no filename: ${href}`);
|
|
23207
|
+
return segments.join("/");
|
|
23208
|
+
}
|
|
23209
|
+
function canonicalizeQtiAssetHref(href) {
|
|
23210
|
+
if (typeof href !== "string") throw new TypeError("QTI asset href must be a string");
|
|
23211
|
+
const path = stripHrefMetadata(href);
|
|
23212
|
+
assertPackageRelativePath(path, href);
|
|
23213
|
+
return normalizePathSegments(path, href);
|
|
23214
|
+
}
|
|
23215
|
+
/** Return the final filename from a canonicalized package-relative href. */
|
|
23216
|
+
function extractQtiAssetBasename(href) {
|
|
23217
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
23218
|
+
return canonicalHref.slice(canonicalHref.lastIndexOf("/") + 1);
|
|
23219
|
+
}
|
|
23134
23220
|
/**
|
|
23135
|
-
*
|
|
23136
|
-
*
|
|
23137
|
-
* `RegExp.prototype.test` on non-global regexes, so they are safe to share.
|
|
23221
|
+
* Return the final filename extension, including its leading dot.
|
|
23222
|
+
* Dotfiles and filenames ending in a dot have no extension.
|
|
23138
23223
|
*/
|
|
23139
|
-
|
|
23140
|
-
|
|
23141
|
-
|
|
23142
|
-
|
|
23143
|
-
|
|
23144
|
-
|
|
23145
|
-
|
|
23146
|
-
|
|
23147
|
-
|
|
23224
|
+
function extractQtiAssetExtension(href) {
|
|
23225
|
+
const basename = extractQtiAssetBasename(href);
|
|
23226
|
+
const extensionStart = basename.lastIndexOf(".");
|
|
23227
|
+
return extensionStart > 0 && extensionStart < basename.length - 1 ? basename.slice(extensionStart) : "";
|
|
23228
|
+
}
|
|
23229
|
+
/**
|
|
23230
|
+
* Serialize the item-scoped asset identity using an ordered JSON tuple.
|
|
23231
|
+
*
|
|
23232
|
+
* JSON serialization is intentional: unlike delimiter-based concatenation, it
|
|
23233
|
+
* keeps the item reference and canonical href unambiguous when either value
|
|
23234
|
+
* contains punctuation that could otherwise be mistaken for a separator.
|
|
23235
|
+
*/
|
|
23236
|
+
function serializeQtiAssetIdentity(finalItemReference, qtiAssetHref) {
|
|
23237
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
23238
|
+
return JSON.stringify([finalItemReference, canonicalHref]);
|
|
23239
|
+
}
|
|
23240
|
+
/** Derive the lowercase MD5 hex hash for a canonical item-scoped identity. */
|
|
23241
|
+
function hashQtiAssetIdentity(finalItemReference, qtiAssetHref) {
|
|
23242
|
+
return md5hex(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
23243
|
+
}
|
|
23244
|
+
/**
|
|
23245
|
+
* Select the output filename for a package-local QTI asset.
|
|
23246
|
+
*
|
|
23247
|
+
* Hashed naming is the default so the full item-scoped identity, rather than a
|
|
23248
|
+
* globally ambiguous source basename, determines the output name. Only the
|
|
23249
|
+
* canonical source extension is retained after the digest. Preserve mode is
|
|
23250
|
+
* an explicit compatibility opt-out and returns the canonical final basename.
|
|
23251
|
+
*/
|
|
23252
|
+
function selectQtiAssetFilename(finalItemReference, qtiAssetHref, preserveAssetFilenames = false) {
|
|
23253
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
23254
|
+
if (preserveAssetFilenames) return extractQtiAssetBasename(canonicalHref);
|
|
23255
|
+
return `${hashQtiAssetIdentity(finalItemReference, canonicalHref)}${extractQtiAssetExtension(canonicalHref)}`;
|
|
23256
|
+
}
|
|
23257
|
+
//#endregion
|
|
23258
|
+
//#region src/qti-to-learnosity/utils/assetUrlTransform.ts
|
|
23148
23259
|
/**
|
|
23149
|
-
*
|
|
23260
|
+
* Asset URL transformation for Learnosity CDN
|
|
23261
|
+
* TASK 030
|
|
23150
23262
|
*
|
|
23151
|
-
*
|
|
23152
|
-
* be influenced at runtime. Global regex used only with
|
|
23153
|
-
* `String.prototype.replace`, which resets lastIndex on completion, so sharing
|
|
23154
|
-
* a single compiled instance across calls is safe.
|
|
23263
|
+
* Transforms asset URLs in HTML content to use Learnosity CDN URLs.
|
|
23155
23264
|
*/
|
|
23156
|
-
|
|
23265
|
+
/** Matches supported asset-bearing HTML attributes on any element. */
|
|
23266
|
+
const ASSET_ATTRIBUTE_PATTERN = /(<[A-Za-z][^>]*?\b(?:src|data|href)\s*=\s*["'])([^"']+)(["'][^>]*>)/gi;
|
|
23267
|
+
/** Matches <object ...> (optionally with its closing tag) for element conversion. */
|
|
23268
|
+
const OBJECT_TAG_PATTERN = /<object\s+[^>]*>(?:<\/object>)?/gi;
|
|
23269
|
+
/** Matches anchors whose href points to inline audio/video media. */
|
|
23270
|
+
const INLINE_MEDIA_LINK_PATTERN = /<a\b([^>]*?)\bhref\s*=\s*(["'])([^"']+)\2([^>]*)>([\s\S]*?)<\/a\s*>/gi;
|
|
23157
23271
|
/**
|
|
23158
23272
|
* Extract filename from a URL path
|
|
23159
23273
|
* Examples:
|
|
@@ -23165,12 +23279,26 @@ function extractFilename$1(url) {
|
|
|
23165
23279
|
const segments = url.split("?")[0].split("#")[0].split("/");
|
|
23166
23280
|
return segments[segments.length - 1];
|
|
23167
23281
|
}
|
|
23168
|
-
/**
|
|
23169
|
-
* Check if a filename has a supported asset extension
|
|
23170
|
-
*/
|
|
23171
23282
|
function isSupportedAsset(filename) {
|
|
23172
|
-
|
|
23173
|
-
|
|
23283
|
+
return isSupportedQtiAssetPath(filename);
|
|
23284
|
+
}
|
|
23285
|
+
function getInlineMediaKind(url, attributes) {
|
|
23286
|
+
const mimeType = attributes.match(/\btype\s*=\s*(["'])([^"']+)\1/i)?.[2].toLowerCase();
|
|
23287
|
+
if (mimeType?.startsWith("audio/")) return "audio";
|
|
23288
|
+
if (mimeType?.startsWith("video/")) return "video";
|
|
23289
|
+
const filename = extractFilename$1(url).toLowerCase();
|
|
23290
|
+
if ([
|
|
23291
|
+
".mp3",
|
|
23292
|
+
".wav",
|
|
23293
|
+
".ogg",
|
|
23294
|
+
".m4a"
|
|
23295
|
+
].some((extension) => filename.endsWith(extension))) return "audio";
|
|
23296
|
+
if ([
|
|
23297
|
+
".mp4",
|
|
23298
|
+
".webm",
|
|
23299
|
+
".ogv",
|
|
23300
|
+
".m4v"
|
|
23301
|
+
].some((extension) => filename.endsWith(extension))) return "video";
|
|
23174
23302
|
}
|
|
23175
23303
|
/**
|
|
23176
23304
|
* Build Learnosity CDN URL for an asset
|
|
@@ -23180,17 +23308,24 @@ function buildLearnosityAssetUrl(filename, organisationId, mediaVault = false, c
|
|
|
23180
23308
|
if (customAssetUrl) return `${customAssetUrl.endsWith("/") ? customAssetUrl.slice(0, -1) : customAssetUrl}/${filename}`;
|
|
23181
23309
|
return `https://${mediaVault ? "media-vault" : "assets"}.learnosity.com/organisations/${organisationId}/${filename}`;
|
|
23182
23310
|
}
|
|
23311
|
+
function resolveQtiAssetHref(url, sourceHrefBase) {
|
|
23312
|
+
const normalizedUrl = url.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
23313
|
+
const isItemRelative = /^\.\.?\//.test(normalizedUrl) || !normalizedUrl.includes("/");
|
|
23314
|
+
if (!sourceHrefBase || !isItemRelative) return canonicalizeQtiAssetHref(url);
|
|
23315
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
23316
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${normalizedUrl}`);
|
|
23317
|
+
}
|
|
23183
23318
|
/**
|
|
23184
23319
|
* Transform a single URL to Learnosity CDN format
|
|
23185
23320
|
* Exported for use in image object source fields
|
|
23186
23321
|
*/
|
|
23187
|
-
function transformUrl(url, organisationId, mediaVault = false, customAssetUrl) {
|
|
23322
|
+
function transformUrl(url, organisationId, mediaVault = false, customAssetUrl, context = {}) {
|
|
23188
23323
|
if (url.includes("assets.learnosity.com") || url.includes("media-vault.learnosity.com")) return url;
|
|
23189
|
-
if (
|
|
23324
|
+
if (/^https?:\/\//i.test(url) || url.startsWith("//")) return url;
|
|
23190
23325
|
if (url.startsWith("data:")) return url;
|
|
23191
23326
|
const filename = extractFilename$1(url);
|
|
23192
23327
|
if (!isSupportedAsset(filename)) return url;
|
|
23193
|
-
return buildLearnosityAssetUrl(filename, organisationId, mediaVault, customAssetUrl);
|
|
23328
|
+
return buildLearnosityAssetUrl(context.finalItemReference ? selectQtiAssetFilename(context.finalItemReference, resolveQtiAssetHref(url, context.sourceHrefBase), context.preserveAssetFilenames ?? false) : filename, organisationId, mediaVault, customAssetUrl);
|
|
23194
23329
|
}
|
|
23195
23330
|
/**
|
|
23196
23331
|
* Transform asset URLs in HTML content
|
|
@@ -23208,14 +23343,24 @@ function transformUrl(url, organisationId, mediaVault = false, customAssetUrl) {
|
|
|
23208
23343
|
*/
|
|
23209
23344
|
function transformAssetUrls(html, options) {
|
|
23210
23345
|
if (!html) return html;
|
|
23211
|
-
if (
|
|
23346
|
+
if (Array.from(html.matchAll(ASSET_ATTRIBUTE_PATTERN)).some((match) => isSupportedAsset(extractFilename$1(match[2]))) && !options.organisationId) throw new Error("Asset references found in QTI content but no --organisation_id provided. Please provide --organisation_id to convert assets to Learnosity CDN URLs.");
|
|
23212
23347
|
if (!options.organisationId) return normalizeTableClass(html);
|
|
23213
23348
|
const orgId = options.organisationId;
|
|
23214
23349
|
const mediaVault = options.mediaVault ?? false;
|
|
23215
23350
|
const customAssetUrl = options.customAssetUrl;
|
|
23351
|
+
const assetContext = {
|
|
23352
|
+
finalItemReference: options.finalItemReference,
|
|
23353
|
+
preserveAssetFilenames: options.preserveAssetFilenames,
|
|
23354
|
+
sourceHrefBase: options.sourceHrefBase
|
|
23355
|
+
};
|
|
23216
23356
|
let result = html;
|
|
23217
|
-
result = result.replace(OBJECT_TAG_PATTERN, (match) => convertObjectToElement(match, orgId, mediaVault, customAssetUrl));
|
|
23218
|
-
result = result.replace(
|
|
23357
|
+
result = result.replace(OBJECT_TAG_PATTERN, (match) => convertObjectToElement(match, orgId, mediaVault, customAssetUrl, assetContext));
|
|
23358
|
+
result = result.replace(INLINE_MEDIA_LINK_PATTERN, (match, beforeAttributes, _quote, url, afterAttributes) => {
|
|
23359
|
+
const kind = getInlineMediaKind(url, `${beforeAttributes}${afterAttributes}`);
|
|
23360
|
+
if (!kind) return match;
|
|
23361
|
+
return buildMediaFeatureSpan(transformUrl(url, orgId, mediaVault, customAssetUrl, assetContext), kind);
|
|
23362
|
+
});
|
|
23363
|
+
result = result.replace(ASSET_ATTRIBUTE_PATTERN, (_match, prefix, url, suffix) => prefix + transformUrl(url, orgId, mediaVault, customAssetUrl, assetContext) + suffix);
|
|
23219
23364
|
result = normalizeHtmlWhitespace(result);
|
|
23220
23365
|
result = normalizeTableClass(result);
|
|
23221
23366
|
return result;
|
|
@@ -23223,12 +23368,16 @@ function transformAssetUrls(html, options) {
|
|
|
23223
23368
|
//#endregion
|
|
23224
23369
|
//#region src/qti-to-learnosity/utils/generateItemReference.ts
|
|
23225
23370
|
/**
|
|
23226
|
-
* Generate item reference based on the configured source
|
|
23371
|
+
* Generate item reference based on the configured source.
|
|
23372
|
+
*
|
|
23373
|
+
* - `'itemIdentifier'` (default) and its deprecated alias `'qti'`, as well as an
|
|
23374
|
+
* omitted source, return the QTI `identifier`.
|
|
23375
|
+
* - `'uuid'` returns an MD5 hash of the QTI `identifier`.
|
|
23376
|
+
* - `'sourceFilename'` derives the reference from the source file name.
|
|
23227
23377
|
*/
|
|
23228
23378
|
function generateItemReference(qtiIdentifier, itemReferenceSource, sourceFile) {
|
|
23229
|
-
if (itemReferenceSource === "qti") return qtiIdentifier;
|
|
23230
23379
|
if (itemReferenceSource === "uuid") return md5hex(qtiIdentifier);
|
|
23231
|
-
if (sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23380
|
+
if (itemReferenceSource === "sourceFilename" && sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23232
23381
|
return qtiIdentifier;
|
|
23233
23382
|
}
|
|
23234
23383
|
//#endregion
|
|
@@ -23361,23 +23510,30 @@ function mapCorrectPairsToValidation(correctPairs, stemIdToIndex, optionIdToInde
|
|
|
23361
23510
|
/**
|
|
23362
23511
|
* Convert matchInteraction to Learnosity choicematrix
|
|
23363
23512
|
*/
|
|
23364
|
-
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23513
|
+
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23365
23514
|
const parsed = readAssessmentItemMatch(inputXml);
|
|
23366
23515
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23367
23516
|
diagnostics.push(...updatedDiagnostics);
|
|
23368
23517
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23369
23518
|
if (!parsed.identifier || parsed.stems.length === 0 || parsed.options.length === 0) return { diagnostics };
|
|
23370
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23519
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23520
|
+
const transformContext = {
|
|
23521
|
+
finalItemReference: itemRef,
|
|
23522
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23523
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23524
|
+
};
|
|
23371
23525
|
const questionRef = md5hex(itemRef);
|
|
23372
23526
|
const stems = parsed.stems.map((stem) => transformAssetUrls(stem.text, {
|
|
23373
23527
|
organisationId,
|
|
23374
23528
|
mediaVault,
|
|
23375
|
-
customAssetUrl
|
|
23529
|
+
customAssetUrl,
|
|
23530
|
+
...transformContext
|
|
23376
23531
|
}));
|
|
23377
23532
|
const options = parsed.options.map((option) => transformAssetUrls(option.text, {
|
|
23378
23533
|
organisationId,
|
|
23379
23534
|
mediaVault,
|
|
23380
|
-
customAssetUrl
|
|
23535
|
+
customAssetUrl,
|
|
23536
|
+
...transformContext
|
|
23381
23537
|
}));
|
|
23382
23538
|
const stemIdToIndex = /* @__PURE__ */ new Map();
|
|
23383
23539
|
parsed.stems.forEach((stem, index) => {
|
|
@@ -23395,7 +23551,8 @@ function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId
|
|
|
23395
23551
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
23396
23552
|
organisationId,
|
|
23397
23553
|
mediaVault,
|
|
23398
|
-
customAssetUrl
|
|
23554
|
+
customAssetUrl,
|
|
23555
|
+
...transformContext
|
|
23399
23556
|
});
|
|
23400
23557
|
const item = {
|
|
23401
23558
|
item: {
|
|
@@ -23775,25 +23932,32 @@ function buildGapValidation(gaps, gapIdToGapTextIds, gapTextIdToContent, sourceF
|
|
|
23775
23932
|
/**
|
|
23776
23933
|
* Convert gapMatchInteraction to Learnosity clozeassociation
|
|
23777
23934
|
*/
|
|
23778
|
-
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23935
|
+
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23779
23936
|
const parsed = readAssessmentItemGapMatch(inputXml);
|
|
23780
23937
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23781
23938
|
diagnostics.push(...updatedDiagnostics);
|
|
23782
23939
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23783
23940
|
if (!parsed.identifier || parsed.gapTexts.length === 0 || parsed.gaps.length === 0) return { diagnostics };
|
|
23784
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23941
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23942
|
+
const transformContext = {
|
|
23943
|
+
finalItemReference: itemRef,
|
|
23944
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23945
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23946
|
+
};
|
|
23785
23947
|
const questionRef = md5hex(itemRef);
|
|
23786
23948
|
const possibleResponses = parsed.gapTexts.map((gt) => transformAssetUrls(gt.text, {
|
|
23787
23949
|
organisationId,
|
|
23788
23950
|
mediaVault,
|
|
23789
|
-
customAssetUrl
|
|
23951
|
+
customAssetUrl,
|
|
23952
|
+
...transformContext
|
|
23790
23953
|
}));
|
|
23791
23954
|
const gapTextIdToContent = /* @__PURE__ */ new Map();
|
|
23792
23955
|
parsed.gapTexts.forEach((gt) => {
|
|
23793
23956
|
const transformedText = transformAssetUrls(gt.text, {
|
|
23794
23957
|
organisationId,
|
|
23795
23958
|
mediaVault,
|
|
23796
|
-
customAssetUrl
|
|
23959
|
+
customAssetUrl,
|
|
23960
|
+
...transformContext
|
|
23797
23961
|
});
|
|
23798
23962
|
gapTextIdToContent.set(gt.identifier, transformedText);
|
|
23799
23963
|
});
|
|
@@ -23811,7 +23975,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23811
23975
|
template: transformAssetUrls(parsed.templateHtml ?? "", {
|
|
23812
23976
|
organisationId,
|
|
23813
23977
|
mediaVault,
|
|
23814
|
-
customAssetUrl
|
|
23978
|
+
customAssetUrl,
|
|
23979
|
+
...transformContext
|
|
23815
23980
|
}),
|
|
23816
23981
|
possible_responses: possibleResponses,
|
|
23817
23982
|
shuffle_options: parsed.shuffle ?? false,
|
|
@@ -23826,7 +23991,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23826
23991
|
if (parsed.promptHtml) questionData.stimulus = transformAssetUrls(parsed.promptHtml, {
|
|
23827
23992
|
organisationId,
|
|
23828
23993
|
mediaVault,
|
|
23829
|
-
customAssetUrl
|
|
23994
|
+
customAssetUrl,
|
|
23995
|
+
...transformContext
|
|
23830
23996
|
});
|
|
23831
23997
|
if (maxResponsesPerZone > 1) questionData.max_response_per_zone = maxResponsesPerZone;
|
|
23832
23998
|
const choiceCounts = /* @__PURE__ */ new Map();
|
|
@@ -24231,19 +24397,22 @@ function buildValidationValues(interactions, responseDeclarations, diagnostics,
|
|
|
24231
24397
|
* Convert inlineChoiceInteraction to Learnosity clozedropdown
|
|
24232
24398
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
24233
24399
|
*/
|
|
24234
|
-
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
24400
|
+
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
24235
24401
|
const parsed = readAssessmentItemInlineChoice(inputXml);
|
|
24236
24402
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24237
24403
|
diagnostics.push(...updatedDiagnostics);
|
|
24238
24404
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24239
24405
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
24240
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24241
|
-
const questionRef = md5hex(itemRef);
|
|
24406
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24242
24407
|
const transformOpts = {
|
|
24243
24408
|
organisationId,
|
|
24244
24409
|
mediaVault,
|
|
24245
|
-
customAssetUrl
|
|
24410
|
+
customAssetUrl,
|
|
24411
|
+
finalItemReference: itemRef,
|
|
24412
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24413
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24246
24414
|
};
|
|
24415
|
+
const questionRef = md5hex(itemRef);
|
|
24247
24416
|
const possibleResponses = parsed.interactions.map((interaction) => interaction.choices.map((choice) => transformAssetUrls(choice.text, transformOpts)));
|
|
24248
24417
|
const validationValue = buildValidationValues(parsed.interactions, parsed.responseDeclarations, diagnostics, transformOpts, sourceFile);
|
|
24249
24418
|
if (!validationValue) return { diagnostics };
|
|
@@ -24510,23 +24679,30 @@ function readAssessmentItemOrder(inputXml) {
|
|
|
24510
24679
|
/**
|
|
24511
24680
|
* Convert orderInteraction to Learnosity orderlist
|
|
24512
24681
|
*/
|
|
24513
|
-
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
24682
|
+
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
24514
24683
|
const parsed = readAssessmentItemOrder(inputXml);
|
|
24515
24684
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24516
24685
|
diagnostics.push(...updatedDiagnostics);
|
|
24517
24686
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24518
24687
|
if (!parsed.identifier || !parsed.responseIdentifier || parsed.choices.length === 0) return { diagnostics };
|
|
24519
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24688
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24689
|
+
const transformContext = {
|
|
24690
|
+
finalItemReference: itemRef,
|
|
24691
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24692
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24693
|
+
};
|
|
24520
24694
|
const questionRef = md5hex(itemRef);
|
|
24521
24695
|
const stimulus = transformAssetUrls(parsed.stimulusText ?? "", {
|
|
24522
24696
|
organisationId,
|
|
24523
24697
|
mediaVault,
|
|
24524
|
-
customAssetUrl
|
|
24698
|
+
customAssetUrl,
|
|
24699
|
+
...transformContext
|
|
24525
24700
|
});
|
|
24526
24701
|
const list = parsed.choices.map((choice) => transformAssetUrls(choice.text, {
|
|
24527
24702
|
organisationId,
|
|
24528
24703
|
mediaVault,
|
|
24529
|
-
customAssetUrl
|
|
24704
|
+
customAssetUrl,
|
|
24705
|
+
...transformContext
|
|
24530
24706
|
}));
|
|
24531
24707
|
let validationValue;
|
|
24532
24708
|
if (parsed.correctOrder && parsed.correctOrder.length > 0) {
|
|
@@ -24901,17 +25077,19 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics, sou
|
|
|
24901
25077
|
/**
|
|
24902
25078
|
* Build the combined stimulus HTML from parsed stimulusText and promptText
|
|
24903
25079
|
*/
|
|
24904
|
-
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
25080
|
+
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
24905
25081
|
let stimulus = "";
|
|
24906
25082
|
if (parsed.stimulusText) stimulus += transformAssetUrls(parsed.stimulusText, {
|
|
24907
25083
|
organisationId,
|
|
24908
25084
|
mediaVault,
|
|
24909
|
-
customAssetUrl
|
|
25085
|
+
customAssetUrl,
|
|
25086
|
+
...assetTransformContext
|
|
24910
25087
|
});
|
|
24911
25088
|
if (parsed.promptText) stimulus += `<p>${transformAssetUrls(parsed.promptText, {
|
|
24912
25089
|
organisationId,
|
|
24913
25090
|
mediaVault,
|
|
24914
|
-
customAssetUrl
|
|
25091
|
+
customAssetUrl,
|
|
25092
|
+
...assetTransformContext
|
|
24915
25093
|
})}</p>`;
|
|
24916
25094
|
return stimulus;
|
|
24917
25095
|
}
|
|
@@ -24936,7 +25114,7 @@ function buildHotspotValidation(correctResponses, choiceIdToIndex) {
|
|
|
24936
25114
|
/**
|
|
24937
25115
|
* Convert hotspotInteraction to Learnosity hotspot
|
|
24938
25116
|
*/
|
|
24939
|
-
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
25117
|
+
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
24940
25118
|
const parsed = readAssessmentItemHotspot(inputXml);
|
|
24941
25119
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24942
25120
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -24958,10 +25136,15 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
24958
25136
|
return { diagnostics };
|
|
24959
25137
|
}
|
|
24960
25138
|
}
|
|
24961
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25139
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25140
|
+
const transformContext = {
|
|
25141
|
+
finalItemReference: itemRef,
|
|
25142
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25143
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25144
|
+
};
|
|
24962
25145
|
const questionRef = md5hex(itemRef);
|
|
24963
|
-
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
24964
|
-
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl) : parsed.imageSource;
|
|
25146
|
+
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
25147
|
+
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.imageSource;
|
|
24965
25148
|
const areas = [];
|
|
24966
25149
|
const choiceIdToIndex = /* @__PURE__ */ new Map();
|
|
24967
25150
|
for (const choice of parsed.hotspotChoices) {
|
|
@@ -25244,14 +25427,19 @@ function readAssessmentItemHottext(inputXml) {
|
|
|
25244
25427
|
/**
|
|
25245
25428
|
* Convert hottextInteraction to Learnosity tokenhighlight
|
|
25246
25429
|
*/
|
|
25247
|
-
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
25430
|
+
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
25248
25431
|
const parsed = readAssessmentItemHottext(inputXml);
|
|
25249
25432
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
25250
25433
|
diagnostics.push(...updatedDiagnostics);
|
|
25251
25434
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
25252
25435
|
if (!parsed.identifier || !parsed.responseIdentifier || !parsed.templateHtml) return { diagnostics };
|
|
25253
25436
|
if (parsed.hottextElements.length === 0) return { diagnostics };
|
|
25254
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25437
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25438
|
+
const transformContext = {
|
|
25439
|
+
finalItemReference: itemRef,
|
|
25440
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25441
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25442
|
+
};
|
|
25255
25443
|
const questionRef = md5hex(itemRef);
|
|
25256
25444
|
if (parsed.shuffle) diagnostics.push({
|
|
25257
25445
|
code: DiagnosticCode.QTI_SHUFFLE_NOT_SUPPORTED,
|
|
@@ -25263,7 +25451,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25263
25451
|
if (stimulus) stimulus = transformAssetUrls(stimulus, {
|
|
25264
25452
|
organisationId,
|
|
25265
25453
|
mediaVault,
|
|
25266
|
-
customAssetUrl
|
|
25454
|
+
customAssetUrl,
|
|
25455
|
+
...transformContext
|
|
25267
25456
|
});
|
|
25268
25457
|
let template = parsed.templateHtml || "";
|
|
25269
25458
|
const identifierToIndex = /* @__PURE__ */ new Map();
|
|
@@ -25276,7 +25465,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25276
25465
|
template = transformAssetUrls(template, {
|
|
25277
25466
|
organisationId,
|
|
25278
25467
|
mediaVault,
|
|
25279
|
-
customAssetUrl
|
|
25468
|
+
customAssetUrl,
|
|
25469
|
+
...transformContext
|
|
25280
25470
|
});
|
|
25281
25471
|
let validation = void 0;
|
|
25282
25472
|
if (parsed.correctResponses && parsed.correctResponses.length > 0) {
|
|
@@ -25743,7 +25933,7 @@ function readAssessmentItemMcq(inputXml, stimulusOverride) {
|
|
|
25743
25933
|
* Supports both single and composite (multiple) choiceInteractions
|
|
25744
25934
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
25745
25935
|
*/
|
|
25746
|
-
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
25936
|
+
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
25747
25937
|
const parsed = readAssessmentItemMcq(inputXml, stimulusOverride);
|
|
25748
25938
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
25749
25939
|
...d,
|
|
@@ -25752,7 +25942,12 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25752
25942
|
diagnostics.push(...contextualDiagnostics);
|
|
25753
25943
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
25754
25944
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
25755
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25945
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25946
|
+
const transformContext = {
|
|
25947
|
+
finalItemReference: itemRef,
|
|
25948
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25949
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25950
|
+
};
|
|
25756
25951
|
const isComposite = parsed.interactions.length > 1;
|
|
25757
25952
|
const questions = [];
|
|
25758
25953
|
const widgets = [];
|
|
@@ -25762,7 +25957,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25762
25957
|
const stimulus = interaction.stimulusText ? transformAssetUrls(interaction.stimulusText, {
|
|
25763
25958
|
organisationId,
|
|
25764
25959
|
mediaVault,
|
|
25765
|
-
customAssetUrl
|
|
25960
|
+
customAssetUrl,
|
|
25961
|
+
...transformContext
|
|
25766
25962
|
}) : void 0;
|
|
25767
25963
|
const choiceMapping = /* @__PURE__ */ new Map();
|
|
25768
25964
|
const options = interaction.choices.map((choice) => {
|
|
@@ -25771,7 +25967,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25771
25967
|
label: transformAssetUrls(choice.text, {
|
|
25772
25968
|
organisationId,
|
|
25773
25969
|
mediaVault,
|
|
25774
|
-
customAssetUrl
|
|
25970
|
+
customAssetUrl,
|
|
25971
|
+
...transformContext
|
|
25775
25972
|
}),
|
|
25776
25973
|
value: choice.identifier
|
|
25777
25974
|
};
|
|
@@ -25808,7 +26005,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25808
26005
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
25809
26006
|
organisationId,
|
|
25810
26007
|
mediaVault,
|
|
25811
|
-
customAssetUrl
|
|
26008
|
+
customAssetUrl,
|
|
26009
|
+
...transformContext
|
|
25812
26010
|
}) : void 0;
|
|
25813
26011
|
questions.push({
|
|
25814
26012
|
reference: questionRef,
|
|
@@ -26176,7 +26374,7 @@ function stripWrapperDiv(html) {
|
|
|
26176
26374
|
* Convert textEntry (textEntryInteraction) to Learnosity clozetext or shorttext
|
|
26177
26375
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26178
26376
|
*/
|
|
26179
|
-
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26377
|
+
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26180
26378
|
const parsed = readAssessmentItemTextEntry(inputXml, stimulusOverride);
|
|
26181
26379
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
26182
26380
|
...d,
|
|
@@ -26186,24 +26384,31 @@ function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile
|
|
|
26186
26384
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
26187
26385
|
if (!parsed.identifier || parsed.textEntries.length === 0) return { diagnostics };
|
|
26188
26386
|
if (typeof parsed.templateText === "string") parsed.templateText = stripWrapperDiv(parsed.templateText);
|
|
26189
|
-
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26190
|
-
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26387
|
+
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26388
|
+
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26191
26389
|
}
|
|
26192
26390
|
/**
|
|
26193
26391
|
* Convert single textEntry to Learnosity shorttext
|
|
26194
26392
|
*/
|
|
26195
|
-
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26196
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26393
|
+
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26394
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26395
|
+
const transformContext = {
|
|
26396
|
+
finalItemReference: itemRef,
|
|
26397
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26398
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26399
|
+
};
|
|
26197
26400
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26198
26401
|
const stimulus = normalizeFinalText(transformAssetUrls((parsed.templateText || "").replace(/{{response}}(?:\s*<\/[^>]+>)*\s*$/, "").trim(), {
|
|
26199
26402
|
organisationId,
|
|
26200
26403
|
mediaVault,
|
|
26201
|
-
customAssetUrl
|
|
26404
|
+
customAssetUrl,
|
|
26405
|
+
...transformContext
|
|
26202
26406
|
}));
|
|
26203
26407
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26204
26408
|
organisationId,
|
|
26205
26409
|
mediaVault,
|
|
26206
|
-
customAssetUrl
|
|
26410
|
+
customAssetUrl,
|
|
26411
|
+
...transformContext
|
|
26207
26412
|
}) : void 0;
|
|
26208
26413
|
const entry = parsed.textEntries[0];
|
|
26209
26414
|
const correctResponses = entry.correctResponses || (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -26277,25 +26482,33 @@ function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisation
|
|
|
26277
26482
|
/**
|
|
26278
26483
|
* Convert textEntry with template to Learnosity clozetext
|
|
26279
26484
|
*/
|
|
26280
|
-
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26485
|
+
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26281
26486
|
const correctResponses = [];
|
|
26282
26487
|
for (const entry of parsed.textEntries) if (entry.correctResponse) correctResponses.push(entry.correctResponse);
|
|
26283
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26488
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26489
|
+
const transformContext = {
|
|
26490
|
+
finalItemReference: itemRef,
|
|
26491
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26492
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26493
|
+
};
|
|
26284
26494
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26285
26495
|
const stimulus = parsed.stimulusText ? normalizeFinalText(transformAssetUrls(parsed.stimulusText, {
|
|
26286
26496
|
organisationId,
|
|
26287
26497
|
mediaVault,
|
|
26288
|
-
customAssetUrl
|
|
26498
|
+
customAssetUrl,
|
|
26499
|
+
...transformContext
|
|
26289
26500
|
})) : void 0;
|
|
26290
26501
|
const template = normalizeFinalText(transformAssetUrls(parsed.templateText, {
|
|
26291
26502
|
organisationId,
|
|
26292
26503
|
mediaVault,
|
|
26293
|
-
customAssetUrl
|
|
26504
|
+
customAssetUrl,
|
|
26505
|
+
...transformContext
|
|
26294
26506
|
}));
|
|
26295
26507
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26296
26508
|
organisationId,
|
|
26297
26509
|
mediaVault,
|
|
26298
|
-
customAssetUrl
|
|
26510
|
+
customAssetUrl,
|
|
26511
|
+
...transformContext
|
|
26299
26512
|
}) : void 0;
|
|
26300
26513
|
const validation = {
|
|
26301
26514
|
scoring_type: "exactMatch",
|
|
@@ -26528,8 +26741,13 @@ function readAssessmentItemExtendedText(inputXml) {
|
|
|
26528
26741
|
/**
|
|
26529
26742
|
* Build multi-interaction extended text item (multiple longtextV2 questions)
|
|
26530
26743
|
*/
|
|
26531
|
-
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26532
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26744
|
+
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26745
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26746
|
+
const transformContext = {
|
|
26747
|
+
finalItemReference: itemRef,
|
|
26748
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26749
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26750
|
+
};
|
|
26533
26751
|
const questions = [];
|
|
26534
26752
|
const widgets = [];
|
|
26535
26753
|
const questionSpans = [];
|
|
@@ -26539,7 +26757,8 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
|
|
|
26539
26757
|
const stimulus = transformAssetUrls(stimulusOverride[i], {
|
|
26540
26758
|
organisationId,
|
|
26541
26759
|
mediaVault,
|
|
26542
|
-
customAssetUrl
|
|
26760
|
+
customAssetUrl,
|
|
26761
|
+
...transformContext
|
|
26543
26762
|
});
|
|
26544
26763
|
widgets.push({
|
|
26545
26764
|
reference: questionRef,
|
|
@@ -26589,19 +26808,25 @@ function extractResponseIdentifiers(inputXml, interactionTag) {
|
|
|
26589
26808
|
* Convert extended text (extendedTextInteraction) to Learnosity longtextV2
|
|
26590
26809
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26591
26810
|
*/
|
|
26592
|
-
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26811
|
+
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26593
26812
|
const parsed = readAssessmentItemExtendedText(inputXml);
|
|
26594
26813
|
const contextualDiagnostics = addFileContextIfProvided(stimulusOverride ? filterOutCodes(parsed.diagnostics, [DiagnosticCode.QTI_EXTENDED_TEXT_MULTIPLE_INTERACTIONS]) : parsed.diagnostics, sourceFile);
|
|
26595
26814
|
diagnostics.push(...contextualDiagnostics);
|
|
26596
26815
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
26597
|
-
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26598
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26816
|
+
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26817
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26818
|
+
const transformContext = {
|
|
26819
|
+
finalItemReference: itemRef,
|
|
26820
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26821
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26822
|
+
};
|
|
26599
26823
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier ?? "unknown");
|
|
26600
26824
|
const stimulusRaw = stimulusOverride && stimulusOverride.length === 1 ? stimulusOverride[0] : parsed.stimulusText;
|
|
26601
26825
|
const stimulus = stimulusRaw ? transformAssetUrls(stimulusRaw, {
|
|
26602
26826
|
organisationId,
|
|
26603
26827
|
mediaVault,
|
|
26604
|
-
customAssetUrl
|
|
26828
|
+
customAssetUrl,
|
|
26829
|
+
...transformContext
|
|
26605
26830
|
}) : void 0;
|
|
26606
26831
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26607
26832
|
organisationId,
|
|
@@ -26896,7 +27121,7 @@ function buildValidationValue$1(hotspots, correctPairs, gapImgIdToResponse) {
|
|
|
26896
27121
|
/**
|
|
26897
27122
|
* Convert QTI graphicGapMatchInteraction to Learnosity imageclozeassociationV2
|
|
26898
27123
|
*/
|
|
26899
|
-
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27124
|
+
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
26900
27125
|
const parsed = readAssessmentItemGraphicGapMatch(inputXml);
|
|
26901
27126
|
const contextualDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
26902
27127
|
diagnostics.push(...contextualDiagnostics);
|
|
@@ -26912,6 +27137,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26912
27137
|
}
|
|
26913
27138
|
const bgWidth = parsed.backgroundImage.width;
|
|
26914
27139
|
const bgHeight = parsed.backgroundImage.height;
|
|
27140
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27141
|
+
const transformContext = {
|
|
27142
|
+
finalItemReference: itemRef,
|
|
27143
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27144
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27145
|
+
};
|
|
26915
27146
|
const gapImgIdToResponse = /* @__PURE__ */ new Map();
|
|
26916
27147
|
const possible_responses = parsed.gapImages.map((g) => {
|
|
26917
27148
|
if (g.text !== void 0) {
|
|
@@ -26930,7 +27161,8 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26930
27161
|
const transformedImgTag = transformAssetUrls(imgTag, {
|
|
26931
27162
|
organisationId,
|
|
26932
27163
|
mediaVault,
|
|
26933
|
-
customAssetUrl
|
|
27164
|
+
customAssetUrl,
|
|
27165
|
+
...transformContext
|
|
26934
27166
|
});
|
|
26935
27167
|
gapImgIdToResponse.set(g.identifier, transformedImgTag);
|
|
26936
27168
|
return transformedImgTag;
|
|
@@ -26968,7 +27200,7 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26968
27200
|
const question = {
|
|
26969
27201
|
type: "imageclozeassociationV2",
|
|
26970
27202
|
image: {
|
|
26971
|
-
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl) : parsed.backgroundImage.src,
|
|
27203
|
+
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.backgroundImage.src,
|
|
26972
27204
|
width: bgWidth,
|
|
26973
27205
|
height: bgHeight
|
|
26974
27206
|
},
|
|
@@ -26992,11 +27224,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26992
27224
|
if (parsed.stimulus) question.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
26993
27225
|
organisationId,
|
|
26994
27226
|
mediaVault,
|
|
26995
|
-
customAssetUrl
|
|
27227
|
+
customAssetUrl,
|
|
27228
|
+
...transformContext
|
|
26996
27229
|
});
|
|
26997
27230
|
const item = {
|
|
26998
27231
|
item: {
|
|
26999
|
-
reference:
|
|
27232
|
+
reference: itemRef,
|
|
27000
27233
|
title: parsed.title ?? void 0,
|
|
27001
27234
|
definition: { widgets: [{
|
|
27002
27235
|
reference: questionRef,
|
|
@@ -27286,35 +27519,38 @@ const readAssessmentItemDrawing = createAssessmentItemReader({
|
|
|
27286
27519
|
/**
|
|
27287
27520
|
* Build drawing stimulus from parsed QTI data
|
|
27288
27521
|
*/
|
|
27289
|
-
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27522
|
+
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27290
27523
|
if (!parsed.stimulusText && !parsed.promptText) return;
|
|
27291
27524
|
const stimulus = parsed.promptText || parsed.stimulusText || "";
|
|
27292
27525
|
try {
|
|
27293
27526
|
return transformAssetUrls(stimulus, {
|
|
27294
27527
|
organisationId,
|
|
27295
27528
|
mediaVault,
|
|
27296
|
-
customAssetUrl
|
|
27529
|
+
customAssetUrl,
|
|
27530
|
+
...assetTransformContext
|
|
27297
27531
|
});
|
|
27298
|
-
} catch {
|
|
27532
|
+
} catch (error) {
|
|
27533
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27299
27534
|
return stimulus;
|
|
27300
27535
|
}
|
|
27301
27536
|
}
|
|
27302
27537
|
/**
|
|
27303
27538
|
* Transform a single image source URL
|
|
27304
27539
|
*/
|
|
27305
|
-
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl) {
|
|
27540
|
+
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27306
27541
|
try {
|
|
27307
|
-
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl) : imageSource;
|
|
27308
|
-
} catch {
|
|
27542
|
+
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) : imageSource;
|
|
27543
|
+
} catch (error) {
|
|
27544
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27309
27545
|
return imageSource;
|
|
27310
27546
|
}
|
|
27311
27547
|
}
|
|
27312
27548
|
/**
|
|
27313
27549
|
* Build drawing image data from parsed QTI data
|
|
27314
27550
|
*/
|
|
27315
|
-
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27551
|
+
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27316
27552
|
if (!parsed.imageSource) return;
|
|
27317
|
-
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl) };
|
|
27553
|
+
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) };
|
|
27318
27554
|
if (parsed.imageWidth) image.width = parsed.imageWidth;
|
|
27319
27555
|
if (parsed.imageHeight) image.height = parsed.imageHeight;
|
|
27320
27556
|
if (parsed.imageAlt) image.alt = parsed.imageAlt;
|
|
@@ -27323,21 +27559,27 @@ function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
|
27323
27559
|
/**
|
|
27324
27560
|
* Convert QTI drawingInteraction to Learnosity drawing question
|
|
27325
27561
|
*/
|
|
27326
|
-
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27562
|
+
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27327
27563
|
const parsed = readAssessmentItemDrawing(inputXml);
|
|
27328
27564
|
diagnostics.push(...parsed.diagnostics);
|
|
27329
27565
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
27330
|
-
const
|
|
27566
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27567
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
27568
|
+
const transformContext = {
|
|
27569
|
+
finalItemReference: itemRef,
|
|
27570
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27571
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27572
|
+
};
|
|
27331
27573
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "drawing"));
|
|
27332
27574
|
const questionData = { type: "drawing" };
|
|
27333
|
-
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27575
|
+
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27334
27576
|
if (stimulus !== void 0) questionData.stimulus = stimulus;
|
|
27335
|
-
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27577
|
+
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27336
27578
|
if (image) questionData.image = image;
|
|
27337
27579
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
27338
27580
|
const item = {
|
|
27339
27581
|
item: {
|
|
27340
|
-
reference:
|
|
27582
|
+
reference: itemRef,
|
|
27341
27583
|
title: parsed.title ?? void 0,
|
|
27342
27584
|
content,
|
|
27343
27585
|
definition: { widgets: [{
|
|
@@ -27627,7 +27869,7 @@ function buildValidationValue(choices, correctPairs, diagnostics, sourceFile) {
|
|
|
27627
27869
|
* This reflects the undirected-pair nature of associateInteraction: no choice is
|
|
27628
27870
|
* inherently a "category" or a "draggable" — both sides of a pair are equivalent.
|
|
27629
27871
|
*/
|
|
27630
|
-
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27872
|
+
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27631
27873
|
const parsed = readAssessmentItemAssociation(inputXml);
|
|
27632
27874
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
27633
27875
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -27635,17 +27877,24 @@ function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisa
|
|
|
27635
27877
|
if (!parsed.identifier || parsed.choices.length === 0) return { diagnostics };
|
|
27636
27878
|
const validationValue = buildValidationValue(parsed.choices, parsed.correctPairs, diagnostics, sourceFile);
|
|
27637
27879
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
27638
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27880
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27881
|
+
const transformContext = {
|
|
27882
|
+
finalItemReference: itemRef,
|
|
27883
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27884
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27885
|
+
};
|
|
27639
27886
|
const questionRef = md5hex(itemRef);
|
|
27640
27887
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
27641
27888
|
organisationId,
|
|
27642
27889
|
mediaVault,
|
|
27643
|
-
customAssetUrl
|
|
27890
|
+
customAssetUrl,
|
|
27891
|
+
...transformContext
|
|
27644
27892
|
});
|
|
27645
27893
|
const possibleResponses = parsed.choices.map((c) => transformAssetUrls(c.text, {
|
|
27646
27894
|
organisationId,
|
|
27647
27895
|
mediaVault,
|
|
27648
|
-
customAssetUrl
|
|
27896
|
+
customAssetUrl,
|
|
27897
|
+
...transformContext
|
|
27649
27898
|
}));
|
|
27650
27899
|
const pairCount = validationValue.length > 0 ? validationValue.length : Math.round(parsed.maxAssociations ?? parsed.choices.length / 2);
|
|
27651
27900
|
const columnHeaders = Array.from({ length: pairCount }, (_, i) => `Pair ${i + 1}`);
|
|
@@ -28061,8 +28310,8 @@ function computeClosingTags(html) {
|
|
|
28061
28310
|
* Converters with different parameter orders are wrapped to normalize the signature.
|
|
28062
28311
|
*/
|
|
28063
28312
|
function getConverterMap() {
|
|
28064
|
-
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli);
|
|
28065
|
-
const hotspotConverter = (xml, diag, tags, orgId, sf, mv, cau, irs, _stimuli, fileAccess, packageRoot) => convertHotspotToLearnosity(xml, diag, tags, orgId, sf, mv, cau, irs, fileAccess, packageRoot);
|
|
28313
|
+
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli, assetTransformContext) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli, assetTransformContext);
|
|
28314
|
+
const hotspotConverter = (xml, diag, tags, orgId, sf, mv, cau, irs, _stimuli, assetTransformContext, fileAccess, packageRoot) => convertHotspotToLearnosity(xml, diag, tags, orgId, sf, mv, cau, irs, fileAccess, packageRoot, assetTransformContext);
|
|
28066
28315
|
return {
|
|
28067
28316
|
choiceInteraction: wrapSourceFirst(convertMcqToLearnosity),
|
|
28068
28317
|
textEntryInteraction: wrapSourceFirst(convertTextEntryToLearnosity),
|
|
@@ -28085,8 +28334,14 @@ const CONVERTER_MAP = getConverterMap();
|
|
|
28085
28334
|
* Strategy: Call each individual converter for its interaction type,
|
|
28086
28335
|
* then combine all questions and widgets into a single composite item
|
|
28087
28336
|
*/
|
|
28088
|
-
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
28337
|
+
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
28089
28338
|
const metadata = extractItemMetadata(inputXml);
|
|
28339
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(metadata.identifier ?? "mixed_item", itemReferenceSource, sourceFile);
|
|
28340
|
+
const transformContext = {
|
|
28341
|
+
finalItemReference: itemRef,
|
|
28342
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28343
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28344
|
+
};
|
|
28090
28345
|
const { segments } = segmentItemBodyByInteractions(inputXml);
|
|
28091
28346
|
const stimuliByType = /* @__PURE__ */ new Map();
|
|
28092
28347
|
for (const segment of segments) {
|
|
@@ -28168,7 +28423,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28168
28423
|
const template = normalizeFinalText(transformAssetUrls(rawTemplate, {
|
|
28169
28424
|
organisationId,
|
|
28170
28425
|
mediaVault,
|
|
28171
|
-
customAssetUrl
|
|
28426
|
+
customAssetUrl,
|
|
28427
|
+
...transformContext
|
|
28172
28428
|
}));
|
|
28173
28429
|
if (groupEntries.length === 1 && /{{response}}(?:<\/[^>]+>|\s)*$/.test(rawTemplate.trim())) {
|
|
28174
28430
|
let stimulusRaw = rawTemplate.replace(/{{response}}(?:<\/[^>]+>|\s)*$/, "").trim();
|
|
@@ -28176,7 +28432,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28176
28432
|
const stimulus = normalizeFinalText(transformAssetUrls(stimulusRaw, {
|
|
28177
28433
|
organisationId,
|
|
28178
28434
|
mediaVault,
|
|
28179
|
-
customAssetUrl
|
|
28435
|
+
customAssetUrl,
|
|
28436
|
+
...transformContext
|
|
28180
28437
|
}));
|
|
28181
28438
|
const entry = groupEntries[0];
|
|
28182
28439
|
const allCorrectResponses = entry.correctResponses ?? (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -28302,7 +28559,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28302
28559
|
continue;
|
|
28303
28560
|
}
|
|
28304
28561
|
const converter = CONVERTER_MAP[group.type];
|
|
28305
|
-
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, fileAccess, packageRoot), subDiagnostics);
|
|
28562
|
+
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, transformContext, fileAccess, packageRoot), subDiagnostics);
|
|
28306
28563
|
}
|
|
28307
28564
|
if (allQuestions.length === 0) {
|
|
28308
28565
|
diagnostics.push({
|
|
@@ -28325,9 +28582,16 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28325
28582
|
passageContent = transformAssetUrls(rawContent, {
|
|
28326
28583
|
organisationId,
|
|
28327
28584
|
mediaVault,
|
|
28328
|
-
customAssetUrl
|
|
28585
|
+
customAssetUrl,
|
|
28586
|
+
...transformContext
|
|
28587
|
+
});
|
|
28588
|
+
} catch (error) {
|
|
28589
|
+
if (isUnsafeQtiAssetHrefError(error)) diagnostics.push({
|
|
28590
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
28591
|
+
level: "error",
|
|
28592
|
+
file: sourceFile ?? "passage",
|
|
28593
|
+
message: error.message
|
|
28329
28594
|
});
|
|
28330
|
-
} catch {
|
|
28331
28595
|
passageContent = rawContent;
|
|
28332
28596
|
}
|
|
28333
28597
|
allFeatures.push({
|
|
@@ -28359,7 +28623,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28359
28623
|
const content = `<div class="row"><div class="col-xs-12">${[...featureSpans, ...questionSpans].join("")}</div></div>`;
|
|
28360
28624
|
const item = {
|
|
28361
28625
|
item: {
|
|
28362
|
-
reference:
|
|
28626
|
+
reference: itemRef,
|
|
28363
28627
|
title: metadata.title ?? void 0,
|
|
28364
28628
|
content,
|
|
28365
28629
|
definition: { widgets: allWidgets },
|
|
@@ -28405,8 +28669,13 @@ function resolvePassageObjects(html, sourceFile, resolvePassageFile) {
|
|
|
28405
28669
|
/**
|
|
28406
28670
|
* Convert passage-only item to Learnosity format with sharedpassage feature
|
|
28407
28671
|
*/
|
|
28408
|
-
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess) {
|
|
28409
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28672
|
+
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, assetTransformContext) {
|
|
28673
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28674
|
+
const transformContext = {
|
|
28675
|
+
finalItemReference: itemRef,
|
|
28676
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28677
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28678
|
+
};
|
|
28410
28679
|
const featureRef = `passage-${md5hex(getPassageDataPath(parsed.content) ?? itemRef).substring(0, 8)}`;
|
|
28411
28680
|
const resolvedContent = resolvePassageObjects(parsed.content, sourceFile, fileAccess?.resolvePassageFile.bind(fileAccess));
|
|
28412
28681
|
let content;
|
|
@@ -28414,11 +28683,12 @@ function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId
|
|
|
28414
28683
|
content = transformAssetUrls(resolvedContent, {
|
|
28415
28684
|
organisationId,
|
|
28416
28685
|
mediaVault,
|
|
28417
|
-
customAssetUrl
|
|
28686
|
+
customAssetUrl,
|
|
28687
|
+
...transformContext
|
|
28418
28688
|
});
|
|
28419
28689
|
} catch (error) {
|
|
28420
28690
|
diagnostics.push({
|
|
28421
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28691
|
+
code: isUnsafeQtiAssetHrefError(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28422
28692
|
level: "error",
|
|
28423
28693
|
file: sourceFile ?? "assessmentItem",
|
|
28424
28694
|
message: error instanceof Error ? error.message : "Failed to transform asset URLs"
|
|
@@ -28808,20 +29078,28 @@ function readAssessmentItemUpload(inputXml) {
|
|
|
28808
29078
|
* and the file limit from `maxChoices` (see readAssessmentItemUpload / the
|
|
28809
29079
|
* serializer). fileupload questions are unscored, so there is no validation.
|
|
28810
29080
|
*/
|
|
28811
|
-
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
29081
|
+
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
28812
29082
|
const parsed = readAssessmentItemUpload(inputXml);
|
|
28813
29083
|
diagnostics.push(...parsed.diagnostics);
|
|
28814
29084
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
28815
|
-
const
|
|
29085
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
29086
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
29087
|
+
const transformContext = {
|
|
29088
|
+
finalItemReference: itemRef,
|
|
29089
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
29090
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
29091
|
+
};
|
|
28816
29092
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "fileupload"));
|
|
28817
29093
|
const questionData = { type: "fileupload" };
|
|
28818
29094
|
if (parsed.stimulus) try {
|
|
28819
29095
|
questionData.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
28820
29096
|
organisationId,
|
|
28821
29097
|
mediaVault,
|
|
28822
|
-
customAssetUrl
|
|
29098
|
+
customAssetUrl,
|
|
29099
|
+
...transformContext
|
|
28823
29100
|
});
|
|
28824
|
-
} catch {
|
|
29101
|
+
} catch (error) {
|
|
29102
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
28825
29103
|
questionData.stimulus = parsed.stimulus;
|
|
28826
29104
|
}
|
|
28827
29105
|
for (const suffix of parsed.allowedFileTypes) questionData[`allow_${suffix}`] = true;
|
|
@@ -28829,7 +29107,7 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28829
29107
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
28830
29108
|
const item = {
|
|
28831
29109
|
item: {
|
|
28832
|
-
reference:
|
|
29110
|
+
reference: itemRef,
|
|
28833
29111
|
title: parsed.title ?? void 0,
|
|
28834
29112
|
content,
|
|
28835
29113
|
definition: { widgets: [{
|
|
@@ -28864,9 +29142,19 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28864
29142
|
* - Rejects DOCTYPE / ENTITY declarations up-front (DTD not allowed).
|
|
28865
29143
|
* - Uses streaming parsers for all interaction types.
|
|
28866
29144
|
*/
|
|
29145
|
+
function getAssetSourceHrefBase(opts) {
|
|
29146
|
+
if (opts.sourceHrefBase) return opts.sourceHrefBase;
|
|
29147
|
+
const source = opts.sourceFile ?? opts.inputPath;
|
|
29148
|
+
if (!source) return;
|
|
29149
|
+
const normalized = source.replaceAll("\\", "/");
|
|
29150
|
+
return normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(normalized) ? normalized.slice(normalized.lastIndexOf("/") + 1) : normalized;
|
|
29151
|
+
}
|
|
28867
29152
|
/**
|
|
28868
29153
|
* Supported interaction type names for counting
|
|
28869
29154
|
*/
|
|
29155
|
+
function isUnsafeAssetHrefError$1(error) {
|
|
29156
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
29157
|
+
}
|
|
28870
29158
|
const INTERACTION_NAMES = [
|
|
28871
29159
|
"choiceInteraction",
|
|
28872
29160
|
"textEntryInteraction",
|
|
@@ -28932,19 +29220,71 @@ function countAllInteractions(xml) {
|
|
|
28932
29220
|
};
|
|
28933
29221
|
}
|
|
28934
29222
|
const SINGLE_INTERACTION_CONVERTERS = /* @__PURE__ */ new Map([
|
|
28935
|
-
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim
|
|
28936
|
-
|
|
28937
|
-
|
|
28938
|
-
|
|
28939
|
-
|
|
28940
|
-
["
|
|
28941
|
-
|
|
28942
|
-
|
|
28943
|
-
|
|
28944
|
-
|
|
28945
|
-
["
|
|
28946
|
-
|
|
28947
|
-
|
|
29223
|
+
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29224
|
+
finalItemReference: opts.finalItemReference,
|
|
29225
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29226
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29227
|
+
})],
|
|
29228
|
+
["textEntryInteraction", (xml, diag, lom, opts, stim) => convertTextEntryToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29229
|
+
finalItemReference: opts.finalItemReference,
|
|
29230
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29231
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29232
|
+
})],
|
|
29233
|
+
["extendedTextInteraction", (xml, diag, lom, opts, stim) => convertExtendedTextToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29234
|
+
finalItemReference: opts.finalItemReference,
|
|
29235
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29236
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29237
|
+
})],
|
|
29238
|
+
["inlineChoiceInteraction", (xml, diag, lom, opts) => convertInlineChoiceToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29239
|
+
finalItemReference: opts.finalItemReference,
|
|
29240
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29241
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29242
|
+
})],
|
|
29243
|
+
["matchInteraction", (xml, diag, lom, opts) => convertMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29244
|
+
finalItemReference: opts.finalItemReference,
|
|
29245
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29246
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29247
|
+
})],
|
|
29248
|
+
["gapMatchInteraction", (xml, diag, lom, opts) => convertGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29249
|
+
finalItemReference: opts.finalItemReference,
|
|
29250
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29251
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29252
|
+
})],
|
|
29253
|
+
["orderInteraction", (xml, diag, lom, opts) => convertOrderToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29254
|
+
finalItemReference: opts.finalItemReference,
|
|
29255
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29256
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29257
|
+
})],
|
|
29258
|
+
["hotspotInteraction", (xml, diag, lom, opts) => convertHotspotToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29259
|
+
finalItemReference: opts.finalItemReference,
|
|
29260
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29261
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29262
|
+
})],
|
|
29263
|
+
["hottextInteraction", (xml, diag, lom, opts) => convertHottextToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29264
|
+
finalItemReference: opts.finalItemReference,
|
|
29265
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29266
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29267
|
+
})],
|
|
29268
|
+
["graphicGapMatchInteraction", (xml, diag, lom, opts) => convertGraphicGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29269
|
+
finalItemReference: opts.finalItemReference,
|
|
29270
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29271
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29272
|
+
})],
|
|
29273
|
+
["drawingInteraction", (xml, diag, lom, opts) => convertDrawingToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29274
|
+
finalItemReference: opts.finalItemReference,
|
|
29275
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29276
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29277
|
+
})],
|
|
29278
|
+
["associateInteraction", (xml, diag, lom, opts) => convertAssociationToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29279
|
+
finalItemReference: opts.finalItemReference,
|
|
29280
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29281
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29282
|
+
})],
|
|
29283
|
+
["uploadInteraction", (xml, diag, lom, opts) => convertUploadToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29284
|
+
finalItemReference: opts.finalItemReference,
|
|
29285
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29286
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29287
|
+
})]
|
|
28948
29288
|
]);
|
|
28949
29289
|
/**
|
|
28950
29290
|
* Dispatch to the appropriate single-interaction converter
|
|
@@ -28970,9 +29310,18 @@ function dispatchSingleInteractionConverter(interactionType, inputXml, count, di
|
|
|
28970
29310
|
passageContent = transformAssetUrls(rawContent, {
|
|
28971
29311
|
organisationId: opts.organisationId,
|
|
28972
29312
|
mediaVault: opts.mediaVault,
|
|
28973
|
-
customAssetUrl: opts.customAssetUrl
|
|
29313
|
+
customAssetUrl: opts.customAssetUrl,
|
|
29314
|
+
finalItemReference: opts.finalItemReference ?? result.item.item.reference,
|
|
29315
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29316
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29317
|
+
});
|
|
29318
|
+
} catch (error) {
|
|
29319
|
+
if (isUnsafeAssetHrefError$1(error)) diagnostics.push({
|
|
29320
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
29321
|
+
level: "error",
|
|
29322
|
+
file: opts.sourceFile ?? "passage",
|
|
29323
|
+
message: error.message
|
|
28974
29324
|
});
|
|
28975
|
-
} catch {
|
|
28976
29325
|
passageContent = rawContent;
|
|
28977
29326
|
}
|
|
28978
29327
|
result.item.features = [...result.item.features, {
|
|
@@ -29020,8 +29369,16 @@ function handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, o
|
|
|
29020
29369
|
}
|
|
29021
29370
|
const passageResult = readAssessmentItemPassage(inputXml);
|
|
29022
29371
|
diagnostics.push(...addFileContextIfProvided(passageResult.diagnostics, opts.sourceFile));
|
|
29023
|
-
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess
|
|
29024
|
-
|
|
29372
|
+
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, {
|
|
29373
|
+
finalItemReference: opts.finalItemReference,
|
|
29374
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29375
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29376
|
+
});
|
|
29377
|
+
const mcqResult = convertMcqToLearnosity(inputXml, diagnostics, lomTags, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29378
|
+
finalItemReference: opts.finalItemReference,
|
|
29379
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29380
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29381
|
+
});
|
|
29025
29382
|
if (diagnostics.some((d) => d.code === DiagnosticCode.LRN_SCHEMA_INVALID)) return mcqResult;
|
|
29026
29383
|
return { diagnostics };
|
|
29027
29384
|
}
|
|
@@ -29067,14 +29424,18 @@ function convertQtiAssessmentItemToLearnosity(inputXml, opts = {}) {
|
|
|
29067
29424
|
const { counts, allInteractions } = countAllInteractions(inputXml);
|
|
29068
29425
|
const presentTypes = INTERACTION_NAMES.filter((name) => counts[name] > 0);
|
|
29069
29426
|
if (presentTypes.reduce((sum, name) => sum + counts[name], 0) === 0) return handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, opts);
|
|
29070
|
-
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot
|
|
29427
|
+
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29428
|
+
finalItemReference: opts.finalItemReference,
|
|
29429
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29430
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29431
|
+
});
|
|
29071
29432
|
return dispatchSingleInteractionConverter(presentTypes[0], inputXml, counts[presentTypes[0]], diagnostics, lomTags, opts);
|
|
29072
29433
|
} catch (error) {
|
|
29073
29434
|
diagnostics.push({
|
|
29074
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29435
|
+
code: isUnsafeAssetHrefError$1(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29075
29436
|
level: "error",
|
|
29076
|
-
file: "root",
|
|
29077
|
-
message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29437
|
+
file: opts.sourceFile ?? "root",
|
|
29438
|
+
message: isUnsafeAssetHrefError$1(error) ? error.message : `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29078
29439
|
});
|
|
29079
29440
|
return { diagnostics };
|
|
29080
29441
|
}
|
|
@@ -29187,9 +29548,11 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29187
29548
|
const result = convertQtiAssessmentItemToLearnosity(input, {
|
|
29188
29549
|
qtiVersion: opts.qtiVersion,
|
|
29189
29550
|
inputPath: opts.inputPath,
|
|
29551
|
+
sourceFile: opts.inputPath,
|
|
29190
29552
|
organisationId: opts.organisationId,
|
|
29191
29553
|
mediaVault: opts.mediaVault,
|
|
29192
29554
|
customAssetUrl: opts.customAssetUrl,
|
|
29555
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29193
29556
|
itemReferenceSource: opts.itemReferenceSource,
|
|
29194
29557
|
fileAccess: opts.fileAccess
|
|
29195
29558
|
});
|
|
@@ -31408,6 +31771,108 @@ function textToBytes(text) {
|
|
|
31408
31771
|
return strToU8(text);
|
|
31409
31772
|
}
|
|
31410
31773
|
//#endregion
|
|
31774
|
+
//#region src/qti-to-learnosity/utils/assetFilenameRegistry.ts
|
|
31775
|
+
/**
|
|
31776
|
+
* Browser-safe registry for item-scoped QTI asset filenames.
|
|
31777
|
+
*
|
|
31778
|
+
* Filename selection belongs to asset identity, not package traversal. Keeping
|
|
31779
|
+
* both identity and filename indexes here lets URL and bundle seams validate
|
|
31780
|
+
* the same contract before either one can overwrite a physical asset.
|
|
31781
|
+
*/
|
|
31782
|
+
var AssetFilenameConflictError = class extends Error {
|
|
31783
|
+
kind;
|
|
31784
|
+
mode;
|
|
31785
|
+
filename;
|
|
31786
|
+
existing;
|
|
31787
|
+
incoming;
|
|
31788
|
+
constructor(kind, mode, filename, existing, incoming) {
|
|
31789
|
+
const existingIdentity = existing.serializedIdentity;
|
|
31790
|
+
const incomingIdentity = incoming.serializedIdentity;
|
|
31791
|
+
const message = kind === "identity-bytes" ? `Asset identity conflict in ${mode} mode for ${incomingIdentity}: filename "${filename}" was registered with different bytes.` : `Asset filename conflict in ${mode} mode: filename "${filename}" is assigned to both ${existingIdentity} and ${incomingIdentity}.`;
|
|
31792
|
+
super(message);
|
|
31793
|
+
this.name = "AssetFilenameConflictError";
|
|
31794
|
+
this.kind = kind;
|
|
31795
|
+
this.mode = mode;
|
|
31796
|
+
this.filename = filename;
|
|
31797
|
+
this.existing = existing;
|
|
31798
|
+
this.incoming = incoming;
|
|
31799
|
+
}
|
|
31800
|
+
};
|
|
31801
|
+
function bytesEqual(left, right) {
|
|
31802
|
+
if (left.length !== right.length) return false;
|
|
31803
|
+
for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
|
|
31804
|
+
return true;
|
|
31805
|
+
}
|
|
31806
|
+
function cloneBytes(bytes) {
|
|
31807
|
+
return new Uint8Array(bytes);
|
|
31808
|
+
}
|
|
31809
|
+
/**
|
|
31810
|
+
* Track selected asset names and their bytes for one conversion.
|
|
31811
|
+
*
|
|
31812
|
+
* Registering an equivalent identity repeatedly is idempotent when its bytes
|
|
31813
|
+
* agree. A filename can never silently change owners, and an identity can
|
|
31814
|
+
* never silently change bytes, in either hashed or preserve mode.
|
|
31815
|
+
*/
|
|
31816
|
+
var AssetFilenameRegistry = class {
|
|
31817
|
+
preserveAssetFilenames;
|
|
31818
|
+
byIdentity = /* @__PURE__ */ new Map();
|
|
31819
|
+
byFilename = /* @__PURE__ */ new Map();
|
|
31820
|
+
constructor(preserveAssetFilenames = false) {
|
|
31821
|
+
this.preserveAssetFilenames = preserveAssetFilenames;
|
|
31822
|
+
}
|
|
31823
|
+
get mode() {
|
|
31824
|
+
return this.preserveAssetFilenames ? "preserve" : "hashed";
|
|
31825
|
+
}
|
|
31826
|
+
get size() {
|
|
31827
|
+
return this.byIdentity.size;
|
|
31828
|
+
}
|
|
31829
|
+
/**
|
|
31830
|
+
* Register an asset and return its selected filename and bytes.
|
|
31831
|
+
*
|
|
31832
|
+
* The input href is canonicalized before both indexes are consulted, so
|
|
31833
|
+
* equivalent directory and ZIP representations reuse one registration.
|
|
31834
|
+
*/
|
|
31835
|
+
register(finalItemReference, qtiAssetHref, bytes) {
|
|
31836
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
31837
|
+
const serializedIdentity = serializeQtiAssetIdentity(finalItemReference, canonicalHref);
|
|
31838
|
+
const filename = selectQtiAssetFilename(finalItemReference, canonicalHref, this.preserveAssetFilenames);
|
|
31839
|
+
const incoming = {
|
|
31840
|
+
finalItemReference,
|
|
31841
|
+
qtiAssetHref: canonicalHref,
|
|
31842
|
+
serializedIdentity,
|
|
31843
|
+
filename,
|
|
31844
|
+
bytes: cloneBytes(bytes)
|
|
31845
|
+
};
|
|
31846
|
+
const existingIdentity = this.byIdentity.get(serializedIdentity);
|
|
31847
|
+
if (existingIdentity) {
|
|
31848
|
+
if (!bytesEqual(existingIdentity.bytes, incoming.bytes)) throw new AssetFilenameConflictError("identity-bytes", this.mode, filename, existingIdentity, incoming);
|
|
31849
|
+
return existingIdentity;
|
|
31850
|
+
}
|
|
31851
|
+
const existingFilename = this.byFilename.get(filename);
|
|
31852
|
+
if (existingFilename) throw new AssetFilenameConflictError("filename-identity", this.mode, filename, existingFilename, incoming);
|
|
31853
|
+
this.byIdentity.set(serializedIdentity, incoming);
|
|
31854
|
+
this.byFilename.set(filename, incoming);
|
|
31855
|
+
return incoming;
|
|
31856
|
+
}
|
|
31857
|
+
/** Look up a previously registered canonical identity without registering it. */
|
|
31858
|
+
get(finalItemReference, qtiAssetHref) {
|
|
31859
|
+
return this.byIdentity.get(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
31860
|
+
}
|
|
31861
|
+
/** Look up an asset by its selected bundle-relative filename. */
|
|
31862
|
+
getByFilename(filename) {
|
|
31863
|
+
return this.byFilename.get(filename);
|
|
31864
|
+
}
|
|
31865
|
+
/** Iterate registrations in deterministic registration order. */
|
|
31866
|
+
entries() {
|
|
31867
|
+
return this.byIdentity.values();
|
|
31868
|
+
}
|
|
31869
|
+
/** Remove all registrations so the registry can be reused for a new conversion. */
|
|
31870
|
+
clear() {
|
|
31871
|
+
this.byIdentity.clear();
|
|
31872
|
+
this.byFilename.clear();
|
|
31873
|
+
}
|
|
31874
|
+
};
|
|
31875
|
+
//#endregion
|
|
31411
31876
|
//#region src/qti-to-learnosity/convertQtiPackageToLearnosityBundle.ts
|
|
31412
31877
|
/**
|
|
31413
31878
|
* QTI Content Package → Learnosity Bundle converter (v1)
|
|
@@ -31421,6 +31886,15 @@ function textToBytes(text) {
|
|
|
31421
31886
|
* - Does not write outputs if any error diagnostics exist
|
|
31422
31887
|
* - Deterministic ordering and stable JSON serialization
|
|
31423
31888
|
*/
|
|
31889
|
+
/**
|
|
31890
|
+
* Normalize an item reference / filename source for comparison and defaulting.
|
|
31891
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`, and an omitted value
|
|
31892
|
+
* defaults to `'itemIdentifier'`.
|
|
31893
|
+
*/
|
|
31894
|
+
function normalizeRefSource(source) {
|
|
31895
|
+
if (source === "qti" || source === void 0) return "itemIdentifier";
|
|
31896
|
+
return source;
|
|
31897
|
+
}
|
|
31424
31898
|
const utf8Decoder = new TextDecoder();
|
|
31425
31899
|
/** Decode entry bytes as UTF-8 (works for both Uint8Array and Node Buffer). */
|
|
31426
31900
|
function decodeUtf8(data) {
|
|
@@ -31455,57 +31929,80 @@ function ensureFailedItemDiagnostic(itemDiagnostics, href) {
|
|
|
31455
31929
|
}];
|
|
31456
31930
|
}
|
|
31457
31931
|
/**
|
|
31458
|
-
* Normalize a forward-slash relative path (collapse `.`/`//`, resolve `..`).
|
|
31459
|
-
* Pure replacement for `node:path`'s `normalize(...).split(sep).join('/')` on
|
|
31460
|
-
* the forward-slash paths used as entry keys.
|
|
31461
|
-
*/
|
|
31462
|
-
function normalizePosix(p) {
|
|
31463
|
-
const parts = [];
|
|
31464
|
-
for (const seg of p.split("/")) {
|
|
31465
|
-
if (seg === "" || seg === ".") continue;
|
|
31466
|
-
if (seg === "..") {
|
|
31467
|
-
parts.pop();
|
|
31468
|
-
continue;
|
|
31469
|
-
}
|
|
31470
|
-
parts.push(seg);
|
|
31471
|
-
}
|
|
31472
|
-
return parts.join("/");
|
|
31473
|
-
}
|
|
31474
|
-
/**
|
|
31475
31932
|
* Normalize href path by removing leading ./ sequences
|
|
31476
31933
|
* This ensures manifest hrefs like "./items/foo.xml" match entries stored as "items/foo.xml"
|
|
31477
31934
|
*/
|
|
31478
31935
|
function normalizeHref(href) {
|
|
31479
31936
|
return href.replace(/^(\.\/)+/, "");
|
|
31480
31937
|
}
|
|
31481
|
-
|
|
31482
|
-
|
|
31483
|
-
|
|
31484
|
-
|
|
31485
|
-
|
|
31486
|
-
|
|
31487
|
-
|
|
31488
|
-
|
|
31489
|
-
|
|
31490
|
-
|
|
31491
|
-
|
|
31492
|
-
|
|
31493
|
-
|
|
31494
|
-
|
|
31495
|
-
|
|
31496
|
-
|
|
31497
|
-
|
|
31498
|
-
|
|
31499
|
-
|
|
31500
|
-
|
|
31501
|
-
|
|
31502
|
-
|
|
31503
|
-
|
|
31504
|
-
|
|
31505
|
-
".
|
|
31506
|
-
|
|
31507
|
-
|
|
31508
|
-
|
|
31938
|
+
function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
31939
|
+
let identifier = fallback;
|
|
31940
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31941
|
+
parser.on("opentag", (tag) => {
|
|
31942
|
+
if ((tag.local ?? tag.name) === "assessmentItem") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31943
|
+
});
|
|
31944
|
+
try {
|
|
31945
|
+
parser.write(inputXml).close();
|
|
31946
|
+
} catch {}
|
|
31947
|
+
return identifier;
|
|
31948
|
+
}
|
|
31949
|
+
function readAssessmentTestIdentifier(inputXml, fallback) {
|
|
31950
|
+
let identifier = fallback;
|
|
31951
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31952
|
+
parser.on("opentag", (tag) => {
|
|
31953
|
+
if ((tag.local ?? tag.name) === "assessmentTest") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31954
|
+
});
|
|
31955
|
+
try {
|
|
31956
|
+
parser.write(inputXml).close();
|
|
31957
|
+
} catch {}
|
|
31958
|
+
return identifier;
|
|
31959
|
+
}
|
|
31960
|
+
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31961
|
+
if (!items.has(baseReference)) return baseReference;
|
|
31962
|
+
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
31963
|
+
if (!items.has(readableCandidate)) return readableCandidate;
|
|
31964
|
+
const sourceDigest = md5hex(normalizeHref(sourceHref));
|
|
31965
|
+
let candidate = `${readableCandidate}_${sourceDigest}`;
|
|
31966
|
+
let suffix = 1;
|
|
31967
|
+
while (items.has(candidate)) {
|
|
31968
|
+
candidate = `${readableCandidate}_${sourceDigest}_${suffix}`;
|
|
31969
|
+
suffix += 1;
|
|
31970
|
+
}
|
|
31971
|
+
return candidate;
|
|
31972
|
+
}
|
|
31973
|
+
function isUnsafeAssetHrefError(error) {
|
|
31974
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
31975
|
+
}
|
|
31976
|
+
function hasAssetNamingDiagnostic(diagnostics) {
|
|
31977
|
+
return diagnostics.some((diagnostic) => diagnostic.code === DiagnosticCode.QTI_ASSET_HREF_UNSAFE || diagnostic.code === DiagnosticCode.QTI_ASSET_FILENAME_CONFLICT || diagnostic.code === DiagnosticCode.QTI_ASSET_IDENTITY_BYTES_CONFLICT);
|
|
31978
|
+
}
|
|
31979
|
+
/**
|
|
31980
|
+
* Resolve a local QTI reference exactly as asset URL transformation does.
|
|
31981
|
+
* References without a leading dot segment are already package-relative;
|
|
31982
|
+
* `./` and `../` references are resolved from the item source directory.
|
|
31983
|
+
*/
|
|
31984
|
+
function resolvePackageAssetHref(href, sourceHrefBase) {
|
|
31985
|
+
const cleanHref = href.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
31986
|
+
if (!cleanHref || /^https?:\/\//i.test(cleanHref) || cleanHref.startsWith("//") || cleanHref.startsWith("data:") || cleanHref.includes("assets.learnosity.com") || cleanHref.includes("media-vault.learnosity.com")) return;
|
|
31987
|
+
if (!(/^\.\.?\//.test(cleanHref) || !cleanHref.includes("/"))) return canonicalizeQtiAssetHref(cleanHref);
|
|
31988
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
31989
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${cleanHref}`);
|
|
31990
|
+
}
|
|
31991
|
+
/** Extract local asset-bearing attributes from item XML or resolved passage HTML. */
|
|
31992
|
+
function extractAssetHrefs(content) {
|
|
31993
|
+
const hrefs = [];
|
|
31994
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31995
|
+
const attributePattern = /\b(?:src|data|href)\s*=\s*["']([^"']+)["']/gi;
|
|
31996
|
+
let match;
|
|
31997
|
+
while ((match = attributePattern.exec(content)) !== null) if (!seen.has(match[1])) {
|
|
31998
|
+
seen.add(match[1]);
|
|
31999
|
+
hrefs.push(match[1]);
|
|
32000
|
+
}
|
|
32001
|
+
return hrefs;
|
|
32002
|
+
}
|
|
32003
|
+
function isCopyableAssetPath(path) {
|
|
32004
|
+
return isSupportedQtiAssetPath(path);
|
|
32005
|
+
}
|
|
31509
32006
|
/**
|
|
31510
32007
|
* Merge two tag objects, combining tag values for each tag type
|
|
31511
32008
|
* Source tags are merged into base tags, avoiding duplicates
|
|
@@ -31576,7 +32073,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31576
32073
|
if (needed.has(normalized)) return true;
|
|
31577
32074
|
const lower = normalized.toLowerCase();
|
|
31578
32075
|
if (lower.endsWith(".html")) return false;
|
|
31579
|
-
return lower.endsWith(".xml") ||
|
|
32076
|
+
return lower.endsWith(".xml") || isSupportedQtiAssetPath(normalized);
|
|
31580
32077
|
};
|
|
31581
32078
|
}
|
|
31582
32079
|
const unzipped = unzipToEntries(input.zipBytes, label, filter ? { filter } : void 0);
|
|
@@ -31611,6 +32108,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31611
32108
|
}
|
|
31612
32109
|
const items = /* @__PURE__ */ new Map();
|
|
31613
32110
|
const itemFilenames = /* @__PURE__ */ new Map();
|
|
32111
|
+
const itemAssetContexts = [];
|
|
31614
32112
|
const qtiRefToMd5Refs = /* @__PURE__ */ new Map();
|
|
31615
32113
|
const convertedSourceFiles = [];
|
|
31616
32114
|
const failedSourceFiles = [];
|
|
@@ -31673,23 +32171,33 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31673
32171
|
}
|
|
31674
32172
|
const itemXml = decodeUtf8(itemEntry.data);
|
|
31675
32173
|
const itemFilePath = opts?.sourceDir ? posixJoin(opts.sourceDir, itemResource.href) : itemResource.href;
|
|
32174
|
+
const baseItemReference = generateItemReference(readAssessmentItemIdentifier(itemXml, itemResource.identifier), opts?.itemReferenceSource, itemFilePath);
|
|
32175
|
+
const finalItemReference = uniqueItemReference(baseItemReference, itemResource.href, items);
|
|
31676
32176
|
const itemResult = convertQtiAssessmentItemToLearnosity(itemXml, {
|
|
31677
32177
|
inputPath: itemFilePath,
|
|
31678
32178
|
sourceFile: itemFilePath,
|
|
31679
32179
|
organisationId: opts?.organisationId,
|
|
31680
32180
|
mediaVault: opts?.mediaVault,
|
|
31681
32181
|
customAssetUrl: opts?.customAssetUrl,
|
|
32182
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31682
32183
|
itemReferenceSource: opts?.itemReferenceSource,
|
|
31683
32184
|
fileAccess: opts?.fileAccess,
|
|
31684
|
-
packageRoot: opts?.sourceDir
|
|
32185
|
+
packageRoot: opts?.sourceDir,
|
|
32186
|
+
finalItemReference,
|
|
32187
|
+
sourceHrefBase: itemResource.href
|
|
31685
32188
|
});
|
|
31686
32189
|
diagnostics.push(...itemResult.diagnostics);
|
|
31687
32190
|
if (itemResult.item) {
|
|
31688
32191
|
let md5Ref = itemResult.item.item.reference;
|
|
32192
|
+
if (finalItemReference !== baseItemReference) diagnostics.push({
|
|
32193
|
+
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
32194
|
+
level: "warning",
|
|
32195
|
+
file: itemResource.href,
|
|
32196
|
+
message: `Duplicate item reference "${finalItemReference}" disambiguated from "${baseItemReference}" (source: ${itemResource.href})`
|
|
32197
|
+
});
|
|
31689
32198
|
if (items.has(md5Ref)) {
|
|
31690
|
-
const
|
|
31691
|
-
|
|
31692
|
-
md5Ref = `${md5Ref}_${filename}`;
|
|
32199
|
+
const originalRef = md5Ref;
|
|
32200
|
+
md5Ref = uniqueItemReference(finalItemReference, itemResource.href, items);
|
|
31693
32201
|
itemResult.item.item.reference = md5Ref;
|
|
31694
32202
|
for (const question of itemResult.item.questions) {
|
|
31695
32203
|
const oldRef = question.reference;
|
|
@@ -31703,7 +32211,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31703
32211
|
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
31704
32212
|
level: "warning",
|
|
31705
32213
|
file: itemResource.href,
|
|
31706
|
-
message: `Duplicate item reference "${
|
|
32214
|
+
message: `Duplicate item reference "${md5Ref}" disambiguated from "${originalRef}" (source: ${itemResource.href})`
|
|
31707
32215
|
});
|
|
31708
32216
|
}
|
|
31709
32217
|
if (itemResource.metadataXml) try {
|
|
@@ -31723,9 +32231,15 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31723
32231
|
});
|
|
31724
32232
|
}
|
|
31725
32233
|
items.set(md5Ref, itemResult.item);
|
|
32234
|
+
itemAssetContexts.push({
|
|
32235
|
+
finalItemReference: md5Ref,
|
|
32236
|
+
sourceHref: itemResource.href,
|
|
32237
|
+
sourceFile: itemFilePath,
|
|
32238
|
+
inputXml: itemXml
|
|
32239
|
+
});
|
|
31726
32240
|
const filenameSource = opts?.itemFilenameSource;
|
|
31727
|
-
if (filenameSource && filenameSource !== (opts.itemReferenceSource
|
|
31728
|
-
const filename = generateItemReference(itemXml
|
|
32241
|
+
if (filenameSource && normalizeRefSource(filenameSource) !== normalizeRefSource(opts.itemReferenceSource)) {
|
|
32242
|
+
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
31729
32243
|
itemFilenames.set(md5Ref, filename);
|
|
31730
32244
|
}
|
|
31731
32245
|
if (!qtiRefToMd5Refs.has(itemResource.identifier)) qtiRefToMd5Refs.set(itemResource.identifier, []);
|
|
@@ -31736,6 +32250,12 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31736
32250
|
diagnostics.push(...ensureFailedItemDiagnostic(itemResult.diagnostics, itemResource.href));
|
|
31737
32251
|
}
|
|
31738
32252
|
}
|
|
32253
|
+
if (hasAssetNamingDiagnostic(diagnostics)) return {
|
|
32254
|
+
diagnostics,
|
|
32255
|
+
convertedSourceFiles,
|
|
32256
|
+
failedSourceFiles,
|
|
32257
|
+
convertedActivityFiles
|
|
32258
|
+
};
|
|
31739
32259
|
if (items.size === 0 && itemResourcesToConvert.length > 0) {
|
|
31740
32260
|
diagnostics.push({
|
|
31741
32261
|
code: DiagnosticCode.QTI_PACKAGE_ITEM_NOT_FOUND,
|
|
@@ -31749,8 +32269,10 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31749
32269
|
const activitiesManifest = {};
|
|
31750
32270
|
if (testResources.length > 0) for (const testResource of testResources) {
|
|
31751
32271
|
let activityReference;
|
|
31752
|
-
if (opts?.itemReferenceSource === "
|
|
31753
|
-
|
|
32272
|
+
if (normalizeRefSource(opts?.itemReferenceSource) === "itemIdentifier") {
|
|
32273
|
+
const testEntry = entries.get(normalizeHref(testResource.href));
|
|
32274
|
+
activityReference = testEntry ? readAssessmentTestIdentifier(decodeUtf8(testEntry.data), testResource.identifier) : testResource.identifier;
|
|
32275
|
+
} else {
|
|
31754
32276
|
const hrefParts = testResource.href.split("/");
|
|
31755
32277
|
activityReference = hrefParts[hrefParts.length - 1].replace(/\.xml$/i, "");
|
|
31756
32278
|
}
|
|
@@ -31840,24 +32362,39 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31840
32362
|
activitiesManifest[activityId] = { items: activityItems };
|
|
31841
32363
|
}
|
|
31842
32364
|
const assets = /* @__PURE__ */ new Map();
|
|
31843
|
-
const
|
|
31844
|
-
|
|
31845
|
-
|
|
31846
|
-
|
|
31847
|
-
|
|
31848
|
-
|
|
31849
|
-
|
|
31850
|
-
|
|
31851
|
-
|
|
32365
|
+
const assetCandidates = /* @__PURE__ */ new Map();
|
|
32366
|
+
const addAssetCandidate = (href, data) => {
|
|
32367
|
+
try {
|
|
32368
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
32369
|
+
if (isCopyableAssetPath(canonicalHref)) assetCandidates.set(canonicalHref, new Uint8Array(data));
|
|
32370
|
+
} catch {}
|
|
32371
|
+
};
|
|
32372
|
+
for (const resource of resources) if (resource.type === "webcontent" || resource.type.includes("associated")) for (const href of [resource.href, ...resource.files ?? []]) {
|
|
32373
|
+
const assetEntry = entries.get(normalizeHref(href));
|
|
32374
|
+
if (assetEntry) addAssetCandidate(href, assetEntry.data);
|
|
31852
32375
|
}
|
|
31853
32376
|
for (const [path, entry] of entries) {
|
|
31854
|
-
if (
|
|
31855
|
-
|
|
31856
|
-
|
|
31857
|
-
|
|
31858
|
-
|
|
31859
|
-
|
|
31860
|
-
|
|
32377
|
+
if (path === "imsmanifest.xml" || path.toLowerCase().endsWith(".xml")) continue;
|
|
32378
|
+
addAssetCandidate(path, entry.data);
|
|
32379
|
+
}
|
|
32380
|
+
const registry = new AssetFilenameRegistry(opts?.preserveAssetFilenames ?? false);
|
|
32381
|
+
const registerContextAsset = (context, rawHref, sourceHrefBase) => {
|
|
32382
|
+
const canonicalHref = resolvePackageAssetHref(rawHref, sourceHrefBase);
|
|
32383
|
+
if (!canonicalHref) return;
|
|
32384
|
+
const bytes = assetCandidates.get(canonicalHref);
|
|
32385
|
+
if (!bytes) return;
|
|
32386
|
+
const registration = registry.register(context.finalItemReference, canonicalHref, bytes);
|
|
32387
|
+
assets.set(registration.filename, registration.bytes);
|
|
32388
|
+
};
|
|
32389
|
+
for (const context of itemAssetContexts) {
|
|
32390
|
+
for (const rawHref of extractAssetHrefs(context.inputXml)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
32391
|
+
for (const passagePath of getAllPassageDataPaths(context.inputXml)) {
|
|
32392
|
+
const passageContent = opts?.fileAccess?.resolvePassageFile(passagePath, context.sourceFile);
|
|
32393
|
+
const passageHref = resolvePackageAssetHref(passagePath, context.sourceHref);
|
|
32394
|
+
const entryContent = passageHref ? entries.get(passageHref) : void 0;
|
|
32395
|
+
const resolvedPassageContent = passageContent ?? (entryContent ? decodeUtf8(entryContent.data) : void 0);
|
|
32396
|
+
if (!resolvedPassageContent) continue;
|
|
32397
|
+
for (const rawHref of extractAssetHrefs(resolvedPassageContent)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
31861
32398
|
}
|
|
31862
32399
|
}
|
|
31863
32400
|
return {
|
|
@@ -31870,7 +32407,8 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31870
32407
|
organisationId: opts?.organisationId,
|
|
31871
32408
|
mediaVault: opts?.mediaVault ?? false,
|
|
31872
32409
|
customAssetUrl: opts?.customAssetUrl,
|
|
31873
|
-
|
|
32410
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
32411
|
+
itemReferenceSource: opts?.itemReferenceSource ?? "itemIdentifier"
|
|
31874
32412
|
}
|
|
31875
32413
|
},
|
|
31876
32414
|
items: Array.from(items.keys()).sort(),
|
|
@@ -31891,7 +32429,25 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31891
32429
|
convertedActivityFiles
|
|
31892
32430
|
};
|
|
31893
32431
|
} catch (error) {
|
|
31894
|
-
diagnostics.push({
|
|
32432
|
+
if (error instanceof AssetFilenameConflictError) diagnostics.push({
|
|
32433
|
+
code: error.kind === "identity-bytes" ? DiagnosticCode.QTI_ASSET_IDENTITY_BYTES_CONFLICT : DiagnosticCode.QTI_ASSET_FILENAME_CONFLICT,
|
|
32434
|
+
level: "error",
|
|
32435
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
32436
|
+
message: error.message,
|
|
32437
|
+
context: {
|
|
32438
|
+
mode: error.mode,
|
|
32439
|
+
filename: error.filename,
|
|
32440
|
+
existingIdentity: error.existing.serializedIdentity,
|
|
32441
|
+
incomingIdentity: error.incoming.serializedIdentity
|
|
32442
|
+
}
|
|
32443
|
+
});
|
|
32444
|
+
else if (isUnsafeAssetHrefError(error)) diagnostics.push({
|
|
32445
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
32446
|
+
level: "error",
|
|
32447
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
32448
|
+
message: error.message
|
|
32449
|
+
});
|
|
32450
|
+
else diagnostics.push({
|
|
31895
32451
|
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
31896
32452
|
level: "error",
|
|
31897
32453
|
file: "root",
|
|
@@ -32818,6 +33374,22 @@ function stringifyDeterministic(obj) {
|
|
|
32818
33374
|
}, 2);
|
|
32819
33375
|
}
|
|
32820
33376
|
/**
|
|
33377
|
+
* Return an asset key relative to the bundle's `assets/` root.
|
|
33378
|
+
*
|
|
33379
|
+
* New callers provide selected filenames or other root-relative keys. Strip
|
|
33380
|
+
* legacy leading `assets/` segments so the writer remains compatible with
|
|
33381
|
+
* source-relative keys without producing `assets/assets/...` paths.
|
|
33382
|
+
*/
|
|
33383
|
+
function normalizeBundleAssetPath(assetPath) {
|
|
33384
|
+
let normalized = assetPath.replaceAll("\\", "/");
|
|
33385
|
+
while (normalized.startsWith("./")) normalized = normalized.slice(2);
|
|
33386
|
+
while (normalized.startsWith("assets/")) normalized = normalized.slice(7);
|
|
33387
|
+
const segments = normalized.split("/").filter((segment) => segment && segment !== ".");
|
|
33388
|
+
const isAbsolute = normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(normalized);
|
|
33389
|
+
if (!normalized || isAbsolute || segments.some((segment) => segment === "..")) throw new Error(`Unsafe bundle asset path: ${assetPath}`);
|
|
33390
|
+
return segments.join("/");
|
|
33391
|
+
}
|
|
33392
|
+
/**
|
|
32821
33393
|
* Write Learnosity Bundle to directory or ZIP
|
|
32822
33394
|
*/
|
|
32823
33395
|
async function writeLearnosityBundle(bundle, options) {
|
|
@@ -32841,10 +33413,13 @@ async function writeLearnosityBundle(bundle, options) {
|
|
|
32841
33413
|
content: stringifyDeterministic(item)
|
|
32842
33414
|
});
|
|
32843
33415
|
}
|
|
32844
|
-
for (const [assetPath, data] of bundle.assets)
|
|
32845
|
-
|
|
32846
|
-
|
|
32847
|
-
|
|
33416
|
+
for (const [assetPath, data] of bundle.assets) {
|
|
33417
|
+
const relativeAssetPath = normalizeBundleAssetPath(assetPath);
|
|
33418
|
+
files.push({
|
|
33419
|
+
path: `assets/${relativeAssetPath}`,
|
|
33420
|
+
content: Buffer.from(data)
|
|
33421
|
+
});
|
|
33422
|
+
}
|
|
32848
33423
|
writeZip(outDir, files);
|
|
32849
33424
|
} else {
|
|
32850
33425
|
await mkdir(outDir, { recursive: true });
|
|
@@ -32863,7 +33438,8 @@ async function writeLearnosityBundle(bundle, options) {
|
|
|
32863
33438
|
await writeFile(itemPath, stringifyDeterministic(item));
|
|
32864
33439
|
}
|
|
32865
33440
|
for (const [assetPath, data] of bundle.assets) {
|
|
32866
|
-
const
|
|
33441
|
+
const relativeAssetPath = normalizeBundleAssetPath(assetPath);
|
|
33442
|
+
const fullPath = join$1(outDir, "assets", relativeAssetPath);
|
|
32867
33443
|
const assetDir = join$1(fullPath, "..");
|
|
32868
33444
|
await mkdir(assetDir, { recursive: true });
|
|
32869
33445
|
await writeFile(fullPath, data);
|
|
@@ -33259,6 +33835,7 @@ async function convertQtiPackageToLearnosity(opts) {
|
|
|
33259
33835
|
organisationId: opts.organisationId,
|
|
33260
33836
|
mediaVault: opts.mediaVault,
|
|
33261
33837
|
customAssetUrl: opts.customAssetUrl,
|
|
33838
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
33262
33839
|
itemReferenceSource: opts.itemReferenceSource,
|
|
33263
33840
|
itemFilenameSource: opts.itemFilenameSource,
|
|
33264
33841
|
truncateTags: opts.truncateTags,
|