wj-elements 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/localize-20081fd1.js +55 -0
  2. package/dist/router-links-26e4a166.js +204 -0
  3. package/dist/style.css +2243 -2
  4. package/dist/wj-animation.js +35 -23
  5. package/dist/wj-aside.js +22 -16
  6. package/dist/wj-avatar.js +49 -30
  7. package/dist/wj-badge.js +22 -18
  8. package/dist/wj-breadcrumb.js +102 -50
  9. package/dist/wj-breadcrumbs.js +36 -19
  10. package/dist/wj-button-group.js +36 -22
  11. package/dist/wj-button.js +104 -39
  12. package/dist/wj-card-content.js +18 -14
  13. package/dist/wj-card-controls.js +18 -14
  14. package/dist/wj-card-header.js +20 -14
  15. package/dist/wj-card-subtitle.js +19 -15
  16. package/dist/wj-card-title.js +18 -14
  17. package/dist/wj-card.js +20 -14
  18. package/dist/wj-carousel-item.js +22 -16
  19. package/dist/wj-carousel.js +169 -92
  20. package/dist/wj-checkbox.js +46 -24
  21. package/dist/wj-chip.js +39 -21
  22. package/dist/wj-col.js +31 -17
  23. package/dist/wj-color-picker.js +877 -509
  24. package/dist/wj-container.js +20 -16
  25. package/dist/wj-copy-button.js +112 -64
  26. package/dist/wj-dialog.js +68 -42
  27. package/dist/wj-divider.js +20 -14
  28. package/dist/wj-dropdown.js +29 -17
  29. package/dist/wj-element.js +415 -241
  30. package/dist/wj-fetchAndParseCSS.js +49 -32
  31. package/dist/wj-file-upload-item.js +64 -38
  32. package/dist/wj-file-upload.js +237 -137
  33. package/dist/wj-footer.js +18 -14
  34. package/dist/wj-form.js +18 -14
  35. package/dist/wj-format-digital.js +40 -25
  36. package/dist/wj-grid.js +20 -16
  37. package/dist/wj-header.js +22 -16
  38. package/dist/wj-icon-picker.js +122 -68
  39. package/dist/wj-icon.js +144 -64
  40. package/dist/wj-img-comparer.js +72 -41
  41. package/dist/wj-img.js +31 -19
  42. package/dist/wj-infinite-scroll.js +90 -52
  43. package/dist/wj-input-file.js +50 -27
  44. package/dist/wj-input.js +169 -70
  45. package/dist/wj-item.js +34 -17
  46. package/dist/wj-label.js +21 -19
  47. package/dist/wj-list.js +20 -15
  48. package/dist/wj-main.js +18 -14
  49. package/dist/wj-masonry.js +140 -83
  50. package/dist/wj-master.js +492 -350
  51. package/dist/wj-menu-button.js +19 -15
  52. package/dist/wj-menu-item.js +150 -64
  53. package/dist/wj-menu-label.js +21 -17
  54. package/dist/wj-menu.js +24 -18
  55. package/dist/wj-popup.js +1140 -712
  56. package/dist/wj-progress-bar.js +100 -40
  57. package/dist/wj-radio-group.js +38 -25
  58. package/dist/wj-radio.js +46 -22
  59. package/dist/wj-rate.js +121 -71
  60. package/dist/wj-relative-time.js +48 -24
  61. package/dist/wj-route.js +11 -8
  62. package/dist/wj-router-link.js +22 -17
  63. package/dist/wj-router-outlet.js +135 -71
  64. package/dist/wj-routerx.js +1124 -641
  65. package/dist/wj-row.js +21 -19
  66. package/dist/wj-slider.js +97 -55
  67. package/dist/wj-split-view.js +81 -43
  68. package/dist/wj-store.js +195 -110
  69. package/dist/wj-textarea.js +86 -37
  70. package/dist/wj-thumbnail.js +19 -15
  71. package/dist/wj-toast.js +87 -34
  72. package/dist/wj-toggle.js +42 -24
  73. package/dist/wj-toolbar-action.js +27 -16
  74. package/dist/wj-toolbar.js +26 -19
  75. package/dist/wj-tooltip.js +40 -24
  76. package/dist/wj-visually-hidden.js +18 -14
  77. package/package.json +1 -1
  78. package/dist/localize-762a9f0f.js +0 -43
  79. package/dist/router-links-e0087f84.js +0 -146
@@ -1,18 +1,21 @@
1
- var m = Object.defineProperty;
2
- var A = (i, o, e) => o in i ? m(i, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[o] = e;
3
- var g = (i, o, e) => (A(i, typeof o != "symbol" ? o + "" : o, e), e);
4
- import j from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- const k = `:host(.wj-color-primary) #bar{--wj-progress-bar-color: var(--wj-color-primary)}:host(.wj-color-complete) #bar{--wj-progress-bar-color: var(--wj-color-complete)}:host(.wj-color-success) #bar{--wj-progress-bar-color: var(--wj-color-success)}:host(.wj-color-warning) #bar{--wj-progress-bar-color: var(--wj-color-warning)}:host(.wj-color-danger) #bar{--wj-progress-bar-color: var(--wj-color-danger)}:host(.wj-color-dark) #bar{--wj-progress-bar-color: var(--wj-color-contrast-0)}:host(.wj-color-light) #bar{--wj-progress-bar-color: var(--wj-color-contrast-11)}:host{--wj-progress-bar-color: var(--wj-color-contrast-6);--wj-progress-bar-text-size: .75rem;--wj-progress-bar-text-color: var(--wj-color)}:host .progress{position:relative;display:flex;align-items:center}:host .slot-wrapper{display:flex;position:absolute;top:0;align-items:center;width:100%;height:100%;justify-content:center}:host #bar{stroke:var(--wj-progress-bar-color)}:host text{transform:rotate(90deg);transform-origin:center;text-anchor:middle;dominant-baseline:middle;font-size:var(--wj-progress-bar-text-size);fill:var(--wj-progress-bar-text-color)}:host(.wj-color) #bar{stroke:var(--wj-progress-bar-color)}::slotted([slot=start]){margin-inline:0 1rem}::slotted([slot=end]){margin-inline:1rem 0}
7
- `;
8
- class f extends j {
9
+ const styles = "/*\n[ WJ Progress bar ]\n*/\n:host(.wj-color-primary) #bar {\n --wj-progress-bar-color: var(--wj-color-primary);\n}\n\n:host(.wj-color-complete) #bar {\n --wj-progress-bar-color: var(--wj-color-complete);\n}\n\n:host(.wj-color-success) #bar {\n --wj-progress-bar-color: var(--wj-color-success);\n}\n\n:host(.wj-color-warning) #bar {\n --wj-progress-bar-color: var(--wj-color-warning);\n}\n\n:host(.wj-color-danger) #bar {\n --wj-progress-bar-color: var(--wj-color-danger);\n}\n\n:host(.wj-color-dark) #bar {\n --wj-progress-bar-color: var(--wj-color-contrast-0);\n}\n\n:host(.wj-color-light) #bar {\n --wj-progress-bar-color: var(--wj-color-contrast-11);\n}\n\n:host {\n --wj-progress-bar-color: var(--wj-color-contrast-6);\n --wj-progress-bar-text-size: .75rem;\n --wj-progress-bar-text-color: var(--wj-color);\n}\n:host .progress {\n position: relative;\n display: flex;\n align-items: center;\n}\n:host .slot-wrapper {\n display: flex;\n position: absolute;\n top: 0;\n align-items: center;\n width: 100%;\n height: 100%;\n justify-content: center;\n}\n:host #bar {\n stroke: var(--wj-progress-bar-color);\n}\n:host text {\n transform: rotate(90deg);\n transform-origin: center;\n text-anchor: middle;\n dominant-baseline: middle;\n font-size: var(--wj-progress-bar-text-size);\n fill: var(--wj-progress-bar-text-color);\n}\n\n:host(.wj-color) #bar {\n stroke: var(--wj-progress-bar-color);\n}\n\n::slotted([slot=start]) {\n margin-inline: 0 1rem;\n}\n\n::slotted([slot=end]) {\n margin-inline: 1rem 0;\n}";
10
+ class ProgressBar extends WJElement {
9
11
  constructor() {
10
12
  super();
11
- g(this, "className", "ProgressBar");
12
- this.timerInterval = null, this.timeLimit = 60;
13
+ __publicField(this, "className", "ProgressBar");
14
+ this.timerInterval = null;
15
+ this.timeLimit = 60;
13
16
  }
14
- set radius(e) {
15
- this.setAttribute("radius", e);
17
+ set radius(value) {
18
+ this.setAttribute("radius", value);
16
19
  }
17
20
  get radius() {
18
21
  return +this.getAttribute("radius") || 70;
@@ -20,8 +23,8 @@ class f extends j {
20
23
  get diameter() {
21
24
  return this.radius * 2 + this.stroke;
22
25
  }
23
- set stroke(e) {
24
- this.setAttribute("stroke", e);
26
+ set stroke(value) {
27
+ this.setAttribute("stroke", value);
25
28
  }
26
29
  get stroke() {
27
30
  return +this.getAttribute("stroke") || 6;
@@ -30,7 +33,7 @@ class f extends j {
30
33
  return this.getAttribute("linecap") || "square";
31
34
  }
32
35
  static get cssStyleSheet() {
33
- return k;
36
+ return styles;
34
37
  }
35
38
  static get observedAttributes() {
36
39
  return ["progress"];
@@ -38,37 +41,94 @@ class f extends j {
38
41
  setupAttributes() {
39
42
  this.isShadowRoot = "open";
40
43
  }
41
- draw(e, h, l) {
42
- let n = this.radius + this.stroke / 2, d = document.createDocumentFragment();
43
- l.color && this.classList.add("wj-color-" + l.color, "wj-color");
44
- let a = document.createElement("div");
45
- a.classList.add("progress");
46
- let w = document.createElement("slot"), u = document.createElement("div");
47
- u.classList.add("slot-wrapper");
48
- let p = document.createElement("slot");
49
- p.setAttribute("name", "start");
50
- let b = document.createElement("slot");
51
- b.setAttribute("name", "end");
52
- let s = document.createElementNS("http://www.w3.org/2000/svg", "svg"), r, t;
44
+ draw(context, store, params) {
45
+ let xy = this.radius + this.stroke / 2;
46
+ let fragment = document.createDocumentFragment();
47
+ if (params.color)
48
+ this.classList.add("wj-color-" + params.color, "wj-color");
49
+ let element = document.createElement("div");
50
+ element.classList.add("progress");
51
+ let slot = document.createElement("slot");
52
+ let slotWrapper = document.createElement("div");
53
+ slotWrapper.classList.add("slot-wrapper");
54
+ let slotStart = document.createElement("slot");
55
+ slotStart.setAttribute("name", "start");
56
+ let slotEnd = document.createElement("slot");
57
+ slotEnd.setAttribute("name", "end");
58
+ let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
59
+ let background;
60
+ let bar;
53
61
  if ((this == null ? void 0 : this.type) === "circle") {
54
- s.setAttribute("width", this.diameter), s.setAttribute("height", this.diameter), s.setAttribute("viewBox", `0 0 ${this.diameter} ${this.diameter}`), s.setAttribute("style", "transform: rotate(-90deg)"), r = document.createElementNS("http://www.w3.org/2000/svg", "circle"), r.setAttribute("r", this.radius), r.setAttribute("cx", n), r.setAttribute("cy", n), r.setAttribute("fill", "transparent"), t = document.createElementNS("http://www.w3.org/2000/svg", "circle"), t.setAttribute("r", this.radius), t.setAttribute("cx", n), t.setAttribute("cy", n), t.setAttribute("fill", "transparent"), t.setAttribute("stroke-dasharray", "0"), t.setAttribute("stroke-dashoffset", "0");
55
- let c = document.createElementNS("http://www.w3.org/2000/svg", "text");
56
- c.setAttribute("x", "50%"), c.setAttribute("y", "50%"), c.innerHTML = this.progress + "%", s.appendChild(c);
57
- } else
58
- s.setAttribute("width", "100%"), s.setAttribute("height", this.stroke), s.setAttribute("preserveAspectRatio", "none"), r = document.createElementNS("http://www.w3.org/2000/svg", "line"), r.setAttribute("x1", 0), r.setAttribute("y1", this.stroke / 2), r.setAttribute("x2", "100%"), r.setAttribute("y2", this.stroke / 2), t = document.createElementNS("http://www.w3.org/2000/svg", "line"), t.setAttribute("x1", 0), t.setAttribute("y1", this.stroke / 2), t.setAttribute("x2", this.progress + "%"), t.setAttribute("y2", this.stroke / 2);
59
- return r.setAttribute("stroke", "#e0e0e0"), r.setAttribute("stroke-linecap", this.linecap), r.setAttribute("stroke-width", this.stroke + "px"), t.setAttribute("stroke-linecap", this.linecap), t.setAttribute("stroke-width", this.stroke + "px"), t.setAttribute("id", "bar"), s.appendChild(r), s.appendChild(t), u.appendChild(w), a.appendChild(p), a.appendChild(u), a.appendChild(s), a.appendChild(b), d.appendChild(a), this.background = r, this.bar = t, d;
62
+ svg.setAttribute("width", this.diameter);
63
+ svg.setAttribute("height", this.diameter);
64
+ svg.setAttribute("viewBox", `0 0 ${this.diameter} ${this.diameter}`);
65
+ svg.setAttribute("style", "transform: rotate(-90deg)");
66
+ background = document.createElementNS("http://www.w3.org/2000/svg", "circle");
67
+ background.setAttribute("r", this.radius);
68
+ background.setAttribute("cx", xy);
69
+ background.setAttribute("cy", xy);
70
+ background.setAttribute("fill", "transparent");
71
+ bar = document.createElementNS("http://www.w3.org/2000/svg", "circle");
72
+ bar.setAttribute("r", this.radius);
73
+ bar.setAttribute("cx", xy);
74
+ bar.setAttribute("cy", xy);
75
+ bar.setAttribute("fill", "transparent");
76
+ bar.setAttribute("stroke-dasharray", "0");
77
+ bar.setAttribute("stroke-dashoffset", "0");
78
+ let text = document.createElementNS("http://www.w3.org/2000/svg", "text");
79
+ text.setAttribute("x", "50%");
80
+ text.setAttribute("y", "50%");
81
+ text.innerHTML = this.progress + "%";
82
+ svg.appendChild(text);
83
+ } else {
84
+ svg.setAttribute("width", "100%");
85
+ svg.setAttribute("height", this.stroke);
86
+ svg.setAttribute("preserveAspectRatio", "none");
87
+ background = document.createElementNS("http://www.w3.org/2000/svg", "line");
88
+ background.setAttribute("x1", 0);
89
+ background.setAttribute("y1", this.stroke / 2);
90
+ background.setAttribute("x2", "100%");
91
+ background.setAttribute("y2", this.stroke / 2);
92
+ bar = document.createElementNS("http://www.w3.org/2000/svg", "line");
93
+ bar.setAttribute("x1", 0);
94
+ bar.setAttribute("y1", this.stroke / 2);
95
+ bar.setAttribute("x2", this.progress + "%");
96
+ bar.setAttribute("y2", this.stroke / 2);
97
+ }
98
+ background.setAttribute("stroke", "#e0e0e0");
99
+ background.setAttribute("stroke-linecap", this.linecap);
100
+ background.setAttribute("stroke-width", this.stroke + "px");
101
+ bar.setAttribute("stroke-linecap", this.linecap);
102
+ bar.setAttribute("stroke-width", this.stroke + "px");
103
+ bar.setAttribute("id", "bar");
104
+ svg.appendChild(background);
105
+ svg.appendChild(bar);
106
+ slotWrapper.appendChild(slot);
107
+ element.appendChild(slotStart);
108
+ element.appendChild(slotWrapper);
109
+ element.appendChild(svg);
110
+ element.appendChild(slotEnd);
111
+ fragment.appendChild(element);
112
+ this.background = background;
113
+ this.bar = bar;
114
+ return fragment;
60
115
  }
61
- afterDraw(e, h, l) {
62
- this.type === "circle" && (this.background.setAttribute("stroke-dasharray", this.getCircleDashoffset(100) + "px"), this.background.setAttribute("stroke-dashoffset", "0px"), this.bar.setAttribute("stroke-dasharray", this.getCircleDasharray(this.radius) + "px"), this.bar.setAttribute("stroke-dashoffset", this.getCircleDashoffset(l.progress, this.radius) + "px"));
116
+ afterDraw(context, store, params) {
117
+ if (this.type === "circle") {
118
+ this.background.setAttribute("stroke-dasharray", this.getCircleDashoffset(100) + "px");
119
+ this.background.setAttribute("stroke-dashoffset", "0px");
120
+ this.bar.setAttribute("stroke-dasharray", this.getCircleDasharray(this.radius) + "px");
121
+ this.bar.setAttribute("stroke-dashoffset", this.getCircleDashoffset(params.progress, this.radius) + "px");
122
+ }
63
123
  }
64
- getCircleDasharray(e = 70) {
65
- return 2 * Math.PI * e;
124
+ getCircleDasharray(radius = 70) {
125
+ return 2 * Math.PI * radius;
66
126
  }
67
- getCircleDashoffset(e = 0, h) {
68
- return this.getCircleDasharray(h) * ((100 - e) / 100);
127
+ getCircleDashoffset(progress = 0, radius) {
128
+ return this.getCircleDasharray(radius) * ((100 - progress) / 100);
69
129
  }
70
130
  }
71
- customElements.get("wj-progress-bar") || window.customElements.define("wj-progress-bar", f);
131
+ customElements.get("wj-progress-bar") || window.customElements.define("wj-progress-bar", ProgressBar);
72
132
  export {
73
- f as ProgressBar
133
+ ProgressBar
74
134
  };
@@ -1,18 +1,20 @@
1
- var d = Object.defineProperty;
2
- var c = (i, t, e) => t in i ? d(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
- var n = (i, t, e) => (c(i, typeof t != "symbol" ? t + "" : t, e), e);
4
- import u from "./wj-element.js";
5
- import { Radio as o } from "./wj-radio.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
8
+ import { Radio } from "./wj-radio.js";
6
9
  import "./wj-store.js";
7
- const h = `.wj-inline{display:flex;flex-direction:row;flex-wrap:wrap;gap:.5rem}
8
- `;
9
- class m extends u {
10
+ const styles = "/*\n[ WJ Radio Group ]\n*/\n.wj-inline {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n gap: 0.5rem;\n}";
11
+ class RadioGroup extends WJElement {
10
12
  constructor() {
11
13
  super();
12
- n(this, "className", "RadioGroup");
14
+ __publicField(this, "className", "RadioGroup");
13
15
  }
14
16
  static get cssStyleSheet() {
15
- return h;
17
+ return styles;
16
18
  }
17
19
  static get observedAttributes() {
18
20
  return [];
@@ -20,33 +22,44 @@ class m extends u {
20
22
  setupAttributes() {
21
23
  this.isShadowRoot = "open";
22
24
  }
23
- draw(e, s, p) {
24
- let a = document.createDocumentFragment(), r = document.createElement("div");
25
- r.classList.add("native-radio-group", this.hasAttribute("inline") ? "wj-inline" : "ddd");
26
- let l = document.createElement("slot");
27
- return r.appendChild(l), a.appendChild(r), a;
25
+ draw(context, store, params) {
26
+ let fragment = document.createDocumentFragment();
27
+ let native = document.createElement("div");
28
+ native.classList.add("native-radio-group", this.hasAttribute("inline") ? "wj-inline" : "ddd");
29
+ let slot = document.createElement("slot");
30
+ native.appendChild(slot);
31
+ fragment.appendChild(native);
32
+ return fragment;
28
33
  }
29
34
  afterDraw() {
30
- this.value && this.setRadioToChekced(this.getRadioByValue(this.value)), this.addEventListener("wj:radio:input", (e) => {
31
- this.removeCheck(), this.setRadioToChekced(e.detail.context);
35
+ if (this.value) {
36
+ this.setRadioToChekced(this.getRadioByValue(this.value));
37
+ }
38
+ this.addEventListener("wj:radio:input", (e) => {
39
+ this.removeCheck();
40
+ this.setRadioToChekced(e.detail.context);
32
41
  });
33
42
  }
34
- getRadioByValue(e) {
35
- return this.getAllElements().filter((s) => s instanceof o && s.value === e)[0];
43
+ getRadioByValue(value) {
44
+ return this.getAllElements().filter((el) => el instanceof Radio && el.value === value)[0];
36
45
  }
37
46
  removeCheck() {
38
- this.getAllElements().forEach((e) => {
39
- e instanceof o && (e.checked = !1);
47
+ this.getAllElements().forEach((el) => {
48
+ if (el instanceof Radio)
49
+ el.checked = false;
40
50
  });
41
51
  }
42
- setRadioToChekced(e) {
43
- e instanceof o && (this.setAttribute("value", e.value), e.checked = !0);
52
+ setRadioToChekced(radio) {
53
+ if (radio instanceof Radio) {
54
+ this.setAttribute("value", radio.value);
55
+ radio.checked = true;
56
+ }
44
57
  }
45
58
  getAllElements() {
46
59
  return Array.from(this.childNodes);
47
60
  }
48
61
  }
49
- customElements.get("wj-radio-group") || window.customElements.define("wj-radio-group", m);
62
+ customElements.get("wj-radio-group") || window.customElements.define("wj-radio-group", RadioGroup);
50
63
  export {
51
- m as RadioGroup
64
+ RadioGroup
52
65
  };
package/dist/wj-radio.js CHANGED
@@ -1,27 +1,33 @@
1
- var c = Object.defineProperty;
2
- var l = (i, t, e) => t in i ? c(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
- var a = (i, t, e) => (l(i, typeof t != "symbol" ? t + "" : t, e), e);
4
- import s, { event as n } from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement, { event } from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- const p = `:host{--wj-radio-margin-top: 0;--wj-radio-margin-bottom: .5rem;--wj-radio-margin-inline: 0;display:block;margin-top:var(--wj-radio-margin-top);margin-bottom:var(--wj-radio-margin-bottom);margin-inline:var(--wj-radio-margin-inline);line-height:100%;padding-left:0}:host label{display:inline-flex;cursor:pointer;position:relative;padding-left:1.5rem;min-width:16px;min-height:16px;margin-bottom:0;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;align-items:center}:host label:before{content:"";position:absolute;width:16px;height:16px;left:0;-webkit-box-sizing:inherit;box-sizing:border-box;background-color:var(--wj-color-contrast-1);border:1px solid var(--wj-color-contrast-4)}.native-radio input[type=radio]+label:before{border-radius:var(--wj-border-radius-circle);transition:border .3s 0s cubic-bezier(.455,.03,.215,1.33)}.native-radio input[type=radio]:checked+label:before{border-color:var(--wj-color-contrast-6);border-width:5px}.native-radio input[type=radio]:focus+label{color:var(--wj-color)}.native-radio input[type=radio]:focus+label:before{outline:none!important;box-shadow:0 0 #78c8fe}.native-radio input[type=radio]{opacity:0;position:absolute;top:3px;width:16px;height:16px}.native-radio input[type=radio][disabled]+label{cursor:not-allowed!important;color:var(--wj-color-contrast-9);opacity:.5}.native-radio input[type=radio][disabled]+label:before{cursor:not-allowed!important}.success input[type=radio]:checked+label:before{border-color:var(--wj-color-success)}.primary input[type=radio]:checked+label:before{border-color:var(--wj-color-primary)}.complete input[type=radio]:checked+label:before{border-color:var(--wj-color-complete)}.warning input[type=radio]:checked+label:before{border-color:var(--wj-color-warning)}.danger input[type=radio]:checked+label:before{border-color:var(--wj-color-danger)}.neutral input[type=radio]:checked+label:before{border-color:var(--wj-color-info)}
7
- `;
8
- class h extends s {
9
+ const styles = '/*\n[ WJ Radio ]\n*/\n:host {\n --wj-radio-margin-top: 0;\n --wj-radio-margin-bottom: .5rem;\n --wj-radio-margin-inline: 0;\n display: block;\n margin-top: var(--wj-radio-margin-top);\n margin-bottom: var(--wj-radio-margin-bottom);\n margin-inline: var(--wj-radio-margin-inline);\n line-height: 100%;\n padding-left: 0;\n}\n:host label {\n display: inline-flex;\n cursor: pointer;\n position: relative;\n padding-left: 1.5rem;\n min-width: 16px;\n min-height: 16px;\n margin-bottom: 0;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -moz-user-select: none; /* Old versions of Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera and Firefox */\n align-items: center;\n}\n:host label:before {\n content: "";\n position: absolute;\n width: 16px;\n height: 16px;\n left: 0;\n -webkit-box-sizing: inherit;\n box-sizing: border-box;\n background-color: var(--wj-color-contrast-1);\n border: 1px solid var(--wj-color-contrast-4);\n}\n\n.native-radio input[type=radio] + label:before {\n border-radius: var(--wj-border-radius-circle);\n transition: border 0.3s 0s cubic-bezier(0.455, 0.03, 0.215, 1.33);\n}\n.native-radio input[type=radio]:checked + label:before {\n border-color: var(--wj-color-contrast-6);\n border-width: 5px;\n}\n.native-radio input[type=radio]:focus + label {\n color: var(--wj-color);\n}\n.native-radio input[type=radio]:focus + label:before {\n outline: none !important;\n box-shadow: 0 0 0 0 #78c8fe;\n}\n.native-radio input[type=radio] {\n opacity: 0;\n position: absolute;\n top: 3px;\n width: 16px;\n height: 16px;\n}\n.native-radio input[type=radio][disabled] + label {\n cursor: not-allowed !important;\n color: var(--wj-color-contrast-9);\n opacity: 0.5;\n}\n.native-radio input[type=radio][disabled] + label:before {\n cursor: not-allowed !important;\n}\n\n.success input[type=radio]:checked + label:before {\n border-color: var(--wj-color-success);\n}\n.primary input[type=radio]:checked + label:before {\n border-color: var(--wj-color-primary);\n}\n.complete input[type=radio]:checked + label:before {\n border-color: var(--wj-color-complete);\n}\n.warning input[type=radio]:checked + label:before {\n border-color: var(--wj-color-warning);\n}\n.danger input[type=radio]:checked + label:before {\n border-color: var(--wj-color-danger);\n}\n.neutral input[type=radio]:checked + label:before {\n border-color: var(--wj-color-info);\n}';
10
+ class Radio extends WJElement {
9
11
  constructor() {
10
12
  super();
11
- a(this, "className", "Radio");
12
- a(this, "inputEvent", (e) => {
13
+ __publicField(this, "className", "Radio");
14
+ __publicField(this, "inputEvent", (e) => {
13
15
  this.checked = e.target.checked;
14
16
  });
15
- this._checked = !1;
17
+ this._checked = false;
16
18
  }
17
- set checked(e) {
18
- this._checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked");
19
+ set checked(value) {
20
+ this._checked = value;
21
+ if (value)
22
+ this.setAttribute("checked", "");
23
+ else
24
+ this.removeAttribute("checked");
19
25
  }
20
26
  get checked() {
21
27
  return this._checked;
22
28
  }
23
29
  static get cssStyleSheet() {
24
- return p;
30
+ return styles;
25
31
  }
26
32
  static get observedAttributes() {
27
33
  return ["checked"];
@@ -29,20 +35,38 @@ class h extends s {
29
35
  setupAttributes() {
30
36
  this.isShadowRoot = "open";
31
37
  }
32
- draw(e, b, u) {
33
- let d = document.createDocumentFragment(), r = document.createElement("div");
34
- r.classList.add("native-radio"), this.color && r.classList.add(this.color), this.input = document.createElement("input"), this.input.type = "radio", this.input.id = "radio", this.input.name = this.name + "-radio", this.input.checked = this.hasAttribute("checked"), this.input.disabled = this.hasAttribute("disabled"), this.input.indeterminate = this.hasAttribute("indeterminate");
35
- let o = document.createElement("label");
36
- return o.htmlFor = "radio", o.innerHTML = "<slot></slot>", r.appendChild(this.input), r.appendChild(o), d.appendChild(r), d;
38
+ draw(context, store, params) {
39
+ let fragment = document.createDocumentFragment();
40
+ let native = document.createElement("div");
41
+ native.classList.add("native-radio");
42
+ if (this.color)
43
+ native.classList.add(this.color);
44
+ this.input = document.createElement("input");
45
+ this.input.type = "radio";
46
+ this.input.id = "radio";
47
+ this.input.name = this.name + "-radio";
48
+ this.input.checked = this.hasAttribute("checked");
49
+ this.input.disabled = this.hasAttribute("disabled");
50
+ this.input.indeterminate = this.hasAttribute("indeterminate");
51
+ let label = document.createElement("label");
52
+ label.htmlFor = "radio";
53
+ label.innerHTML = "<slot></slot>";
54
+ native.appendChild(this.input);
55
+ native.appendChild(label);
56
+ fragment.appendChild(native);
57
+ return fragment;
37
58
  }
38
59
  afterDraw() {
39
- this.hasAttribute("disabled") || (n.addListener(this, "click", "wj:radio:change"), n.addListener(this, "click", "wj:radio:input"));
60
+ if (!this.hasAttribute("disabled")) {
61
+ event.addListener(this, "click", "wj:radio:change");
62
+ event.addListener(this, "click", "wj:radio:input");
63
+ }
40
64
  }
41
65
  disconnectedCallback() {
42
- n.removeElement(this);
66
+ event.removeElement(this);
43
67
  }
44
68
  }
45
- customElements.get("wj-radio") || window.customElements.define("wj-radio", h);
69
+ customElements.get("wj-radio") || window.customElements.define("wj-radio", Radio);
46
70
  export {
47
- h as Radio
71
+ Radio
48
72
  };
package/dist/wj-rate.js CHANGED
@@ -1,127 +1,177 @@
1
- var c = Object.defineProperty;
2
- var u = (a, o, e) => o in a ? c(a, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[o] = e;
3
- var n = (a, o, e) => (u(a, typeof o != "symbol" ? o + "" : o, e), e);
4
- import d from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- const v = `:host{display:flex}.native-rate{position:relative;display:flex;gap:var(--wj-rate-gap, .25rem)}.wj-rate-icon{position:relative;cursor:pointer}.selected{color:var(--wj-color-danger)}:host(:not([readonly])) .wj-rate-icon:hover{transform:scale(1.2)}.half wj-icon:first-child{color:#fff}.half wj-icon:last-child{color:currentColor;position:absolute;top:0;left:0}:host([disabled]) .native-rate{pointer-events:none;opacity:.5}
7
- `;
8
- class m extends d {
9
+ const styles = "/*\n[ WJ Rate ]\n*/\n:host {\n display: flex;\n}\n\n.native-rate {\n position: relative;\n display: flex;\n gap: var(--wj-rate-gap, 0.25rem);\n}\n\n.wj-rate-icon {\n position: relative;\n cursor: pointer;\n}\n\n.selected {\n color: var(--wj-color-danger);\n}\n\n:host(:not([readonly])) .wj-rate-icon:hover {\n transform: scale(1.2);\n}\n\n.half wj-icon:first-child {\n color: white;\n}\n\n.half wj-icon:last-child {\n color: currentColor;\n position: absolute;\n top: 0;\n left: 0;\n}\n\n:host([disabled]) .native-rate {\n pointer-events: none;\n opacity: 0.5;\n}";
10
+ class Rate extends WJElement {
9
11
  constructor() {
10
12
  super();
11
- n(this, "className", "Rate");
13
+ __publicField(this, "className", "Rate");
12
14
  /*
13
15
  * Events - Mouse
14
16
  */
15
- n(this, "onMouseEnter", (e) => {
16
- e.preventDefault(), this.hoverValue = this.getValueFromXPosition(e.clientX), this.changeRate();
17
+ __publicField(this, "onMouseEnter", (e) => {
18
+ e.preventDefault();
19
+ this.hoverValue = this.getValueFromXPosition(e.clientX);
20
+ this.changeRate();
17
21
  });
18
- n(this, "onMouseLeave", (e) => {
19
- e.preventDefault(), this.hoverValue = 0, this.changeRate();
22
+ __publicField(this, "onMouseLeave", (e) => {
23
+ e.preventDefault();
24
+ this.hoverValue = 0;
25
+ this.changeRate();
20
26
  });
21
- n(this, "onMouseMove", (e) => {
27
+ __publicField(this, "onMouseMove", (e) => {
22
28
  e.preventDefault();
23
- let i = this.getValueFromXPosition(e.clientX);
24
- i != this.hoverValue && (this.hoverValue = i, this.changeRate());
29
+ let newValue = this.getValueFromXPosition(e.clientX);
30
+ if (newValue != this.hoverValue) {
31
+ this.hoverValue = newValue;
32
+ this.changeRate();
33
+ }
25
34
  });
26
35
  /*
27
36
  * Events - Touch
28
37
  */
29
- n(this, "onTouchStart", (e) => {
30
- e.preventDefault(), this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX), this.changeRate();
38
+ __publicField(this, "onTouchStart", (e) => {
39
+ e.preventDefault();
40
+ this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);
41
+ this.changeRate();
31
42
  });
32
- n(this, "onTouchEnd", (e) => {
33
- e.preventDefault(), this.hoverValue = 0, this.changeRate();
43
+ __publicField(this, "onTouchEnd", (e) => {
44
+ e.preventDefault();
45
+ this.hoverValue = 0;
46
+ this.changeRate();
34
47
  });
35
- n(this, "onTouchMove", (e) => {
36
- e.preventDefault(), this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX), this.changeRate();
48
+ __publicField(this, "onTouchMove", (e) => {
49
+ e.preventDefault();
50
+ this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);
51
+ this.changeRate();
37
52
  });
38
- n(this, "onClick", (e) => {
39
- e.preventDefault(), this.value = +this.hoverValue;
53
+ __publicField(this, "onClick", (e) => {
54
+ e.preventDefault();
55
+ this.value = +this.hoverValue;
40
56
  });
41
57
  }
42
- set precision(e) {
43
- this.setAttribute("precision", e);
58
+ set precision(value) {
59
+ this.setAttribute("precision", value);
44
60
  }
45
61
  get precision() {
46
62
  return this.hasAttribute("precision") ? +this.getAttribute("precision") : 1;
47
63
  }
48
- set max(e) {
49
- this.setAttribute("max", e);
64
+ set max(value) {
65
+ this.setAttribute("max", value);
50
66
  }
51
67
  get max() {
52
68
  return this.hasAttribute("icons") ? this.icons.length : +this.getAttribute("max");
53
69
  }
54
- set icons(e) {
55
- return e;
70
+ set icons(value) {
71
+ return value;
56
72
  }
57
73
  get icons() {
58
74
  return this.hasAttribute("icons") ? JSON.parse(this.getAttribute("icons").replace(/'/g, '"')) : ["star-filled"];
59
75
  }
60
- set value(e) {
61
- this.setAttribute("value", e);
76
+ set value(value) {
77
+ this.setAttribute("value", value);
62
78
  }
63
79
  get value() {
64
80
  return this.hasAttribute("value") ? +this.getAttribute("value") : 0;
65
81
  }
66
82
  static get cssStyleSheet() {
67
- return v;
83
+ return styles;
68
84
  }
69
85
  static get observedAttributes() {
70
86
  return ["is-hover"];
71
87
  }
72
- attributeChangedCallback(e, i, t) {
88
+ attributeChangedCallback(name, old, newName) {
73
89
  }
74
90
  setupAttributes() {
75
91
  this.isShadowRoot = "open";
76
92
  }
77
- draw(e, i, t) {
78
- let r = document.createDocumentFragment(), s = document.createElement("div");
79
- if (s.setAttribute("part", "native"), s.classList.add("native-rate"), this.native = s, this.hasAttribute("icons")) {
80
- let h = this.icons;
81
- for (let l = 0; l < h.length; l++)
82
- s.appendChild(this.createIcons(l));
83
- } else
84
- for (let h = 0; h < this.max; h++)
85
- s.appendChild(this.createIcons(h));
86
- return this.changeRate(), r.appendChild(s), r;
93
+ draw(context, store, params) {
94
+ let fragment = document.createDocumentFragment();
95
+ let native = document.createElement("div");
96
+ native.setAttribute("part", "native");
97
+ native.classList.add("native-rate");
98
+ this.native = native;
99
+ if (this.hasAttribute("icons")) {
100
+ let icons = this.icons;
101
+ for (let i = 0; i < icons.length; i++) {
102
+ native.appendChild(this.createIcons(i));
103
+ }
104
+ } else {
105
+ for (let i = 0; i < this.max; i++) {
106
+ native.appendChild(this.createIcons(i));
107
+ }
108
+ }
109
+ this.changeRate();
110
+ fragment.appendChild(native);
111
+ return fragment;
87
112
  }
88
113
  afterDraw() {
89
- this.hasAttribute("disabled") || this.hasAttribute("readonly") || (this.addEventListener("mouseenter", this.onMouseEnter), this.addEventListener("mouseleave", this.onMouseLeave), this.addEventListener("mousemove", this.onMouseMove), this.addEventListener("touchstart", this.onTouchStart), this.addEventListener("touchend", this.onTouchEnd), this.addEventListener("touchmove", this.onTouchMove), this.addEventListener("click", this.onClick));
90
- }
91
- createIcons(e) {
92
- let i = document.createElement("div");
93
- i.classList.add("wj-rate-icon");
94
- let t = this.getIcons(e);
95
- if (i.appendChild(t), this.value > e && this.value < e + 1) {
96
- let r = t.cloneNode(!0);
97
- i.appendChild(r);
114
+ if (this.hasAttribute("disabled") || this.hasAttribute("readonly")) {
115
+ return;
116
+ }
117
+ this.addEventListener("mouseenter", this.onMouseEnter);
118
+ this.addEventListener("mouseleave", this.onMouseLeave);
119
+ this.addEventListener("mousemove", this.onMouseMove);
120
+ this.addEventListener("touchstart", this.onTouchStart);
121
+ this.addEventListener("touchend", this.onTouchEnd);
122
+ this.addEventListener("touchmove", this.onTouchMove);
123
+ this.addEventListener("click", this.onClick);
124
+ }
125
+ createIcons(i) {
126
+ let div = document.createElement("div");
127
+ div.classList.add("wj-rate-icon");
128
+ let icon = this.getIcons(i);
129
+ div.appendChild(icon);
130
+ if (this.value > i && this.value < i + 1) {
131
+ let clone = icon.cloneNode(true);
132
+ div.appendChild(clone);
98
133
  }
99
- return i;
134
+ return div;
100
135
  }
101
136
  changeRate() {
102
- const e = this.native.children, i = this.value !== this.hoverValue && this.hoverValue !== 0 && this.hoverValue !== void 0 ? this.hoverValue : this.value;
103
- for (let t = 0; t < e.length; t++)
104
- if (e[t].classList.remove("selected", "hovered"), e[t].children.length > 1 && (e[t].classList.remove("half"), e[t].querySelector("wj-icon:first-child").removeAttribute("style"), e[t].querySelector("wj-icon:last-child").remove()), t < i && e[t].classList.add("selected"), i > t && i < t + 1 && e[t].children.length === 1) {
105
- let r = e[t].querySelector("wj-icon").cloneNode(!0);
106
- e[t].appendChild(r);
107
- let s = (i - t) * 100;
108
- e[t].classList.add("half"), e[t].querySelector("wj-icon:first-child").style.clipPath = `inset(0 0 0 ${s}%)`, e[t].querySelector("wj-icon:last-child").style.clipPath = `inset(0 ${s}% 0 0)`;
137
+ const icons = this.native.children;
138
+ const rateValue = this.value !== this.hoverValue && this.hoverValue !== 0 && this.hoverValue !== void 0 ? this.hoverValue : this.value;
139
+ for (let i = 0; i < icons.length; i++) {
140
+ icons[i].classList.remove("selected", "hovered");
141
+ if (icons[i].children.length > 1) {
142
+ icons[i].classList.remove("half");
143
+ icons[i].querySelector("wj-icon:first-child").removeAttribute("style");
144
+ icons[i].querySelector("wj-icon:last-child").remove();
109
145
  }
146
+ if (i < rateValue) {
147
+ icons[i].classList.add("selected");
148
+ }
149
+ if (rateValue > i && rateValue < i + 1 && icons[i].children.length === 1) {
150
+ let clone = icons[i].querySelector("wj-icon").cloneNode(true);
151
+ icons[i].appendChild(clone);
152
+ let percent = (rateValue - i) * 100;
153
+ icons[i].classList.add("half");
154
+ icons[i].querySelector("wj-icon:first-child").style.clipPath = `inset(0 0 0 ${percent}%)`;
155
+ icons[i].querySelector("wj-icon:last-child").style.clipPath = `inset(0 ${percent}% 0 0)`;
156
+ }
157
+ }
110
158
  }
111
- getIcons(e) {
112
- let i = document.createElement("wj-icon");
113
- return i.setAttribute("name", this.max ? this.icons[0] : this.icons[e]), i;
159
+ getIcons(index) {
160
+ let icon = document.createElement("wj-icon");
161
+ icon.setAttribute("name", this.max ? this.icons[0] : this.icons[index]);
162
+ return icon;
114
163
  }
115
- getValueFromXPosition(e) {
116
- const { left: i, right: t, width: r } = this.native.getBoundingClientRect(), s = this.roundToPrecision((e - i) / r * this.max, this.precision);
117
- return Math.min(Math.max(s, 0), this.max);
164
+ getValueFromXPosition(coordinate) {
165
+ const { left, right, width } = this.native.getBoundingClientRect();
166
+ const value = this.roundToPrecision((coordinate - left) / width * this.max, this.precision);
167
+ return Math.min(Math.max(value, 0), this.max);
118
168
  }
119
- roundToPrecision(e, i = 0.5) {
120
- const t = 1 / i;
121
- return Math.ceil(e * t) / t;
169
+ roundToPrecision(numberToRound, precision = 0.5) {
170
+ const multiplier = 1 / precision;
171
+ return Math.ceil(numberToRound * multiplier) / multiplier;
122
172
  }
123
173
  }
124
- customElements.get("wj-rate") || window.customElements.define("wj-rate", m);
174
+ customElements.get("wj-rate") || window.customElements.define("wj-rate", Rate);
125
175
  export {
126
- m as Rate
176
+ Rate
127
177
  };