@pollinations/ui 0.1.0-alpha.12 → 0.1.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1308,6 +1308,7 @@ function systemMode() {
1308
1308
  }
1309
1309
  var current = readStored() ?? systemMode();
1310
1310
  var listeners = /* @__PURE__ */ new Set();
1311
+ var systemQuery;
1311
1312
  function apply() {
1312
1313
  if (typeof document === "undefined") return;
1313
1314
  document.documentElement.classList.toggle("dark", current === "dark");
@@ -1336,16 +1337,28 @@ function handleStorage(event) {
1336
1337
  apply();
1337
1338
  emit();
1338
1339
  }
1340
+ function handleSystemChange() {
1341
+ if (readStored() !== null) return;
1342
+ const next = systemMode();
1343
+ if (next === current) return;
1344
+ current = next;
1345
+ apply();
1346
+ emit();
1347
+ }
1339
1348
  function subscribe(listener) {
1340
1349
  if (listeners.size === 0 && typeof window !== "undefined") {
1341
1350
  apply();
1342
1351
  window.addEventListener("storage", handleStorage);
1352
+ systemQuery = window.matchMedia?.("(prefers-color-scheme: dark)");
1353
+ systemQuery?.addEventListener("change", handleSystemChange);
1343
1354
  }
1344
1355
  listeners.add(listener);
1345
1356
  return () => {
1346
1357
  listeners.delete(listener);
1347
1358
  if (listeners.size === 0 && typeof window !== "undefined") {
1348
1359
  window.removeEventListener("storage", handleStorage);
1360
+ systemQuery?.removeEventListener("change", handleSystemChange);
1361
+ systemQuery = void 0;
1349
1362
  }
1350
1363
  };
1351
1364
  }