@learnosity/lib-qti-converter 0.12.8 → 0.13.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/GETTING_STARTED.md +71 -18
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +23 -7
- package/package.json +1 -1
- package/packages/cli/dist/{batchProcessors-CUJoQD8a.js → batchProcessors-DgiDpfpP.js} +270 -76
- package/packages/cli/dist/batchProcessors-DgiDpfpP.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +1 -1
- package/packages/cli/dist/{learnosityToQti-CvfVQ6Kl.js → learnosityToQti-CIj5603P.js} +4 -4
- package/packages/cli/dist/{learnosityToQti-CvfVQ6Kl.js.map → learnosityToQti-CIj5603P.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQtiPackage-CXMsJNQD.js → learnosityToQtiPackage-n6nGGr32.js} +4 -4
- package/packages/cli/dist/{learnosityToQtiPackage-CXMsJNQD.js.map → learnosityToQtiPackage-n6nGGr32.js.map} +1 -1
- package/packages/cli/dist/main.js +4 -4
- package/packages/cli/dist/{pathUtils-DmtCfutO.js → pathUtils-mTQZ0wYS.js} +12 -2
- package/packages/cli/dist/{pathUtils-DmtCfutO.js.map → pathUtils-mTQZ0wYS.js.map} +1 -1
- package/packages/cli/dist/{qtiPackageToLearnosity-FhfNr7gf.js → qtiPackageToLearnosity-B4cD8jUw.js} +12 -6
- package/packages/cli/dist/qtiPackageToLearnosity-B4cD8jUw.js.map +1 -0
- package/packages/cli/dist/{qtiToLearnosity-5lQ5f3-t.js → qtiToLearnosity-DDjcpShJ.js} +6 -5
- package/packages/cli/dist/qtiToLearnosity-DDjcpShJ.js.map +1 -0
- package/packages/cli/dist/{resolveOptions-lHxSyq9F.js → resolveOptions-Czapkfc1.js} +20 -6
- package/packages/cli/dist/resolveOptions-Czapkfc1.js.map +1 -0
- package/packages/cli/dist/{table-7b-8MN2z.js → table-DTSv0atR.js} +529 -172
- package/packages/cli/dist/table-DTSv0atR.js.map +1 -0
- package/packages/core/dist/index.d.ts +13 -0
- package/packages/core/dist/index.js +768 -239
- package/packages/core/dist/node.d.ts +15 -0
- package/packages/core/dist/node.js +794 -244
- 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.
|
|
23107
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
|
+
}
|
|
23108
23172
|
/**
|
|
23109
|
-
*
|
|
23110
|
-
|
|
23111
|
-
|
|
23112
|
-
|
|
23113
|
-
|
|
23114
|
-
|
|
23115
|
-
|
|
23116
|
-
|
|
23117
|
-
"
|
|
23118
|
-
|
|
23119
|
-
|
|
23120
|
-
"
|
|
23121
|
-
"
|
|
23122
|
-
"
|
|
23123
|
-
|
|
23124
|
-
|
|
23125
|
-
|
|
23126
|
-
|
|
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.
|
|
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
|
+
}
|
|
23127
23213
|
/**
|
|
23128
|
-
*
|
|
23129
|
-
*
|
|
23130
|
-
* `RegExp.prototype.test` on non-global regexes, so they are safe to share.
|
|
23214
|
+
* Return the final filename extension, including its leading dot.
|
|
23215
|
+
* Dotfiles and filenames ending in a dot have no extension.
|
|
23131
23216
|
*/
|
|
23132
|
-
|
|
23133
|
-
|
|
23134
|
-
|
|
23135
|
-
|
|
23136
|
-
|
|
23137
|
-
|
|
23138
|
-
|
|
23139
|
-
|
|
23140
|
-
|
|
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
|
+
}
|
|
23222
|
+
/**
|
|
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.
|
|
23228
|
+
*/
|
|
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;
|
|
@@ -23354,23 +23499,30 @@ function mapCorrectPairsToValidation(correctPairs, stemIdToIndex, optionIdToInde
|
|
|
23354
23499
|
/**
|
|
23355
23500
|
* Convert matchInteraction to Learnosity choicematrix
|
|
23356
23501
|
*/
|
|
23357
|
-
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23502
|
+
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23358
23503
|
const parsed = readAssessmentItemMatch(inputXml);
|
|
23359
23504
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23360
23505
|
diagnostics.push(...updatedDiagnostics);
|
|
23361
23506
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23362
23507
|
if (!parsed.identifier || parsed.stems.length === 0 || parsed.options.length === 0) return { diagnostics };
|
|
23363
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23508
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23509
|
+
const transformContext = {
|
|
23510
|
+
finalItemReference: itemRef,
|
|
23511
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23512
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23513
|
+
};
|
|
23364
23514
|
const questionRef = md5hex(itemRef);
|
|
23365
23515
|
const stems = parsed.stems.map((stem) => transformAssetUrls(stem.text, {
|
|
23366
23516
|
organisationId,
|
|
23367
23517
|
mediaVault,
|
|
23368
|
-
customAssetUrl
|
|
23518
|
+
customAssetUrl,
|
|
23519
|
+
...transformContext
|
|
23369
23520
|
}));
|
|
23370
23521
|
const options = parsed.options.map((option) => transformAssetUrls(option.text, {
|
|
23371
23522
|
organisationId,
|
|
23372
23523
|
mediaVault,
|
|
23373
|
-
customAssetUrl
|
|
23524
|
+
customAssetUrl,
|
|
23525
|
+
...transformContext
|
|
23374
23526
|
}));
|
|
23375
23527
|
const stemIdToIndex = /* @__PURE__ */ new Map();
|
|
23376
23528
|
parsed.stems.forEach((stem, index) => {
|
|
@@ -23388,7 +23540,8 @@ function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId
|
|
|
23388
23540
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
23389
23541
|
organisationId,
|
|
23390
23542
|
mediaVault,
|
|
23391
|
-
customAssetUrl
|
|
23543
|
+
customAssetUrl,
|
|
23544
|
+
...transformContext
|
|
23392
23545
|
});
|
|
23393
23546
|
const item = {
|
|
23394
23547
|
item: {
|
|
@@ -23768,25 +23921,32 @@ function buildGapValidation(gaps, gapIdToGapTextIds, gapTextIdToContent, sourceF
|
|
|
23768
23921
|
/**
|
|
23769
23922
|
* Convert gapMatchInteraction to Learnosity clozeassociation
|
|
23770
23923
|
*/
|
|
23771
|
-
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23924
|
+
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23772
23925
|
const parsed = readAssessmentItemGapMatch(inputXml);
|
|
23773
23926
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23774
23927
|
diagnostics.push(...updatedDiagnostics);
|
|
23775
23928
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23776
23929
|
if (!parsed.identifier || parsed.gapTexts.length === 0 || parsed.gaps.length === 0) return { diagnostics };
|
|
23777
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23930
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23931
|
+
const transformContext = {
|
|
23932
|
+
finalItemReference: itemRef,
|
|
23933
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23934
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23935
|
+
};
|
|
23778
23936
|
const questionRef = md5hex(itemRef);
|
|
23779
23937
|
const possibleResponses = parsed.gapTexts.map((gt) => transformAssetUrls(gt.text, {
|
|
23780
23938
|
organisationId,
|
|
23781
23939
|
mediaVault,
|
|
23782
|
-
customAssetUrl
|
|
23940
|
+
customAssetUrl,
|
|
23941
|
+
...transformContext
|
|
23783
23942
|
}));
|
|
23784
23943
|
const gapTextIdToContent = /* @__PURE__ */ new Map();
|
|
23785
23944
|
parsed.gapTexts.forEach((gt) => {
|
|
23786
23945
|
const transformedText = transformAssetUrls(gt.text, {
|
|
23787
23946
|
organisationId,
|
|
23788
23947
|
mediaVault,
|
|
23789
|
-
customAssetUrl
|
|
23948
|
+
customAssetUrl,
|
|
23949
|
+
...transformContext
|
|
23790
23950
|
});
|
|
23791
23951
|
gapTextIdToContent.set(gt.identifier, transformedText);
|
|
23792
23952
|
});
|
|
@@ -23804,7 +23964,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23804
23964
|
template: transformAssetUrls(parsed.templateHtml ?? "", {
|
|
23805
23965
|
organisationId,
|
|
23806
23966
|
mediaVault,
|
|
23807
|
-
customAssetUrl
|
|
23967
|
+
customAssetUrl,
|
|
23968
|
+
...transformContext
|
|
23808
23969
|
}),
|
|
23809
23970
|
possible_responses: possibleResponses,
|
|
23810
23971
|
shuffle_options: parsed.shuffle ?? false,
|
|
@@ -23819,7 +23980,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23819
23980
|
if (parsed.promptHtml) questionData.stimulus = transformAssetUrls(parsed.promptHtml, {
|
|
23820
23981
|
organisationId,
|
|
23821
23982
|
mediaVault,
|
|
23822
|
-
customAssetUrl
|
|
23983
|
+
customAssetUrl,
|
|
23984
|
+
...transformContext
|
|
23823
23985
|
});
|
|
23824
23986
|
if (maxResponsesPerZone > 1) questionData.max_response_per_zone = maxResponsesPerZone;
|
|
23825
23987
|
const choiceCounts = /* @__PURE__ */ new Map();
|
|
@@ -24224,19 +24386,22 @@ function buildValidationValues(interactions, responseDeclarations, diagnostics,
|
|
|
24224
24386
|
* Convert inlineChoiceInteraction to Learnosity clozedropdown
|
|
24225
24387
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
24226
24388
|
*/
|
|
24227
|
-
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
24389
|
+
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
24228
24390
|
const parsed = readAssessmentItemInlineChoice(inputXml);
|
|
24229
24391
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24230
24392
|
diagnostics.push(...updatedDiagnostics);
|
|
24231
24393
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24232
24394
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
24233
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24234
|
-
const questionRef = md5hex(itemRef);
|
|
24395
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24235
24396
|
const transformOpts = {
|
|
24236
24397
|
organisationId,
|
|
24237
24398
|
mediaVault,
|
|
24238
|
-
customAssetUrl
|
|
24399
|
+
customAssetUrl,
|
|
24400
|
+
finalItemReference: itemRef,
|
|
24401
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24402
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24239
24403
|
};
|
|
24404
|
+
const questionRef = md5hex(itemRef);
|
|
24240
24405
|
const possibleResponses = parsed.interactions.map((interaction) => interaction.choices.map((choice) => transformAssetUrls(choice.text, transformOpts)));
|
|
24241
24406
|
const validationValue = buildValidationValues(parsed.interactions, parsed.responseDeclarations, diagnostics, transformOpts, sourceFile);
|
|
24242
24407
|
if (!validationValue) return { diagnostics };
|
|
@@ -24503,23 +24668,30 @@ function readAssessmentItemOrder(inputXml) {
|
|
|
24503
24668
|
/**
|
|
24504
24669
|
* Convert orderInteraction to Learnosity orderlist
|
|
24505
24670
|
*/
|
|
24506
|
-
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
24671
|
+
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
24507
24672
|
const parsed = readAssessmentItemOrder(inputXml);
|
|
24508
24673
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24509
24674
|
diagnostics.push(...updatedDiagnostics);
|
|
24510
24675
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24511
24676
|
if (!parsed.identifier || !parsed.responseIdentifier || parsed.choices.length === 0) return { diagnostics };
|
|
24512
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24677
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24678
|
+
const transformContext = {
|
|
24679
|
+
finalItemReference: itemRef,
|
|
24680
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24681
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24682
|
+
};
|
|
24513
24683
|
const questionRef = md5hex(itemRef);
|
|
24514
24684
|
const stimulus = transformAssetUrls(parsed.stimulusText ?? "", {
|
|
24515
24685
|
organisationId,
|
|
24516
24686
|
mediaVault,
|
|
24517
|
-
customAssetUrl
|
|
24687
|
+
customAssetUrl,
|
|
24688
|
+
...transformContext
|
|
24518
24689
|
});
|
|
24519
24690
|
const list = parsed.choices.map((choice) => transformAssetUrls(choice.text, {
|
|
24520
24691
|
organisationId,
|
|
24521
24692
|
mediaVault,
|
|
24522
|
-
customAssetUrl
|
|
24693
|
+
customAssetUrl,
|
|
24694
|
+
...transformContext
|
|
24523
24695
|
}));
|
|
24524
24696
|
let validationValue;
|
|
24525
24697
|
if (parsed.correctOrder && parsed.correctOrder.length > 0) {
|
|
@@ -24894,17 +25066,19 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics, sou
|
|
|
24894
25066
|
/**
|
|
24895
25067
|
* Build the combined stimulus HTML from parsed stimulusText and promptText
|
|
24896
25068
|
*/
|
|
24897
|
-
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
25069
|
+
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
24898
25070
|
let stimulus = "";
|
|
24899
25071
|
if (parsed.stimulusText) stimulus += transformAssetUrls(parsed.stimulusText, {
|
|
24900
25072
|
organisationId,
|
|
24901
25073
|
mediaVault,
|
|
24902
|
-
customAssetUrl
|
|
25074
|
+
customAssetUrl,
|
|
25075
|
+
...assetTransformContext
|
|
24903
25076
|
});
|
|
24904
25077
|
if (parsed.promptText) stimulus += `<p>${transformAssetUrls(parsed.promptText, {
|
|
24905
25078
|
organisationId,
|
|
24906
25079
|
mediaVault,
|
|
24907
|
-
customAssetUrl
|
|
25080
|
+
customAssetUrl,
|
|
25081
|
+
...assetTransformContext
|
|
24908
25082
|
})}</p>`;
|
|
24909
25083
|
return stimulus;
|
|
24910
25084
|
}
|
|
@@ -24929,7 +25103,7 @@ function buildHotspotValidation(correctResponses, choiceIdToIndex) {
|
|
|
24929
25103
|
/**
|
|
24930
25104
|
* Convert hotspotInteraction to Learnosity hotspot
|
|
24931
25105
|
*/
|
|
24932
|
-
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
25106
|
+
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
24933
25107
|
const parsed = readAssessmentItemHotspot(inputXml);
|
|
24934
25108
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24935
25109
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -24951,10 +25125,15 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
24951
25125
|
return { diagnostics };
|
|
24952
25126
|
}
|
|
24953
25127
|
}
|
|
24954
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25128
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25129
|
+
const transformContext = {
|
|
25130
|
+
finalItemReference: itemRef,
|
|
25131
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25132
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25133
|
+
};
|
|
24955
25134
|
const questionRef = md5hex(itemRef);
|
|
24956
|
-
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
24957
|
-
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl) : parsed.imageSource;
|
|
25135
|
+
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
25136
|
+
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.imageSource;
|
|
24958
25137
|
const areas = [];
|
|
24959
25138
|
const choiceIdToIndex = /* @__PURE__ */ new Map();
|
|
24960
25139
|
for (const choice of parsed.hotspotChoices) {
|
|
@@ -25237,14 +25416,19 @@ function readAssessmentItemHottext(inputXml) {
|
|
|
25237
25416
|
/**
|
|
25238
25417
|
* Convert hottextInteraction to Learnosity tokenhighlight
|
|
25239
25418
|
*/
|
|
25240
|
-
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
25419
|
+
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
25241
25420
|
const parsed = readAssessmentItemHottext(inputXml);
|
|
25242
25421
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
25243
25422
|
diagnostics.push(...updatedDiagnostics);
|
|
25244
25423
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
25245
25424
|
if (!parsed.identifier || !parsed.responseIdentifier || !parsed.templateHtml) return { diagnostics };
|
|
25246
25425
|
if (parsed.hottextElements.length === 0) return { diagnostics };
|
|
25247
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25426
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25427
|
+
const transformContext = {
|
|
25428
|
+
finalItemReference: itemRef,
|
|
25429
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25430
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25431
|
+
};
|
|
25248
25432
|
const questionRef = md5hex(itemRef);
|
|
25249
25433
|
if (parsed.shuffle) diagnostics.push({
|
|
25250
25434
|
code: DiagnosticCode.QTI_SHUFFLE_NOT_SUPPORTED,
|
|
@@ -25256,7 +25440,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25256
25440
|
if (stimulus) stimulus = transformAssetUrls(stimulus, {
|
|
25257
25441
|
organisationId,
|
|
25258
25442
|
mediaVault,
|
|
25259
|
-
customAssetUrl
|
|
25443
|
+
customAssetUrl,
|
|
25444
|
+
...transformContext
|
|
25260
25445
|
});
|
|
25261
25446
|
let template = parsed.templateHtml || "";
|
|
25262
25447
|
const identifierToIndex = /* @__PURE__ */ new Map();
|
|
@@ -25269,7 +25454,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25269
25454
|
template = transformAssetUrls(template, {
|
|
25270
25455
|
organisationId,
|
|
25271
25456
|
mediaVault,
|
|
25272
|
-
customAssetUrl
|
|
25457
|
+
customAssetUrl,
|
|
25458
|
+
...transformContext
|
|
25273
25459
|
});
|
|
25274
25460
|
let validation = void 0;
|
|
25275
25461
|
if (parsed.correctResponses && parsed.correctResponses.length > 0) {
|
|
@@ -25736,7 +25922,7 @@ function readAssessmentItemMcq(inputXml, stimulusOverride) {
|
|
|
25736
25922
|
* Supports both single and composite (multiple) choiceInteractions
|
|
25737
25923
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
25738
25924
|
*/
|
|
25739
|
-
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
25925
|
+
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
25740
25926
|
const parsed = readAssessmentItemMcq(inputXml, stimulusOverride);
|
|
25741
25927
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
25742
25928
|
...d,
|
|
@@ -25745,7 +25931,12 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25745
25931
|
diagnostics.push(...contextualDiagnostics);
|
|
25746
25932
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
25747
25933
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
25748
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25934
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25935
|
+
const transformContext = {
|
|
25936
|
+
finalItemReference: itemRef,
|
|
25937
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25938
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25939
|
+
};
|
|
25749
25940
|
const isComposite = parsed.interactions.length > 1;
|
|
25750
25941
|
const questions = [];
|
|
25751
25942
|
const widgets = [];
|
|
@@ -25755,7 +25946,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25755
25946
|
const stimulus = interaction.stimulusText ? transformAssetUrls(interaction.stimulusText, {
|
|
25756
25947
|
organisationId,
|
|
25757
25948
|
mediaVault,
|
|
25758
|
-
customAssetUrl
|
|
25949
|
+
customAssetUrl,
|
|
25950
|
+
...transformContext
|
|
25759
25951
|
}) : void 0;
|
|
25760
25952
|
const choiceMapping = /* @__PURE__ */ new Map();
|
|
25761
25953
|
const options = interaction.choices.map((choice) => {
|
|
@@ -25764,7 +25956,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25764
25956
|
label: transformAssetUrls(choice.text, {
|
|
25765
25957
|
organisationId,
|
|
25766
25958
|
mediaVault,
|
|
25767
|
-
customAssetUrl
|
|
25959
|
+
customAssetUrl,
|
|
25960
|
+
...transformContext
|
|
25768
25961
|
}),
|
|
25769
25962
|
value: choice.identifier
|
|
25770
25963
|
};
|
|
@@ -25801,7 +25994,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25801
25994
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
25802
25995
|
organisationId,
|
|
25803
25996
|
mediaVault,
|
|
25804
|
-
customAssetUrl
|
|
25997
|
+
customAssetUrl,
|
|
25998
|
+
...transformContext
|
|
25805
25999
|
}) : void 0;
|
|
25806
26000
|
questions.push({
|
|
25807
26001
|
reference: questionRef,
|
|
@@ -26169,7 +26363,7 @@ function stripWrapperDiv(html) {
|
|
|
26169
26363
|
* Convert textEntry (textEntryInteraction) to Learnosity clozetext or shorttext
|
|
26170
26364
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26171
26365
|
*/
|
|
26172
|
-
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26366
|
+
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26173
26367
|
const parsed = readAssessmentItemTextEntry(inputXml, stimulusOverride);
|
|
26174
26368
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
26175
26369
|
...d,
|
|
@@ -26179,24 +26373,31 @@ function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile
|
|
|
26179
26373
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
26180
26374
|
if (!parsed.identifier || parsed.textEntries.length === 0) return { diagnostics };
|
|
26181
26375
|
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);
|
|
26376
|
+
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26377
|
+
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26184
26378
|
}
|
|
26185
26379
|
/**
|
|
26186
26380
|
* Convert single textEntry to Learnosity shorttext
|
|
26187
26381
|
*/
|
|
26188
|
-
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26189
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26382
|
+
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26383
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26384
|
+
const transformContext = {
|
|
26385
|
+
finalItemReference: itemRef,
|
|
26386
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26387
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26388
|
+
};
|
|
26190
26389
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26191
26390
|
const stimulus = normalizeFinalText(transformAssetUrls((parsed.templateText || "").replace(/{{response}}(?:\s*<\/[^>]+>)*\s*$/, "").trim(), {
|
|
26192
26391
|
organisationId,
|
|
26193
26392
|
mediaVault,
|
|
26194
|
-
customAssetUrl
|
|
26393
|
+
customAssetUrl,
|
|
26394
|
+
...transformContext
|
|
26195
26395
|
}));
|
|
26196
26396
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26197
26397
|
organisationId,
|
|
26198
26398
|
mediaVault,
|
|
26199
|
-
customAssetUrl
|
|
26399
|
+
customAssetUrl,
|
|
26400
|
+
...transformContext
|
|
26200
26401
|
}) : void 0;
|
|
26201
26402
|
const entry = parsed.textEntries[0];
|
|
26202
26403
|
const correctResponses = entry.correctResponses || (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -26270,25 +26471,33 @@ function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisation
|
|
|
26270
26471
|
/**
|
|
26271
26472
|
* Convert textEntry with template to Learnosity clozetext
|
|
26272
26473
|
*/
|
|
26273
|
-
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26474
|
+
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26274
26475
|
const correctResponses = [];
|
|
26275
26476
|
for (const entry of parsed.textEntries) if (entry.correctResponse) correctResponses.push(entry.correctResponse);
|
|
26276
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26477
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26478
|
+
const transformContext = {
|
|
26479
|
+
finalItemReference: itemRef,
|
|
26480
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26481
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26482
|
+
};
|
|
26277
26483
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26278
26484
|
const stimulus = parsed.stimulusText ? normalizeFinalText(transformAssetUrls(parsed.stimulusText, {
|
|
26279
26485
|
organisationId,
|
|
26280
26486
|
mediaVault,
|
|
26281
|
-
customAssetUrl
|
|
26487
|
+
customAssetUrl,
|
|
26488
|
+
...transformContext
|
|
26282
26489
|
})) : void 0;
|
|
26283
26490
|
const template = normalizeFinalText(transformAssetUrls(parsed.templateText, {
|
|
26284
26491
|
organisationId,
|
|
26285
26492
|
mediaVault,
|
|
26286
|
-
customAssetUrl
|
|
26493
|
+
customAssetUrl,
|
|
26494
|
+
...transformContext
|
|
26287
26495
|
}));
|
|
26288
26496
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26289
26497
|
organisationId,
|
|
26290
26498
|
mediaVault,
|
|
26291
|
-
customAssetUrl
|
|
26499
|
+
customAssetUrl,
|
|
26500
|
+
...transformContext
|
|
26292
26501
|
}) : void 0;
|
|
26293
26502
|
const validation = {
|
|
26294
26503
|
scoring_type: "exactMatch",
|
|
@@ -26521,8 +26730,13 @@ function readAssessmentItemExtendedText(inputXml) {
|
|
|
26521
26730
|
/**
|
|
26522
26731
|
* Build multi-interaction extended text item (multiple longtextV2 questions)
|
|
26523
26732
|
*/
|
|
26524
|
-
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26525
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26733
|
+
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26734
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26735
|
+
const transformContext = {
|
|
26736
|
+
finalItemReference: itemRef,
|
|
26737
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26738
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26739
|
+
};
|
|
26526
26740
|
const questions = [];
|
|
26527
26741
|
const widgets = [];
|
|
26528
26742
|
const questionSpans = [];
|
|
@@ -26532,7 +26746,8 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
|
|
|
26532
26746
|
const stimulus = transformAssetUrls(stimulusOverride[i], {
|
|
26533
26747
|
organisationId,
|
|
26534
26748
|
mediaVault,
|
|
26535
|
-
customAssetUrl
|
|
26749
|
+
customAssetUrl,
|
|
26750
|
+
...transformContext
|
|
26536
26751
|
});
|
|
26537
26752
|
widgets.push({
|
|
26538
26753
|
reference: questionRef,
|
|
@@ -26582,19 +26797,25 @@ function extractResponseIdentifiers(inputXml, interactionTag) {
|
|
|
26582
26797
|
* Convert extended text (extendedTextInteraction) to Learnosity longtextV2
|
|
26583
26798
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26584
26799
|
*/
|
|
26585
|
-
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26800
|
+
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26586
26801
|
const parsed = readAssessmentItemExtendedText(inputXml);
|
|
26587
26802
|
const contextualDiagnostics = addFileContextIfProvided(stimulusOverride ? filterOutCodes(parsed.diagnostics, [DiagnosticCode.QTI_EXTENDED_TEXT_MULTIPLE_INTERACTIONS]) : parsed.diagnostics, sourceFile);
|
|
26588
26803
|
diagnostics.push(...contextualDiagnostics);
|
|
26589
26804
|
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);
|
|
26805
|
+
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26806
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26807
|
+
const transformContext = {
|
|
26808
|
+
finalItemReference: itemRef,
|
|
26809
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26810
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26811
|
+
};
|
|
26592
26812
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier ?? "unknown");
|
|
26593
26813
|
const stimulusRaw = stimulusOverride && stimulusOverride.length === 1 ? stimulusOverride[0] : parsed.stimulusText;
|
|
26594
26814
|
const stimulus = stimulusRaw ? transformAssetUrls(stimulusRaw, {
|
|
26595
26815
|
organisationId,
|
|
26596
26816
|
mediaVault,
|
|
26597
|
-
customAssetUrl
|
|
26817
|
+
customAssetUrl,
|
|
26818
|
+
...transformContext
|
|
26598
26819
|
}) : void 0;
|
|
26599
26820
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26600
26821
|
organisationId,
|
|
@@ -26889,7 +27110,7 @@ function buildValidationValue$1(hotspots, correctPairs, gapImgIdToResponse) {
|
|
|
26889
27110
|
/**
|
|
26890
27111
|
* Convert QTI graphicGapMatchInteraction to Learnosity imageclozeassociationV2
|
|
26891
27112
|
*/
|
|
26892
|
-
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27113
|
+
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
26893
27114
|
const parsed = readAssessmentItemGraphicGapMatch(inputXml);
|
|
26894
27115
|
const contextualDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
26895
27116
|
diagnostics.push(...contextualDiagnostics);
|
|
@@ -26905,6 +27126,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26905
27126
|
}
|
|
26906
27127
|
const bgWidth = parsed.backgroundImage.width;
|
|
26907
27128
|
const bgHeight = parsed.backgroundImage.height;
|
|
27129
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27130
|
+
const transformContext = {
|
|
27131
|
+
finalItemReference: itemRef,
|
|
27132
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27133
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27134
|
+
};
|
|
26908
27135
|
const gapImgIdToResponse = /* @__PURE__ */ new Map();
|
|
26909
27136
|
const possible_responses = parsed.gapImages.map((g) => {
|
|
26910
27137
|
if (g.text !== void 0) {
|
|
@@ -26923,7 +27150,8 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26923
27150
|
const transformedImgTag = transformAssetUrls(imgTag, {
|
|
26924
27151
|
organisationId,
|
|
26925
27152
|
mediaVault,
|
|
26926
|
-
customAssetUrl
|
|
27153
|
+
customAssetUrl,
|
|
27154
|
+
...transformContext
|
|
26927
27155
|
});
|
|
26928
27156
|
gapImgIdToResponse.set(g.identifier, transformedImgTag);
|
|
26929
27157
|
return transformedImgTag;
|
|
@@ -26961,7 +27189,7 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26961
27189
|
const question = {
|
|
26962
27190
|
type: "imageclozeassociationV2",
|
|
26963
27191
|
image: {
|
|
26964
|
-
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl) : parsed.backgroundImage.src,
|
|
27192
|
+
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.backgroundImage.src,
|
|
26965
27193
|
width: bgWidth,
|
|
26966
27194
|
height: bgHeight
|
|
26967
27195
|
},
|
|
@@ -26985,11 +27213,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26985
27213
|
if (parsed.stimulus) question.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
26986
27214
|
organisationId,
|
|
26987
27215
|
mediaVault,
|
|
26988
|
-
customAssetUrl
|
|
27216
|
+
customAssetUrl,
|
|
27217
|
+
...transformContext
|
|
26989
27218
|
});
|
|
26990
27219
|
const item = {
|
|
26991
27220
|
item: {
|
|
26992
|
-
reference:
|
|
27221
|
+
reference: itemRef,
|
|
26993
27222
|
title: parsed.title ?? void 0,
|
|
26994
27223
|
definition: { widgets: [{
|
|
26995
27224
|
reference: questionRef,
|
|
@@ -27279,35 +27508,38 @@ const readAssessmentItemDrawing = createAssessmentItemReader({
|
|
|
27279
27508
|
/**
|
|
27280
27509
|
* Build drawing stimulus from parsed QTI data
|
|
27281
27510
|
*/
|
|
27282
|
-
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27511
|
+
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27283
27512
|
if (!parsed.stimulusText && !parsed.promptText) return;
|
|
27284
27513
|
const stimulus = parsed.promptText || parsed.stimulusText || "";
|
|
27285
27514
|
try {
|
|
27286
27515
|
return transformAssetUrls(stimulus, {
|
|
27287
27516
|
organisationId,
|
|
27288
27517
|
mediaVault,
|
|
27289
|
-
customAssetUrl
|
|
27518
|
+
customAssetUrl,
|
|
27519
|
+
...assetTransformContext
|
|
27290
27520
|
});
|
|
27291
|
-
} catch {
|
|
27521
|
+
} catch (error) {
|
|
27522
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27292
27523
|
return stimulus;
|
|
27293
27524
|
}
|
|
27294
27525
|
}
|
|
27295
27526
|
/**
|
|
27296
27527
|
* Transform a single image source URL
|
|
27297
27528
|
*/
|
|
27298
|
-
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl) {
|
|
27529
|
+
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27299
27530
|
try {
|
|
27300
|
-
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl) : imageSource;
|
|
27301
|
-
} catch {
|
|
27531
|
+
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) : imageSource;
|
|
27532
|
+
} catch (error) {
|
|
27533
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27302
27534
|
return imageSource;
|
|
27303
27535
|
}
|
|
27304
27536
|
}
|
|
27305
27537
|
/**
|
|
27306
27538
|
* Build drawing image data from parsed QTI data
|
|
27307
27539
|
*/
|
|
27308
|
-
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27540
|
+
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27309
27541
|
if (!parsed.imageSource) return;
|
|
27310
|
-
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl) };
|
|
27542
|
+
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) };
|
|
27311
27543
|
if (parsed.imageWidth) image.width = parsed.imageWidth;
|
|
27312
27544
|
if (parsed.imageHeight) image.height = parsed.imageHeight;
|
|
27313
27545
|
if (parsed.imageAlt) image.alt = parsed.imageAlt;
|
|
@@ -27316,21 +27548,27 @@ function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
|
27316
27548
|
/**
|
|
27317
27549
|
* Convert QTI drawingInteraction to Learnosity drawing question
|
|
27318
27550
|
*/
|
|
27319
|
-
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27551
|
+
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27320
27552
|
const parsed = readAssessmentItemDrawing(inputXml);
|
|
27321
27553
|
diagnostics.push(...parsed.diagnostics);
|
|
27322
27554
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
27323
|
-
const
|
|
27555
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27556
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
27557
|
+
const transformContext = {
|
|
27558
|
+
finalItemReference: itemRef,
|
|
27559
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27560
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27561
|
+
};
|
|
27324
27562
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "drawing"));
|
|
27325
27563
|
const questionData = { type: "drawing" };
|
|
27326
|
-
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27564
|
+
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27327
27565
|
if (stimulus !== void 0) questionData.stimulus = stimulus;
|
|
27328
|
-
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27566
|
+
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27329
27567
|
if (image) questionData.image = image;
|
|
27330
27568
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
27331
27569
|
const item = {
|
|
27332
27570
|
item: {
|
|
27333
|
-
reference:
|
|
27571
|
+
reference: itemRef,
|
|
27334
27572
|
title: parsed.title ?? void 0,
|
|
27335
27573
|
content,
|
|
27336
27574
|
definition: { widgets: [{
|
|
@@ -27620,7 +27858,7 @@ function buildValidationValue(choices, correctPairs, diagnostics, sourceFile) {
|
|
|
27620
27858
|
* This reflects the undirected-pair nature of associateInteraction: no choice is
|
|
27621
27859
|
* inherently a "category" or a "draggable" — both sides of a pair are equivalent.
|
|
27622
27860
|
*/
|
|
27623
|
-
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27861
|
+
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27624
27862
|
const parsed = readAssessmentItemAssociation(inputXml);
|
|
27625
27863
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
27626
27864
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -27628,17 +27866,24 @@ function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisa
|
|
|
27628
27866
|
if (!parsed.identifier || parsed.choices.length === 0) return { diagnostics };
|
|
27629
27867
|
const validationValue = buildValidationValue(parsed.choices, parsed.correctPairs, diagnostics, sourceFile);
|
|
27630
27868
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
27631
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27869
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27870
|
+
const transformContext = {
|
|
27871
|
+
finalItemReference: itemRef,
|
|
27872
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27873
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27874
|
+
};
|
|
27632
27875
|
const questionRef = md5hex(itemRef);
|
|
27633
27876
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
27634
27877
|
organisationId,
|
|
27635
27878
|
mediaVault,
|
|
27636
|
-
customAssetUrl
|
|
27879
|
+
customAssetUrl,
|
|
27880
|
+
...transformContext
|
|
27637
27881
|
});
|
|
27638
27882
|
const possibleResponses = parsed.choices.map((c) => transformAssetUrls(c.text, {
|
|
27639
27883
|
organisationId,
|
|
27640
27884
|
mediaVault,
|
|
27641
|
-
customAssetUrl
|
|
27885
|
+
customAssetUrl,
|
|
27886
|
+
...transformContext
|
|
27642
27887
|
}));
|
|
27643
27888
|
const pairCount = validationValue.length > 0 ? validationValue.length : Math.round(parsed.maxAssociations ?? parsed.choices.length / 2);
|
|
27644
27889
|
const columnHeaders = Array.from({ length: pairCount }, (_, i) => `Pair ${i + 1}`);
|
|
@@ -28054,8 +28299,8 @@ function computeClosingTags(html) {
|
|
|
28054
28299
|
* Converters with different parameter orders are wrapped to normalize the signature.
|
|
28055
28300
|
*/
|
|
28056
28301
|
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);
|
|
28302
|
+
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli, assetTransformContext) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli, assetTransformContext);
|
|
28303
|
+
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
28304
|
return {
|
|
28060
28305
|
choiceInteraction: wrapSourceFirst(convertMcqToLearnosity),
|
|
28061
28306
|
textEntryInteraction: wrapSourceFirst(convertTextEntryToLearnosity),
|
|
@@ -28078,8 +28323,14 @@ const CONVERTER_MAP = getConverterMap();
|
|
|
28078
28323
|
* Strategy: Call each individual converter for its interaction type,
|
|
28079
28324
|
* then combine all questions and widgets into a single composite item
|
|
28080
28325
|
*/
|
|
28081
|
-
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
28326
|
+
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
28082
28327
|
const metadata = extractItemMetadata(inputXml);
|
|
28328
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(metadata.identifier ?? "mixed_item", itemReferenceSource, sourceFile);
|
|
28329
|
+
const transformContext = {
|
|
28330
|
+
finalItemReference: itemRef,
|
|
28331
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28332
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28333
|
+
};
|
|
28083
28334
|
const { segments } = segmentItemBodyByInteractions(inputXml);
|
|
28084
28335
|
const stimuliByType = /* @__PURE__ */ new Map();
|
|
28085
28336
|
for (const segment of segments) {
|
|
@@ -28161,7 +28412,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28161
28412
|
const template = normalizeFinalText(transformAssetUrls(rawTemplate, {
|
|
28162
28413
|
organisationId,
|
|
28163
28414
|
mediaVault,
|
|
28164
|
-
customAssetUrl
|
|
28415
|
+
customAssetUrl,
|
|
28416
|
+
...transformContext
|
|
28165
28417
|
}));
|
|
28166
28418
|
if (groupEntries.length === 1 && /{{response}}(?:<\/[^>]+>|\s)*$/.test(rawTemplate.trim())) {
|
|
28167
28419
|
let stimulusRaw = rawTemplate.replace(/{{response}}(?:<\/[^>]+>|\s)*$/, "").trim();
|
|
@@ -28169,7 +28421,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28169
28421
|
const stimulus = normalizeFinalText(transformAssetUrls(stimulusRaw, {
|
|
28170
28422
|
organisationId,
|
|
28171
28423
|
mediaVault,
|
|
28172
|
-
customAssetUrl
|
|
28424
|
+
customAssetUrl,
|
|
28425
|
+
...transformContext
|
|
28173
28426
|
}));
|
|
28174
28427
|
const entry = groupEntries[0];
|
|
28175
28428
|
const allCorrectResponses = entry.correctResponses ?? (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -28295,7 +28548,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28295
28548
|
continue;
|
|
28296
28549
|
}
|
|
28297
28550
|
const converter = CONVERTER_MAP[group.type];
|
|
28298
|
-
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, fileAccess, packageRoot), subDiagnostics);
|
|
28551
|
+
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, transformContext, fileAccess, packageRoot), subDiagnostics);
|
|
28299
28552
|
}
|
|
28300
28553
|
if (allQuestions.length === 0) {
|
|
28301
28554
|
diagnostics.push({
|
|
@@ -28318,9 +28571,16 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28318
28571
|
passageContent = transformAssetUrls(rawContent, {
|
|
28319
28572
|
organisationId,
|
|
28320
28573
|
mediaVault,
|
|
28321
|
-
customAssetUrl
|
|
28574
|
+
customAssetUrl,
|
|
28575
|
+
...transformContext
|
|
28576
|
+
});
|
|
28577
|
+
} catch (error) {
|
|
28578
|
+
if (isUnsafeQtiAssetHrefError(error)) diagnostics.push({
|
|
28579
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
28580
|
+
level: "error",
|
|
28581
|
+
file: sourceFile ?? "passage",
|
|
28582
|
+
message: error.message
|
|
28322
28583
|
});
|
|
28323
|
-
} catch {
|
|
28324
28584
|
passageContent = rawContent;
|
|
28325
28585
|
}
|
|
28326
28586
|
allFeatures.push({
|
|
@@ -28352,7 +28612,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28352
28612
|
const content = `<div class="row"><div class="col-xs-12">${[...featureSpans, ...questionSpans].join("")}</div></div>`;
|
|
28353
28613
|
const item = {
|
|
28354
28614
|
item: {
|
|
28355
|
-
reference:
|
|
28615
|
+
reference: itemRef,
|
|
28356
28616
|
title: metadata.title ?? void 0,
|
|
28357
28617
|
content,
|
|
28358
28618
|
definition: { widgets: allWidgets },
|
|
@@ -28398,8 +28658,13 @@ function resolvePassageObjects(html, sourceFile, resolvePassageFile) {
|
|
|
28398
28658
|
/**
|
|
28399
28659
|
* Convert passage-only item to Learnosity format with sharedpassage feature
|
|
28400
28660
|
*/
|
|
28401
|
-
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess) {
|
|
28402
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28661
|
+
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, assetTransformContext) {
|
|
28662
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28663
|
+
const transformContext = {
|
|
28664
|
+
finalItemReference: itemRef,
|
|
28665
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28666
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28667
|
+
};
|
|
28403
28668
|
const featureRef = `passage-${md5hex(getPassageDataPath(parsed.content) ?? itemRef).substring(0, 8)}`;
|
|
28404
28669
|
const resolvedContent = resolvePassageObjects(parsed.content, sourceFile, fileAccess?.resolvePassageFile.bind(fileAccess));
|
|
28405
28670
|
let content;
|
|
@@ -28407,11 +28672,12 @@ function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId
|
|
|
28407
28672
|
content = transformAssetUrls(resolvedContent, {
|
|
28408
28673
|
organisationId,
|
|
28409
28674
|
mediaVault,
|
|
28410
|
-
customAssetUrl
|
|
28675
|
+
customAssetUrl,
|
|
28676
|
+
...transformContext
|
|
28411
28677
|
});
|
|
28412
28678
|
} catch (error) {
|
|
28413
28679
|
diagnostics.push({
|
|
28414
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28680
|
+
code: isUnsafeQtiAssetHrefError(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28415
28681
|
level: "error",
|
|
28416
28682
|
file: sourceFile ?? "assessmentItem",
|
|
28417
28683
|
message: error instanceof Error ? error.message : "Failed to transform asset URLs"
|
|
@@ -28801,20 +29067,28 @@ function readAssessmentItemUpload(inputXml) {
|
|
|
28801
29067
|
* and the file limit from `maxChoices` (see readAssessmentItemUpload / the
|
|
28802
29068
|
* serializer). fileupload questions are unscored, so there is no validation.
|
|
28803
29069
|
*/
|
|
28804
|
-
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
29070
|
+
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
28805
29071
|
const parsed = readAssessmentItemUpload(inputXml);
|
|
28806
29072
|
diagnostics.push(...parsed.diagnostics);
|
|
28807
29073
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
28808
|
-
const
|
|
29074
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
29075
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
29076
|
+
const transformContext = {
|
|
29077
|
+
finalItemReference: itemRef,
|
|
29078
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
29079
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
29080
|
+
};
|
|
28809
29081
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "fileupload"));
|
|
28810
29082
|
const questionData = { type: "fileupload" };
|
|
28811
29083
|
if (parsed.stimulus) try {
|
|
28812
29084
|
questionData.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
28813
29085
|
organisationId,
|
|
28814
29086
|
mediaVault,
|
|
28815
|
-
customAssetUrl
|
|
29087
|
+
customAssetUrl,
|
|
29088
|
+
...transformContext
|
|
28816
29089
|
});
|
|
28817
|
-
} catch {
|
|
29090
|
+
} catch (error) {
|
|
29091
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
28818
29092
|
questionData.stimulus = parsed.stimulus;
|
|
28819
29093
|
}
|
|
28820
29094
|
for (const suffix of parsed.allowedFileTypes) questionData[`allow_${suffix}`] = true;
|
|
@@ -28822,7 +29096,7 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28822
29096
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
28823
29097
|
const item = {
|
|
28824
29098
|
item: {
|
|
28825
|
-
reference:
|
|
29099
|
+
reference: itemRef,
|
|
28826
29100
|
title: parsed.title ?? void 0,
|
|
28827
29101
|
content,
|
|
28828
29102
|
definition: { widgets: [{
|
|
@@ -28857,9 +29131,19 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28857
29131
|
* - Rejects DOCTYPE / ENTITY declarations up-front (DTD not allowed).
|
|
28858
29132
|
* - Uses streaming parsers for all interaction types.
|
|
28859
29133
|
*/
|
|
29134
|
+
function getAssetSourceHrefBase(opts) {
|
|
29135
|
+
if (opts.sourceHrefBase) return opts.sourceHrefBase;
|
|
29136
|
+
const source = opts.sourceFile ?? opts.inputPath;
|
|
29137
|
+
if (!source) return;
|
|
29138
|
+
const normalized = source.replaceAll("\\", "/");
|
|
29139
|
+
return normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(normalized) ? normalized.slice(normalized.lastIndexOf("/") + 1) : normalized;
|
|
29140
|
+
}
|
|
28860
29141
|
/**
|
|
28861
29142
|
* Supported interaction type names for counting
|
|
28862
29143
|
*/
|
|
29144
|
+
function isUnsafeAssetHrefError$1(error) {
|
|
29145
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
29146
|
+
}
|
|
28863
29147
|
const INTERACTION_NAMES = [
|
|
28864
29148
|
"choiceInteraction",
|
|
28865
29149
|
"textEntryInteraction",
|
|
@@ -28925,19 +29209,71 @@ function countAllInteractions(xml) {
|
|
|
28925
29209
|
};
|
|
28926
29210
|
}
|
|
28927
29211
|
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
|
-
|
|
29212
|
+
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29213
|
+
finalItemReference: opts.finalItemReference,
|
|
29214
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29215
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29216
|
+
})],
|
|
29217
|
+
["textEntryInteraction", (xml, diag, lom, opts, stim) => convertTextEntryToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29218
|
+
finalItemReference: opts.finalItemReference,
|
|
29219
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29220
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29221
|
+
})],
|
|
29222
|
+
["extendedTextInteraction", (xml, diag, lom, opts, stim) => convertExtendedTextToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29223
|
+
finalItemReference: opts.finalItemReference,
|
|
29224
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29225
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29226
|
+
})],
|
|
29227
|
+
["inlineChoiceInteraction", (xml, diag, lom, opts) => convertInlineChoiceToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29228
|
+
finalItemReference: opts.finalItemReference,
|
|
29229
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29230
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29231
|
+
})],
|
|
29232
|
+
["matchInteraction", (xml, diag, lom, opts) => convertMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29233
|
+
finalItemReference: opts.finalItemReference,
|
|
29234
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29235
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29236
|
+
})],
|
|
29237
|
+
["gapMatchInteraction", (xml, diag, lom, opts) => convertGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29238
|
+
finalItemReference: opts.finalItemReference,
|
|
29239
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29240
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29241
|
+
})],
|
|
29242
|
+
["orderInteraction", (xml, diag, lom, opts) => convertOrderToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29243
|
+
finalItemReference: opts.finalItemReference,
|
|
29244
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29245
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29246
|
+
})],
|
|
29247
|
+
["hotspotInteraction", (xml, diag, lom, opts) => convertHotspotToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29248
|
+
finalItemReference: opts.finalItemReference,
|
|
29249
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29250
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29251
|
+
})],
|
|
29252
|
+
["hottextInteraction", (xml, diag, lom, opts) => convertHottextToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29253
|
+
finalItemReference: opts.finalItemReference,
|
|
29254
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29255
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29256
|
+
})],
|
|
29257
|
+
["graphicGapMatchInteraction", (xml, diag, lom, opts) => convertGraphicGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29258
|
+
finalItemReference: opts.finalItemReference,
|
|
29259
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29260
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29261
|
+
})],
|
|
29262
|
+
["drawingInteraction", (xml, diag, lom, opts) => convertDrawingToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29263
|
+
finalItemReference: opts.finalItemReference,
|
|
29264
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29265
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29266
|
+
})],
|
|
29267
|
+
["associateInteraction", (xml, diag, lom, opts) => convertAssociationToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29268
|
+
finalItemReference: opts.finalItemReference,
|
|
29269
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29270
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29271
|
+
})],
|
|
29272
|
+
["uploadInteraction", (xml, diag, lom, opts) => convertUploadToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29273
|
+
finalItemReference: opts.finalItemReference,
|
|
29274
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29275
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29276
|
+
})]
|
|
28941
29277
|
]);
|
|
28942
29278
|
/**
|
|
28943
29279
|
* Dispatch to the appropriate single-interaction converter
|
|
@@ -28963,9 +29299,18 @@ function dispatchSingleInteractionConverter(interactionType, inputXml, count, di
|
|
|
28963
29299
|
passageContent = transformAssetUrls(rawContent, {
|
|
28964
29300
|
organisationId: opts.organisationId,
|
|
28965
29301
|
mediaVault: opts.mediaVault,
|
|
28966
|
-
customAssetUrl: opts.customAssetUrl
|
|
29302
|
+
customAssetUrl: opts.customAssetUrl,
|
|
29303
|
+
finalItemReference: opts.finalItemReference ?? result.item.item.reference,
|
|
29304
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29305
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29306
|
+
});
|
|
29307
|
+
} catch (error) {
|
|
29308
|
+
if (isUnsafeAssetHrefError$1(error)) diagnostics.push({
|
|
29309
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
29310
|
+
level: "error",
|
|
29311
|
+
file: opts.sourceFile ?? "passage",
|
|
29312
|
+
message: error.message
|
|
28967
29313
|
});
|
|
28968
|
-
} catch {
|
|
28969
29314
|
passageContent = rawContent;
|
|
28970
29315
|
}
|
|
28971
29316
|
result.item.features = [...result.item.features, {
|
|
@@ -29013,8 +29358,16 @@ function handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, o
|
|
|
29013
29358
|
}
|
|
29014
29359
|
const passageResult = readAssessmentItemPassage(inputXml);
|
|
29015
29360
|
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
|
-
|
|
29361
|
+
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, {
|
|
29362
|
+
finalItemReference: opts.finalItemReference,
|
|
29363
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29364
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29365
|
+
});
|
|
29366
|
+
const mcqResult = convertMcqToLearnosity(inputXml, diagnostics, lomTags, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29367
|
+
finalItemReference: opts.finalItemReference,
|
|
29368
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29369
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29370
|
+
});
|
|
29018
29371
|
if (diagnostics.some((d) => d.code === DiagnosticCode.LRN_SCHEMA_INVALID)) return mcqResult;
|
|
29019
29372
|
return { diagnostics };
|
|
29020
29373
|
}
|
|
@@ -29060,14 +29413,18 @@ function convertQtiAssessmentItemToLearnosity(inputXml, opts = {}) {
|
|
|
29060
29413
|
const { counts, allInteractions } = countAllInteractions(inputXml);
|
|
29061
29414
|
const presentTypes = INTERACTION_NAMES.filter((name) => counts[name] > 0);
|
|
29062
29415
|
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
|
|
29416
|
+
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29417
|
+
finalItemReference: opts.finalItemReference,
|
|
29418
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29419
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29420
|
+
});
|
|
29064
29421
|
return dispatchSingleInteractionConverter(presentTypes[0], inputXml, counts[presentTypes[0]], diagnostics, lomTags, opts);
|
|
29065
29422
|
} catch (error) {
|
|
29066
29423
|
diagnostics.push({
|
|
29067
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29424
|
+
code: isUnsafeAssetHrefError$1(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29068
29425
|
level: "error",
|
|
29069
|
-
file: "root",
|
|
29070
|
-
message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29426
|
+
file: opts.sourceFile ?? "root",
|
|
29427
|
+
message: isUnsafeAssetHrefError$1(error) ? error.message : `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29071
29428
|
});
|
|
29072
29429
|
return { diagnostics };
|
|
29073
29430
|
}
|
|
@@ -29183,6 +29540,7 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29183
29540
|
organisationId: opts.organisationId,
|
|
29184
29541
|
mediaVault: opts.mediaVault,
|
|
29185
29542
|
customAssetUrl: opts.customAssetUrl,
|
|
29543
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29186
29544
|
itemReferenceSource: opts.itemReferenceSource,
|
|
29187
29545
|
fileAccess: opts.fileAccess
|
|
29188
29546
|
});
|
|
@@ -30876,6 +31234,108 @@ function unzipToEntries(bytes, sourceLabel, options) {
|
|
|
30876
31234
|
};
|
|
30877
31235
|
}
|
|
30878
31236
|
//#endregion
|
|
31237
|
+
//#region src/qti-to-learnosity/utils/assetFilenameRegistry.ts
|
|
31238
|
+
/**
|
|
31239
|
+
* Browser-safe registry for item-scoped QTI asset filenames.
|
|
31240
|
+
*
|
|
31241
|
+
* Filename selection belongs to asset identity, not package traversal. Keeping
|
|
31242
|
+
* both identity and filename indexes here lets URL and bundle seams validate
|
|
31243
|
+
* the same contract before either one can overwrite a physical asset.
|
|
31244
|
+
*/
|
|
31245
|
+
var AssetFilenameConflictError = class extends Error {
|
|
31246
|
+
kind;
|
|
31247
|
+
mode;
|
|
31248
|
+
filename;
|
|
31249
|
+
existing;
|
|
31250
|
+
incoming;
|
|
31251
|
+
constructor(kind, mode, filename, existing, incoming) {
|
|
31252
|
+
const existingIdentity = existing.serializedIdentity;
|
|
31253
|
+
const incomingIdentity = incoming.serializedIdentity;
|
|
31254
|
+
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}.`;
|
|
31255
|
+
super(message);
|
|
31256
|
+
this.name = "AssetFilenameConflictError";
|
|
31257
|
+
this.kind = kind;
|
|
31258
|
+
this.mode = mode;
|
|
31259
|
+
this.filename = filename;
|
|
31260
|
+
this.existing = existing;
|
|
31261
|
+
this.incoming = incoming;
|
|
31262
|
+
}
|
|
31263
|
+
};
|
|
31264
|
+
function bytesEqual(left, right) {
|
|
31265
|
+
if (left.length !== right.length) return false;
|
|
31266
|
+
for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
|
|
31267
|
+
return true;
|
|
31268
|
+
}
|
|
31269
|
+
function cloneBytes(bytes) {
|
|
31270
|
+
return new Uint8Array(bytes);
|
|
31271
|
+
}
|
|
31272
|
+
/**
|
|
31273
|
+
* Track selected asset names and their bytes for one conversion.
|
|
31274
|
+
*
|
|
31275
|
+
* Registering an equivalent identity repeatedly is idempotent when its bytes
|
|
31276
|
+
* agree. A filename can never silently change owners, and an identity can
|
|
31277
|
+
* never silently change bytes, in either hashed or preserve mode.
|
|
31278
|
+
*/
|
|
31279
|
+
var AssetFilenameRegistry = class {
|
|
31280
|
+
preserveAssetFilenames;
|
|
31281
|
+
byIdentity = /* @__PURE__ */ new Map();
|
|
31282
|
+
byFilename = /* @__PURE__ */ new Map();
|
|
31283
|
+
constructor(preserveAssetFilenames = false) {
|
|
31284
|
+
this.preserveAssetFilenames = preserveAssetFilenames;
|
|
31285
|
+
}
|
|
31286
|
+
get mode() {
|
|
31287
|
+
return this.preserveAssetFilenames ? "preserve" : "hashed";
|
|
31288
|
+
}
|
|
31289
|
+
get size() {
|
|
31290
|
+
return this.byIdentity.size;
|
|
31291
|
+
}
|
|
31292
|
+
/**
|
|
31293
|
+
* Register an asset and return its selected filename and bytes.
|
|
31294
|
+
*
|
|
31295
|
+
* The input href is canonicalized before both indexes are consulted, so
|
|
31296
|
+
* equivalent directory and ZIP representations reuse one registration.
|
|
31297
|
+
*/
|
|
31298
|
+
register(finalItemReference, qtiAssetHref, bytes) {
|
|
31299
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
31300
|
+
const serializedIdentity = serializeQtiAssetIdentity(finalItemReference, canonicalHref);
|
|
31301
|
+
const filename = selectQtiAssetFilename(finalItemReference, canonicalHref, this.preserveAssetFilenames);
|
|
31302
|
+
const incoming = {
|
|
31303
|
+
finalItemReference,
|
|
31304
|
+
qtiAssetHref: canonicalHref,
|
|
31305
|
+
serializedIdentity,
|
|
31306
|
+
filename,
|
|
31307
|
+
bytes: cloneBytes(bytes)
|
|
31308
|
+
};
|
|
31309
|
+
const existingIdentity = this.byIdentity.get(serializedIdentity);
|
|
31310
|
+
if (existingIdentity) {
|
|
31311
|
+
if (!bytesEqual(existingIdentity.bytes, incoming.bytes)) throw new AssetFilenameConflictError("identity-bytes", this.mode, filename, existingIdentity, incoming);
|
|
31312
|
+
return existingIdentity;
|
|
31313
|
+
}
|
|
31314
|
+
const existingFilename = this.byFilename.get(filename);
|
|
31315
|
+
if (existingFilename) throw new AssetFilenameConflictError("filename-identity", this.mode, filename, existingFilename, incoming);
|
|
31316
|
+
this.byIdentity.set(serializedIdentity, incoming);
|
|
31317
|
+
this.byFilename.set(filename, incoming);
|
|
31318
|
+
return incoming;
|
|
31319
|
+
}
|
|
31320
|
+
/** Look up a previously registered canonical identity without registering it. */
|
|
31321
|
+
get(finalItemReference, qtiAssetHref) {
|
|
31322
|
+
return this.byIdentity.get(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
31323
|
+
}
|
|
31324
|
+
/** Look up an asset by its selected bundle-relative filename. */
|
|
31325
|
+
getByFilename(filename) {
|
|
31326
|
+
return this.byFilename.get(filename);
|
|
31327
|
+
}
|
|
31328
|
+
/** Iterate registrations in deterministic registration order. */
|
|
31329
|
+
entries() {
|
|
31330
|
+
return this.byIdentity.values();
|
|
31331
|
+
}
|
|
31332
|
+
/** Remove all registrations so the registry can be reused for a new conversion. */
|
|
31333
|
+
clear() {
|
|
31334
|
+
this.byIdentity.clear();
|
|
31335
|
+
this.byFilename.clear();
|
|
31336
|
+
}
|
|
31337
|
+
};
|
|
31338
|
+
//#endregion
|
|
30879
31339
|
//#region src/qti-to-learnosity/convertQtiPackageToLearnosityBundle.ts
|
|
30880
31340
|
/**
|
|
30881
31341
|
* QTI Content Package → Learnosity Bundle converter (v1)
|
|
@@ -30923,57 +31383,69 @@ function ensureFailedItemDiagnostic(itemDiagnostics, href) {
|
|
|
30923
31383
|
}];
|
|
30924
31384
|
}
|
|
30925
31385
|
/**
|
|
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
31386
|
* Normalize href path by removing leading ./ sequences
|
|
30944
31387
|
* This ensures manifest hrefs like "./items/foo.xml" match entries stored as "items/foo.xml"
|
|
30945
31388
|
*/
|
|
30946
31389
|
function normalizeHref(href) {
|
|
30947
31390
|
return href.replace(/^(\.\/)+/, "");
|
|
30948
31391
|
}
|
|
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
|
-
|
|
31392
|
+
function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
31393
|
+
let identifier = fallback;
|
|
31394
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31395
|
+
parser.on("opentag", (tag) => {
|
|
31396
|
+
if ((tag.local ?? tag.name) === "assessmentItem") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31397
|
+
});
|
|
31398
|
+
try {
|
|
31399
|
+
parser.write(inputXml).close();
|
|
31400
|
+
} catch {}
|
|
31401
|
+
return identifier;
|
|
31402
|
+
}
|
|
31403
|
+
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31404
|
+
if (!items.has(baseReference)) return baseReference;
|
|
31405
|
+
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
31406
|
+
if (!items.has(readableCandidate)) return readableCandidate;
|
|
31407
|
+
const sourceDigest = md5hex(normalizeHref(sourceHref));
|
|
31408
|
+
let candidate = `${readableCandidate}_${sourceDigest}`;
|
|
31409
|
+
let suffix = 1;
|
|
31410
|
+
while (items.has(candidate)) {
|
|
31411
|
+
candidate = `${readableCandidate}_${sourceDigest}_${suffix}`;
|
|
31412
|
+
suffix += 1;
|
|
31413
|
+
}
|
|
31414
|
+
return candidate;
|
|
31415
|
+
}
|
|
31416
|
+
function isUnsafeAssetHrefError(error) {
|
|
31417
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
31418
|
+
}
|
|
31419
|
+
function hasAssetNamingDiagnostic(diagnostics) {
|
|
31420
|
+
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);
|
|
31421
|
+
}
|
|
31422
|
+
/**
|
|
31423
|
+
* Resolve a local QTI reference exactly as asset URL transformation does.
|
|
31424
|
+
* References without a leading dot segment are already package-relative;
|
|
31425
|
+
* `./` and `../` references are resolved from the item source directory.
|
|
31426
|
+
*/
|
|
31427
|
+
function resolvePackageAssetHref(href, sourceHrefBase) {
|
|
31428
|
+
const cleanHref = href.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
31429
|
+
if (!cleanHref || /^https?:\/\//i.test(cleanHref) || cleanHref.startsWith("//") || cleanHref.startsWith("data:") || cleanHref.includes("assets.learnosity.com") || cleanHref.includes("media-vault.learnosity.com")) return;
|
|
31430
|
+
if (!(/^\.\.?\//.test(cleanHref) || !cleanHref.includes("/"))) return canonicalizeQtiAssetHref(cleanHref);
|
|
31431
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
31432
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${cleanHref}`);
|
|
31433
|
+
}
|
|
31434
|
+
/** Extract local asset-bearing attributes from item XML or resolved passage HTML. */
|
|
31435
|
+
function extractAssetHrefs(content) {
|
|
31436
|
+
const hrefs = [];
|
|
31437
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31438
|
+
const attributePattern = /\b(?:src|data|href)\s*=\s*["']([^"']+)["']/gi;
|
|
31439
|
+
let match;
|
|
31440
|
+
while ((match = attributePattern.exec(content)) !== null) if (!seen.has(match[1])) {
|
|
31441
|
+
seen.add(match[1]);
|
|
31442
|
+
hrefs.push(match[1]);
|
|
31443
|
+
}
|
|
31444
|
+
return hrefs;
|
|
31445
|
+
}
|
|
31446
|
+
function isCopyableAssetPath(path) {
|
|
31447
|
+
return isSupportedQtiAssetPath(path);
|
|
31448
|
+
}
|
|
30977
31449
|
/**
|
|
30978
31450
|
* Merge two tag objects, combining tag values for each tag type
|
|
30979
31451
|
* Source tags are merged into base tags, avoiding duplicates
|
|
@@ -31044,7 +31516,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31044
31516
|
if (needed.has(normalized)) return true;
|
|
31045
31517
|
const lower = normalized.toLowerCase();
|
|
31046
31518
|
if (lower.endsWith(".html")) return false;
|
|
31047
|
-
return lower.endsWith(".xml") ||
|
|
31519
|
+
return lower.endsWith(".xml") || isSupportedQtiAssetPath(normalized);
|
|
31048
31520
|
};
|
|
31049
31521
|
}
|
|
31050
31522
|
const unzipped = unzipToEntries(input.zipBytes, label, filter ? { filter } : void 0);
|
|
@@ -31079,6 +31551,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31079
31551
|
}
|
|
31080
31552
|
const items = /* @__PURE__ */ new Map();
|
|
31081
31553
|
const itemFilenames = /* @__PURE__ */ new Map();
|
|
31554
|
+
const itemAssetContexts = [];
|
|
31082
31555
|
const qtiRefToMd5Refs = /* @__PURE__ */ new Map();
|
|
31083
31556
|
const convertedSourceFiles = [];
|
|
31084
31557
|
const failedSourceFiles = [];
|
|
@@ -31141,23 +31614,33 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31141
31614
|
}
|
|
31142
31615
|
const itemXml = decodeUtf8(itemEntry.data);
|
|
31143
31616
|
const itemFilePath = opts?.sourceDir ? posixJoin(opts.sourceDir, itemResource.href) : itemResource.href;
|
|
31617
|
+
const baseItemReference = generateItemReference(readAssessmentItemIdentifier(itemXml, itemResource.identifier), opts?.itemReferenceSource, itemFilePath);
|
|
31618
|
+
const finalItemReference = uniqueItemReference(baseItemReference, itemResource.href, items);
|
|
31144
31619
|
const itemResult = convertQtiAssessmentItemToLearnosity(itemXml, {
|
|
31145
31620
|
inputPath: itemFilePath,
|
|
31146
31621
|
sourceFile: itemFilePath,
|
|
31147
31622
|
organisationId: opts?.organisationId,
|
|
31148
31623
|
mediaVault: opts?.mediaVault,
|
|
31149
31624
|
customAssetUrl: opts?.customAssetUrl,
|
|
31625
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31150
31626
|
itemReferenceSource: opts?.itemReferenceSource,
|
|
31151
31627
|
fileAccess: opts?.fileAccess,
|
|
31152
|
-
packageRoot: opts?.sourceDir
|
|
31628
|
+
packageRoot: opts?.sourceDir,
|
|
31629
|
+
finalItemReference,
|
|
31630
|
+
sourceHrefBase: itemResource.href
|
|
31153
31631
|
});
|
|
31154
31632
|
diagnostics.push(...itemResult.diagnostics);
|
|
31155
31633
|
if (itemResult.item) {
|
|
31156
31634
|
let md5Ref = itemResult.item.item.reference;
|
|
31635
|
+
if (finalItemReference !== baseItemReference) diagnostics.push({
|
|
31636
|
+
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
31637
|
+
level: "warning",
|
|
31638
|
+
file: itemResource.href,
|
|
31639
|
+
message: `Duplicate item reference "${finalItemReference}" disambiguated from "${baseItemReference}" (source: ${itemResource.href})`
|
|
31640
|
+
});
|
|
31157
31641
|
if (items.has(md5Ref)) {
|
|
31158
|
-
const
|
|
31159
|
-
|
|
31160
|
-
md5Ref = `${md5Ref}_${filename}`;
|
|
31642
|
+
const originalRef = md5Ref;
|
|
31643
|
+
md5Ref = uniqueItemReference(finalItemReference, itemResource.href, items);
|
|
31161
31644
|
itemResult.item.item.reference = md5Ref;
|
|
31162
31645
|
for (const question of itemResult.item.questions) {
|
|
31163
31646
|
const oldRef = question.reference;
|
|
@@ -31171,7 +31654,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31171
31654
|
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
31172
31655
|
level: "warning",
|
|
31173
31656
|
file: itemResource.href,
|
|
31174
|
-
message: `Duplicate item reference "${
|
|
31657
|
+
message: `Duplicate item reference "${md5Ref}" disambiguated from "${originalRef}" (source: ${itemResource.href})`
|
|
31175
31658
|
});
|
|
31176
31659
|
}
|
|
31177
31660
|
if (itemResource.metadataXml) try {
|
|
@@ -31191,9 +31674,15 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31191
31674
|
});
|
|
31192
31675
|
}
|
|
31193
31676
|
items.set(md5Ref, itemResult.item);
|
|
31677
|
+
itemAssetContexts.push({
|
|
31678
|
+
finalItemReference: md5Ref,
|
|
31679
|
+
sourceHref: itemResource.href,
|
|
31680
|
+
sourceFile: itemFilePath,
|
|
31681
|
+
inputXml: itemXml
|
|
31682
|
+
});
|
|
31194
31683
|
const filenameSource = opts?.itemFilenameSource;
|
|
31195
31684
|
if (filenameSource && filenameSource !== (opts.itemReferenceSource ?? "sourceFilename")) {
|
|
31196
|
-
const filename = generateItemReference(itemXml
|
|
31685
|
+
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
31197
31686
|
itemFilenames.set(md5Ref, filename);
|
|
31198
31687
|
}
|
|
31199
31688
|
if (!qtiRefToMd5Refs.has(itemResource.identifier)) qtiRefToMd5Refs.set(itemResource.identifier, []);
|
|
@@ -31204,6 +31693,12 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31204
31693
|
diagnostics.push(...ensureFailedItemDiagnostic(itemResult.diagnostics, itemResource.href));
|
|
31205
31694
|
}
|
|
31206
31695
|
}
|
|
31696
|
+
if (hasAssetNamingDiagnostic(diagnostics)) return {
|
|
31697
|
+
diagnostics,
|
|
31698
|
+
convertedSourceFiles,
|
|
31699
|
+
failedSourceFiles,
|
|
31700
|
+
convertedActivityFiles
|
|
31701
|
+
};
|
|
31207
31702
|
if (items.size === 0 && itemResourcesToConvert.length > 0) {
|
|
31208
31703
|
diagnostics.push({
|
|
31209
31704
|
code: DiagnosticCode.QTI_PACKAGE_ITEM_NOT_FOUND,
|
|
@@ -31308,24 +31803,39 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31308
31803
|
activitiesManifest[activityId] = { items: activityItems };
|
|
31309
31804
|
}
|
|
31310
31805
|
const assets = /* @__PURE__ */ new Map();
|
|
31311
|
-
const
|
|
31312
|
-
|
|
31313
|
-
|
|
31314
|
-
|
|
31315
|
-
|
|
31316
|
-
|
|
31317
|
-
|
|
31318
|
-
|
|
31319
|
-
|
|
31806
|
+
const assetCandidates = /* @__PURE__ */ new Map();
|
|
31807
|
+
const addAssetCandidate = (href, data) => {
|
|
31808
|
+
try {
|
|
31809
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
31810
|
+
if (isCopyableAssetPath(canonicalHref)) assetCandidates.set(canonicalHref, new Uint8Array(data));
|
|
31811
|
+
} catch {}
|
|
31812
|
+
};
|
|
31813
|
+
for (const resource of resources) if (resource.type === "webcontent" || resource.type.includes("associated")) for (const href of [resource.href, ...resource.files ?? []]) {
|
|
31814
|
+
const assetEntry = entries.get(normalizeHref(href));
|
|
31815
|
+
if (assetEntry) addAssetCandidate(href, assetEntry.data);
|
|
31320
31816
|
}
|
|
31321
31817
|
for (const [path, entry] of entries) {
|
|
31322
|
-
if (
|
|
31323
|
-
|
|
31324
|
-
|
|
31325
|
-
|
|
31326
|
-
|
|
31327
|
-
|
|
31328
|
-
|
|
31818
|
+
if (path === "imsmanifest.xml" || path.toLowerCase().endsWith(".xml")) continue;
|
|
31819
|
+
addAssetCandidate(path, entry.data);
|
|
31820
|
+
}
|
|
31821
|
+
const registry = new AssetFilenameRegistry(opts?.preserveAssetFilenames ?? false);
|
|
31822
|
+
const registerContextAsset = (context, rawHref, sourceHrefBase) => {
|
|
31823
|
+
const canonicalHref = resolvePackageAssetHref(rawHref, sourceHrefBase);
|
|
31824
|
+
if (!canonicalHref) return;
|
|
31825
|
+
const bytes = assetCandidates.get(canonicalHref);
|
|
31826
|
+
if (!bytes) return;
|
|
31827
|
+
const registration = registry.register(context.finalItemReference, canonicalHref, bytes);
|
|
31828
|
+
assets.set(registration.filename, registration.bytes);
|
|
31829
|
+
};
|
|
31830
|
+
for (const context of itemAssetContexts) {
|
|
31831
|
+
for (const rawHref of extractAssetHrefs(context.inputXml)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
31832
|
+
for (const passagePath of getAllPassageDataPaths(context.inputXml)) {
|
|
31833
|
+
const passageContent = opts?.fileAccess?.resolvePassageFile(passagePath, context.sourceFile);
|
|
31834
|
+
const passageHref = resolvePackageAssetHref(passagePath, context.sourceHref);
|
|
31835
|
+
const entryContent = passageHref ? entries.get(passageHref) : void 0;
|
|
31836
|
+
const resolvedPassageContent = passageContent ?? (entryContent ? decodeUtf8(entryContent.data) : void 0);
|
|
31837
|
+
if (!resolvedPassageContent) continue;
|
|
31838
|
+
for (const rawHref of extractAssetHrefs(resolvedPassageContent)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
31329
31839
|
}
|
|
31330
31840
|
}
|
|
31331
31841
|
return {
|
|
@@ -31338,6 +31848,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31338
31848
|
organisationId: opts?.organisationId,
|
|
31339
31849
|
mediaVault: opts?.mediaVault ?? false,
|
|
31340
31850
|
customAssetUrl: opts?.customAssetUrl,
|
|
31851
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31341
31852
|
itemReferenceSource: opts?.itemReferenceSource ?? "sourceFilename"
|
|
31342
31853
|
}
|
|
31343
31854
|
},
|
|
@@ -31359,7 +31870,25 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31359
31870
|
convertedActivityFiles
|
|
31360
31871
|
};
|
|
31361
31872
|
} catch (error) {
|
|
31362
|
-
diagnostics.push({
|
|
31873
|
+
if (error instanceof AssetFilenameConflictError) diagnostics.push({
|
|
31874
|
+
code: error.kind === "identity-bytes" ? DiagnosticCode.QTI_ASSET_IDENTITY_BYTES_CONFLICT : DiagnosticCode.QTI_ASSET_FILENAME_CONFLICT,
|
|
31875
|
+
level: "error",
|
|
31876
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
31877
|
+
message: error.message,
|
|
31878
|
+
context: {
|
|
31879
|
+
mode: error.mode,
|
|
31880
|
+
filename: error.filename,
|
|
31881
|
+
existingIdentity: error.existing.serializedIdentity,
|
|
31882
|
+
incomingIdentity: error.incoming.serializedIdentity
|
|
31883
|
+
}
|
|
31884
|
+
});
|
|
31885
|
+
else if (isUnsafeAssetHrefError(error)) diagnostics.push({
|
|
31886
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
31887
|
+
level: "error",
|
|
31888
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
31889
|
+
message: error.message
|
|
31890
|
+
});
|
|
31891
|
+
else diagnostics.push({
|
|
31363
31892
|
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
31364
31893
|
level: "error",
|
|
31365
31894
|
file: "root",
|