mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-05 16:02:03 +00:00
With the preference on, the shell and the first-paint stamp set dir="rtl" and data-mirror while lang stays as it is, so a reload paints no left-to-right frame, and I18nProvider gets the direction so React Aria's keys, popovers and toasts turn with the page. Under data-mirror every box takes its text direction from its text, so labels, times and parentheses keep their order, and the page aligns to the right. Chrome treats match-parent as inherit, so the right is set on the root and the few boxes that align to start or end name their side.
39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
// Normalize appearance before first paint. The build fills the palette list and default from src/shell/palettes.ts, and
|
|
// the right-to-left scripts from src/i18n/direction.ts.
|
|
(function () {
|
|
var read = function (key) {
|
|
try {
|
|
return localStorage.getItem(key);
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
var scheme = read('doona-scheme');
|
|
var palette = read('doona-palette');
|
|
var lang = read('doona-lang');
|
|
var d = document.documentElement;
|
|
var dark = scheme === 'dark' || (scheme !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches);
|
|
var palettes = '__PALETTES__';
|
|
var parts = (palettes.includes(palette) ? palette : '__DEFAULT_PALETTE__').split('/');
|
|
d.dataset.scheme = dark ? 'dark' : 'light';
|
|
d.dataset.family = parts[0];
|
|
d.dataset.flavour = parts[1];
|
|
d.dataset.wordmark = read('doona-wordmark') === 'plain' ? 'plain' : 'gradient';
|
|
d.lang = lang === 'zh-CN' ? 'zh-CN' : lang === 'en' ? 'en-US' : 'zh-TW';
|
|
// The direction as pageDirection in src/i18n/direction.ts decides it: right to left in the mirrored layout, else the
|
|
// locale's text info, else its likely script.
|
|
var mirrored = read('doona-mirror') === 'on';
|
|
var rtlScripts = '__RTL_SCRIPTS__';
|
|
var dir = mirrored ? 'rtl' : 'ltr';
|
|
if (!mirrored)
|
|
try {
|
|
var tag = new Intl.Locale(d.lang);
|
|
var info = tag.getTextInfo ? tag.getTextInfo() : tag.textInfo;
|
|
if (info && info.direction ? info.direction === 'rtl' : rtlScripts.includes(tag.maximize().script)) dir = 'rtl';
|
|
} catch {
|
|
// Left to right.
|
|
}
|
|
d.dir = dir;
|
|
if (mirrored) d.dataset.mirror = '';
|
|
})();
|