@ryanhelsing/ry-ui 1.0.0 → 1.0.2
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.
- package/README.md +2 -0
- package/USING_CDN.md +591 -0
- package/dist/components/ry-dropdown.d.ts.map +1 -1
- package/dist/components/ry-example.d.ts +7 -0
- package/dist/components/ry-example.d.ts.map +1 -1
- package/dist/components/ry-gradient-picker.d.ts +39 -0
- package/dist/components/ry-gradient-picker.d.ts.map +1 -0
- package/dist/components/ry-number-select.d.ts +30 -0
- package/dist/components/ry-number-select.d.ts.map +1 -0
- package/dist/components/ry-tree.d.ts +41 -0
- package/dist/components/ry-tree.d.ts.map +1 -0
- package/dist/core/ry-icons.d.ts.map +1 -1
- package/dist/core/ry-transform.d.ts.map +1 -1
- package/dist/css/ry-structure.css +484 -1
- package/dist/css/ry-theme.css +365 -0
- package/dist/css/ry-ui.css +151 -6
- package/dist/ry-ui.d.ts +5 -0
- package/dist/ry-ui.d.ts.map +1 -1
- package/dist/ry-ui.js +1391 -441
- package/dist/ry-ui.js.map +1 -1
- package/dist/themes/dark.css +92 -0
- package/dist/themes/light.css +38 -0
- package/dist/themes/ocean.css +48 -0
- package/package.json +6 -4
package/dist/ry-ui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class p extends HTMLElement {
|
|
2
2
|
// Store for cleanup functions
|
|
3
3
|
#t = [];
|
|
4
4
|
// Store for MutationObserver
|
|
@@ -89,7 +89,7 @@ class d extends HTMLElement {
|
|
|
89
89
|
this.on(t, "keydown", a), i?.focus();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
const
|
|
92
|
+
const D = [
|
|
93
93
|
// Layout
|
|
94
94
|
"page",
|
|
95
95
|
"header",
|
|
@@ -132,26 +132,30 @@ const C = [
|
|
|
132
132
|
"toggle-button",
|
|
133
133
|
"slider",
|
|
134
134
|
"knob",
|
|
135
|
+
"number-select",
|
|
135
136
|
"color-picker",
|
|
136
|
-
"color-input"
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
"color-input",
|
|
138
|
+
"gradient-picker",
|
|
139
|
+
"tree",
|
|
140
|
+
"tree-item"
|
|
141
|
+
], B = new RegExp(
|
|
142
|
+
`<(/?)(${D.join("|")})(\\s|>|/)`,
|
|
139
143
|
"g"
|
|
140
144
|
);
|
|
141
|
-
function
|
|
142
|
-
return o.replace(
|
|
145
|
+
function M(o) {
|
|
146
|
+
return o.replace(B, "<$1ry-$2$3");
|
|
143
147
|
}
|
|
144
|
-
function
|
|
148
|
+
function C() {
|
|
145
149
|
document.querySelectorAll("ry").forEach((o) => {
|
|
146
|
-
const t =
|
|
150
|
+
const t = M(o.innerHTML), e = document.createElement("template");
|
|
147
151
|
e.innerHTML = t, o.replaceWith(e.content);
|
|
148
152
|
}), document.querySelectorAll("template[ry]").forEach((o) => {
|
|
149
|
-
const t =
|
|
153
|
+
const t = M(o.innerHTML), e = document.createElement("template");
|
|
150
154
|
e.innerHTML = t, o.replaceWith(e.content);
|
|
151
155
|
});
|
|
152
156
|
}
|
|
153
|
-
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded",
|
|
154
|
-
class
|
|
157
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", C) : C();
|
|
158
|
+
class F extends p {
|
|
155
159
|
setup() {
|
|
156
160
|
this.#t(), this.$$('[data-ry-target="trigger"]').forEach((t) => {
|
|
157
161
|
this.on(t, "click", this.#i);
|
|
@@ -227,10 +231,10 @@ class T extends d {
|
|
|
227
231
|
this.$$('[data-ry-target="item"]').forEach((t) => this.close(t));
|
|
228
232
|
}
|
|
229
233
|
}
|
|
230
|
-
customElements.define("ry-accordion",
|
|
234
|
+
customElements.define("ry-accordion", F);
|
|
231
235
|
customElements.get("ry-accordion-item") || customElements.define("ry-accordion-item", class extends HTMLElement {
|
|
232
236
|
});
|
|
233
|
-
class
|
|
237
|
+
class P extends p {
|
|
234
238
|
#t = null;
|
|
235
239
|
#e = 0;
|
|
236
240
|
setup() {
|
|
@@ -279,8 +283,8 @@ class H extends d {
|
|
|
279
283
|
this.state === "open" ? this.close() : this.open();
|
|
280
284
|
}
|
|
281
285
|
}
|
|
282
|
-
customElements.define("ry-modal",
|
|
283
|
-
class
|
|
286
|
+
customElements.define("ry-modal", P);
|
|
287
|
+
class R extends p {
|
|
284
288
|
setup() {
|
|
285
289
|
this.#t(), this.$$('[data-ry-target="trigger"]').forEach((t) => {
|
|
286
290
|
this.on(t, "click", this.#i);
|
|
@@ -291,8 +295,8 @@ class L extends d {
|
|
|
291
295
|
if (t.length === 0) return;
|
|
292
296
|
const e = t.findIndex((r) => r.hasAttribute("active")), s = e === -1 ? 0 : e, i = document.createElement("div");
|
|
293
297
|
i.setAttribute("data-ry-target", "list"), i.className = "ry-tabs__list", i.setAttribute("role", "tablist"), t.forEach((r, a) => {
|
|
294
|
-
const n = r.getAttribute("title") ?? `Tab ${a + 1}`,
|
|
295
|
-
|
|
298
|
+
const n = r.getAttribute("title") ?? `Tab ${a + 1}`, h = a === s, l = document.createElement("button");
|
|
299
|
+
l.setAttribute("data-ry-target", "trigger"), l.className = "ry-tabs__trigger", l.setAttribute("role", "tab"), l.setAttribute("aria-selected", String(h)), l.textContent = n, i.appendChild(l), r.setAttribute("data-ry-target", "panel"), r.className = "ry-tabs__panel", r.setAttribute("role", "tabpanel"), r.dataset.ryState = h ? "active" : "", r.removeAttribute("title"), r.removeAttribute("active");
|
|
296
300
|
}), this.insertBefore(i, this.firstChild);
|
|
297
301
|
}
|
|
298
302
|
#e() {
|
|
@@ -300,8 +304,8 @@ class L extends d {
|
|
|
300
304
|
t.forEach((i, r) => {
|
|
301
305
|
const a = e[r];
|
|
302
306
|
if (!a) return;
|
|
303
|
-
const n = i.id || `ry-tab-${this.id || ""}-${r}`,
|
|
304
|
-
i.id = n, a.id =
|
|
307
|
+
const n = i.id || `ry-tab-${this.id || ""}-${r}`, h = a.id || `ry-tabpanel-${this.id || ""}-${r}`;
|
|
308
|
+
i.id = n, a.id = h, i.setAttribute("aria-controls", h), a.setAttribute("aria-labelledby", n), i.setAttribute("tabindex", i.getAttribute("aria-selected") === "true" ? "0" : "-1");
|
|
305
309
|
}), t.findIndex((i) => i.getAttribute("aria-selected") === "true") === -1 && t.length > 0 && this.select(0);
|
|
306
310
|
}
|
|
307
311
|
#i = (t) => {
|
|
@@ -342,10 +346,10 @@ class L extends d {
|
|
|
342
346
|
return this.$$('[data-ry-target="trigger"]').findIndex((e) => e.getAttribute("aria-selected") === "true");
|
|
343
347
|
}
|
|
344
348
|
}
|
|
345
|
-
customElements.define("ry-tabs",
|
|
349
|
+
customElements.define("ry-tabs", R);
|
|
346
350
|
customElements.get("ry-tab") || customElements.define("ry-tab", class extends HTMLElement {
|
|
347
351
|
});
|
|
348
|
-
class
|
|
352
|
+
class j extends p {
|
|
349
353
|
setup() {
|
|
350
354
|
this.#t();
|
|
351
355
|
const t = this.$('[data-ry-target="trigger"]');
|
|
@@ -375,24 +379,30 @@ class I extends d {
|
|
|
375
379
|
};
|
|
376
380
|
open() {
|
|
377
381
|
if (this.state === "open") return;
|
|
378
|
-
this.$('[data-ry-target="trigger"]')?.setAttribute("aria-expanded", "true"), this.state = "open", this.nextFrame().then(() => {
|
|
382
|
+
this.#s(), this.$('[data-ry-target="trigger"]')?.setAttribute("aria-expanded", "true"), this.state = "open", this.nextFrame().then(() => {
|
|
379
383
|
this.$('[data-ry-target="item"], ry-menu-item')?.focus();
|
|
380
384
|
}), this.emit("open");
|
|
381
385
|
}
|
|
382
386
|
close() {
|
|
383
387
|
if (this.state === "closed") return;
|
|
384
|
-
this.$('[data-ry-target="trigger"]')?.setAttribute("aria-expanded", "false"), this.state = "closed", this.emit("close");
|
|
388
|
+
this.$('[data-ry-target="trigger"]')?.setAttribute("aria-expanded", "false"), this.state = "closed", this.removeAttribute("data-ry-position"), this.emit("close");
|
|
389
|
+
}
|
|
390
|
+
#s() {
|
|
391
|
+
const t = this.$('[data-ry-target="menu"], ry-menu');
|
|
392
|
+
if (!t) return;
|
|
393
|
+
const e = this.getBoundingClientRect(), s = t.scrollHeight || 240, i = window.innerHeight - e.bottom, r = e.top;
|
|
394
|
+
i < s && r > i ? this.setAttribute("data-ry-position", "top") : this.setAttribute("data-ry-position", "bottom");
|
|
385
395
|
}
|
|
386
396
|
toggle() {
|
|
387
397
|
this.state === "open" ? this.close() : this.open();
|
|
388
398
|
}
|
|
389
399
|
}
|
|
390
|
-
customElements.define("ry-dropdown",
|
|
400
|
+
customElements.define("ry-dropdown", j);
|
|
391
401
|
customElements.get("ry-menu") || customElements.define("ry-menu", class extends HTMLElement {
|
|
392
402
|
});
|
|
393
403
|
customElements.get("ry-menu-item") || customElements.define("ry-menu-item", class extends HTMLElement {
|
|
394
404
|
});
|
|
395
|
-
class
|
|
405
|
+
class O extends p {
|
|
396
406
|
setup() {
|
|
397
407
|
this.hasAttribute("tabindex") || this.setAttribute("tabindex", "0"), this.setAttribute("role", "button"), this.on(this, "click", this.#t), this.on(this, "keydown", this.#e);
|
|
398
408
|
}
|
|
@@ -407,8 +417,8 @@ class D extends d {
|
|
|
407
417
|
(t.key === "Enter" || t.key === " ") && (t.preventDefault(), this.click());
|
|
408
418
|
};
|
|
409
419
|
}
|
|
410
|
-
customElements.define("ry-button",
|
|
411
|
-
class
|
|
420
|
+
customElements.define("ry-button", O);
|
|
421
|
+
class N extends p {
|
|
412
422
|
#t = ["light", "dark"];
|
|
413
423
|
#e = 0;
|
|
414
424
|
setup() {
|
|
@@ -448,8 +458,8 @@ class F extends d {
|
|
|
448
458
|
}
|
|
449
459
|
}
|
|
450
460
|
}
|
|
451
|
-
customElements.define("ry-theme-toggle",
|
|
452
|
-
class
|
|
461
|
+
customElements.define("ry-theme-toggle", N);
|
|
462
|
+
class K extends p {
|
|
453
463
|
setup() {
|
|
454
464
|
this.#t();
|
|
455
465
|
const t = this.$("[close]");
|
|
@@ -469,8 +479,8 @@ class B extends d {
|
|
|
469
479
|
}, 200), this.emit("close");
|
|
470
480
|
}
|
|
471
481
|
}
|
|
472
|
-
customElements.define("ry-alert",
|
|
473
|
-
class
|
|
482
|
+
customElements.define("ry-alert", K);
|
|
483
|
+
class q extends p {
|
|
474
484
|
setup() {
|
|
475
485
|
this.#t();
|
|
476
486
|
}
|
|
@@ -486,9 +496,9 @@ class j extends d {
|
|
|
486
496
|
i.setAttribute("data-ry-target", "label"), i.className = "ry-label", i.setAttribute("for", s), i.textContent = t, this.insertBefore(i, e);
|
|
487
497
|
}
|
|
488
498
|
}
|
|
489
|
-
customElements.define("ry-field",
|
|
490
|
-
let
|
|
491
|
-
class
|
|
499
|
+
customElements.define("ry-field", q);
|
|
500
|
+
let U = 0;
|
|
501
|
+
class V extends p {
|
|
492
502
|
#t = null;
|
|
493
503
|
static observedAttributes = ["checked", "disabled"];
|
|
494
504
|
setup() {
|
|
@@ -496,7 +506,7 @@ class P extends d {
|
|
|
496
506
|
}
|
|
497
507
|
#e() {
|
|
498
508
|
if (this.$('[data-ry-target="track"]')) return;
|
|
499
|
-
const t = `ry-switch-${++
|
|
509
|
+
const t = `ry-switch-${++U}`, e = this.getAttribute("name") ?? "", s = this.hasAttribute("checked"), i = this.hasAttribute("disabled"), r = this.textContent?.trim() ?? "";
|
|
500
510
|
this.innerHTML = `
|
|
501
511
|
<label data-ry-target="wrapper" class="ry-switch__wrapper" for="${t}">
|
|
502
512
|
<input
|
|
@@ -541,16 +551,16 @@ class P extends d {
|
|
|
541
551
|
this.#t && (this.#t.value = t);
|
|
542
552
|
}
|
|
543
553
|
}
|
|
544
|
-
customElements.define("ry-switch",
|
|
545
|
-
let
|
|
546
|
-
class
|
|
554
|
+
customElements.define("ry-switch", V);
|
|
555
|
+
let Y = 0;
|
|
556
|
+
class z extends p {
|
|
547
557
|
#t = null;
|
|
548
558
|
#e = null;
|
|
549
559
|
#i = null;
|
|
550
560
|
setup() {
|
|
551
|
-
this.#i = `ry-tooltip-${++
|
|
561
|
+
this.#i = `ry-tooltip-${++Y}`, this.#s();
|
|
552
562
|
const t = this.firstElementChild;
|
|
553
|
-
t && (t.setAttribute("aria-describedby", this.#i), this.on(t, "mouseenter", this.#r), this.on(t, "mouseleave", this.#
|
|
563
|
+
t && (t.setAttribute("aria-describedby", this.#i), this.on(t, "mouseenter", this.#r), this.on(t, "mouseleave", this.#h), this.on(t, "focusin", this.#r), this.on(t, "focusout", this.#h)), this.on(document, "keydown", this.#l);
|
|
554
564
|
}
|
|
555
565
|
#s() {
|
|
556
566
|
this.#e = document.createElement("div"), this.#e.id = this.#i, this.#e.setAttribute("data-ry-target", "content"), this.#e.className = "ry-tooltip__content", this.#e.setAttribute("role", "tooltip"), this.#e.textContent = this.getAttribute("content") ?? "", this.appendChild(this.#e);
|
|
@@ -564,18 +574,18 @@ class K extends d {
|
|
|
564
574
|
const t = this.getAttribute("position") ?? "top";
|
|
565
575
|
this.setAttribute("data-ry-position", t), this.state = "open";
|
|
566
576
|
};
|
|
567
|
-
#
|
|
577
|
+
#h = () => {
|
|
568
578
|
this.#t && (clearTimeout(this.#t), this.#t = null), this.state = "closed";
|
|
569
579
|
};
|
|
570
|
-
#
|
|
571
|
-
t.key === "Escape" && this.state === "open" && this.#
|
|
580
|
+
#l = (t) => {
|
|
581
|
+
t.key === "Escape" && this.state === "open" && this.#h();
|
|
572
582
|
};
|
|
573
583
|
teardown() {
|
|
574
584
|
this.#t && clearTimeout(this.#t);
|
|
575
585
|
}
|
|
576
586
|
}
|
|
577
|
-
customElements.define("ry-tooltip",
|
|
578
|
-
class W extends
|
|
587
|
+
customElements.define("ry-tooltip", z);
|
|
588
|
+
class W extends p {
|
|
579
589
|
#t = null;
|
|
580
590
|
#e = 0;
|
|
581
591
|
setup() {
|
|
@@ -621,37 +631,37 @@ class W extends d {
|
|
|
621
631
|
}
|
|
622
632
|
}
|
|
623
633
|
customElements.define("ry-drawer", W);
|
|
624
|
-
const
|
|
625
|
-
class
|
|
634
|
+
const X = 4e3;
|
|
635
|
+
class f extends p {
|
|
626
636
|
#t = null;
|
|
627
637
|
static observedAttributes = ["variant", "duration"];
|
|
628
638
|
// Static container for programmatic toasts
|
|
629
639
|
static #e = null;
|
|
630
640
|
static #i() {
|
|
631
|
-
return
|
|
641
|
+
return f.#e || (f.#e = document.createElement("div"), f.#e.setAttribute("data-ry-target", "toast-container"), f.#e.className = "ry-toast-container", document.body.appendChild(f.#e)), f.#e;
|
|
632
642
|
}
|
|
633
643
|
// Static API
|
|
634
644
|
static show(t) {
|
|
635
645
|
const e = document.createElement("ry-toast");
|
|
636
|
-
return e.textContent = t.message, t.variant && e.setAttribute("variant", t.variant), t.duration !== void 0 && e.setAttribute("duration", String(t.duration)),
|
|
646
|
+
return e.textContent = t.message, t.variant && e.setAttribute("variant", t.variant), t.duration !== void 0 && e.setAttribute("duration", String(t.duration)), f.#i().appendChild(e), e;
|
|
637
647
|
}
|
|
638
648
|
static success(t, e) {
|
|
639
|
-
return
|
|
649
|
+
return f.show({ message: t, variant: "success", duration: e });
|
|
640
650
|
}
|
|
641
651
|
static error(t, e) {
|
|
642
|
-
return
|
|
652
|
+
return f.show({ message: t, variant: "error", duration: e });
|
|
643
653
|
}
|
|
644
654
|
static info(t, e) {
|
|
645
|
-
return
|
|
655
|
+
return f.show({ message: t, variant: "info", duration: e });
|
|
646
656
|
}
|
|
647
657
|
static warning(t, e) {
|
|
648
|
-
return
|
|
658
|
+
return f.show({ message: t, variant: "warning", duration: e });
|
|
649
659
|
}
|
|
650
660
|
setup() {
|
|
651
661
|
this.#s();
|
|
652
662
|
const t = this.$("[close]");
|
|
653
663
|
t && this.on(t, "click", () => this.dismiss());
|
|
654
|
-
const e = parseInt(this.getAttribute("duration") ?? String(
|
|
664
|
+
const e = parseInt(this.getAttribute("duration") ?? String(X), 10);
|
|
655
665
|
e > 0 && (this.#t = setTimeout(() => this.dismiss(), e)), requestAnimationFrame(() => {
|
|
656
666
|
this.state = "visible";
|
|
657
667
|
});
|
|
@@ -683,9 +693,9 @@ class p extends d {
|
|
|
683
693
|
this.#t && clearTimeout(this.#t);
|
|
684
694
|
}
|
|
685
695
|
}
|
|
686
|
-
customElements.define("ry-toast",
|
|
687
|
-
let
|
|
688
|
-
class
|
|
696
|
+
customElements.define("ry-toast", f);
|
|
697
|
+
let G = 0;
|
|
698
|
+
class J extends p {
|
|
689
699
|
#t = null;
|
|
690
700
|
#e = -1;
|
|
691
701
|
#i = "";
|
|
@@ -694,7 +704,7 @@ class N extends d {
|
|
|
694
704
|
_options = [];
|
|
695
705
|
static observedAttributes = ["value", "disabled"];
|
|
696
706
|
setup() {
|
|
697
|
-
this.#t = `ry-select-${++
|
|
707
|
+
this.#t = `ry-select-${++G}`, this.#r(), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "0"), this.on(this, "click", this.#n), this.on(this, "keydown", this.#h), this.on(document, "click", this.#l), this.hasAttribute("data-ry-state") || (this.state = "closed");
|
|
698
708
|
const t = this.getAttribute("value");
|
|
699
709
|
t && (this.value = t);
|
|
700
710
|
}
|
|
@@ -705,10 +715,10 @@ class N extends d {
|
|
|
705
715
|
disabled: n.hasAttribute("disabled")
|
|
706
716
|
})), e = this.getAttribute("placeholder") ?? "Select...", s = this.getAttribute("name") ?? "", i = this.hasAttribute("disabled"), r = t.map(
|
|
707
717
|
(n) => `<option value="${n.value}"${n.disabled ? " disabled" : ""}>${n.label}</option>`
|
|
708
|
-
).join(""), a = t.map((n,
|
|
718
|
+
).join(""), a = t.map((n, h) => `
|
|
709
719
|
<div data-ry-target="option" class="ry-select__option"
|
|
710
720
|
role="option"
|
|
711
|
-
id="${this.#t}-option-${
|
|
721
|
+
id="${this.#t}-option-${h}"
|
|
712
722
|
data-value="${n.value}"
|
|
713
723
|
${n.disabled ? "data-disabled" : ""}
|
|
714
724
|
aria-disabled="${n.disabled}">
|
|
@@ -733,12 +743,12 @@ class N extends d {
|
|
|
733
743
|
if (this.hasAttribute("disabled")) return;
|
|
734
744
|
const e = t.target, s = e.closest('[data-ry-target="option"]');
|
|
735
745
|
if (s instanceof HTMLElement && !s.hasAttribute("data-disabled")) {
|
|
736
|
-
this.#
|
|
746
|
+
this.#f(s), this.close();
|
|
737
747
|
return;
|
|
738
748
|
}
|
|
739
749
|
e.closest('[data-ry-target="trigger"]') && this.toggle();
|
|
740
750
|
};
|
|
741
|
-
#
|
|
751
|
+
#h = (t) => {
|
|
742
752
|
if (this.hasAttribute("disabled")) return;
|
|
743
753
|
const e = this.state === "open";
|
|
744
754
|
switch (t.key) {
|
|
@@ -746,7 +756,7 @@ class N extends d {
|
|
|
746
756
|
case " ":
|
|
747
757
|
if (t.preventDefault(), e && this.#e >= 0) {
|
|
748
758
|
const i = this.$$('[data-ry-target="option"]:not([data-disabled])')[this.#e];
|
|
749
|
-
i && (this.#
|
|
759
|
+
i && (this.#f(i), this.close());
|
|
750
760
|
} else
|
|
751
761
|
this.toggle();
|
|
752
762
|
break;
|
|
@@ -754,43 +764,43 @@ class N extends d {
|
|
|
754
764
|
e && (t.preventDefault(), this.close());
|
|
755
765
|
break;
|
|
756
766
|
case "ArrowDown":
|
|
757
|
-
t.preventDefault(), e ? this.#
|
|
767
|
+
t.preventDefault(), e ? this.#a() : this.open();
|
|
758
768
|
break;
|
|
759
769
|
case "ArrowUp":
|
|
760
|
-
t.preventDefault(), e && this.#
|
|
770
|
+
t.preventDefault(), e && this.#u();
|
|
761
771
|
break;
|
|
762
772
|
case "Home":
|
|
763
|
-
e && (t.preventDefault(), this.#
|
|
773
|
+
e && (t.preventDefault(), this.#g());
|
|
764
774
|
break;
|
|
765
775
|
case "End":
|
|
766
|
-
e && (t.preventDefault(), this.#
|
|
776
|
+
e && (t.preventDefault(), this.#m());
|
|
767
777
|
break;
|
|
768
778
|
default:
|
|
769
|
-
t.key.length === 1 && !t.ctrlKey && !t.metaKey && this.#
|
|
779
|
+
t.key.length === 1 && !t.ctrlKey && !t.metaKey && this.#d(t.key);
|
|
770
780
|
break;
|
|
771
781
|
}
|
|
772
782
|
};
|
|
773
|
-
#
|
|
783
|
+
#l = (t) => {
|
|
774
784
|
const e = t.target;
|
|
775
785
|
!this.contains(e) && this.state === "open" && this.close();
|
|
776
786
|
};
|
|
777
|
-
#
|
|
787
|
+
#d(t) {
|
|
778
788
|
this.#s && clearTimeout(this.#s), this.#i += t.toLowerCase();
|
|
779
789
|
const e = this.$$('[data-ry-target="option"]:not([data-disabled])'), s = e.findIndex(
|
|
780
790
|
(i) => i.textContent?.trim().toLowerCase().startsWith(this.#i)
|
|
781
791
|
);
|
|
782
792
|
if (s >= 0)
|
|
783
793
|
if (this.state === "open")
|
|
784
|
-
this.#
|
|
794
|
+
this.#o(s);
|
|
785
795
|
else {
|
|
786
796
|
const i = e[s];
|
|
787
|
-
i && this.#
|
|
797
|
+
i && this.#f(i);
|
|
788
798
|
}
|
|
789
799
|
this.#s = setTimeout(() => {
|
|
790
800
|
this.#i = "";
|
|
791
801
|
}, 500);
|
|
792
802
|
}
|
|
793
|
-
#
|
|
803
|
+
#o(t) {
|
|
794
804
|
const e = this.$$('[data-ry-target="option"]:not([data-disabled])');
|
|
795
805
|
if (t < 0 || t >= e.length) return;
|
|
796
806
|
this.$$('[data-ry-target="option"][data-highlighted]').forEach((r) => {
|
|
@@ -802,22 +812,22 @@ class N extends d {
|
|
|
802
812
|
const i = this.$('[data-ry-target="trigger"]');
|
|
803
813
|
i && i.setAttribute("aria-activedescendant", s.id);
|
|
804
814
|
}
|
|
805
|
-
#
|
|
815
|
+
#a() {
|
|
806
816
|
const t = this.$$('[data-ry-target="option"]:not([data-disabled])'), e = Math.min(this.#e + 1, t.length - 1);
|
|
807
|
-
this.#
|
|
817
|
+
this.#o(e);
|
|
808
818
|
}
|
|
809
|
-
#
|
|
819
|
+
#u() {
|
|
810
820
|
const t = Math.max(this.#e - 1, 0);
|
|
811
|
-
this.#
|
|
812
|
-
}
|
|
813
|
-
#f() {
|
|
814
|
-
this.#a(0);
|
|
821
|
+
this.#o(t);
|
|
815
822
|
}
|
|
816
823
|
#g() {
|
|
824
|
+
this.#o(0);
|
|
825
|
+
}
|
|
826
|
+
#m() {
|
|
817
827
|
const t = this.$$('[data-ry-target="option"]:not([data-disabled])');
|
|
818
|
-
this.#
|
|
828
|
+
this.#o(t.length - 1);
|
|
819
829
|
}
|
|
820
|
-
#
|
|
830
|
+
#f(t) {
|
|
821
831
|
const e = t.dataset.value ?? "", s = t.textContent?.trim() ?? "", i = this.$('[data-ry-target="value"]');
|
|
822
832
|
i && (i.textContent = s, i.setAttribute("data-selected", ""));
|
|
823
833
|
const r = this.$('[data-ry-target="native"]');
|
|
@@ -829,16 +839,16 @@ class N extends d {
|
|
|
829
839
|
if (this.state === "open") return;
|
|
830
840
|
this.state = "open";
|
|
831
841
|
const t = this.$('[data-ry-target="trigger"]');
|
|
832
|
-
t && t.setAttribute("aria-expanded", "true"), this.#
|
|
842
|
+
t && t.setAttribute("aria-expanded", "true"), this.#A();
|
|
833
843
|
const e = this.getAttribute("value");
|
|
834
844
|
if (e) {
|
|
835
845
|
const i = this.$$('[data-ry-target="option"]:not([data-disabled])').findIndex((r) => r.dataset.value === e);
|
|
836
|
-
i >= 0 && this.#
|
|
846
|
+
i >= 0 && this.#o(i);
|
|
837
847
|
} else
|
|
838
|
-
this.#
|
|
848
|
+
this.#o(0);
|
|
839
849
|
this.emit("open");
|
|
840
850
|
}
|
|
841
|
-
#
|
|
851
|
+
#A() {
|
|
842
852
|
const t = this.$('[data-ry-target="dropdown"]');
|
|
843
853
|
if (!t) return;
|
|
844
854
|
this.removeAttribute("data-ry-position");
|
|
@@ -861,17 +871,17 @@ class N extends d {
|
|
|
861
871
|
}
|
|
862
872
|
set value(t) {
|
|
863
873
|
const e = this.$(`[data-ry-target="option"][data-value="${t}"]`);
|
|
864
|
-
e && this.#
|
|
874
|
+
e && this.#f(e);
|
|
865
875
|
}
|
|
866
876
|
teardown() {
|
|
867
877
|
this.#s && clearTimeout(this.#s);
|
|
868
878
|
}
|
|
869
879
|
}
|
|
870
|
-
class
|
|
880
|
+
class Z extends HTMLElement {
|
|
871
881
|
}
|
|
872
|
-
customElements.define("ry-option",
|
|
873
|
-
customElements.define("ry-select",
|
|
874
|
-
const
|
|
882
|
+
customElements.define("ry-option", Z);
|
|
883
|
+
customElements.define("ry-select", J);
|
|
884
|
+
const A = {
|
|
875
885
|
// Close / X
|
|
876
886
|
close: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6L6 18"/><path d="M6 6l12 12"/></svg>',
|
|
877
887
|
// Chevron down
|
|
@@ -923,28 +933,44 @@ const v = {
|
|
|
923
933
|
// Download
|
|
924
934
|
download: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',
|
|
925
935
|
// Upload
|
|
926
|
-
upload: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>'
|
|
936
|
+
upload: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>',
|
|
937
|
+
// Folder (closed)
|
|
938
|
+
folder: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 2H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"/></svg>',
|
|
939
|
+
// Folder open
|
|
940
|
+
"folder-open": '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 2H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"/><path d="M2 10h20"/></svg>',
|
|
941
|
+
// File
|
|
942
|
+
file: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg>',
|
|
943
|
+
// Gradient: solid color
|
|
944
|
+
"gradient-solid": '<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" stroke="none"><rect x="4" y="4" width="16" height="16" rx="2"/></svg>',
|
|
945
|
+
// Gradient: linear
|
|
946
|
+
"gradient-linear": '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="21" x2="21" y2="3"/><line x1="3" y1="15" x2="15" y2="3"/><line x1="9" y1="21" x2="21" y2="9"/></svg>',
|
|
947
|
+
// Gradient: radial
|
|
948
|
+
"gradient-radial": '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/></svg>',
|
|
949
|
+
// Shape: circle
|
|
950
|
+
"shape-circle": '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/></svg>',
|
|
951
|
+
// Shape: ellipse
|
|
952
|
+
"shape-ellipse": '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="12" rx="10" ry="6"/></svg>'
|
|
927
953
|
};
|
|
928
|
-
function
|
|
929
|
-
return
|
|
954
|
+
function g(o) {
|
|
955
|
+
return A[o] ?? "";
|
|
930
956
|
}
|
|
931
|
-
function
|
|
932
|
-
|
|
957
|
+
function kt(o, t) {
|
|
958
|
+
A[o] = t;
|
|
933
959
|
}
|
|
934
|
-
function
|
|
935
|
-
Object.assign(
|
|
960
|
+
function At(o) {
|
|
961
|
+
Object.assign(A, o);
|
|
936
962
|
}
|
|
937
|
-
function
|
|
938
|
-
return Object.keys(
|
|
963
|
+
function $t() {
|
|
964
|
+
return Object.keys(A);
|
|
939
965
|
}
|
|
940
|
-
class
|
|
966
|
+
class Q extends p {
|
|
941
967
|
#t = "";
|
|
942
968
|
static get observedAttributes() {
|
|
943
969
|
return ["language", "title", "line-numbers"];
|
|
944
970
|
}
|
|
945
971
|
setup() {
|
|
946
972
|
const t = this.querySelector("template");
|
|
947
|
-
t ? this.#t = this.#
|
|
973
|
+
t ? this.#t = this.#a(t.innerHTML) : this.#t = this.textContent?.trim() ?? "", this.#e();
|
|
948
974
|
const e = this.$('[data-ry-target="copy"]');
|
|
949
975
|
e && this.on(e, "click", this.#i);
|
|
950
976
|
}
|
|
@@ -955,7 +981,7 @@ class z extends d {
|
|
|
955
981
|
<div data-ry-target="header" class="ry-code__header">
|
|
956
982
|
<span data-ry-target="title" class="ry-code__title">${e}</span>
|
|
957
983
|
<button data-ry-target="copy" class="ry-code__copy" type="button" aria-label="Copy code">
|
|
958
|
-
${
|
|
984
|
+
${g("copy")}
|
|
959
985
|
</button>
|
|
960
986
|
</div>
|
|
961
987
|
<div data-ry-target="content" class="ry-code__content">
|
|
@@ -967,8 +993,8 @@ class z extends d {
|
|
|
967
993
|
const t = this.$('[data-ry-target="copy"]');
|
|
968
994
|
if (t)
|
|
969
995
|
try {
|
|
970
|
-
await navigator.clipboard.writeText(this.#t), t.innerHTML =
|
|
971
|
-
t.innerHTML =
|
|
996
|
+
await navigator.clipboard.writeText(this.#t), t.innerHTML = g("check"), t.classList.add("ry-code__copy--success"), this.emit("copy", { code: this.#t }), setTimeout(() => {
|
|
997
|
+
t.innerHTML = g("copy"), t.classList.remove("ry-code__copy--success");
|
|
972
998
|
}, 2e3);
|
|
973
999
|
} catch {
|
|
974
1000
|
this.emit("copy-error");
|
|
@@ -982,11 +1008,11 @@ class z extends d {
|
|
|
982
1008
|
case "javascript":
|
|
983
1009
|
return this.#n(t);
|
|
984
1010
|
case "html":
|
|
985
|
-
return this.#
|
|
1011
|
+
return this.#h(t);
|
|
986
1012
|
case "json":
|
|
987
|
-
return this.#
|
|
1013
|
+
return this.#l(t);
|
|
988
1014
|
default:
|
|
989
|
-
return this.#
|
|
1015
|
+
return this.#o(t);
|
|
990
1016
|
}
|
|
991
1017
|
}
|
|
992
1018
|
#r(t) {
|
|
@@ -994,9 +1020,9 @@ class z extends d {
|
|
|
994
1020
|
let s = t;
|
|
995
1021
|
for (; s.length > 0; ) {
|
|
996
1022
|
if (s.startsWith("/*")) {
|
|
997
|
-
const
|
|
998
|
-
if (
|
|
999
|
-
e.push({ type: "comment", value: s.slice(0,
|
|
1023
|
+
const m = s.indexOf("*/");
|
|
1024
|
+
if (m !== -1) {
|
|
1025
|
+
e.push({ type: "comment", value: s.slice(0, m + 2) }), s = s.slice(m + 2);
|
|
1000
1026
|
continue;
|
|
1001
1027
|
}
|
|
1002
1028
|
}
|
|
@@ -1020,14 +1046,14 @@ class z extends d {
|
|
|
1020
1046
|
e.push({ type: "color", value: n[1], color: n[1] }), s = s.slice(n[1].length);
|
|
1021
1047
|
continue;
|
|
1022
1048
|
}
|
|
1023
|
-
const
|
|
1024
|
-
if (
|
|
1025
|
-
e.push({ type: "number", value:
|
|
1049
|
+
const h = s.match(/^(-?[\d.]+(?:px|em|rem|%|vh|vw|deg|s|ms)?)/);
|
|
1050
|
+
if (h?.[1]) {
|
|
1051
|
+
e.push({ type: "number", value: h[1] }), s = s.slice(h[1].length);
|
|
1026
1052
|
continue;
|
|
1027
1053
|
}
|
|
1028
|
-
const
|
|
1029
|
-
if (
|
|
1030
|
-
e.push({ type: "string", value:
|
|
1054
|
+
const l = s.match(/^(['"])((?:[^\\]|\\.)*?)\1/);
|
|
1055
|
+
if (l) {
|
|
1056
|
+
e.push({ type: "string", value: l[0] }), s = s.slice(l[0].length);
|
|
1031
1057
|
continue;
|
|
1032
1058
|
}
|
|
1033
1059
|
const c = s[0];
|
|
@@ -1035,21 +1061,21 @@ class z extends d {
|
|
|
1035
1061
|
e.push({ type: "punctuation", value: c }), s = s.slice(1);
|
|
1036
1062
|
continue;
|
|
1037
1063
|
}
|
|
1038
|
-
const
|
|
1039
|
-
if (
|
|
1040
|
-
e.push({ type: "text", value:
|
|
1064
|
+
const d = s.match(/^(\s+)/);
|
|
1065
|
+
if (d?.[1]) {
|
|
1066
|
+
e.push({ type: "text", value: d[1] }), s = s.slice(d[1].length);
|
|
1041
1067
|
continue;
|
|
1042
1068
|
}
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1045
|
-
const
|
|
1046
|
-
["inherit", "initial", "unset", "none", "auto", "transparent", "solid", "dashed", "dotted", "flex", "grid", "block", "inline", "inline-block", "absolute", "relative", "fixed", "sticky"].includes(
|
|
1069
|
+
const u = s.match(/^([\w-]+)/);
|
|
1070
|
+
if (u?.[1]) {
|
|
1071
|
+
const m = u[1];
|
|
1072
|
+
["inherit", "initial", "unset", "none", "auto", "transparent", "solid", "dashed", "dotted", "flex", "grid", "block", "inline", "inline-block", "absolute", "relative", "fixed", "sticky"].includes(m) ? e.push({ type: "keyword", value: m }) : e.push({ type: "value", value: m }), s = s.slice(m.length);
|
|
1047
1073
|
continue;
|
|
1048
1074
|
}
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1075
|
+
const b = s[0];
|
|
1076
|
+
b && e.push({ type: "text", value: b }), s = s.slice(1);
|
|
1051
1077
|
}
|
|
1052
|
-
return e.map((i) => this.#
|
|
1078
|
+
return e.map((i) => this.#d(i)).join("");
|
|
1053
1079
|
}
|
|
1054
1080
|
#n(t) {
|
|
1055
1081
|
const e = [];
|
|
@@ -1057,10 +1083,10 @@ class z extends d {
|
|
|
1057
1083
|
const i = ["const", "let", "var", "function", "return", "if", "else", "for", "while", "do", "switch", "case", "break", "continue", "try", "catch", "finally", "throw", "new", "class", "extends", "import", "export", "default", "from", "async", "await", "typeof", "instanceof", "in", "of", "true", "false", "null", "undefined", "this", "super", "static", "get", "set"];
|
|
1058
1084
|
for (; s.length > 0; ) {
|
|
1059
1085
|
if (s.startsWith("//")) {
|
|
1060
|
-
const
|
|
1086
|
+
const d = s.indexOf(`
|
|
1061
1087
|
`);
|
|
1062
|
-
if (
|
|
1063
|
-
e.push({ type: "comment", value: s.slice(0,
|
|
1088
|
+
if (d !== -1) {
|
|
1089
|
+
e.push({ type: "comment", value: s.slice(0, d) }), s = s.slice(d);
|
|
1064
1090
|
continue;
|
|
1065
1091
|
} else {
|
|
1066
1092
|
e.push({ type: "comment", value: s });
|
|
@@ -1068,9 +1094,9 @@ class z extends d {
|
|
|
1068
1094
|
}
|
|
1069
1095
|
}
|
|
1070
1096
|
if (s.startsWith("/*")) {
|
|
1071
|
-
const
|
|
1072
|
-
if (
|
|
1073
|
-
e.push({ type: "comment", value: s.slice(0,
|
|
1097
|
+
const d = s.indexOf("*/");
|
|
1098
|
+
if (d !== -1) {
|
|
1099
|
+
e.push({ type: "comment", value: s.slice(0, d + 2) }), s = s.slice(d + 2);
|
|
1074
1100
|
continue;
|
|
1075
1101
|
}
|
|
1076
1102
|
}
|
|
@@ -1086,26 +1112,26 @@ class z extends d {
|
|
|
1086
1112
|
}
|
|
1087
1113
|
const n = s.match(/^([a-zA-Z_$][\w$]*)/);
|
|
1088
1114
|
if (n?.[1]) {
|
|
1089
|
-
const
|
|
1090
|
-
i.includes(
|
|
1115
|
+
const d = n[1];
|
|
1116
|
+
i.includes(d) ? e.push({ type: "keyword", value: d }) : e.push({ type: "text", value: d }), s = s.slice(d.length);
|
|
1091
1117
|
continue;
|
|
1092
1118
|
}
|
|
1093
|
-
const
|
|
1094
|
-
if (
|
|
1095
|
-
e.push({ type: "punctuation", value:
|
|
1119
|
+
const h = s[0];
|
|
1120
|
+
if (h && /^[{}[\]();,.:?!<>=+\-*/&|^%~@#]/.test(h)) {
|
|
1121
|
+
e.push({ type: "punctuation", value: h }), s = s.slice(1);
|
|
1096
1122
|
continue;
|
|
1097
1123
|
}
|
|
1098
|
-
const
|
|
1099
|
-
if (
|
|
1100
|
-
e.push({ type: "text", value:
|
|
1124
|
+
const l = s.match(/^(\s+)/);
|
|
1125
|
+
if (l?.[1]) {
|
|
1126
|
+
e.push({ type: "text", value: l[1] }), s = s.slice(l[1].length);
|
|
1101
1127
|
continue;
|
|
1102
1128
|
}
|
|
1103
1129
|
const c = s[0];
|
|
1104
1130
|
c && e.push({ type: "text", value: c }), s = s.slice(1);
|
|
1105
1131
|
}
|
|
1106
|
-
return e.map((r) => this.#
|
|
1132
|
+
return e.map((r) => this.#d(r)).join("");
|
|
1107
1133
|
}
|
|
1108
|
-
#
|
|
1134
|
+
#h(t) {
|
|
1109
1135
|
const e = [];
|
|
1110
1136
|
let s = t;
|
|
1111
1137
|
for (; s.length > 0; ) {
|
|
@@ -1141,17 +1167,17 @@ class z extends d {
|
|
|
1141
1167
|
e.push({ type: "text", value: n[1] }), s = s.slice(n[1].length);
|
|
1142
1168
|
continue;
|
|
1143
1169
|
}
|
|
1144
|
-
const
|
|
1145
|
-
if (
|
|
1146
|
-
e.push({ type: "text", value:
|
|
1170
|
+
const h = s.match(/^([^<]+)/);
|
|
1171
|
+
if (h?.[1]) {
|
|
1172
|
+
e.push({ type: "text", value: h[1] }), s = s.slice(h[1].length);
|
|
1147
1173
|
continue;
|
|
1148
1174
|
}
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1175
|
+
const l = s[0];
|
|
1176
|
+
l && e.push({ type: "text", value: l }), s = s.slice(1);
|
|
1151
1177
|
}
|
|
1152
|
-
return e.map((i) => this.#
|
|
1178
|
+
return e.map((i) => this.#d(i)).join("");
|
|
1153
1179
|
}
|
|
1154
|
-
#
|
|
1180
|
+
#l(t) {
|
|
1155
1181
|
const e = [];
|
|
1156
1182
|
let s = t;
|
|
1157
1183
|
for (; s.length > 0; ) {
|
|
@@ -1175,18 +1201,18 @@ class z extends d {
|
|
|
1175
1201
|
e.push({ type: "punctuation", value: n }), s = s.slice(1);
|
|
1176
1202
|
continue;
|
|
1177
1203
|
}
|
|
1178
|
-
const
|
|
1179
|
-
if (
|
|
1180
|
-
e.push({ type: "text", value:
|
|
1204
|
+
const h = s.match(/^(\s+)/);
|
|
1205
|
+
if (h?.[1]) {
|
|
1206
|
+
e.push({ type: "text", value: h[1] }), s = s.slice(h[1].length);
|
|
1181
1207
|
continue;
|
|
1182
1208
|
}
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1209
|
+
const l = s[0];
|
|
1210
|
+
l && e.push({ type: "text", value: l }), s = s.slice(1);
|
|
1185
1211
|
}
|
|
1186
|
-
return e.map((i) => this.#
|
|
1212
|
+
return e.map((i) => this.#d(i)).join("");
|
|
1187
1213
|
}
|
|
1188
|
-
#
|
|
1189
|
-
const e = this.#
|
|
1214
|
+
#d(t) {
|
|
1215
|
+
const e = this.#o(t.value);
|
|
1190
1216
|
switch (t.type) {
|
|
1191
1217
|
case "keyword":
|
|
1192
1218
|
return `<span class="ry-code__keyword">${e}</span>`;
|
|
@@ -1214,10 +1240,10 @@ class z extends d {
|
|
|
1214
1240
|
return e;
|
|
1215
1241
|
}
|
|
1216
1242
|
}
|
|
1217
|
-
#
|
|
1243
|
+
#o(t) {
|
|
1218
1244
|
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1219
1245
|
}
|
|
1220
|
-
#
|
|
1246
|
+
#a(t) {
|
|
1221
1247
|
const e = t.split(`
|
|
1222
1248
|
`);
|
|
1223
1249
|
for (; e.length && !e[0]?.trim(); ) e.shift();
|
|
@@ -1236,25 +1262,39 @@ class z extends d {
|
|
|
1236
1262
|
this.#t = t, this.#e();
|
|
1237
1263
|
}
|
|
1238
1264
|
}
|
|
1239
|
-
customElements.define("ry-code",
|
|
1240
|
-
class
|
|
1265
|
+
customElements.define("ry-code", Q);
|
|
1266
|
+
class tt extends p {
|
|
1241
1267
|
setup() {
|
|
1242
1268
|
const t = this.$("template");
|
|
1243
1269
|
if (!t) return;
|
|
1244
|
-
const e = this.#
|
|
1270
|
+
const e = this.$('script[slot="js"]'), s = e ? this.#e(e.textContent ?? "") : null, i = this.#e(t.innerHTML), r = M(i), a = this.hasAttribute("stacked");
|
|
1245
1271
|
this.innerHTML = `
|
|
1246
1272
|
<div data-ry-target="preview" class="ry-example__preview"></div>
|
|
1247
1273
|
<div data-ry-target="code" class="ry-example__code"></div>
|
|
1248
|
-
|
|
1274
|
+
${s ? '<div data-ry-target="usage" class="ry-example__usage"></div>' : ""}
|
|
1275
|
+
`, a && this.setAttribute("data-stacked", "");
|
|
1276
|
+
const n = document.createElement("ry-code");
|
|
1277
|
+
n.setAttribute("language", "html"), n.setAttribute("title", this.getAttribute("title") ?? "Example"), n.textContent = i, this.$('[data-ry-target="code"]').appendChild(n);
|
|
1278
|
+
const h = document.createElement("template");
|
|
1279
|
+
h.innerHTML = r, this.$('[data-ry-target="preview"]').appendChild(h.content), s && this.#t(s);
|
|
1280
|
+
}
|
|
1281
|
+
#t(t) {
|
|
1282
|
+
const e = this.$('[data-ry-target="usage"]');
|
|
1283
|
+
if (!e) return;
|
|
1284
|
+
const s = document.createElement("button");
|
|
1285
|
+
s.className = "ry-example__usage-toggle", s.type = "button", s.innerHTML = '<span>JS Usage</span><ry-icon name="chevron-down" size="16"></ry-icon>', s.setAttribute("aria-expanded", "false");
|
|
1286
|
+
const i = document.createElement("div");
|
|
1287
|
+
i.className = "ry-example__usage-panel", i.hidden = !0;
|
|
1249
1288
|
const r = document.createElement("ry-code");
|
|
1250
|
-
r.setAttribute("language", "
|
|
1251
|
-
|
|
1252
|
-
|
|
1289
|
+
r.setAttribute("language", "js"), r.setAttribute("title", "JavaScript"), r.textContent = t, i.appendChild(r), e.appendChild(s), e.appendChild(i), this.on(s, "click", () => {
|
|
1290
|
+
const a = s.getAttribute("aria-expanded") === "true";
|
|
1291
|
+
s.setAttribute("aria-expanded", String(!a)), i.hidden = a;
|
|
1292
|
+
});
|
|
1253
1293
|
}
|
|
1254
1294
|
/**
|
|
1255
1295
|
* Normalize indentation by removing common leading whitespace
|
|
1256
1296
|
*/
|
|
1257
|
-
#
|
|
1297
|
+
#e(t) {
|
|
1258
1298
|
const e = t.split(`
|
|
1259
1299
|
`);
|
|
1260
1300
|
for (; e.length && !e[0].trim(); ) e.shift();
|
|
@@ -1267,8 +1307,8 @@ class Y extends d {
|
|
|
1267
1307
|
`).trim();
|
|
1268
1308
|
}
|
|
1269
1309
|
}
|
|
1270
|
-
customElements.define("ry-example",
|
|
1271
|
-
class
|
|
1310
|
+
customElements.define("ry-example", tt);
|
|
1311
|
+
class et extends p {
|
|
1272
1312
|
static get observedAttributes() {
|
|
1273
1313
|
return ["name", "size", "label"];
|
|
1274
1314
|
}
|
|
@@ -1279,7 +1319,7 @@ class G extends d {
|
|
|
1279
1319
|
e !== s && this.hasAttribute("data-ry-initialized") && this.#t();
|
|
1280
1320
|
}
|
|
1281
1321
|
#t() {
|
|
1282
|
-
const t = this.getAttribute("name") ?? "", e = this.getAttribute("size") ?? "24", s = this.getAttribute("label"), i =
|
|
1322
|
+
const t = this.getAttribute("name") ?? "", e = this.getAttribute("size") ?? "24", s = this.getAttribute("label"), i = g(t);
|
|
1283
1323
|
if (!i) {
|
|
1284
1324
|
this.innerHTML = "";
|
|
1285
1325
|
return;
|
|
@@ -1301,24 +1341,24 @@ class G extends d {
|
|
|
1301
1341
|
this.setAttribute("size", String(t));
|
|
1302
1342
|
}
|
|
1303
1343
|
}
|
|
1304
|
-
customElements.define("ry-icon",
|
|
1305
|
-
const
|
|
1306
|
-
function
|
|
1344
|
+
customElements.define("ry-icon", et);
|
|
1345
|
+
const st = ["form", "section", "fieldset", "ry-section"], y = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Set();
|
|
1346
|
+
function it(o) {
|
|
1307
1347
|
let t = o.parentElement;
|
|
1308
1348
|
for (; t; ) {
|
|
1309
|
-
if (
|
|
1349
|
+
if (st.some((e) => t.matches(e)))
|
|
1310
1350
|
return t;
|
|
1311
1351
|
t = t.parentElement;
|
|
1312
1352
|
}
|
|
1313
1353
|
return null;
|
|
1314
1354
|
}
|
|
1315
|
-
function
|
|
1316
|
-
if (
|
|
1317
|
-
const t =
|
|
1355
|
+
function rt(o) {
|
|
1356
|
+
if (E.has(o)) return;
|
|
1357
|
+
const t = y.get(o);
|
|
1318
1358
|
if (!t || t.size < 2) return;
|
|
1319
1359
|
const e = /* @__PURE__ */ new Map();
|
|
1320
1360
|
for (const s of t) {
|
|
1321
|
-
const i =
|
|
1361
|
+
const i = it(s), r = e.get(i) ?? [];
|
|
1322
1362
|
r.push(s), e.set(i, r);
|
|
1323
1363
|
}
|
|
1324
1364
|
if (e.size > 1) {
|
|
@@ -1331,10 +1371,10 @@ function Z(o) {
|
|
|
1331
1371
|
s.push("(no container)");
|
|
1332
1372
|
console.warn(
|
|
1333
1373
|
`ry-toggle-button: Buttons with name="${o}" span multiple containers (${s.join(", ")}). Intentional?`
|
|
1334
|
-
),
|
|
1374
|
+
), E.add(o);
|
|
1335
1375
|
}
|
|
1336
1376
|
}
|
|
1337
|
-
class
|
|
1377
|
+
class at extends p {
|
|
1338
1378
|
static observedAttributes = ["pressed", "disabled", "name", "value"];
|
|
1339
1379
|
#t = !1;
|
|
1340
1380
|
setup() {
|
|
@@ -1345,12 +1385,12 @@ class Q extends d {
|
|
|
1345
1385
|
}
|
|
1346
1386
|
#e() {
|
|
1347
1387
|
const t = this.name;
|
|
1348
|
-
t && (
|
|
1388
|
+
t && (y.has(t) || y.set(t, /* @__PURE__ */ new Set()), y.get(t).add(this), this.#t = !0, queueMicrotask(() => rt(t)));
|
|
1349
1389
|
}
|
|
1350
1390
|
#i() {
|
|
1351
1391
|
if (!this.#t) return;
|
|
1352
1392
|
const t = this.name;
|
|
1353
|
-
t &&
|
|
1393
|
+
t && y.has(t) && (y.get(t).delete(this), y.get(t).size === 0 && (y.delete(t), E.delete(t))), this.#t = !1;
|
|
1354
1394
|
}
|
|
1355
1395
|
#s = (t) => {
|
|
1356
1396
|
if (this.disabled) {
|
|
@@ -1365,7 +1405,7 @@ class Q extends d {
|
|
|
1365
1405
|
#n() {
|
|
1366
1406
|
const t = this.name;
|
|
1367
1407
|
if (!t) return;
|
|
1368
|
-
const e =
|
|
1408
|
+
const e = y.get(t);
|
|
1369
1409
|
if (e)
|
|
1370
1410
|
for (const s of e)
|
|
1371
1411
|
s !== this && s.pressed && (s.pressed = !1);
|
|
@@ -1406,8 +1446,8 @@ class Q extends d {
|
|
|
1406
1446
|
this.setAttribute("icon", t);
|
|
1407
1447
|
}
|
|
1408
1448
|
}
|
|
1409
|
-
customElements.define("ry-toggle-button",
|
|
1410
|
-
class
|
|
1449
|
+
customElements.define("ry-toggle-button", at);
|
|
1450
|
+
class nt extends p {
|
|
1411
1451
|
#t = !1;
|
|
1412
1452
|
#e = null;
|
|
1413
1453
|
#i = null;
|
|
@@ -1416,9 +1456,9 @@ class tt extends d {
|
|
|
1416
1456
|
#n = /* @__PURE__ */ new Map();
|
|
1417
1457
|
static observedAttributes = ["min", "max", "step", "value", "start", "end", "disabled"];
|
|
1418
1458
|
setup() {
|
|
1419
|
-
this.#
|
|
1459
|
+
this.#h(), this.#d(), this.#y();
|
|
1420
1460
|
}
|
|
1421
|
-
#
|
|
1461
|
+
#h() {
|
|
1422
1462
|
const t = this.hasAttribute("range"), e = this.hasAttribute("labeled"), s = this.hasAttribute("tooltip");
|
|
1423
1463
|
this.hasAttribute("vertical");
|
|
1424
1464
|
let i = `
|
|
@@ -1436,20 +1476,20 @@ class tt extends d {
|
|
|
1436
1476
|
<div data-ry-target="thumb-value" class="ry-slider__thumb" tabindex="0" role="slider" aria-label="Value">
|
|
1437
1477
|
${s ? '<span data-ry-target="tooltip-value" class="ry-slider__tooltip"></span>' : ""}
|
|
1438
1478
|
</div>
|
|
1439
|
-
`, i += "</div>", e && (i += this.#
|
|
1479
|
+
`, i += "</div>", e && (i += this.#l()), this.innerHTML = i, this.#i = this.$('[data-ry-target="track"]'), this.#s = this.$('[data-ry-target="fill"]'), t ? (this.#r.set("start", this.$('[data-ry-target="thumb-start"]')), this.#r.set("end", this.$('[data-ry-target="thumb-end"]')), s && (this.#n.set("start", this.$('[data-ry-target="tooltip-start"]')), this.#n.set("end", this.$('[data-ry-target="tooltip-end"]')))) : (this.#r.set("value", this.$('[data-ry-target="thumb-value"]')), s && this.#n.set("value", this.$('[data-ry-target="tooltip-value"]')));
|
|
1440
1480
|
}
|
|
1441
|
-
#
|
|
1481
|
+
#l() {
|
|
1442
1482
|
const t = this.min, e = this.max, s = this.getAttribute("labels")?.split(","), i = this.getAttribute("label-type") || "number";
|
|
1443
1483
|
let r = [];
|
|
1444
1484
|
if (s)
|
|
1445
1485
|
r = s;
|
|
1446
1486
|
else
|
|
1447
1487
|
for (let n = 0; n < 5; n++) {
|
|
1448
|
-
const
|
|
1488
|
+
const h = n / 4, l = t + h * (e - t);
|
|
1449
1489
|
if (i === "letter")
|
|
1450
1490
|
r.push(String.fromCharCode(65 + n));
|
|
1451
1491
|
else {
|
|
1452
|
-
const c = Math.round(
|
|
1492
|
+
const c = Math.round(l * 100) / 100;
|
|
1453
1493
|
r.push(String(Number.isInteger(c) ? c : c.toFixed(1)));
|
|
1454
1494
|
}
|
|
1455
1495
|
}
|
|
@@ -1459,34 +1499,34 @@ class tt extends d {
|
|
|
1459
1499
|
</div>
|
|
1460
1500
|
`;
|
|
1461
1501
|
}
|
|
1462
|
-
#
|
|
1463
|
-
this.#i && this.on(this.#i, "pointerdown", this.#
|
|
1502
|
+
#d() {
|
|
1503
|
+
this.#i && this.on(this.#i, "pointerdown", this.#o);
|
|
1464
1504
|
for (const [t, e] of this.#r)
|
|
1465
|
-
this.on(e, "pointerdown", (s) => this.#
|
|
1466
|
-
this.on(document, "pointermove", this.#
|
|
1505
|
+
this.on(e, "pointerdown", (s) => this.#a(s, t)), this.on(e, "keydown", (s) => this.#m(s, t));
|
|
1506
|
+
this.on(document, "pointermove", this.#u), this.on(document, "pointerup", this.#g);
|
|
1467
1507
|
}
|
|
1468
|
-
#
|
|
1508
|
+
#o = (t) => {
|
|
1469
1509
|
if (this.disabled) return;
|
|
1470
|
-
const e = this.#
|
|
1510
|
+
const e = this.#A(t);
|
|
1471
1511
|
if (this.hasAttribute("range")) {
|
|
1472
1512
|
const i = Math.abs(e - this.start), r = Math.abs(e - this.end);
|
|
1473
1513
|
i < r ? (this.start = e, this.#e = "start") : (this.end = e, this.#e = "end");
|
|
1474
1514
|
} else
|
|
1475
1515
|
this.value = e, this.#e = "value";
|
|
1476
|
-
this.#t = !0, this.#
|
|
1516
|
+
this.#t = !0, this.#y(), this.#b();
|
|
1477
1517
|
};
|
|
1478
|
-
#
|
|
1518
|
+
#a = (t, e) => {
|
|
1479
1519
|
this.disabled || (t.stopPropagation(), this.#t = !0, this.#e = e, t.target.setPointerCapture(t.pointerId));
|
|
1480
1520
|
};
|
|
1481
|
-
#
|
|
1521
|
+
#u = (t) => {
|
|
1482
1522
|
if (!this.#t || !this.#e) return;
|
|
1483
|
-
const e = this.#
|
|
1484
|
-
this.hasAttribute("range") ? this.#e === "start" ? this.start = Math.min(e, this.end) : this.#e === "end" && (this.end = Math.max(e, this.start)) : this.value = e, this.#
|
|
1523
|
+
const e = this.#A(t);
|
|
1524
|
+
this.hasAttribute("range") ? this.#e === "start" ? this.start = Math.min(e, this.end) : this.#e === "end" && (this.end = Math.max(e, this.start)) : this.value = e, this.#y(), this.#b();
|
|
1485
1525
|
};
|
|
1486
|
-
#
|
|
1487
|
-
this.#t && (this.#t = !1, this.#e = null, this.#
|
|
1526
|
+
#g = () => {
|
|
1527
|
+
this.#t && (this.#t = !1, this.#e = null, this.#S());
|
|
1488
1528
|
};
|
|
1489
|
-
#
|
|
1529
|
+
#m = (t, e) => {
|
|
1490
1530
|
if (this.disabled) return;
|
|
1491
1531
|
const s = this.step || 1, i = (this.max - this.min) / 10;
|
|
1492
1532
|
let r = 0;
|
|
@@ -1506,66 +1546,66 @@ class tt extends d {
|
|
|
1506
1546
|
r = -i;
|
|
1507
1547
|
break;
|
|
1508
1548
|
case "Home":
|
|
1509
|
-
r = this.min - this.#
|
|
1549
|
+
r = this.min - this.#f(e);
|
|
1510
1550
|
break;
|
|
1511
1551
|
case "End":
|
|
1512
|
-
r = this.max - this.#
|
|
1552
|
+
r = this.max - this.#f(e);
|
|
1513
1553
|
break;
|
|
1514
1554
|
default:
|
|
1515
1555
|
return;
|
|
1516
1556
|
}
|
|
1517
1557
|
t.preventDefault();
|
|
1518
|
-
const a = this.#
|
|
1519
|
-
e === "start" ? this.start = Math.min(a, this.end) : e === "end" ? this.end = Math.max(a, this.start) : this.value = a, this.#
|
|
1558
|
+
const a = this.#p(this.#f(e) + r);
|
|
1559
|
+
e === "start" ? this.start = Math.min(a, this.end) : e === "end" ? this.end = Math.max(a, this.start) : this.value = a, this.#y(), this.#b(), this.#S();
|
|
1520
1560
|
};
|
|
1521
|
-
#
|
|
1561
|
+
#f(t) {
|
|
1522
1562
|
return t === "start" ? this.start : t === "end" ? this.end : this.value;
|
|
1523
1563
|
}
|
|
1524
|
-
#
|
|
1564
|
+
#A(t) {
|
|
1525
1565
|
if (!this.#i) return this.min;
|
|
1526
1566
|
const e = this.#i.getBoundingClientRect(), s = this.hasAttribute("vertical"), i = this.hasAttribute("reversed");
|
|
1527
1567
|
let r;
|
|
1528
1568
|
s ? r = (e.bottom - t.clientY) / e.height : r = (t.clientX - e.left) / e.width, i && (r = 1 - r), r = Math.max(0, Math.min(1, r));
|
|
1529
1569
|
const a = this.min + r * (this.max - this.min);
|
|
1530
|
-
return this.#
|
|
1570
|
+
return this.#c(a);
|
|
1531
1571
|
}
|
|
1532
|
-
#
|
|
1572
|
+
#c(t) {
|
|
1533
1573
|
const e = this.step;
|
|
1534
|
-
if (e === 0) return this.#
|
|
1574
|
+
if (e === 0) return this.#p(t);
|
|
1535
1575
|
const s = Math.round((t - this.min) / e) * e + this.min;
|
|
1536
|
-
return this.#
|
|
1576
|
+
return this.#p(s);
|
|
1537
1577
|
}
|
|
1538
|
-
#
|
|
1578
|
+
#p(t) {
|
|
1539
1579
|
return Math.max(this.min, Math.min(this.max, t));
|
|
1540
1580
|
}
|
|
1541
|
-
#
|
|
1581
|
+
#y() {
|
|
1542
1582
|
const t = this.hasAttribute("range"), e = this.hasAttribute("vertical"), s = this.hasAttribute("reversed"), i = (r) => {
|
|
1543
1583
|
let a = (r - this.min) / (this.max - this.min) * 100;
|
|
1544
1584
|
return s && (a = 100 - a), a;
|
|
1545
1585
|
};
|
|
1546
1586
|
if (t) {
|
|
1547
|
-
const r = i(this.start), a = i(this.end), n = Math.min(r, a),
|
|
1548
|
-
this.#s && (e ? (this.#s.style.bottom = `${n}%`, this.#s.style.height = `${
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1587
|
+
const r = i(this.start), a = i(this.end), n = Math.min(r, a), h = Math.max(r, a);
|
|
1588
|
+
this.#s && (e ? (this.#s.style.bottom = `${n}%`, this.#s.style.height = `${h - n}%`, this.#s.style.left = "", this.#s.style.width = "") : (this.#s.style.left = `${n}%`, this.#s.style.width = `${h - n}%`, this.#s.style.bottom = "", this.#s.style.height = ""));
|
|
1589
|
+
const l = this.#r.get("start"), c = this.#r.get("end");
|
|
1590
|
+
l && (e ? (l.style.bottom = `${r}%`, l.style.left = "") : (l.style.left = `${r}%`, l.style.bottom = "")), c && (e ? (c.style.bottom = `${a}%`, c.style.left = "") : (c.style.left = `${a}%`, c.style.bottom = "")), this.#w("start", this.start), this.#w("end", this.end), l?.setAttribute("aria-valuenow", String(this.start)), l?.setAttribute("aria-valuemin", String(this.min)), l?.setAttribute("aria-valuemax", String(this.end)), c?.setAttribute("aria-valuenow", String(this.end)), c?.setAttribute("aria-valuemin", String(this.start)), c?.setAttribute("aria-valuemax", String(this.max));
|
|
1551
1591
|
} else {
|
|
1552
1592
|
const r = i(this.value);
|
|
1553
1593
|
this.#s && (e ? (this.#s.style.bottom = "0", this.#s.style.height = `${r}%`, this.#s.style.left = "", this.#s.style.width = "") : (this.#s.style.left = "0", this.#s.style.width = `${r}%`, this.#s.style.bottom = "", this.#s.style.height = ""));
|
|
1554
1594
|
const a = this.#r.get("value");
|
|
1555
|
-
a && (e ? (a.style.bottom = `${r}%`, a.style.left = "") : (a.style.left = `${r}%`, a.style.bottom = "")), this.#
|
|
1595
|
+
a && (e ? (a.style.bottom = `${r}%`, a.style.left = "") : (a.style.left = `${r}%`, a.style.bottom = "")), this.#w("value", this.value), a?.setAttribute("aria-valuenow", String(this.value)), a?.setAttribute("aria-valuemin", String(this.min)), a?.setAttribute("aria-valuemax", String(this.max));
|
|
1556
1596
|
}
|
|
1557
1597
|
}
|
|
1558
|
-
#
|
|
1598
|
+
#w(t, e) {
|
|
1559
1599
|
const s = this.#n.get(t);
|
|
1560
1600
|
if (s) {
|
|
1561
1601
|
const i = this.step === 0 ? 2 : String(this.step).split(".")[1]?.length || 0;
|
|
1562
1602
|
s.textContent = e.toFixed(i);
|
|
1563
1603
|
}
|
|
1564
1604
|
}
|
|
1565
|
-
#
|
|
1605
|
+
#b() {
|
|
1566
1606
|
this.hasAttribute("range") ? this.emit("input", { start: this.start, end: this.end }) : this.emit("input", { value: this.value });
|
|
1567
1607
|
}
|
|
1568
|
-
#
|
|
1608
|
+
#S() {
|
|
1569
1609
|
this.hasAttribute("range") ? this.emit("change", { start: this.start, end: this.end }) : this.emit("change", { value: this.value });
|
|
1570
1610
|
}
|
|
1571
1611
|
// --- Public API ---
|
|
@@ -1591,19 +1631,19 @@ class tt extends d {
|
|
|
1591
1631
|
return parseFloat(this.getAttribute("value") ?? String(this.min));
|
|
1592
1632
|
}
|
|
1593
1633
|
set value(t) {
|
|
1594
|
-
this.setAttribute("value", String(this.#
|
|
1634
|
+
this.setAttribute("value", String(this.#p(t)));
|
|
1595
1635
|
}
|
|
1596
1636
|
get start() {
|
|
1597
1637
|
return parseFloat(this.getAttribute("start") ?? String(this.min));
|
|
1598
1638
|
}
|
|
1599
1639
|
set start(t) {
|
|
1600
|
-
this.setAttribute("start", String(this.#
|
|
1640
|
+
this.setAttribute("start", String(this.#p(t)));
|
|
1601
1641
|
}
|
|
1602
1642
|
get end() {
|
|
1603
1643
|
return parseFloat(this.getAttribute("end") ?? String(this.max));
|
|
1604
1644
|
}
|
|
1605
1645
|
set end(t) {
|
|
1606
|
-
this.setAttribute("end", String(this.#
|
|
1646
|
+
this.setAttribute("end", String(this.#p(t)));
|
|
1607
1647
|
}
|
|
1608
1648
|
get disabled() {
|
|
1609
1649
|
return this.hasAttribute("disabled");
|
|
@@ -1612,8 +1652,8 @@ class tt extends d {
|
|
|
1612
1652
|
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
1613
1653
|
}
|
|
1614
1654
|
}
|
|
1615
|
-
customElements.define("ry-slider",
|
|
1616
|
-
class
|
|
1655
|
+
customElements.define("ry-slider", nt);
|
|
1656
|
+
class ot extends p {
|
|
1617
1657
|
#t = !1;
|
|
1618
1658
|
#e = 0;
|
|
1619
1659
|
#i = 0;
|
|
@@ -1622,9 +1662,9 @@ class et extends d {
|
|
|
1622
1662
|
#n = null;
|
|
1623
1663
|
static observedAttributes = ["min", "max", "step", "value", "disabled", "label", "labels", "description"];
|
|
1624
1664
|
setup() {
|
|
1625
|
-
this.#
|
|
1665
|
+
this.#h(), this.#l(), this.#p();
|
|
1626
1666
|
}
|
|
1627
|
-
#
|
|
1667
|
+
#h() {
|
|
1628
1668
|
const t = this.getAttribute("label"), e = this.getAttribute("description"), s = e ? ` title="${e}"` : "";
|
|
1629
1669
|
this.innerHTML = `
|
|
1630
1670
|
<div data-ry-target="ring" class="ry-knob__ring"${s}>
|
|
@@ -1636,41 +1676,41 @@ class et extends d {
|
|
|
1636
1676
|
${t ? `<span data-ry-target="label" class="ry-knob__label"${s}>${t}</span>` : ""}
|
|
1637
1677
|
`, this.#s = this.$('[data-ry-target="ring"]'), this.#r = this.$('[data-ry-target="indicator"]'), this.#n = this.$('[data-ry-target="display"]');
|
|
1638
1678
|
}
|
|
1639
|
-
#
|
|
1640
|
-
this.#s && (this.on(this.#s, "mousedown", this.#
|
|
1679
|
+
#l() {
|
|
1680
|
+
this.#s && (this.on(this.#s, "mousedown", this.#d), this.on(document, "mousemove", this.#o), this.on(document, "mouseup", this.#a), this.on(this.#s, "touchstart", this.#u), this.on(document, "touchmove", this.#g), this.on(document, "touchend", this.#m), this.on(this.#s, "wheel", this.#f), this.on(this, "keydown", this.#A));
|
|
1641
1681
|
}
|
|
1642
|
-
#
|
|
1682
|
+
#d = (t) => {
|
|
1643
1683
|
this.disabled || (t.preventDefault(), this.#t = !0, this.#e = t.clientY, this.#i = this.value, this.#s?.classList.add("ry-knob__ring--dragging"), this.setAttribute("data-dragging", ""));
|
|
1644
1684
|
};
|
|
1645
|
-
#
|
|
1685
|
+
#o = (t) => {
|
|
1646
1686
|
if (!this.#t) return;
|
|
1647
1687
|
const e = this.#e - t.clientY, s = (this.max - this.min) / 100;
|
|
1648
|
-
this.#
|
|
1688
|
+
this.#c(this.#i + e * s);
|
|
1649
1689
|
};
|
|
1650
|
-
#
|
|
1651
|
-
this.#t && (this.#t = !1, this.#s?.classList.remove("ry-knob__ring--dragging"), this.removeAttribute("data-dragging"), this.#
|
|
1690
|
+
#a = () => {
|
|
1691
|
+
this.#t && (this.#t = !1, this.#s?.classList.remove("ry-knob__ring--dragging"), this.removeAttribute("data-dragging"), this.#b());
|
|
1652
1692
|
};
|
|
1653
|
-
#
|
|
1693
|
+
#u = (t) => {
|
|
1654
1694
|
this.disabled || (t.preventDefault(), this.#t = !0, this.#e = t.touches[0]?.clientY ?? 0, this.#i = this.value, this.#s?.classList.add("ry-knob__ring--dragging"), this.setAttribute("data-dragging", ""));
|
|
1655
1695
|
};
|
|
1656
|
-
#
|
|
1696
|
+
#g = (t) => {
|
|
1657
1697
|
if (!this.#t) return;
|
|
1658
1698
|
t.preventDefault();
|
|
1659
1699
|
const e = t.touches[0];
|
|
1660
1700
|
if (!e) return;
|
|
1661
1701
|
const s = this.#e - e.clientY, i = (this.max - this.min) / 100;
|
|
1662
|
-
this.#
|
|
1702
|
+
this.#c(this.#i + s * i);
|
|
1663
1703
|
};
|
|
1664
|
-
#
|
|
1665
|
-
this.#t && (this.#t = !1, this.#s?.classList.remove("ry-knob__ring--dragging"), this.removeAttribute("data-dragging"), this.#
|
|
1704
|
+
#m = () => {
|
|
1705
|
+
this.#t && (this.#t = !1, this.#s?.classList.remove("ry-knob__ring--dragging"), this.removeAttribute("data-dragging"), this.#b());
|
|
1666
1706
|
};
|
|
1667
|
-
#
|
|
1707
|
+
#f = (t) => {
|
|
1668
1708
|
if (this.disabled) return;
|
|
1669
1709
|
t.preventDefault();
|
|
1670
1710
|
const e = this.step || (this.max - this.min) / 50, s = t.deltaY < 0 ? e : -e;
|
|
1671
|
-
this.#
|
|
1711
|
+
this.#c(this.value + s), this.#b();
|
|
1672
1712
|
};
|
|
1673
|
-
#
|
|
1713
|
+
#A = (t) => {
|
|
1674
1714
|
if (this.disabled) return;
|
|
1675
1715
|
const e = this.step || 1, s = (this.max - this.min) / 10;
|
|
1676
1716
|
let i = 0;
|
|
@@ -1690,26 +1730,26 @@ class et extends d {
|
|
|
1690
1730
|
i = -s;
|
|
1691
1731
|
break;
|
|
1692
1732
|
case "Home":
|
|
1693
|
-
this.#
|
|
1733
|
+
this.#c(this.min), this.#b();
|
|
1694
1734
|
return;
|
|
1695
1735
|
case "End":
|
|
1696
|
-
this.#
|
|
1736
|
+
this.#c(this.max), this.#b();
|
|
1697
1737
|
return;
|
|
1698
1738
|
default:
|
|
1699
1739
|
return;
|
|
1700
1740
|
}
|
|
1701
|
-
t.preventDefault(), this.#
|
|
1741
|
+
t.preventDefault(), this.#c(this.value + i), this.#b();
|
|
1702
1742
|
};
|
|
1703
|
-
#
|
|
1743
|
+
#c(t) {
|
|
1704
1744
|
let e = Math.max(this.min, Math.min(this.max, t));
|
|
1705
1745
|
const s = this.step;
|
|
1706
|
-
s > 0 && (e = Math.round((e - this.min) / s) * s + this.min, e = Math.max(this.min, Math.min(this.max, e))), this.value = e, this.#
|
|
1746
|
+
s > 0 && (e = Math.round((e - this.min) / s) * s + this.min, e = Math.max(this.min, Math.min(this.max, e))), this.value = e, this.#p(), this.#w();
|
|
1707
1747
|
}
|
|
1708
|
-
#
|
|
1748
|
+
#p() {
|
|
1709
1749
|
const t = (this.value - this.min) / (this.max - this.min), e = -135 + t * 270;
|
|
1710
|
-
this.#s && (this.#s.style.setProperty("--knob-rotation", `${e}deg`), this.#s.style.setProperty("--knob-percent", String(t))), this.#n && (this.#n.textContent = this.#
|
|
1750
|
+
this.#s && (this.#s.style.setProperty("--knob-rotation", `${e}deg`), this.#s.style.setProperty("--knob-percent", String(t))), this.#n && (this.#n.textContent = this.#y(this.value)), this.setAttribute("aria-valuenow", String(this.value)), this.setAttribute("aria-valuemin", String(this.min)), this.setAttribute("aria-valuemax", String(this.max));
|
|
1711
1751
|
}
|
|
1712
|
-
#
|
|
1752
|
+
#y(t) {
|
|
1713
1753
|
const e = this.getAttribute("labels");
|
|
1714
1754
|
if (e) {
|
|
1715
1755
|
const i = e.split(","), r = Math.round(t);
|
|
@@ -1717,16 +1757,16 @@ class et extends d {
|
|
|
1717
1757
|
}
|
|
1718
1758
|
return this.step >= 1 ? Math.round(t).toString() : Math.abs(t) >= 1e3 ? (t / 1e3).toFixed(1) + "k" : Math.abs(t) >= 100 ? Math.round(t).toString() : Math.abs(t) >= 10 ? t.toFixed(1) : t.toFixed(2);
|
|
1719
1759
|
}
|
|
1720
|
-
#
|
|
1760
|
+
#w() {
|
|
1721
1761
|
const t = (this.value - this.min) / (this.max - this.min);
|
|
1722
1762
|
this.emit("input", { value: this.value, percent: t });
|
|
1723
1763
|
}
|
|
1724
|
-
#
|
|
1764
|
+
#b() {
|
|
1725
1765
|
const t = (this.value - this.min) / (this.max - this.min);
|
|
1726
1766
|
this.emit("change", { value: this.value, percent: t });
|
|
1727
1767
|
}
|
|
1728
1768
|
attributeChangedCallback(t, e, s) {
|
|
1729
|
-
e !== s && t === "value" && this.#s && this.#
|
|
1769
|
+
e !== s && t === "value" && this.#s && this.#p();
|
|
1730
1770
|
}
|
|
1731
1771
|
// --- Public API ---
|
|
1732
1772
|
get min() {
|
|
@@ -1760,29 +1800,280 @@ class et extends d {
|
|
|
1760
1800
|
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
1761
1801
|
}
|
|
1762
1802
|
}
|
|
1763
|
-
customElements.define("ry-knob",
|
|
1764
|
-
|
|
1803
|
+
customElements.define("ry-knob", ot);
|
|
1804
|
+
const S = 15, T = 3;
|
|
1805
|
+
class ht extends p {
|
|
1806
|
+
#t = null;
|
|
1807
|
+
#e = null;
|
|
1808
|
+
#i = null;
|
|
1809
|
+
#s = null;
|
|
1810
|
+
#r = null;
|
|
1811
|
+
#n = !1;
|
|
1812
|
+
#h = 0;
|
|
1813
|
+
#l = 0;
|
|
1814
|
+
#d = 0;
|
|
1815
|
+
#o = !1;
|
|
1816
|
+
#a = null;
|
|
1817
|
+
#u = null;
|
|
1818
|
+
static observedAttributes = ["min", "max", "step", "value", "disabled", "arrows", "icons", "drag", "editable", "wrap", "label", "prefix", "suffix"];
|
|
1819
|
+
setup() {
|
|
1820
|
+
this.#g(), this.#f(), this.#A(), this.#v();
|
|
1821
|
+
}
|
|
1822
|
+
#g() {
|
|
1823
|
+
const t = this.getAttribute("arrows") ?? "both", e = this.getAttribute("label"), s = t === "stacked", [i, r] = this.#m(s), a = t === "both" || t === "start" || s, n = t === "both" || t === "end" || s, h = this.getAttribute("prefix"), l = this.getAttribute("suffix"), c = a ? `<button data-ry-target="decrement" class="ry-number-select__btn ry-number-select__decrement" aria-label="Decrease" tabindex="-1" type="button">${i}</button>` : "", d = n ? `<button data-ry-target="increment" class="ry-number-select__btn ry-number-select__increment" aria-label="Increase" tabindex="-1" type="button">${r}</button>` : "", u = `
|
|
1824
|
+
<div data-ry-target="display" class="ry-number-select__display" tabindex="0" role="spinbutton"
|
|
1825
|
+
aria-valuenow="${this.value}" aria-valuemin="${this.min}" aria-valuemax="${this.max}"
|
|
1826
|
+
${e ? `aria-label="${e}"` : ""}>
|
|
1827
|
+
${h ? `<span data-ry-target="prefix" class="ry-number-select__affix">${h}</span>` : ""}
|
|
1828
|
+
<span data-ry-target="value" class="ry-number-select__value">${this.#j(this.value)}</span>
|
|
1829
|
+
${l ? `<span data-ry-target="suffix" class="ry-number-select__affix">${l}</span>` : ""}
|
|
1830
|
+
<input data-ry-target="input" class="ry-number-select__input" type="text" inputmode="decimal" tabindex="-1">
|
|
1831
|
+
</div>`, b = e ? `<span data-ry-target="label" class="ry-number-select__label">${e}</span>` : "";
|
|
1832
|
+
s ? this.innerHTML = `${d}${u}${c}${b}` : this.innerHTML = `${c}${u}${d}${b}`;
|
|
1833
|
+
}
|
|
1834
|
+
#m(t) {
|
|
1835
|
+
const e = this.getAttribute("icons") ?? "plus-minus";
|
|
1836
|
+
return e === "chevron" ? t ? [g("chevron-down") ?? "▾", g("chevron-up") ?? "▴"] : [g("chevron-left") ?? "‹", g("chevron-right") ?? "›"] : e === "arrow" ? t ? [g("chevron-down") ?? "▼", g("chevron-up") ?? "▲"] : [g("chevron-left") ?? "◀", g("chevron-right") ?? "▶"] : [g("minus") ?? "−", g("plus") ?? "+"];
|
|
1837
|
+
}
|
|
1838
|
+
#f() {
|
|
1839
|
+
this.#t = this.$('[data-ry-target="display"]'), this.#e = this.$('[data-ry-target="value"]'), this.#i = this.$('[data-ry-target="input"]'), this.#s = this.$('[data-ry-target="decrement"]'), this.#r = this.$('[data-ry-target="increment"]');
|
|
1840
|
+
}
|
|
1841
|
+
#A() {
|
|
1842
|
+
this.#s && (this.on(this.#s, "mousedown", (t) => {
|
|
1843
|
+
t.preventDefault(), this.#c(-1);
|
|
1844
|
+
}), this.on(this.#s, "mouseup", () => this.#p()), this.on(this.#s, "mouseleave", () => this.#p())), this.#r && (this.on(this.#r, "mousedown", (t) => {
|
|
1845
|
+
t.preventDefault(), this.#c(1);
|
|
1846
|
+
}), this.on(this.#r, "mouseup", () => this.#p()), this.on(this.#r, "mouseleave", () => this.#p())), this.#t && this.on(this.#t, "mousedown", this.#F), this.on(document, "mousemove", this.#W), this.on(document, "mouseup", this.#E), this.#t && this.on(this.#t, "touchstart", this.#X), this.on(document, "touchmove", this.#G), this.on(document, "touchend", this.#K), this.#t && this.on(this.#t, "keydown", this.#q), this.on(this, "wheel", this.#J), this.#t && this.on(this.#t, "dblclick", () => this.#_()), this.#i && (this.on(this.#i, "blur", () => this.#U()), this.on(this.#i, "keydown", (t) => {
|
|
1847
|
+
t.key === "Enter" && (t.preventDefault(), this.#U()), t.key === "Escape" && (t.preventDefault(), this.#P()), t.stopPropagation();
|
|
1848
|
+
}));
|
|
1849
|
+
}
|
|
1850
|
+
// --- Button hold-to-repeat ---
|
|
1851
|
+
#c(t) {
|
|
1852
|
+
if (this.disabled) return;
|
|
1853
|
+
const e = this.step || 1;
|
|
1854
|
+
this.#B(t * e), this.#x(), this.#a = setTimeout(() => {
|
|
1855
|
+
let s = 150;
|
|
1856
|
+
const i = () => {
|
|
1857
|
+
this.#B(t * e), this.#$(), s = Math.max(40, s * 0.85), this.#u = setTimeout(i, s);
|
|
1858
|
+
};
|
|
1859
|
+
i();
|
|
1860
|
+
}, 400);
|
|
1861
|
+
}
|
|
1862
|
+
#p() {
|
|
1863
|
+
this.#a && (clearTimeout(this.#a), this.#a = null), this.#u && (clearTimeout(this.#u), this.#u = null);
|
|
1864
|
+
}
|
|
1865
|
+
// --- Drag helpers ---
|
|
1866
|
+
get #y() {
|
|
1867
|
+
const t = this.getAttribute("drag");
|
|
1868
|
+
return t === "x" || t === "y" || t === "none" ? t : this.getAttribute("arrows") === "stacked" ? "y" : "x";
|
|
1869
|
+
}
|
|
1870
|
+
#w(t, e) {
|
|
1871
|
+
return this.#y === "y" ? this.#l - e : t - this.#h;
|
|
1872
|
+
}
|
|
1873
|
+
#b(t, e) {
|
|
1874
|
+
return this.#y === "y" ? Math.abs(e - this.#l) : Math.abs(t - this.#h);
|
|
1875
|
+
}
|
|
1876
|
+
#S(t, e) {
|
|
1877
|
+
if (!this.#e) return;
|
|
1878
|
+
const s = t / e * 4, i = this.#y;
|
|
1879
|
+
this.#e.style.transform = i === "y" ? `translateY(${-s}px)` : `translateX(${s}px)`;
|
|
1880
|
+
}
|
|
1881
|
+
#M(t, e, s) {
|
|
1882
|
+
const i = this.#w(t, e), r = this.step || 1, a = s ? r * 10 : r, n = s ? S * 2 : S, h = Math.round(i / n), l = this.#d + h * a, c = i - h * n;
|
|
1883
|
+
this.#S(c, n);
|
|
1884
|
+
const d = this.hasAttribute("wrap") ? this.#V(l) : this.#T(l), u = this.#R(d);
|
|
1885
|
+
u !== this.value && (this.value = u, this.#v(), this.#$());
|
|
1886
|
+
}
|
|
1887
|
+
// --- Mouse drag ---
|
|
1888
|
+
#F = (t) => {
|
|
1889
|
+
this.disabled || this.#o || this.#y === "none" || (t.preventDefault(), this.#n = !0, this.#h = t.clientX, this.#l = t.clientY, this.#d = this.value, this.setAttribute("data-dragging", ""));
|
|
1890
|
+
};
|
|
1891
|
+
#W = (t) => {
|
|
1892
|
+
this.#n && this.#M(t.clientX, t.clientY, t.shiftKey);
|
|
1893
|
+
};
|
|
1894
|
+
#E = (t) => {
|
|
1895
|
+
if (!this.#n) return;
|
|
1896
|
+
const e = this.#b(t.clientX, t.clientY);
|
|
1897
|
+
this.#n = !1, this.removeAttribute("data-dragging"), this.#e && (this.#e.style.transform = ""), e < T && this.hasAttribute("editable") ? this.#_() : e >= T && this.#x();
|
|
1898
|
+
};
|
|
1899
|
+
// --- Touch drag ---
|
|
1900
|
+
#X = (t) => {
|
|
1901
|
+
this.disabled || this.#o || this.#y === "none" || (t.preventDefault(), this.#n = !0, this.#h = t.touches[0]?.clientX ?? 0, this.#l = t.touches[0]?.clientY ?? 0, this.#d = this.value, this.setAttribute("data-dragging", ""));
|
|
1902
|
+
};
|
|
1903
|
+
#G = (t) => {
|
|
1904
|
+
if (!this.#n) return;
|
|
1905
|
+
t.preventDefault();
|
|
1906
|
+
const e = t.touches[0];
|
|
1907
|
+
e && this.#M(e.clientX, e.clientY, !1);
|
|
1908
|
+
};
|
|
1909
|
+
#K = () => {
|
|
1910
|
+
this.#n && (this.#n = !1, this.removeAttribute("data-dragging"), this.#e && (this.#e.style.transform = ""), this.#x());
|
|
1911
|
+
};
|
|
1912
|
+
// --- Keyboard ---
|
|
1913
|
+
#q = (t) => {
|
|
1914
|
+
if (this.disabled || this.#o) return;
|
|
1915
|
+
const e = this.step || 1, s = e * 10;
|
|
1916
|
+
let i = 0;
|
|
1917
|
+
switch (t.key) {
|
|
1918
|
+
case "ArrowUp":
|
|
1919
|
+
case "ArrowRight":
|
|
1920
|
+
i = t.shiftKey ? s : e;
|
|
1921
|
+
break;
|
|
1922
|
+
case "ArrowDown":
|
|
1923
|
+
case "ArrowLeft":
|
|
1924
|
+
i = -(t.shiftKey ? s : e);
|
|
1925
|
+
break;
|
|
1926
|
+
case "PageUp":
|
|
1927
|
+
i = s;
|
|
1928
|
+
break;
|
|
1929
|
+
case "PageDown":
|
|
1930
|
+
i = -s;
|
|
1931
|
+
break;
|
|
1932
|
+
case "Home":
|
|
1933
|
+
i = this.min - this.value;
|
|
1934
|
+
break;
|
|
1935
|
+
case "End":
|
|
1936
|
+
i = this.max - this.value;
|
|
1937
|
+
break;
|
|
1938
|
+
case "Enter":
|
|
1939
|
+
this.hasAttribute("editable") && this.#_();
|
|
1940
|
+
return;
|
|
1941
|
+
default:
|
|
1942
|
+
this.hasAttribute("editable") && /^[0-9.\-]$/.test(t.key) && (this.#_(t.key), t.preventDefault());
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
t.preventDefault(), this.#B(i), this.#$(), this.#x();
|
|
1946
|
+
};
|
|
1947
|
+
// --- Wheel ---
|
|
1948
|
+
#J = (t) => {
|
|
1949
|
+
if (this.disabled || this.#o || !this.matches(":hover") && !this.contains(document.activeElement)) return;
|
|
1950
|
+
t.preventDefault();
|
|
1951
|
+
const e = this.step || 1, s = t.shiftKey ? e * 10 : e, i = t.deltaY < 0 ? s : -s;
|
|
1952
|
+
this.#B(i), this.#$(), this.#x();
|
|
1953
|
+
};
|
|
1954
|
+
// --- Edit mode ---
|
|
1955
|
+
#_(t) {
|
|
1956
|
+
this.disabled || this.#o || (this.#o = !0, this.state = "editing", this.#e && (this.#e.style.display = "none"), this.#i && (this.#i.style.display = "block", this.#i.value = t ?? this.#j(this.value), this.#i.focus(), t ? this.#i.setSelectionRange(1, 1) : this.#i.select()));
|
|
1957
|
+
}
|
|
1958
|
+
#U() {
|
|
1959
|
+
if (!this.#o) return;
|
|
1960
|
+
this.#o = !1, this.state = "";
|
|
1961
|
+
const t = parseFloat(this.#i?.value ?? "");
|
|
1962
|
+
if (!isNaN(t)) {
|
|
1963
|
+
const e = this.#T(t), s = this.#R(e);
|
|
1964
|
+
this.value = s, this.#x();
|
|
1965
|
+
}
|
|
1966
|
+
this.#e && (this.#e.style.display = ""), this.#i && (this.#i.style.display = "none"), this.#v(), this.#t?.focus();
|
|
1967
|
+
}
|
|
1968
|
+
#P() {
|
|
1969
|
+
this.#o && (this.#o = !1, this.state = "", this.#e && (this.#e.style.display = ""), this.#i && (this.#i.style.display = "none"), this.#t?.focus());
|
|
1970
|
+
}
|
|
1971
|
+
// --- Value management ---
|
|
1972
|
+
#B(t) {
|
|
1973
|
+
let e = this.value + t;
|
|
1974
|
+
this.hasAttribute("wrap") ? e = this.#V(e) : e = this.#T(e), e = this.#R(e), this.value = e, this.#v();
|
|
1975
|
+
}
|
|
1976
|
+
#T(t) {
|
|
1977
|
+
return Math.max(this.min, Math.min(this.max, t));
|
|
1978
|
+
}
|
|
1979
|
+
#V(t) {
|
|
1980
|
+
const e = this.step || 1, s = this.max - this.min + e;
|
|
1981
|
+
let i = t;
|
|
1982
|
+
for (; i > this.max; ) i -= s;
|
|
1983
|
+
for (; i < this.min; ) i += s;
|
|
1984
|
+
return i;
|
|
1985
|
+
}
|
|
1986
|
+
#R(t) {
|
|
1987
|
+
const e = this.step;
|
|
1988
|
+
if (e <= 0) return this.#T(t);
|
|
1989
|
+
const s = Math.round((t - this.min) / e) * e + this.min;
|
|
1990
|
+
return this.#T(s);
|
|
1991
|
+
}
|
|
1992
|
+
#j(t) {
|
|
1993
|
+
const e = this.step;
|
|
1994
|
+
if (e >= 1) return Math.round(t).toString();
|
|
1995
|
+
const s = Math.max(0, -Math.floor(Math.log10(e)));
|
|
1996
|
+
return t.toFixed(s);
|
|
1997
|
+
}
|
|
1998
|
+
#v() {
|
|
1999
|
+
this.#e && (this.#e.textContent = this.#j(this.value)), this.#Y();
|
|
2000
|
+
}
|
|
2001
|
+
#Y() {
|
|
2002
|
+
this.#t && (this.#t.setAttribute("aria-valuenow", String(this.value)), this.#t.setAttribute("aria-valuemin", String(this.min)), this.#t.setAttribute("aria-valuemax", String(this.max)));
|
|
2003
|
+
}
|
|
2004
|
+
#$() {
|
|
2005
|
+
this.emit("input", { value: this.value });
|
|
2006
|
+
}
|
|
2007
|
+
#x() {
|
|
2008
|
+
this.emit("change", { value: this.value });
|
|
2009
|
+
}
|
|
2010
|
+
// --- Public API ---
|
|
2011
|
+
get value() {
|
|
2012
|
+
return parseFloat(this.getAttribute("value") ?? "0");
|
|
2013
|
+
}
|
|
2014
|
+
set value(t) {
|
|
2015
|
+
this.setAttribute("value", String(t));
|
|
2016
|
+
}
|
|
2017
|
+
get min() {
|
|
2018
|
+
return parseFloat(this.getAttribute("min") ?? "0");
|
|
2019
|
+
}
|
|
2020
|
+
set min(t) {
|
|
2021
|
+
this.setAttribute("min", String(t));
|
|
2022
|
+
}
|
|
2023
|
+
get max() {
|
|
2024
|
+
return parseFloat(this.getAttribute("max") ?? "100");
|
|
2025
|
+
}
|
|
2026
|
+
set max(t) {
|
|
2027
|
+
this.setAttribute("max", String(t));
|
|
2028
|
+
}
|
|
2029
|
+
get step() {
|
|
2030
|
+
return parseFloat(this.getAttribute("step") ?? "1");
|
|
2031
|
+
}
|
|
2032
|
+
set step(t) {
|
|
2033
|
+
this.setAttribute("step", String(t));
|
|
2034
|
+
}
|
|
2035
|
+
get drag() {
|
|
2036
|
+
return this.#y;
|
|
2037
|
+
}
|
|
2038
|
+
set drag(t) {
|
|
2039
|
+
this.setAttribute("drag", t);
|
|
2040
|
+
}
|
|
2041
|
+
get disabled() {
|
|
2042
|
+
return this.hasAttribute("disabled");
|
|
2043
|
+
}
|
|
2044
|
+
set disabled(t) {
|
|
2045
|
+
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
2046
|
+
}
|
|
2047
|
+
attributeChangedCallback(t, e, s) {
|
|
2048
|
+
e !== s && t === "value" && this.#t && this.#v();
|
|
2049
|
+
}
|
|
2050
|
+
teardown() {
|
|
2051
|
+
this.#p();
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
customElements.define("ry-number-select", ht);
|
|
2055
|
+
function v(o) {
|
|
1765
2056
|
const t = o.h / 360, e = o.s / 100, s = o.v / 100;
|
|
1766
2057
|
let i = 0, r = 0, a = 0;
|
|
1767
|
-
const n = Math.floor(t * 6),
|
|
2058
|
+
const n = Math.floor(t * 6), h = t * 6 - n, l = s * (1 - e), c = s * (1 - h * e), d = s * (1 - (1 - h) * e);
|
|
1768
2059
|
switch (n % 6) {
|
|
1769
2060
|
case 0:
|
|
1770
|
-
i = s, r =
|
|
2061
|
+
i = s, r = d, a = l;
|
|
1771
2062
|
break;
|
|
1772
2063
|
case 1:
|
|
1773
|
-
i = c, r = s, a =
|
|
2064
|
+
i = c, r = s, a = l;
|
|
1774
2065
|
break;
|
|
1775
2066
|
case 2:
|
|
1776
|
-
i =
|
|
2067
|
+
i = l, r = s, a = d;
|
|
1777
2068
|
break;
|
|
1778
2069
|
case 3:
|
|
1779
|
-
i =
|
|
2070
|
+
i = l, r = c, a = s;
|
|
1780
2071
|
break;
|
|
1781
2072
|
case 4:
|
|
1782
|
-
i =
|
|
2073
|
+
i = d, r = l, a = s;
|
|
1783
2074
|
break;
|
|
1784
2075
|
case 5:
|
|
1785
|
-
i = s, r =
|
|
2076
|
+
i = s, r = l, a = c;
|
|
1786
2077
|
break;
|
|
1787
2078
|
}
|
|
1788
2079
|
return {
|
|
@@ -1791,10 +2082,10 @@ function b(o) {
|
|
|
1791
2082
|
b: Math.round(a * 255)
|
|
1792
2083
|
};
|
|
1793
2084
|
}
|
|
1794
|
-
function
|
|
2085
|
+
function $(o) {
|
|
1795
2086
|
const t = o.r / 255, e = o.g / 255, s = o.b / 255, i = Math.max(t, e, s), r = Math.min(t, e, s), a = i - r;
|
|
1796
2087
|
let n = 0;
|
|
1797
|
-
const
|
|
2088
|
+
const h = i === 0 ? 0 : a / i, l = i;
|
|
1798
2089
|
if (i !== r)
|
|
1799
2090
|
switch (i) {
|
|
1800
2091
|
case t:
|
|
@@ -1809,11 +2100,11 @@ function w(o) {
|
|
|
1809
2100
|
}
|
|
1810
2101
|
return {
|
|
1811
2102
|
h: Math.round(n * 360),
|
|
1812
|
-
s: Math.round(
|
|
1813
|
-
v: Math.round(
|
|
2103
|
+
s: Math.round(h * 100),
|
|
2104
|
+
v: Math.round(l * 100)
|
|
1814
2105
|
};
|
|
1815
2106
|
}
|
|
1816
|
-
function
|
|
2107
|
+
function L(o) {
|
|
1817
2108
|
const t = o.s / 100, e = o.v / 100, s = e * (1 - t / 2), i = s === 0 || s === 1 ? 0 : (e - s) / Math.min(s, 1 - s);
|
|
1818
2109
|
return {
|
|
1819
2110
|
h: o.h,
|
|
@@ -1821,7 +2112,7 @@ function M(o) {
|
|
|
1821
2112
|
l: Math.round(s * 100)
|
|
1822
2113
|
};
|
|
1823
2114
|
}
|
|
1824
|
-
function
|
|
2115
|
+
function lt(o) {
|
|
1825
2116
|
const t = o.s / 100, e = o.l / 100, s = e + t * Math.min(e, 1 - e), i = s === 0 ? 0 : 2 * (1 - e / s);
|
|
1826
2117
|
return {
|
|
1827
2118
|
h: o.h,
|
|
@@ -1829,11 +2120,11 @@ function st(o) {
|
|
|
1829
2120
|
v: Math.round(s * 100)
|
|
1830
2121
|
};
|
|
1831
2122
|
}
|
|
1832
|
-
function
|
|
2123
|
+
function I(o) {
|
|
1833
2124
|
const t = (e) => e.toString(16).padStart(2, "0");
|
|
1834
2125
|
return `#${t(o.r)}${t(o.g)}${t(o.b)}`;
|
|
1835
2126
|
}
|
|
1836
|
-
function
|
|
2127
|
+
function ct(o) {
|
|
1837
2128
|
const t = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);
|
|
1838
2129
|
if (!t) {
|
|
1839
2130
|
const e = /^#?([a-f\d])([a-f\d])([a-f\d])$/i.exec(o);
|
|
@@ -1849,7 +2140,7 @@ function it(o) {
|
|
|
1849
2140
|
b: parseInt(t[3], 16)
|
|
1850
2141
|
};
|
|
1851
2142
|
}
|
|
1852
|
-
function
|
|
2143
|
+
function w(o) {
|
|
1853
2144
|
const t = o.trim().toLowerCase();
|
|
1854
2145
|
if (t.startsWith("#")) {
|
|
1855
2146
|
const i = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);
|
|
@@ -1859,10 +2150,10 @@ function m(o) {
|
|
|
1859
2150
|
g: parseInt(i[2], 16),
|
|
1860
2151
|
b: parseInt(i[3], 16)
|
|
1861
2152
|
}, n = parseInt(i[4], 16) / 255;
|
|
1862
|
-
return { hsv:
|
|
2153
|
+
return { hsv: $(a), alpha: Math.round(n * 100) };
|
|
1863
2154
|
}
|
|
1864
|
-
const r =
|
|
1865
|
-
return r ? { hsv:
|
|
2155
|
+
const r = ct(t);
|
|
2156
|
+
return r ? { hsv: $(r), alpha: 100 } : null;
|
|
1866
2157
|
}
|
|
1867
2158
|
const e = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/.exec(t);
|
|
1868
2159
|
if (e) {
|
|
@@ -1871,7 +2162,7 @@ function m(o) {
|
|
|
1871
2162
|
g: parseInt(e[2], 10),
|
|
1872
2163
|
b: parseInt(e[3], 10)
|
|
1873
2164
|
}, r = e[4] ? parseFloat(e[4]) * 100 : 100;
|
|
1874
|
-
return { hsv:
|
|
2165
|
+
return { hsv: $(i), alpha: r };
|
|
1875
2166
|
}
|
|
1876
2167
|
const s = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*([\d.]+))?\s*\)$/.exec(t);
|
|
1877
2168
|
if (s) {
|
|
@@ -1880,33 +2171,33 @@ function m(o) {
|
|
|
1880
2171
|
s: parseFloat(s[2]),
|
|
1881
2172
|
l: parseFloat(s[3])
|
|
1882
2173
|
}, r = s[4] ? parseFloat(s[4]) * 100 : 100;
|
|
1883
|
-
return { hsv:
|
|
2174
|
+
return { hsv: lt(i), alpha: r };
|
|
1884
2175
|
}
|
|
1885
2176
|
return null;
|
|
1886
2177
|
}
|
|
1887
|
-
class
|
|
2178
|
+
class dt extends p {
|
|
1888
2179
|
#t = 0;
|
|
1889
2180
|
#e = 100;
|
|
1890
2181
|
#i = 100;
|
|
1891
2182
|
#s = 100;
|
|
1892
2183
|
#r = !1;
|
|
1893
2184
|
#n = !1;
|
|
1894
|
-
#
|
|
1895
|
-
#
|
|
1896
|
-
#
|
|
2185
|
+
#h = !1;
|
|
2186
|
+
#l = null;
|
|
2187
|
+
#d = null;
|
|
2188
|
+
#o = null;
|
|
1897
2189
|
#a = null;
|
|
1898
2190
|
#u = null;
|
|
1899
|
-
#b = null;
|
|
1900
|
-
#f = null;
|
|
1901
2191
|
#g = null;
|
|
1902
|
-
#
|
|
1903
|
-
#
|
|
1904
|
-
#
|
|
2192
|
+
#m = null;
|
|
2193
|
+
#f = null;
|
|
2194
|
+
#A = null;
|
|
2195
|
+
#c = null;
|
|
1905
2196
|
static observedAttributes = ["value", "format", "opacity", "disabled", "swatches", "inline"];
|
|
1906
2197
|
setup() {
|
|
1907
|
-
this.#
|
|
2198
|
+
this.#p(), this.#y(), this.#w(), this.#v();
|
|
1908
2199
|
}
|
|
1909
|
-
#
|
|
2200
|
+
#p() {
|
|
1910
2201
|
const t = this.hasAttribute("inline"), e = this.hasAttribute("opacity"), s = this.getAttribute("swatches");
|
|
1911
2202
|
let i = `
|
|
1912
2203
|
<div data-ry-target="grid" class="ry-color-picker__grid">
|
|
@@ -1946,57 +2237,57 @@ class rt extends d {
|
|
|
1946
2237
|
<span data-ry-target="trigger-color" class="ry-color-picker__trigger-color"></span>
|
|
1947
2238
|
</button>
|
|
1948
2239
|
<div data-ry-target="panel" class="ry-color-picker__panel">${i}</div>
|
|
1949
|
-
`, this.#
|
|
2240
|
+
`, this.#l = this.$('[data-ry-target="trigger"]'), this.#d = this.$('[data-ry-target="panel"]'), this.#o = this.$('[data-ry-target="grid"]'), this.#a = this.$('[data-ry-target="grid-handle"]'), this.#u = this.$('[data-ry-target="hue-slider"]'), this.#g = this.$('[data-ry-target="hue-handle"]'), this.#m = this.$('[data-ry-target="alpha-slider"]'), this.#f = this.$('[data-ry-target="alpha-handle"]'), this.#A = this.$('[data-ry-target="preview"]'), this.#c = this.$('[data-ry-target="input"]');
|
|
1950
2241
|
}
|
|
1951
|
-
#
|
|
1952
|
-
this.#
|
|
2242
|
+
#y() {
|
|
2243
|
+
this.#l && this.on(this.#l, "click", this.#b), this.on(document, "click", this.#S), this.on(document, "keydown", this.#M), this.#o && this.on(this.#o, "pointerdown", this.#W), this.#a && this.on(this.#a, "keydown", this.#X), this.#u && this.on(this.#u, "pointerdown", this.#G), this.#g && this.on(this.#g, "keydown", this.#q), this.#m && this.on(this.#m, "pointerdown", this.#J), this.#f && this.on(this.#f, "keydown", this.#U), this.on(document, "pointermove", this.#P), this.on(document, "pointerup", this.#B), this.#c && (this.on(this.#c, "change", this.#T), this.on(this.#c, "keydown", this.#V));
|
|
1953
2244
|
const t = this.$('[data-ry-target="format-toggle"]');
|
|
1954
|
-
t && this.on(t, "click", this.#
|
|
2245
|
+
t && this.on(t, "click", this.#R);
|
|
1955
2246
|
const e = this.$('[data-ry-target="swatches"]');
|
|
1956
|
-
e && this.on(e, "click", this.#
|
|
2247
|
+
e && this.on(e, "click", this.#j);
|
|
1957
2248
|
}
|
|
1958
|
-
#
|
|
2249
|
+
#w() {
|
|
1959
2250
|
const t = this.getAttribute("value");
|
|
1960
2251
|
if (t) {
|
|
1961
|
-
const e =
|
|
2252
|
+
const e = w(t);
|
|
1962
2253
|
e && (this.#t = e.hsv.h, this.#e = e.hsv.s, this.#i = e.hsv.v, this.#s = e.alpha);
|
|
1963
2254
|
}
|
|
1964
2255
|
}
|
|
1965
2256
|
// ───────────────────────────────────────────────────────────────────────────
|
|
1966
2257
|
// Dropdown handlers
|
|
1967
2258
|
// ───────────────────────────────────────────────────────────────────────────
|
|
1968
|
-
#
|
|
2259
|
+
#b = () => {
|
|
1969
2260
|
this.disabled || (this.state === "open" ? this.close() : this.open());
|
|
1970
2261
|
};
|
|
1971
|
-
#
|
|
2262
|
+
#S = (t) => {
|
|
1972
2263
|
this.state === "open" && (this.contains(t.target) || this.close());
|
|
1973
2264
|
};
|
|
1974
|
-
#
|
|
1975
|
-
t.key === "Escape" && this.state === "open" && (this.close(), this.#
|
|
2265
|
+
#M = (t) => {
|
|
2266
|
+
t.key === "Escape" && this.state === "open" && (this.close(), this.#l?.focus());
|
|
1976
2267
|
};
|
|
1977
2268
|
open() {
|
|
1978
|
-
this.hasAttribute("inline") || (this.#
|
|
2269
|
+
this.hasAttribute("inline") || (this.#F(), this.state = "open");
|
|
1979
2270
|
}
|
|
1980
2271
|
close() {
|
|
1981
2272
|
this.hasAttribute("inline") || (this.state = "closed", this.removeAttribute("data-ry-position"));
|
|
1982
2273
|
}
|
|
1983
|
-
#
|
|
1984
|
-
if (!this.#
|
|
1985
|
-
const t = this.#
|
|
2274
|
+
#F() {
|
|
2275
|
+
if (!this.#d || !this.#l) return;
|
|
2276
|
+
const t = this.#l.getBoundingClientRect(), e = 320, i = window.innerHeight - t.bottom, r = t.top;
|
|
1986
2277
|
i < e && r > i ? this.setAttribute("data-ry-position", "top") : this.setAttribute("data-ry-position", "bottom");
|
|
1987
2278
|
}
|
|
1988
2279
|
// ───────────────────────────────────────────────────────────────────────────
|
|
1989
2280
|
// Grid handlers
|
|
1990
2281
|
// ───────────────────────────────────────────────────────────────────────────
|
|
1991
|
-
#
|
|
1992
|
-
this.disabled || (t.preventDefault(), this.#r = !0, this.#
|
|
2282
|
+
#W = (t) => {
|
|
2283
|
+
this.disabled || (t.preventDefault(), this.#r = !0, this.#a?.focus(), this.#E(t));
|
|
1993
2284
|
};
|
|
1994
2285
|
#E(t) {
|
|
1995
|
-
if (!this.#
|
|
1996
|
-
const e = this.#
|
|
1997
|
-
this.#e = Math.round(s * 100), this.#i = Math.round((1 - i) * 100), this.#
|
|
2286
|
+
if (!this.#o) return;
|
|
2287
|
+
const e = this.#o.getBoundingClientRect(), s = Math.max(0, Math.min(1, (t.clientX - e.left) / e.width)), i = Math.max(0, Math.min(1, (t.clientY - e.top) / e.height));
|
|
2288
|
+
this.#e = Math.round(s * 100), this.#i = Math.round((1 - i) * 100), this.#v(), this.#L();
|
|
1998
2289
|
}
|
|
1999
|
-
#
|
|
2290
|
+
#X = (t) => {
|
|
2000
2291
|
if (this.disabled) return;
|
|
2001
2292
|
const e = t.shiftKey ? 10 : 1;
|
|
2002
2293
|
let s = !1;
|
|
@@ -2014,20 +2305,20 @@ class rt extends d {
|
|
|
2014
2305
|
this.#i = Math.max(0, this.#i - e), s = !0;
|
|
2015
2306
|
break;
|
|
2016
2307
|
}
|
|
2017
|
-
s && (t.preventDefault(), this.#
|
|
2308
|
+
s && (t.preventDefault(), this.#v(), this.#L(), this.#k());
|
|
2018
2309
|
};
|
|
2019
2310
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2020
2311
|
// Hue handlers
|
|
2021
2312
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2022
|
-
#
|
|
2023
|
-
this.disabled || (t.preventDefault(), this.#n = !0, this.#
|
|
2313
|
+
#G = (t) => {
|
|
2314
|
+
this.disabled || (t.preventDefault(), this.#n = !0, this.#g?.focus(), this.#K(t));
|
|
2024
2315
|
};
|
|
2025
|
-
#
|
|
2026
|
-
if (!this.#
|
|
2027
|
-
const e = this.#
|
|
2028
|
-
this.#t = Math.round(s * 360), this.#
|
|
2316
|
+
#K(t) {
|
|
2317
|
+
if (!this.#u) return;
|
|
2318
|
+
const e = this.#u.getBoundingClientRect(), s = Math.max(0, Math.min(1, (t.clientX - e.left) / e.width));
|
|
2319
|
+
this.#t = Math.round(s * 360), this.#v(), this.#L();
|
|
2029
2320
|
}
|
|
2030
|
-
#
|
|
2321
|
+
#q = (t) => {
|
|
2031
2322
|
if (this.disabled) return;
|
|
2032
2323
|
const e = t.shiftKey ? 10 : 1;
|
|
2033
2324
|
let s = !1;
|
|
@@ -2041,20 +2332,20 @@ class rt extends d {
|
|
|
2041
2332
|
this.#t = (this.#t - e + 360) % 360, s = !0;
|
|
2042
2333
|
break;
|
|
2043
2334
|
}
|
|
2044
|
-
s && (t.preventDefault(), this.#
|
|
2335
|
+
s && (t.preventDefault(), this.#v(), this.#L(), this.#k());
|
|
2045
2336
|
};
|
|
2046
2337
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2047
2338
|
// Alpha handlers
|
|
2048
2339
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2049
|
-
#
|
|
2050
|
-
this.disabled || (t.preventDefault(), this.#
|
|
2340
|
+
#J = (t) => {
|
|
2341
|
+
this.disabled || (t.preventDefault(), this.#h = !0, this.#f?.focus(), this.#_(t));
|
|
2051
2342
|
};
|
|
2052
|
-
#
|
|
2053
|
-
if (!this.#
|
|
2054
|
-
const e = this.#
|
|
2055
|
-
this.#s = Math.round(s * 100), this.#
|
|
2343
|
+
#_(t) {
|
|
2344
|
+
if (!this.#m) return;
|
|
2345
|
+
const e = this.#m.getBoundingClientRect(), s = Math.max(0, Math.min(1, (t.clientX - e.left) / e.width));
|
|
2346
|
+
this.#s = Math.round(s * 100), this.#v(), this.#L();
|
|
2056
2347
|
}
|
|
2057
|
-
#
|
|
2348
|
+
#U = (t) => {
|
|
2058
2349
|
if (this.disabled) return;
|
|
2059
2350
|
const e = t.shiftKey ? 10 : 1;
|
|
2060
2351
|
let s = !1;
|
|
@@ -2068,99 +2359,99 @@ class rt extends d {
|
|
|
2068
2359
|
this.#s = Math.max(0, this.#s - e), s = !0;
|
|
2069
2360
|
break;
|
|
2070
2361
|
}
|
|
2071
|
-
s && (t.preventDefault(), this.#
|
|
2362
|
+
s && (t.preventDefault(), this.#v(), this.#L(), this.#k());
|
|
2072
2363
|
};
|
|
2073
2364
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2074
2365
|
// Pointer move/up
|
|
2075
2366
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2076
|
-
#
|
|
2077
|
-
this.#r ? this.#E(t) : this.#n ? this.#
|
|
2367
|
+
#P = (t) => {
|
|
2368
|
+
this.#r ? this.#E(t) : this.#n ? this.#K(t) : this.#h && this.#_(t);
|
|
2078
2369
|
};
|
|
2079
|
-
#
|
|
2080
|
-
(this.#r || this.#n || this.#
|
|
2370
|
+
#B = () => {
|
|
2371
|
+
(this.#r || this.#n || this.#h) && (this.#r = !1, this.#n = !1, this.#h = !1, this.#k());
|
|
2081
2372
|
};
|
|
2082
2373
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2083
2374
|
// Input handlers
|
|
2084
2375
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2085
2376
|
#T = () => {
|
|
2086
|
-
if (!this.#
|
|
2087
|
-
const t =
|
|
2088
|
-
t ? (this.#t = t.hsv.h, this.#e = t.hsv.s, this.#i = t.hsv.v, this.hasAttribute("opacity") && (this.#s = t.alpha), this.#
|
|
2377
|
+
if (!this.#c) return;
|
|
2378
|
+
const t = w(this.#c.value);
|
|
2379
|
+
t ? (this.#t = t.hsv.h, this.#e = t.hsv.s, this.#i = t.hsv.v, this.hasAttribute("opacity") && (this.#s = t.alpha), this.#v(), this.#k()) : this.#z();
|
|
2089
2380
|
};
|
|
2090
|
-
#
|
|
2381
|
+
#V = (t) => {
|
|
2091
2382
|
t.key === "Enter" && (t.preventDefault(), this.#T());
|
|
2092
2383
|
};
|
|
2093
2384
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2094
2385
|
// Format toggle
|
|
2095
2386
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2096
|
-
#
|
|
2387
|
+
#R = () => {
|
|
2097
2388
|
const t = ["hex", "rgb", "hsl"], e = this.format, s = t.indexOf(e), i = t[(s + 1) % t.length];
|
|
2098
2389
|
this.format = i;
|
|
2099
2390
|
const r = this.$('[data-ry-target="format-toggle"]');
|
|
2100
|
-
r && (r.textContent = i.toUpperCase()), this.#
|
|
2391
|
+
r && (r.textContent = i.toUpperCase()), this.#z();
|
|
2101
2392
|
};
|
|
2102
2393
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2103
2394
|
// Swatches
|
|
2104
2395
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2105
|
-
#
|
|
2396
|
+
#j = (t) => {
|
|
2106
2397
|
const e = t.target;
|
|
2107
2398
|
if (e.classList.contains("ry-color-picker__swatch")) {
|
|
2108
2399
|
const s = e.dataset.color;
|
|
2109
2400
|
if (s) {
|
|
2110
|
-
const i =
|
|
2111
|
-
i && (this.#t = i.hsv.h, this.#e = i.hsv.s, this.#i = i.hsv.v, this.hasAttribute("opacity") && (this.#s = i.alpha), this.#
|
|
2401
|
+
const i = w(s);
|
|
2402
|
+
i && (this.#t = i.hsv.h, this.#e = i.hsv.s, this.#i = i.hsv.v, this.hasAttribute("opacity") && (this.#s = i.alpha), this.#v(), this.#L(), this.#k());
|
|
2112
2403
|
}
|
|
2113
2404
|
}
|
|
2114
2405
|
};
|
|
2115
2406
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2116
2407
|
// Update methods
|
|
2117
2408
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2118
|
-
#
|
|
2119
|
-
this.#
|
|
2409
|
+
#v() {
|
|
2410
|
+
this.#Y(), this.#$(), this.#x(), this.#H(), this.#O(), this.#z(), this.#Z();
|
|
2120
2411
|
}
|
|
2121
|
-
#
|
|
2412
|
+
#Y() {
|
|
2122
2413
|
const t = this.$('[data-ry-target="trigger-color"]');
|
|
2123
2414
|
if (t) {
|
|
2124
|
-
const e =
|
|
2415
|
+
const e = v({ h: this.#t, s: this.#e, v: this.#i }), s = this.hasAttribute("opacity") ? this.#s / 100 : 1;
|
|
2125
2416
|
t.style.backgroundColor = `rgba(${e.r}, ${e.g}, ${e.b}, ${s})`;
|
|
2126
2417
|
}
|
|
2127
2418
|
}
|
|
2128
|
-
|
|
2129
|
-
if (this.#
|
|
2130
|
-
const t =
|
|
2131
|
-
this.#
|
|
2419
|
+
#$() {
|
|
2420
|
+
if (this.#o) {
|
|
2421
|
+
const t = v({ h: this.#t, s: 100, v: 100 });
|
|
2422
|
+
this.#o.style.setProperty("--grid-hue-color", `rgb(${t.r}, ${t.g}, ${t.b})`);
|
|
2132
2423
|
}
|
|
2133
|
-
this.#
|
|
2424
|
+
this.#a && (this.#a.style.left = `${this.#e}%`, this.#a.style.top = `${100 - this.#i}%`);
|
|
2134
2425
|
}
|
|
2135
|
-
#
|
|
2136
|
-
this.#
|
|
2426
|
+
#x() {
|
|
2427
|
+
this.#g && (this.#g.style.left = `${this.#t / 360 * 100}%`);
|
|
2137
2428
|
}
|
|
2138
|
-
#
|
|
2139
|
-
if (this.#
|
|
2140
|
-
const t =
|
|
2141
|
-
this.#
|
|
2429
|
+
#H() {
|
|
2430
|
+
if (this.#m) {
|
|
2431
|
+
const t = v({ h: this.#t, s: this.#e, v: this.#i });
|
|
2432
|
+
this.#m.style.setProperty("--alpha-color", `rgb(${t.r}, ${t.g}, ${t.b})`);
|
|
2142
2433
|
}
|
|
2143
|
-
this.#
|
|
2434
|
+
this.#f && (this.#f.style.left = `${this.#s}%`);
|
|
2144
2435
|
}
|
|
2145
|
-
#
|
|
2436
|
+
#O() {
|
|
2146
2437
|
const t = this.$('[data-ry-target="preview-color"]');
|
|
2147
2438
|
if (t) {
|
|
2148
|
-
const e =
|
|
2439
|
+
const e = v({ h: this.#t, s: this.#e, v: this.#i }), s = this.hasAttribute("opacity") ? this.#s / 100 : 1;
|
|
2149
2440
|
t.style.backgroundColor = `rgba(${e.r}, ${e.g}, ${e.b}, ${s})`;
|
|
2150
2441
|
}
|
|
2151
2442
|
}
|
|
2152
|
-
#
|
|
2153
|
-
this.#
|
|
2443
|
+
#z() {
|
|
2444
|
+
this.#c && (this.#c.value = this.#N());
|
|
2154
2445
|
}
|
|
2155
|
-
#
|
|
2156
|
-
const t = this.#
|
|
2446
|
+
#Z() {
|
|
2447
|
+
const t = this.#N();
|
|
2157
2448
|
this.getAttribute("value") !== t && this.setAttribute("value", t);
|
|
2158
2449
|
}
|
|
2159
|
-
#
|
|
2160
|
-
const t = this.format, e =
|
|
2450
|
+
#N() {
|
|
2451
|
+
const t = this.format, e = v({ h: this.#t, s: this.#e, v: this.#i }), s = this.hasAttribute("opacity");
|
|
2161
2452
|
switch (t) {
|
|
2162
2453
|
case "hex": {
|
|
2163
|
-
const i =
|
|
2454
|
+
const i = I(e);
|
|
2164
2455
|
if (s && this.#s < 100) {
|
|
2165
2456
|
const r = Math.round(this.#s / 100 * 255).toString(16).padStart(2, "0");
|
|
2166
2457
|
return i + r;
|
|
@@ -2170,40 +2461,40 @@ class rt extends d {
|
|
|
2170
2461
|
case "rgb":
|
|
2171
2462
|
return s ? `rgba(${e.r}, ${e.g}, ${e.b}, ${(this.#s / 100).toFixed(2)})` : `rgb(${e.r}, ${e.g}, ${e.b})`;
|
|
2172
2463
|
case "hsl": {
|
|
2173
|
-
const i =
|
|
2464
|
+
const i = L({ h: this.#t, s: this.#e, v: this.#i });
|
|
2174
2465
|
return s ? `hsla(${i.h}, ${i.s}%, ${i.l}%, ${(this.#s / 100).toFixed(2)})` : `hsl(${i.h}, ${i.s}%, ${i.l}%)`;
|
|
2175
2466
|
}
|
|
2176
2467
|
default:
|
|
2177
|
-
return
|
|
2468
|
+
return I(e);
|
|
2178
2469
|
}
|
|
2179
2470
|
}
|
|
2180
2471
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2181
2472
|
// Events
|
|
2182
2473
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2183
|
-
#
|
|
2474
|
+
#L() {
|
|
2184
2475
|
this.emit("input", { value: this.value, hsv: this.hsv, rgb: this.rgb });
|
|
2185
2476
|
}
|
|
2186
|
-
|
|
2477
|
+
#k() {
|
|
2187
2478
|
this.emit("change", { value: this.value, hsv: this.hsv, rgb: this.rgb });
|
|
2188
2479
|
}
|
|
2189
2480
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2190
2481
|
// Attribute changed
|
|
2191
2482
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2192
2483
|
attributeChangedCallback(t, e, s) {
|
|
2193
|
-
if (e !== s && t === "value" && this.#
|
|
2194
|
-
const i =
|
|
2195
|
-
i && (this.#t = i.hsv.h, this.#e = i.hsv.s, this.#i = i.hsv.v, this.hasAttribute("opacity") && (this.#s = i.alpha), this.#
|
|
2484
|
+
if (e !== s && t === "value" && this.#o && s) {
|
|
2485
|
+
const i = w(s);
|
|
2486
|
+
i && (this.#t = i.hsv.h, this.#e = i.hsv.s, this.#i = i.hsv.v, this.hasAttribute("opacity") && (this.#s = i.alpha), this.#Y(), this.#$(), this.#x(), this.#H(), this.#O());
|
|
2196
2487
|
}
|
|
2197
2488
|
}
|
|
2198
2489
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2199
2490
|
// Public API
|
|
2200
2491
|
// ───────────────────────────────────────────────────────────────────────────
|
|
2201
2492
|
get value() {
|
|
2202
|
-
return this.#
|
|
2493
|
+
return this.#N();
|
|
2203
2494
|
}
|
|
2204
2495
|
set value(t) {
|
|
2205
|
-
const e =
|
|
2206
|
-
e && (this.#t = e.hsv.h, this.#e = e.hsv.s, this.#i = e.hsv.v, this.hasAttribute("opacity") && (this.#s = e.alpha), this.#
|
|
2496
|
+
const e = w(t);
|
|
2497
|
+
e && (this.#t = e.hsv.h, this.#e = e.hsv.s, this.#i = e.hsv.v, this.hasAttribute("opacity") && (this.#s = e.alpha), this.#v());
|
|
2207
2498
|
}
|
|
2208
2499
|
get format() {
|
|
2209
2500
|
return this.getAttribute("format") || "hex";
|
|
@@ -2221,39 +2512,39 @@ class rt extends d {
|
|
|
2221
2512
|
return { h: this.#t, s: this.#e, v: this.#i };
|
|
2222
2513
|
}
|
|
2223
2514
|
get rgb() {
|
|
2224
|
-
return
|
|
2515
|
+
return v(this.hsv);
|
|
2225
2516
|
}
|
|
2226
2517
|
get hsl() {
|
|
2227
|
-
return
|
|
2518
|
+
return L(this.hsv);
|
|
2228
2519
|
}
|
|
2229
2520
|
get alpha() {
|
|
2230
2521
|
return this.#s;
|
|
2231
2522
|
}
|
|
2232
2523
|
set alpha(t) {
|
|
2233
|
-
this.#s = Math.max(0, Math.min(100, t)), this.#
|
|
2524
|
+
this.#s = Math.max(0, Math.min(100, t)), this.#v();
|
|
2234
2525
|
}
|
|
2235
2526
|
/** Set color from any valid color string */
|
|
2236
2527
|
setColor(t) {
|
|
2237
|
-
const e =
|
|
2238
|
-
return e ? (this.#t = e.hsv.h, this.#e = e.hsv.s, this.#i = e.hsv.v, this.hasAttribute("opacity") && (this.#s = e.alpha), this.#
|
|
2528
|
+
const e = w(t);
|
|
2529
|
+
return e ? (this.#t = e.hsv.h, this.#e = e.hsv.s, this.#i = e.hsv.v, this.hasAttribute("opacity") && (this.#s = e.alpha), this.#v(), !0) : !1;
|
|
2239
2530
|
}
|
|
2240
2531
|
/** Get color in specific format */
|
|
2241
2532
|
getFormattedValue(t) {
|
|
2242
2533
|
const e = this.format;
|
|
2243
2534
|
this.format = t;
|
|
2244
|
-
const s = this.#
|
|
2535
|
+
const s = this.#N();
|
|
2245
2536
|
return this.format = e, s;
|
|
2246
2537
|
}
|
|
2247
2538
|
}
|
|
2248
|
-
customElements.define("ry-color-picker",
|
|
2249
|
-
class
|
|
2539
|
+
customElements.define("ry-color-picker", dt);
|
|
2540
|
+
class ut extends p {
|
|
2250
2541
|
#t = null;
|
|
2251
2542
|
#e = null;
|
|
2252
2543
|
#i = null;
|
|
2253
2544
|
#s = null;
|
|
2254
2545
|
static observedAttributes = ["value", "format", "opacity", "disabled", "placeholder"];
|
|
2255
2546
|
setup() {
|
|
2256
|
-
this.#r(), this.#n(), this.#
|
|
2547
|
+
this.#r(), this.#n(), this.#y(), this.state = "closed";
|
|
2257
2548
|
}
|
|
2258
2549
|
#r() {
|
|
2259
2550
|
const t = this.hasAttribute("opacity"), e = this.getAttribute("format") || "hex", s = this.getAttribute("value") || "#000000", i = this.getAttribute("placeholder") || "#000000";
|
|
@@ -2285,15 +2576,15 @@ class at extends d {
|
|
|
2285
2576
|
`, this.#t = this.$('[data-ry-target="swatch"]'), this.#e = this.$('[data-ry-target="input"]'), this.#i = this.$('[data-ry-target="panel"]'), this.#s = this.$('[data-ry-target="picker"]');
|
|
2286
2577
|
}
|
|
2287
2578
|
#n() {
|
|
2288
|
-
this.#t && this.on(this.#t, "click", this.#
|
|
2579
|
+
this.#t && this.on(this.#t, "click", this.#h), this.#e && (this.on(this.#e, "input", this.#d), this.on(this.#e, "keydown", this.#u), this.on(this.#e, "focus", this.#l)), this.#s && (this.on(this.#s, "ry:input", this.#g), this.on(this.#s, "ry:change", this.#m)), this.on(document, "click", this.#f), this.on(document, "keydown", this.#A);
|
|
2289
2580
|
}
|
|
2290
|
-
#
|
|
2581
|
+
#h = () => {
|
|
2291
2582
|
this.disabled || (this.state === "open" ? this.close() : this.open());
|
|
2292
2583
|
};
|
|
2293
|
-
#
|
|
2584
|
+
#l = () => {
|
|
2294
2585
|
this.disabled || this.open();
|
|
2295
2586
|
};
|
|
2296
|
-
#
|
|
2587
|
+
#d = () => {
|
|
2297
2588
|
if (!this.#e || !this.#s) return;
|
|
2298
2589
|
let t = this.#e.value;
|
|
2299
2590
|
const e = this.#e.selectionStart ?? t.length, r = "#" + t.replace(/[^#a-fA-F0-9]/g, "").replace(/#/g, "").slice(0, 6);
|
|
@@ -2302,10 +2593,10 @@ class at extends d {
|
|
|
2302
2593
|
const n = Math.min(e, r.length);
|
|
2303
2594
|
this.#e.setSelectionRange(n, n);
|
|
2304
2595
|
}
|
|
2305
|
-
const a = this.#
|
|
2306
|
-
a && (this.#s.setColor(a), this.#
|
|
2596
|
+
const a = this.#o(r);
|
|
2597
|
+
a && (this.#s.setColor(a), this.#p(), this.#a(r) && this.#w(), this.emit("input", { value: this.value }));
|
|
2307
2598
|
};
|
|
2308
|
-
#
|
|
2599
|
+
#o(t) {
|
|
2309
2600
|
let e = t;
|
|
2310
2601
|
e.startsWith("#") || (e = "#" + e);
|
|
2311
2602
|
const s = e.slice(1);
|
|
@@ -2319,67 +2610,67 @@ class at extends d {
|
|
|
2319
2610
|
}
|
|
2320
2611
|
return "#" + s.padEnd(6, "0");
|
|
2321
2612
|
}
|
|
2322
|
-
#
|
|
2613
|
+
#a(t) {
|
|
2323
2614
|
return !!(/^#[a-fA-F0-9]{6}$/.test(t) || /^#[a-fA-F0-9]{3}$/.test(t));
|
|
2324
2615
|
}
|
|
2325
|
-
#
|
|
2326
|
-
t.key === "Enter" && (t.preventDefault(), this.#
|
|
2327
|
-
};
|
|
2328
|
-
#f = () => {
|
|
2329
|
-
!this.#s || !this.#e || (document.activeElement !== this.#e && (this.#e.value = this.#s.value), this.#d(), this.#v(), this.emit("input", { value: this.value }));
|
|
2616
|
+
#u = (t) => {
|
|
2617
|
+
t.key === "Enter" && (t.preventDefault(), this.#d(), this.emit("change", { value: this.value }));
|
|
2330
2618
|
};
|
|
2331
2619
|
#g = () => {
|
|
2620
|
+
!this.#s || !this.#e || (document.activeElement !== this.#e && (this.#e.value = this.#s.value), this.#p(), this.#w(), this.emit("input", { value: this.value }));
|
|
2621
|
+
};
|
|
2622
|
+
#m = () => {
|
|
2332
2623
|
this.emit("change", { value: this.value });
|
|
2333
2624
|
};
|
|
2334
|
-
#
|
|
2625
|
+
#f = (t) => {
|
|
2335
2626
|
this.state === "open" && (this.contains(t.target) || this.close());
|
|
2336
2627
|
};
|
|
2337
|
-
#
|
|
2628
|
+
#A = (t) => {
|
|
2338
2629
|
t.key === "Escape" && this.state === "open" && (this.close(), this.#t?.focus());
|
|
2339
2630
|
};
|
|
2340
2631
|
open() {
|
|
2341
|
-
this.#
|
|
2632
|
+
this.#c(), this.state = "open";
|
|
2342
2633
|
}
|
|
2343
2634
|
close() {
|
|
2344
2635
|
this.state = "closed", this.removeAttribute("data-ry-position");
|
|
2345
2636
|
}
|
|
2346
|
-
#
|
|
2637
|
+
#c() {
|
|
2347
2638
|
if (!this.#i) return;
|
|
2348
2639
|
const t = this.getBoundingClientRect(), e = 280, i = window.innerHeight - t.bottom, r = t.top;
|
|
2349
2640
|
i < e && r > i ? this.setAttribute("data-ry-position", "top") : this.setAttribute("data-ry-position", "bottom");
|
|
2350
2641
|
}
|
|
2351
|
-
#
|
|
2642
|
+
#p() {
|
|
2352
2643
|
const t = this.$('[data-ry-target="swatch-color"]');
|
|
2353
2644
|
if (t && this.#s) {
|
|
2354
2645
|
const e = this.#s.rgb, s = this.hasAttribute("opacity") ? this.#s.alpha / 100 : 1;
|
|
2355
2646
|
t.style.backgroundColor = `rgba(${e.r}, ${e.g}, ${e.b}, ${s})`;
|
|
2356
2647
|
}
|
|
2357
2648
|
}
|
|
2358
|
-
#
|
|
2649
|
+
#y() {
|
|
2359
2650
|
const t = this.getAttribute("value") || "#000000";
|
|
2360
2651
|
if (this.#s) {
|
|
2361
2652
|
if (this.#s.setColor(t), this.#e) {
|
|
2362
2653
|
const e = this.#s.value;
|
|
2363
2654
|
this.#e.value = e.startsWith("#") ? e : "#" + e;
|
|
2364
2655
|
}
|
|
2365
|
-
this.#
|
|
2656
|
+
this.#p();
|
|
2366
2657
|
}
|
|
2367
2658
|
}
|
|
2368
|
-
#
|
|
2659
|
+
#w() {
|
|
2369
2660
|
if (this.#s) {
|
|
2370
2661
|
const t = this.#s.value;
|
|
2371
2662
|
this.getAttribute("value") !== t && this.setAttribute("value", t);
|
|
2372
2663
|
}
|
|
2373
2664
|
}
|
|
2374
2665
|
attributeChangedCallback(t, e, s) {
|
|
2375
|
-
e !== s && (t === "value" && this.#s && this.#e && s && (this.#s.setColor(s), document.activeElement !== this.#e && (this.#e.value = this.#s.value), this.#
|
|
2666
|
+
e !== s && (t === "value" && this.#s && this.#e && s && (this.#s.setColor(s), document.activeElement !== this.#e && (this.#e.value = this.#s.value), this.#p()), t === "disabled" && this.#e && (s !== null ? this.#e.setAttribute("disabled", "") : this.#e.removeAttribute("disabled")));
|
|
2376
2667
|
}
|
|
2377
2668
|
// Public API
|
|
2378
2669
|
get value() {
|
|
2379
2670
|
return this.#s?.value ?? this.getAttribute("value") ?? "#000000";
|
|
2380
2671
|
}
|
|
2381
2672
|
set value(t) {
|
|
2382
|
-
this.#s?.setColor(t) && (this.#e && (this.#e.value = this.#s.value), this.#
|
|
2673
|
+
this.#s?.setColor(t) && (this.#e && (this.#e.value = this.#s.value), this.#p(), this.#w());
|
|
2383
2674
|
}
|
|
2384
2675
|
get disabled() {
|
|
2385
2676
|
return this.hasAttribute("disabled");
|
|
@@ -2397,37 +2688,696 @@ class at extends d {
|
|
|
2397
2688
|
return this.#s?.hsv ?? { h: 0, s: 0, v: 0 };
|
|
2398
2689
|
}
|
|
2399
2690
|
}
|
|
2400
|
-
customElements.define("ry-color-input",
|
|
2401
|
-
|
|
2691
|
+
customElements.define("ry-color-input", ut);
|
|
2692
|
+
function x(o) {
|
|
2693
|
+
const t = o.trim().toLowerCase();
|
|
2694
|
+
if (t.startsWith("#")) {
|
|
2695
|
+
const i = t.slice(1);
|
|
2696
|
+
return i.length === 3 ? {
|
|
2697
|
+
r: parseInt(i[0] + i[0], 16),
|
|
2698
|
+
g: parseInt(i[1] + i[1], 16),
|
|
2699
|
+
b: parseInt(i[2] + i[2], 16)
|
|
2700
|
+
} : i.length >= 6 ? {
|
|
2701
|
+
r: parseInt(i.slice(0, 2), 16),
|
|
2702
|
+
g: parseInt(i.slice(2, 4), 16),
|
|
2703
|
+
b: parseInt(i.slice(4, 6), 16)
|
|
2704
|
+
} : null;
|
|
2705
|
+
}
|
|
2706
|
+
const e = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(t);
|
|
2707
|
+
if (e)
|
|
2708
|
+
return {
|
|
2709
|
+
r: parseInt(e[1], 10),
|
|
2710
|
+
g: parseInt(e[2], 10),
|
|
2711
|
+
b: parseInt(e[3], 10)
|
|
2712
|
+
};
|
|
2713
|
+
const s = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%/.exec(t);
|
|
2714
|
+
if (s) {
|
|
2715
|
+
const i = parseFloat(s[1]) / 360, r = parseFloat(s[2]) / 100, a = parseFloat(s[3]) / 100, n = (c, d, u) => (u < 0 && (u += 1), u > 1 && (u -= 1), u < 1 / 6 ? c + (d - c) * 6 * u : u < 1 / 2 ? d : u < 2 / 3 ? c + (d - c) * (2 / 3 - u) * 6 : c), h = a < 0.5 ? a * (1 + r) : a + r - a * r, l = 2 * a - h;
|
|
2716
|
+
return {
|
|
2717
|
+
r: Math.round(n(l, h, i + 1 / 3) * 255),
|
|
2718
|
+
g: Math.round(n(l, h, i) * 255),
|
|
2719
|
+
b: Math.round(n(l, h, i - 1 / 3) * 255)
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
return null;
|
|
2723
|
+
}
|
|
2724
|
+
function pt(o) {
|
|
2725
|
+
const t = (e) => Math.max(0, Math.min(255, e)).toString(16).padStart(2, "0");
|
|
2726
|
+
return `#${t(o.r)}${t(o.g)}${t(o.b)}`;
|
|
2727
|
+
}
|
|
2728
|
+
function gt(o, t, e) {
|
|
2729
|
+
return {
|
|
2730
|
+
r: Math.round(o.r + (t.r - o.r) * e),
|
|
2731
|
+
g: Math.round(o.g + (t.g - o.g) * e),
|
|
2732
|
+
b: Math.round(o.b + (t.b - o.b) * e)
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
const H = "linear-gradient(90deg, #000000 0%, #ffffff 100%)", ft = 50;
|
|
2736
|
+
class bt extends p {
|
|
2737
|
+
#t = "linear";
|
|
2738
|
+
#e = 90;
|
|
2739
|
+
#i = "circle";
|
|
2740
|
+
#s = [];
|
|
2741
|
+
#r = null;
|
|
2742
|
+
#n = 0;
|
|
2743
|
+
#h = null;
|
|
2744
|
+
#l = !1;
|
|
2745
|
+
#d = null;
|
|
2746
|
+
#o = !1;
|
|
2747
|
+
// Cached DOM refs
|
|
2748
|
+
#a = null;
|
|
2749
|
+
#u = null;
|
|
2750
|
+
#g = null;
|
|
2751
|
+
static observedAttributes = ["value", "disabled", "output"];
|
|
2752
|
+
setup() {
|
|
2753
|
+
this.#m(), this.#W(), this.#X(), this.#$();
|
|
2754
|
+
}
|
|
2755
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2756
|
+
// Parsing / Serialization
|
|
2757
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2758
|
+
#m() {
|
|
2759
|
+
const t = this.getAttribute("value") || H;
|
|
2760
|
+
this.#f(t) || this.#f(H);
|
|
2761
|
+
}
|
|
2762
|
+
#f(t) {
|
|
2763
|
+
const e = t.trim();
|
|
2764
|
+
if (!e.startsWith("linear-gradient(") && !e.startsWith("radial-gradient("))
|
|
2765
|
+
return x(e) ? (this.#t = "solid", this.#s = [this.#p(e, 0), this.#p(e, 100)], this.#r = this.#s[0].id, !0) : !1;
|
|
2766
|
+
let s, i;
|
|
2767
|
+
e.startsWith("linear-gradient(") ? (s = "linear", i = e.slice(16, -1)) : (s = "radial", i = e.slice(16, -1));
|
|
2768
|
+
let r = 90, a = "circle", n = i;
|
|
2769
|
+
if (s === "linear") {
|
|
2770
|
+
const d = /^([\d.]+)deg\s*,\s*/.exec(i);
|
|
2771
|
+
if (d)
|
|
2772
|
+
r = parseFloat(d[1]), n = i.slice(d[0].length);
|
|
2773
|
+
else {
|
|
2774
|
+
const u = /^to\s+\w+(?:\s+\w+)?\s*,\s*/.exec(i);
|
|
2775
|
+
if (u) {
|
|
2776
|
+
const b = u[0].trim().replace(/,\s*$/, "");
|
|
2777
|
+
r = this.#A(b), n = i.slice(u[0].length);
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
} else {
|
|
2781
|
+
const d = /^(circle|ellipse)(?:\s+at\s+[^,]+)?\s*,\s*/.exec(i);
|
|
2782
|
+
d && (a = d[1], n = i.slice(d[0].length));
|
|
2783
|
+
}
|
|
2784
|
+
const h = [], l = /(#[a-fA-F0-9]{3,8}|rgba?\([^)]+\)|hsla?\([^)]+\)|[a-z]+)\s+([\d.]+)%/g;
|
|
2785
|
+
let c;
|
|
2786
|
+
for (; (c = l.exec(n)) !== null; )
|
|
2787
|
+
h.push(this.#p(c[1], parseFloat(c[2])));
|
|
2788
|
+
return h.length < 2 ? !1 : (this.#t = s, this.#e = r, this.#i = a, this.#s = h, this.#r = h[0].id, !0);
|
|
2789
|
+
}
|
|
2790
|
+
#A(t) {
|
|
2791
|
+
return {
|
|
2792
|
+
"to top": 0,
|
|
2793
|
+
"to top right": 45,
|
|
2794
|
+
"to right": 90,
|
|
2795
|
+
"to bottom right": 135,
|
|
2796
|
+
"to bottom": 180,
|
|
2797
|
+
"to bottom left": 225,
|
|
2798
|
+
"to left": 270,
|
|
2799
|
+
"to top left": 315
|
|
2800
|
+
}[t] ?? 90;
|
|
2801
|
+
}
|
|
2802
|
+
#c() {
|
|
2803
|
+
if (this.#t === "solid")
|
|
2804
|
+
return this.#s[0]?.color ?? "#000000";
|
|
2805
|
+
const t = this.#s.map((e) => `${e.color} ${Math.round(e.position)}%`).join(", ");
|
|
2806
|
+
return this.#t === "linear" ? `linear-gradient(${Math.round(this.#e)}deg, ${t})` : `radial-gradient(${this.#i}, ${t})`;
|
|
2807
|
+
}
|
|
2808
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2809
|
+
// Stop management
|
|
2810
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2811
|
+
#p(t, e) {
|
|
2812
|
+
return { id: `stop-${this.#n++}`, color: t, position: e };
|
|
2813
|
+
}
|
|
2814
|
+
/** CSS left value clamped so the stop handle stays within the bar */
|
|
2815
|
+
#y(t) {
|
|
2816
|
+
const e = "calc(var(--ry-gradient-picker-stop-size, 16px) / 2)";
|
|
2817
|
+
return `clamp(${e}, ${t}%, calc(100% - ${e}))`;
|
|
2818
|
+
}
|
|
2819
|
+
#w(t, e) {
|
|
2820
|
+
const s = this.#p(t, e);
|
|
2821
|
+
this.#s.push(s), this.#M(), this.#r = s.id, this.#E(), this.#$();
|
|
2822
|
+
}
|
|
2823
|
+
#b(t) {
|
|
2824
|
+
if (this.#s.length <= 2) return !1;
|
|
2825
|
+
const e = this.#s.findIndex((s) => s.id === t);
|
|
2826
|
+
return e === -1 ? !1 : (this.#s.splice(e, 1), this.#r === t && (this.#r = this.#s[Math.min(e, this.#s.length - 1)]?.id ?? null), this.#E(), this.#$(), !0);
|
|
2827
|
+
}
|
|
2828
|
+
#S(t) {
|
|
2829
|
+
this.#r !== t && (this.#r = t, this.#N(), this.#L());
|
|
2830
|
+
}
|
|
2831
|
+
#M() {
|
|
2832
|
+
this.#s.sort((t, e) => t.position - e.position);
|
|
2833
|
+
}
|
|
2834
|
+
#F() {
|
|
2835
|
+
return this.#s.find((t) => t.id === this.#r) ?? null;
|
|
2836
|
+
}
|
|
2837
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2838
|
+
// Markup
|
|
2839
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2840
|
+
#W() {
|
|
2841
|
+
const t = this.hasAttribute("output"), e = g("copy"), s = g("gradient-solid"), i = g("gradient-linear"), r = g("gradient-radial"), a = g("shape-circle"), n = g("shape-ellipse");
|
|
2842
|
+
let h = "";
|
|
2843
|
+
t && (h = `
|
|
2844
|
+
<div data-ry-target="output-row" class="ry-gradient-picker__output-row">
|
|
2845
|
+
<input data-ry-target="output" type="text" class="ry-gradient-picker__output" spellcheck="false" />
|
|
2846
|
+
<button data-ry-target="copy-btn" type="button" class="ry-gradient-picker__copy-btn">${e}</button>
|
|
2847
|
+
</div>`), this.innerHTML = `
|
|
2848
|
+
<div data-ry-target="controls" class="ry-gradient-picker__controls">
|
|
2849
|
+
<div data-ry-target="type-toggle" class="ry-gradient-picker__type-toggle">
|
|
2850
|
+
<button data-ry-target="type-solid" type="button" class="ry-gradient-picker__type-btn">${s}</button>
|
|
2851
|
+
<button data-ry-target="type-linear" type="button" class="ry-gradient-picker__type-btn">${i}</button>
|
|
2852
|
+
<button data-ry-target="type-radial" type="button" class="ry-gradient-picker__type-btn">${r}</button>
|
|
2853
|
+
</div>
|
|
2854
|
+
<div data-ry-target="angle-control" class="ry-gradient-picker__angle-control">
|
|
2855
|
+
<ry-number-select data-ry-target="angle-select" min="0" max="360" step="1" value="${this.#e}" wrap suffix="°" size="xs" arrows="none"></ry-number-select>
|
|
2856
|
+
</div>
|
|
2857
|
+
<div data-ry-target="shape-control" class="ry-gradient-picker__shape-control">
|
|
2858
|
+
<button data-ry-target="shape-circle" type="button" class="ry-gradient-picker__shape-btn">${a}</button>
|
|
2859
|
+
<button data-ry-target="shape-ellipse" type="button" class="ry-gradient-picker__shape-btn">${n}</button>
|
|
2860
|
+
</div>
|
|
2861
|
+
</div>
|
|
2862
|
+
<div data-ry-target="bar-container" class="ry-gradient-picker__bar-container">
|
|
2863
|
+
<div data-ry-target="bar" class="ry-gradient-picker__bar"></div>
|
|
2864
|
+
</div>
|
|
2865
|
+
<ry-color-picker data-ry-target="picker" inline opacity></ry-color-picker>
|
|
2866
|
+
${h}
|
|
2867
|
+
`, this.#a = this.$('[data-ry-target="bar"]'), this.#u = this.$('[data-ry-target="picker"]'), this.#g = this.$('[data-ry-target="output"]'), this.#E();
|
|
2868
|
+
}
|
|
2869
|
+
#E() {
|
|
2870
|
+
if (this.#a) {
|
|
2871
|
+
this.#a.querySelectorAll('[data-ry-target="stop"]').forEach((t) => t.remove());
|
|
2872
|
+
for (const t of this.#s) {
|
|
2873
|
+
const e = document.createElement("div");
|
|
2874
|
+
e.setAttribute("data-ry-target", "stop"), e.setAttribute("data-stop-id", t.id), e.classList.add("ry-gradient-picker__stop"), e.tabIndex = 0, e.style.left = this.#y(t.position), e.style.setProperty("--stop-color", t.color), t.id === this.#r && e.setAttribute("data-selected", ""), this.#a.appendChild(e);
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2879
|
+
// Event binding
|
|
2880
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2881
|
+
#X() {
|
|
2882
|
+
this.#a && (this.on(this.#a, "pointerdown", this.#G), this.on(this.#a, "pointermove", this.#K), this.on(this.#a, "pointerup", this.#q), this.on(this.#a, "lostpointercapture", this.#q));
|
|
2883
|
+
const t = this.$('[data-ry-target="type-solid"]'), e = this.$('[data-ry-target="type-linear"]'), s = this.$('[data-ry-target="type-radial"]');
|
|
2884
|
+
t && this.on(t, "click", () => this.#_("solid")), e && this.on(e, "click", () => this.#_("linear")), s && this.on(s, "click", () => this.#_("radial"));
|
|
2885
|
+
const i = this.$('[data-ry-target="angle-select"]');
|
|
2886
|
+
i && this.on(i, "ry:input", this.#U);
|
|
2887
|
+
const r = this.$('[data-ry-target="shape-circle"]'), a = this.$('[data-ry-target="shape-ellipse"]');
|
|
2888
|
+
r && this.on(r, "click", () => this.#P("circle")), a && this.on(a, "click", () => this.#P("ellipse")), this.#u && (this.on(this.#u, "ry:input", this.#B), this.on(this.#u, "ry:change", this.#T)), this.#g && (this.on(this.#g, "keydown", this.#R), this.on(this.#g, "blur", this.#j));
|
|
2889
|
+
const n = this.$('[data-ry-target="copy-btn"]');
|
|
2890
|
+
n && this.on(n, "click", this.#V), this.#a && this.on(this.#a, "keydown", this.#J);
|
|
2891
|
+
}
|
|
2892
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2893
|
+
// Bar / Stop interaction handlers
|
|
2894
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2895
|
+
#G = (t) => {
|
|
2896
|
+
if (this.disabled) return;
|
|
2897
|
+
const s = t.target.closest('[data-ry-target="stop"]');
|
|
2898
|
+
if (s) {
|
|
2899
|
+
const i = s.getAttribute("data-stop-id");
|
|
2900
|
+
if (!i) return;
|
|
2901
|
+
t.preventDefault(), this.#h = i, this.#l = !1, this.#d = this.#a.getBoundingClientRect(), this.#S(i), this.#a.setPointerCapture(t.pointerId), s.focus();
|
|
2902
|
+
} else {
|
|
2903
|
+
if (t.preventDefault(), !this.#a) return;
|
|
2904
|
+
const i = this.#a.getBoundingClientRect(), r = Math.round(Math.max(0, Math.min(100, (t.clientX - i.left) / i.width * 100))), a = this.#Y(r);
|
|
2905
|
+
this.#w(a, r), this.#a.querySelector(`[data-stop-id="${this.#r}"]`)?.focus(), this.#h = this.#r, this.#l = !1, this.#d = i, this.#a.setPointerCapture(t.pointerId), this.#I();
|
|
2906
|
+
}
|
|
2907
|
+
};
|
|
2908
|
+
#K = (t) => {
|
|
2909
|
+
if (!this.#h || !this.#d) return;
|
|
2910
|
+
const e = this.#s.find((n) => n.id === this.#h);
|
|
2911
|
+
if (!e) return;
|
|
2912
|
+
const s = Math.max(0, Math.min(1, (t.clientX - this.#d.left) / this.#d.width));
|
|
2913
|
+
e.position = Math.round(s * 100);
|
|
2914
|
+
const i = this.#d.top + this.#d.height / 2, r = Math.abs(t.clientY - i);
|
|
2915
|
+
this.#l = r > ft && this.#s.length > 2;
|
|
2916
|
+
const a = this.#a?.querySelector(`[data-stop-id="${e.id}"]`);
|
|
2917
|
+
a && (a.style.left = this.#y(e.position), this.#l ? (a.style.opacity = "0.3", a.style.transform = "translate(-50%, -50%) scale(0.7)") : (a.style.opacity = "", a.style.transform = "")), this.#M(), this.#O(), this.#H(), this.#k(), this.#I();
|
|
2918
|
+
};
|
|
2919
|
+
#q = () => {
|
|
2920
|
+
this.#h && (this.#l && this.#b(this.#h), this.#h = null, this.#l = !1, this.#d = null, this.#C(), this.#D());
|
|
2921
|
+
};
|
|
2922
|
+
#J = (t) => {
|
|
2923
|
+
if (this.disabled) return;
|
|
2924
|
+
const s = t.target.closest('[data-ry-target="stop"]');
|
|
2925
|
+
if (!s) return;
|
|
2926
|
+
const i = s.getAttribute("data-stop-id");
|
|
2927
|
+
if (!i) return;
|
|
2928
|
+
const r = this.#s.find((h) => h.id === i);
|
|
2929
|
+
if (!r) return;
|
|
2930
|
+
const a = t.shiftKey ? 10 : 1;
|
|
2931
|
+
let n = !1;
|
|
2932
|
+
switch (t.key) {
|
|
2933
|
+
case "ArrowRight":
|
|
2934
|
+
r.position = Math.min(100, r.position + a), n = !0;
|
|
2935
|
+
break;
|
|
2936
|
+
case "ArrowLeft":
|
|
2937
|
+
r.position = Math.max(0, r.position - a), n = !0;
|
|
2938
|
+
break;
|
|
2939
|
+
case "Delete":
|
|
2940
|
+
case "Backspace":
|
|
2941
|
+
this.#b(i) && (this.#I(), this.#D()), t.preventDefault();
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
n && (t.preventDefault(), this.#M(), this.#z(), this.#O(), this.#H(), this.#k(), this.#C(), this.#I(), this.#D());
|
|
2945
|
+
};
|
|
2946
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2947
|
+
// Type / Angle / Shape handlers
|
|
2948
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2949
|
+
#_(t) {
|
|
2950
|
+
this.#t !== t && (this.#t = t, this.setAttribute("data-ry-type", t), this.#x(), this.#H(), this.#k(), this.#C(), this.#I(), this.#D());
|
|
2951
|
+
}
|
|
2952
|
+
#U = (t) => {
|
|
2953
|
+
const e = t.detail;
|
|
2954
|
+
this.#e = e.value, this.#H(), this.#k(), this.#C(), this.#I();
|
|
2955
|
+
};
|
|
2956
|
+
#P(t) {
|
|
2957
|
+
this.#i !== t && (this.#i = t, this.#x(), this.#k(), this.#C(), this.#I(), this.#D());
|
|
2958
|
+
}
|
|
2959
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2960
|
+
// Color picker handlers
|
|
2961
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2962
|
+
#B = () => {
|
|
2963
|
+
const t = this.#F();
|
|
2964
|
+
!t || !this.#u || (t.color = this.#u.value, this.#Z(t), this.#O(), this.#H(), this.#k(), this.#I());
|
|
2965
|
+
};
|
|
2966
|
+
#T = () => {
|
|
2967
|
+
this.#C(), this.#D();
|
|
2968
|
+
};
|
|
2969
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2970
|
+
// Copy handler
|
|
2971
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2972
|
+
#V = () => {
|
|
2973
|
+
const t = this.#c();
|
|
2974
|
+
navigator.clipboard.writeText(t).then(() => {
|
|
2975
|
+
const e = this.$('[data-ry-target="copy-btn"]');
|
|
2976
|
+
e && (e.setAttribute("data-copied", ""), setTimeout(() => e.removeAttribute("data-copied"), 1500));
|
|
2977
|
+
});
|
|
2978
|
+
};
|
|
2979
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2980
|
+
// Output (editable CSS) handlers
|
|
2981
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2982
|
+
#R = (t) => {
|
|
2983
|
+
t.key === "Enter" && (t.preventDefault(), this.#v());
|
|
2984
|
+
};
|
|
2985
|
+
#j = () => {
|
|
2986
|
+
this.#v();
|
|
2987
|
+
};
|
|
2988
|
+
#v() {
|
|
2989
|
+
if (!this.#g) return;
|
|
2990
|
+
const t = this.#g.value.trim();
|
|
2991
|
+
t && this.#f(t) ? (this.#E(), this.#$(), this.#C(), this.#I(), this.#D()) : this.#k();
|
|
2992
|
+
}
|
|
2993
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2994
|
+
// Color interpolation
|
|
2995
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
2996
|
+
#Y(t) {
|
|
2997
|
+
if (this.#s.length === 0) return "#808080";
|
|
2998
|
+
if (this.#s.length === 1) return this.#s[0].color;
|
|
2999
|
+
const e = [...this.#s].sort((l, c) => l.position - c.position);
|
|
3000
|
+
if (t <= e[0].position) return e[0].color;
|
|
3001
|
+
if (t >= e[e.length - 1].position) return e[e.length - 1].color;
|
|
3002
|
+
let s = e[0], i = e[1];
|
|
3003
|
+
for (let l = 0; l < e.length - 1; l++)
|
|
3004
|
+
if (e[l].position <= t && e[l + 1].position >= t) {
|
|
3005
|
+
s = e[l], i = e[l + 1];
|
|
3006
|
+
break;
|
|
3007
|
+
}
|
|
3008
|
+
const r = i.position - s.position;
|
|
3009
|
+
if (r === 0) return s.color;
|
|
3010
|
+
const a = (t - s.position) / r, n = x(s.color), h = x(i.color);
|
|
3011
|
+
return !n || !h ? s.color : pt(gt(n, h, a));
|
|
3012
|
+
}
|
|
3013
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3014
|
+
// Update methods
|
|
3015
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3016
|
+
#$() {
|
|
3017
|
+
this.setAttribute("data-ry-type", this.#t), this.#x(), this.#O(), this.#H(), this.#z(), this.#N(), this.#L(), this.#k();
|
|
3018
|
+
}
|
|
3019
|
+
#x() {
|
|
3020
|
+
const t = this.$('[data-ry-target="type-solid"]'), e = this.$('[data-ry-target="type-linear"]'), s = this.$('[data-ry-target="type-radial"]');
|
|
3021
|
+
t && t.toggleAttribute("data-active", this.#t === "solid"), e && e.toggleAttribute("data-active", this.#t === "linear"), s && s.toggleAttribute("data-active", this.#t === "radial");
|
|
3022
|
+
const i = this.$('[data-ry-target="shape-circle"]'), r = this.$('[data-ry-target="shape-ellipse"]');
|
|
3023
|
+
i && i.toggleAttribute("data-active", this.#i === "circle"), r && r.toggleAttribute("data-active", this.#i === "ellipse");
|
|
3024
|
+
const a = this.$('[data-ry-target="angle-select"]');
|
|
3025
|
+
a && a.setAttribute("value", String(this.#e));
|
|
3026
|
+
}
|
|
3027
|
+
#H() {
|
|
3028
|
+
if (!this.#u) return;
|
|
3029
|
+
const t = this.#u.querySelector('[data-ry-target="preview-color"]');
|
|
3030
|
+
t && (t.style.backgroundImage = this.#t === "solid" ? "" : this.#c());
|
|
3031
|
+
}
|
|
3032
|
+
#O() {
|
|
3033
|
+
if (!this.#a) return;
|
|
3034
|
+
const t = this.#s.map((e) => `${e.color} ${e.position}%`).join(", ");
|
|
3035
|
+
this.#a.style.backgroundImage = `linear-gradient(to right, ${t})`;
|
|
3036
|
+
}
|
|
3037
|
+
#z() {
|
|
3038
|
+
if (this.#a)
|
|
3039
|
+
for (const t of this.#s) {
|
|
3040
|
+
const e = this.#a.querySelector(`[data-stop-id="${t.id}"]`);
|
|
3041
|
+
e && (e.style.left = this.#y(t.position));
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
#Z(t) {
|
|
3045
|
+
if (!this.#a) return;
|
|
3046
|
+
const e = this.#a.querySelector(`[data-stop-id="${t.id}"]`);
|
|
3047
|
+
e && e.style.setProperty("--stop-color", t.color);
|
|
3048
|
+
}
|
|
3049
|
+
#N() {
|
|
3050
|
+
if (!this.#a) return;
|
|
3051
|
+
const t = this.#a.querySelectorAll('[data-ry-target="stop"]');
|
|
3052
|
+
for (const e of t)
|
|
3053
|
+
e.getAttribute("data-stop-id") === this.#r ? e.setAttribute("data-selected", "") : e.removeAttribute("data-selected");
|
|
3054
|
+
}
|
|
3055
|
+
#L() {
|
|
3056
|
+
const t = this.#F();
|
|
3057
|
+
!t || !this.#u || this.#u.setColor(t.color);
|
|
3058
|
+
}
|
|
3059
|
+
#k() {
|
|
3060
|
+
this.#g && document.activeElement !== this.#g && (this.#g.value = this.#c());
|
|
3061
|
+
}
|
|
3062
|
+
#C() {
|
|
3063
|
+
const t = this.#c();
|
|
3064
|
+
this.getAttribute("value") !== t && (this.#o = !0, this.setAttribute("value", t), this.#o = !1);
|
|
3065
|
+
}
|
|
3066
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3067
|
+
// Events
|
|
3068
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3069
|
+
#I() {
|
|
3070
|
+
this.emit("input", {
|
|
3071
|
+
value: this.#c(),
|
|
3072
|
+
type: this.#t,
|
|
3073
|
+
angle: this.#e,
|
|
3074
|
+
shape: this.#i,
|
|
3075
|
+
stops: this.stops
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
#D() {
|
|
3079
|
+
this.emit("change", {
|
|
3080
|
+
value: this.#c(),
|
|
3081
|
+
type: this.#t,
|
|
3082
|
+
angle: this.#e,
|
|
3083
|
+
shape: this.#i,
|
|
3084
|
+
stops: this.stops
|
|
3085
|
+
});
|
|
3086
|
+
}
|
|
3087
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3088
|
+
// Attribute changed
|
|
3089
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3090
|
+
attributeChangedCallback(t, e, s) {
|
|
3091
|
+
e === s || this.#o || t === "value" && this.#a && s && this.#f(s) && (this.#E(), this.#$());
|
|
3092
|
+
}
|
|
3093
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3094
|
+
// Public API
|
|
3095
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
3096
|
+
get value() {
|
|
3097
|
+
return this.#c();
|
|
3098
|
+
}
|
|
3099
|
+
set value(t) {
|
|
3100
|
+
this.#f(t) && (this.#E(), this.#$(), this.#C());
|
|
3101
|
+
}
|
|
3102
|
+
get type() {
|
|
3103
|
+
return this.#t;
|
|
3104
|
+
}
|
|
3105
|
+
set type(t) {
|
|
3106
|
+
this.#_(t);
|
|
3107
|
+
}
|
|
3108
|
+
get angle() {
|
|
3109
|
+
return this.#e;
|
|
3110
|
+
}
|
|
3111
|
+
set angle(t) {
|
|
3112
|
+
this.#e = (t % 360 + 360) % 360, this.#x(), this.#k(), this.#C();
|
|
3113
|
+
}
|
|
3114
|
+
get shape() {
|
|
3115
|
+
return this.#i;
|
|
3116
|
+
}
|
|
3117
|
+
set shape(t) {
|
|
3118
|
+
this.#P(t);
|
|
3119
|
+
}
|
|
3120
|
+
get stops() {
|
|
3121
|
+
return this.#s.map((t) => ({ ...t }));
|
|
3122
|
+
}
|
|
3123
|
+
get selectedStop() {
|
|
3124
|
+
const t = this.#F();
|
|
3125
|
+
return t ? { ...t } : null;
|
|
3126
|
+
}
|
|
3127
|
+
get disabled() {
|
|
3128
|
+
return this.hasAttribute("disabled");
|
|
3129
|
+
}
|
|
3130
|
+
set disabled(t) {
|
|
3131
|
+
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
3132
|
+
}
|
|
3133
|
+
addStop(t, e) {
|
|
3134
|
+
this.#w(t, e), this.#C(), this.#I(), this.#D();
|
|
3135
|
+
}
|
|
3136
|
+
removeStop(t) {
|
|
3137
|
+
const e = this.#b(t);
|
|
3138
|
+
return e && (this.#k(), this.#C(), this.#D()), e;
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
customElements.define("ry-gradient-picker", bt);
|
|
3142
|
+
let yt = 0;
|
|
3143
|
+
const mt = 5;
|
|
3144
|
+
function _(o) {
|
|
3145
|
+
return g(o).replace(/width="24"/g, 'width="16"').replace(/height="24"/g, 'height="16"').replace(/viewBox/, 'class="ry-tree__icon" viewBox');
|
|
3146
|
+
}
|
|
3147
|
+
class k extends p {
|
|
3148
|
+
// Drag state
|
|
3149
|
+
#t = !1;
|
|
3150
|
+
#e = !1;
|
|
3151
|
+
#i = 0;
|
|
3152
|
+
#s = 0;
|
|
3153
|
+
#r = null;
|
|
3154
|
+
#n = null;
|
|
3155
|
+
#h = null;
|
|
3156
|
+
#l = null;
|
|
3157
|
+
setup() {
|
|
3158
|
+
this.#d(), this.on(this, "click", (t) => {
|
|
3159
|
+
const s = t.target.closest('[data-ry-target="file"]');
|
|
3160
|
+
s && (this.$$("[data-ry-selected]").forEach((i) => i.removeAttribute("data-ry-selected")), s.setAttribute("data-ry-selected", ""), this.emit("select", {
|
|
3161
|
+
label: s.dataset.ryLabel ?? ""
|
|
3162
|
+
}));
|
|
3163
|
+
}), this.on(this, "change", (t) => {
|
|
3164
|
+
const e = t.target;
|
|
3165
|
+
if (!e.classList.contains("ry-tree__toggle")) return;
|
|
3166
|
+
const i = e.closest(".ry-tree__item")?.querySelector('[data-ry-target="folder"]')?.dataset.ryLabel ?? "";
|
|
3167
|
+
this.emit("toggle", {
|
|
3168
|
+
label: i,
|
|
3169
|
+
open: e.checked
|
|
3170
|
+
});
|
|
3171
|
+
}), this.hasAttribute("sortable") && this.#m();
|
|
3172
|
+
}
|
|
3173
|
+
// ── Build ──────────────────────────────────────────────────
|
|
3174
|
+
#d() {
|
|
3175
|
+
if (this.$(".ry-tree__root")) return;
|
|
3176
|
+
const t = Array.from(this.children), e = document.createElement("ul");
|
|
3177
|
+
e.className = "ry-tree__root";
|
|
3178
|
+
for (const s of t)
|
|
3179
|
+
e.appendChild(this.#o(s));
|
|
3180
|
+
this.innerHTML = "", this.appendChild(e);
|
|
3181
|
+
}
|
|
3182
|
+
#o(t) {
|
|
3183
|
+
const e = document.createElement("li");
|
|
3184
|
+
e.className = "ry-tree__item";
|
|
3185
|
+
const s = t.getAttribute("label") ?? "", i = t.hasAttribute("open"), r = t.hasAttribute("selected"), a = Array.from(t.children).filter(
|
|
3186
|
+
(h) => h.tagName === "RY-TREE-ITEM"
|
|
3187
|
+
);
|
|
3188
|
+
if (a.length > 0) {
|
|
3189
|
+
const h = `ry-tree-${++yt}`, l = document.createElement("input");
|
|
3190
|
+
l.type = "checkbox", l.id = h, l.className = "ry-tree__toggle", i && (l.checked = !0);
|
|
3191
|
+
const c = document.createElement("label");
|
|
3192
|
+
c.htmlFor = h, c.className = "ry-tree__label", c.setAttribute("data-ry-target", "folder"), c.dataset.ryLabel = s, c.innerHTML = `
|
|
3193
|
+
<span class="ry-tree__icon-closed">${_("folder")}</span>
|
|
3194
|
+
<span class="ry-tree__icon-open">${_("folder-open")}</span>
|
|
3195
|
+
${s}
|
|
3196
|
+
`;
|
|
3197
|
+
const d = document.createElement("div");
|
|
3198
|
+
d.className = "ry-tree__children-wrapper";
|
|
3199
|
+
const u = document.createElement("ul");
|
|
3200
|
+
u.className = "ry-tree__children";
|
|
3201
|
+
for (const b of a)
|
|
3202
|
+
u.appendChild(this.#o(b));
|
|
3203
|
+
d.appendChild(u), e.appendChild(l), e.appendChild(c), e.appendChild(d);
|
|
3204
|
+
} else {
|
|
3205
|
+
const h = document.createElement("div");
|
|
3206
|
+
h.className = "ry-tree__file", h.setAttribute("data-ry-target", "file"), h.dataset.ryLabel = s, r && h.setAttribute("data-ry-selected", ""), h.innerHTML = `${_("file")} ${s}`, e.appendChild(h);
|
|
3207
|
+
}
|
|
3208
|
+
return e;
|
|
3209
|
+
}
|
|
3210
|
+
// ── Serialization ──────────────────────────────────────────
|
|
3211
|
+
/** Serialize the current tree state to JSON. */
|
|
3212
|
+
toJSON() {
|
|
3213
|
+
const t = this.$(".ry-tree__root");
|
|
3214
|
+
return t ? this.#a(t) : [];
|
|
3215
|
+
}
|
|
3216
|
+
/** Alias for toJSON(). */
|
|
3217
|
+
get value() {
|
|
3218
|
+
return this.toJSON();
|
|
3219
|
+
}
|
|
3220
|
+
#a(t) {
|
|
3221
|
+
return Array.from(t.children).filter(
|
|
3222
|
+
(s) => s instanceof HTMLElement && s.classList.contains("ry-tree__item")
|
|
3223
|
+
).map((s) => this.#u(s));
|
|
3224
|
+
}
|
|
3225
|
+
#u(t) {
|
|
3226
|
+
const e = t.querySelector(':scope > [data-ry-target="folder"]'), s = t.querySelector(':scope > [data-ry-target="file"]');
|
|
3227
|
+
if (e) {
|
|
3228
|
+
const r = t.querySelector(":scope > .ry-tree__toggle"), a = t.querySelector(".ry-tree__children"), n = { label: e.dataset.ryLabel ?? "" };
|
|
3229
|
+
if (r?.checked && (n.open = !0), a) {
|
|
3230
|
+
const h = this.#a(a);
|
|
3231
|
+
h.length > 0 && (n.children = h);
|
|
3232
|
+
}
|
|
3233
|
+
return n;
|
|
3234
|
+
}
|
|
3235
|
+
const i = { label: s?.dataset.ryLabel ?? "" };
|
|
3236
|
+
return s?.hasAttribute("data-ry-selected") && (i.selected = !0), i;
|
|
3237
|
+
}
|
|
3238
|
+
/** Create a tree element from JSON data. */
|
|
3239
|
+
static from(t) {
|
|
3240
|
+
const e = document.createElement("ry-tree");
|
|
3241
|
+
for (const s of t)
|
|
3242
|
+
e.appendChild(k.#g(s));
|
|
3243
|
+
return e;
|
|
3244
|
+
}
|
|
3245
|
+
static #g(t) {
|
|
3246
|
+
const e = document.createElement("ry-tree-item");
|
|
3247
|
+
if (e.setAttribute("label", t.label), t.open && e.setAttribute("open", ""), t.selected && e.setAttribute("selected", ""), t.children)
|
|
3248
|
+
for (const s of t.children)
|
|
3249
|
+
e.appendChild(k.#g(s));
|
|
3250
|
+
return e;
|
|
3251
|
+
}
|
|
3252
|
+
// ── Drag and Drop ──────────────────────────────────────────
|
|
3253
|
+
#m() {
|
|
3254
|
+
this.on(this, "pointerdown", this.#f), this.on(document, "pointermove", this.#A), this.on(document, "pointerup", this.#c);
|
|
3255
|
+
}
|
|
3256
|
+
#f = (t) => {
|
|
3257
|
+
const s = t.target.closest(".ry-tree__label, .ry-tree__file");
|
|
3258
|
+
if (!s) return;
|
|
3259
|
+
const i = s.closest(".ry-tree__item");
|
|
3260
|
+
i && (this.#t = !0, this.#i = t.clientX, this.#s = t.clientY, this.#r = i);
|
|
3261
|
+
};
|
|
3262
|
+
#A = (t) => {
|
|
3263
|
+
if (!this.#t && !this.#e) return;
|
|
3264
|
+
if (this.#t && !this.#e) {
|
|
3265
|
+
const c = t.clientX - this.#i, d = t.clientY - this.#s;
|
|
3266
|
+
if (Math.hypot(c, d) < mt) return;
|
|
3267
|
+
this.#t = !1, this.#e = !0, this.#p(t);
|
|
3268
|
+
}
|
|
3269
|
+
if (!this.#e || !this.#n) return;
|
|
3270
|
+
this.#n.style.left = `${t.clientX + 12}px`, this.#n.style.top = `${t.clientY - 14}px`, this.#n.style.display = "none";
|
|
3271
|
+
const e = document.elementFromPoint(t.clientX, t.clientY);
|
|
3272
|
+
if (this.#n.style.display = "", !e) {
|
|
3273
|
+
this.#b();
|
|
3274
|
+
return;
|
|
3275
|
+
}
|
|
3276
|
+
const s = e.closest(".ry-tree__label, .ry-tree__file");
|
|
3277
|
+
if (!s) {
|
|
3278
|
+
this.#b();
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
const i = s.closest(".ry-tree__item");
|
|
3282
|
+
if (!i || i === this.#r) {
|
|
3283
|
+
this.#b();
|
|
3284
|
+
return;
|
|
3285
|
+
}
|
|
3286
|
+
if (this.#r?.contains(i)) {
|
|
3287
|
+
this.#b();
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
const r = s.getBoundingClientRect(), a = t.clientY - r.top, n = r.height, h = i.querySelector(":scope > .ry-tree__toggle") !== null;
|
|
3291
|
+
let l;
|
|
3292
|
+
h && a > n * 0.25 && a < n * 0.75 ? l = "inside" : a < n * 0.5 ? l = "before" : l = "after", this.#w(i, l);
|
|
3293
|
+
};
|
|
3294
|
+
#c = () => {
|
|
3295
|
+
this.#e && this.#y(), this.#t = !1, this.#e = !1, this.#r = null;
|
|
3296
|
+
};
|
|
3297
|
+
#p(t) {
|
|
3298
|
+
if (!this.#r) return;
|
|
3299
|
+
t.preventDefault(), this.#r.setAttribute("data-ry-dragging", ""), this.#r.classList.add("ry-tree__item--collapsed");
|
|
3300
|
+
const e = this.#r.querySelector(".ry-tree__label, .ry-tree__file");
|
|
3301
|
+
if (!e) return;
|
|
3302
|
+
const s = e.cloneNode(!0);
|
|
3303
|
+
s.className = "ry-tree__ghost", s.style.display = "flex", s.style.alignItems = "center", s.style.gap = "var(--ry-space-2, 0.5rem)", s.style.padding = "var(--ry-space-1, 0.25rem) var(--ry-space-2, 0.5rem)", s.style.height = "28px", s.style.fontSize = "var(--ry-text-sm, 0.875rem)", s.style.whiteSpace = "nowrap", s.style.left = `${t.clientX + 12}px`, s.style.top = `${t.clientY - 14}px`, document.body.appendChild(s), this.#n = s;
|
|
3304
|
+
}
|
|
3305
|
+
#y() {
|
|
3306
|
+
this.#n?.parentNode && this.#n.parentNode.removeChild(this.#n), this.#n = null, this.#r?.classList.remove("ry-tree__item--collapsed"), this.#r?.removeAttribute("data-ry-dragging");
|
|
3307
|
+
const t = this.#h, e = this.#l;
|
|
3308
|
+
this.#b(), this.#r && t && e && this.#S(this.#r, t, e);
|
|
3309
|
+
}
|
|
3310
|
+
#w(t, e) {
|
|
3311
|
+
this.#h === t && this.#l === e || (this.#b(), t.setAttribute("data-ry-drop-target", e), this.#h = t, this.#l = e);
|
|
3312
|
+
}
|
|
3313
|
+
#b() {
|
|
3314
|
+
this.#h?.removeAttribute("data-ry-drop-target"), this.#h = null, this.#l = null;
|
|
3315
|
+
}
|
|
3316
|
+
#S(t, e, s) {
|
|
3317
|
+
if (s === "inside" && e.contains(t)) return;
|
|
3318
|
+
const i = this.#M(t), r = this.#M(e);
|
|
3319
|
+
if (s === "before")
|
|
3320
|
+
e.parentNode?.insertBefore(t, e);
|
|
3321
|
+
else if (s === "after")
|
|
3322
|
+
e.parentNode?.insertBefore(t, e.nextSibling);
|
|
3323
|
+
else {
|
|
3324
|
+
const a = e.querySelector(".ry-tree__children");
|
|
3325
|
+
if (a) {
|
|
3326
|
+
a.appendChild(t);
|
|
3327
|
+
const n = e.querySelector(":scope > .ry-tree__toggle");
|
|
3328
|
+
n && !n.checked && (n.checked = !0);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
this.emit("move", {
|
|
3332
|
+
item: i,
|
|
3333
|
+
target: r,
|
|
3334
|
+
position: s
|
|
3335
|
+
});
|
|
3336
|
+
}
|
|
3337
|
+
#M(t) {
|
|
3338
|
+
const e = t.querySelector(':scope > [data-ry-target="folder"]'), s = t.querySelector(':scope > [data-ry-target="file"]');
|
|
3339
|
+
return e?.dataset.ryLabel ?? s?.dataset.ryLabel ?? "";
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
class vt extends p {
|
|
3343
|
+
// Declarative container consumed by RyTree#build
|
|
3344
|
+
}
|
|
3345
|
+
customElements.define("ry-tree", k);
|
|
3346
|
+
customElements.define("ry-tree-item", vt);
|
|
3347
|
+
window.RyToast = f;
|
|
2402
3348
|
console.log("ry-ui loaded");
|
|
2403
3349
|
export {
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
3350
|
+
F as RyAccordion,
|
|
3351
|
+
K as RyAlert,
|
|
3352
|
+
O as RyButton,
|
|
3353
|
+
Q as RyCode,
|
|
3354
|
+
ut as RyColorInput,
|
|
3355
|
+
dt as RyColorPicker,
|
|
2410
3356
|
W as RyDrawer,
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
et as
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
3357
|
+
j as RyDropdown,
|
|
3358
|
+
p as RyElement,
|
|
3359
|
+
tt as RyExample,
|
|
3360
|
+
q as RyField,
|
|
3361
|
+
bt as RyGradientPicker,
|
|
3362
|
+
et as RyIcon,
|
|
3363
|
+
ot as RyKnob,
|
|
3364
|
+
P as RyModal,
|
|
3365
|
+
ht as RyNumberSelect,
|
|
3366
|
+
J as RySelect,
|
|
3367
|
+
nt as RySlider,
|
|
3368
|
+
V as RySwitch,
|
|
3369
|
+
R as RyTabs,
|
|
3370
|
+
N as RyThemeToggle,
|
|
3371
|
+
f as RyToast,
|
|
3372
|
+
at as RyToggleButton,
|
|
3373
|
+
z as RyTooltip,
|
|
3374
|
+
k as RyTree,
|
|
3375
|
+
vt as RyTreeItem,
|
|
3376
|
+
g as getIcon,
|
|
3377
|
+
$t as getIconNames,
|
|
3378
|
+
C as processTransforms,
|
|
3379
|
+
kt as registerIcon,
|
|
3380
|
+
At as registerIcons,
|
|
3381
|
+
M as transform
|
|
2432
3382
|
};
|
|
2433
3383
|
//# sourceMappingURL=ry-ui.js.map
|