@learnosity/lib-qti-converter 0.12.7 → 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.
Files changed (38) hide show
  1. package/docs/GETTING_STARTED.md +71 -18
  2. package/docs/LEARNOSITY_BUNDLE_FORMAT.md +23 -7
  3. package/package.json +8 -8
  4. package/packages/cli/dist/{batchProcessors-DU1HwpHY.js → batchProcessors-DgiDpfpP.js} +271 -77
  5. package/packages/cli/dist/batchProcessors-DgiDpfpP.js.map +1 -0
  6. package/packages/cli/dist/batchWorker.js +1 -1
  7. package/packages/cli/dist/{create-prompt-DU9wLVhI.js → create-prompt-DyNnKXYU.js} +63 -53
  8. package/packages/cli/dist/create-prompt-DyNnKXYU.js.map +1 -0
  9. package/packages/cli/dist/{dist-DjpU2mIj.js → dist-D3v6G5F8.js} +6 -6
  10. package/packages/cli/dist/{dist-DjpU2mIj.js.map → dist-D3v6G5F8.js.map} +1 -1
  11. package/packages/cli/dist/{learnosityToQti-BSbH3jyx.js → learnosityToQti-CIj5603P.js} +4 -4
  12. package/packages/cli/dist/{learnosityToQti-BSbH3jyx.js.map → learnosityToQti-CIj5603P.js.map} +1 -1
  13. package/packages/cli/dist/{learnosityToQtiPackage-B0xRzYmy.js → learnosityToQtiPackage-n6nGGr32.js} +7 -7
  14. package/packages/cli/dist/{learnosityToQtiPackage-B0xRzYmy.js.map → learnosityToQtiPackage-n6nGGr32.js.map} +1 -1
  15. package/packages/cli/dist/main.js +5 -5
  16. package/packages/cli/dist/{nodeFileAccess-BkzSHCOh.js → nodeFileAccess-BhCoGDOi.js} +6 -3
  17. package/packages/cli/dist/{nodeFileAccess-BkzSHCOh.js.map → nodeFileAccess-BhCoGDOi.js.map} +1 -1
  18. package/packages/cli/dist/{pathUtils-B9yPTlVF.js → pathUtils-mTQZ0wYS.js} +36 -20
  19. package/packages/cli/dist/pathUtils-mTQZ0wYS.js.map +1 -0
  20. package/packages/cli/dist/{qtiPackageToLearnosity-C7JaaUDU.js → qtiPackageToLearnosity-B4cD8jUw.js} +13 -7
  21. package/packages/cli/dist/qtiPackageToLearnosity-B4cD8jUw.js.map +1 -0
  22. package/packages/cli/dist/{qtiToLearnosity-CYoG2aIX.js → qtiToLearnosity-DDjcpShJ.js} +7 -6
  23. package/packages/cli/dist/qtiToLearnosity-DDjcpShJ.js.map +1 -0
  24. package/packages/cli/dist/{resolveOptions-CW80R2EQ.js → resolveOptions-Czapkfc1.js} +22 -8
  25. package/packages/cli/dist/resolveOptions-Czapkfc1.js.map +1 -0
  26. package/packages/cli/dist/{table-DjOn2Tsk.js → table-DTSv0atR.js} +619 -236
  27. package/packages/cli/dist/table-DTSv0atR.js.map +1 -0
  28. package/packages/core/dist/index.d.ts +197 -184
  29. package/packages/core/dist/index.js +858 -303
  30. package/packages/core/dist/node.d.ts +211 -196
  31. package/packages/core/dist/node.js +889 -310
  32. package/packages/cli/dist/batchProcessors-DU1HwpHY.js.map +0 -1
  33. package/packages/cli/dist/create-prompt-DU9wLVhI.js.map +0 -1
  34. package/packages/cli/dist/pathUtils-B9yPTlVF.js.map +0 -1
  35. package/packages/cli/dist/qtiPackageToLearnosity-C7JaaUDU.js.map +0 -1
  36. package/packages/cli/dist/qtiToLearnosity-CYoG2aIX.js.map +0 -1
  37. package/packages/cli/dist/resolveOptions-CW80R2EQ.js.map +0 -1
  38. package/packages/cli/dist/table-DjOn2Tsk.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"nodeFileAccess-BkzSHCOh.js","names":["containedPath"],"sources":["../../core/src/qti-to-learnosity/utils/passageResolver.ts","../../core/src/qti-to-learnosity/utils/lomFinder.ts","../../core/src/qti-to-learnosity/utils/imageDimensions.ts","../../core/src/qti-to-learnosity/nodeFileAccess.ts"],"sourcesContent":["/**\n * Passage HTML file resolver\n * Resolves and reads external HTML files referenced by <object> tags in QTI passages\n */\n\nimport { existsSync, readFileSync } from 'fs';\nimport { dirname, join, isAbsolute, resolve, relative, sep } from 'path';\n\n/**\n * Resolve `candidate` and confirm it stays inside `root`.\n *\n * The `data` attribute of an <object> tag comes from the QTI file being\n * converted, which is untrusted input. Without this check a crafted value such\n * as \"../../../../etc/passwd\" would let a QTI package read arbitrary files.\n *\n * @param candidate - Path to check (absolute or already joined)\n * @param root - Directory the path must stay within\n * @returns Absolute path if contained by root, undefined otherwise\n */\nfunction containedPath(candidate: string, root: string): string | undefined {\n // These two resolve() calls are the sanitiser, not a sink: normalising both\n // sides is what makes the relative() comparison below meaningful.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedRoot = resolve(root);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedCandidate = resolve(candidate);\n const rel = relative(resolvedRoot, resolvedCandidate);\n\n // Empty means the candidate is the root itself; a leading \"..\" segment or an\n // absolute result means it escaped the root (e.g. a different drive).\n if (rel === '' || isAbsolute(rel) || rel.split(sep)[0] === '..') {\n return undefined;\n }\n\n return resolvedCandidate;\n}\n\n/**\n * Resolve and read a passage HTML file referenced by an <object> tag\n *\n * @param objectDataPath - The path from the object's data attribute (e.g., \"passages/passage.html\")\n * @param sourceFile - The absolute path to the source QTI XML file\n * @returns The HTML content of the passage file, or undefined if not found\n */\nexport function resolvePassageFile(\n objectDataPath: string,\n sourceFile?: string\n): string | undefined {\n if (!sourceFile || !objectDataPath) {\n return undefined;\n }\n\n // Get the directory containing the source XML file\n const sourceDir = dirname(sourceFile);\n\n // Passages sit either beside the item (passages/passage.html) or one level\n // up (items/item.xml -> ../passages/passage.html), so the parent directory\n // is the widest location a passage may legitimately be read from.\n const root = dirname(sourceDir);\n\n // Candidates, in priority order: relative to the source directory, then\n // relative to its parent. Absolute values are taken as-is. Each one is passed\n // through containedPath() below before it reaches the filesystem.\n const candidates: string[] = [];\n\n if (isAbsolute(objectDataPath)) {\n candidates.push(objectDataPath);\n } else {\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(sourceDir, objectDataPath));\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(root, objectDataPath));\n }\n\n for (const candidate of candidates) {\n // Every candidate is confined to `root` before it reaches the filesystem\n const passagePath = containedPath(candidate, root);\n\n if (!passagePath || !existsSync(passagePath)) {\n continue;\n }\n\n try {\n return readFileSync(passagePath, 'utf-8').replace(/^\\uFEFF/, '');\n } catch {\n // File exists but couldn't be read\n return undefined;\n }\n }\n\n return undefined;\n}\n\n","/**\n * LOM file discovery utility\n * Locates LOM metadata files for QTI items\n */\n\nimport { existsSync, readFileSync } from 'fs';\nimport { dirname, basename, join } from 'path';\n\n/**\n * Find LOM file for a given QTI item file path\n * Checks for:\n * - .../items/<id>.xml → .../metadata/<id>.lom.xml\n * - <dir>/<id>.xml → <dir>/metadata/<id>.lom.xml\n * - <dir>/<id>.xml → <dir>/../metadata/<id>.lom.xml\n *\n * @param itemPath - Absolute path to the QTI item XML file\n * @returns LOM XML content if found, undefined otherwise\n */\nexport function findAndReadLomFile(itemPath: string): string | undefined {\n const dir = dirname(itemPath);\n const filename = basename(itemPath);\n const itemId = filename.replace(/\\.xml$/i, '');\n\n // basename() strips every directory separator, so lomFilename cannot carry\n // traversal segments. The joins below stay within dir or its parent, both of\n // which are derived from the item path the operator asked us to convert.\n const lomFilename = `${itemId}.lom.xml`;\n\n // Pattern 1: .../items/<id>.xml → .../metadata/<id>.lom.xml (sibling folder)\n if (dir.endsWith('/items') || dir.endsWith('\\\\items')) {\n const parentDir = dirname(dir);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const lomPath = join(parentDir, 'metadata', lomFilename);\n\n if (existsSync(lomPath)) {\n try {\n return readFileSync(lomPath, 'utf-8');\n } catch {\n return undefined;\n }\n }\n }\n\n // Pattern 2: <dir>/<id>.xml → <dir>/metadata/<id>.lom.xml\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const lomPath1 = join(dir, 'metadata', lomFilename);\n\n if (existsSync(lomPath1)) {\n try {\n return readFileSync(lomPath1, 'utf-8');\n } catch {\n return undefined;\n }\n }\n\n // Pattern 3: <dir>/<id>.xml → <dir>/../metadata/<id>.lom.xml\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const lomPath2 = join(dir, '..', 'metadata', lomFilename);\n\n if (existsSync(lomPath2)) {\n try {\n return readFileSync(lomPath2, 'utf-8');\n } catch {\n return undefined;\n }\n }\n\n return undefined;\n}\n","/**\n * Image dimension resolver\n *\n * Resolves an image file referenced by a QTI `<object data=\"...\">` /\n * `<img src=\"...\">` tag and reads its intrinsic pixel dimensions directly from\n * the file header. This is a dependency-free reader for the formats commonly\n * found in QTI packages (GIF, PNG, JPEG). It reads only the small header region\n * needed to determine dimensions, not the whole file.\n *\n * QTI legitimately allows an `<object>` without width/height attributes, but\n * some Learnosity question types (e.g. hotspot) need pixel dimensions to convert\n * absolute coordinates into percentages. When the markup omits them, the\n * dimensions are recovered from the referenced image file.\n */\n\nimport { existsSync, closeSync, openSync, readSync, realpathSync } from 'fs';\nimport { dirname, join, isAbsolute, resolve, relative, sep } from 'path';\n\nexport interface ImageDimensions {\n width: number;\n height: number;\n}\n\n/**\n * Only the leading bytes of an image are needed to read its dimensions: GIF and\n * PNG carry them in the first ~24 bytes, and a JPEG's first Start-Of-Frame\n * marker is virtually always within the first segments. Cap the read so a huge\n * asset can never be loaded whole into memory.\n */\nconst MAX_HEADER_BYTES = 64 * 1024;\n\n/**\n * Check that `resolvedCandidate` stays lexically inside `resolvedRoot`.\n *\n * Both arguments must already be absolute/normalised. Returns true when the\n * candidate is contained (and is not the root itself).\n */\nfunction isContained(resolvedCandidate: string, resolvedRoot: string): boolean {\n const rel = relative(resolvedRoot, resolvedCandidate);\n\n return rel !== '' && !isAbsolute(rel) && rel.split(sep)[0] !== '..';\n}\n\n/**\n * Resolve `candidate` and confirm it stays inside `root`, both lexically and\n * after dereferencing symlinks.\n *\n * The `data`/`src` attribute comes from the QTI file being converted, which is\n * untrusted input. A lexical check alone is insufficient: a package could place\n * a symlink under `root` that targets a file outside it (e.g. `/dev/zero`), so\n * the real path is re-verified against the real root before it is returned for\n * reading.\n *\n * @returns The real (symlink-dereferenced) absolute path if contained, else undefined.\n */\nfunction containedPath(candidate: string, root: string): string | undefined {\n // These resolve() calls are the sanitiser, not a sink: normalising both\n // sides is what makes the relative() comparison below meaningful.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedRoot = resolve(root);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedCandidate = resolve(candidate);\n\n // Lexical containment first (cheap, and rejects obvious \"../\" escapes even\n // when the target does not exist).\n if (!isContained(resolvedCandidate, resolvedRoot)) {\n return undefined;\n }\n\n if (!existsSync(resolvedCandidate)) {\n return undefined;\n }\n\n // Dereference symlinks on both sides and re-verify: this closes the gap\n // where a symlink inside root points outside it. If realpath fails (broken\n // link, race), treat as not resolvable.\n let realCandidate: string;\n let realRoot: string;\n\n try {\n realCandidate = realpathSync(resolvedCandidate);\n realRoot = realpathSync(resolvedRoot);\n } catch {\n return undefined;\n }\n\n if (!isContained(realCandidate, realRoot)) {\n return undefined;\n }\n\n return realCandidate;\n}\n\n/**\n * Read up to {@link MAX_HEADER_BYTES} from the start of a file without loading\n * the whole file into memory. Returns the bytes actually read.\n */\nfunction readHeaderBytes(path: string): Buffer | undefined {\n let fd: number | undefined;\n\n try {\n fd = openSync(path, 'r');\n const buf = Buffer.alloc(MAX_HEADER_BYTES);\n const bytesRead = readSync(fd, buf, 0, MAX_HEADER_BYTES, 0);\n\n return buf.subarray(0, bytesRead);\n } catch {\n return undefined;\n } finally {\n if (fd !== undefined) {\n try {\n closeSync(fd);\n } catch {\n // Best-effort close; nothing actionable if it fails.\n }\n }\n }\n}\n\n/**\n * Read image dimensions from an in-memory file header buffer.\n * Exported for unit testing without touching the filesystem.\n *\n * Supports GIF (87a/89a), PNG, and JPEG (baseline and progressive).\n *\n * @param buf - The image file bytes (at least the header region)\n * @returns The pixel dimensions, or undefined if the format is unrecognised\n */\nexport function readImageDimensionsFromBuffer(buf: Buffer): ImageDimensions | undefined {\n // GIF: \"GIF87a\" or \"GIF89a\"; width/height are little-endian uint16 at offset 6/8.\n if (\n buf.length >= 10 &&\n buf[0] === 0x47 && // G\n buf[1] === 0x49 && // I\n buf[2] === 0x46 // F\n ) {\n const width = buf.readUInt16LE(6);\n const height = buf.readUInt16LE(8);\n\n if (width > 0 && height > 0) {\n return { width, height };\n }\n\n return undefined;\n }\n\n // PNG: 8-byte signature, then IHDR with width/height as big-endian uint32\n // at offset 16/20.\n if (\n buf.length >= 24 &&\n buf[0] === 0x89 &&\n buf[1] === 0x50 && // P\n buf[2] === 0x4e && // N\n buf[3] === 0x47 // G\n ) {\n const width = buf.readUInt32BE(16);\n const height = buf.readUInt32BE(20);\n\n if (width > 0 && height > 0) {\n return { width, height };\n }\n\n return undefined;\n }\n\n // JPEG: starts with 0xFFD8. Scan marker segments for a Start Of Frame\n // (SOF0-SOF15, excluding non-SOF markers 0xC4/0xC8/0xCC) which carries\n // height/width as big-endian uint16.\n if (buf.length >= 4 && buf[0] === 0xff && buf[1] === 0xd8) {\n let offset = 2;\n\n while (offset + 9 < buf.length) {\n // A marker is 0xFF followed by a non-0xFF, non-0x00 marker code.\n // JPEG permits any number of 0xFF fill bytes before the marker code,\n // so skip the whole run of 0xFF and land on the marker byte itself.\n if (buf[offset] !== 0xff) {\n offset++;\n continue;\n }\n\n let markerOffset = offset;\n\n while (markerOffset < buf.length && buf[markerOffset] === 0xff) {\n markerOffset++;\n }\n\n if (markerOffset >= buf.length) {\n break;\n }\n\n const marker = buf[markerOffset];\n // The length field (if any) follows the marker code byte.\n const segmentStart = markerOffset + 1;\n\n // 0x00 after 0xFF is a stuffed byte inside entropy-coded data, not a\n // marker; skip past it and keep scanning.\n if (marker === 0x00) {\n offset = segmentStart;\n continue;\n }\n\n // Standalone markers without a length payload.\n if (marker === 0xd8 || marker === 0xd9 || (marker >= 0xd0 && marker <= 0xd7)) {\n offset = segmentStart;\n continue;\n }\n\n if (segmentStart + 1 >= buf.length) {\n break;\n }\n\n const segmentLength = buf.readUInt16BE(segmentStart);\n\n // SOF markers carrying frame dimensions (exclude DHT 0xC4, JPG 0xC8,\n // DAC 0xCC which share the 0xCn range but are not frame headers).\n const isSof =\n marker >= 0xc0 &&\n marker <= 0xcf &&\n marker !== 0xc4 &&\n marker !== 0xc8 &&\n marker !== 0xcc;\n\n if (isSof) {\n // SOF payload after the 2-byte length: precision (1 byte),\n // height (2 bytes), width (2 bytes).\n if (segmentStart + 6 >= buf.length) {\n break;\n }\n\n const height = buf.readUInt16BE(segmentStart + 3);\n const width = buf.readUInt16BE(segmentStart + 5);\n\n if (width > 0 && height > 0) {\n return { width, height };\n }\n\n return undefined;\n }\n\n // Advance past this segment: length field + its payload.\n offset = segmentStart + segmentLength;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolve and read the intrinsic dimensions of an image referenced by a QTI\n * `<object>`/`<img>` tag.\n *\n * Security model: the `objectDataPath` comes from untrusted QTI markup, so every\n * resolved path is confined to a containment root before it is read.\n *\n * - When `packageRoot` is supplied (the normal case for package conversion), any\n * asset located anywhere inside the package is allowed — including assets a\n * sibling directory up, e.g. `questions/item.xml` referencing\n * `../images/foo.png`. This does not rely on directory names.\n * - When `packageRoot` is omitted (in-memory callers with no package context),\n * the read is confined to the source file's own directory. This is the safe\n * default: no path is read from outside where the item lives.\n *\n * @param objectDataPath - Path from the data/src attribute (e.g. \"754493.gif\")\n * @param sourceFile - Absolute path to the source QTI XML file\n * @param packageRoot - Absolute path to the package root that bounds all reads\n * @returns The image dimensions, or undefined if it cannot be resolved/read.\n */\nexport function resolveImageDimensions(\n objectDataPath: string,\n sourceFile?: string,\n packageRoot?: string\n): ImageDimensions | undefined {\n if (!sourceFile || !objectDataPath) {\n return undefined;\n }\n\n const sourceDir = dirname(sourceFile);\n\n // The containment root: the package root when known (so any in-package asset\n // resolves regardless of directory naming), otherwise the item's own\n // directory. If a packageRoot is given but the source file somehow sits\n // outside it, fall back to the source directory rather than trusting it.\n let root = sourceDir;\n\n if (packageRoot) {\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedRoot = resolve(packageRoot);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedSourceDir = resolve(sourceDir);\n const rel = relative(resolvedRoot, resolvedSourceDir);\n const sourceInsideRoot = rel === '' || (!isAbsolute(rel) && rel.split(sep)[0] !== '..');\n\n root = sourceInsideRoot ? resolvedRoot : resolvedSourceDir;\n }\n\n const candidates: string[] = [];\n\n if (isAbsolute(objectDataPath)) {\n candidates.push(objectDataPath);\n } else {\n // Resolve relative to the item first (most common), then relative to the\n // package root. Both are re-checked for containment before any read.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(sourceDir, objectDataPath));\n\n if (resolve(root) !== resolve(sourceDir)) {\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(root, objectDataPath));\n }\n }\n\n for (const candidate of candidates) {\n // containedPath dereferences symlinks and re-verifies containment, so\n // the returned path is safe to read.\n const imagePath = containedPath(candidate, root);\n\n if (!imagePath) {\n continue;\n }\n\n // Read only a bounded header region: enough for GIF/PNG and to scan the\n // early JPEG marker segments that carry frame dimensions, without\n // loading a potentially very large asset into memory.\n const buf = readHeaderBytes(imagePath);\n\n if (buf) {\n return readImageDimensionsFromBuffer(buf);\n }\n }\n\n return undefined;\n}\n","/**\n * Filesystem-backed {@link FileAccess} for Node.js callers (the CLI and\n * disk-based package conversion). Reads passage HTML and LOM metadata from the\n * local filesystem.\n *\n * This module imports Node built-ins (via the resolver helpers) and is therefore\n * NOT part of the browser-safe surface — it is wired in by Node entry points.\n */\nimport type { FileAccess } from './fileAccess.js';\nimport { resolvePassageFile } from './utils/passageResolver.js';\nimport { findAndReadLomFile } from './utils/lomFinder.js';\nimport { resolveImageDimensions } from './utils/imageDimensions.js';\n\nexport const nodeFileAccess: FileAccess = {\n resolvePassageFile,\n findAndReadLomFile,\n resolveImageDimensions,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,SAASA,gBAAc,WAAmB,MAAkC;CAIxE,MAAM,eAAe,QAAQ,IAAI;CAEjC,MAAM,oBAAoB,QAAQ,SAAS;CAC3C,MAAM,MAAM,SAAS,cAAc,iBAAiB;CAIpD,IAAI,QAAQ,MAAM,WAAW,GAAG,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,OAAO,MACvD;CAGJ,OAAO;AACX;;;;;;;;AASA,SAAgB,mBACZ,gBACA,YACkB;CAClB,IAAI,CAAC,cAAc,CAAC,gBAChB;CAIJ,MAAM,YAAY,QAAQ,UAAU;CAKpC,MAAM,OAAO,QAAQ,SAAS;CAK9B,MAAM,aAAuB,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,OAAO,OAExD,eAAe;CAC7C;CAEA,MAAM,aAAuB,CAAC;CAE9B,IAAI,WAAW,cAAc,GACzB,WAAW,KAAK,cAAc;MAC3B;EAIH,WAAW,KAAK,KAAK,WAAW,cAAc,CAAC;EAE/C,IAAI,QAAQ,IAAI,MAAM,QAAQ,SAAS,GAEnC,WAAW,KAAK,KAAK,MAAM,cAAc,CAAC;CAElD;CAEA,KAAK,MAAM,aAAa,YAAY;EAGhC,MAAM,YAAY,cAAc,WAAW,IAAI;EAE/C,IAAI,CAAC,WACD;EAMJ,MAAM,MAAM,gBAAgB,SAAS;EAErC,IAAI,KACA,OAAO,8BAA8B,GAAG;CAEhD;AAGJ;;;AC9TA,MAAa,iBAA6B;CACtC;CACA;CACA;AACJ"}
1
+ {"version":3,"file":"nodeFileAccess-BhCoGDOi.js","names":["containedPath"],"sources":["../../core/src/qti-to-learnosity/utils/passageResolver.ts","../../core/src/qti-to-learnosity/utils/lomFinder.ts","../../core/src/qti-to-learnosity/utils/imageDimensions.ts","../../core/src/qti-to-learnosity/nodeFileAccess.ts"],"sourcesContent":["/**\n * Passage HTML file resolver\n * Resolves and reads external HTML files referenced by <object> tags in QTI passages\n */\n\nimport { existsSync, readFileSync } from 'fs';\nimport { dirname, join, isAbsolute, resolve, relative, sep } from 'path';\n\n/**\n * Resolve `candidate` and confirm it stays inside `root`.\n *\n * The `data` attribute of an <object> tag comes from the QTI file being\n * converted, which is untrusted input. Without this check a crafted value such\n * as \"../../../../etc/passwd\" would let a QTI package read arbitrary files.\n *\n * @param candidate - Path to check (absolute or already joined)\n * @param root - Directory the path must stay within\n * @returns Absolute path if contained by root, undefined otherwise\n */\nfunction containedPath(candidate: string, root: string): string | undefined {\n // These two resolve() calls are the sanitiser, not a sink: normalising both\n // sides is what makes the relative() comparison below meaningful.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedRoot = resolve(root);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedCandidate = resolve(candidate);\n const rel = relative(resolvedRoot, resolvedCandidate);\n\n // Empty means the candidate is the root itself; a leading \"..\" segment or an\n // absolute result means it escaped the root (e.g. a different drive).\n if (rel === '' || isAbsolute(rel) || rel.split(sep)[0] === '..') {\n return undefined;\n }\n\n return resolvedCandidate;\n}\n\n/**\n * Resolve and read a passage HTML file referenced by an <object> tag\n *\n * @param objectDataPath - The path from the object's data attribute (e.g., \"passages/passage.html\")\n * @param sourceFile - The absolute path to the source QTI XML file\n * @returns The HTML content of the passage file, or undefined if not found\n */\nexport function resolvePassageFile(\n objectDataPath: string,\n sourceFile?: string\n): string | undefined {\n if (!sourceFile || !objectDataPath) {\n return undefined;\n }\n\n // Get the directory containing the source XML file\n const sourceDir = dirname(sourceFile);\n\n // Passages sit either beside the item (passages/passage.html) or one level\n // up (items/item.xml -> ../passages/passage.html), so the parent directory\n // is the widest location a passage may legitimately be read from.\n const root = dirname(sourceDir);\n\n // Candidates, in priority order: relative to the source directory, then\n // relative to its parent. Absolute values are taken as-is. Each one is passed\n // through containedPath() below before it reaches the filesystem.\n const candidates: string[] = [];\n\n if (isAbsolute(objectDataPath)) {\n candidates.push(objectDataPath);\n } else {\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(sourceDir, objectDataPath));\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(root, objectDataPath));\n }\n\n for (const candidate of candidates) {\n // Every candidate is confined to `root` before it reaches the filesystem\n const passagePath = containedPath(candidate, root);\n\n if (!passagePath || !existsSync(passagePath)) {\n continue;\n }\n\n try {\n return readFileSync(passagePath, 'utf-8').replace(/^\\uFEFF/, '');\n } catch {\n // File exists but couldn't be read\n return undefined;\n }\n }\n\n return undefined;\n}\n\n","/**\n * LOM file discovery utility\n * Locates LOM metadata files for QTI items\n */\n\nimport { existsSync, readFileSync } from 'fs';\nimport { dirname, basename, join } from 'path';\n\n/**\n * Find LOM file for a given QTI item file path\n * Checks for:\n * - .../items/<id>.xml → .../metadata/<id>.lom.xml\n * - <dir>/<id>.xml → <dir>/metadata/<id>.lom.xml\n * - <dir>/<id>.xml → <dir>/../metadata/<id>.lom.xml\n *\n * @param itemPath - Absolute path to the QTI item XML file\n * @returns LOM XML content if found, undefined otherwise\n */\nexport function findAndReadLomFile(itemPath: string): string | undefined {\n const dir = dirname(itemPath);\n const filename = basename(itemPath);\n const itemId = filename.replace(/\\.xml$/i, '');\n\n // basename() strips every directory separator, so lomFilename cannot carry\n // traversal segments. The joins below stay within dir or its parent, both of\n // which are derived from the item path the operator asked us to convert.\n const lomFilename = `${itemId}.lom.xml`;\n\n // Pattern 1: .../items/<id>.xml → .../metadata/<id>.lom.xml (sibling folder)\n if (dir.endsWith('/items') || dir.endsWith('\\\\items')) {\n const parentDir = dirname(dir);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const lomPath = join(parentDir, 'metadata', lomFilename);\n\n if (existsSync(lomPath)) {\n try {\n return readFileSync(lomPath, 'utf-8');\n } catch {\n return undefined;\n }\n }\n }\n\n // Pattern 2: <dir>/<id>.xml → <dir>/metadata/<id>.lom.xml\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const lomPath1 = join(dir, 'metadata', lomFilename);\n\n if (existsSync(lomPath1)) {\n try {\n return readFileSync(lomPath1, 'utf-8');\n } catch {\n return undefined;\n }\n }\n\n // Pattern 3: <dir>/<id>.xml → <dir>/../metadata/<id>.lom.xml\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const lomPath2 = join(dir, '..', 'metadata', lomFilename);\n\n if (existsSync(lomPath2)) {\n try {\n return readFileSync(lomPath2, 'utf-8');\n } catch {\n return undefined;\n }\n }\n\n return undefined;\n}\n","/**\n * Image dimension resolver\n *\n * Resolves an image file referenced by a QTI `<object data=\"...\">` /\n * `<img src=\"...\">` tag and reads its intrinsic pixel dimensions directly from\n * the file header. This is a dependency-free reader for the formats commonly\n * found in QTI packages (GIF, PNG, JPEG). It reads only the small header region\n * needed to determine dimensions, not the whole file.\n *\n * QTI legitimately allows an `<object>` without width/height attributes, but\n * some Learnosity question types (e.g. hotspot) need pixel dimensions to convert\n * absolute coordinates into percentages. When the markup omits them, the\n * dimensions are recovered from the referenced image file.\n */\n\nimport { existsSync, closeSync, openSync, readSync, realpathSync } from 'fs';\nimport { dirname, join, isAbsolute, resolve, relative, sep } from 'path';\n\nexport interface ImageDimensions {\n width: number;\n height: number;\n}\n\n/**\n * Only the leading bytes of an image are needed to read its dimensions: GIF and\n * PNG carry them in the first ~24 bytes, and a JPEG's first Start-Of-Frame\n * marker is virtually always within the first segments. Cap the read so a huge\n * asset can never be loaded whole into memory.\n */\nconst MAX_HEADER_BYTES = 64 * 1024;\n\n/**\n * Check that `resolvedCandidate` stays lexically inside `resolvedRoot`.\n *\n * Both arguments must already be absolute/normalised. Returns true when the\n * candidate is contained (and is not the root itself).\n */\nfunction isContained(resolvedCandidate: string, resolvedRoot: string): boolean {\n const rel = relative(resolvedRoot, resolvedCandidate);\n\n return rel !== '' && !isAbsolute(rel) && rel.split(sep)[0] !== '..';\n}\n\n/**\n * Resolve `candidate` and confirm it stays inside `root`, both lexically and\n * after dereferencing symlinks.\n *\n * The `data`/`src` attribute comes from the QTI file being converted, which is\n * untrusted input. A lexical check alone is insufficient: a package could place\n * a symlink under `root` that targets a file outside it (e.g. `/dev/zero`), so\n * the real path is re-verified against the real root before it is returned for\n * reading.\n *\n * @returns The real (symlink-dereferenced) absolute path if contained, else undefined.\n */\nfunction containedPath(candidate: string, root: string): string | undefined {\n // These resolve() calls are the sanitiser, not a sink: normalising both\n // sides is what makes the relative() comparison below meaningful.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedRoot = resolve(root);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedCandidate = resolve(candidate);\n\n // Lexical containment first (cheap, and rejects obvious \"../\" escapes even\n // when the target does not exist).\n if (!isContained(resolvedCandidate, resolvedRoot)) {\n return undefined;\n }\n\n if (!existsSync(resolvedCandidate)) {\n return undefined;\n }\n\n // Dereference symlinks on both sides and re-verify: this closes the gap\n // where a symlink inside root points outside it. If realpath fails (broken\n // link, race), treat as not resolvable.\n let realCandidate: string;\n let realRoot: string;\n\n try {\n realCandidate = realpathSync(resolvedCandidate);\n realRoot = realpathSync(resolvedRoot);\n } catch {\n return undefined;\n }\n\n if (!isContained(realCandidate, realRoot)) {\n return undefined;\n }\n\n return realCandidate;\n}\n\n/**\n * Read up to {@link MAX_HEADER_BYTES} from the start of a file without loading\n * the whole file into memory. Returns the bytes actually read.\n */\nfunction readHeaderBytes(path: string): Buffer | undefined {\n let fd: number | undefined;\n\n try {\n fd = openSync(path, 'r');\n const buf = Buffer.alloc(MAX_HEADER_BYTES);\n const bytesRead = readSync(fd, buf, 0, MAX_HEADER_BYTES, 0);\n\n return buf.subarray(0, bytesRead);\n } catch {\n return undefined;\n } finally {\n if (fd !== undefined) {\n try {\n closeSync(fd);\n } catch {\n // Best-effort close; nothing actionable if it fails.\n }\n }\n }\n}\n\n/**\n * Read image dimensions from an in-memory file header buffer.\n * Exported for unit testing without touching the filesystem.\n *\n * Supports GIF (87a/89a), PNG, and JPEG (baseline and progressive).\n *\n * @param buf - The image file bytes (at least the header region)\n * @returns The pixel dimensions, or undefined if the format is unrecognised\n */\nexport function readImageDimensionsFromBuffer(buf: Buffer): ImageDimensions | undefined {\n // GIF: \"GIF87a\" or \"GIF89a\"; width/height are little-endian uint16 at offset 6/8.\n if (\n buf.length >= 10 &&\n buf[0] === 0x47 && // G\n buf[1] === 0x49 && // I\n buf[2] === 0x46 // F\n ) {\n const width = buf.readUInt16LE(6);\n const height = buf.readUInt16LE(8);\n\n if (width > 0 && height > 0) {\n return { width, height };\n }\n\n return undefined;\n }\n\n // PNG: 8-byte signature, then IHDR with width/height as big-endian uint32\n // at offset 16/20.\n if (\n buf.length >= 24 &&\n buf[0] === 0x89 &&\n buf[1] === 0x50 && // P\n buf[2] === 0x4e && // N\n buf[3] === 0x47 // G\n ) {\n const width = buf.readUInt32BE(16);\n const height = buf.readUInt32BE(20);\n\n if (width > 0 && height > 0) {\n return { width, height };\n }\n\n return undefined;\n }\n\n // JPEG: starts with 0xFFD8. Scan marker segments for a Start Of Frame\n // (SOF0-SOF15, excluding non-SOF markers 0xC4/0xC8/0xCC) which carries\n // height/width as big-endian uint16.\n if (buf.length >= 4 && buf[0] === 0xff && buf[1] === 0xd8) {\n let offset = 2;\n\n while (offset + 9 < buf.length) {\n // A marker is 0xFF followed by a non-0xFF, non-0x00 marker code.\n // JPEG permits any number of 0xFF fill bytes before the marker code,\n // so skip the whole run of 0xFF and land on the marker byte itself.\n if (buf[offset] !== 0xff) {\n offset++;\n continue;\n }\n\n let markerOffset = offset;\n\n while (markerOffset < buf.length && buf[markerOffset] === 0xff) {\n markerOffset++;\n }\n\n if (markerOffset >= buf.length) {\n break;\n }\n\n const marker = buf[markerOffset];\n // The length field (if any) follows the marker code byte.\n const segmentStart = markerOffset + 1;\n\n // 0x00 after 0xFF is a stuffed byte inside entropy-coded data, not a\n // marker; skip past it and keep scanning.\n if (marker === 0x00) {\n offset = segmentStart;\n continue;\n }\n\n // Standalone markers without a length payload.\n if (marker === 0xd8 || marker === 0xd9 || (marker >= 0xd0 && marker <= 0xd7)) {\n offset = segmentStart;\n continue;\n }\n\n if (segmentStart + 1 >= buf.length) {\n break;\n }\n\n const segmentLength = buf.readUInt16BE(segmentStart);\n\n // SOF markers carrying frame dimensions (exclude DHT 0xC4, JPG 0xC8,\n // DAC 0xCC which share the 0xCn range but are not frame headers).\n const isSof =\n marker >= 0xc0 &&\n marker <= 0xcf &&\n marker !== 0xc4 &&\n marker !== 0xc8 &&\n marker !== 0xcc;\n\n if (isSof) {\n // SOF payload after the 2-byte length: precision (1 byte),\n // height (2 bytes), width (2 bytes).\n if (segmentStart + 6 >= buf.length) {\n break;\n }\n\n const height = buf.readUInt16BE(segmentStart + 3);\n const width = buf.readUInt16BE(segmentStart + 5);\n\n if (width > 0 && height > 0) {\n return { width, height };\n }\n\n return undefined;\n }\n\n // Advance past this segment: length field + its payload.\n offset = segmentStart + segmentLength;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolve and read the intrinsic dimensions of an image referenced by a QTI\n * `<object>`/`<img>` tag.\n *\n * Security model: the `objectDataPath` comes from untrusted QTI markup, so every\n * resolved path is confined to a containment root before it is read.\n *\n * - When `packageRoot` is supplied (the normal case for package conversion), any\n * asset located anywhere inside the package is allowed — including assets a\n * sibling directory up, e.g. `questions/item.xml` referencing\n * `../images/foo.png`. This does not rely on directory names.\n * - When `packageRoot` is omitted (in-memory callers with no package context),\n * the read is confined to the source file's own directory. This is the safe\n * default: no path is read from outside where the item lives.\n *\n * @param objectDataPath - Path from the data/src attribute (e.g. \"754493.gif\")\n * @param sourceFile - Absolute path to the source QTI XML file\n * @param packageRoot - Absolute path to the package root that bounds all reads\n * @returns The image dimensions, or undefined if it cannot be resolved/read.\n */\nexport function resolveImageDimensions(\n objectDataPath: string,\n sourceFile?: string,\n packageRoot?: string\n): ImageDimensions | undefined {\n if (!sourceFile || !objectDataPath) {\n return undefined;\n }\n\n const sourceDir = dirname(sourceFile);\n\n // The containment root: the package root when known (so any in-package asset\n // resolves regardless of directory naming), otherwise the item's own\n // directory. If a packageRoot is given but the source file somehow sits\n // outside it, fall back to the source directory rather than trusting it.\n let root = sourceDir;\n let shouldTryPackageRoot = false;\n\n if (packageRoot) {\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedRoot = resolve(packageRoot);\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const resolvedSourceDir = resolve(sourceDir);\n const rel = relative(resolvedRoot, resolvedSourceDir);\n const sourceInsideRoot = rel === '' || (!isAbsolute(rel) && rel.split(sep)[0] !== '..');\n\n root = sourceInsideRoot ? resolvedRoot : resolvedSourceDir;\n shouldTryPackageRoot = sourceInsideRoot && resolvedRoot !== resolvedSourceDir;\n }\n\n const candidates: string[] = [];\n\n if (isAbsolute(objectDataPath)) {\n candidates.push(objectDataPath);\n } else {\n // Resolve relative to the item first (most common), then relative to the\n // package root. Both are re-checked for containment before any read.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(sourceDir, objectDataPath));\n\n if (shouldTryPackageRoot) {\n // The candidate is rechecked by containedPath() for lexical and\n // realpath containment before it can reach the filesystem.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n candidates.push(join(root, objectDataPath));\n }\n }\n\n for (const candidate of candidates) {\n // containedPath dereferences symlinks and re-verifies containment, so\n // the returned path is safe to read.\n const imagePath = containedPath(candidate, root);\n\n if (!imagePath) {\n continue;\n }\n\n // Read only a bounded header region: enough for GIF/PNG and to scan the\n // early JPEG marker segments that carry frame dimensions, without\n // loading a potentially very large asset into memory.\n const buf = readHeaderBytes(imagePath);\n\n if (buf) {\n return readImageDimensionsFromBuffer(buf);\n }\n }\n\n return undefined;\n}\n","/**\n * Filesystem-backed {@link FileAccess} for Node.js callers (the CLI and\n * disk-based package conversion). Reads passage HTML and LOM metadata from the\n * local filesystem.\n *\n * This module imports Node built-ins (via the resolver helpers) and is therefore\n * NOT part of the browser-safe surface — it is wired in by Node entry points.\n */\nimport type { FileAccess } from './fileAccess.js';\nimport { resolvePassageFile } from './utils/passageResolver.js';\nimport { findAndReadLomFile } from './utils/lomFinder.js';\nimport { resolveImageDimensions } from './utils/imageDimensions.js';\n\nexport const nodeFileAccess: FileAccess = {\n resolvePassageFile,\n findAndReadLomFile,\n resolveImageDimensions,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,SAASA,gBAAc,WAAmB,MAAkC;CAIxE,MAAM,eAAe,QAAQ,IAAI;CAEjC,MAAM,oBAAoB,QAAQ,SAAS;CAC3C,MAAM,MAAM,SAAS,cAAc,iBAAiB;CAIpD,IAAI,QAAQ,MAAM,WAAW,GAAG,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,OAAO,MACvD;CAGJ,OAAO;AACX;;;;;;;;AASA,SAAgB,mBACZ,gBACA,YACkB;CAClB,IAAI,CAAC,cAAc,CAAC,gBAChB;CAIJ,MAAM,YAAY,QAAQ,UAAU;CAKpC,MAAM,OAAO,QAAQ,SAAS;CAK9B,MAAM,aAAuB,CAAC;CAE9B,IAAI,WAAW,cAAc,GACzB,WAAW,KAAK,cAAc;MAC3B;EAEH,WAAW,KAAK,KAAK,WAAW,cAAc,CAAC;EAE/C,WAAW,KAAK,KAAK,MAAM,cAAc,CAAC;CAC9C;CAEA,KAAK,MAAM,aAAa,YAAY;EAEhC,MAAM,cAAcA,gBAAc,WAAW,IAAI;EAEjD,IAAI,CAAC,eAAe,CAAC,WAAW,WAAW,GACvC;EAGJ,IAAI;GACA,OAAO,aAAa,aAAa,OAAO,CA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C,MAAM,YAAY,cAAc,WAAW,IAAI;EAE/C,IAAI,CAAC,WACD;EAMJ,MAAM,MAAM,gBAAgB,SAAS;EAErC,IAAI,KACA,OAAO,8BAA8B,GAAG;CAEhD;AAGJ;;;AClUA,MAAa,iBAA6B;CACtC;CACA;CACA;AACJ"}
@@ -1,13 +1,13 @@
1
1
  import { i as __toESM, t as __commonJSMin } from "./rolldown-runtime-B4iAMlE-.js";
2
- import { _ as isEnterKey, b as isTabKey, c as usePrefix, d as useEffect, f as useState, h as isBackspaceKey, l as makeTheme, o as useKeypress, t as createPrompt } from "./create-prompt-DU9wLVhI.js";
3
- import { i as chalk$1, o as require_string_width, x as DiagnosticCode } from "./table-DjOn2Tsk.js";
2
+ import { _ as isEnterKey, b as isTabKey, c as usePrefix, d as useEffect, f as useState, h as isBackspaceKey, l as makeTheme, o as useKeypress, t as createPrompt } from "./create-prompt-DyNnKXYU.js";
3
+ import { D as DiagnosticCode, i as chalk$1, o as require_string_width } from "./table-DTSv0atR.js";
4
4
  import process$1 from "node:process";
5
5
  import { access, readFile } from "fs/promises";
6
6
  import { resolve } from "path";
7
7
  import os from "node:os";
8
8
  import { homedir } from "os";
9
9
  import tty from "node:tty";
10
- //#region ../../node_modules/.pnpm/@inquirer+input@5.1.3_@types+node@26.3.0/node_modules/@inquirer/input/dist/index.js
10
+ //#region ../../node_modules/.pnpm/@inquirer+input@5.1.6_@types+node@26.6.2/node_modules/@inquirer/input/dist/index.js
11
11
  const inputTheme = { validationFailureMode: "keep" };
12
12
  var dist_default = createPrompt((config, done) => {
13
13
  const { prefill = "tab" } = config;
@@ -578,11 +578,15 @@ const wideRanges = [
578
578
  94192,
579
579
  94198,
580
580
  94208,
581
- 101589,
581
+ 101594,
582
582
  101631,
583
- 101662,
583
+ 101664,
584
584
  101760,
585
585
  101874,
586
+ 101888,
587
+ 102801,
588
+ 102816,
589
+ 102866,
586
590
  110576,
587
591
  110579,
588
592
  110581,
@@ -590,7 +594,7 @@ const wideRanges = [
590
594
  110589,
591
595
  110590,
592
596
  110592,
593
- 110882,
597
+ 110888,
594
598
  110898,
595
599
  110898,
596
600
  110928,
@@ -598,7 +602,7 @@ const wideRanges = [
598
602
  110933,
599
603
  110933,
600
604
  110948,
601
- 110951,
605
+ 110952,
602
606
  110960,
603
607
  111355,
604
608
  119552,
@@ -613,6 +617,8 @@ const wideRanges = [
613
617
  127374,
614
618
  127377,
615
619
  127386,
620
+ 127406,
621
+ 127406,
616
622
  127488,
617
623
  127490,
618
624
  127504,
@@ -666,13 +672,15 @@ const wideRanges = [
666
672
  128720,
667
673
  128722,
668
674
  128725,
669
- 128728,
675
+ 128729,
670
676
  128732,
671
677
  128735,
672
678
  128747,
673
679
  128748,
674
680
  128756,
675
681
  128764,
682
+ 128986,
683
+ 128986,
676
684
  128992,
677
685
  129003,
678
686
  129008,
@@ -686,24 +694,22 @@ const wideRanges = [
686
694
  129648,
687
695
  129660,
688
696
  129664,
689
- 129674,
690
- 129678,
691
697
  129734,
692
698
  129736,
693
699
  129736,
694
- 129741,
695
- 129756,
700
+ 129740,
701
+ 129757,
696
702
  129759,
697
- 129770,
703
+ 129771,
698
704
  129775,
699
- 129784,
705
+ 129786,
700
706
  131072,
701
707
  196605,
702
708
  196608,
703
709
  262141
704
710
  ];
705
711
  //#endregion
706
- //#region ../../node_modules/.pnpm/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/utilities.js
712
+ //#region ../../node_modules/.pnpm/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/utilities.js
707
713
  /**
708
714
  Binary search on a sorted flat array of [start, end] pairs.
709
715
 
@@ -724,7 +730,7 @@ const isInRange = (ranges, codePoint) => {
724
730
  return false;
725
731
  };
726
732
  //#endregion
727
- //#region ../../node_modules/.pnpm/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/lookup.js
733
+ //#region ../../node_modules/.pnpm/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/lookup.js
728
734
  const commonCjkCodePoint = 19968;
729
735
  const [wideFastPathStart, wideFastPathEnd] = /* #__PURE__ */ findWideFastPathRange(wideRanges);
730
736
  function findWideFastPathRange(ranges) {
@@ -745,7 +751,7 @@ const isAmbiguous = (codePoint) => {
745
751
  if (codePoint < 161 || codePoint > 1114109) return false;
746
752
  return isInRange(ambiguousRanges, codePoint);
747
753
  };
748
- const isFullWidth = (codePoint) => {
754
+ const isFullwidth = (codePoint) => {
749
755
  if (codePoint < 12288 || codePoint > 65510) return false;
750
756
  return isInRange(fullwidthRanges, codePoint);
751
757
  };
@@ -755,13 +761,13 @@ const isWide = (codePoint) => {
755
761
  return isInRange(wideRanges, codePoint);
756
762
  };
757
763
  //#endregion
758
- //#region ../../node_modules/.pnpm/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/index.js
764
+ //#region ../../node_modules/.pnpm/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/index.js
759
765
  function validate(codePoint) {
760
766
  if (!Number.isSafeInteger(codePoint)) throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
761
767
  }
762
768
  function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
763
769
  validate(codePoint);
764
- if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
770
+ if (isFullwidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
765
771
  return 1;
766
772
  }
767
773
  //#endregion
@@ -1963,6 +1969,7 @@ const KNOWN_CONFIG_KEYS = /* @__PURE__ */ new Set([
1963
1969
  "organisationId",
1964
1970
  "mediaVault",
1965
1971
  "customAssetUrl",
1972
+ "preserveAssetFilenames",
1966
1973
  "itemReferenceSource",
1967
1974
  "itemFilenameSource",
1968
1975
  "truncateTags"
@@ -2061,6 +2068,15 @@ function validateConfig(config) {
2061
2068
  file: "customAssetUrl"
2062
2069
  });
2063
2070
  }
2071
+ if ("preserveAssetFilenames" in config) {
2072
+ if (typeof config.preserveAssetFilenames === "boolean") valid.preserveAssetFilenames = config.preserveAssetFilenames;
2073
+ else diagnostics.push({
2074
+ level: "error",
2075
+ code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
2076
+ message: `Invalid preserveAssetFilenames: "${String(config.preserveAssetFilenames)}". Must be boolean.`,
2077
+ file: "preserveAssetFilenames"
2078
+ });
2079
+ }
2064
2080
  if ("itemReferenceSource" in config) {
2065
2081
  if (typeof config.itemReferenceSource === "string" && VALID_ITEM_REFERENCE_SOURCES.includes(config.itemReferenceSource)) valid.itemReferenceSource = config.itemReferenceSource;
2066
2082
  else diagnostics.push({
@@ -2238,4 +2254,4 @@ function expandTilde(filePath) {
2238
2254
  //#endregion
2239
2255
  export { chalk as a, dist_default as c, boxen as i, loadConfig as n, eastAsianWidth as o, showBanner as r, stripAnsi as s, expandTilde as t };
2240
2256
 
2241
- //# sourceMappingURL=pathUtils-B9yPTlVF.js.map
2257
+ //# sourceMappingURL=pathUtils-mTQZ0wYS.js.map