fix(styles): synchronize accent across open apps
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@wrnexus/cli",
|
"name": "@wrnexus/cli",
|
||||||
"version": "0.8.26",
|
"version": "0.8.27",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@wrnexus/dev-server",
|
"name": "@wrnexus/dev-server",
|
||||||
"version": "0.8.25",
|
"version": "0.8.26",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@wrnexus/styles",
|
"name": "@wrnexus/styles",
|
||||||
"version": "0.8.11",
|
"version": "0.8.12",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -745,6 +745,17 @@ export function renderThemeRuntime(theme: ResolvedTheme): string {
|
|||||||
window.dispatchEvent(new CustomEvent("wrnexus:accent-changed",{detail:{accent:null}}));
|
window.dispatchEvent(new CustomEvent("wrnexus:accent-changed",{detail:{accent:null}}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function syncSharedAccent(){
|
||||||
|
var cookieAccent=readCookie(ACCENT_COOKIE);
|
||||||
|
var next=cookieAccent&&ACCENTS.indexOf(cookieAccent)>=0?cookieAccent:DEFAULT_ACCENT;
|
||||||
|
var current=el.getAttribute("data-accent");
|
||||||
|
if(next===current)return;
|
||||||
|
if(next)el.setAttribute("data-accent",next);else el.removeAttribute("data-accent");
|
||||||
|
syncStylesheet(getTheme(),next);
|
||||||
|
syncAccentButtons(document);
|
||||||
|
window.dispatchEvent(new CustomEvent("wrnexus:accent-changed",{detail:{accent:next}}));
|
||||||
|
}
|
||||||
|
|
||||||
function bind(root){
|
function bind(root){
|
||||||
var target=root||document;
|
var target=root||document;
|
||||||
|
|
||||||
@@ -803,6 +814,10 @@ export function renderThemeRuntime(theme: ResolvedTheme): string {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("wrnexus:navigated",function(){bind(document);});
|
window.addEventListener("wrnexus:navigated",function(){bind(document);});
|
||||||
|
window.addEventListener("focus",syncSharedAccent);
|
||||||
|
window.addEventListener("pageshow",syncSharedAccent);
|
||||||
|
document.addEventListener("visibilitychange",function(){if(!document.hidden)syncSharedAccent();});
|
||||||
|
window.setInterval(syncSharedAccent,1000);
|
||||||
if(document.readyState==="loading"){
|
if(document.readyState==="loading"){
|
||||||
document.addEventListener("DOMContentLoaded",function(){bind(document);});
|
document.addEventListener("DOMContentLoaded",function(){bind(document);});
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ describe("theme accents", () => {
|
|||||||
expect(runtime).toContain('"domain":"localhost"');
|
expect(runtime).toContain('"domain":"localhost"');
|
||||||
expect(runtime).toContain("deleteCookie(ACCENT_COOKIE);");
|
expect(runtime).toContain("deleteCookie(ACCENT_COOKIE);");
|
||||||
expect(runtime).toContain("writeCookie(ACCENT_COOKIE,name,ACCENT_COOKIE_OPTIONS)");
|
expect(runtime).toContain("writeCookie(ACCENT_COOKIE,name,ACCENT_COOKIE_OPTIONS)");
|
||||||
|
expect(runtime).toContain('window.addEventListener("focus",syncSharedAccent)');
|
||||||
|
expect(runtime).toContain("window.setInterval(syncSharedAccent,1000)");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test("live document accent has priority over cookie and default", () => {
|
test("live document accent has priority over cookie and default", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user