From 7938f9ca7446cfc8726a4b863c26ece686b11bd1 Mon Sep 17 00:00:00 2001 From: mARTin-B78 Date: Fri, 4 Sep 2026 13:27:43 +0200 Subject: [PATCH] refactor: scope frontend utilities --- CHANGELOG.md | 2 ++ TODO.md | 4 ++-- VERSION | 2 +- docs/ARCHITECTURE.md | 1 + static/index.html | 16 ++++++++-------- static/js/utils.js | 27 +++++++++++++++++++++++++++ 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f61295..9614c9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) · versioned wi ## [Unreleased] ### Changed +- **Utility namespace migration.** Shared DOM, status, accessibility, language, tab, and low-memory helpers now use a + private scope with explicit compatibility exports and a `window.TTVC.utils` API. - **Voice-inspector namespace migration.** The three-pane voice inspector now keeps its selection state in a private scope while preserving `selectVoice` and exposing `window.TTVC.voiceInspector.select`. - **Character-library namespace migration.** Character rendering, detail views, avatar handling, and generation actions diff --git a/TODO.md b/TODO.md index 5f7efb7..657f4a2 100644 --- a/TODO.md +++ b/TODO.md @@ -127,8 +127,8 @@ architecture change: the larger Audiobook/Rehearser/style split. - [ ] Replace broad globals with namespaces such as `window.TTVC.audiobook`; pure leaves, Audiobook/Reader/Rehearser feature modules, Studio, and character-library persistence now use private scopes with explicit compatibility exports. Voice-library loading, rendering, benchmarking, import workflows, character-sheet extraction, and character-library - rendering/actions, and voice-inspector selection are now scoped; - remaining utility and legacy library UI modules still require the same responsibility-by-responsibility migration. + rendering/actions, voice-inspector selection, and shared utility helpers are now scoped; remaining legacy library UI + modules still require the same responsibility-by-responsibility migration. - [x] Generate the feature-module list for `loader.js` and `scripts/minify.mjs` from one shared manifest; larger responsibility splits remain. - [x] Add a dependency-free frontend syntax and top-level declaration collision gate (`npm run check:frontend`); diff --git a/VERSION b/VERSION index a6db507..ac73399 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.24.88 +1.24.89 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 067ac14..c36acb8 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -78,6 +78,7 @@ Done incrementally as global-scope ordered files (no ES-module change needed) - ✅ Character-sheet extraction and prompt helpers use a private scope with explicit compatibility exports and a namespace API. - ✅ Character-library rendering, detail, avatar, and generation actions use a private scope with compatibility exports and a namespace API. - ✅ Voice-inspector selection state uses a private scope with a compatibility export and namespace API. +- ✅ Shared utility helpers use a private scope with explicit compatibility exports and a `window.TTVC.utils` API. - ✅ `static/css/resource-diagnostics.css` — isolated Performance/resource diagnostic panel styles. - ✅ `static/css/background-jobs.css` — isolated background-job history and retry-panel styles. - ✅ `static/css/voice-design.css` — isolated Voice Design form, samples, and preview-match styles. diff --git a/static/index.html b/static/index.html index 24363f2..6112ad7 100644 --- a/static/index.html +++ b/static/index.html @@ -10,7 +10,7 @@ - + @@ -27,12 +27,12 @@ - - - - - - + + + + + + @@ -397,7 +397,7 @@ window.toggleNavTree = function(treeId, chevronId) { - + diff --git a/static/js/utils.js b/static/js/utils.js index eb5bd64..bf6152f 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1,5 +1,7 @@ // ── Utility ─────────────────────────────────────────────────────────────── +(function (root) { + const $ = id => document.getElementById(id); // ── Voice avatar colors ─────────────────────────────────────────────────── @@ -1382,3 +1384,28 @@ if (typeof MutationObserver !== 'undefined') { } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => initLangSelects(document)); else initLangSelects(document); + +Object.assign(root, { + $, avatarColor, toast, confirmDialog, status, ensureStatusBar, updateStatusBar, + escHtml, debounce, logErr, ttvcIsLowMemoryDevice, fmtDuration, loadingMarkup, + setBusyButton, enhanceAccessibility, applyTheme, cc2flag, ccDisplay, + setPreviewLang, openPreviewLangPicker, createSearchablePicker, getStoredTags, + addStoredTag, scheduleVoiceLibraryLoad, disabledBackendTabMessage, switchTab, + detectLang, workflowCrumbGo, refreshWorkflowCrumbs, ensureLangDatalist, + normalizeLangCodeInput, langFlag, enhanceLangSelect, initLangSelects, + FLAG_OPTIONS, ALL_FLAGS, LANG_FLAG_DEFAULT, VL_SAMPLE_TEXTS, _VL_LANG_FLAG, + LANG_CODE_OPTIONS, +}); +// `window.status` is a replaceable legacy browser property; assignment via +// Object.assign can be ignored or coerce the function to a string. +try { Object.defineProperty(root, 'status', { configurable: true, writable: true, value: status }); } catch (_) {} +root.TTVC = root.TTVC || {}; +root.TTVC.utils = root.TTVC.utils || {}; +Object.assign(root.TTVC.utils, { + dom: { $, escHtml }, + ui: { toast, confirmDialog, status, setBusyButton, loadingMarkup }, + accessibility: { enhance: enhanceAccessibility }, + language: { detect: detectLang, flag: langFlag, enhanceSelect: enhanceLangSelect }, + memory: { isLow: ttvcIsLowMemoryDevice }, +}); +})(window);