ranui 0.2.0-alpha.6 → 0.2.1-alpha.1

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.
Files changed (121) hide show
  1. package/README.md +38 -3
  2. package/README.zh-CN.md +40 -10
  3. package/dist/arrow-down-Bi5kqUrX.js +12 -0
  4. package/dist/builder.d.ts +2 -2
  5. package/dist/builder.js +32 -28
  6. package/dist/builtin-D9djWkCE.js +409 -0
  7. package/dist/{button-Be_uHDZG.js → button-BfYw0fes.js} +1 -1
  8. package/dist/button.js +1 -1
  9. package/dist/{card-BVvXX6KM.js → card-CqJa4Q_v.js} +1 -1
  10. package/dist/card.js +1 -1
  11. package/dist/{checkbox-BtoX9X2Z.js → checkbox-CThC9-vy.js} +1 -1
  12. package/dist/checkbox.js +1 -1
  13. package/dist/{colorpicker-Dukms7ET.js → colorpicker-XNxDRcQ-.js} +5 -6
  14. package/dist/colorpicker.js +1 -1
  15. package/dist/components/colorpicker/index.d.ts +3 -3
  16. package/dist/components/icon/builtin.d.ts +9 -0
  17. package/dist/components/icon/index.d.ts +8 -0
  18. package/dist/components/route/index.d.ts +10 -4
  19. package/dist/components/router/index.d.ts +3 -0
  20. package/dist/{dropdown-BYS1Trdu.js → dropdown-CCvsambb.js} +1 -1
  21. package/dist/dropdown.js +1 -1
  22. package/dist/factory-DCrO37si.js +334 -0
  23. package/dist/{form-BsB5JhS4.js → form-Ceq3uJzz.js} +1 -1
  24. package/dist/form.js +1 -1
  25. package/dist/i18n.d.ts +2 -0
  26. package/dist/i18n.js +6 -0
  27. package/dist/{icon-pfolda2m.js → icon-C_ENrJ3F.js} +50 -13
  28. package/dist/icon.js +4 -3
  29. package/dist/icons.js +5 -0
  30. package/dist/iife/button.iife.js +1 -1
  31. package/dist/iife/card.iife.js +1 -1
  32. package/dist/iife/checkbox.iife.js +1 -1
  33. package/dist/iife/colorpicker.iife.js +2 -2
  34. package/dist/iife/dropdown.iife.js +1 -1
  35. package/dist/iife/form.iife.js +1 -1
  36. package/dist/iife/icon.iife.js +1 -1
  37. package/dist/iife/image.iife.js +1 -1
  38. package/dist/iife/input.iife.js +1 -1
  39. package/dist/iife/loading.iife.js +1 -1
  40. package/dist/iife/math.iife.js +14 -14
  41. package/dist/iife/message.iife.js +1 -1
  42. package/dist/iife/modal.iife.js +1 -1
  43. package/dist/iife/player.iife.js +8 -8
  44. package/dist/iife/popover.iife.js +1 -1
  45. package/dist/iife/progress.iife.js +1 -1
  46. package/dist/iife/radar.iife.js +1 -1
  47. package/dist/iife/route.iife.js +1 -1
  48. package/dist/iife/router.iife.js +1 -1
  49. package/dist/iife/scratch.iife.js +1 -1
  50. package/dist/iife/section.iife.js +1 -1
  51. package/dist/iife/select.iife.js +2 -2
  52. package/dist/iife/skeleton.iife.js +1 -1
  53. package/dist/iife/tab.iife.js +1 -1
  54. package/dist/iife/tabpane.iife.js +1 -1
  55. package/dist/{image-BXpKQ9sU.js → image-B7MBI5n_.js} +1 -1
  56. package/dist/image.js +1 -1
  57. package/dist/index.cjs +256 -23
  58. package/dist/index.d.ts +3 -1
  59. package/dist/index.iife.js +266 -33
  60. package/dist/index.js +79 -74
  61. package/dist/{input-BMMM60e6.js → input-RNqdEHPf.js} +2 -2
  62. package/dist/input.js +1 -1
  63. package/dist/{loading-BScjyeVm.js → loading-B9MFI03l.js} +1 -1
  64. package/dist/loading.js +1 -1
  65. package/dist/{math-IjzOAwnA.js → math-CudIwEXZ.js} +1 -1
  66. package/dist/math.js +1 -1
  67. package/dist/{message-CLpuP8HY.js → message-DW7qWpEm.js} +34 -49
  68. package/dist/message.js +1 -1
  69. package/dist/{modal-DOTpABRe.js → modal-CrvGKL2B.js} +1 -1
  70. package/dist/modal.js +1 -1
  71. package/dist/{player-5olrw-qB.js → player-BKQaaT7o.js} +2 -2
  72. package/dist/player.js +1 -1
  73. package/dist/{popover-DRUQjdPs.js → popover-CvYIVgUS.js} +2 -2
  74. package/dist/popover.js +1 -1
  75. package/dist/{progress-BIEXYYd2.js → progress-C6jctsFH.js} +1 -1
  76. package/dist/progress.js +1 -1
  77. package/dist/{radar-DAF95_Mj.js → radar-BUb4EzmG.js} +1 -1
  78. package/dist/radar.js +1 -1
  79. package/dist/route-Djrf9UR_.js +116 -0
  80. package/dist/route.js +1 -1
  81. package/dist/{router-B9rCrWXm.js → router-BU2KhtxV.js} +22 -17
  82. package/dist/router.js +1 -1
  83. package/dist/{scratch-QlPyy1f4.js → scratch-CO4I2dIa.js} +1 -1
  84. package/dist/scratch.js +1 -1
  85. package/dist/{section-D0qMm9KM.js → section-CsUkp8bv.js} +1 -1
  86. package/dist/section.js +1 -1
  87. package/dist/{select-aAaWoveE.js → select-Dn26ajJZ.js} +8 -15
  88. package/dist/select.js +1 -1
  89. package/dist/{skeleton-CFqQmKyt.js → skeleton-BuMLhvzQ.js} +1 -1
  90. package/dist/skeleton.js +1 -1
  91. package/dist/{tab-CiF2YPck.js → tab-40fDkuox.js} +1 -1
  92. package/dist/tab.js +1 -1
  93. package/dist/{tabpane-B-m3xwqu.js → tabpane-F4Pd7JtC.js} +1 -1
  94. package/dist/tabpane.js +1 -1
  95. package/dist/test/unit/icon.builtin.test.d.ts +1 -0
  96. package/dist/test/unit/utils.colorpicker.reconnect.test.d.ts +1 -0
  97. package/dist/test/unit/utils.route.lazy.test.d.ts +1 -0
  98. package/dist/test/unit/utils.router.match.test.d.ts +1 -0
  99. package/dist/test/unit/utils.signal.owner.test.d.ts +1 -0
  100. package/dist/theme-kOWZbKCq.js +70 -0
  101. package/dist/theme-switch-B09egc6h.js +104 -0
  102. package/dist/theme-switch.js +1 -1
  103. package/dist/theme.d.ts +2 -0
  104. package/dist/theme.js +9 -0
  105. package/dist/utils/builder/core.d.ts +20 -13
  106. package/dist/utils/builder/factory.d.ts +1 -1
  107. package/dist/utils/builder/index.d.ts +2 -2
  108. package/dist/utils/builder/signal.d.ts +93 -64
  109. package/dist/utils/i18n/index.d.ts +17 -1
  110. package/dist/utils/i18n.js +16 -15
  111. package/dist/utils/router/index.d.ts +13 -3
  112. package/dist/utils/router.js +95 -54
  113. package/dist/utils/theme.d.ts +1 -1
  114. package/dist/warning-circle-fill-Cz0qu7AH.js +23 -0
  115. package/docs/BUILDER.md +230 -0
  116. package/docs/COMPONENTS.md +21 -3
  117. package/package.json +41 -3
  118. package/dist/factory-BdsO0dEW.js +0 -165
  119. package/dist/route-MQZpn2BP.js +0 -88
  120. package/dist/signal-CSSZxlK5.js +0 -57
  121. package/dist/theme-switch-B_FZvqBN.js +0 -170
@@ -1,165 +0,0 @@
1
- import { c as l, n as d } from "./mocks-CMGoftIc.js";
2
- var p = () => ({ current: null }), o = class h {
3
- el;
4
- constructor(t) {
5
- this.el = l ? new d(t) : document.createElement(t);
6
- }
7
- id(t) {
8
- return this.el.setAttribute("id", t), this;
9
- }
10
- class(t) {
11
- return l ? this.el.attributes.set("class", t) : this.el.className = t, this;
12
- }
13
- addClass(...t) {
14
- return t.forEach((e) => this.el.classList.add(e)), this;
15
- }
16
- removeClass(...t) {
17
- return t.forEach((e) => this.el.classList.remove(e)), this;
18
- }
19
- attr(t, e) {
20
- return this.el.setAttribute(t, e), this;
21
- }
22
- attrs(t) {
23
- return Object.entries(t).forEach(([e, r]) => {
24
- r != null && this.el.setAttribute(e, String(r));
25
- }), this;
26
- }
27
- boolAttr(t, e, r = "") {
28
- return e ? this.el.setAttribute(t, r) : this.el.removeAttribute(t), this;
29
- }
30
- part(t) {
31
- return this.el.setAttribute("part", t), this;
32
- }
33
- data(t, e) {
34
- return this.attr(`data-${t}`, e);
35
- }
36
- style(t, e) {
37
- return typeof t == "string" ? this.el.style.setProperty(t, e ?? "") : Object.entries(t).forEach(([r, a]) => this.el.style.setProperty(r, a)), this;
38
- }
39
- cssVar(t, e) {
40
- const r = t.startsWith("--") ? t : `--${t}`;
41
- return this.style(r, e);
42
- }
43
- aria(t, e) {
44
- return this.attr(`aria-${t}`, e);
45
- }
46
- role(t) {
47
- return this.attr("role", t);
48
- }
49
- tabIndex(t) {
50
- return this.attr("tabindex", String(t));
51
- }
52
- label(t) {
53
- return this.aria("label", t);
54
- }
55
- labelledBy(t) {
56
- return this.aria("labelledby", t);
57
- }
58
- describedBy(t) {
59
- return this.aria("describedby", t);
60
- }
61
- ariaHidden(t = !0) {
62
- return this.aria("hidden", String(t));
63
- }
64
- on(t, e, r) {
65
- return this.el.addEventListener(t, e, r), this;
66
- }
67
- listen(t, e, r, a) {
68
- return t.on(this.el, e, r, a), this;
69
- }
70
- delegate(t, e, r, a, n) {
71
- return t.delegate(this.el, e, r, a, n), this;
72
- }
73
- children(...t) {
74
- const e = (r) => r.reduce((a, n) => Array.isArray(n) ? a.concat(e(n)) : a.concat(n), []);
75
- return e(t).forEach((r) => {
76
- r != null && (r instanceof h ? this.el.appendChild(r.build()) : typeof r == "string" ? l ? this.el.appendChild(r) : this.el.appendChild(document.createTextNode(r)) : this.el.appendChild(r));
77
- }), this;
78
- }
79
- replaceChildren(...t) {
80
- if (l) {
81
- const e = this.el;
82
- e.childrenList = [];
83
- } else this.el.replaceChildren();
84
- return this.children(...t);
85
- }
86
- text(t) {
87
- return this.el.textContent = t, this;
88
- }
89
- ref(t) {
90
- return t.current = this.el, this;
91
- }
92
- shadow(t = { mode: "closed" }) {
93
- const e = this.el.attachShadow(t);
94
- return new u(this.el, e, t);
95
- }
96
- build() {
97
- return this.el;
98
- }
99
- serialize() {
100
- if (l) return this.el.serialize();
101
- const t = document.createElement("div");
102
- return t.appendChild(this.el.cloneNode(!0)), t.innerHTML;
103
- }
104
- }, u = class {
105
- root;
106
- hostEl;
107
- options;
108
- constructor(i, t, e) {
109
- this.hostEl = i, this.root = t, this.options = e;
110
- }
111
- children(...i) {
112
- const t = (e) => e.reduce((r, a) => Array.isArray(a) ? r.concat(t(a)) : r.concat(a), []);
113
- return t(i).forEach((e) => {
114
- e != null && (e instanceof o ? this.root.appendChild(e.build()) : typeof e == "string" ? l ? this.root.appendChild(e) : this.root.appendChild(document.createTextNode(e)) : this.root.appendChild(e));
115
- }), this;
116
- }
117
- adoptSheet(...i) {
118
- return this.root.adoptedStyleSheets = [...this.root.adoptedStyleSheets, ...i], this;
119
- }
120
- css(i) {
121
- if (l)
122
- return this.root.adoptedStyleSheets.push(i), this;
123
- if (typeof CSSStyleSheet < "u") try {
124
- const e = new CSSStyleSheet();
125
- return e.replaceSync(i), this.root.adoptedStyleSheets = [...this.root.adoptedStyleSheets, e], this;
126
- } catch {
127
- }
128
- const t = document.createElement("style");
129
- return t.textContent = i, this.root.appendChild(t), this;
130
- }
131
- done() {
132
- return {
133
- host: this.hostEl,
134
- shadow: this.root
135
- };
136
- }
137
- serialize() {
138
- return l ? this.root.serialize() : this.root.innerHTML;
139
- }
140
- }, s = (i) => new o(i), f = () => s("div"), S = () => s("span"), y = () => s("slot"), b = () => s("button"), v = () => s("input"), C = () => s("style"), E = () => s("label"), w = () => s("ul"), A = () => s("li"), g = () => s("section"), L = () => s("article"), B = () => s("nav"), m = () => s("header"), x = () => s("footer"), H = () => s("main"), N = (i = "open", t = !1) => {
141
- const e = s("template");
142
- return e.attr("shadowrootmode", i), t && e.attr("shadowrootdelegatesfocus", ""), e;
143
- };
144
- export {
145
- s as _,
146
- x as a,
147
- p as b,
148
- E as c,
149
- B as d,
150
- g as f,
151
- w as g,
152
- C as h,
153
- f as i,
154
- A as l,
155
- S as m,
156
- b as n,
157
- m as o,
158
- y as p,
159
- N as r,
160
- v as s,
161
- L as t,
162
- H as u,
163
- o as v,
164
- u as y
165
- };
@@ -1,88 +0,0 @@
1
- import { a as p, i as o, n as l, r as n, t as d } from "./utils-DBfrRFoE.js";
2
- import { t as m } from "./events-C59wGdni.js";
3
- import { p as f } from "./factory-BdsO0dEW.js";
4
- import { a as _, n as b } from "./ssr-DSGwPtEd.js";
5
- import { getSSGPath as g } from "./utils/router.js";
6
- var v = ".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:block}:host([hidden]){display:none!important}", w = class extends b {
7
- static get observedAttributes() {
8
- return [
9
- "path",
10
- "exact",
11
- "sheet"
12
- ];
13
- }
14
- _events = new m();
15
- _shadowDom;
16
- _params = {};
17
- constructor() {
18
- super(), this._shadowDom = l(this, v), d(this._shadowDom, "slot", () => f().build());
19
- }
20
- get path() {
21
- return n(this, "path", "/");
22
- }
23
- set path(t) {
24
- o(this, "path", t);
25
- }
26
- get exact() {
27
- return this.hasAttribute("exact");
28
- }
29
- get params() {
30
- return { ...this._params };
31
- }
32
- get sheet() {
33
- return n(this, "sheet");
34
- }
35
- set sheet(t) {
36
- o(this, "sheet", t);
37
- }
38
- handlerExternalCss = () => {
39
- p(this, this._shadowDom, "sheet", null, this.sheet);
40
- };
41
- _matchPath(t) {
42
- const a = this.path, e = {}, r = [], h = a.split("/").map((s) => s.startsWith(":") ? (r.push(s.slice(1)), "([^/]+)") : s === "*" ? "(.*)" : s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/"), c = this.exact ? new RegExp(`^${h}$`) : new RegExp(`^${h}(?:/.*)?$`), i = t.match(c);
43
- return i ? (r.forEach((s, u) => {
44
- e[s] = decodeURIComponent(i[u + 1] ?? "");
45
- }), {
46
- matched: !0,
47
- params: e
48
- }) : {
49
- matched: !1,
50
- params: e
51
- };
52
- }
53
- _update(t) {
54
- const { matched: a, params: e } = this._matchPath(t);
55
- this._params = e, this.hidden = !a, a && this.dispatchEvent(new CustomEvent("routematch", {
56
- detail: {
57
- path: t,
58
- params: e
59
- },
60
- bubbles: !0
61
- }));
62
- }
63
- _preSerialize() {
64
- const t = g();
65
- t !== null && this._update(t);
66
- }
67
- connectedCallback() {
68
- this.handlerExternalCss();
69
- const t = this.closest("r-router");
70
- t && t._currentPath && this._update(t._currentPath);
71
- }
72
- disconnectedCallback() {
73
- this._events.abort();
74
- }
75
- attributeChangedCallback(t, a, e) {
76
- if (a !== e) {
77
- if (t === "path" || t === "exact") {
78
- const r = this.closest("r-router");
79
- r && this._update(r._currentPath);
80
- }
81
- t === "sheet" && this.handlerExternalCss();
82
- }
83
- }
84
- };
85
- _("r-route", w);
86
- export {
87
- w as t
88
- };
@@ -1,57 +0,0 @@
1
- var c = null, u = null, f = null;
2
- function b(r, e) {
3
- const s = e?.equals ?? Object.is;
4
- let t = r;
5
- const n = /* @__PURE__ */ new Set();
6
- return [() => (c && u && (n.add(c), u.add(n)), t), (o) => {
7
- const d = typeof o == "function" ? o(t) : o;
8
- if (!s(t, d))
9
- if (t = d, f) for (const a of n) f.add(a);
10
- else for (const a of [...n]) a();
11
- }];
12
- }
13
- function p(r) {
14
- let e, s = !1;
15
- const t = /* @__PURE__ */ new Set(), n = () => {
16
- if (s) return;
17
- e?.();
18
- for (const o of t) o.delete(n);
19
- t.clear();
20
- const l = c, i = u;
21
- c = n, u = t;
22
- try {
23
- e = r() ?? void 0;
24
- } finally {
25
- c = l, u = i;
26
- }
27
- };
28
- return n(), () => {
29
- s = !0, e?.();
30
- for (const l of t) l.delete(n);
31
- t.clear();
32
- };
33
- }
34
- function v(r) {
35
- const [e, s] = b(void 0);
36
- return p(() => s(r())), e;
37
- }
38
- function S(r) {
39
- if (f) {
40
- r();
41
- return;
42
- }
43
- const e = /* @__PURE__ */ new Set();
44
- f = e;
45
- try {
46
- r();
47
- } finally {
48
- f = null;
49
- for (const s of e) s();
50
- }
51
- }
52
- export {
53
- b as i,
54
- v as n,
55
- p as r,
56
- S as t
57
- };
@@ -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
- };