ifcurl/forgejo/custom/public/assets/viewer-util.js
Bruno Postle 10ea3ca071 Fix license headers: correct copyright owner and add SPDX identifiers
JS files had wrong copyright owner (The Forgejo Authors → Bruno Postle).
Python files lacked SPDX-License-Identifier: LGPL-3.0-or-later.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 21:07:23 +01:00

39 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2026 Bruno Postle <bruno@postle.net>
// SPDX-License-Identifier: MIT
//
// Pure utility functions shared between viewer.js, ifcurl.js, and tests.
// Parse a Forgejo browse path: /owner/repo/src/commit/{40hex}/{treepath}
// Returns {repoPath, hash, treePath} or null.
export function parseCommitHref(href) {
const m = href.match(/^\/([^/]+\/[^/]+)\/src\/commit\/([0-9a-f]{40})\/(.+)$/i);
if (!m) return null;
return { repoPath: m[1], hash: m[2], treePath: m[3] };
}
// Returns true if the selector contains only IFC type names joined by "+".
// E.g. "IfcWall", "IfcWall+IfcSlab". Property filters and name= require
// server-side resolution via /select.
export function isSimpleTypeSelector(selectorStr) {
return selectorStr.split("+").every(part => /^[Ii]fc[A-Za-z0-9]+$/.test(part.trim()));
}
// Set-subtract toRemove from allItems across all model IDs.
// Both arguments are ModelIdMap: { [modelId]: Iterable<number> }.
export function subtractIdMap(allItems, toRemove) {
const result = {};
for (const [modelId, allIds] of Object.entries(allItems)) {
const removeSet = new Set(toRemove[modelId] ?? []);
const remaining = [];
for (const id of allIds) {
if (!removeSet.has(id)) remaining.push(id);
}
if (remaining.length > 0) result[modelId] = remaining;
}
return result;
}
// Returns true if ref looks like a git commit hash (740 hex chars).
export function isCommitHash(ref) {
return /^[0-9a-f]{7,40}$/.test(ref);
}