ranui 0.2.0-alpha.6 → 0.2.0-alpha.7

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.
@@ -1,170 +0,0 @@
1
- import { a as u, i as m, n as b, r as v, t as f } from "./utils-DBfrRFoE.js";
2
- import { t as g } from "./events-C59wGdni.js";
3
- import { a as p, n as w } from "./ssr-DSGwPtEd.js";
4
- var i = "ran-theme", s = null, a = null, o = (e) => {
5
- if (e && "style" in e) return e;
6
- if (e && "documentElement" in e) return e.documentElement;
7
- if (!(typeof document > "u"))
8
- return document.documentElement;
9
- }, l = (e) => {
10
- const t = typeof window < "u" && window.matchMedia("(prefers-color-scheme: dark)").matches;
11
- e.setAttribute("data-ran-theme", t ? "dark" : "light"), e.setAttribute("theme", t ? "dark" : "light");
12
- }, y = () => {
13
- s && a && (s.removeEventListener("change", a), s = null, a = null);
14
- }, d = (e, t) => {
15
- const r = o(t);
16
- if (r) {
17
- if (y(), e === "system") {
18
- if (typeof window > "u") return;
19
- l(r), s = window.matchMedia("(prefers-color-scheme: dark)"), a = () => l(r), s.addEventListener("change", a);
20
- try {
21
- localStorage.setItem(i, "system");
22
- } catch {
23
- }
24
- return;
25
- }
26
- r.setAttribute("data-ran-theme", e), r.setAttribute("theme", e);
27
- try {
28
- localStorage.setItem(i, e);
29
- } catch {
30
- }
31
- }
32
- }, k = (e) => {
33
- const t = o(e);
34
- if (!t) return "";
35
- const r = t.getAttribute("data-ran-theme") || t.getAttribute("theme") || "";
36
- if (r === "light" || r === "dark") {
37
- try {
38
- if (localStorage.getItem(i) === "system") return "system";
39
- } catch {
40
- }
41
- return r;
42
- }
43
- return "";
44
- }, _ = (e, t, r) => {
45
- const n = o(r);
46
- n && n.style.setProperty(e, String(t));
47
- }, x = (e, t) => {
48
- const r = o(t);
49
- r && r.style.removeProperty(e);
50
- }, L = (e, t) => {
51
- Object.entries(e).forEach(([r, n]) => {
52
- if (n == null) {
53
- x(r, t);
54
- return;
55
- }
56
- _(r, n, t);
57
- });
58
- }, z = (e) => {
59
- if (!(typeof localStorage > "u"))
60
- try {
61
- const t = localStorage.getItem(i);
62
- (t === "light" || t === "dark" || t === "system") && d(t, e);
63
- } catch {
64
- }
65
- }, E = ".remove-wap-active-focus{outline:0;-webkit-tap-highlight-color:transparent}.remove-wap-active-focus:active,.remove-wap-active-focus:focus{outline:0;-webkit-tap-highlight-color:transparent}:host{display:var(--ran-theme-switch-display, inline-flex);box-sizing:border-box}.ran-theme-switch{display:inline-flex;align-items:center;gap:var(--ran-theme-switch-gap, 2px);padding:var(--ran-theme-switch-padding, 2px);border-width:var(--ran-skin-border-width, 1px);border-style:var(--ran-skin-border-style, solid);border-color:var(--ran-theme-switch-border-color, var(--ran-color-border, #eaeaea));border-radius:var(--ran-theme-switch-radius, var(--ran-radius-full, 9999px));background:var(--ran-theme-switch-background, transparent);box-sizing:border-box}.ran-theme-switch button{width:var(--ran-theme-switch-button-size, 28px);height:var(--ran-theme-switch-button-size, 28px);display:grid;place-items:center;border:none;border-radius:var(--ran-theme-switch-radius, var(--ran-radius-full, 9999px));background:transparent;color:var(--ran-theme-switch-color, var(--ran-color-text-secondary, #4d4d4d));cursor:pointer;padding:0}.ran-theme-switch button:hover{color:var(--ran-theme-switch-hover-color, var(--ran-color-text, #171717))}.ran-theme-switch button[aria-pressed=true]{background:var(--ran-theme-switch-active-background, var(--ran-color-bg-hover, #ebebeb));color:var(--ran-theme-switch-active-color, var(--ran-color-text, #171717))}.ran-theme-switch button:focus-visible{outline:var(--ran-theme-switch-focus-outline, 2px solid var(--ran-color-primary, #006bff));outline-offset:2px}.ran-theme-switch svg{width:var(--ran-theme-switch-icon-size, 16px);height:var(--ran-theme-switch-icon-size, 16px)}", h = [
66
- "system",
67
- "light",
68
- "dark"
69
- ], S = {
70
- system: '<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="1.5" y="2.5" width="13" height="9" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M5.5 14h5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
71
- light: '<svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="3" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M8 1v1.8M8 13.2V15M15 8h-1.8M2.8 8H1m11.4-4.4-1.3 1.3M4.9 11.1l-1.3 1.3m9.8 0-1.3-1.3M4.9 4.9 3.6 3.6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
72
- dark: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M13.5 9.5A6 6 0 0 1 6.5 2.5a6 6 0 1 0 7 7z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>'
73
- }, c = "ran-theme-switch-sync", A = class extends w {
74
- static get observedAttributes() {
75
- return [
76
- "label-system",
77
- "label-light",
78
- "label-dark",
79
- "sheet"
80
- ];
81
- }
82
- _events = new g();
83
- _shadowDom;
84
- _group;
85
- constructor() {
86
- super(), this._shadowDom = b(this, E), this._group = f(this._shadowDom, ".ran-theme-switch", () => {
87
- const e = document.createElement("div");
88
- e.className = "ran-theme-switch", e.setAttribute("part", "switch"), e.setAttribute("role", "group");
89
- for (const t of h) {
90
- const r = document.createElement("button");
91
- r.type = "button", r.dataset.choice = t, r.setAttribute("part", `button ${t}`), r.setAttribute("aria-pressed", "false"), r.innerHTML = S[t], e.appendChild(r);
92
- }
93
- return e;
94
- });
95
- }
96
- get sheet() {
97
- return v(this, "sheet");
98
- }
99
- set sheet(e) {
100
- m(this, "sheet", e);
101
- }
102
- get value() {
103
- return k() || "system";
104
- }
105
- set value(e) {
106
- h.includes(e) && this._select(e);
107
- }
108
- _label(e) {
109
- const t = {
110
- system: "System theme",
111
- light: "Light theme",
112
- dark: "Dark theme"
113
- }[e];
114
- return this.getAttribute(`label-${e}`) || t;
115
- }
116
- _syncLabels() {
117
- this._group.setAttribute("aria-label", this.getAttribute("label") || "Theme");
118
- for (const e of this._group.querySelectorAll("button")) e.setAttribute("aria-label", this._label(e.dataset.choice));
119
- }
120
- _reflect() {
121
- const e = this.value;
122
- for (const t of this._group.querySelectorAll("button")) t.setAttribute("aria-pressed", t.dataset.choice === e ? "true" : "false");
123
- }
124
- _select(e) {
125
- d(e), this._reflect(), this._syncMeta(e), document.dispatchEvent(new CustomEvent(c)), this.dispatchEvent(new CustomEvent("change", {
126
- detail: { theme: e },
127
- bubbles: !0,
128
- composed: !0
129
- }));
130
- }
131
- _syncMeta(e) {
132
- if (typeof requestAnimationFrame > "u") return;
133
- const t = document.querySelectorAll('meta[name="theme-color"]');
134
- t.length && requestAnimationFrame(() => {
135
- for (const r of t)
136
- if (r.dataset.ranOriginalContent === void 0 && (r.dataset.ranOriginalContent = r.getAttribute("content") || ""), e === "system") r.setAttribute("content", r.dataset.ranOriginalContent);
137
- else {
138
- const n = getComputedStyle(document.documentElement).getPropertyValue("--ran-color-bg").trim() || getComputedStyle(document.body).backgroundColor;
139
- r.setAttribute("content", n);
140
- }
141
- });
142
- }
143
- _handleClick = (e) => {
144
- const t = e.target.closest?.("button")?.dataset.choice;
145
- t && h.includes(t) && this._select(t);
146
- };
147
- _handleSync = () => this._reflect();
148
- handlerExternalCss = () => {
149
- u(this, this._shadowDom, "sheet", null, this.sheet);
150
- };
151
- connectedCallback() {
152
- this.handlerExternalCss(), this._syncLabels(), this._reflect(), this._events.on(this._group, "click", this._handleClick), document.addEventListener(c, this._handleSync), typeof window < "u" && window.addEventListener("storage", this._handleSync);
153
- }
154
- disconnectedCallback() {
155
- this._events.abort(), document.removeEventListener(c, this._handleSync), typeof window < "u" && window.removeEventListener("storage", this._handleSync);
156
- }
157
- attributeChangedCallback(e, t, r) {
158
- t !== r && (e === "sheet" && this.handlerExternalCss(), e.startsWith("label") && this._syncLabels());
159
- }
160
- };
161
- p("r-theme-switch", A);
162
- export {
163
- d as a,
164
- z as i,
165
- x as n,
166
- _ as o,
167
- k as r,
168
- L as s,
169
- A as t
170
- };