Release 0.0.9

This commit is contained in:
2026-04-20 21:32:36 +00:00
parent c99788f3e2
commit 43d1a61535
5 changed files with 111 additions and 10 deletions

View File

@@ -5,23 +5,23 @@ const ATTRIBUTE_PATTERNS = [
/url\(\s*["']?([^"')]+)["']?\s*\)/gi
];
export function collectStringCandidates(value, visit) {
export function collectStringCandidates(value, visit, path = []) {
if (typeof value === "string") {
visit(value);
visit(value, path);
return;
}
if (Array.isArray(value)) {
for (const entry of value) collectStringCandidates(entry, visit);
for (const [index, entry] of value.entries()) collectStringCandidates(entry, visit, [...path, index]);
return;
}
if ((value !== null) && (typeof value === "object")) {
for (const entry of Object.values(value)) collectStringCandidates(entry, visit);
for (const [key, entry] of Object.entries(value)) collectStringCandidates(entry, visit, [...path, key]);
}
}
export function extractReferencesFromValue(value, source) {
const references = [];
collectStringCandidates(value, candidate => {
collectStringCandidates(value, (candidate, candidatePath) => {
const direct = resolveReference(candidate, source);
if (direct && isMediaPath(direct.path)) {
references.push({
@@ -30,6 +30,7 @@ export function extractReferencesFromValue(value, source) {
sourceLabel: source.sourceLabel,
sourceName: source.sourceName,
sourceUuid: source.sourceUuid,
sourceTrail: source.resolveSourceTrail?.(candidatePath) ?? null,
rawValue: candidate,
normalized: {
...direct,
@@ -50,6 +51,7 @@ export function extractReferencesFromValue(value, source) {
sourceLabel: source.sourceLabel,
sourceName: source.sourceName,
sourceUuid: source.sourceUuid,
sourceTrail: source.resolveSourceTrail?.(candidatePath) ?? null,
rawValue: match[1],
normalized: {
...nested,