PageSourceSearch

https://crm.basecloudglobal.com/theme-boot.js

js basecloudglobal.com collected 2026-10-03 21:54:00 UTC 2,757 bytes, 64 lines download raw bytes

1// theme-boot.js
2//
3// Paints the last theme this browser showed for the current account before Angular loads.
4//
5// Themes are resolved on the server and arrive with /me, which is after the bundle has
6// downloaded, parsed and made a round trip. Until then the page would render the stylesheet's
7// fallback colours: a light flash for every dark or custom-theme user, on every load.
8// ThemeService writes the exact CSS variables it paints to localStorage under
9// `bc-theme-cache`; this replays them.
10//
11// A classic script loaded from index.html, deliberately outside src/, because it has to run
12// before any bundle. It reads storage and sets style properties and nothing else. It can only
13// ever be one load behind: ThemeService repaints from the server's answer moments later.
14//
15// Keep the key and the entry shape in step with THEME_CACHE_STORAGE_KEY in
16// src/app/services/theme.service.ts.
17(function () {
18    'use strict';
19
20    try {
21        var raw = window.localStorage.getItem('bc-theme-cache');
22        if (!raw) return;
23        var cache = JSON.parse(raw);
24        if (!cache || typeof cache !== 'object') return;
25
26        // The account is per tab (sessionStorage), so a refreshed tab gets its own account's
27        // theme; a fresh tab has no account yet and takes the last theme painted anywhere.
28        var ownerId = null;
29        try {
30            var context = JSON.parse(
31                window.sessionStorage.getItem('bc_account_context') || 'null'
32            );
33            ownerId = context && context.id ? String(context.id) : null;
34        } catch (e) {
35            ownerId = null;
36        }
37
38        var entry =
39            (ownerId && cache.owners && cache.owners[ownerId]) || cache.last;
40        if (!entry || !entry.vars || typeof entry.vars !== 'object') return;
41
42        var root = document.documentElement;
43        for (var name in entry.vars) {
44            // Only the variables ThemeService writes — never arbitrary properties from storage.
45            if (
46                Object.prototype.hasOwnProperty.call(entry.vars, name) &&
47                (name.indexOf('--theme-') === 0 ||
48                    name === '--picker-icon-filter') &&
49                typeof entry.vars[name] === 'string'
50            ) {
51                root.style.setProperty(name, entry.vars[name]);
52            }
53        }
54        if (typeof entry.key === 'string')
55            root.setAttribute('data-theme', entry.key);
56
57        if (typeof entry.meta === 'string') {
58            var meta = document.querySelector('meta[name="theme-color"]');
59            if (meta) meta.setAttribute('content', entry.meta);
60        }
61    } catch (e) {
62        // Storage unavailable or corrupt — the stylesheet's fallback colours still render.
63    }
64})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.