@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
|
@@ -181,6 +181,9 @@ const DiagnosticCode = {
|
|
|
181
181
|
QTI_PACKAGE_NO_CONTENT: "QTI_PACKAGE_NO_CONTENT",
|
|
182
182
|
QTI_PACKAGE_DUPLICATE_IDENTIFIER: "QTI_PACKAGE_DUPLICATE_IDENTIFIER",
|
|
183
183
|
QTI_ITEM_CONVERSION_FAILED: "QTI_ITEM_CONVERSION_FAILED",
|
|
184
|
+
QTI_ASSET_HREF_UNSAFE: "QTI_ASSET_HREF_UNSAFE",
|
|
185
|
+
QTI_ASSET_FILENAME_CONFLICT: "QTI_ASSET_FILENAME_CONFLICT",
|
|
186
|
+
QTI_ASSET_IDENTITY_BYTES_CONFLICT: "QTI_ASSET_IDENTITY_BYTES_CONFLICT",
|
|
184
187
|
LRN_BUNDLE_WRITTEN: "LRN_BUNDLE_WRITTEN",
|
|
185
188
|
QTI_DOWNGRADE_NAMESPACE: "QTI_DOWNGRADE_NAMESPACE",
|
|
186
189
|
QTI_DOWNGRADE_SCHEMA_LOCATION: "QTI_DOWNGRADE_SCHEMA_LOCATION",
|
|
@@ -22996,6 +22999,33 @@ function md5hex(input) {
|
|
|
22996
22999
|
return hex;
|
|
22997
23000
|
}
|
|
22998
23001
|
//#endregion
|
|
23002
|
+
//#region src/qti-to-learnosity/utils/mediaFeature.ts
|
|
23003
|
+
/**
|
|
23004
|
+
* Build a stable UUID-shaped identifier for a media feature.
|
|
23005
|
+
*
|
|
23006
|
+
* Feature output must remain identical for equivalent directory and ZIP
|
|
23007
|
+
* package conversions, so the identifier is derived from the final media URL
|
|
23008
|
+
* rather than generated randomly. The UUID version and variant bits are set
|
|
23009
|
+
* to keep the value compatible with consumers expecting a v4-shaped UUID.
|
|
23010
|
+
*/
|
|
23011
|
+
function buildMediaFeatureId(transformedUrl) {
|
|
23012
|
+
const hash = md5hex(transformedUrl).split("");
|
|
23013
|
+
const variant = [
|
|
23014
|
+
"8",
|
|
23015
|
+
"9",
|
|
23016
|
+
"a",
|
|
23017
|
+
"b"
|
|
23018
|
+
][parseInt(hash[16], 16) & 3];
|
|
23019
|
+
hash[12] = "4";
|
|
23020
|
+
hash[16] = variant;
|
|
23021
|
+
return `${hash.slice(0, 8).join("")}-${hash.slice(8, 12).join("")}-${hash.slice(12, 16).join("")}-${hash.slice(16, 20).join("")}-${hash.slice(20).join("")}`;
|
|
23022
|
+
}
|
|
23023
|
+
/** Build a Learnosity simple-feature span for audio or hosted video. */
|
|
23024
|
+
function buildMediaFeatureSpan(transformedUrl, kind, featureId = buildMediaFeatureId(transformedUrl)) {
|
|
23025
|
+
if (kind === "audio") return `<span class="learnosity-feature" data-player="button" data-simplefeature_id="${featureId}" data-src="${transformedUrl}" data-type="audioplayer"></span>`;
|
|
23026
|
+
return `<span class="learnosity-feature" data-player_type="hosted-video" data-simplefeature_id="${featureId}" data-src="${transformedUrl}" data-text_alternative.caption.src="" data-type="videoplayer"></span>`;
|
|
23027
|
+
}
|
|
23028
|
+
//#endregion
|
|
22999
23029
|
//#region src/qti-to-learnosity/utils/convertObjectElement.ts
|
|
23000
23030
|
/**
|
|
23001
23031
|
* Convert QTI <object> elements to appropriate Learnosity HTML elements
|
|
@@ -23047,7 +23077,7 @@ function buildDeterministicFeatureId(transformedUrl) {
|
|
|
23047
23077
|
* <object data="video.mp4" type="video/mp4"/>
|
|
23048
23078
|
* → <span class="learnosity-feature" data-player_type="hosted-video" data-simplefeature_id="..." data-src="[cdn-url]" data-text_alternative.caption.src="" data-type="videoplayer"></span>
|
|
23049
23079
|
*/
|
|
23050
|
-
function convertObjectToElement(objectTag, organisationId, mediaVault = false, customAssetUrl) {
|
|
23080
|
+
function convertObjectToElement(objectTag, organisationId, mediaVault = false, customAssetUrl, assetContext = {}) {
|
|
23051
23081
|
const dataMatch = objectTag.match(/data=["']([^"']+)["']/i);
|
|
23052
23082
|
const srcMatch = objectTag.match(/src=["']([^"']+)["']/i);
|
|
23053
23083
|
const typeMatch = objectTag.match(/type=["']([^"']+)["']/i);
|
|
@@ -23057,11 +23087,11 @@ function convertObjectToElement(objectTag, organisationId, mediaVault = false, c
|
|
|
23057
23087
|
if (!urlMatch) return objectTag;
|
|
23058
23088
|
const sourceUrl = urlMatch[1];
|
|
23059
23089
|
const category = getMimeTypeCategory(typeMatch ? typeMatch[1] : "");
|
|
23060
|
-
const transformedUrl = transformUrl(sourceUrl, organisationId, mediaVault, customAssetUrl);
|
|
23090
|
+
const transformedUrl = transformUrl(sourceUrl, organisationId, mediaVault, customAssetUrl, assetContext);
|
|
23061
23091
|
switch (category) {
|
|
23062
23092
|
case "image": return buildImageTag(transformedUrl, heightMatch, widthMatch);
|
|
23063
|
-
case "audio": return
|
|
23064
|
-
case "video": return
|
|
23093
|
+
case "audio": return buildMediaFeatureSpan(transformedUrl, "audio", buildDeterministicFeatureId(transformedUrl));
|
|
23094
|
+
case "video": return buildMediaFeatureSpan(transformedUrl, "video", buildDeterministicFeatureId(transformedUrl));
|
|
23065
23095
|
default: return objectTag.replace(sourceUrl, transformedUrl);
|
|
23066
23096
|
}
|
|
23067
23097
|
}
|
|
@@ -23105,55 +23135,139 @@ function normalizeTableClass(html) {
|
|
|
23105
23135
|
});
|
|
23106
23136
|
}
|
|
23107
23137
|
//#endregion
|
|
23108
|
-
//#region src/qti-to-learnosity/utils/
|
|
23138
|
+
//#region src/qti-to-learnosity/utils/assetIdentity.ts
|
|
23109
23139
|
/**
|
|
23110
|
-
*
|
|
23111
|
-
* TASK 030
|
|
23140
|
+
* Browser-safe helpers for identifying package-local QTI assets.
|
|
23112
23141
|
*
|
|
23113
|
-
*
|
|
23142
|
+
* QTI asset references are package-relative paths, not filesystem paths. Keeping
|
|
23143
|
+
* their canonical form here makes directory and ZIP inputs produce the same
|
|
23144
|
+
* identity while rejecting references that could escape the package root.
|
|
23114
23145
|
*/
|
|
23146
|
+
/** Asset extensions copied and rewritten by QTI → Learnosity conversion. */
|
|
23147
|
+
const QTI_ASSET_EXTENSIONS = [
|
|
23148
|
+
".png",
|
|
23149
|
+
".jpg",
|
|
23150
|
+
".jpeg",
|
|
23151
|
+
".gif",
|
|
23152
|
+
".svg",
|
|
23153
|
+
".webp",
|
|
23154
|
+
".bmp",
|
|
23155
|
+
".ico",
|
|
23156
|
+
".mp3",
|
|
23157
|
+
".mp4",
|
|
23158
|
+
".wav",
|
|
23159
|
+
".ogg",
|
|
23160
|
+
".webm",
|
|
23161
|
+
".ogv",
|
|
23162
|
+
".m4a",
|
|
23163
|
+
".m4v",
|
|
23164
|
+
".css",
|
|
23165
|
+
".woff",
|
|
23166
|
+
".woff2",
|
|
23167
|
+
".ttf",
|
|
23168
|
+
".eot",
|
|
23169
|
+
".pdf",
|
|
23170
|
+
".json"
|
|
23171
|
+
];
|
|
23172
|
+
function isSupportedQtiAssetPath(path) {
|
|
23173
|
+
const lowerPath = path.toLowerCase();
|
|
23174
|
+
return !lowerPath.endsWith(".html") && !lowerPath.endsWith(".htm") && QTI_ASSET_EXTENSIONS.some((extension) => lowerPath.endsWith(extension));
|
|
23175
|
+
}
|
|
23176
|
+
function isUnsafeQtiAssetHrefError(error) {
|
|
23177
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
23178
|
+
}
|
|
23115
23179
|
/**
|
|
23116
|
-
*
|
|
23117
|
-
|
|
23118
|
-
|
|
23119
|
-
|
|
23120
|
-
|
|
23121
|
-
|
|
23122
|
-
|
|
23123
|
-
|
|
23124
|
-
"
|
|
23125
|
-
|
|
23126
|
-
|
|
23127
|
-
"
|
|
23128
|
-
"
|
|
23129
|
-
"
|
|
23130
|
-
|
|
23131
|
-
|
|
23132
|
-
|
|
23133
|
-
|
|
23180
|
+
* Canonicalize a package-relative QTI asset href.
|
|
23181
|
+
*
|
|
23182
|
+
* Query strings and fragments are URL metadata and do not identify a different
|
|
23183
|
+
* package asset. Path separators are normalized to `/`, dot segments are
|
|
23184
|
+
* resolved, and traversal above the package root is rejected.
|
|
23185
|
+
*/
|
|
23186
|
+
function stripHrefMetadata(href) {
|
|
23187
|
+
const metadataStart = href.search(/[?#]/);
|
|
23188
|
+
return (metadataStart === -1 ? href : href.slice(0, metadataStart)).replaceAll("\\", "/");
|
|
23189
|
+
}
|
|
23190
|
+
function assertPackageRelativePath(path, href) {
|
|
23191
|
+
const isAbsolute = path.startsWith("/") || /^[A-Za-z]:/.test(path) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(path);
|
|
23192
|
+
if (!path || path.includes("\0") || isAbsolute) throw new Error(`Unsafe QTI asset href: ${href}`);
|
|
23193
|
+
if (path.endsWith("/")) throw new Error(`QTI asset href has no filename: ${href}`);
|
|
23194
|
+
}
|
|
23195
|
+
function normalizePathSegments(path, href) {
|
|
23196
|
+
const segments = [];
|
|
23197
|
+
for (const segment of path.split("/")) {
|
|
23198
|
+
if (!segment || segment === ".") continue;
|
|
23199
|
+
if (segment === "..") {
|
|
23200
|
+
if (segments.length === 0) throw new Error(`Unsafe QTI asset href: ${href}`);
|
|
23201
|
+
segments.pop();
|
|
23202
|
+
continue;
|
|
23203
|
+
}
|
|
23204
|
+
segments.push(segment);
|
|
23205
|
+
}
|
|
23206
|
+
if (segments.length === 0) throw new Error(`QTI asset href has no filename: ${href}`);
|
|
23207
|
+
return segments.join("/");
|
|
23208
|
+
}
|
|
23209
|
+
function canonicalizeQtiAssetHref(href) {
|
|
23210
|
+
if (typeof href !== "string") throw new TypeError("QTI asset href must be a string");
|
|
23211
|
+
const path = stripHrefMetadata(href);
|
|
23212
|
+
assertPackageRelativePath(path, href);
|
|
23213
|
+
return normalizePathSegments(path, href);
|
|
23214
|
+
}
|
|
23215
|
+
/** Return the final filename from a canonicalized package-relative href. */
|
|
23216
|
+
function extractQtiAssetBasename(href) {
|
|
23217
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
23218
|
+
return canonicalHref.slice(canonicalHref.lastIndexOf("/") + 1);
|
|
23219
|
+
}
|
|
23134
23220
|
/**
|
|
23135
|
-
*
|
|
23136
|
-
*
|
|
23137
|
-
* `RegExp.prototype.test` on non-global regexes, so they are safe to share.
|
|
23221
|
+
* Return the final filename extension, including its leading dot.
|
|
23222
|
+
* Dotfiles and filenames ending in a dot have no extension.
|
|
23138
23223
|
*/
|
|
23139
|
-
|
|
23140
|
-
|
|
23141
|
-
|
|
23142
|
-
|
|
23143
|
-
|
|
23144
|
-
/<source\s+[^>]*src=/i
|
|
23145
|
-
];
|
|
23146
|
-
/** Matches `<object ...>` (optionally with its closing tag) for element conversion. */
|
|
23147
|
-
const OBJECT_TAG_PATTERN = /<object\s+[^>]*>(?:<\/object>)?/gi;
|
|
23224
|
+
function extractQtiAssetExtension(href) {
|
|
23225
|
+
const basename = extractQtiAssetBasename(href);
|
|
23226
|
+
const extensionStart = basename.lastIndexOf(".");
|
|
23227
|
+
return extensionStart > 0 && extensionStart < basename.length - 1 ? basename.slice(extensionStart) : "";
|
|
23228
|
+
}
|
|
23148
23229
|
/**
|
|
23149
|
-
*
|
|
23230
|
+
* Serialize the item-scoped asset identity using an ordered JSON tuple.
|
|
23150
23231
|
*
|
|
23151
|
-
*
|
|
23152
|
-
*
|
|
23153
|
-
*
|
|
23154
|
-
* a single compiled instance across calls is safe.
|
|
23232
|
+
* JSON serialization is intentional: unlike delimiter-based concatenation, it
|
|
23233
|
+
* keeps the item reference and canonical href unambiguous when either value
|
|
23234
|
+
* contains punctuation that could otherwise be mistaken for a separator.
|
|
23155
23235
|
*/
|
|
23156
|
-
|
|
23236
|
+
function serializeQtiAssetIdentity(finalItemReference, qtiAssetHref) {
|
|
23237
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
23238
|
+
return JSON.stringify([finalItemReference, canonicalHref]);
|
|
23239
|
+
}
|
|
23240
|
+
/** Derive the lowercase MD5 hex hash for a canonical item-scoped identity. */
|
|
23241
|
+
function hashQtiAssetIdentity(finalItemReference, qtiAssetHref) {
|
|
23242
|
+
return md5hex(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
23243
|
+
}
|
|
23244
|
+
/**
|
|
23245
|
+
* Select the output filename for a package-local QTI asset.
|
|
23246
|
+
*
|
|
23247
|
+
* Hashed naming is the default so the full item-scoped identity, rather than a
|
|
23248
|
+
* globally ambiguous source basename, determines the output name. Only the
|
|
23249
|
+
* canonical source extension is retained after the digest. Preserve mode is
|
|
23250
|
+
* an explicit compatibility opt-out and returns the canonical final basename.
|
|
23251
|
+
*/
|
|
23252
|
+
function selectQtiAssetFilename(finalItemReference, qtiAssetHref, preserveAssetFilenames = false) {
|
|
23253
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
23254
|
+
if (preserveAssetFilenames) return extractQtiAssetBasename(canonicalHref);
|
|
23255
|
+
return `${hashQtiAssetIdentity(finalItemReference, canonicalHref)}${extractQtiAssetExtension(canonicalHref)}`;
|
|
23256
|
+
}
|
|
23257
|
+
//#endregion
|
|
23258
|
+
//#region src/qti-to-learnosity/utils/assetUrlTransform.ts
|
|
23259
|
+
/**
|
|
23260
|
+
* Asset URL transformation for Learnosity CDN
|
|
23261
|
+
* TASK 030
|
|
23262
|
+
*
|
|
23263
|
+
* Transforms asset URLs in HTML content to use Learnosity CDN URLs.
|
|
23264
|
+
*/
|
|
23265
|
+
/** Matches supported asset-bearing HTML attributes on any element. */
|
|
23266
|
+
const ASSET_ATTRIBUTE_PATTERN = /(<[A-Za-z][^>]*?\b(?:src|data|href)\s*=\s*["'])([^"']+)(["'][^>]*>)/gi;
|
|
23267
|
+
/** Matches <object ...> (optionally with its closing tag) for element conversion. */
|
|
23268
|
+
const OBJECT_TAG_PATTERN = /<object\s+[^>]*>(?:<\/object>)?/gi;
|
|
23269
|
+
/** Matches anchors whose href points to inline audio/video media. */
|
|
23270
|
+
const INLINE_MEDIA_LINK_PATTERN = /<a\b([^>]*?)\bhref\s*=\s*(["'])([^"']+)\2([^>]*)>([\s\S]*?)<\/a\s*>/gi;
|
|
23157
23271
|
/**
|
|
23158
23272
|
* Extract filename from a URL path
|
|
23159
23273
|
* Examples:
|
|
@@ -23165,12 +23279,26 @@ function extractFilename$1(url) {
|
|
|
23165
23279
|
const segments = url.split("?")[0].split("#")[0].split("/");
|
|
23166
23280
|
return segments[segments.length - 1];
|
|
23167
23281
|
}
|
|
23168
|
-
/**
|
|
23169
|
-
* Check if a filename has a supported asset extension
|
|
23170
|
-
*/
|
|
23171
23282
|
function isSupportedAsset(filename) {
|
|
23172
|
-
|
|
23173
|
-
|
|
23283
|
+
return isSupportedQtiAssetPath(filename);
|
|
23284
|
+
}
|
|
23285
|
+
function getInlineMediaKind(url, attributes) {
|
|
23286
|
+
const mimeType = attributes.match(/\btype\s*=\s*(["'])([^"']+)\1/i)?.[2].toLowerCase();
|
|
23287
|
+
if (mimeType?.startsWith("audio/")) return "audio";
|
|
23288
|
+
if (mimeType?.startsWith("video/")) return "video";
|
|
23289
|
+
const filename = extractFilename$1(url).toLowerCase();
|
|
23290
|
+
if ([
|
|
23291
|
+
".mp3",
|
|
23292
|
+
".wav",
|
|
23293
|
+
".ogg",
|
|
23294
|
+
".m4a"
|
|
23295
|
+
].some((extension) => filename.endsWith(extension))) return "audio";
|
|
23296
|
+
if ([
|
|
23297
|
+
".mp4",
|
|
23298
|
+
".webm",
|
|
23299
|
+
".ogv",
|
|
23300
|
+
".m4v"
|
|
23301
|
+
].some((extension) => filename.endsWith(extension))) return "video";
|
|
23174
23302
|
}
|
|
23175
23303
|
/**
|
|
23176
23304
|
* Build Learnosity CDN URL for an asset
|
|
@@ -23180,17 +23308,24 @@ function buildLearnosityAssetUrl(filename, organisationId, mediaVault = false, c
|
|
|
23180
23308
|
if (customAssetUrl) return `${customAssetUrl.endsWith("/") ? customAssetUrl.slice(0, -1) : customAssetUrl}/${filename}`;
|
|
23181
23309
|
return `https://${mediaVault ? "media-vault" : "assets"}.learnosity.com/organisations/${organisationId}/${filename}`;
|
|
23182
23310
|
}
|
|
23311
|
+
function resolveQtiAssetHref(url, sourceHrefBase) {
|
|
23312
|
+
const normalizedUrl = url.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
23313
|
+
const isItemRelative = /^\.\.?\//.test(normalizedUrl) || !normalizedUrl.includes("/");
|
|
23314
|
+
if (!sourceHrefBase || !isItemRelative) return canonicalizeQtiAssetHref(url);
|
|
23315
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
23316
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${normalizedUrl}`);
|
|
23317
|
+
}
|
|
23183
23318
|
/**
|
|
23184
23319
|
* Transform a single URL to Learnosity CDN format
|
|
23185
23320
|
* Exported for use in image object source fields
|
|
23186
23321
|
*/
|
|
23187
|
-
function transformUrl(url, organisationId, mediaVault = false, customAssetUrl) {
|
|
23322
|
+
function transformUrl(url, organisationId, mediaVault = false, customAssetUrl, context = {}) {
|
|
23188
23323
|
if (url.includes("assets.learnosity.com") || url.includes("media-vault.learnosity.com")) return url;
|
|
23189
|
-
if (
|
|
23324
|
+
if (/^https?:\/\//i.test(url) || url.startsWith("//")) return url;
|
|
23190
23325
|
if (url.startsWith("data:")) return url;
|
|
23191
23326
|
const filename = extractFilename$1(url);
|
|
23192
23327
|
if (!isSupportedAsset(filename)) return url;
|
|
23193
|
-
return buildLearnosityAssetUrl(filename, organisationId, mediaVault, customAssetUrl);
|
|
23328
|
+
return buildLearnosityAssetUrl(context.finalItemReference ? selectQtiAssetFilename(context.finalItemReference, resolveQtiAssetHref(url, context.sourceHrefBase), context.preserveAssetFilenames ?? false) : filename, organisationId, mediaVault, customAssetUrl);
|
|
23194
23329
|
}
|
|
23195
23330
|
/**
|
|
23196
23331
|
* Transform asset URLs in HTML content
|
|
@@ -23208,14 +23343,24 @@ function transformUrl(url, organisationId, mediaVault = false, customAssetUrl) {
|
|
|
23208
23343
|
*/
|
|
23209
23344
|
function transformAssetUrls(html, options) {
|
|
23210
23345
|
if (!html) return html;
|
|
23211
|
-
if (
|
|
23346
|
+
if (Array.from(html.matchAll(ASSET_ATTRIBUTE_PATTERN)).some((match) => isSupportedAsset(extractFilename$1(match[2]))) && !options.organisationId) throw new Error("Asset references found in QTI content but no --organisation_id provided. Please provide --organisation_id to convert assets to Learnosity CDN URLs.");
|
|
23212
23347
|
if (!options.organisationId) return normalizeTableClass(html);
|
|
23213
23348
|
const orgId = options.organisationId;
|
|
23214
23349
|
const mediaVault = options.mediaVault ?? false;
|
|
23215
23350
|
const customAssetUrl = options.customAssetUrl;
|
|
23351
|
+
const assetContext = {
|
|
23352
|
+
finalItemReference: options.finalItemReference,
|
|
23353
|
+
preserveAssetFilenames: options.preserveAssetFilenames,
|
|
23354
|
+
sourceHrefBase: options.sourceHrefBase
|
|
23355
|
+
};
|
|
23216
23356
|
let result = html;
|
|
23217
|
-
result = result.replace(OBJECT_TAG_PATTERN, (match) => convertObjectToElement(match, orgId, mediaVault, customAssetUrl));
|
|
23218
|
-
result = result.replace(
|
|
23357
|
+
result = result.replace(OBJECT_TAG_PATTERN, (match) => convertObjectToElement(match, orgId, mediaVault, customAssetUrl, assetContext));
|
|
23358
|
+
result = result.replace(INLINE_MEDIA_LINK_PATTERN, (match, beforeAttributes, _quote, url, afterAttributes) => {
|
|
23359
|
+
const kind = getInlineMediaKind(url, `${beforeAttributes}${afterAttributes}`);
|
|
23360
|
+
if (!kind) return match;
|
|
23361
|
+
return buildMediaFeatureSpan(transformUrl(url, orgId, mediaVault, customAssetUrl, assetContext), kind);
|
|
23362
|
+
});
|
|
23363
|
+
result = result.replace(ASSET_ATTRIBUTE_PATTERN, (_match, prefix, url, suffix) => prefix + transformUrl(url, orgId, mediaVault, customAssetUrl, assetContext) + suffix);
|
|
23219
23364
|
result = normalizeHtmlWhitespace(result);
|
|
23220
23365
|
result = normalizeTableClass(result);
|
|
23221
23366
|
return result;
|
|
@@ -23361,23 +23506,30 @@ function mapCorrectPairsToValidation(correctPairs, stemIdToIndex, optionIdToInde
|
|
|
23361
23506
|
/**
|
|
23362
23507
|
* Convert matchInteraction to Learnosity choicematrix
|
|
23363
23508
|
*/
|
|
23364
|
-
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23509
|
+
function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23365
23510
|
const parsed = readAssessmentItemMatch(inputXml);
|
|
23366
23511
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23367
23512
|
diagnostics.push(...updatedDiagnostics);
|
|
23368
23513
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23369
23514
|
if (!parsed.identifier || parsed.stems.length === 0 || parsed.options.length === 0) return { diagnostics };
|
|
23370
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23515
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23516
|
+
const transformContext = {
|
|
23517
|
+
finalItemReference: itemRef,
|
|
23518
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23519
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23520
|
+
};
|
|
23371
23521
|
const questionRef = md5hex(itemRef);
|
|
23372
23522
|
const stems = parsed.stems.map((stem) => transformAssetUrls(stem.text, {
|
|
23373
23523
|
organisationId,
|
|
23374
23524
|
mediaVault,
|
|
23375
|
-
customAssetUrl
|
|
23525
|
+
customAssetUrl,
|
|
23526
|
+
...transformContext
|
|
23376
23527
|
}));
|
|
23377
23528
|
const options = parsed.options.map((option) => transformAssetUrls(option.text, {
|
|
23378
23529
|
organisationId,
|
|
23379
23530
|
mediaVault,
|
|
23380
|
-
customAssetUrl
|
|
23531
|
+
customAssetUrl,
|
|
23532
|
+
...transformContext
|
|
23381
23533
|
}));
|
|
23382
23534
|
const stemIdToIndex = /* @__PURE__ */ new Map();
|
|
23383
23535
|
parsed.stems.forEach((stem, index) => {
|
|
@@ -23395,7 +23547,8 @@ function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId
|
|
|
23395
23547
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
23396
23548
|
organisationId,
|
|
23397
23549
|
mediaVault,
|
|
23398
|
-
customAssetUrl
|
|
23550
|
+
customAssetUrl,
|
|
23551
|
+
...transformContext
|
|
23399
23552
|
});
|
|
23400
23553
|
const item = {
|
|
23401
23554
|
item: {
|
|
@@ -23775,25 +23928,32 @@ function buildGapValidation(gaps, gapIdToGapTextIds, gapTextIdToContent, sourceF
|
|
|
23775
23928
|
/**
|
|
23776
23929
|
* Convert gapMatchInteraction to Learnosity clozeassociation
|
|
23777
23930
|
*/
|
|
23778
|
-
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
23931
|
+
function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
23779
23932
|
const parsed = readAssessmentItemGapMatch(inputXml);
|
|
23780
23933
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
23781
23934
|
diagnostics.push(...updatedDiagnostics);
|
|
23782
23935
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
23783
23936
|
if (!parsed.identifier || parsed.gapTexts.length === 0 || parsed.gaps.length === 0) return { diagnostics };
|
|
23784
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23937
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
23938
|
+
const transformContext = {
|
|
23939
|
+
finalItemReference: itemRef,
|
|
23940
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23941
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23942
|
+
};
|
|
23785
23943
|
const questionRef = md5hex(itemRef);
|
|
23786
23944
|
const possibleResponses = parsed.gapTexts.map((gt) => transformAssetUrls(gt.text, {
|
|
23787
23945
|
organisationId,
|
|
23788
23946
|
mediaVault,
|
|
23789
|
-
customAssetUrl
|
|
23947
|
+
customAssetUrl,
|
|
23948
|
+
...transformContext
|
|
23790
23949
|
}));
|
|
23791
23950
|
const gapTextIdToContent = /* @__PURE__ */ new Map();
|
|
23792
23951
|
parsed.gapTexts.forEach((gt) => {
|
|
23793
23952
|
const transformedText = transformAssetUrls(gt.text, {
|
|
23794
23953
|
organisationId,
|
|
23795
23954
|
mediaVault,
|
|
23796
|
-
customAssetUrl
|
|
23955
|
+
customAssetUrl,
|
|
23956
|
+
...transformContext
|
|
23797
23957
|
});
|
|
23798
23958
|
gapTextIdToContent.set(gt.identifier, transformedText);
|
|
23799
23959
|
});
|
|
@@ -23811,7 +23971,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23811
23971
|
template: transformAssetUrls(parsed.templateHtml ?? "", {
|
|
23812
23972
|
organisationId,
|
|
23813
23973
|
mediaVault,
|
|
23814
|
-
customAssetUrl
|
|
23974
|
+
customAssetUrl,
|
|
23975
|
+
...transformContext
|
|
23815
23976
|
}),
|
|
23816
23977
|
possible_responses: possibleResponses,
|
|
23817
23978
|
shuffle_options: parsed.shuffle ?? false,
|
|
@@ -23826,7 +23987,8 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23826
23987
|
if (parsed.promptHtml) questionData.stimulus = transformAssetUrls(parsed.promptHtml, {
|
|
23827
23988
|
organisationId,
|
|
23828
23989
|
mediaVault,
|
|
23829
|
-
customAssetUrl
|
|
23990
|
+
customAssetUrl,
|
|
23991
|
+
...transformContext
|
|
23830
23992
|
});
|
|
23831
23993
|
if (maxResponsesPerZone > 1) questionData.max_response_per_zone = maxResponsesPerZone;
|
|
23832
23994
|
const choiceCounts = /* @__PURE__ */ new Map();
|
|
@@ -24231,19 +24393,22 @@ function buildValidationValues(interactions, responseDeclarations, diagnostics,
|
|
|
24231
24393
|
* Convert inlineChoiceInteraction to Learnosity clozedropdown
|
|
24232
24394
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
24233
24395
|
*/
|
|
24234
|
-
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
24396
|
+
function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
24235
24397
|
const parsed = readAssessmentItemInlineChoice(inputXml);
|
|
24236
24398
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24237
24399
|
diagnostics.push(...updatedDiagnostics);
|
|
24238
24400
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24239
24401
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
24240
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24241
|
-
const questionRef = md5hex(itemRef);
|
|
24402
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24242
24403
|
const transformOpts = {
|
|
24243
24404
|
organisationId,
|
|
24244
24405
|
mediaVault,
|
|
24245
|
-
customAssetUrl
|
|
24406
|
+
customAssetUrl,
|
|
24407
|
+
finalItemReference: itemRef,
|
|
24408
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24409
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24246
24410
|
};
|
|
24411
|
+
const questionRef = md5hex(itemRef);
|
|
24247
24412
|
const possibleResponses = parsed.interactions.map((interaction) => interaction.choices.map((choice) => transformAssetUrls(choice.text, transformOpts)));
|
|
24248
24413
|
const validationValue = buildValidationValues(parsed.interactions, parsed.responseDeclarations, diagnostics, transformOpts, sourceFile);
|
|
24249
24414
|
if (!validationValue) return { diagnostics };
|
|
@@ -24510,23 +24675,30 @@ function readAssessmentItemOrder(inputXml) {
|
|
|
24510
24675
|
/**
|
|
24511
24676
|
* Convert orderInteraction to Learnosity orderlist
|
|
24512
24677
|
*/
|
|
24513
|
-
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
24678
|
+
function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
24514
24679
|
const parsed = readAssessmentItemOrder(inputXml);
|
|
24515
24680
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24516
24681
|
diagnostics.push(...updatedDiagnostics);
|
|
24517
24682
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
24518
24683
|
if (!parsed.identifier || !parsed.responseIdentifier || parsed.choices.length === 0) return { diagnostics };
|
|
24519
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24684
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
24685
|
+
const transformContext = {
|
|
24686
|
+
finalItemReference: itemRef,
|
|
24687
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24688
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24689
|
+
};
|
|
24520
24690
|
const questionRef = md5hex(itemRef);
|
|
24521
24691
|
const stimulus = transformAssetUrls(parsed.stimulusText ?? "", {
|
|
24522
24692
|
organisationId,
|
|
24523
24693
|
mediaVault,
|
|
24524
|
-
customAssetUrl
|
|
24694
|
+
customAssetUrl,
|
|
24695
|
+
...transformContext
|
|
24525
24696
|
});
|
|
24526
24697
|
const list = parsed.choices.map((choice) => transformAssetUrls(choice.text, {
|
|
24527
24698
|
organisationId,
|
|
24528
24699
|
mediaVault,
|
|
24529
|
-
customAssetUrl
|
|
24700
|
+
customAssetUrl,
|
|
24701
|
+
...transformContext
|
|
24530
24702
|
}));
|
|
24531
24703
|
let validationValue;
|
|
24532
24704
|
if (parsed.correctOrder && parsed.correctOrder.length > 0) {
|
|
@@ -24901,17 +25073,19 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics, sou
|
|
|
24901
25073
|
/**
|
|
24902
25074
|
* Build the combined stimulus HTML from parsed stimulusText and promptText
|
|
24903
25075
|
*/
|
|
24904
|
-
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
25076
|
+
function buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
24905
25077
|
let stimulus = "";
|
|
24906
25078
|
if (parsed.stimulusText) stimulus += transformAssetUrls(parsed.stimulusText, {
|
|
24907
25079
|
organisationId,
|
|
24908
25080
|
mediaVault,
|
|
24909
|
-
customAssetUrl
|
|
25081
|
+
customAssetUrl,
|
|
25082
|
+
...assetTransformContext
|
|
24910
25083
|
});
|
|
24911
25084
|
if (parsed.promptText) stimulus += `<p>${transformAssetUrls(parsed.promptText, {
|
|
24912
25085
|
organisationId,
|
|
24913
25086
|
mediaVault,
|
|
24914
|
-
customAssetUrl
|
|
25087
|
+
customAssetUrl,
|
|
25088
|
+
...assetTransformContext
|
|
24915
25089
|
})}</p>`;
|
|
24916
25090
|
return stimulus;
|
|
24917
25091
|
}
|
|
@@ -24936,7 +25110,7 @@ function buildHotspotValidation(correctResponses, choiceIdToIndex) {
|
|
|
24936
25110
|
/**
|
|
24937
25111
|
* Convert hotspotInteraction to Learnosity hotspot
|
|
24938
25112
|
*/
|
|
24939
|
-
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
25113
|
+
function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
24940
25114
|
const parsed = readAssessmentItemHotspot(inputXml);
|
|
24941
25115
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
24942
25116
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -24958,10 +25132,15 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
24958
25132
|
return { diagnostics };
|
|
24959
25133
|
}
|
|
24960
25134
|
}
|
|
24961
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25135
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25136
|
+
const transformContext = {
|
|
25137
|
+
finalItemReference: itemRef,
|
|
25138
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25139
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25140
|
+
};
|
|
24962
25141
|
const questionRef = md5hex(itemRef);
|
|
24963
|
-
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
24964
|
-
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl) : parsed.imageSource;
|
|
25142
|
+
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
25143
|
+
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.imageSource;
|
|
24965
25144
|
const areas = [];
|
|
24966
25145
|
const choiceIdToIndex = /* @__PURE__ */ new Map();
|
|
24967
25146
|
for (const choice of parsed.hotspotChoices) {
|
|
@@ -25244,14 +25423,19 @@ function readAssessmentItemHottext(inputXml) {
|
|
|
25244
25423
|
/**
|
|
25245
25424
|
* Convert hottextInteraction to Learnosity tokenhighlight
|
|
25246
25425
|
*/
|
|
25247
|
-
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
25426
|
+
function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
25248
25427
|
const parsed = readAssessmentItemHottext(inputXml);
|
|
25249
25428
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
25250
25429
|
diagnostics.push(...updatedDiagnostics);
|
|
25251
25430
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
25252
25431
|
if (!parsed.identifier || !parsed.responseIdentifier || !parsed.templateHtml) return { diagnostics };
|
|
25253
25432
|
if (parsed.hottextElements.length === 0) return { diagnostics };
|
|
25254
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25433
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25434
|
+
const transformContext = {
|
|
25435
|
+
finalItemReference: itemRef,
|
|
25436
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25437
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25438
|
+
};
|
|
25255
25439
|
const questionRef = md5hex(itemRef);
|
|
25256
25440
|
if (parsed.shuffle) diagnostics.push({
|
|
25257
25441
|
code: DiagnosticCode.QTI_SHUFFLE_NOT_SUPPORTED,
|
|
@@ -25263,7 +25447,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25263
25447
|
if (stimulus) stimulus = transformAssetUrls(stimulus, {
|
|
25264
25448
|
organisationId,
|
|
25265
25449
|
mediaVault,
|
|
25266
|
-
customAssetUrl
|
|
25450
|
+
customAssetUrl,
|
|
25451
|
+
...transformContext
|
|
25267
25452
|
});
|
|
25268
25453
|
let template = parsed.templateHtml || "";
|
|
25269
25454
|
const identifierToIndex = /* @__PURE__ */ new Map();
|
|
@@ -25276,7 +25461,8 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25276
25461
|
template = transformAssetUrls(template, {
|
|
25277
25462
|
organisationId,
|
|
25278
25463
|
mediaVault,
|
|
25279
|
-
customAssetUrl
|
|
25464
|
+
customAssetUrl,
|
|
25465
|
+
...transformContext
|
|
25280
25466
|
});
|
|
25281
25467
|
let validation = void 0;
|
|
25282
25468
|
if (parsed.correctResponses && parsed.correctResponses.length > 0) {
|
|
@@ -25743,7 +25929,7 @@ function readAssessmentItemMcq(inputXml, stimulusOverride) {
|
|
|
25743
25929
|
* Supports both single and composite (multiple) choiceInteractions
|
|
25744
25930
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
25745
25931
|
*/
|
|
25746
|
-
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
25932
|
+
function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
25747
25933
|
const parsed = readAssessmentItemMcq(inputXml, stimulusOverride);
|
|
25748
25934
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
25749
25935
|
...d,
|
|
@@ -25752,7 +25938,12 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25752
25938
|
diagnostics.push(...contextualDiagnostics);
|
|
25753
25939
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
25754
25940
|
if (!parsed.identifier || parsed.interactions.length === 0) return { diagnostics };
|
|
25755
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25941
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
25942
|
+
const transformContext = {
|
|
25943
|
+
finalItemReference: itemRef,
|
|
25944
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25945
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25946
|
+
};
|
|
25756
25947
|
const isComposite = parsed.interactions.length > 1;
|
|
25757
25948
|
const questions = [];
|
|
25758
25949
|
const widgets = [];
|
|
@@ -25762,7 +25953,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25762
25953
|
const stimulus = interaction.stimulusText ? transformAssetUrls(interaction.stimulusText, {
|
|
25763
25954
|
organisationId,
|
|
25764
25955
|
mediaVault,
|
|
25765
|
-
customAssetUrl
|
|
25956
|
+
customAssetUrl,
|
|
25957
|
+
...transformContext
|
|
25766
25958
|
}) : void 0;
|
|
25767
25959
|
const choiceMapping = /* @__PURE__ */ new Map();
|
|
25768
25960
|
const options = interaction.choices.map((choice) => {
|
|
@@ -25771,7 +25963,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25771
25963
|
label: transformAssetUrls(choice.text, {
|
|
25772
25964
|
organisationId,
|
|
25773
25965
|
mediaVault,
|
|
25774
|
-
customAssetUrl
|
|
25966
|
+
customAssetUrl,
|
|
25967
|
+
...transformContext
|
|
25775
25968
|
}),
|
|
25776
25969
|
value: choice.identifier
|
|
25777
25970
|
};
|
|
@@ -25808,7 +26001,8 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25808
26001
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
25809
26002
|
organisationId,
|
|
25810
26003
|
mediaVault,
|
|
25811
|
-
customAssetUrl
|
|
26004
|
+
customAssetUrl,
|
|
26005
|
+
...transformContext
|
|
25812
26006
|
}) : void 0;
|
|
25813
26007
|
questions.push({
|
|
25814
26008
|
reference: questionRef,
|
|
@@ -26176,7 +26370,7 @@ function stripWrapperDiv(html) {
|
|
|
26176
26370
|
* Convert textEntry (textEntryInteraction) to Learnosity clozetext or shorttext
|
|
26177
26371
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26178
26372
|
*/
|
|
26179
|
-
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26373
|
+
function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26180
26374
|
const parsed = readAssessmentItemTextEntry(inputXml, stimulusOverride);
|
|
26181
26375
|
const contextualDiagnostics = sourceFile ? parsed.diagnostics.map((d) => ({
|
|
26182
26376
|
...d,
|
|
@@ -26186,24 +26380,31 @@ function convertTextEntryToLearnosity(inputXml, diagnostics, lomTags, sourceFile
|
|
|
26186
26380
|
if (diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
26187
26381
|
if (!parsed.identifier || parsed.textEntries.length === 0) return { diagnostics };
|
|
26188
26382
|
if (typeof parsed.templateText === "string") parsed.templateText = stripWrapperDiv(parsed.templateText);
|
|
26189
|
-
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26190
|
-
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26383
|
+
if (parsed.textEntries.length === 1 && /{{response}}(?:\s*<\/[^>]+>)*\s*$/.test(parsed.templateText.trim())) return convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26384
|
+
else return convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26191
26385
|
}
|
|
26192
26386
|
/**
|
|
26193
26387
|
* Convert single textEntry to Learnosity shorttext
|
|
26194
26388
|
*/
|
|
26195
|
-
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26196
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26389
|
+
function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26390
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26391
|
+
const transformContext = {
|
|
26392
|
+
finalItemReference: itemRef,
|
|
26393
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26394
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26395
|
+
};
|
|
26197
26396
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26198
26397
|
const stimulus = normalizeFinalText(transformAssetUrls((parsed.templateText || "").replace(/{{response}}(?:\s*<\/[^>]+>)*\s*$/, "").trim(), {
|
|
26199
26398
|
organisationId,
|
|
26200
26399
|
mediaVault,
|
|
26201
|
-
customAssetUrl
|
|
26400
|
+
customAssetUrl,
|
|
26401
|
+
...transformContext
|
|
26202
26402
|
}));
|
|
26203
26403
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26204
26404
|
organisationId,
|
|
26205
26405
|
mediaVault,
|
|
26206
|
-
customAssetUrl
|
|
26406
|
+
customAssetUrl,
|
|
26407
|
+
...transformContext
|
|
26207
26408
|
}) : void 0;
|
|
26208
26409
|
const entry = parsed.textEntries[0];
|
|
26209
26410
|
const correctResponses = entry.correctResponses || (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -26277,25 +26478,33 @@ function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisation
|
|
|
26277
26478
|
/**
|
|
26278
26479
|
* Convert textEntry with template to Learnosity clozetext
|
|
26279
26480
|
*/
|
|
26280
|
-
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26481
|
+
function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26281
26482
|
const correctResponses = [];
|
|
26282
26483
|
for (const entry of parsed.textEntries) if (entry.correctResponse) correctResponses.push(entry.correctResponse);
|
|
26283
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26484
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
26485
|
+
const transformContext = {
|
|
26486
|
+
finalItemReference: itemRef,
|
|
26487
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26488
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26489
|
+
};
|
|
26284
26490
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
|
|
26285
26491
|
const stimulus = parsed.stimulusText ? normalizeFinalText(transformAssetUrls(parsed.stimulusText, {
|
|
26286
26492
|
organisationId,
|
|
26287
26493
|
mediaVault,
|
|
26288
|
-
customAssetUrl
|
|
26494
|
+
customAssetUrl,
|
|
26495
|
+
...transformContext
|
|
26289
26496
|
})) : void 0;
|
|
26290
26497
|
const template = normalizeFinalText(transformAssetUrls(parsed.templateText, {
|
|
26291
26498
|
organisationId,
|
|
26292
26499
|
mediaVault,
|
|
26293
|
-
customAssetUrl
|
|
26500
|
+
customAssetUrl,
|
|
26501
|
+
...transformContext
|
|
26294
26502
|
}));
|
|
26295
26503
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26296
26504
|
organisationId,
|
|
26297
26505
|
mediaVault,
|
|
26298
|
-
customAssetUrl
|
|
26506
|
+
customAssetUrl,
|
|
26507
|
+
...transformContext
|
|
26299
26508
|
}) : void 0;
|
|
26300
26509
|
const validation = {
|
|
26301
26510
|
scoring_type: "exactMatch",
|
|
@@ -26528,8 +26737,13 @@ function readAssessmentItemExtendedText(inputXml) {
|
|
|
26528
26737
|
/**
|
|
26529
26738
|
* Build multi-interaction extended text item (multiple longtextV2 questions)
|
|
26530
26739
|
*/
|
|
26531
|
-
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile) {
|
|
26532
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26740
|
+
function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26741
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26742
|
+
const transformContext = {
|
|
26743
|
+
finalItemReference: itemRef,
|
|
26744
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26745
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26746
|
+
};
|
|
26533
26747
|
const questions = [];
|
|
26534
26748
|
const widgets = [];
|
|
26535
26749
|
const questionSpans = [];
|
|
@@ -26539,7 +26753,8 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
|
|
|
26539
26753
|
const stimulus = transformAssetUrls(stimulusOverride[i], {
|
|
26540
26754
|
organisationId,
|
|
26541
26755
|
mediaVault,
|
|
26542
|
-
customAssetUrl
|
|
26756
|
+
customAssetUrl,
|
|
26757
|
+
...transformContext
|
|
26543
26758
|
});
|
|
26544
26759
|
widgets.push({
|
|
26545
26760
|
reference: questionRef,
|
|
@@ -26589,19 +26804,25 @@ function extractResponseIdentifiers(inputXml, interactionTag) {
|
|
|
26589
26804
|
* Convert extended text (extendedTextInteraction) to Learnosity longtextV2
|
|
26590
26805
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26591
26806
|
*/
|
|
26592
|
-
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride) {
|
|
26807
|
+
function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceFile, organisationId, mediaVault, customAssetUrl, itemReferenceSource, stimulusOverride, assetTransformContext) {
|
|
26593
26808
|
const parsed = readAssessmentItemExtendedText(inputXml);
|
|
26594
26809
|
const contextualDiagnostics = addFileContextIfProvided(stimulusOverride ? filterOutCodes(parsed.diagnostics, [DiagnosticCode.QTI_EXTENDED_TEXT_MULTIPLE_INTERACTIONS]) : parsed.diagnostics, sourceFile);
|
|
26595
26810
|
diagnostics.push(...contextualDiagnostics);
|
|
26596
26811
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
26597
|
-
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile);
|
|
26598
|
-
const itemRef = generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26812
|
+
if (stimulusOverride && stimulusOverride.length > 1) return buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext);
|
|
26813
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26814
|
+
const transformContext = {
|
|
26815
|
+
finalItemReference: itemRef,
|
|
26816
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26817
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26818
|
+
};
|
|
26599
26819
|
const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier ?? "unknown");
|
|
26600
26820
|
const stimulusRaw = stimulusOverride && stimulusOverride.length === 1 ? stimulusOverride[0] : parsed.stimulusText;
|
|
26601
26821
|
const stimulus = stimulusRaw ? transformAssetUrls(stimulusRaw, {
|
|
26602
26822
|
organisationId,
|
|
26603
26823
|
mediaVault,
|
|
26604
|
-
customAssetUrl
|
|
26824
|
+
customAssetUrl,
|
|
26825
|
+
...transformContext
|
|
26605
26826
|
}) : void 0;
|
|
26606
26827
|
const instructorStimulus = parsed.instructorStimulus ? transformAssetUrls(parsed.instructorStimulus, {
|
|
26607
26828
|
organisationId,
|
|
@@ -26896,7 +27117,7 @@ function buildValidationValue$1(hotspots, correctPairs, gapImgIdToResponse) {
|
|
|
26896
27117
|
/**
|
|
26897
27118
|
* Convert QTI graphicGapMatchInteraction to Learnosity imageclozeassociationV2
|
|
26898
27119
|
*/
|
|
26899
|
-
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27120
|
+
function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
26900
27121
|
const parsed = readAssessmentItemGraphicGapMatch(inputXml);
|
|
26901
27122
|
const contextualDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
26902
27123
|
diagnostics.push(...contextualDiagnostics);
|
|
@@ -26912,6 +27133,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26912
27133
|
}
|
|
26913
27134
|
const bgWidth = parsed.backgroundImage.width;
|
|
26914
27135
|
const bgHeight = parsed.backgroundImage.height;
|
|
27136
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27137
|
+
const transformContext = {
|
|
27138
|
+
finalItemReference: itemRef,
|
|
27139
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27140
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27141
|
+
};
|
|
26915
27142
|
const gapImgIdToResponse = /* @__PURE__ */ new Map();
|
|
26916
27143
|
const possible_responses = parsed.gapImages.map((g) => {
|
|
26917
27144
|
if (g.text !== void 0) {
|
|
@@ -26930,7 +27157,8 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26930
27157
|
const transformedImgTag = transformAssetUrls(imgTag, {
|
|
26931
27158
|
organisationId,
|
|
26932
27159
|
mediaVault,
|
|
26933
|
-
customAssetUrl
|
|
27160
|
+
customAssetUrl,
|
|
27161
|
+
...transformContext
|
|
26934
27162
|
});
|
|
26935
27163
|
gapImgIdToResponse.set(g.identifier, transformedImgTag);
|
|
26936
27164
|
return transformedImgTag;
|
|
@@ -26968,7 +27196,7 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26968
27196
|
const question = {
|
|
26969
27197
|
type: "imageclozeassociationV2",
|
|
26970
27198
|
image: {
|
|
26971
|
-
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl) : parsed.backgroundImage.src,
|
|
27199
|
+
src: organisationId ? transformUrl(parsed.backgroundImage.src, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.backgroundImage.src,
|
|
26972
27200
|
width: bgWidth,
|
|
26973
27201
|
height: bgHeight
|
|
26974
27202
|
},
|
|
@@ -26992,11 +27220,12 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
26992
27220
|
if (parsed.stimulus) question.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
26993
27221
|
organisationId,
|
|
26994
27222
|
mediaVault,
|
|
26995
|
-
customAssetUrl
|
|
27223
|
+
customAssetUrl,
|
|
27224
|
+
...transformContext
|
|
26996
27225
|
});
|
|
26997
27226
|
const item = {
|
|
26998
27227
|
item: {
|
|
26999
|
-
reference:
|
|
27228
|
+
reference: itemRef,
|
|
27000
27229
|
title: parsed.title ?? void 0,
|
|
27001
27230
|
definition: { widgets: [{
|
|
27002
27231
|
reference: questionRef,
|
|
@@ -27286,35 +27515,38 @@ const readAssessmentItemDrawing = createAssessmentItemReader({
|
|
|
27286
27515
|
/**
|
|
27287
27516
|
* Build drawing stimulus from parsed QTI data
|
|
27288
27517
|
*/
|
|
27289
|
-
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27518
|
+
function buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27290
27519
|
if (!parsed.stimulusText && !parsed.promptText) return;
|
|
27291
27520
|
const stimulus = parsed.promptText || parsed.stimulusText || "";
|
|
27292
27521
|
try {
|
|
27293
27522
|
return transformAssetUrls(stimulus, {
|
|
27294
27523
|
organisationId,
|
|
27295
27524
|
mediaVault,
|
|
27296
|
-
customAssetUrl
|
|
27525
|
+
customAssetUrl,
|
|
27526
|
+
...assetTransformContext
|
|
27297
27527
|
});
|
|
27298
|
-
} catch {
|
|
27528
|
+
} catch (error) {
|
|
27529
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27299
27530
|
return stimulus;
|
|
27300
27531
|
}
|
|
27301
27532
|
}
|
|
27302
27533
|
/**
|
|
27303
27534
|
* Transform a single image source URL
|
|
27304
27535
|
*/
|
|
27305
|
-
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl) {
|
|
27536
|
+
function transformImageSource(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27306
27537
|
try {
|
|
27307
|
-
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl) : imageSource;
|
|
27308
|
-
} catch {
|
|
27538
|
+
return organisationId ? transformUrl(imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) : imageSource;
|
|
27539
|
+
} catch (error) {
|
|
27540
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
27309
27541
|
return imageSource;
|
|
27310
27542
|
}
|
|
27311
27543
|
}
|
|
27312
27544
|
/**
|
|
27313
27545
|
* Build drawing image data from parsed QTI data
|
|
27314
27546
|
*/
|
|
27315
|
-
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
27547
|
+
function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, assetTransformContext) {
|
|
27316
27548
|
if (!parsed.imageSource) return;
|
|
27317
|
-
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl) };
|
|
27549
|
+
const image = { source: transformImageSource(parsed.imageSource, organisationId, mediaVault, customAssetUrl, assetTransformContext) };
|
|
27318
27550
|
if (parsed.imageWidth) image.width = parsed.imageWidth;
|
|
27319
27551
|
if (parsed.imageHeight) image.height = parsed.imageHeight;
|
|
27320
27552
|
if (parsed.imageAlt) image.alt = parsed.imageAlt;
|
|
@@ -27323,21 +27555,27 @@ function buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl) {
|
|
|
27323
27555
|
/**
|
|
27324
27556
|
* Convert QTI drawingInteraction to Learnosity drawing question
|
|
27325
27557
|
*/
|
|
27326
|
-
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27558
|
+
function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27327
27559
|
const parsed = readAssessmentItemDrawing(inputXml);
|
|
27328
27560
|
diagnostics.push(...parsed.diagnostics);
|
|
27329
27561
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
27330
|
-
const
|
|
27562
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
27563
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
27564
|
+
const transformContext = {
|
|
27565
|
+
finalItemReference: itemRef,
|
|
27566
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27567
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27568
|
+
};
|
|
27331
27569
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "drawing"));
|
|
27332
27570
|
const questionData = { type: "drawing" };
|
|
27333
|
-
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27571
|
+
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27334
27572
|
if (stimulus !== void 0) questionData.stimulus = stimulus;
|
|
27335
|
-
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl);
|
|
27573
|
+
const image = buildDrawingImage(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27336
27574
|
if (image) questionData.image = image;
|
|
27337
27575
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
27338
27576
|
const item = {
|
|
27339
27577
|
item: {
|
|
27340
|
-
reference:
|
|
27578
|
+
reference: itemRef,
|
|
27341
27579
|
title: parsed.title ?? void 0,
|
|
27342
27580
|
content,
|
|
27343
27581
|
definition: { widgets: [{
|
|
@@ -27627,7 +27865,7 @@ function buildValidationValue(choices, correctPairs, diagnostics, sourceFile) {
|
|
|
27627
27865
|
* This reflects the undirected-pair nature of associateInteraction: no choice is
|
|
27628
27866
|
* inherently a "category" or a "draggable" — both sides of a pair are equivalent.
|
|
27629
27867
|
*/
|
|
27630
|
-
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
27868
|
+
function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
27631
27869
|
const parsed = readAssessmentItemAssociation(inputXml);
|
|
27632
27870
|
const updatedDiagnostics = addFileContextIfProvided(parsed.diagnostics, sourceFile);
|
|
27633
27871
|
diagnostics.push(...updatedDiagnostics);
|
|
@@ -27635,17 +27873,24 @@ function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisa
|
|
|
27635
27873
|
if (!parsed.identifier || parsed.choices.length === 0) return { diagnostics };
|
|
27636
27874
|
const validationValue = buildValidationValue(parsed.choices, parsed.correctPairs, diagnostics, sourceFile);
|
|
27637
27875
|
if (hasErrors(diagnostics)) return { diagnostics };
|
|
27638
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27876
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
27877
|
+
const transformContext = {
|
|
27878
|
+
finalItemReference: itemRef,
|
|
27879
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27880
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27881
|
+
};
|
|
27639
27882
|
const questionRef = md5hex(itemRef);
|
|
27640
27883
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
27641
27884
|
organisationId,
|
|
27642
27885
|
mediaVault,
|
|
27643
|
-
customAssetUrl
|
|
27886
|
+
customAssetUrl,
|
|
27887
|
+
...transformContext
|
|
27644
27888
|
});
|
|
27645
27889
|
const possibleResponses = parsed.choices.map((c) => transformAssetUrls(c.text, {
|
|
27646
27890
|
organisationId,
|
|
27647
27891
|
mediaVault,
|
|
27648
|
-
customAssetUrl
|
|
27892
|
+
customAssetUrl,
|
|
27893
|
+
...transformContext
|
|
27649
27894
|
}));
|
|
27650
27895
|
const pairCount = validationValue.length > 0 ? validationValue.length : Math.round(parsed.maxAssociations ?? parsed.choices.length / 2);
|
|
27651
27896
|
const columnHeaders = Array.from({ length: pairCount }, (_, i) => `Pair ${i + 1}`);
|
|
@@ -28061,8 +28306,8 @@ function computeClosingTags(html) {
|
|
|
28061
28306
|
* Converters with different parameter orders are wrapped to normalize the signature.
|
|
28062
28307
|
*/
|
|
28063
28308
|
function getConverterMap() {
|
|
28064
|
-
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli);
|
|
28065
|
-
const hotspotConverter = (xml, diag, tags, orgId, sf, mv, cau, irs, _stimuli, fileAccess, packageRoot) => convertHotspotToLearnosity(xml, diag, tags, orgId, sf, mv, cau, irs, fileAccess, packageRoot);
|
|
28309
|
+
const wrapSourceFirst = (fn) => (xml, diag, tags, orgId, sf, mv, cau, irs, stimuli, assetTransformContext) => fn(xml, diag, tags, sf, orgId, mv, cau, irs, stimuli, assetTransformContext);
|
|
28310
|
+
const hotspotConverter = (xml, diag, tags, orgId, sf, mv, cau, irs, _stimuli, assetTransformContext, fileAccess, packageRoot) => convertHotspotToLearnosity(xml, diag, tags, orgId, sf, mv, cau, irs, fileAccess, packageRoot, assetTransformContext);
|
|
28066
28311
|
return {
|
|
28067
28312
|
choiceInteraction: wrapSourceFirst(convertMcqToLearnosity),
|
|
28068
28313
|
textEntryInteraction: wrapSourceFirst(convertTextEntryToLearnosity),
|
|
@@ -28085,8 +28330,14 @@ const CONVERTER_MAP = getConverterMap();
|
|
|
28085
28330
|
* Strategy: Call each individual converter for its interaction type,
|
|
28086
28331
|
* then combine all questions and widgets into a single composite item
|
|
28087
28332
|
*/
|
|
28088
|
-
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot) {
|
|
28333
|
+
function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, packageRoot, assetTransformContext) {
|
|
28089
28334
|
const metadata = extractItemMetadata(inputXml);
|
|
28335
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(metadata.identifier ?? "mixed_item", itemReferenceSource, sourceFile);
|
|
28336
|
+
const transformContext = {
|
|
28337
|
+
finalItemReference: itemRef,
|
|
28338
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28339
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28340
|
+
};
|
|
28090
28341
|
const { segments } = segmentItemBodyByInteractions(inputXml);
|
|
28091
28342
|
const stimuliByType = /* @__PURE__ */ new Map();
|
|
28092
28343
|
for (const segment of segments) {
|
|
@@ -28168,7 +28419,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28168
28419
|
const template = normalizeFinalText(transformAssetUrls(rawTemplate, {
|
|
28169
28420
|
organisationId,
|
|
28170
28421
|
mediaVault,
|
|
28171
|
-
customAssetUrl
|
|
28422
|
+
customAssetUrl,
|
|
28423
|
+
...transformContext
|
|
28172
28424
|
}));
|
|
28173
28425
|
if (groupEntries.length === 1 && /{{response}}(?:<\/[^>]+>|\s)*$/.test(rawTemplate.trim())) {
|
|
28174
28426
|
let stimulusRaw = rawTemplate.replace(/{{response}}(?:<\/[^>]+>|\s)*$/, "").trim();
|
|
@@ -28176,7 +28428,8 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28176
28428
|
const stimulus = normalizeFinalText(transformAssetUrls(stimulusRaw, {
|
|
28177
28429
|
organisationId,
|
|
28178
28430
|
mediaVault,
|
|
28179
|
-
customAssetUrl
|
|
28431
|
+
customAssetUrl,
|
|
28432
|
+
...transformContext
|
|
28180
28433
|
}));
|
|
28181
28434
|
const entry = groupEntries[0];
|
|
28182
28435
|
const allCorrectResponses = entry.correctResponses ?? (entry.correctResponse ? [entry.correctResponse] : []);
|
|
@@ -28302,7 +28555,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28302
28555
|
continue;
|
|
28303
28556
|
}
|
|
28304
28557
|
const converter = CONVERTER_MAP[group.type];
|
|
28305
|
-
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, fileAccess, packageRoot), subDiagnostics);
|
|
28558
|
+
if (converter) processResult(converter(inputXml, subDiagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, group.stimuli, transformContext, fileAccess, packageRoot), subDiagnostics);
|
|
28306
28559
|
}
|
|
28307
28560
|
if (allQuestions.length === 0) {
|
|
28308
28561
|
diagnostics.push({
|
|
@@ -28325,9 +28578,16 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28325
28578
|
passageContent = transformAssetUrls(rawContent, {
|
|
28326
28579
|
organisationId,
|
|
28327
28580
|
mediaVault,
|
|
28328
|
-
customAssetUrl
|
|
28581
|
+
customAssetUrl,
|
|
28582
|
+
...transformContext
|
|
28583
|
+
});
|
|
28584
|
+
} catch (error) {
|
|
28585
|
+
if (isUnsafeQtiAssetHrefError(error)) diagnostics.push({
|
|
28586
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
28587
|
+
level: "error",
|
|
28588
|
+
file: sourceFile ?? "passage",
|
|
28589
|
+
message: error.message
|
|
28329
28590
|
});
|
|
28330
|
-
} catch {
|
|
28331
28591
|
passageContent = rawContent;
|
|
28332
28592
|
}
|
|
28333
28593
|
allFeatures.push({
|
|
@@ -28359,7 +28619,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28359
28619
|
const content = `<div class="row"><div class="col-xs-12">${[...featureSpans, ...questionSpans].join("")}</div></div>`;
|
|
28360
28620
|
const item = {
|
|
28361
28621
|
item: {
|
|
28362
|
-
reference:
|
|
28622
|
+
reference: itemRef,
|
|
28363
28623
|
title: metadata.title ?? void 0,
|
|
28364
28624
|
content,
|
|
28365
28625
|
definition: { widgets: allWidgets },
|
|
@@ -28405,8 +28665,13 @@ function resolvePassageObjects(html, sourceFile, resolvePassageFile) {
|
|
|
28405
28665
|
/**
|
|
28406
28666
|
* Convert passage-only item to Learnosity format with sharedpassage feature
|
|
28407
28667
|
*/
|
|
28408
|
-
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess) {
|
|
28409
|
-
const itemRef = generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28668
|
+
function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, fileAccess, assetTransformContext) {
|
|
28669
|
+
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier, itemReferenceSource, sourceFile);
|
|
28670
|
+
const transformContext = {
|
|
28671
|
+
finalItemReference: itemRef,
|
|
28672
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
28673
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
28674
|
+
};
|
|
28410
28675
|
const featureRef = `passage-${md5hex(getPassageDataPath(parsed.content) ?? itemRef).substring(0, 8)}`;
|
|
28411
28676
|
const resolvedContent = resolvePassageObjects(parsed.content, sourceFile, fileAccess?.resolvePassageFile.bind(fileAccess));
|
|
28412
28677
|
let content;
|
|
@@ -28414,11 +28679,12 @@ function convertPassageToLearnosity(parsed, diagnostics, lomTags, organisationId
|
|
|
28414
28679
|
content = transformAssetUrls(resolvedContent, {
|
|
28415
28680
|
organisationId,
|
|
28416
28681
|
mediaVault,
|
|
28417
|
-
customAssetUrl
|
|
28682
|
+
customAssetUrl,
|
|
28683
|
+
...transformContext
|
|
28418
28684
|
});
|
|
28419
28685
|
} catch (error) {
|
|
28420
28686
|
diagnostics.push({
|
|
28421
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28687
|
+
code: isUnsafeQtiAssetHrefError(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
28422
28688
|
level: "error",
|
|
28423
28689
|
file: sourceFile ?? "assessmentItem",
|
|
28424
28690
|
message: error instanceof Error ? error.message : "Failed to transform asset URLs"
|
|
@@ -28808,20 +29074,28 @@ function readAssessmentItemUpload(inputXml) {
|
|
|
28808
29074
|
* and the file limit from `maxChoices` (see readAssessmentItemUpload / the
|
|
28809
29075
|
* serializer). fileupload questions are unscored, so there is no validation.
|
|
28810
29076
|
*/
|
|
28811
|
-
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource) {
|
|
29077
|
+
function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationId, sourceFile, mediaVault, customAssetUrl, itemReferenceSource, _stimulusOverride, assetTransformContext) {
|
|
28812
29078
|
const parsed = readAssessmentItemUpload(inputXml);
|
|
28813
29079
|
diagnostics.push(...parsed.diagnostics);
|
|
28814
29080
|
if (parsed.diagnostics.some((d) => d.level === "error")) return { diagnostics };
|
|
28815
|
-
const
|
|
29081
|
+
const generatedItemRef = generateItemReference(parsed.identifier ?? "item", itemReferenceSource, sourceFile);
|
|
29082
|
+
const itemRef = assetTransformContext?.finalItemReference ?? parsed.identifier ?? generatedItemRef;
|
|
29083
|
+
const transformContext = {
|
|
29084
|
+
finalItemReference: itemRef,
|
|
29085
|
+
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
29086
|
+
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
29087
|
+
};
|
|
28816
29088
|
const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "fileupload"));
|
|
28817
29089
|
const questionData = { type: "fileupload" };
|
|
28818
29090
|
if (parsed.stimulus) try {
|
|
28819
29091
|
questionData.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
28820
29092
|
organisationId,
|
|
28821
29093
|
mediaVault,
|
|
28822
|
-
customAssetUrl
|
|
29094
|
+
customAssetUrl,
|
|
29095
|
+
...transformContext
|
|
28823
29096
|
});
|
|
28824
|
-
} catch {
|
|
29097
|
+
} catch (error) {
|
|
29098
|
+
if (isUnsafeQtiAssetHrefError(error)) throw error;
|
|
28825
29099
|
questionData.stimulus = parsed.stimulus;
|
|
28826
29100
|
}
|
|
28827
29101
|
for (const suffix of parsed.allowedFileTypes) questionData[`allow_${suffix}`] = true;
|
|
@@ -28829,7 +29103,7 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28829
29103
|
const content = `<span class="learnosity-response question-${questionRef}"></span>`;
|
|
28830
29104
|
const item = {
|
|
28831
29105
|
item: {
|
|
28832
|
-
reference:
|
|
29106
|
+
reference: itemRef,
|
|
28833
29107
|
title: parsed.title ?? void 0,
|
|
28834
29108
|
content,
|
|
28835
29109
|
definition: { widgets: [{
|
|
@@ -28864,9 +29138,19 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
28864
29138
|
* - Rejects DOCTYPE / ENTITY declarations up-front (DTD not allowed).
|
|
28865
29139
|
* - Uses streaming parsers for all interaction types.
|
|
28866
29140
|
*/
|
|
29141
|
+
function getAssetSourceHrefBase(opts) {
|
|
29142
|
+
if (opts.sourceHrefBase) return opts.sourceHrefBase;
|
|
29143
|
+
const source = opts.sourceFile ?? opts.inputPath;
|
|
29144
|
+
if (!source) return;
|
|
29145
|
+
const normalized = source.replaceAll("\\", "/");
|
|
29146
|
+
return normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(normalized) ? normalized.slice(normalized.lastIndexOf("/") + 1) : normalized;
|
|
29147
|
+
}
|
|
28867
29148
|
/**
|
|
28868
29149
|
* Supported interaction type names for counting
|
|
28869
29150
|
*/
|
|
29151
|
+
function isUnsafeAssetHrefError$1(error) {
|
|
29152
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
29153
|
+
}
|
|
28870
29154
|
const INTERACTION_NAMES = [
|
|
28871
29155
|
"choiceInteraction",
|
|
28872
29156
|
"textEntryInteraction",
|
|
@@ -28932,19 +29216,71 @@ function countAllInteractions(xml) {
|
|
|
28932
29216
|
};
|
|
28933
29217
|
}
|
|
28934
29218
|
const SINGLE_INTERACTION_CONVERTERS = /* @__PURE__ */ new Map([
|
|
28935
|
-
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim
|
|
28936
|
-
|
|
28937
|
-
|
|
28938
|
-
|
|
28939
|
-
|
|
28940
|
-
["
|
|
28941
|
-
|
|
28942
|
-
|
|
28943
|
-
|
|
28944
|
-
|
|
28945
|
-
["
|
|
28946
|
-
|
|
28947
|
-
|
|
29219
|
+
["choiceInteraction", (xml, diag, lom, opts, stim) => convertMcqToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29220
|
+
finalItemReference: opts.finalItemReference,
|
|
29221
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29222
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29223
|
+
})],
|
|
29224
|
+
["textEntryInteraction", (xml, diag, lom, opts, stim) => convertTextEntryToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29225
|
+
finalItemReference: opts.finalItemReference,
|
|
29226
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29227
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29228
|
+
})],
|
|
29229
|
+
["extendedTextInteraction", (xml, diag, lom, opts, stim) => convertExtendedTextToLearnosity(xml, diag, lom, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, stim, {
|
|
29230
|
+
finalItemReference: opts.finalItemReference,
|
|
29231
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29232
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29233
|
+
})],
|
|
29234
|
+
["inlineChoiceInteraction", (xml, diag, lom, opts) => convertInlineChoiceToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29235
|
+
finalItemReference: opts.finalItemReference,
|
|
29236
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29237
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29238
|
+
})],
|
|
29239
|
+
["matchInteraction", (xml, diag, lom, opts) => convertMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29240
|
+
finalItemReference: opts.finalItemReference,
|
|
29241
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29242
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29243
|
+
})],
|
|
29244
|
+
["gapMatchInteraction", (xml, diag, lom, opts) => convertGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29245
|
+
finalItemReference: opts.finalItemReference,
|
|
29246
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29247
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29248
|
+
})],
|
|
29249
|
+
["orderInteraction", (xml, diag, lom, opts) => convertOrderToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29250
|
+
finalItemReference: opts.finalItemReference,
|
|
29251
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29252
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29253
|
+
})],
|
|
29254
|
+
["hotspotInteraction", (xml, diag, lom, opts) => convertHotspotToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29255
|
+
finalItemReference: opts.finalItemReference,
|
|
29256
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29257
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29258
|
+
})],
|
|
29259
|
+
["hottextInteraction", (xml, diag, lom, opts) => convertHottextToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29260
|
+
finalItemReference: opts.finalItemReference,
|
|
29261
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29262
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29263
|
+
})],
|
|
29264
|
+
["graphicGapMatchInteraction", (xml, diag, lom, opts) => convertGraphicGapMatchToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29265
|
+
finalItemReference: opts.finalItemReference,
|
|
29266
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29267
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29268
|
+
})],
|
|
29269
|
+
["drawingInteraction", (xml, diag, lom, opts) => convertDrawingToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29270
|
+
finalItemReference: opts.finalItemReference,
|
|
29271
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29272
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29273
|
+
})],
|
|
29274
|
+
["associateInteraction", (xml, diag, lom, opts) => convertAssociationToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29275
|
+
finalItemReference: opts.finalItemReference,
|
|
29276
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29277
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29278
|
+
})],
|
|
29279
|
+
["uploadInteraction", (xml, diag, lom, opts) => convertUploadToLearnosity(xml, diag, lom, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29280
|
+
finalItemReference: opts.finalItemReference,
|
|
29281
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29282
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29283
|
+
})]
|
|
28948
29284
|
]);
|
|
28949
29285
|
/**
|
|
28950
29286
|
* Dispatch to the appropriate single-interaction converter
|
|
@@ -28970,9 +29306,18 @@ function dispatchSingleInteractionConverter(interactionType, inputXml, count, di
|
|
|
28970
29306
|
passageContent = transformAssetUrls(rawContent, {
|
|
28971
29307
|
organisationId: opts.organisationId,
|
|
28972
29308
|
mediaVault: opts.mediaVault,
|
|
28973
|
-
customAssetUrl: opts.customAssetUrl
|
|
29309
|
+
customAssetUrl: opts.customAssetUrl,
|
|
29310
|
+
finalItemReference: opts.finalItemReference ?? result.item.item.reference,
|
|
29311
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29312
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29313
|
+
});
|
|
29314
|
+
} catch (error) {
|
|
29315
|
+
if (isUnsafeAssetHrefError$1(error)) diagnostics.push({
|
|
29316
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
29317
|
+
level: "error",
|
|
29318
|
+
file: opts.sourceFile ?? "passage",
|
|
29319
|
+
message: error.message
|
|
28974
29320
|
});
|
|
28975
|
-
} catch {
|
|
28976
29321
|
passageContent = rawContent;
|
|
28977
29322
|
}
|
|
28978
29323
|
result.item.features = [...result.item.features, {
|
|
@@ -29020,8 +29365,16 @@ function handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, o
|
|
|
29020
29365
|
}
|
|
29021
29366
|
const passageResult = readAssessmentItemPassage(inputXml);
|
|
29022
29367
|
diagnostics.push(...addFileContextIfProvided(passageResult.diagnostics, opts.sourceFile));
|
|
29023
|
-
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess
|
|
29024
|
-
|
|
29368
|
+
if (passageResult.data) return convertPassageToLearnosity(passageResult.data, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, {
|
|
29369
|
+
finalItemReference: opts.finalItemReference,
|
|
29370
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29371
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29372
|
+
});
|
|
29373
|
+
const mcqResult = convertMcqToLearnosity(inputXml, diagnostics, lomTags, opts.sourceFile, opts.organisationId, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, void 0, {
|
|
29374
|
+
finalItemReference: opts.finalItemReference,
|
|
29375
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29376
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29377
|
+
});
|
|
29025
29378
|
if (diagnostics.some((d) => d.code === DiagnosticCode.LRN_SCHEMA_INVALID)) return mcqResult;
|
|
29026
29379
|
return { diagnostics };
|
|
29027
29380
|
}
|
|
@@ -29067,14 +29420,18 @@ function convertQtiAssessmentItemToLearnosity(inputXml, opts = {}) {
|
|
|
29067
29420
|
const { counts, allInteractions } = countAllInteractions(inputXml);
|
|
29068
29421
|
const presentTypes = INTERACTION_NAMES.filter((name) => counts[name] > 0);
|
|
29069
29422
|
if (presentTypes.reduce((sum, name) => sum + counts[name], 0) === 0) return handleNoInteractions(inputXml, diagnostics, allInteractions, lomTags, opts);
|
|
29070
|
-
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot
|
|
29423
|
+
if (presentTypes.length > 1) return convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, opts.organisationId, opts.sourceFile, opts.mediaVault, opts.customAssetUrl, opts.itemReferenceSource, opts.fileAccess, opts.packageRoot, {
|
|
29424
|
+
finalItemReference: opts.finalItemReference,
|
|
29425
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29426
|
+
sourceHrefBase: getAssetSourceHrefBase(opts)
|
|
29427
|
+
});
|
|
29071
29428
|
return dispatchSingleInteractionConverter(presentTypes[0], inputXml, counts[presentTypes[0]], diagnostics, lomTags, opts);
|
|
29072
29429
|
} catch (error) {
|
|
29073
29430
|
diagnostics.push({
|
|
29074
|
-
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29431
|
+
code: isUnsafeAssetHrefError$1(error) ? DiagnosticCode.QTI_ASSET_HREF_UNSAFE : DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
29075
29432
|
level: "error",
|
|
29076
|
-
file: "root",
|
|
29077
|
-
message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29433
|
+
file: opts.sourceFile ?? "root",
|
|
29434
|
+
message: isUnsafeAssetHrefError$1(error) ? error.message : `Failed to parse QTI XML: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
29078
29435
|
});
|
|
29079
29436
|
return { diagnostics };
|
|
29080
29437
|
}
|
|
@@ -29190,6 +29547,7 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29190
29547
|
organisationId: opts.organisationId,
|
|
29191
29548
|
mediaVault: opts.mediaVault,
|
|
29192
29549
|
customAssetUrl: opts.customAssetUrl,
|
|
29550
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29193
29551
|
itemReferenceSource: opts.itemReferenceSource,
|
|
29194
29552
|
fileAccess: opts.fileAccess
|
|
29195
29553
|
});
|
|
@@ -31408,6 +31766,108 @@ function textToBytes(text) {
|
|
|
31408
31766
|
return strToU8(text);
|
|
31409
31767
|
}
|
|
31410
31768
|
//#endregion
|
|
31769
|
+
//#region src/qti-to-learnosity/utils/assetFilenameRegistry.ts
|
|
31770
|
+
/**
|
|
31771
|
+
* Browser-safe registry for item-scoped QTI asset filenames.
|
|
31772
|
+
*
|
|
31773
|
+
* Filename selection belongs to asset identity, not package traversal. Keeping
|
|
31774
|
+
* both identity and filename indexes here lets URL and bundle seams validate
|
|
31775
|
+
* the same contract before either one can overwrite a physical asset.
|
|
31776
|
+
*/
|
|
31777
|
+
var AssetFilenameConflictError = class extends Error {
|
|
31778
|
+
kind;
|
|
31779
|
+
mode;
|
|
31780
|
+
filename;
|
|
31781
|
+
existing;
|
|
31782
|
+
incoming;
|
|
31783
|
+
constructor(kind, mode, filename, existing, incoming) {
|
|
31784
|
+
const existingIdentity = existing.serializedIdentity;
|
|
31785
|
+
const incomingIdentity = incoming.serializedIdentity;
|
|
31786
|
+
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}.`;
|
|
31787
|
+
super(message);
|
|
31788
|
+
this.name = "AssetFilenameConflictError";
|
|
31789
|
+
this.kind = kind;
|
|
31790
|
+
this.mode = mode;
|
|
31791
|
+
this.filename = filename;
|
|
31792
|
+
this.existing = existing;
|
|
31793
|
+
this.incoming = incoming;
|
|
31794
|
+
}
|
|
31795
|
+
};
|
|
31796
|
+
function bytesEqual(left, right) {
|
|
31797
|
+
if (left.length !== right.length) return false;
|
|
31798
|
+
for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
|
|
31799
|
+
return true;
|
|
31800
|
+
}
|
|
31801
|
+
function cloneBytes(bytes) {
|
|
31802
|
+
return new Uint8Array(bytes);
|
|
31803
|
+
}
|
|
31804
|
+
/**
|
|
31805
|
+
* Track selected asset names and their bytes for one conversion.
|
|
31806
|
+
*
|
|
31807
|
+
* Registering an equivalent identity repeatedly is idempotent when its bytes
|
|
31808
|
+
* agree. A filename can never silently change owners, and an identity can
|
|
31809
|
+
* never silently change bytes, in either hashed or preserve mode.
|
|
31810
|
+
*/
|
|
31811
|
+
var AssetFilenameRegistry = class {
|
|
31812
|
+
preserveAssetFilenames;
|
|
31813
|
+
byIdentity = /* @__PURE__ */ new Map();
|
|
31814
|
+
byFilename = /* @__PURE__ */ new Map();
|
|
31815
|
+
constructor(preserveAssetFilenames = false) {
|
|
31816
|
+
this.preserveAssetFilenames = preserveAssetFilenames;
|
|
31817
|
+
}
|
|
31818
|
+
get mode() {
|
|
31819
|
+
return this.preserveAssetFilenames ? "preserve" : "hashed";
|
|
31820
|
+
}
|
|
31821
|
+
get size() {
|
|
31822
|
+
return this.byIdentity.size;
|
|
31823
|
+
}
|
|
31824
|
+
/**
|
|
31825
|
+
* Register an asset and return its selected filename and bytes.
|
|
31826
|
+
*
|
|
31827
|
+
* The input href is canonicalized before both indexes are consulted, so
|
|
31828
|
+
* equivalent directory and ZIP representations reuse one registration.
|
|
31829
|
+
*/
|
|
31830
|
+
register(finalItemReference, qtiAssetHref, bytes) {
|
|
31831
|
+
const canonicalHref = canonicalizeQtiAssetHref(qtiAssetHref);
|
|
31832
|
+
const serializedIdentity = serializeQtiAssetIdentity(finalItemReference, canonicalHref);
|
|
31833
|
+
const filename = selectQtiAssetFilename(finalItemReference, canonicalHref, this.preserveAssetFilenames);
|
|
31834
|
+
const incoming = {
|
|
31835
|
+
finalItemReference,
|
|
31836
|
+
qtiAssetHref: canonicalHref,
|
|
31837
|
+
serializedIdentity,
|
|
31838
|
+
filename,
|
|
31839
|
+
bytes: cloneBytes(bytes)
|
|
31840
|
+
};
|
|
31841
|
+
const existingIdentity = this.byIdentity.get(serializedIdentity);
|
|
31842
|
+
if (existingIdentity) {
|
|
31843
|
+
if (!bytesEqual(existingIdentity.bytes, incoming.bytes)) throw new AssetFilenameConflictError("identity-bytes", this.mode, filename, existingIdentity, incoming);
|
|
31844
|
+
return existingIdentity;
|
|
31845
|
+
}
|
|
31846
|
+
const existingFilename = this.byFilename.get(filename);
|
|
31847
|
+
if (existingFilename) throw new AssetFilenameConflictError("filename-identity", this.mode, filename, existingFilename, incoming);
|
|
31848
|
+
this.byIdentity.set(serializedIdentity, incoming);
|
|
31849
|
+
this.byFilename.set(filename, incoming);
|
|
31850
|
+
return incoming;
|
|
31851
|
+
}
|
|
31852
|
+
/** Look up a previously registered canonical identity without registering it. */
|
|
31853
|
+
get(finalItemReference, qtiAssetHref) {
|
|
31854
|
+
return this.byIdentity.get(serializeQtiAssetIdentity(finalItemReference, qtiAssetHref));
|
|
31855
|
+
}
|
|
31856
|
+
/** Look up an asset by its selected bundle-relative filename. */
|
|
31857
|
+
getByFilename(filename) {
|
|
31858
|
+
return this.byFilename.get(filename);
|
|
31859
|
+
}
|
|
31860
|
+
/** Iterate registrations in deterministic registration order. */
|
|
31861
|
+
entries() {
|
|
31862
|
+
return this.byIdentity.values();
|
|
31863
|
+
}
|
|
31864
|
+
/** Remove all registrations so the registry can be reused for a new conversion. */
|
|
31865
|
+
clear() {
|
|
31866
|
+
this.byIdentity.clear();
|
|
31867
|
+
this.byFilename.clear();
|
|
31868
|
+
}
|
|
31869
|
+
};
|
|
31870
|
+
//#endregion
|
|
31411
31871
|
//#region src/qti-to-learnosity/convertQtiPackageToLearnosityBundle.ts
|
|
31412
31872
|
/**
|
|
31413
31873
|
* QTI Content Package → Learnosity Bundle converter (v1)
|
|
@@ -31455,57 +31915,69 @@ function ensureFailedItemDiagnostic(itemDiagnostics, href) {
|
|
|
31455
31915
|
}];
|
|
31456
31916
|
}
|
|
31457
31917
|
/**
|
|
31458
|
-
* Normalize a forward-slash relative path (collapse `.`/`//`, resolve `..`).
|
|
31459
|
-
* Pure replacement for `node:path`'s `normalize(...).split(sep).join('/')` on
|
|
31460
|
-
* the forward-slash paths used as entry keys.
|
|
31461
|
-
*/
|
|
31462
|
-
function normalizePosix(p) {
|
|
31463
|
-
const parts = [];
|
|
31464
|
-
for (const seg of p.split("/")) {
|
|
31465
|
-
if (seg === "" || seg === ".") continue;
|
|
31466
|
-
if (seg === "..") {
|
|
31467
|
-
parts.pop();
|
|
31468
|
-
continue;
|
|
31469
|
-
}
|
|
31470
|
-
parts.push(seg);
|
|
31471
|
-
}
|
|
31472
|
-
return parts.join("/");
|
|
31473
|
-
}
|
|
31474
|
-
/**
|
|
31475
31918
|
* Normalize href path by removing leading ./ sequences
|
|
31476
31919
|
* This ensures manifest hrefs like "./items/foo.xml" match entries stored as "items/foo.xml"
|
|
31477
31920
|
*/
|
|
31478
31921
|
function normalizeHref(href) {
|
|
31479
31922
|
return href.replace(/^(\.\/)+/, "");
|
|
31480
31923
|
}
|
|
31481
|
-
|
|
31482
|
-
|
|
31483
|
-
|
|
31484
|
-
|
|
31485
|
-
|
|
31486
|
-
|
|
31487
|
-
|
|
31488
|
-
|
|
31489
|
-
|
|
31490
|
-
|
|
31491
|
-
|
|
31492
|
-
|
|
31493
|
-
|
|
31494
|
-
".
|
|
31495
|
-
|
|
31496
|
-
|
|
31497
|
-
|
|
31498
|
-
|
|
31499
|
-
|
|
31500
|
-
|
|
31501
|
-
|
|
31502
|
-
|
|
31503
|
-
|
|
31504
|
-
|
|
31505
|
-
|
|
31506
|
-
".
|
|
31507
|
-
|
|
31508
|
-
|
|
31924
|
+
function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
31925
|
+
let identifier = fallback;
|
|
31926
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
31927
|
+
parser.on("opentag", (tag) => {
|
|
31928
|
+
if ((tag.local ?? tag.name) === "assessmentItem") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
31929
|
+
});
|
|
31930
|
+
try {
|
|
31931
|
+
parser.write(inputXml).close();
|
|
31932
|
+
} catch {}
|
|
31933
|
+
return identifier;
|
|
31934
|
+
}
|
|
31935
|
+
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31936
|
+
if (!items.has(baseReference)) return baseReference;
|
|
31937
|
+
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
31938
|
+
if (!items.has(readableCandidate)) return readableCandidate;
|
|
31939
|
+
const sourceDigest = md5hex(normalizeHref(sourceHref));
|
|
31940
|
+
let candidate = `${readableCandidate}_${sourceDigest}`;
|
|
31941
|
+
let suffix = 1;
|
|
31942
|
+
while (items.has(candidate)) {
|
|
31943
|
+
candidate = `${readableCandidate}_${sourceDigest}_${suffix}`;
|
|
31944
|
+
suffix += 1;
|
|
31945
|
+
}
|
|
31946
|
+
return candidate;
|
|
31947
|
+
}
|
|
31948
|
+
function isUnsafeAssetHrefError(error) {
|
|
31949
|
+
return error instanceof Error && (error.message.startsWith("Unsafe QTI asset href:") || error.message.startsWith("QTI asset href has no filename:"));
|
|
31950
|
+
}
|
|
31951
|
+
function hasAssetNamingDiagnostic(diagnostics) {
|
|
31952
|
+
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);
|
|
31953
|
+
}
|
|
31954
|
+
/**
|
|
31955
|
+
* Resolve a local QTI reference exactly as asset URL transformation does.
|
|
31956
|
+
* References without a leading dot segment are already package-relative;
|
|
31957
|
+
* `./` and `../` references are resolved from the item source directory.
|
|
31958
|
+
*/
|
|
31959
|
+
function resolvePackageAssetHref(href, sourceHrefBase) {
|
|
31960
|
+
const cleanHref = href.split(/[?#]/, 1)[0].replaceAll("\\", "/");
|
|
31961
|
+
if (!cleanHref || /^https?:\/\//i.test(cleanHref) || cleanHref.startsWith("//") || cleanHref.startsWith("data:") || cleanHref.includes("assets.learnosity.com") || cleanHref.includes("media-vault.learnosity.com")) return;
|
|
31962
|
+
if (!(/^\.\.?\//.test(cleanHref) || !cleanHref.includes("/"))) return canonicalizeQtiAssetHref(cleanHref);
|
|
31963
|
+
const baseHref = canonicalizeQtiAssetHref(sourceHrefBase);
|
|
31964
|
+
return canonicalizeQtiAssetHref(`${baseHref.slice(0, baseHref.lastIndexOf("/") + 1)}${cleanHref}`);
|
|
31965
|
+
}
|
|
31966
|
+
/** Extract local asset-bearing attributes from item XML or resolved passage HTML. */
|
|
31967
|
+
function extractAssetHrefs(content) {
|
|
31968
|
+
const hrefs = [];
|
|
31969
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31970
|
+
const attributePattern = /\b(?:src|data|href)\s*=\s*["']([^"']+)["']/gi;
|
|
31971
|
+
let match;
|
|
31972
|
+
while ((match = attributePattern.exec(content)) !== null) if (!seen.has(match[1])) {
|
|
31973
|
+
seen.add(match[1]);
|
|
31974
|
+
hrefs.push(match[1]);
|
|
31975
|
+
}
|
|
31976
|
+
return hrefs;
|
|
31977
|
+
}
|
|
31978
|
+
function isCopyableAssetPath(path) {
|
|
31979
|
+
return isSupportedQtiAssetPath(path);
|
|
31980
|
+
}
|
|
31509
31981
|
/**
|
|
31510
31982
|
* Merge two tag objects, combining tag values for each tag type
|
|
31511
31983
|
* Source tags are merged into base tags, avoiding duplicates
|
|
@@ -31576,7 +32048,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31576
32048
|
if (needed.has(normalized)) return true;
|
|
31577
32049
|
const lower = normalized.toLowerCase();
|
|
31578
32050
|
if (lower.endsWith(".html")) return false;
|
|
31579
|
-
return lower.endsWith(".xml") ||
|
|
32051
|
+
return lower.endsWith(".xml") || isSupportedQtiAssetPath(normalized);
|
|
31580
32052
|
};
|
|
31581
32053
|
}
|
|
31582
32054
|
const unzipped = unzipToEntries(input.zipBytes, label, filter ? { filter } : void 0);
|
|
@@ -31611,6 +32083,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31611
32083
|
}
|
|
31612
32084
|
const items = /* @__PURE__ */ new Map();
|
|
31613
32085
|
const itemFilenames = /* @__PURE__ */ new Map();
|
|
32086
|
+
const itemAssetContexts = [];
|
|
31614
32087
|
const qtiRefToMd5Refs = /* @__PURE__ */ new Map();
|
|
31615
32088
|
const convertedSourceFiles = [];
|
|
31616
32089
|
const failedSourceFiles = [];
|
|
@@ -31673,23 +32146,33 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31673
32146
|
}
|
|
31674
32147
|
const itemXml = decodeUtf8(itemEntry.data);
|
|
31675
32148
|
const itemFilePath = opts?.sourceDir ? posixJoin(opts.sourceDir, itemResource.href) : itemResource.href;
|
|
32149
|
+
const baseItemReference = generateItemReference(readAssessmentItemIdentifier(itemXml, itemResource.identifier), opts?.itemReferenceSource, itemFilePath);
|
|
32150
|
+
const finalItemReference = uniqueItemReference(baseItemReference, itemResource.href, items);
|
|
31676
32151
|
const itemResult = convertQtiAssessmentItemToLearnosity(itemXml, {
|
|
31677
32152
|
inputPath: itemFilePath,
|
|
31678
32153
|
sourceFile: itemFilePath,
|
|
31679
32154
|
organisationId: opts?.organisationId,
|
|
31680
32155
|
mediaVault: opts?.mediaVault,
|
|
31681
32156
|
customAssetUrl: opts?.customAssetUrl,
|
|
32157
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31682
32158
|
itemReferenceSource: opts?.itemReferenceSource,
|
|
31683
32159
|
fileAccess: opts?.fileAccess,
|
|
31684
|
-
packageRoot: opts?.sourceDir
|
|
32160
|
+
packageRoot: opts?.sourceDir,
|
|
32161
|
+
finalItemReference,
|
|
32162
|
+
sourceHrefBase: itemResource.href
|
|
31685
32163
|
});
|
|
31686
32164
|
diagnostics.push(...itemResult.diagnostics);
|
|
31687
32165
|
if (itemResult.item) {
|
|
31688
32166
|
let md5Ref = itemResult.item.item.reference;
|
|
32167
|
+
if (finalItemReference !== baseItemReference) diagnostics.push({
|
|
32168
|
+
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
32169
|
+
level: "warning",
|
|
32170
|
+
file: itemResource.href,
|
|
32171
|
+
message: `Duplicate item reference "${finalItemReference}" disambiguated from "${baseItemReference}" (source: ${itemResource.href})`
|
|
32172
|
+
});
|
|
31689
32173
|
if (items.has(md5Ref)) {
|
|
31690
|
-
const
|
|
31691
|
-
|
|
31692
|
-
md5Ref = `${md5Ref}_${filename}`;
|
|
32174
|
+
const originalRef = md5Ref;
|
|
32175
|
+
md5Ref = uniqueItemReference(finalItemReference, itemResource.href, items);
|
|
31693
32176
|
itemResult.item.item.reference = md5Ref;
|
|
31694
32177
|
for (const question of itemResult.item.questions) {
|
|
31695
32178
|
const oldRef = question.reference;
|
|
@@ -31703,7 +32186,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31703
32186
|
code: DiagnosticCode.QTI_PACKAGE_DUPLICATE_IDENTIFIER,
|
|
31704
32187
|
level: "warning",
|
|
31705
32188
|
file: itemResource.href,
|
|
31706
|
-
message: `Duplicate item reference "${
|
|
32189
|
+
message: `Duplicate item reference "${md5Ref}" disambiguated from "${originalRef}" (source: ${itemResource.href})`
|
|
31707
32190
|
});
|
|
31708
32191
|
}
|
|
31709
32192
|
if (itemResource.metadataXml) try {
|
|
@@ -31723,9 +32206,15 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31723
32206
|
});
|
|
31724
32207
|
}
|
|
31725
32208
|
items.set(md5Ref, itemResult.item);
|
|
32209
|
+
itemAssetContexts.push({
|
|
32210
|
+
finalItemReference: md5Ref,
|
|
32211
|
+
sourceHref: itemResource.href,
|
|
32212
|
+
sourceFile: itemFilePath,
|
|
32213
|
+
inputXml: itemXml
|
|
32214
|
+
});
|
|
31726
32215
|
const filenameSource = opts?.itemFilenameSource;
|
|
31727
32216
|
if (filenameSource && filenameSource !== (opts.itemReferenceSource ?? "sourceFilename")) {
|
|
31728
|
-
const filename = generateItemReference(itemXml
|
|
32217
|
+
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
31729
32218
|
itemFilenames.set(md5Ref, filename);
|
|
31730
32219
|
}
|
|
31731
32220
|
if (!qtiRefToMd5Refs.has(itemResource.identifier)) qtiRefToMd5Refs.set(itemResource.identifier, []);
|
|
@@ -31736,6 +32225,12 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31736
32225
|
diagnostics.push(...ensureFailedItemDiagnostic(itemResult.diagnostics, itemResource.href));
|
|
31737
32226
|
}
|
|
31738
32227
|
}
|
|
32228
|
+
if (hasAssetNamingDiagnostic(diagnostics)) return {
|
|
32229
|
+
diagnostics,
|
|
32230
|
+
convertedSourceFiles,
|
|
32231
|
+
failedSourceFiles,
|
|
32232
|
+
convertedActivityFiles
|
|
32233
|
+
};
|
|
31739
32234
|
if (items.size === 0 && itemResourcesToConvert.length > 0) {
|
|
31740
32235
|
diagnostics.push({
|
|
31741
32236
|
code: DiagnosticCode.QTI_PACKAGE_ITEM_NOT_FOUND,
|
|
@@ -31840,24 +32335,39 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31840
32335
|
activitiesManifest[activityId] = { items: activityItems };
|
|
31841
32336
|
}
|
|
31842
32337
|
const assets = /* @__PURE__ */ new Map();
|
|
31843
|
-
const
|
|
31844
|
-
|
|
31845
|
-
|
|
31846
|
-
|
|
31847
|
-
|
|
31848
|
-
|
|
31849
|
-
|
|
31850
|
-
|
|
31851
|
-
|
|
32338
|
+
const assetCandidates = /* @__PURE__ */ new Map();
|
|
32339
|
+
const addAssetCandidate = (href, data) => {
|
|
32340
|
+
try {
|
|
32341
|
+
const canonicalHref = canonicalizeQtiAssetHref(href);
|
|
32342
|
+
if (isCopyableAssetPath(canonicalHref)) assetCandidates.set(canonicalHref, new Uint8Array(data));
|
|
32343
|
+
} catch {}
|
|
32344
|
+
};
|
|
32345
|
+
for (const resource of resources) if (resource.type === "webcontent" || resource.type.includes("associated")) for (const href of [resource.href, ...resource.files ?? []]) {
|
|
32346
|
+
const assetEntry = entries.get(normalizeHref(href));
|
|
32347
|
+
if (assetEntry) addAssetCandidate(href, assetEntry.data);
|
|
31852
32348
|
}
|
|
31853
32349
|
for (const [path, entry] of entries) {
|
|
31854
|
-
if (
|
|
31855
|
-
|
|
31856
|
-
|
|
31857
|
-
|
|
31858
|
-
|
|
31859
|
-
|
|
31860
|
-
|
|
32350
|
+
if (path === "imsmanifest.xml" || path.toLowerCase().endsWith(".xml")) continue;
|
|
32351
|
+
addAssetCandidate(path, entry.data);
|
|
32352
|
+
}
|
|
32353
|
+
const registry = new AssetFilenameRegistry(opts?.preserveAssetFilenames ?? false);
|
|
32354
|
+
const registerContextAsset = (context, rawHref, sourceHrefBase) => {
|
|
32355
|
+
const canonicalHref = resolvePackageAssetHref(rawHref, sourceHrefBase);
|
|
32356
|
+
if (!canonicalHref) return;
|
|
32357
|
+
const bytes = assetCandidates.get(canonicalHref);
|
|
32358
|
+
if (!bytes) return;
|
|
32359
|
+
const registration = registry.register(context.finalItemReference, canonicalHref, bytes);
|
|
32360
|
+
assets.set(registration.filename, registration.bytes);
|
|
32361
|
+
};
|
|
32362
|
+
for (const context of itemAssetContexts) {
|
|
32363
|
+
for (const rawHref of extractAssetHrefs(context.inputXml)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
32364
|
+
for (const passagePath of getAllPassageDataPaths(context.inputXml)) {
|
|
32365
|
+
const passageContent = opts?.fileAccess?.resolvePassageFile(passagePath, context.sourceFile);
|
|
32366
|
+
const passageHref = resolvePackageAssetHref(passagePath, context.sourceHref);
|
|
32367
|
+
const entryContent = passageHref ? entries.get(passageHref) : void 0;
|
|
32368
|
+
const resolvedPassageContent = passageContent ?? (entryContent ? decodeUtf8(entryContent.data) : void 0);
|
|
32369
|
+
if (!resolvedPassageContent) continue;
|
|
32370
|
+
for (const rawHref of extractAssetHrefs(resolvedPassageContent)) registerContextAsset(context, rawHref, context.sourceHref);
|
|
31861
32371
|
}
|
|
31862
32372
|
}
|
|
31863
32373
|
return {
|
|
@@ -31870,6 +32380,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31870
32380
|
organisationId: opts?.organisationId,
|
|
31871
32381
|
mediaVault: opts?.mediaVault ?? false,
|
|
31872
32382
|
customAssetUrl: opts?.customAssetUrl,
|
|
32383
|
+
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
31873
32384
|
itemReferenceSource: opts?.itemReferenceSource ?? "sourceFilename"
|
|
31874
32385
|
}
|
|
31875
32386
|
},
|
|
@@ -31891,7 +32402,25 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
31891
32402
|
convertedActivityFiles
|
|
31892
32403
|
};
|
|
31893
32404
|
} catch (error) {
|
|
31894
|
-
diagnostics.push({
|
|
32405
|
+
if (error instanceof AssetFilenameConflictError) diagnostics.push({
|
|
32406
|
+
code: error.kind === "identity-bytes" ? DiagnosticCode.QTI_ASSET_IDENTITY_BYTES_CONFLICT : DiagnosticCode.QTI_ASSET_FILENAME_CONFLICT,
|
|
32407
|
+
level: "error",
|
|
32408
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
32409
|
+
message: error.message,
|
|
32410
|
+
context: {
|
|
32411
|
+
mode: error.mode,
|
|
32412
|
+
filename: error.filename,
|
|
32413
|
+
existingIdentity: error.existing.serializedIdentity,
|
|
32414
|
+
incomingIdentity: error.incoming.serializedIdentity
|
|
32415
|
+
}
|
|
32416
|
+
});
|
|
32417
|
+
else if (isUnsafeAssetHrefError(error)) diagnostics.push({
|
|
32418
|
+
code: DiagnosticCode.QTI_ASSET_HREF_UNSAFE,
|
|
32419
|
+
level: "error",
|
|
32420
|
+
file: opts?.sourceLabel ?? opts?.sourceDir ?? "package",
|
|
32421
|
+
message: error.message
|
|
32422
|
+
});
|
|
32423
|
+
else diagnostics.push({
|
|
31895
32424
|
code: DiagnosticCode.LRN_SCHEMA_INVALID,
|
|
31896
32425
|
level: "error",
|
|
31897
32426
|
file: "root",
|
|
@@ -32818,6 +33347,22 @@ function stringifyDeterministic(obj) {
|
|
|
32818
33347
|
}, 2);
|
|
32819
33348
|
}
|
|
32820
33349
|
/**
|
|
33350
|
+
* Return an asset key relative to the bundle's `assets/` root.
|
|
33351
|
+
*
|
|
33352
|
+
* New callers provide selected filenames or other root-relative keys. Strip
|
|
33353
|
+
* legacy leading `assets/` segments so the writer remains compatible with
|
|
33354
|
+
* source-relative keys without producing `assets/assets/...` paths.
|
|
33355
|
+
*/
|
|
33356
|
+
function normalizeBundleAssetPath(assetPath) {
|
|
33357
|
+
let normalized = assetPath.replaceAll("\\", "/");
|
|
33358
|
+
while (normalized.startsWith("./")) normalized = normalized.slice(2);
|
|
33359
|
+
while (normalized.startsWith("assets/")) normalized = normalized.slice(7);
|
|
33360
|
+
const segments = normalized.split("/").filter((segment) => segment && segment !== ".");
|
|
33361
|
+
const isAbsolute = normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || /^[A-Za-z][A-Za-z\d+.-]*:/.test(normalized);
|
|
33362
|
+
if (!normalized || isAbsolute || segments.some((segment) => segment === "..")) throw new Error(`Unsafe bundle asset path: ${assetPath}`);
|
|
33363
|
+
return segments.join("/");
|
|
33364
|
+
}
|
|
33365
|
+
/**
|
|
32821
33366
|
* Write Learnosity Bundle to directory or ZIP
|
|
32822
33367
|
*/
|
|
32823
33368
|
async function writeLearnosityBundle(bundle, options) {
|
|
@@ -32841,10 +33386,13 @@ async function writeLearnosityBundle(bundle, options) {
|
|
|
32841
33386
|
content: stringifyDeterministic(item)
|
|
32842
33387
|
});
|
|
32843
33388
|
}
|
|
32844
|
-
for (const [assetPath, data] of bundle.assets)
|
|
32845
|
-
|
|
32846
|
-
|
|
32847
|
-
|
|
33389
|
+
for (const [assetPath, data] of bundle.assets) {
|
|
33390
|
+
const relativeAssetPath = normalizeBundleAssetPath(assetPath);
|
|
33391
|
+
files.push({
|
|
33392
|
+
path: `assets/${relativeAssetPath}`,
|
|
33393
|
+
content: Buffer.from(data)
|
|
33394
|
+
});
|
|
33395
|
+
}
|
|
32848
33396
|
writeZip(outDir, files);
|
|
32849
33397
|
} else {
|
|
32850
33398
|
await mkdir(outDir, { recursive: true });
|
|
@@ -32863,7 +33411,8 @@ async function writeLearnosityBundle(bundle, options) {
|
|
|
32863
33411
|
await writeFile(itemPath, stringifyDeterministic(item));
|
|
32864
33412
|
}
|
|
32865
33413
|
for (const [assetPath, data] of bundle.assets) {
|
|
32866
|
-
const
|
|
33414
|
+
const relativeAssetPath = normalizeBundleAssetPath(assetPath);
|
|
33415
|
+
const fullPath = join$1(outDir, "assets", relativeAssetPath);
|
|
32867
33416
|
const assetDir = join$1(fullPath, "..");
|
|
32868
33417
|
await mkdir(assetDir, { recursive: true });
|
|
32869
33418
|
await writeFile(fullPath, data);
|
|
@@ -33259,6 +33808,7 @@ async function convertQtiPackageToLearnosity(opts) {
|
|
|
33259
33808
|
organisationId: opts.organisationId,
|
|
33260
33809
|
mediaVault: opts.mediaVault,
|
|
33261
33810
|
customAssetUrl: opts.customAssetUrl,
|
|
33811
|
+
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
33262
33812
|
itemReferenceSource: opts.itemReferenceSource,
|
|
33263
33813
|
itemFilenameSource: opts.itemFilenameSource,
|
|
33264
33814
|
truncateTags: opts.truncateTags,
|