@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
|
@@ -174,6 +174,9 @@ const DiagnosticCode = {
|
|
|
174
174
|
QTI_PACKAGE_NO_CONTENT: "QTI_PACKAGE_NO_CONTENT",
|
|
175
175
|
QTI_PACKAGE_DUPLICATE_IDENTIFIER: "QTI_PACKAGE_DUPLICATE_IDENTIFIER",
|
|
176
176
|
QTI_ITEM_CONVERSION_FAILED: "QTI_ITEM_CONVERSION_FAILED",
|
|
177
|
+
QTI_ASSET_HREF_UNSAFE: "QTI_ASSET_HREF_UNSAFE",
|
|
178
|
+
QTI_ASSET_FILENAME_CONFLICT: "QTI_ASSET_FILENAME_CONFLICT",
|
|
179
|
+
QTI_ASSET_IDENTITY_BYTES_CONFLICT: "QTI_ASSET_IDENTITY_BYTES_CONFLICT",
|
|
177
180
|
LRN_BUNDLE_WRITTEN: "LRN_BUNDLE_WRITTEN",
|
|
178
181
|
QTI_DOWNGRADE_NAMESPACE: "QTI_DOWNGRADE_NAMESPACE",
|
|
179
182
|
QTI_DOWNGRADE_SCHEMA_LOCATION: "QTI_DOWNGRADE_SCHEMA_LOCATION",
|
|
@@ -22989,6 +22992,33 @@ function md5hex(input) {
|
|
|
22989
22992
|
return hex;
|
|
22990
22993
|
}
|
|
22991
22994
|
//#endregion
|
|
22995
|
+
//#region src/qti-to-learnosity/utils/mediaFeature.ts
|
|
22996
|
+
/**
|
|
22997
|
+
* Build a stable UUID-shaped identifier for a media feature.
|
|
22998
|
+
*
|
|
22999
|
+
* Feature output must remain identical for equivalent directory and ZIP
|
|
23000
|
+
* package conversions, so the identifier is derived from the final media URL
|
|
23001
|
+
* rather than generated randomly. The UUID version and variant bits are set
|
|
23002
|
+
* to keep the value compatible with consumers expecting a v4-shaped UUID.
|
|
23003
|
+
*/
|
|
23004
|
+
function buildMediaFeatureId(transformedUrl) {
|
|
23005
|
+
const hash = md5hex(transformedUrl).split("");
|
|
23006
|
+
const variant = [
|
|
23007
|
+
"8",
|
|
23008
|
+
"9",
|
|
23009
|
+
"a",
|
|
23010
|
+
"b"
|
|
23011
|
+
][parseInt(hash[16], 16) & 3];
|
|
23012
|
+
hash[12] = "4";
|
|
23013
|
+
hash[16] = variant;
|
|
23014
|
+
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("")}`;
|
|
23015
|
+
}
|
|
23016
|
+
/** Build a Learnosity simple-feature span for audio or hosted video. */
|
|
23017
|
+
function buildMediaFeatureSpan(transformedUrl, kind, featureId = buildMediaFeatureId(transformedUrl)) {
|
|
23018
|
+
if (kind === "audio") return `<span class="learnosity-feature" data-player="button" data-simplefeature_id="${featureId}" data-src="${transformedUrl}" data-type="audioplayer"></span>`;
|
|
23019
|
+
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>`;
|
|
23020
|
+
}
|
|
23021
|
+
//#endregion
|
|
22992
23022
|
//#region src/qti-to-learnosity/utils/convertObjectElement.ts
|
|
22993
23023
|
/**
|
|
22994
23024
|
* Convert QTI <object> elements to appropriate Learnosity HTML elements
|
|
@@ -23040,7 +23070,7 @@ function buildDeterministicFeatureId(transformedUrl) {
|
|
|
23040
23070
|
* <object data="video.mp4" type="video/mp4"/>
|
|
23041
23071
|
* → <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>
|
|
23042
23072
|
*/
|
|
23043
|
-
function convertObjectToElement(objectTag, organisationId, mediaVault = false, customAssetUrl) {
|
|
23073
|
+
function convertObjectToElement(objectTag, organisationId, mediaVault = false, customAssetUrl, assetContext = {}) {
|
|
23044
23074
|
const dataMatch = objectTag.match(/data=["']([^"']+)["']/i);
|
|
23045
23075
|
const srcMatch = objectTag.match(/src=["']([^"']+)["']/i);
|
|
23046
23076
|
const typeMatch = objectTag.match(/type=["']([^"']+)["']/i);
|
|
@@ -23050,11 +23080,11 @@ function convertObjectToElement(objectTag, organisationId, mediaVault = false, c
|
|
|
23050
23080
|
if (!urlMatch) return objectTag;
|
|
23051
23081
|
const sourceUrl = urlMatch[1];
|
|
23052
23082
|
const category = getMimeTypeCategory(typeMatch ? typeMatch[1] : "");
|
|
23053
|
-
const transformedUrl = transformUrl(sourceUrl, organisationId, mediaVault, customAssetUrl);
|
|
23083
|
+
const transformedUrl = transformUrl(sourceUrl, organisationId, mediaVault, customAssetUrl, assetContext);
|
|
23054
23084
|
switch (category) {
|
|
23055
23085
|
case "image": return buildImageTag(transformedUrl, heightMatch, widthMatch);
|
|
23056
|
-
case "audio": return
|
|
23057
|
-
case "video": return
|
|
23086
|
+
case "audio": return buildMediaFeatureSpan(transformedUrl, "audio", buildDeterministicFeatureId(transformedUrl));
|
|
23087
|
+
case "video": return buildMediaFeatureSpan(transformedUrl, "video", buildDeterministicFeatureId(transformedUrl));
|
|
23058
23088
|
default: return objectTag.replace(sourceUrl, transformedUrl);
|
|
23059
23089
|
}
|
|
23060
23090
|
}
|
|
@@ -23098,55 +23128,139 @@ function normalizeTableClass(html) {
|
|
|
23098
23128
|
});
|
|
23099
23129
|
}
|
|
23100
23130
|
//#endregion
|
|
23101
|
-
//#region src/qti-to-learnosity/utils/
|
|
23131
|
+
//#region src/qti-to-learnosity/utils/assetIdentity.ts
|
|
23102
23132
|
/**
|
|
23103
|
-
*
|
|
23104
|
-
* TASK 030
|
|
23133
|
+
* Browser-safe helpers for identifying package-local QTI assets.
|
|
23105
23134
|
*
|
|
23106
|
-
*
|
|
23135
|
+
* QTI asset references are package-relative paths, not filesystem paths. Keeping
|
|
23136
|
+
* their canonical form here makes directory and ZIP inputs produce the same
|
|
23137
|
+
* identity while rejecting references that could escape the package root.
|
|
23138
|
+
*/
|
|
23139
|
+
/** Asset extensions copied and rewritten by QTI → Learnosity conversion. */
|
|
23140
|
+
const QTI_ASSET_EXTENSIONS = [
|
|
23141
|
+
".png",
|
|
23142
|
+
".jpg",
|
|
23143
|
+
".jpeg",
|
|
23144
|
+
".gif",
|
|
23145
|
+
".svg",
|
|
23146
|
+
".webp",
|
|
23147
|
+
".bmp",
|
|
23148
|
+
".ico",
|
|
23149
|
+
".mp3",
|
|
23150
|
+
".mp4",
|
|
23151
|
+
".wav",
|
|
23152
|
+
".ogg",
|
|
23153
|
+
".webm",
|
|
23154
|
+
".ogv",
|
|
23155
|
+
".m4a",
|
|
23156
|
+
".m4v",
|
|
23157
|
+
".css",
|
|
23158
|
+
".woff",
|
|
23159
|
+
".woff2",
|
|
23160
|
+
".ttf",
|
|
23161
|
+
".eot",
|
|
23162
|
+
".pdf",
|
|
23163
|
+
".json"
|
|
23164
|
+
];
|
|
23165
|
+
function isSupportedQtiAssetPath(path) {
|
|
23166
|
+
const lowerPath = path.toLowerCase();
|
|
23167
|
+
return !lowerPath.endsWith(".html") && !lowerPath.endsWith(".htm") && QTI_ASSET_EXTENSIONS.some((extension) => lowerPath.endsWith(extension));
|
|
23168
|
+
}
|
|
23169
|
+
function isUnsafeQtiAssetHrefError(error) {
|
|
23170
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
23171
|
+
}
|
|
23172
|
+
/**
|
|
23173
|
+
* Canonicalize a package-relative QTI asset href.
|
|
23174
|
+
*
|
|
23175
|
+
* Query strings and fragments are URL metadata and do not identify a different
|
|
23176
|
+
* package asset. Path separators are normalized to `/`, dot segments are
|
|
23177
|
+
* resolved, and traversal above the package root is rejected.
|
|
23107
23178
|
*/
|
|
23179
|
+
function stripHrefMetadata(href) {
|
|
23180
|
+
const metadataStart = href.search(/[?#]/);
|
|
23181
|
+
return (metadataStart === -1 ? href : href.slice(0, metadataStart)).replaceAll("\\", "/");
|
|
23182
|
+
}
|
|
23183
|
+
function assertPackageRelativePath(path, href) {
|
|
23184
|
+
const isAbsolute = path.startsWith("/") || /^[A-Za-z]:/.test(path) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(path);
|
|
23185
|
+
if (!path || path.includes("\0") || isAbsolute) throw new Error(`Unsafe QTI asset href: ${href}`);
|
|
23186
|
+
if (path.endsWith("/")) throw new Error(`QTI asset href has no filename: ${href}`);
|
|
23187
|
+
}
|
|
23188
|
+
function normalizePathSegments(path, href) {
|
|
23189
|
+
const segments = [];
|
|
23190
|
+
for (const segment of path.split("/")) {
|
|
23191
|
+
if (!segment || segment === ".") continue;
|
|
23192
|
+
if (segment === "..") {
|
|
23193
|
+
if (segments.length === 0) throw new Error(`Unsafe QTI asset href: ${href}`);
|
|
23194
|
+
segments.pop();
|
|
23195
|
+
continue;
|
|
23196
|
+
}
|
|
23197
|
+
segments.push(segment);
|
|
23198
|
+
}
|
|
23199
|
+
if (segments.length === 0) throw new Error(`QTI asset href has no filename: ${href}`);
|
|
23200
|
+
return segments.join("/");
|
|
23201
|
+
}
|
|
23202
|
+
function canonicalizeQtiAssetHref(href) {
|
|
23203
|
+
if (typeof href !== "string") throw new TypeError("QTI asset href must be a string");
|
|
23204
|
+
const path = stripHrefMetadata(href);
|
|
23205
|
+
assertPackageRelativePath(path, href);
|
|
23206
|
+
return normalizePathSegments(path, href);
|
|
23207
|
+
}
|
|
23208
|
+
/** Return the final filename from a canonicalized package-relative href. */
|
|
23209
|
+
function extractQtiAssetBasename(href) {
|
|
23210
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
23211
|
+
return canonicalHref.slice(canonicalHref.lastIndexOf("/") + 1);
|
|
23212
|
+
}
|
|
23108
23213
|
/**
|
|
23109
|
-
*
|
|
23110
|
-
|
|
23111
|
-
|
|
23112
|
-
|
|
23113
|
-
|
|
23114
|
-
"
|
|
23115
|
-
"
|
|
23116
|
-
|
|
23117
|
-
"webp",
|
|
23118
|
-
"mp3",
|
|
23119
|
-
"wav",
|
|
23120
|
-
"ogg",
|
|
23121
|
-
"m4a",
|
|
23122
|
-
"mp4",
|
|
23123
|
-
"webm",
|
|
23124
|
-
"ogv",
|
|
23125
|
-
"m4v"
|
|
23126
|
-
]);
|
|
23214
|
+
* Return the final filename extension, including its leading dot.
|
|
23215
|
+
* Dotfiles and filenames ending in a dot have no extension.
|
|
23216
|
+
*/
|
|
23217
|
+
function extractQtiAssetExtension(href) {
|
|
23218
|
+
const basename = extractQtiAssetBasename(href);
|
|
23219
|
+
const extensionStart = basename.lastIndexOf(".");
|
|
23220
|
+
return extensionStart > 0 && extensionStart < basename.length - 1 ? basename.slice(extensionStart) : "";
|
|
23221
|
+
}
|
|
23127
23222
|
/**
|
|
23128
|
-
*
|
|
23129
|
-
*
|
|
23130
|
-
*
|
|
23223
|
+
* Serialize the item-scoped asset identity using an ordered JSON tuple.
|
|
23224
|
+
*
|
|
23225
|
+
* JSON serialization is intentional: unlike delimiter-based concatenation, it
|
|
23226
|
+
* keeps the item reference and canonical href unambiguous when either value
|
|
23227
|
+
* contains punctuation that could otherwise be mistaken for a separator.
|
|
23131
23228
|
*/
|
|
23132
|
-
|
|
23133
|
-
|
|
23134
|
-
|
|
23135
|
-
|
|
23136
|
-
|
|
23137
|
-
|
|
23138
|
-
|
|
23139
|
-
|
|
23140
|
-
|
|
23229
|
+
function serializeQtiAssetIdentity(finalItemReference, qtiAssetHref) {
|
|
23230
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
23231
|
+
return JSON.stringify([finalItemReference, canonicalHref]);
|
|
23232
|
+
}
|
|
23233
|
+
/** Derive the lowercase MD5 hex hash for a canonical item-scoped identity. */
|
|
23234
|
+
function hashQtiAssetIdentity(finalItemReference, qtiAssetHref) {
|
|
23235
|
+
return md5hex(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
23236
|
+
}
|
|
23237
|
+
/**
|
|
23238
|
+
* Select the output filename for a package-local QTI asset.
|
|
23239
|
+
*
|
|
23240
|
+
* Hashed naming is the default so the full item-scoped identity, rather than a
|
|
23241
|
+
* globally ambiguous source basename, determines the output name. Only the
|
|
23242
|
+
* canonical source extension is retained after the digest. Preserve mode is
|
|
23243
|
+
* an explicit compatibility opt-out and returns the canonical final basename.
|
|
23244
|
+
*/
|
|
23245
|
+
function selectQtiAssetFilename(finalItemReference, qtiAssetHref, preserveAssetFilenames = false) {
|
|
23246
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
23247
|
+
if (preserveAssetFilenames) return extractQtiAssetBasename(canonicalHref);
|
|
23248
|
+
return `${hashQtiAssetIdentity(finalItemReference, canonicalHref)}${extractQtiAssetExtension(canonicalHref)}`;
|
|
23249
|
+
}
|
|
23250
|
+
//#endregion
|
|
23251
|
+
//#region src/qti-to-learnosity/utils/assetUrlTransform.ts
|
|
23141
23252
|
/**
|
|
23142
|
-
*
|
|
23253
|
+
* Asset URL transformation for Learnosity CDN
|
|
23254
|
+
* TASK 030
|
|
23143
23255
|
*
|
|
23144
|
-
*
|
|
23145
|
-
* be influenced at runtime. Global regex used only with
|
|
23146
|
-
* `String.prototype.replace`, which resets lastIndex on completion, so sharing
|
|
23147
|
-
* a single compiled instance across calls is safe.
|
|
23256
|
+
* Transforms asset URLs in HTML content to use Learnosity CDN URLs.
|
|
23148
23257
|
*/
|
|
23149
|
-
|
|
23258
|
+
/** Matches supported asset-bearing HTML attributes on any element. */
|
|
23259
|
+
const ASSET_ATTRIBUTE_PATTERN = /(<[A-Za-z][^>]*?\b(?:src|data|href)\s*=\s*["'])([^"']+)(["'][^>]*>)/gi;
|
|
23260
|
+
/** Matches <object ...> (optionally with its closing tag) for element conversion. */
|
|
23261
|
+
const OBJECT_TAG_PATTERN = /<object\s+[^>]*>(?:<\/object>)?/gi;
|
|
23262
|
+
/** Matches anchors whose href points to inline audio/video media. */
|
|
23263
|
+
const INLINE_MEDIA_LINK_PATTERN = /<a\b([^>]*?)\bhref\s*=\s*(["'])([^"']+)\2([^>]*)>([\s\S]*?)<\/a\s*>/gi;
|
|
23150
23264
|
/**
|
|
23151
23265
|
* Extract filename from a URL path
|
|
23152
23266
|
* Examples:
|
|
@@ -23158,12 +23272,26 @@ function extractFilename$1(url) {
|
|
|
23158
23272
|
const segments = url.split("?")[0].split("#")[0].split("/");
|
|
23159
23273
|
return segments[segments.length - 1];
|
|
23160
23274
|
}
|
|
23161
|
-
/**
|
|
23162
|
-
* Check if a filename has a supported asset extension
|
|
23163
|
-
*/
|
|
23164
23275
|
function isSupportedAsset(filename) {
|
|
23165
|
-
|
|
23166
|
-
|
|
23276
|
+
return isSupportedQtiAssetPath(filename);
|
|
23277
|
+
}
|
|
23278
|
+
function getInlineMediaKind(url, attributes) {
|
|
23279
|
+
const mimeType = attributes.match(/\btype\s*=\s*(["'])([^"']+)\1/i)?.[2].toLowerCase();
|
|
23280
|
+
if (mimeType?.startsWith("audio/")) return "audio";
|
|
23281
|
+
if (mimeType?.startsWith("video/")) return "video";
|
|
23282
|
+
const filename = extractFilename$1(url).toLowerCase();
|
|
23283
|
+
if ([
|
|
23284
|
+
".mp3",
|
|
23285
|
+
".wav",
|
|
23286
|
+
".ogg",
|
|
23287
|
+
".m4a"
|
|
23288
|
+
].some((extension) => filename.endsWith(extension))) return "audio";
|
|
23289
|
+
if ([
|
|
23290
|
+
".mp4",
|
|
23291
|
+
".webm",
|
|
23292
|
+
".ogv",
|
|
23293
|
+
".m4v"
|
|
23294
|
+
].some((extension) => filename.endsWith(extension))) return "video";
|
|
23167
23295
|
}
|
|
23168
23296
|
/**
|
|
23169
23297
|
* Build Learnosity CDN URL for an asset
|
|
@@ -23173,17 +23301,24 @@ function buildLearnosityAssetUrl(filename, organisationId, mediaVault = false, c
|
|
|
23173
23301
|
if (customAssetUrl) return `${customAssetUrl.endsWith("/") ? customAssetUrl.slice(0, -1) : customAssetUrl}/${filename}`;
|
|
23174
23302
|
return `https://${mediaVault ? "media-vault" : "assets"}.learnosity.com/organisations/${organisationId}/${filename}`;
|
|
23175
23303
|
}
|
|
23304
|
+
function resolveQtiAssetHref(url, sourceHrefBase) {
|
|
23305
|
+
const normalizedUrl = url.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
23306
|
+
const isItemRelative = /^\.\.?\//.test(normalizedUrl) || !normalizedUrl.includes("/");
|
|
23307
|
+
if (!sourceHrefBase || !isItemRelative) return canonicalizeQtiAssetHref(url);
|
|
23308
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
23309
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${normalizedUrl}`);
|
|
23310
|
+
}
|
|
23176
23311
|
/**
|
|
23177
23312
|
* Transform a single URL to Learnosity CDN format
|
|
23178
23313
|
* Exported for use in image object source fields
|
|
23179
23314
|
*/
|
|
23180
|
-
function transformUrl(url, organisationId, mediaVault = false, customAssetUrl) {
|
|
23315
|
+
function transformUrl(url, organisationId, mediaVault = false, customAssetUrl, context = {}) {
|
|
23181
23316
|
if (url.includes("assets.learnosity.com") || url.includes("media-vault.learnosity.com")) return url;
|
|
23182
|
-
if (
|
|
23317
|
+
if (/^https?:\/\//i.test(url) || url.startsWith("//")) return url;
|
|
23183
23318
|
if (url.startsWith("data:")) return url;
|
|
23184
23319
|
const filename = extractFilename$1(url);
|
|
23185
23320
|
if (!isSupportedAsset(filename)) return url;
|
|
23186
|
-
return buildLearnosityAssetUrl(filename, organisationId, mediaVault, customAssetUrl);
|
|
23321
|
+
return buildLearnosityAssetUrl(context.finalItemReference ? selectQtiAssetFilename(context.finalItemReference, resolveQtiAssetHref(url, context.sourceHrefBase), context.preserveAssetFilenames ?? false) : filename, organisationId, mediaVault, customAssetUrl);
|
|
23187
23322
|
}
|
|
23188
23323
|
/**
|
|
23189
23324
|
* Transform asset URLs in HTML content
|
|
@@ -23201,14 +23336,24 @@ function transformUrl(url, organisationId, mediaVault = false, customAssetUrl) {
|
|
|
23201
23336
|
*/
|
|
23202
23337
|
function transformAssetUrls(html, options) {
|
|
23203
23338
|
if (!html) return html;
|
|
23204
|
-
if (
|
|
23339
|
+
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.");
|
|
23205
23340
|
if (!options.organisationId) return normalizeTableClass(html);
|
|
23206
23341
|
const orgId = options.organisationId;
|
|
23207
23342
|
const mediaVault = options.mediaVault ?? false;
|
|
23208
23343
|
const customAssetUrl = options.customAssetUrl;
|
|
23344
|
+
const assetContext = {
|
|
23345
|
+
finalItemReference: options.finalItemReference,
|
|
23346
|
+
preserveAssetFilenames: options.preserveAssetFilenames,
|
|
23347
|
+
sourceHrefBase: options.sourceHrefBase
|
|
23348
|
+
};
|
|
23209
23349
|
let result = html;
|
|
23210
|
-
result = result.replace(OBJECT_TAG_PATTERN, (match) => convertObjectToElement(match, orgId, mediaVault, customAssetUrl));
|
|
23211
|
-
result = result.replace(
|
|
23350
|
+
result = result.replace(OBJECT_TAG_PATTERN, (match) => convertObjectToElement(match, orgId, mediaVault, customAssetUrl, assetContext));
|
|
23351
|
+
result = result.replace(INLINE_MEDIA_LINK_PATTERN, (match, beforeAttributes, _quote, url, afterAttributes) => {
|
|
23352
|
+
const kind = getInlineMediaKind(url, `${beforeAttributes}${afterAttributes}`);
|
|
23353
|
+
if (!kind) return match;
|
|
23354
|
+
return buildMediaFeatureSpan(transformUrl(url, orgId, mediaVault, customAssetUrl, assetContext), kind);
|
|
23355
|
+
});
|
|
23356
|
+
result = result.replace(ASSET_ATTRIBUTE_PATTERN, (_match, prefix, url, suffix) => prefix + transformUrl(url, orgId, mediaVault, customAssetUrl, assetContext) + suffix);
|
|
23212
23357
|
result = normalizeHtmlWhitespace(result);
|
|
23213
23358
|
result = normalizeTableClass(result);
|
|
23214
23359
|
return result;
|
|
@@ -23216,12 +23361,16 @@ function transformAssetUrls(html, options) {
|
|
|
23216
23361
|
//#endregion
|
|
23217
23362
|
//#region src/qti-to-learnosity/utils/generateItemReference.ts
|
|
23218
23363
|
/**
|
|
23219
|
-
* Generate item reference based on the configured source
|
|
23364
|
+
* Generate item reference based on the configured source.
|
|
23365
|
+
*
|
|
23366
|
+
* - `'itemIdentifier'` (default) and its deprecated alias `'qti'`, as well as an
|
|
23367
|
+
* omitted source, return the QTI `identifier`.
|
|
23368
|
+
* - `'uuid'` returns an MD5 hash of the QTI `identifier`.
|
|
23369
|
+
* - `'sourceFilename'` derives the reference from the source file name.
|
|
23220
23370
|
*/
|
|
23221
23371
|
function generateItemReference(qtiIdentifier, itemReferenceSource, sourceFile) {
|
|
23222
|
-
if (itemReferenceSource === "qti") return qtiIdentifier;
|
|
23223
23372
|
if (itemReferenceSource === "uuid") return md5hex(qtiIdentifier);
|
|
23224
|
-
if (sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23373
|
+
if (itemReferenceSource === "sourceFilename" && sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23225
23374
|
return qtiIdentifier;
|
|
23226
23375
|
}
|
|
23227
23376
|
//#endregion
|
|
@@ -23354,23 +23503,30 @@ function mapCorrectPairsToValidation(correctPairs, stemIdToIndex, optionIdToInde
|
|
|
23354
23503
|
/**
|
|
23355
23504
|
* Convert matchInteraction to Learnosity choicematrix
|
|
23356
23505
|
*/
|
|
23357
|
-
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23506
|
+
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23358
23507
|
const parsed = readAssessmentItemMatch(inputXml);
|
|
23359
23508
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23360
23509
|
diagnostics.push(...updatedDiagnostics);
|
|
23361
23510
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23362
23511
|
if (!parsed.identifier || parsed.stems.length === 0 || parsed.options.length === 0) return { diagnostics };
|
|
23363
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23512
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23513
|
+
const transformContext = {
|
|
23514
|
+
finalItemReference: itemRef,
|
|
23515
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23516
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23517
|
+
};
|
|
23364
23518
|
const questionRef = md5hex(itemRef);
|
|
23365
23519
|
const stems = parsed.stems.map((stem) => transformAssetUrls(stem.text, {
|
|
23366
23520
|
organisationId,
|
|
23367
23521
|
mediaVault,
|
|
23368
|
-
customAssetUrl
|
|
23522
|
+
customAssetUrl,
|
|
23523
|
+
...transformContext
|
|
23369
23524
|
}));
|
|
23370
23525
|
const options = parsed.options.map((option) => transformAssetUrls(option.text, {
|
|
23371
23526
|
organisationId,
|
|
23372
23527
|
mediaVault,
|
|
23373
|
-
customAssetUrl
|
|
23528
|
+
customAssetUrl,
|
|
23529
|
+
...transformContext
|
|
23374
23530
|
}));
|
|
23375
23531
|
const stemIdToIndex = /* @__PURE__ */ new Map();
|
|
23376
23532
|
parsed.stems.forEach((stem, index) => {
|
|
@@ -23388,7 +23544,8 @@ function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId
|
|
|
23388
23544
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
23389
23545
|
organisationId,
|
|
23390
23546
|
mediaVault,
|
|
23391
|
-
customAssetUrl
|
|
23547
|
+
customAssetUrl,
|
|
23548
|
+
...transformContext
|
|
23392
23549
|
});
|
|
23393
23550
|
const item = {
|
|
23394
23551
|
item: {
|
|
@@ -23768,25 +23925,32 @@ function buildGapValidation(gaps, gapIdToGapTextIds, gapTextIdToContent, sourceF
|
|
|
23768
23925
|
/**
|
|
23769
23926
|
* Convert gapMatchInteraction to Learnosity clozeassociation
|
|
23770
23927
|
*/
|
|
23771
|
-
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23928
|
+
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23772
23929
|
const parsed = readAssessmentItemGapMatch(inputXml);
|
|
23773
23930
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23774
23931
|
diagnostics.push(...updatedDiagnostics);
|
|
23775
23932
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23776
23933
|
if (!parsed.identifier || parsed.gapTexts.length === 0 || parsed.gaps.length === 0) return { diagnostics };
|
|
23777
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23934
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23935
|
+
const transformContext = {
|
|
23936
|
+
finalItemReference: itemRef,
|
|
23937
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23938
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23939
|
+
};
|
|
23778
23940
|
const questionRef = md5hex(itemRef);
|
|
23779
23941
|
const possibleResponses = parsed.gapTexts.map((gt) => transformAssetUrls(gt.text, {
|
|
23780
23942
|
organisationId,
|
|
23781
23943
|
mediaVault,
|
|
23782
|
-
customAssetUrl
|
|
23944
|
+
customAssetUrl,
|
|
23945
|
+
...transformContext
|
|
23783
23946
|
}));
|
|
23784
23947
|
const gapTextIdToContent = /* @__PURE__ */ new Map();
|
|
23785
23948
|
parsed.gapTexts.forEach((gt) => {
|
|
23786
23949
|
const transformedText = transformAssetUrls(gt.text, {
|
|
23787
23950
|
organisationId,
|
|
23788
23951
|
mediaVault,
|
|
23789
|
-
customAssetUrl
|
|
23952
|
+
customAssetUrl,
|
|
23953
|
+
...transformContext
|
|
23790
23954
|
});
|
|
23791
23955
|
gapTextIdToContent.set(gt.identifier, transformedText);
|
|
23792
23956
|
});
|
|
@@ -23804,7 +23968,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23804
23968
|
template: transformAssetUrls(parsed.templateHtml ?? "", {
|
|
23805
23969
|
organisationId,
|
|
23806
23970
|
mediaVault,
|
|
23807
|
-
customAssetUrl
|
|
23971
|
+
customAssetUrl,
|
|
23972
|
+
...transformContext
|
|
23808
23973
|
}),
|
|
23809
23974
|
possible_responses: possibleResponses,
|
|
23810
23975
|
shuffle_options: parsed.shuffle ?? false,
|
|
@@ -23819,7 +23984,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23819
23984
|
if (parsed.promptHtml) questionData.stimulus = transformAssetUrls(parsed.promptHtml, {
|
|
23820
23985
|
organisationId,
|
|
23821
23986
|
mediaVault,
|
|
23822
|
-
customAssetUrl
|
|
23987
|
+
customAssetUrl,
|
|
23988
|
+
...transformContext
|
|
23823
23989
|
});
|
|
23824
23990
|
if (maxResponsesPerZone > 1) questionData.max_response_per_zone = maxResponsesPerZone;
|
|
23825
23991
|
const choiceCounts = /* @__PURE__ */ new Map();
|
|
@@ -24224,19 +24390,22 @@ function buildValidationValues(interactions, responseDeclarations, diagnostics,
|
|
|
24224
24390
|
* Convert inlineChoiceInteraction to Learnosity clozedropdown
|
|
24225
24391
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
24226
24392
|
*/
|
|
24227
|
-
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
24393
|
+
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
24228
24394
|
const parsed = readAssessmentItemInlineChoice(inputXml);
|
|
24229
24395
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24230
24396
|
diagnostics.push(...updatedDiagnostics);
|
|
24231
24397
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24232
24398
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
24233
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24234
|
-
const questionRef = md5hex(itemRef);
|
|
24399
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24235
24400
|
const transformOpts = {
|
|
24236
24401
|
organisationId,
|
|
24237
24402
|
mediaVault,
|
|
24238
|
-
customAssetUrl
|
|
24403
|
+
customAssetUrl,
|
|
24404
|
+
finalItemReference: itemRef,
|
|
24405
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24406
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24239
24407
|
};
|
|
24408
|
+
const questionRef = md5hex(itemRef);
|
|
24240
24409
|
const possibleResponses = parsed.interactions.map((interaction) => interaction.choices.map((choice) => transformAssetUrls(choice.text, transformOpts)));
|
|
24241
24410
|
const validationValue = buildValidationValues(parsed.interactions, parsed.responseDeclarations, diagnostics, transformOpts, sourceFile);
|
|
24242
24411
|
if (!validationValue) return { diagnostics };
|
|
@@ -24503,23 +24672,30 @@ function readAssessmentItemOrder(inputXml) {
|
|
|
24503
24672
|
/**
|
|
24504
24673
|
* Convert orderInteraction to Learnosity orderlist
|
|
24505
24674
|
*/
|
|
24506
|
-
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
24675
|
+
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
24507
24676
|
const parsed = readAssessmentItemOrder(inputXml);
|
|
24508
24677
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24509
24678
|
diagnostics.push(...updatedDiagnostics);
|
|
24510
24679
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24511
24680
|
if (!parsed.identifier || !parsed.responseIdentifier || parsed.choices.length === 0) return { diagnostics };
|
|
24512
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24681
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24682
|
+
const transformContext = {
|
|
24683
|
+
finalItemReference: itemRef,
|
|
24684
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24685
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24686
|
+
};
|
|
24513
24687
|
const questionRef = md5hex(itemRef);
|
|
24514
24688
|
const stimulus = transformAssetUrls(parsed.stimulusText ?? "", {
|
|
24515
24689
|
organisationId,
|
|
24516
24690
|
mediaVault,
|
|
24517
|
-
customAssetUrl
|
|
24691
|
+
customAssetUrl,
|
|
24692
|
+
...transformContext
|
|
24518
24693
|
});
|
|
24519
24694
|
const list = parsed.choices.map((choice) => transformAssetUrls(choice.text, {
|
|
24520
24695
|
organisationId,
|
|
24521
24696
|
mediaVault,
|
|
24522
|
-
customAssetUrl
|
|
24697
|
+
customAssetUrl,
|
|
24698
|
+
...transformContext
|
|
24523
24699
|
}));
|
|
24524
24700
|
let validationValue;
|
|
24525
24701
|
if (parsed.correctOrder && parsed.correctOrder.length > 0) {
|
|
@@ -24894,17 +25070,19 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics, sou
|
|
|
24894
25070
|
/**
|
|
24895
25071
|
* Build the combined stimulus HTML from parsed stimulusText and promptText
|
|
24896
25072
|
*/
|
|
24897
|
-
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
25073
|
+
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
24898
25074
|
let stimulus = "";
|
|
24899
25075
|
if (parsed.stimulusText) stimulus += transformAssetUrls(parsed.stimulusText, {
|
|
24900
25076
|
organisationId,
|
|
24901
25077
|
mediaVault,
|
|
24902
|
-
customAssetUrl
|
|
25078
|
+
customAssetUrl,
|
|
25079
|
+
...assetTransformContext
|
|
24903
25080
|
});
|
|
24904
25081
|
if (parsed.promptText) stimulus += `<p>${transformAssetUrls(parsed.promptText, {
|
|
24905
25082
|
organisationId,
|
|
24906
25083
|
mediaVault,
|
|
24907
|
-
customAssetUrl
|
|
25084
|
+
customAssetUrl,
|
|
25085
|
+
...assetTransformContext
|
|
24908
25086
|
})}</p>`;
|
|
24909
25087
|
return stimulus;
|
|
24910
25088
|
}
|
|
@@ -24929,7 +25107,7 @@ function buildHotspotValidation(correctResponses, choiceIdToIndex) {
|
|
|
24929
25107
|
/**
|
|
24930
25108
|
* Convert hotspotInteraction to Learnosity hotspot
|
|
24931
25109
|
*/
|
|
24932
|
-
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
25110
|
+
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
24933
25111
|
const parsed = readAssessmentItemHotspot(inputXml);
|
|
24934
25112
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24935
25113
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -24951,10 +25129,15 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
24951
25129
|
return { diagnostics };
|
|
24952
25130
|
}
|
|
24953
25131
|
}
|
|
24954
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25132
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25133
|
+
const transformContext = {
|
|
25134
|
+
finalItemReference: itemRef,
|
|
25135
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25136
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25137
|
+
};
|
|
24955
25138
|
const questionRef = md5hex(itemRef);
|
|
24956
|
-
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
24957
|
-
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl) : parsed.imageSource;
|
|
25139
|
+
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
25140
|
+
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.imageSource;
|
|
24958
25141
|
const areas = [];
|
|
24959
25142
|
const choiceIdToIndex = /* @__PURE__ */ new Map();
|
|
24960
25143
|
for (const choice of parsed.hotspotChoices) {
|
|
@@ -25237,14 +25420,19 @@ function readAssessmentItemHottext(inputXml) {
|
|
|
25237
25420
|
/**
|
|
25238
25421
|
* Convert hottextInteraction to Learnosity tokenhighlight
|
|
25239
25422
|
*/
|
|
25240
|
-
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
25423
|
+
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
25241
25424
|
const parsed = readAssessmentItemHottext(inputXml);
|
|
25242
25425
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
25243
25426
|
diagnostics.push(...updatedDiagnostics);
|
|
25244
25427
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
25245
25428
|
if (!parsed.identifier || !parsed.responseIdentifier || !parsed.templateHtml) return { diagnostics };
|
|
25246
25429
|
if (parsed.hottextElements.length === 0) return { diagnostics };
|
|
25247
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25430
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25431
|
+
const transformContext = {
|
|
25432
|
+
finalItemReference: itemRef,
|
|
25433
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25434
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25435
|
+
};
|
|
25248
25436
|
const questionRef = md5hex(itemRef);
|
|
25249
25437
|
if (parsed.shuffle) diagnostics.push({
|
|
25250
25438
|
code: DiagnosticCode.QTI_SHUFFLE_NOT_SUPPORTED,
|
|
@@ -25256,7 +25444,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25256
25444
|
if (stimulus) stimulus = transformAssetUrls(stimulus, {
|
|
25257
25445
|
organisationId,
|
|
25258
25446
|
mediaVault,
|
|
25259
|
-
customAssetUrl
|
|
25447
|
+
customAssetUrl,
|
|
25448
|
+
...transformContext
|
|
25260
25449
|
});
|
|
25261
25450
|
let template = parsed.templateHtml || "";
|
|
25262
25451
|
const identifierToIndex = /* @__PURE__ */ new Map();
|
|
@@ -25269,7 +25458,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25269
25458
|
template = transformAssetUrls(template, {
|
|
25270
25459
|
organisationId,
|
|
25271
25460
|
mediaVault,
|
|
25272
|
-
customAssetUrl
|
|
25461
|
+
customAssetUrl,
|
|
25462
|
+
...transformContext
|
|
25273
25463
|
});
|
|
25274
25464
|
let validation = void 0;
|
|
25275
25465
|
if (parsed.correctResponses && parsed.correctResponses.length > 0) {
|
|
@@ -25736,7 +25926,7 @@ function readAssessmentItemMcq(inputXml, stimulusOverride) {
|
|
|
25736
25926
|
* Supports both single and composite (multiple) choiceInteractions
|
|
25737
25927
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
25738
25928
|
*/
|
|
25739
|
-
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
25929
|
+
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
25740
25930
|
const parsed = readAssessmentItemMcq(inputXml, stimulusOverride);
|
|
25741
25931
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
25742
25932
|
...d,
|
|
@@ -25745,7 +25935,12 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25745
25935
|
diagnostics.push(...contextualDiagnostics);
|
|
25746
25936
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
25747
25937
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
25748
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25938
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25939
|
+
const transformContext = {
|
|
25940
|
+
finalItemReference: itemRef,
|
|
25941
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25942
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25943
|
+
};
|
|
25749
25944
|
const isComposite = parsed.interactions.length > 1;
|
|
25750
25945
|
const questions = [];
|
|
25751
25946
|
const widgets = [];
|
|
@@ -25755,7 +25950,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25755
25950
|
const stimulus = interaction.stimulusText ? transformAssetUrls(interaction.stimulusText, {
|
|
25756
25951
|
organisationId,
|
|
25757
25952
|
mediaVault,
|
|
25758
|
-
customAssetUrl
|
|
25953
|
+
customAssetUrl,
|
|
25954
|
+
...transformContext
|
|
25759
25955
|
}) : void 0;
|
|
25760
25956
|
const choiceMapping = /* @__PURE__ */ new Map();
|
|
25761
25957
|
const options = interaction.choices.map((choice) => {
|
|
@@ -25764,7 +25960,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25764
25960
|
label: transformAssetUrls(choice.text, {
|
|
25765
25961
|
organisationId,
|
|
25766
25962
|
mediaVault,
|
|
25767
|
-
customAssetUrl
|
|
25963
|
+
customAssetUrl,
|
|
25964
|
+
...transformContext
|
|
25768
25965
|
}),
|
|
25769
25966
|
value: choice.identifier
|
|
25770
25967
|
};
|
|
@@ -25801,7 +25998,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25801
25998
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
25802
25999
|
organisationId,
|
|
25803
26000
|
mediaVault,
|
|
25804
|
-
customAssetUrl
|
|
26001
|
+
customAssetUrl,
|
|
26002
|
+
...transformContext
|
|
25805
26003
|
}) : void 0;
|
|
25806
26004
|
questions.push({
|
|
25807
26005
|
reference: questionRef,
|
|
@@ -26169,7 +26367,7 @@ function stripWrapperDiv(html) {
|
|
|
26169
26367
|
* Convert textEntry (textEntryInteraction) to Learnosity clozetext or shorttext
|
|
26170
26368
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26171
26369
|
*/
|
|
26172
|
-
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26370
|
+
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26173
26371
|
const parsed = readAssessmentItemTextEntry(inputXml, stimulusOverride);
|
|
26174
26372
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
26175
26373
|
...d,
|
|
@@ -26179,24 +26377,31 @@ function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile
|
|
|
26179
26377
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
26180
26378
|
if (!parsed.identifier || parsed.textEntries.length === 0) return { diagnostics };
|
|
26181
26379
|
if (typeof parsed.templateText === "string") parsed.templateText = stripWrapperDiv(parsed.templateText);
|
|
26182
|
-
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26183
|
-
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26380
|
+
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26381
|
+
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26184
26382
|
}
|
|
26185
26383
|
/**
|
|
26186
26384
|
* Convert single textEntry to Learnosity shorttext
|
|
26187
26385
|
*/
|
|
26188
|
-
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26189
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26386
|
+
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26387
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26388
|
+
const transformContext = {
|
|
26389
|
+
finalItemReference: itemRef,
|
|
26390
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26391
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26392
|
+
};
|
|
26190
26393
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26191
26394
|
const stimulus = normalizeFinalText(transformAssetUrls((parsed.templateText || "").replace(/{{response}}(?:\s*<\/[^>]+>)*\s*$/, "").trim(), {
|
|
26192
26395
|
organisationId,
|
|
26193
26396
|
mediaVault,
|
|
26194
|
-
customAssetUrl
|
|
26397
|
+
customAssetUrl,
|
|
26398
|
+
...transformContext
|
|
26195
26399
|
}));
|
|
26196
26400
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26197
26401
|
organisationId,
|
|
26198
26402
|
mediaVault,
|
|
26199
|
-
customAssetUrl
|
|
26403
|
+
customAssetUrl,
|
|
26404
|
+
...transformContext
|
|
26200
26405
|
}) : void 0;
|
|
26201
26406
|
const entry = parsed.textEntries[0];
|
|
26202
26407
|
const correctResponses = entry.correctResponses || (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -26270,25 +26475,33 @@ function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisation
|
|
|
26270
26475
|
/**
|
|
26271
26476
|
* Convert textEntry with template to Learnosity clozetext
|
|
26272
26477
|
*/
|
|
26273
|
-
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26478
|
+
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26274
26479
|
const correctResponses = [];
|
|
26275
26480
|
for (const entry of parsed.textEntries) if (entry.correctResponse) correctResponses.push(entry.correctResponse);
|
|
26276
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26481
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26482
|
+
const transformContext = {
|
|
26483
|
+
finalItemReference: itemRef,
|
|
26484
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26485
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26486
|
+
};
|
|
26277
26487
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26278
26488
|
const stimulus = parsed.stimulusText ? normalizeFinalText(transformAssetUrls(parsed.stimulusText, {
|
|
26279
26489
|
organisationId,
|
|
26280
26490
|
mediaVault,
|
|
26281
|
-
customAssetUrl
|
|
26491
|
+
customAssetUrl,
|
|
26492
|
+
...transformContext
|
|
26282
26493
|
})) : void 0;
|
|
26283
26494
|
const template = normalizeFinalText(transformAssetUrls(parsed.templateText, {
|
|
26284
26495
|
organisationId,
|
|
26285
26496
|
mediaVault,
|
|
26286
|
-
customAssetUrl
|
|
26497
|
+
customAssetUrl,
|
|
26498
|
+
...transformContext
|
|
26287
26499
|
}));
|
|
26288
26500
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26289
26501
|
organisationId,
|
|
26290
26502
|
mediaVault,
|
|
26291
|
-
customAssetUrl
|
|
26503
|
+
customAssetUrl,
|
|
26504
|
+
...transformContext
|
|
26292
26505
|
}) : void 0;
|
|
26293
26506
|
const validation = {
|
|
26294
26507
|
scoring_type: "exactMatch",
|
|
@@ -26521,8 +26734,13 @@ function readAssessmentItemExtendedText(inputXml) {
|
|
|
26521
26734
|
/**
|
|
26522
26735
|
* Build multi-interaction extended text item (multiple longtextV2 questions)
|
|
26523
26736
|
*/
|
|
26524
|
-
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26525
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26737
|
+
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26738
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26739
|
+
const transformContext = {
|
|
26740
|
+
finalItemReference: itemRef,
|
|
26741
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26742
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26743
|
+
};
|
|
26526
26744
|
const questions = [];
|
|
26527
26745
|
const widgets = [];
|
|
26528
26746
|
const questionSpans = [];
|
|
@@ -26532,7 +26750,8 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
|
|
|
26532
26750
|
const stimulus = transformAssetUrls(stimulusOverride[i], {
|
|
26533
26751
|
organisationId,
|
|
26534
26752
|
mediaVault,
|
|
26535
|
-
customAssetUrl
|
|
26753
|
+
customAssetUrl,
|
|
26754
|
+
...transformContext
|
|
26536
26755
|
});
|
|
26537
26756
|
widgets.push({
|
|
26538
26757
|
reference: questionRef,
|
|
@@ -26582,19 +26801,25 @@ function extractResponseIdentifiers(inputXml, interactionTag) {
|
|
|
26582
26801
|
* Convert extended text (extendedTextInteraction) to Learnosity longtextV2
|
|
26583
26802
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26584
26803
|
*/
|
|
26585
|
-
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26804
|
+
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26586
26805
|
const parsed = readAssessmentItemExtendedText(inputXml);
|
|
26587
26806
|
const contextualDiagnostics = addFileContextIfProvided(stimulusOverride ? filterOutCodes(parsed.diagnostics, [DiagnosticCode.QTI_EXTENDED_TEXT_MULTIPLE_INTERACTIONS]) : parsed.diagnostics, sourceFile);
|
|
26588
26807
|
diagnostics.push(...contextualDiagnostics);
|
|
26589
26808
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
26590
|
-
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26591
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26809
|
+
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26810
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26811
|
+
const transformContext = {
|
|
26812
|
+
finalItemReference: itemRef,
|
|
26813
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26814
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26815
|
+
};
|
|
26592
26816
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier ?? "unknown");
|
|
26593
26817
|
const stimulusRaw = stimulusOverride && stimulusOverride.length === 1 ? stimulusOverride[0] : parsed.stimulusText;
|
|
26594
26818
|
const stimulus = stimulusRaw ? transformAssetUrls(stimulusRaw, {
|
|
26595
26819
|
organisationId,
|
|
26596
26820
|
mediaVault,
|
|
26597
|
-
customAssetUrl
|
|
26821
|
+
customAssetUrl,
|
|
26822
|
+
...transformContext
|
|
26598
26823
|
}) : void 0;
|
|
26599
26824
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26600
26825
|
organisationId,
|
|
@@ -26889,7 +27114,7 @@ function buildValidationValue$1(hotspots, correctPairs, gapImgIdToResponse) {
|
|
|
26889
27114
|
/**
|
|
26890
27115
|
* Convert QTI graphicGapMatchInteraction to Learnosity imageclozeassociationV2
|
|
26891
27116
|
*/
|
|
26892
|
-
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27117
|
+
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
26893
27118
|
const parsed = readAssessmentItemGraphicGapMatch(inputXml);
|
|
26894
27119
|
const contextualDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
26895
27120
|
diagnostics.push(...contextualDiagnostics);
|
|
@@ -26905,6 +27130,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26905
27130
|
}
|
|
26906
27131
|
const bgWidth = parsed.backgroundImage.width;
|
|
26907
27132
|
const bgHeight = parsed.backgroundImage.height;
|
|
27133
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27134
|
+
const transformContext = {
|
|
27135
|
+
finalItemReference: itemRef,
|
|
27136
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27137
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27138
|
+
};
|
|
26908
27139
|
const gapImgIdToResponse = /* @__PURE__ */ new Map();
|
|
26909
27140
|
const possible_responses = parsed.gapImages.map((g) => {
|
|
26910
27141
|
if (g.text !== void 0) {
|
|
@@ -26923,7 +27154,8 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26923
27154
|
const transformedImgTag = transformAssetUrls(imgTag, {
|
|
26924
27155
|
organisationId,
|
|
26925
27156
|
mediaVault,
|
|
26926
|
-
customAssetUrl
|
|
27157
|
+
customAssetUrl,
|
|
27158
|
+
...transformContext
|
|
26927
27159
|
});
|
|
26928
27160
|
gapImgIdToResponse.set(g.identifier, transformedImgTag);
|
|
26929
27161
|
return transformedImgTag;
|
|
@@ -26961,7 +27193,7 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26961
27193
|
const question = {
|
|
26962
27194
|
type: "imageclozeassociationV2",
|
|
26963
27195
|
image: {
|
|
26964
|
-
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl) : parsed.backgroundImage.src,
|
|
27196
|
+
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.backgroundImage.src,
|
|
26965
27197
|
width: bgWidth,
|
|
26966
27198
|
height: bgHeight
|
|
26967
27199
|
},
|
|
@@ -26985,11 +27217,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26985
27217
|
if (parsed.stimulus) question.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
26986
27218
|
organisationId,
|
|
26987
27219
|
mediaVault,
|
|
26988
|
-
customAssetUrl
|
|
27220
|
+
customAssetUrl,
|
|
27221
|
+
...transformContext
|
|
26989
27222
|
});
|
|
26990
27223
|
const item = {
|
|
26991
27224
|
item: {
|
|
26992
|
-
reference:
|
|
27225
|
+
reference: itemRef,
|
|
26993
27226
|
title: parsed.title ?? void 0,
|
|
26994
27227
|
definition: { widgets: [{
|
|
26995
27228
|
reference: questionRef,
|
|
@@ -27279,35 +27512,38 @@ const readAssessmentItemDrawing = createAssessmentItemReader({
|
|
|
27279
27512
|
/**
|
|
27280
27513
|
* Build drawing stimulus from parsed QTI data
|
|
27281
27514
|
*/
|
|
27282
|
-
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27515
|
+
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27283
27516
|
if (!parsed.stimulusText && !parsed.promptText) return;
|
|
27284
27517
|
const stimulus = parsed.promptText || parsed.stimulusText || "";
|
|
27285
27518
|
try {
|
|
27286
27519
|
return transformAssetUrls(stimulus, {
|
|
27287
27520
|
organisationId,
|
|
27288
27521
|
mediaVault,
|
|
27289
|
-
customAssetUrl
|
|
27522
|
+
customAssetUrl,
|
|
27523
|
+
...assetTransformContext
|
|
27290
27524
|
});
|
|
27291
|
-
} catch {
|
|
27525
|
+
} catch (error) {
|
|
27526
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27292
27527
|
return stimulus;
|
|
27293
27528
|
}
|
|
27294
27529
|
}
|
|
27295
27530
|
/**
|
|
27296
27531
|
* Transform a single image source URL
|
|
27297
27532
|
*/
|
|
27298
|
-
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl) {
|
|
27533
|
+
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27299
27534
|
try {
|
|
27300
|
-
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl) : imageSource;
|
|
27301
|
-
} catch {
|
|
27535
|
+
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) : imageSource;
|
|
27536
|
+
} catch (error) {
|
|
27537
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27302
27538
|
return imageSource;
|
|
27303
27539
|
}
|
|
27304
27540
|
}
|
|
27305
27541
|
/**
|
|
27306
27542
|
* Build drawing image data from parsed QTI data
|
|
27307
27543
|
*/
|
|
27308
|
-
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27544
|
+
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27309
27545
|
if (!parsed.imageSource) return;
|
|
27310
|
-
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl) };
|
|
27546
|
+
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) };
|
|
27311
27547
|
if (parsed.imageWidth) image.width = parsed.imageWidth;
|
|
27312
27548
|
if (parsed.imageHeight) image.height = parsed.imageHeight;
|
|
27313
27549
|
if (parsed.imageAlt) image.alt = parsed.imageAlt;
|
|
@@ -27316,21 +27552,27 @@ function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
|
27316
27552
|
/**
|
|
27317
27553
|
* Convert QTI drawingInteraction to Learnosity drawing question
|
|
27318
27554
|
*/
|
|
27319
|
-
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27555
|
+
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27320
27556
|
const parsed = readAssessmentItemDrawing(inputXml);
|
|
27321
27557
|
diagnostics.push(...parsed.diagnostics);
|
|
27322
27558
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
27323
|
-
const
|
|
27559
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27560
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
27561
|
+
const transformContext = {
|
|
27562
|
+
finalItemReference: itemRef,
|
|
27563
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27564
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27565
|
+
};
|
|
27324
27566
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "drawing"));
|
|
27325
27567
|
const questionData = { type: "drawing" };
|
|
27326
|
-
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27568
|
+
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27327
27569
|
if (stimulus !== void 0) questionData.stimulus = stimulus;
|
|
27328
|
-
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27570
|
+
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27329
27571
|
if (image) questionData.image = image;
|
|
27330
27572
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
27331
27573
|
const item = {
|
|
27332
27574
|
item: {
|
|
27333
|
-
reference:
|
|
27575
|
+
reference: itemRef,
|
|
27334
27576
|
title: parsed.title ?? void 0,
|
|
27335
27577
|
content,
|
|
27336
27578
|
definition: { widgets: [{
|
|
@@ -27620,7 +27862,7 @@ function buildValidationValue(choices, correctPairs, diagnostics, sourceFile) {
|
|
|
27620
27862
|
* This reflects the undirected-pair nature of associateInteraction: no choice is
|
|
27621
27863
|
* inherently a "category" or a "draggable" — both sides of a pair are equivalent.
|
|
27622
27864
|
*/
|
|
27623
|
-
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27865
|
+
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27624
27866
|
const parsed = readAssessmentItemAssociation(inputXml);
|
|
27625
27867
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
27626
27868
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -27628,17 +27870,24 @@ function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisa
|
|
|
27628
27870
|
if (!parsed.identifier || parsed.choices.length === 0) return { diagnostics };
|
|
27629
27871
|
const validationValue = buildValidationValue(parsed.choices, parsed.correctPairs, diagnostics, sourceFile);
|
|
27630
27872
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
27631
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27873
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27874
|
+
const transformContext = {
|
|
27875
|
+
finalItemReference: itemRef,
|
|
27876
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27877
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27878
|
+
};
|
|
27632
27879
|
const questionRef = md5hex(itemRef);
|
|
27633
27880
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
27634
27881
|
organisationId,
|
|
27635
27882
|
mediaVault,
|
|
27636
|
-
customAssetUrl
|
|
27883
|
+
customAssetUrl,
|
|
27884
|
+
...transformContext
|
|
27637
27885
|
});
|
|
27638
27886
|
const possibleResponses = parsed.choices.map((c) => transformAssetUrls(c.text, {
|
|
27639
27887
|
organisationId,
|
|
27640
27888
|
mediaVault,
|
|
27641
|
-
customAssetUrl
|
|
27889
|
+
customAssetUrl,
|
|
27890
|
+
...transformContext
|
|
27642
27891
|
}));
|
|
27643
27892
|
const pairCount = validationValue.length > 0 ? validationValue.length : Math.round(parsed.maxAssociations ?? parsed.choices.length / 2);
|
|
27644
27893
|
const columnHeaders = Array.from({ length: pairCount }, (_, i) => `Pair ${i + 1}`);
|
|
@@ -28054,8 +28303,8 @@ function computeClosingTags(html) {
|
|
|
28054
28303
|
* Converters with different parameter orders are wrapped to normalize the signature.
|
|
28055
28304
|
*/
|
|
28056
28305
|
function getConverterMap() {
|
|
28057
|
-
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli);
|
|
28058
|
-
const hotspotConverter = (xml, diag, tags, orgId, sf, mv, cau, irs, _stimuli, fileAccess, packageRoot) => convertHotspotToLearnosity(xml, diag, tags, orgId, sf, mv, cau, irs, fileAccess, packageRoot);
|
|
28306
|
+
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli, assetTransformContext) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli, assetTransformContext);
|
|
28307
|
+
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);
|
|
28059
28308
|
return {
|
|
28060
28309
|
choiceInteraction: wrapSourceFirst(convertMcqToLearnosity),
|
|
28061
28310
|
textEntryInteraction: wrapSourceFirst(convertTextEntryToLearnosity),
|
|
@@ -28078,8 +28327,14 @@ const CONVERTER_MAP = getConverterMap();
|
|
|
28078
28327
|
* Strategy: Call each individual converter for its interaction type,
|
|
28079
28328
|
* then combine all questions and widgets into a single composite item
|
|
28080
28329
|
*/
|
|
28081
|
-
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
28330
|
+
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
28082
28331
|
const metadata = extractItemMetadata(inputXml);
|
|
28332
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(metadata.identifier ?? "mixed_item", itemReferenceSource, sourceFile);
|
|
28333
|
+
const transformContext = {
|
|
28334
|
+
finalItemReference: itemRef,
|
|
28335
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28336
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28337
|
+
};
|
|
28083
28338
|
const { segments } = segmentItemBodyByInteractions(inputXml);
|
|
28084
28339
|
const stimuliByType = /* @__PURE__ */ new Map();
|
|
28085
28340
|
for (const segment of segments) {
|
|
@@ -28161,7 +28416,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28161
28416
|
const template = normalizeFinalText(transformAssetUrls(rawTemplate, {
|
|
28162
28417
|
organisationId,
|
|
28163
28418
|
mediaVault,
|
|
28164
|
-
customAssetUrl
|
|
28419
|
+
customAssetUrl,
|
|
28420
|
+
...transformContext
|
|
28165
28421
|
}));
|
|
28166
28422
|
if (groupEntries.length === 1 && /{{response}}(?:<\/[^>]+>|\s)*$/.test(rawTemplate.trim())) {
|
|
28167
28423
|
let stimulusRaw = rawTemplate.replace(/{{response}}(?:<\/[^>]+>|\s)*$/, "").trim();
|
|
@@ -28169,7 +28425,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28169
28425
|
const stimulus = normalizeFinalText(transformAssetUrls(stimulusRaw, {
|
|
28170
28426
|
organisationId,
|
|
28171
28427
|
mediaVault,
|
|
28172
|
-
customAssetUrl
|
|
28428
|
+
customAssetUrl,
|
|
28429
|
+
...transformContext
|
|
28173
28430
|
}));
|
|
28174
28431
|
const entry = groupEntries[0];
|
|
28175
28432
|
const allCorrectResponses = entry.correctResponses ?? (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -28295,7 +28552,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28295
28552
|
continue;
|
|
28296
28553
|
}
|
|
28297
28554
|
const converter = CONVERTER_MAP[group.type];
|
|
28298
|
-
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, fileAccess, packageRoot), subDiagnostics);
|
|
28555
|
+
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, transformContext, fileAccess, packageRoot), subDiagnostics);
|
|
28299
28556
|
}
|
|
28300
28557
|
if (allQuestions.length === 0) {
|
|
28301
28558
|
diagnostics.push({
|
|
@@ -28318,9 +28575,16 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28318
28575
|
passageContent = transformAssetUrls(rawContent, {
|
|
28319
28576
|
organisationId,
|
|
28320
28577
|
mediaVault,
|
|
28321
|
-
customAssetUrl
|
|
28578
|
+
customAssetUrl,
|
|
28579
|
+
...transformContext
|
|
28580
|
+
});
|
|
28581
|
+
} catch (error) {
|
|
28582
|
+
if (isUnsafeQtiAssetHrefError(error)) diagnostics.push({
|
|
28583
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
28584
|
+
level: "error",
|
|
28585
|
+
file: sourceFile ?? "passage",
|
|
28586
|
+
message: error.message
|
|
28322
28587
|
});
|
|
28323
|
-
} catch {
|
|
28324
28588
|
passageContent = rawContent;
|
|
28325
28589
|
}
|
|
28326
28590
|
allFeatures.push({
|
|
@@ -28352,7 +28616,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28352
28616
|
const content = `<div class="row"><div class="col-xs-12">${[...featureSpans, ...questionSpans].join("")}</div></div>`;
|
|
28353
28617
|
const item = {
|
|
28354
28618
|
item: {
|
|
28355
|
-
reference:
|
|
28619
|
+
reference: itemRef,
|
|
28356
28620
|
title: metadata.title ?? void 0,
|
|
28357
28621
|
content,
|
|
28358
28622
|
definition: { widgets: allWidgets },
|
|
@@ -28398,8 +28662,13 @@ function resolvePassageObjects(html, sourceFile, resolvePassageFile) {
|
|
|
28398
28662
|
/**
|
|
28399
28663
|
* Convert passage-only item to Learnosity format with sharedpassage feature
|
|
28400
28664
|
*/
|
|
28401
|
-
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess) {
|
|
28402
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28665
|
+
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, assetTransformContext) {
|
|
28666
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28667
|
+
const transformContext = {
|
|
28668
|
+
finalItemReference: itemRef,
|
|
28669
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28670
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28671
|
+
};
|
|
28403
28672
|
const featureRef = `passage-${md5hex(getPassageDataPath(parsed.content) ?? itemRef).substring(0, 8)}`;
|
|
28404
28673
|
const resolvedContent = resolvePassageObjects(parsed.content, sourceFile, fileAccess?.resolvePassageFile.bind(fileAccess));
|
|
28405
28674
|
let content;
|
|
@@ -28407,11 +28676,12 @@ function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId
|
|
|
28407
28676
|
content = transformAssetUrls(resolvedContent, {
|
|
28408
28677
|
organisationId,
|
|
28409
28678
|
mediaVault,
|
|
28410
|
-
customAssetUrl
|
|
28679
|
+
customAssetUrl,
|
|
28680
|
+
...transformContext
|
|
28411
28681
|
});
|
|
28412
28682
|
} catch (error) {
|
|
28413
28683
|
diagnostics.push({
|
|
28414
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28684
|
+
code: isUnsafeQtiAssetHrefError(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28415
28685
|
level: "error",
|
|
28416
28686
|
file: sourceFile ?? "assessmentItem",
|
|
28417
28687
|
message: error instanceof Error ? error.message : "Failed to transform asset URLs"
|
|
@@ -28801,20 +29071,28 @@ function readAssessmentItemUpload(inputXml) {
|
|
|
28801
29071
|
* and the file limit from `maxChoices` (see readAssessmentItemUpload / the
|
|
28802
29072
|
* serializer). fileupload questions are unscored, so there is no validation.
|
|
28803
29073
|
*/
|
|
28804
|
-
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
29074
|
+
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
28805
29075
|
const parsed = readAssessmentItemUpload(inputXml);
|
|
28806
29076
|
diagnostics.push(...parsed.diagnostics);
|
|
28807
29077
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
28808
|
-
const
|
|
29078
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
29079
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
29080
|
+
const transformContext = {
|
|
29081
|
+
finalItemReference: itemRef,
|
|
29082
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
29083
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
29084
|
+
};
|
|
28809
29085
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "fileupload"));
|
|
28810
29086
|
const questionData = { type: "fileupload" };
|
|
28811
29087
|
if (parsed.stimulus) try {
|
|
28812
29088
|
questionData.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
28813
29089
|
organisationId,
|
|
28814
29090
|
mediaVault,
|
|
28815
|
-
customAssetUrl
|
|
29091
|
+
customAssetUrl,
|
|
29092
|
+
...transformContext
|
|
28816
29093
|
});
|
|
28817
|
-
} catch {
|
|
29094
|
+
} catch (error) {
|
|
29095
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
28818
29096
|
questionData.stimulus = parsed.stimulus;
|
|
28819
29097
|
}
|
|
28820
29098
|
for (const suffix of parsed.allowedFileTypes) questionData[`allow_${suffix}`] = true;
|
|
@@ -28822,7 +29100,7 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28822
29100
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
28823
29101
|
const item = {
|
|
28824
29102
|
item: {
|
|
28825
|
-
reference:
|
|
29103
|
+
reference: itemRef,
|
|
28826
29104
|
title: parsed.title ?? void 0,
|
|
28827
29105
|
content,
|
|
28828
29106
|
definition: { widgets: [{
|
|
@@ -28857,9 +29135,19 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28857
29135
|
* - Rejects DOCTYPE / ENTITY declarations up-front (DTD not allowed).
|
|
28858
29136
|
* - Uses streaming parsers for all interaction types.
|
|
28859
29137
|
*/
|
|
29138
|
+
function getAssetSourceHrefBase(opts) {
|
|
29139
|
+
if (opts.sourceHrefBase) return opts.sourceHrefBase;
|
|
29140
|
+
const source = opts.sourceFile ?? opts.inputPath;
|
|
29141
|
+
if (!source) return;
|
|
29142
|
+
const normalized = source.replaceAll("\\", "/");
|
|
29143
|
+
return normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(normalized) ? normalized.slice(normalized.lastIndexOf("/") + 1) : normalized;
|
|
29144
|
+
}
|
|
28860
29145
|
/**
|
|
28861
29146
|
* Supported interaction type names for counting
|
|
28862
29147
|
*/
|
|
29148
|
+
function isUnsafeAssetHrefError$1(error) {
|
|
29149
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
29150
|
+
}
|
|
28863
29151
|
const INTERACTION_NAMES = [
|
|
28864
29152
|
"choiceInteraction",
|
|
28865
29153
|
"textEntryInteraction",
|
|
@@ -28925,19 +29213,71 @@ function countAllInteractions(xml) {
|
|
|
28925
29213
|
};
|
|
28926
29214
|
}
|
|
28927
29215
|
const SINGLE_INTERACTION_CONVERTERS = /* @__PURE__ */ new Map([
|
|
28928
|
-
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim
|
|
28929
|
-
|
|
28930
|
-
|
|
28931
|
-
|
|
28932
|
-
|
|
28933
|
-
["
|
|
28934
|
-
|
|
28935
|
-
|
|
28936
|
-
|
|
28937
|
-
|
|
28938
|
-
["
|
|
28939
|
-
|
|
28940
|
-
|
|
29216
|
+
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29217
|
+
finalItemReference: opts.finalItemReference,
|
|
29218
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29219
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29220
|
+
})],
|
|
29221
|
+
["textEntryInteraction", (xml, diag, lom, opts, stim) => convertTextEntryToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29222
|
+
finalItemReference: opts.finalItemReference,
|
|
29223
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29224
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29225
|
+
})],
|
|
29226
|
+
["extendedTextInteraction", (xml, diag, lom, opts, stim) => convertExtendedTextToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29227
|
+
finalItemReference: opts.finalItemReference,
|
|
29228
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29229
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29230
|
+
})],
|
|
29231
|
+
["inlineChoiceInteraction", (xml, diag, lom, opts) => convertInlineChoiceToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29232
|
+
finalItemReference: opts.finalItemReference,
|
|
29233
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29234
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29235
|
+
})],
|
|
29236
|
+
["matchInteraction", (xml, diag, lom, opts) => convertMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29237
|
+
finalItemReference: opts.finalItemReference,
|
|
29238
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29239
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29240
|
+
})],
|
|
29241
|
+
["gapMatchInteraction", (xml, diag, lom, opts) => convertGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29242
|
+
finalItemReference: opts.finalItemReference,
|
|
29243
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29244
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29245
|
+
})],
|
|
29246
|
+
["orderInteraction", (xml, diag, lom, opts) => convertOrderToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29247
|
+
finalItemReference: opts.finalItemReference,
|
|
29248
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29249
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29250
|
+
})],
|
|
29251
|
+
["hotspotInteraction", (xml, diag, lom, opts) => convertHotspotToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29252
|
+
finalItemReference: opts.finalItemReference,
|
|
29253
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29254
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29255
|
+
})],
|
|
29256
|
+
["hottextInteraction", (xml, diag, lom, opts) => convertHottextToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29257
|
+
finalItemReference: opts.finalItemReference,
|
|
29258
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29259
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29260
|
+
})],
|
|
29261
|
+
["graphicGapMatchInteraction", (xml, diag, lom, opts) => convertGraphicGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29262
|
+
finalItemReference: opts.finalItemReference,
|
|
29263
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29264
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29265
|
+
})],
|
|
29266
|
+
["drawingInteraction", (xml, diag, lom, opts) => convertDrawingToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29267
|
+
finalItemReference: opts.finalItemReference,
|
|
29268
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29269
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29270
|
+
})],
|
|
29271
|
+
["associateInteraction", (xml, diag, lom, opts) => convertAssociationToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29272
|
+
finalItemReference: opts.finalItemReference,
|
|
29273
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29274
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29275
|
+
})],
|
|
29276
|
+
["uploadInteraction", (xml, diag, lom, opts) => convertUploadToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29277
|
+
finalItemReference: opts.finalItemReference,
|
|
29278
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29279
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29280
|
+
})]
|
|
28941
29281
|
]);
|
|
28942
29282
|
/**
|
|
28943
29283
|
* Dispatch to the appropriate single-interaction converter
|
|
@@ -28963,9 +29303,18 @@ function dispatchSingleInteractionConverter(interactionType, inputXml, count, di
|
|
|
28963
29303
|
passageContent = transformAssetUrls(rawContent, {
|
|
28964
29304
|
organisationId: opts.organisationId,
|
|
28965
29305
|
mediaVault: opts.mediaVault,
|
|
28966
|
-
customAssetUrl: opts.customAssetUrl
|
|
29306
|
+
customAssetUrl: opts.customAssetUrl,
|
|
29307
|
+
finalItemReference: opts.finalItemReference ?? result.item.item.reference,
|
|
29308
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29309
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29310
|
+
});
|
|
29311
|
+
} catch (error) {
|
|
29312
|
+
if (isUnsafeAssetHrefError$1(error)) diagnostics.push({
|
|
29313
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
29314
|
+
level: "error",
|
|
29315
|
+
file: opts.sourceFile ?? "passage",
|
|
29316
|
+
message: error.message
|
|
28967
29317
|
});
|
|
28968
|
-
} catch {
|
|
28969
29318
|
passageContent = rawContent;
|
|
28970
29319
|
}
|
|
28971
29320
|
result.item.features = [...result.item.features, {
|
|
@@ -29013,8 +29362,16 @@ function handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, o
|
|
|
29013
29362
|
}
|
|
29014
29363
|
const passageResult = readAssessmentItemPassage(inputXml);
|
|
29015
29364
|
diagnostics.push(...addFileContextIfProvided(passageResult.diagnostics, opts.sourceFile));
|
|
29016
|
-
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess
|
|
29017
|
-
|
|
29365
|
+
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, {
|
|
29366
|
+
finalItemReference: opts.finalItemReference,
|
|
29367
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29368
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29369
|
+
});
|
|
29370
|
+
const mcqResult = convertMcqToLearnosity(inputXml, diagnostics, lomTags, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29371
|
+
finalItemReference: opts.finalItemReference,
|
|
29372
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29373
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29374
|
+
});
|
|
29018
29375
|
if (diagnostics.some((d) => d.code === DiagnosticCode.LRN_SCHEMA_INVALID)) return mcqResult;
|
|
29019
29376
|
return { diagnostics };
|
|
29020
29377
|
}
|
|
@@ -29060,14 +29417,18 @@ function convertQtiAssessmentItemToLearnosity(inputXml, opts = {}) {
|
|
|
29060
29417
|
const { counts, allInteractions } = countAllInteractions(inputXml);
|
|
29061
29418
|
const presentTypes = INTERACTION_NAMES.filter((name) => counts[name] > 0);
|
|
29062
29419
|
if (presentTypes.reduce((sum, name) => sum + counts[name], 0) === 0) return handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, opts);
|
|
29063
|
-
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot
|
|
29420
|
+
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29421
|
+
finalItemReference: opts.finalItemReference,
|
|
29422
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29423
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29424
|
+
});
|
|
29064
29425
|
return dispatchSingleInteractionConverter(presentTypes[0], inputXml, counts[presentTypes[0]], diagnostics, lomTags, opts);
|
|
29065
29426
|
} catch (error) {
|
|
29066
29427
|
diagnostics.push({
|
|
29067
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29428
|
+
code: isUnsafeAssetHrefError$1(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29068
29429
|
level: "error",
|
|
29069
|
-
file: "root",
|
|
29070
|
-
message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29430
|
+
file: opts.sourceFile ?? "root",
|
|
29431
|
+
message: isUnsafeAssetHrefError$1(error) ? error.message : `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29071
29432
|
});
|
|
29072
29433
|
return { diagnostics };
|
|
29073
29434
|
}
|
|
@@ -29180,9 +29541,11 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29180
29541
|
const result = convertQtiAssessmentItemToLearnosity(input, {
|
|
29181
29542
|
qtiVersion: opts.qtiVersion,
|
|
29182
29543
|
inputPath: opts.inputPath,
|
|
29544
|
+
sourceFile: opts.inputPath,
|
|
29183
29545
|
organisationId: opts.organisationId,
|
|
29184
29546
|
mediaVault: opts.mediaVault,
|
|
29185
29547
|
customAssetUrl: opts.customAssetUrl,
|
|
29548
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29186
29549
|
itemReferenceSource: opts.itemReferenceSource,
|
|
29187
29550
|
fileAccess: opts.fileAccess
|
|
29188
29551
|
});
|
|
@@ -30876,6 +31239,108 @@ function unzipToEntries(bytes, sourceLabel, options) {
|
|
|
30876
31239
|
};
|
|
30877
31240
|
}
|
|
30878
31241
|
//#endregion
|
|
31242
|
+
//#region src/qti-to-learnosity/utils/assetFilenameRegistry.ts
|
|
31243
|
+
/**
|
|
31244
|
+
* Browser-safe registry for item-scoped QTI asset filenames.
|
|
31245
|
+
*
|
|
31246
|
+
* Filename selection belongs to asset identity, not package traversal. Keeping
|
|
31247
|
+
* both identity and filename indexes here lets URL and bundle seams validate
|
|
31248
|
+
* the same contract before either one can overwrite a physical asset.
|
|
31249
|
+
*/
|
|
31250
|
+
var AssetFilenameConflictError = class extends Error {
|
|
31251
|
+
kind;
|
|
31252
|
+
mode;
|
|
31253
|
+
filename;
|
|
31254
|
+
existing;
|
|
31255
|
+
incoming;
|
|
31256
|
+
constructor(kind, mode, filename, existing, incoming) {
|
|
31257
|
+
const existingIdentity = existing.serializedIdentity;
|
|
31258
|
+
const incomingIdentity = incoming.serializedIdentity;
|
|
31259
|
+
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}.`;
|
|
31260
|
+
super(message);
|
|
31261
|
+
this.name = "AssetFilenameConflictError";
|
|
31262
|
+
this.kind = kind;
|
|
31263
|
+
this.mode = mode;
|
|
31264
|
+
this.filename = filename;
|
|
31265
|
+
this.existing = existing;
|
|
31266
|
+
this.incoming = incoming;
|
|
31267
|
+
}
|
|
31268
|
+
};
|
|
31269
|
+
function bytesEqual(left, right) {
|
|
31270
|
+
if (left.length !== right.length) return false;
|
|
31271
|
+
for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
|
|
31272
|
+
return true;
|
|
31273
|
+
}
|
|
31274
|
+
function cloneBytes(bytes) {
|
|
31275
|
+
return new Uint8Array(bytes);
|
|
31276
|
+
}
|
|
31277
|
+
/**
|
|
31278
|
+
* Track selected asset names and their bytes for one conversion.
|
|
31279
|
+
*
|
|
31280
|
+
* Registering an equivalent identity repeatedly is idempotent when its bytes
|
|
31281
|
+
* agree. A filename can never silently change owners, and an identity can
|
|
31282
|
+
* never silently change bytes, in either hashed or preserve mode.
|
|
31283
|
+
*/
|
|
31284
|
+
var AssetFilenameRegistry = class {
|
|
31285
|
+
preserveAssetFilenames;
|
|
31286
|
+
byIdentity = /* @__PURE__ */ new Map();
|
|
31287
|
+
byFilename = /* @__PURE__ */ new Map();
|
|
31288
|
+
constructor(preserveAssetFilenames = false) {
|
|
31289
|
+
this.preserveAssetFilenames = preserveAssetFilenames;
|
|
31290
|
+
}
|
|
31291
|
+
get mode() {
|
|
31292
|
+
return this.preserveAssetFilenames ? "preserve" : "hashed";
|
|
31293
|
+
}
|
|
31294
|
+
get size() {
|
|
31295
|
+
return this.byIdentity.size;
|
|
31296
|
+
}
|
|
31297
|
+
/**
|
|
31298
|
+
* Register an asset and return its selected filename and bytes.
|
|
31299
|
+
*
|
|
31300
|
+
* The input href is canonicalized before both indexes are consulted, so
|
|
31301
|
+
* equivalent directory and ZIP representations reuse one registration.
|
|
31302
|
+
*/
|
|
31303
|
+
register(finalItemReference, qtiAssetHref, bytes) {
|
|
31304
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
31305
|
+
const serializedIdentity = serializeQtiAssetIdentity(finalItemReference, canonicalHref);
|
|
31306
|
+
const filename = selectQtiAssetFilename(finalItemReference, canonicalHref, this.preserveAssetFilenames);
|
|
31307
|
+
const incoming = {
|
|
31308
|
+
finalItemReference,
|
|
31309
|
+
qtiAssetHref: canonicalHref,
|
|
31310
|
+
serializedIdentity,
|
|
31311
|
+
filename,
|
|
31312
|
+
bytes: cloneBytes(bytes)
|
|
31313
|
+
};
|
|
31314
|
+
const existingIdentity = this.byIdentity.get(serializedIdentity);
|
|
31315
|
+
if (existingIdentity) {
|
|
31316
|
+
if (!bytesEqual(existingIdentity.bytes, incoming.bytes)) throw new AssetFilenameConflictError("identity-bytes", this.mode, filename, existingIdentity, incoming);
|
|
31317
|
+
return existingIdentity;
|
|
31318
|
+
}
|
|
31319
|
+
const existingFilename = this.byFilename.get(filename);
|
|
31320
|
+
if (existingFilename) throw new AssetFilenameConflictError("filename-identity", this.mode, filename, existingFilename, incoming);
|
|
31321
|
+
this.byIdentity.set(serializedIdentity, incoming);
|
|
31322
|
+
this.byFilename.set(filename, incoming);
|
|
31323
|
+
return incoming;
|
|
31324
|
+
}
|
|
31325
|
+
/** Look up a previously registered canonical identity without registering it. */
|
|
31326
|
+
get(finalItemReference, qtiAssetHref) {
|
|
31327
|
+
return this.byIdentity.get(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
31328
|
+
}
|
|
31329
|
+
/** Look up an asset by its selected bundle-relative filename. */
|
|
31330
|
+
getByFilename(filename) {
|
|
31331
|
+
return this.byFilename.get(filename);
|
|
31332
|
+
}
|
|
31333
|
+
/** Iterate registrations in deterministic registration order. */
|
|
31334
|
+
entries() {
|
|
31335
|
+
return this.byIdentity.values();
|
|
31336
|
+
}
|
|
31337
|
+
/** Remove all registrations so the registry can be reused for a new conversion. */
|
|
31338
|
+
clear() {
|
|
31339
|
+
this.byIdentity.clear();
|
|
31340
|
+
this.byFilename.clear();
|
|
31341
|
+
}
|
|
31342
|
+
};
|
|
31343
|
+
//#endregion
|
|
30879
31344
|
//#region src/qti-to-learnosity/convertQtiPackageToLearnosityBundle.ts
|
|
30880
31345
|
/**
|
|
30881
31346
|
* QTI Content Package → Learnosity Bundle converter (v1)
|
|
@@ -30889,6 +31354,15 @@ function unzipToEntries(bytes, sourceLabel, options) {
|
|
|
30889
31354
|
* - Does not write outputs if any error diagnostics exist
|
|
30890
31355
|
* - Deterministic ordering and stable JSON serialization
|
|
30891
31356
|
*/
|
|
31357
|
+
/**
|
|
31358
|
+
* Normalize an item reference / filename source for comparison and defaulting.
|
|
31359
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`, and an omitted value
|
|
31360
|
+
* defaults to `'itemIdentifier'`.
|
|
31361
|
+
*/
|
|
31362
|
+
function normalizeRefSource(source) {
|
|
31363
|
+
if (source === "qti" || source === void 0) return "itemIdentifier";
|
|
31364
|
+
return source;
|
|
31365
|
+
}
|
|
30892
31366
|
const utf8Decoder = new TextDecoder();
|
|
30893
31367
|
/** Decode entry bytes as UTF-8 (works for both Uint8Array and Node Buffer). */
|
|
30894
31368
|
function decodeUtf8(data) {
|
|
@@ -30923,57 +31397,80 @@ function ensureFailedItemDiagnostic(itemDiagnostics, href) {
|
|
|
30923
31397
|
}];
|
|
30924
31398
|
}
|
|
30925
31399
|
/**
|
|
30926
|
-
* Normalize a forward-slash relative path (collapse `.`/`//`, resolve `..`).
|
|
30927
|
-
* Pure replacement for `node:path`'s `normalize(...).split(sep).join('/')` on
|
|
30928
|
-
* the forward-slash paths used as entry keys.
|
|
30929
|
-
*/
|
|
30930
|
-
function normalizePosix(p) {
|
|
30931
|
-
const parts = [];
|
|
30932
|
-
for (const seg of p.split("/")) {
|
|
30933
|
-
if (seg === "" || seg === ".") continue;
|
|
30934
|
-
if (seg === "..") {
|
|
30935
|
-
parts.pop();
|
|
30936
|
-
continue;
|
|
30937
|
-
}
|
|
30938
|
-
parts.push(seg);
|
|
30939
|
-
}
|
|
30940
|
-
return parts.join("/");
|
|
30941
|
-
}
|
|
30942
|
-
/**
|
|
30943
31400
|
* Normalize href path by removing leading ./ sequences
|
|
30944
31401
|
* This ensures manifest hrefs like "./items/foo.xml" match entries stored as "items/foo.xml"
|
|
30945
31402
|
*/
|
|
30946
31403
|
function normalizeHref(href) {
|
|
30947
31404
|
return href.replace(/^(\.\/)+/, "");
|
|
30948
31405
|
}
|
|
30949
|
-
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
|
|
30953
|
-
|
|
30954
|
-
|
|
30955
|
-
|
|
30956
|
-
|
|
30957
|
-
|
|
30958
|
-
|
|
30959
|
-
|
|
30960
|
-
|
|
30961
|
-
|
|
30962
|
-
|
|
30963
|
-
|
|
30964
|
-
|
|
30965
|
-
|
|
30966
|
-
|
|
30967
|
-
|
|
30968
|
-
|
|
30969
|
-
|
|
30970
|
-
|
|
30971
|
-
|
|
30972
|
-
|
|
30973
|
-
".
|
|
30974
|
-
|
|
30975
|
-
|
|
30976
|
-
|
|
31406
|
+
function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
31407
|
+
let identifier = fallback;
|
|
31408
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31409
|
+
parser.on("opentag", (tag) => {
|
|
31410
|
+
if ((tag.local ?? tag.name) === "assessmentItem") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31411
|
+
});
|
|
31412
|
+
try {
|
|
31413
|
+
parser.write(inputXml).close();
|
|
31414
|
+
} catch {}
|
|
31415
|
+
return identifier;
|
|
31416
|
+
}
|
|
31417
|
+
function readAssessmentTestIdentifier(inputXml, fallback) {
|
|
31418
|
+
let identifier = fallback;
|
|
31419
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31420
|
+
parser.on("opentag", (tag) => {
|
|
31421
|
+
if ((tag.local ?? tag.name) === "assessmentTest") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31422
|
+
});
|
|
31423
|
+
try {
|
|
31424
|
+
parser.write(inputXml).close();
|
|
31425
|
+
} catch {}
|
|
31426
|
+
return identifier;
|
|
31427
|
+
}
|
|
31428
|
+
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31429
|
+
if (!items.has(baseReference)) return baseReference;
|
|
31430
|
+
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
31431
|
+
if (!items.has(readableCandidate)) return readableCandidate;
|
|
31432
|
+
const sourceDigest = md5hex(normalizeHref(sourceHref));
|
|
31433
|
+
let candidate = `${readableCandidate}_${sourceDigest}`;
|
|
31434
|
+
let suffix = 1;
|
|
31435
|
+
while (items.has(candidate)) {
|
|
31436
|
+
candidate = `${readableCandidate}_${sourceDigest}_${suffix}`;
|
|
31437
|
+
suffix += 1;
|
|
31438
|
+
}
|
|
31439
|
+
return candidate;
|
|
31440
|
+
}
|
|
31441
|
+
function isUnsafeAssetHrefError(error) {
|
|
31442
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
31443
|
+
}
|
|
31444
|
+
function hasAssetNamingDiagnostic(diagnostics) {
|
|
31445
|
+
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);
|
|
31446
|
+
}
|
|
31447
|
+
/**
|
|
31448
|
+
* Resolve a local QTI reference exactly as asset URL transformation does.
|
|
31449
|
+
* References without a leading dot segment are already package-relative;
|
|
31450
|
+
* `./` and `../` references are resolved from the item source directory.
|
|
31451
|
+
*/
|
|
31452
|
+
function resolvePackageAssetHref(href, sourceHrefBase) {
|
|
31453
|
+
const cleanHref = href.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
31454
|
+
if (!cleanHref || /^https?:\/\//i.test(cleanHref) || cleanHref.startsWith("//") || cleanHref.startsWith("data:") || cleanHref.includes("assets.learnosity.com") || cleanHref.includes("media-vault.learnosity.com")) return;
|
|
31455
|
+
if (!(/^\.\.?\//.test(cleanHref) || !cleanHref.includes("/"))) return canonicalizeQtiAssetHref(cleanHref);
|
|
31456
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
31457
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${cleanHref}`);
|
|
31458
|
+
}
|
|
31459
|
+
/** Extract local asset-bearing attributes from item XML or resolved passage HTML. */
|
|
31460
|
+
function extractAssetHrefs(content) {
|
|
31461
|
+
const hrefs = [];
|
|
31462
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31463
|
+
const attributePattern = /\b(?:src|data|href)\s*=\s*["']([^"']+)["']/gi;
|
|
31464
|
+
let match;
|
|
31465
|
+
while ((match = attributePattern.exec(content)) !== null) if (!seen.has(match[1])) {
|
|
31466
|
+
seen.add(match[1]);
|
|
31467
|
+
hrefs.push(match[1]);
|
|
31468
|
+
}
|
|
31469
|
+
return hrefs;
|
|
31470
|
+
}
|
|
31471
|
+
function isCopyableAssetPath(path) {
|
|
31472
|
+
return isSupportedQtiAssetPath(path);
|
|
31473
|
+
}
|
|
30977
31474
|
/**
|
|
30978
31475
|
* Merge two tag objects, combining tag values for each tag type
|
|
30979
31476
|
* Source tags are merged into base tags, avoiding duplicates
|
|
@@ -31044,7 +31541,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31044
31541
|
if (needed.has(normalized)) return true;
|
|
31045
31542
|
const lower = normalized.toLowerCase();
|
|
31046
31543
|
if (lower.endsWith(".html")) return false;
|
|
31047
|
-
return lower.endsWith(".xml") ||
|
|
31544
|
+
return lower.endsWith(".xml") || isSupportedQtiAssetPath(normalized);
|
|
31048
31545
|
};
|
|
31049
31546
|
}
|
|
31050
31547
|
const unzipped = unzipToEntries(input.zipBytes, label, filter ? { filter } : void 0);
|
|
@@ -31079,6 +31576,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31079
31576
|
}
|
|
31080
31577
|
const items = /* @__PURE__ */ new Map();
|
|
31081
31578
|
const itemFilenames = /* @__PURE__ */ new Map();
|
|
31579
|
+
const itemAssetContexts = [];
|
|
31082
31580
|
const qtiRefToMd5Refs = /* @__PURE__ */ new Map();
|
|
31083
31581
|
const convertedSourceFiles = [];
|
|
31084
31582
|
const failedSourceFiles = [];
|
|
@@ -31141,23 +31639,33 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31141
31639
|
}
|
|
31142
31640
|
const itemXml = decodeUtf8(itemEntry.data);
|
|
31143
31641
|
const itemFilePath = opts?.sourceDir ? posixJoin(opts.sourceDir, itemResource.href) : itemResource.href;
|
|
31642
|
+
const baseItemReference = generateItemReference(readAssessmentItemIdentifier(itemXml, itemResource.identifier), opts?.itemReferenceSource, itemFilePath);
|
|
31643
|
+
const finalItemReference = uniqueItemReference(baseItemReference, itemResource.href, items);
|
|
31144
31644
|
const itemResult = convertQtiAssessmentItemToLearnosity(itemXml, {
|
|
31145
31645
|
inputPath: itemFilePath,
|
|
31146
31646
|
sourceFile: itemFilePath,
|
|
31147
31647
|
organisationId: opts?.organisationId,
|
|
31148
31648
|
mediaVault: opts?.mediaVault,
|
|
31149
31649
|
customAssetUrl: opts?.customAssetUrl,
|
|
31650
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31150
31651
|
itemReferenceSource: opts?.itemReferenceSource,
|
|
31151
31652
|
fileAccess: opts?.fileAccess,
|
|
31152
|
-
packageRoot: opts?.sourceDir
|
|
31653
|
+
packageRoot: opts?.sourceDir,
|
|
31654
|
+
finalItemReference,
|
|
31655
|
+
sourceHrefBase: itemResource.href
|
|
31153
31656
|
});
|
|
31154
31657
|
diagnostics.push(...itemResult.diagnostics);
|
|
31155
31658
|
if (itemResult.item) {
|
|
31156
31659
|
let md5Ref = itemResult.item.item.reference;
|
|
31660
|
+
if (finalItemReference !== baseItemReference) diagnostics.push({
|
|
31661
|
+
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
31662
|
+
level: "warning",
|
|
31663
|
+
file: itemResource.href,
|
|
31664
|
+
message: `Duplicate item reference "${finalItemReference}" disambiguated from "${baseItemReference}" (source: ${itemResource.href})`
|
|
31665
|
+
});
|
|
31157
31666
|
if (items.has(md5Ref)) {
|
|
31158
|
-
const
|
|
31159
|
-
|
|
31160
|
-
md5Ref = `${md5Ref}_${filename}`;
|
|
31667
|
+
const originalRef = md5Ref;
|
|
31668
|
+
md5Ref = uniqueItemReference(finalItemReference, itemResource.href, items);
|
|
31161
31669
|
itemResult.item.item.reference = md5Ref;
|
|
31162
31670
|
for (const question of itemResult.item.questions) {
|
|
31163
31671
|
const oldRef = question.reference;
|
|
@@ -31171,7 +31679,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31171
31679
|
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
31172
31680
|
level: "warning",
|
|
31173
31681
|
file: itemResource.href,
|
|
31174
|
-
message: `Duplicate item reference "${
|
|
31682
|
+
message: `Duplicate item reference "${md5Ref}" disambiguated from "${originalRef}" (source: ${itemResource.href})`
|
|
31175
31683
|
});
|
|
31176
31684
|
}
|
|
31177
31685
|
if (itemResource.metadataXml) try {
|
|
@@ -31191,9 +31699,15 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31191
31699
|
});
|
|
31192
31700
|
}
|
|
31193
31701
|
items.set(md5Ref, itemResult.item);
|
|
31702
|
+
itemAssetContexts.push({
|
|
31703
|
+
finalItemReference: md5Ref,
|
|
31704
|
+
sourceHref: itemResource.href,
|
|
31705
|
+
sourceFile: itemFilePath,
|
|
31706
|
+
inputXml: itemXml
|
|
31707
|
+
});
|
|
31194
31708
|
const filenameSource = opts?.itemFilenameSource;
|
|
31195
|
-
if (filenameSource && filenameSource !== (opts.itemReferenceSource
|
|
31196
|
-
const filename = generateItemReference(itemXml
|
|
31709
|
+
if (filenameSource && normalizeRefSource(filenameSource) !== normalizeRefSource(opts.itemReferenceSource)) {
|
|
31710
|
+
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
31197
31711
|
itemFilenames.set(md5Ref, filename);
|
|
31198
31712
|
}
|
|
31199
31713
|
if (!qtiRefToMd5Refs.has(itemResource.identifier)) qtiRefToMd5Refs.set(itemResource.identifier, []);
|
|
@@ -31204,6 +31718,12 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31204
31718
|
diagnostics.push(...ensureFailedItemDiagnostic(itemResult.diagnostics, itemResource.href));
|
|
31205
31719
|
}
|
|
31206
31720
|
}
|
|
31721
|
+
if (hasAssetNamingDiagnostic(diagnostics)) return {
|
|
31722
|
+
diagnostics,
|
|
31723
|
+
convertedSourceFiles,
|
|
31724
|
+
failedSourceFiles,
|
|
31725
|
+
convertedActivityFiles
|
|
31726
|
+
};
|
|
31207
31727
|
if (items.size === 0 && itemResourcesToConvert.length > 0) {
|
|
31208
31728
|
diagnostics.push({
|
|
31209
31729
|
code: DiagnosticCode.QTI_PACKAGE_ITEM_NOT_FOUND,
|
|
@@ -31217,8 +31737,10 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31217
31737
|
const activitiesManifest = {};
|
|
31218
31738
|
if (testResources.length > 0) for (const testResource of testResources) {
|
|
31219
31739
|
let activityReference;
|
|
31220
|
-
if (opts?.itemReferenceSource === "
|
|
31221
|
-
|
|
31740
|
+
if (normalizeRefSource(opts?.itemReferenceSource) === "itemIdentifier") {
|
|
31741
|
+
const testEntry = entries.get(normalizeHref(testResource.href));
|
|
31742
|
+
activityReference = testEntry ? readAssessmentTestIdentifier(decodeUtf8(testEntry.data), testResource.identifier) : testResource.identifier;
|
|
31743
|
+
} else {
|
|
31222
31744
|
const hrefParts = testResource.href.split("/");
|
|
31223
31745
|
activityReference = hrefParts[hrefParts.length - 1].replace(/\.xml$/i, "");
|
|
31224
31746
|
}
|
|
@@ -31308,24 +31830,39 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31308
31830
|
activitiesManifest[activityId] = { items: activityItems };
|
|
31309
31831
|
}
|
|
31310
31832
|
const assets = /* @__PURE__ */ new Map();
|
|
31311
|
-
const
|
|
31312
|
-
|
|
31313
|
-
|
|
31314
|
-
|
|
31315
|
-
|
|
31316
|
-
|
|
31317
|
-
|
|
31318
|
-
|
|
31319
|
-
|
|
31833
|
+
const assetCandidates = /* @__PURE__ */ new Map();
|
|
31834
|
+
const addAssetCandidate = (href, data) => {
|
|
31835
|
+
try {
|
|
31836
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
31837
|
+
if (isCopyableAssetPath(canonicalHref)) assetCandidates.set(canonicalHref, new Uint8Array(data));
|
|
31838
|
+
} catch {}
|
|
31839
|
+
};
|
|
31840
|
+
for (const resource of resources) if (resource.type === "webcontent" || resource.type.includes("associated")) for (const href of [resource.href, ...resource.files ?? []]) {
|
|
31841
|
+
const assetEntry = entries.get(normalizeHref(href));
|
|
31842
|
+
if (assetEntry) addAssetCandidate(href, assetEntry.data);
|
|
31320
31843
|
}
|
|
31321
31844
|
for (const [path, entry] of entries) {
|
|
31322
|
-
if (
|
|
31323
|
-
|
|
31324
|
-
|
|
31325
|
-
|
|
31326
|
-
|
|
31327
|
-
|
|
31328
|
-
|
|
31845
|
+
if (path === "imsmanifest.xml" || path.toLowerCase().endsWith(".xml")) continue;
|
|
31846
|
+
addAssetCandidate(path, entry.data);
|
|
31847
|
+
}
|
|
31848
|
+
const registry = new AssetFilenameRegistry(opts?.preserveAssetFilenames ?? false);
|
|
31849
|
+
const registerContextAsset = (context, rawHref, sourceHrefBase) => {
|
|
31850
|
+
const canonicalHref = resolvePackageAssetHref(rawHref, sourceHrefBase);
|
|
31851
|
+
if (!canonicalHref) return;
|
|
31852
|
+
const bytes = assetCandidates.get(canonicalHref);
|
|
31853
|
+
if (!bytes) return;
|
|
31854
|
+
const registration = registry.register(context.finalItemReference, canonicalHref, bytes);
|
|
31855
|
+
assets.set(registration.filename, registration.bytes);
|
|
31856
|
+
};
|
|
31857
|
+
for (const context of itemAssetContexts) {
|
|
31858
|
+
for (const rawHref of extractAssetHrefs(context.inputXml)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
31859
|
+
for (const passagePath of getAllPassageDataPaths(context.inputXml)) {
|
|
31860
|
+
const passageContent = opts?.fileAccess?.resolvePassageFile(passagePath, context.sourceFile);
|
|
31861
|
+
const passageHref = resolvePackageAssetHref(passagePath, context.sourceHref);
|
|
31862
|
+
const entryContent = passageHref ? entries.get(passageHref) : void 0;
|
|
31863
|
+
const resolvedPassageContent = passageContent ?? (entryContent ? decodeUtf8(entryContent.data) : void 0);
|
|
31864
|
+
if (!resolvedPassageContent) continue;
|
|
31865
|
+
for (const rawHref of extractAssetHrefs(resolvedPassageContent)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
31329
31866
|
}
|
|
31330
31867
|
}
|
|
31331
31868
|
return {
|
|
@@ -31338,7 +31875,8 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31338
31875
|
organisationId: opts?.organisationId,
|
|
31339
31876
|
mediaVault: opts?.mediaVault ?? false,
|
|
31340
31877
|
customAssetUrl: opts?.customAssetUrl,
|
|
31341
|
-
|
|
31878
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31879
|
+
itemReferenceSource: opts?.itemReferenceSource ?? "itemIdentifier"
|
|
31342
31880
|
}
|
|
31343
31881
|
},
|
|
31344
31882
|
items: Array.from(items.keys()).sort(),
|
|
@@ -31359,7 +31897,25 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31359
31897
|
convertedActivityFiles
|
|
31360
31898
|
};
|
|
31361
31899
|
} catch (error) {
|
|
31362
|
-
diagnostics.push({
|
|
31900
|
+
if (error instanceof AssetFilenameConflictError) diagnostics.push({
|
|
31901
|
+
code: error.kind === "identity-bytes" ? DiagnosticCode.QTI_ASSET_IDENTITY_BYTES_CONFLICT : DiagnosticCode.QTI_ASSET_FILENAME_CONFLICT,
|
|
31902
|
+
level: "error",
|
|
31903
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
31904
|
+
message: error.message,
|
|
31905
|
+
context: {
|
|
31906
|
+
mode: error.mode,
|
|
31907
|
+
filename: error.filename,
|
|
31908
|
+
existingIdentity: error.existing.serializedIdentity,
|
|
31909
|
+
incomingIdentity: error.incoming.serializedIdentity
|
|
31910
|
+
}
|
|
31911
|
+
});
|
|
31912
|
+
else if (isUnsafeAssetHrefError(error)) diagnostics.push({
|
|
31913
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
31914
|
+
level: "error",
|
|
31915
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
31916
|
+
message: error.message
|
|
31917
|
+
});
|
|
31918
|
+
else diagnostics.push({
|
|
31363
31919
|
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
31364
31920
|
level: "error",
|
|
31365
31921
|
file: "root",
|