wj-elements 0.7.6 → 0.8.0

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 (234) hide show
  1. package/dist/animations.js +28 -51
  2. package/dist/animations.js.map +1 -1
  3. package/dist/base-path.js +19 -31
  4. package/dist/base-path.js.map +1 -1
  5. package/dist/custom-elements.json +9053 -9048
  6. package/dist/dark.css +1 -302
  7. package/dist/date.js +16 -36
  8. package/dist/date.js.map +1 -1
  9. package/dist/element-utils.js +20 -81
  10. package/dist/element-utils.js.map +1 -1
  11. package/dist/event.js +49 -165
  12. package/dist/event.js.map +1 -1
  13. package/dist/form-associated-element-BjeJn7j8.js +101 -0
  14. package/dist/{form-associated-element-DEQ4y-jn.js.map → form-associated-element-BjeJn7j8.js.map} +1 -1
  15. package/dist/icon-DmsqtDpL.js +102 -0
  16. package/dist/{icon-CReYMzAK.js.map → icon-DmsqtDpL.js.map} +1 -1
  17. package/dist/light.css +1 -731
  18. package/dist/localize.js +36 -111
  19. package/dist/localize.js.map +1 -1
  20. package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +3 -2
  21. package/dist/packages/wje-img/img.element.d.ts +4 -4
  22. package/dist/permissions.js +14 -41
  23. package/dist/permissions.js.map +1 -1
  24. package/dist/popup.element-CbkhthPP.js +806 -0
  25. package/dist/{popup.element-CwXvVFK7.js.map → popup.element-CbkhthPP.js.map} +1 -1
  26. package/dist/router-links-CNsJ-elb.js +105 -0
  27. package/dist/{router-links-wjqCnncc.js.map → router-links-CNsJ-elb.js.map} +1 -1
  28. package/dist/skeleton.css +1 -197
  29. package/dist/styles.css +1 -866
  30. package/dist/universal-service.js +48 -109
  31. package/dist/universal-service.js.map +1 -1
  32. package/dist/utils.js +11 -18
  33. package/dist/utils.js.map +1 -1
  34. package/dist/web-types.json +698 -698
  35. package/dist/wje-accordion-item.js +33 -106
  36. package/dist/wje-accordion-item.js.map +1 -1
  37. package/dist/wje-accordion.js +19 -84
  38. package/dist/wje-accordion.js.map +1 -1
  39. package/dist/wje-animation.js +37 -4258
  40. package/dist/wje-animation.js.map +1 -1
  41. package/dist/wje-aside.js +9 -34
  42. package/dist/wje-aside.js.map +1 -1
  43. package/dist/wje-avatar.js +36 -126
  44. package/dist/wje-avatar.js.map +1 -1
  45. package/dist/wje-badge.js +10 -52
  46. package/dist/wje-badge.js.map +1 -1
  47. package/dist/wje-breadcrumb.js +205 -668
  48. package/dist/wje-breadcrumb.js.map +1 -1
  49. package/dist/wje-breadcrumbs.js +177 -633
  50. package/dist/wje-breadcrumbs.js.map +1 -1
  51. package/dist/wje-button-group.js +48 -153
  52. package/dist/wje-button-group.js.map +1 -1
  53. package/dist/wje-button.js +92 -413
  54. package/dist/wje-button.js.map +1 -1
  55. package/dist/wje-card-content.js +7 -30
  56. package/dist/wje-card-content.js.map +1 -1
  57. package/dist/wje-card-controls.js +7 -30
  58. package/dist/wje-card-controls.js.map +1 -1
  59. package/dist/wje-card-header.js +7 -30
  60. package/dist/wje-card-header.js.map +1 -1
  61. package/dist/wje-card-subtitle.js +7 -34
  62. package/dist/wje-card-subtitle.js.map +1 -1
  63. package/dist/wje-card-title.js +7 -34
  64. package/dist/wje-card-title.js.map +1 -1
  65. package/dist/wje-card.js +15 -71
  66. package/dist/wje-card.js.map +1 -1
  67. package/dist/wje-carousel-item.js +12 -56
  68. package/dist/wje-carousel-item.js.map +1 -1
  69. package/dist/wje-carousel.js +154 -509
  70. package/dist/wje-carousel.js.map +1 -1
  71. package/dist/wje-checkbox.js +50 -227
  72. package/dist/wje-checkbox.js.map +1 -1
  73. package/dist/wje-chip.js +43 -160
  74. package/dist/wje-chip.js.map +1 -1
  75. package/dist/wje-col.js +7 -20
  76. package/dist/wje-col.js.map +1 -1
  77. package/dist/wje-color-picker.js +445 -1464
  78. package/dist/wje-color-picker.js.map +1 -1
  79. package/dist/wje-container.js +9 -35
  80. package/dist/wje-container.js.map +1 -1
  81. package/dist/wje-copy-button.js +64 -204
  82. package/dist/wje-copy-button.js.map +1 -1
  83. package/dist/wje-dialog.js +85 -553
  84. package/dist/wje-dialog.js.map +1 -1
  85. package/dist/wje-divider.js +7 -34
  86. package/dist/wje-divider.js.map +1 -1
  87. package/dist/wje-dropdown.js +78 -305
  88. package/dist/wje-dropdown.js.map +1 -1
  89. package/dist/wje-element.js +191 -700
  90. package/dist/wje-element.js.map +1 -1
  91. package/dist/wje-file-upload-item.js +51 -156
  92. package/dist/wje-file-upload-item.js.map +1 -1
  93. package/dist/wje-file-upload.js +181 -619
  94. package/dist/wje-file-upload.js.map +1 -1
  95. package/dist/wje-footer.js +7 -31
  96. package/dist/wje-footer.js.map +1 -1
  97. package/dist/wje-form.js +7 -32
  98. package/dist/wje-form.js.map +1 -1
  99. package/dist/wje-format-digital.js +26 -118
  100. package/dist/wje-format-digital.js.map +1 -1
  101. package/dist/wje-grid.js +7 -33
  102. package/dist/wje-grid.js.map +1 -1
  103. package/dist/wje-header.js +9 -35
  104. package/dist/wje-header.js.map +1 -1
  105. package/dist/wje-icon-library.js +12 -18
  106. package/dist/wje-icon-library.js.map +1 -1
  107. package/dist/wje-icon-picker.js +65 -320
  108. package/dist/wje-icon-picker.js.map +1 -1
  109. package/dist/wje-icon.js +1 -1
  110. package/dist/wje-img-comparer.js +37 -114
  111. package/dist/wje-img-comparer.js.map +1 -1
  112. package/dist/wje-img.js +50 -197
  113. package/dist/wje-img.js.map +1 -1
  114. package/dist/wje-infinite-scroll.js +94 -346
  115. package/dist/wje-infinite-scroll.js.map +1 -1
  116. package/dist/wje-input-file.js +23 -84
  117. package/dist/wje-input-file.js.map +1 -1
  118. package/dist/wje-input.js +78 -392
  119. package/dist/wje-input.js.map +1 -1
  120. package/dist/wje-item.js +11 -64
  121. package/dist/wje-item.js.map +1 -1
  122. package/dist/wje-kanban.js +124 -401
  123. package/dist/wje-kanban.js.map +1 -1
  124. package/dist/wje-label.js +9 -32
  125. package/dist/wje-label.js.map +1 -1
  126. package/dist/wje-level-indicator.js +38 -157
  127. package/dist/wje-level-indicator.js.map +1 -1
  128. package/dist/wje-list.js +10 -40
  129. package/dist/wje-list.js.map +1 -1
  130. package/dist/wje-main.js +7 -31
  131. package/dist/wje-main.js.map +1 -1
  132. package/dist/wje-masonry.js +66 -211
  133. package/dist/wje-masonry.js.map +1 -1
  134. package/dist/wje-master.js +45 -161
  135. package/dist/wje-master.js.map +1 -1
  136. package/dist/wje-menu-button.js +10 -38
  137. package/dist/wje-menu-button.js.map +1 -1
  138. package/dist/wje-menu-item.js +127 -577
  139. package/dist/wje-menu-item.js.map +1 -1
  140. package/dist/wje-menu-label.js +9 -35
  141. package/dist/wje-menu-label.js.map +1 -1
  142. package/dist/wje-menu.js +14 -49
  143. package/dist/wje-menu.js.map +1 -1
  144. package/dist/wje-option.js +48 -279
  145. package/dist/wje-option.js.map +1 -1
  146. package/dist/wje-options.js +130 -384
  147. package/dist/wje-options.js.map +1 -1
  148. package/dist/wje-orgchart-group.js +16 -52
  149. package/dist/wje-orgchart-group.js.map +1 -1
  150. package/dist/wje-orgchart-item.js +24 -93
  151. package/dist/wje-orgchart-item.js.map +1 -1
  152. package/dist/wje-orgchart.js +18 -68
  153. package/dist/wje-orgchart.js.map +1 -1
  154. package/dist/wje-pagination.js +113 -397
  155. package/dist/wje-pagination.js.map +1 -1
  156. package/dist/wje-popup.js +3 -3
  157. package/dist/wje-popup.js.map +1 -1
  158. package/dist/wje-progress-bar.js +53 -205
  159. package/dist/wje-progress-bar.js.map +1 -1
  160. package/dist/wje-qr-code.js +398 -2980
  161. package/dist/wje-qr-code.js.map +1 -1
  162. package/dist/wje-radio-group.js +52 -190
  163. package/dist/wje-radio-group.js.map +1 -1
  164. package/dist/wje-radio.js +24 -118
  165. package/dist/wje-radio.js.map +1 -1
  166. package/dist/wje-rate.js +62 -266
  167. package/dist/wje-rate.js.map +1 -1
  168. package/dist/wje-relative-time.js +24 -99
  169. package/dist/wje-relative-time.js.map +1 -1
  170. package/dist/wje-reorder-dropzone.js +9 -31
  171. package/dist/wje-reorder-dropzone.js.map +1 -1
  172. package/dist/wje-reorder-handle.js +67 -204
  173. package/dist/wje-reorder-handle.js.map +1 -1
  174. package/dist/wje-reorder-item.js +14 -44
  175. package/dist/wje-reorder-item.js.map +1 -1
  176. package/dist/wje-reorder.js +61 -246
  177. package/dist/wje-reorder.js.map +1 -1
  178. package/dist/wje-route.js +6 -24
  179. package/dist/wje-route.js.map +1 -1
  180. package/dist/wje-router-link.js +11 -39
  181. package/dist/wje-router-link.js.map +1 -1
  182. package/dist/wje-router-outlet.js +76 -172
  183. package/dist/wje-router-outlet.js.map +1 -1
  184. package/dist/wje-routerx.js +537 -1331
  185. package/dist/wje-routerx.js.map +1 -1
  186. package/dist/wje-row.js +9 -31
  187. package/dist/wje-row.js.map +1 -1
  188. package/dist/wje-select.js +326 -1152
  189. package/dist/wje-select.js.map +1 -1
  190. package/dist/wje-slider.js +44 -225
  191. package/dist/wje-slider.js.map +1 -1
  192. package/dist/wje-sliding-container.js +295 -1319
  193. package/dist/wje-sliding-container.js.map +1 -1
  194. package/dist/wje-split-view.js +35 -121
  195. package/dist/wje-split-view.js.map +1 -1
  196. package/dist/wje-status.js +14 -45
  197. package/dist/wje-status.js.map +1 -1
  198. package/dist/wje-step.js +9 -32
  199. package/dist/wje-step.js.map +1 -1
  200. package/dist/wje-stepper.js +109 -357
  201. package/dist/wje-stepper.js.map +1 -1
  202. package/dist/wje-store.js +67 -360
  203. package/dist/wje-store.js.map +1 -1
  204. package/dist/wje-tab-group.js +85 -314
  205. package/dist/wje-tab-group.js.map +1 -1
  206. package/dist/wje-tab-panel.js +7 -28
  207. package/dist/wje-tab-panel.js.map +1 -1
  208. package/dist/wje-tab.js +21 -198
  209. package/dist/wje-tab.js.map +1 -1
  210. package/dist/wje-textarea.js +64 -264
  211. package/dist/wje-textarea.js.map +1 -1
  212. package/dist/wje-thumbnail.js +10 -51
  213. package/dist/wje-thumbnail.js.map +1 -1
  214. package/dist/wje-toast.js +127 -632
  215. package/dist/wje-toast.js.map +1 -1
  216. package/dist/wje-toggle.js +52 -177
  217. package/dist/wje-toggle.js.map +1 -1
  218. package/dist/wje-toolbar-action.js +128 -456
  219. package/dist/wje-toolbar-action.js.map +1 -1
  220. package/dist/wje-toolbar.js +75 -270
  221. package/dist/wje-toolbar.js.map +1 -1
  222. package/dist/wje-tooltip.js +50 -161
  223. package/dist/wje-tooltip.js.map +1 -1
  224. package/dist/wje-tree-item.js +70 -301
  225. package/dist/wje-tree-item.js.map +1 -1
  226. package/dist/wje-tree.js +145 -489
  227. package/dist/wje-tree.js.map +1 -1
  228. package/dist/wje-visually-hidden.js +7 -34
  229. package/dist/wje-visually-hidden.js.map +1 -1
  230. package/package.json +4 -2
  231. package/dist/form-associated-element-DEQ4y-jn.js +0 -245
  232. package/dist/icon-CReYMzAK.js +0 -245
  233. package/dist/popup.element-CwXvVFK7.js +0 -2133
  234. package/dist/router-links-wjqCnncc.js +0 -156
package/dist/wje-rate.js CHANGED
@@ -1,322 +1,118 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import WJElement from "./wje-element.js";
5
- const styles = "/*\n[ WJ Rate ]\n*/\n\n:host {\n display: flex;\n color: var(--wje-rate-color);\n}\n\n:host([readonly]) .wje-rate-icon {\n cursor: default;\n}\n\n.native-rate {\n position: relative;\n display: flex;\n gap: var(--wje-rate-gap);\n}\n\n.wje-rate-icon {\n position: relative;\n cursor: pointer;\n}\n\n.selected {\n color: var(--wje-rate-selected-color);\n}\n\n:host(:not([readonly])) .wje-rate-icon:hover {\n transform: scale(1.2);\n}\n\nwje-icon:first-child {\n color: var(--wje-rate-color);\n}\n\nwje-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}\n";
6
- class Rate extends WJElement {
7
- /**
8
- * Creates an instance of Rate.
9
- * @class
10
- */
4
+ import t from "./wje-element.js";
5
+ class e extends t {
11
6
  constructor() {
12
7
  super();
13
- /**
14
- * Sets the hover value of the rating component.
15
- * @type {string}
16
- */
17
8
  __publicField(this, "className", "Rate");
18
- /**
19
- * Event handler for the mouse enter event.
20
- * @param {Event} e The event.
21
- */
22
- __publicField(this, "onMouseEnter", (e) => {
23
- e.preventDefault();
24
- this.hoverValue = this.getValueFromXPosition(e.clientX);
25
- this.changeRate();
9
+ __publicField(this, "onMouseEnter", (t2) => {
10
+ t2.preventDefault(), this.hoverValue = this.getValueFromXPosition(t2.clientX), this.changeRate();
26
11
  });
27
- /**
28
- * Event handler for the mouse leave event.
29
- * @param {Event} e The event.
30
- */
31
- __publicField(this, "onMouseLeave", (e) => {
32
- e.preventDefault();
33
- this.hoverValue = 0;
34
- this.changeRate();
12
+ __publicField(this, "onMouseLeave", (t2) => {
13
+ t2.preventDefault(), this.hoverValue = 0, this.changeRate();
35
14
  });
36
- /**
37
- * Event handler for the mouse move event.
38
- * @param {Event} e The event.
39
- */
40
- __publicField(this, "onMouseMove", (e) => {
41
- e.preventDefault();
42
- let newValue = +this.getValueFromXPosition(e.clientX);
43
- if (newValue !== +this.hoverValue) {
44
- this.hoverValue = newValue;
45
- this.changeRate();
46
- }
15
+ __publicField(this, "onMouseMove", (t2) => {
16
+ t2.preventDefault();
17
+ let e2 = +this.getValueFromXPosition(t2.clientX);
18
+ e2 !== +this.hoverValue && (this.hoverValue = e2, this.changeRate());
47
19
  });
48
- /**
49
- * Event handler for the touch start event.
50
- * @param {Event} e The event.
51
- */
52
- __publicField(this, "onTouchStart", (e) => {
53
- e.preventDefault();
54
- this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);
55
- this.changeRate();
20
+ __publicField(this, "onTouchStart", (t2) => {
21
+ t2.preventDefault(), this.hoverValue = this.getValueFromXPosition(t2.touches[0].clientX), this.changeRate();
56
22
  });
57
- /**
58
- * Event handler for the touch end event.
59
- * @param {Event} e The event.
60
- */
61
- __publicField(this, "onTouchEnd", (e) => {
62
- e.preventDefault();
63
- this.hoverValue = 0;
64
- this.changeRate();
23
+ __publicField(this, "onTouchEnd", (t2) => {
24
+ t2.preventDefault(), this.hoverValue = 0, this.changeRate();
65
25
  });
66
- /**
67
- * Event handler for the touch move event.
68
- * @param {Event} e The event.
69
- */
70
- __publicField(this, "onTouchMove", (e) => {
71
- e.preventDefault();
72
- this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);
73
- this.changeRate();
26
+ __publicField(this, "onTouchMove", (t2) => {
27
+ t2.preventDefault(), this.hoverValue = this.getValueFromXPosition(t2.touches[0].clientX), this.changeRate();
74
28
  });
75
- /**
76
- * Event handler for the click event.
77
- * @param {Event} e The event.
78
- */
79
- __publicField(this, "onClick", (e) => {
80
- e.preventDefault();
81
- this.value = +this.hoverValue;
29
+ __publicField(this, "onClick", (t2) => {
30
+ t2.preventDefault(), this.value = +this.hoverValue;
82
31
  });
83
32
  }
84
- /**
85
- * Sets the precision of the rating component.
86
- * @param {number} value The value to set.
87
- */
88
- set precision(value) {
89
- this.setAttribute("precision", value);
33
+ set precision(t2) {
34
+ this.setAttribute("precision", t2);
90
35
  }
91
- /**
92
- * Gets the precision of the rating component.
93
- * @returns {number} The value of the precision.
94
- */
95
36
  get precision() {
96
37
  return this.hasAttribute("precision") ? +this.getAttribute("precision") : 1;
97
38
  }
98
- /**
99
- * Sets the maximum value of the rating component.
100
- * @param {number} value The value to set.
101
- */
102
- set max(value) {
103
- this.setAttribute("max", value);
39
+ set max(t2) {
40
+ this.setAttribute("max", t2);
104
41
  }
105
- /**
106
- * Gets the maximum value of the rating component.
107
- * @returns {number} The value of the maximum value.
108
- */
109
42
  get max() {
110
43
  return this.hasAttribute("icons") ? this.icons.length : +this.getAttribute("max");
111
44
  }
112
- /**
113
- * Sets the icons of the rating component.
114
- * @param {Array<string>} value The value to set.
115
- */
116
- set icons(value) {
117
- return value;
45
+ set icons(t2) {
46
+ return t2;
118
47
  }
119
- /**
120
- * Gets the icons of the rating component.
121
- * @returns {Array<string>} The value of the icons.
122
- */
123
48
  get icons() {
124
49
  return this.hasAttribute("icons") ? JSON.parse(this.getAttribute("icons").replace(/'/g, '"')) : ["star"];
125
50
  }
126
- /**
127
- * Sets the value of the rating component.
128
- * @param {number} value The value to set.
129
- */
130
- set value(value) {
131
- this.setAttribute("value", value);
51
+ set value(t2) {
52
+ this.setAttribute("value", t2);
132
53
  }
133
- /**
134
- * Gets the value of the rating component.
135
- * @returns {number} The value of the rating component.
136
- */
137
54
  get value() {
138
55
  return this.hasAttribute("value") ? +this.getAttribute("value") : 0;
139
56
  }
140
- /**
141
- * Returns the CSS styles for the component.
142
- * @static
143
- * @returns {CSSStyleSheet}
144
- */
145
57
  static get cssStyleSheet() {
146
- return styles;
58
+ return ":host{display:flex;color:var(--wje-rate-color)}:host([readonly]) .wje-rate-icon{cursor:default}.native-rate{position:relative;display:flex;gap:var(--wje-rate-gap)}.wje-rate-icon{position:relative;cursor:pointer}.selected{color:var(--wje-rate-selected-color)}:host(:not([readonly])) .wje-rate-icon:hover{transform:scale(1.2)}wje-icon:first-child{color:var(--wje-rate-color)}wje-icon:last-child{color:currentColor;position:absolute;top:0;left:0}:host([disabled]) .native-rate{pointer-events:none;opacity:.5}";
147
59
  }
148
- /**
149
- * Returns the list of attributes to observe for changes.
150
- * @static
151
- * @returns {Array<string>}
152
- */
153
60
  static get observedAttributes() {
154
61
  return ["is-hover", "value", "max", "disabled", "readonly"];
155
62
  }
156
- /**
157
- * Called when an attribute changes.
158
- * @param {string} name The name of the attribute that changed.
159
- * @param {string} old The old value of the attribute.
160
- * @param {string} newName The new value of the attribute.
161
- */
162
- attributeChangedCallback(name, old, newName) {
163
- if (super.attributeChangedCallback) {
164
- super.attributeChangedCallback(name, old, newName);
165
- }
166
- if (old !== newName && name !== "is-hover") {
167
- this.syncAria();
168
- }
63
+ attributeChangedCallback(t2, e2, i) {
64
+ super.attributeChangedCallback && super.attributeChangedCallback(t2, e2, i), e2 !== i && "is-hover" !== t2 && this.syncAria();
169
65
  }
170
- /**
171
- * Sets up the attributes for the component.
172
- */
173
66
  setupAttributes() {
174
- this.isShadowRoot = "open";
175
- this.syncAria();
67
+ this.isShadowRoot = "open", this.syncAria();
176
68
  }
177
- /**
178
- * Draws the component for the rating component.
179
- * @returns {DocumentFragment}
180
- */
181
69
  draw() {
182
- let fragment = document.createDocumentFragment();
183
- let native = document.createElement("div");
184
- native.setAttribute("part", "native");
185
- native.classList.add("native-rate");
186
- this.native = native;
187
- if (this.hasAttribute("icons")) {
188
- let icons = this.icons;
189
- for (let i = 0; i < icons.length; i++) {
190
- native.appendChild(this.createIcons(i));
191
- }
192
- } else {
193
- for (let i = 0; i < this.max; i++) {
194
- native.appendChild(this.createIcons(i));
195
- }
196
- }
197
- this.changeRate();
198
- fragment.appendChild(native);
199
- return fragment;
70
+ let t2 = document.createDocumentFragment(), e2 = document.createElement("div");
71
+ if (e2.setAttribute("part", "native"), e2.classList.add("native-rate"), this.native = e2, this.hasAttribute("icons")) {
72
+ let t3 = this.icons;
73
+ for (let i = 0; i < t3.length; i++) e2.appendChild(this.createIcons(i));
74
+ } else for (let t3 = 0; t3 < this.max; t3++) e2.appendChild(this.createIcons(t3));
75
+ return this.changeRate(), t2.appendChild(e2), t2;
200
76
  }
201
- /**
202
- * Adds event listeners after the component is drawn.
203
- */
204
77
  afterDraw() {
205
- this.syncAria();
206
- if (this.hasAttribute("disabled") || this.hasAttribute("readonly")) {
207
- return;
208
- }
209
- this.addEventListener("mouseenter", this.onMouseEnter);
210
- this.addEventListener("mouseleave", this.onMouseLeave);
211
- this.addEventListener("mousemove", this.onMouseMove);
212
- this.addEventListener("touchstart", this.onTouchStart);
213
- this.addEventListener("touchend", this.onTouchEnd);
214
- this.addEventListener("touchmove", this.onTouchMove);
215
- this.addEventListener("click", this.onClick);
78
+ this.syncAria(), 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));
216
79
  }
217
- /**
218
- * Creates the icons for the rating component.
219
- * @param {number} i The index of the icon.
220
- * @returns {Element} The icon element.
221
- */
222
- createIcons(i) {
223
- let div = document.createElement("div");
224
- div.classList.add("wje-rate-icon");
225
- let icon = this.getIcons(i);
226
- let clone = icon.cloneNode(true);
227
- div.appendChild(icon);
228
- div.appendChild(clone);
229
- return div;
80
+ createIcons(t2) {
81
+ let e2 = document.createElement("div");
82
+ e2.classList.add("wje-rate-icon");
83
+ let i = this.getIcons(t2), s = i.cloneNode(true);
84
+ return e2.appendChild(i), e2.appendChild(s), e2;
230
85
  }
231
- /**
232
- * Changes the rate of the rating component.
233
- */
234
86
  changeRate() {
235
- const icons = this.native.children;
236
- const rateValue = this.value !== this.hoverValue && this.hoverValue !== 0 && this.hoverValue !== void 0 ? this.hoverValue : this.value;
237
- for (let i = 0; i < icons.length; i++) {
238
- const icon = icons[i];
239
- const firstIcon = icon.querySelector("wje-icon:first-child");
240
- const lastIcon = icon.querySelector("wje-icon:last-child");
241
- const isSelected = i < rateValue;
242
- const isPartial = rateValue > i && rateValue < i + 1;
243
- if (isSelected) {
244
- icon.classList.add("selected");
245
- if (this.hasAttribute("selected") && this.getAttribute("selected") === "filled") {
246
- lastIcon.setAttribute("filled", "");
247
- }
248
- } else {
249
- icon.classList.remove("selected");
250
- lastIcon.removeAttribute("filled");
251
- }
252
- if (isPartial) {
253
- const percent = ((rateValue - i) * 100).toFixed(2);
254
- icon.classList.add("half");
255
- firstIcon.style.clipPath = `inset(0 0 0 ${percent}%)`;
256
- lastIcon.style.clipPath = `inset(0 ${100 - percent}% 0 0)`;
257
- lastIcon.removeAttribute("hidden");
258
- } else {
259
- icon.classList.remove("half");
260
- firstIcon.style.clipPath = ``;
261
- lastIcon.style.clipPath = ``;
262
- lastIcon.setAttribute("hidden", "");
263
- }
264
- icon.setAttribute("data-index", i);
265
- icon.setAttribute("data-rate", rateValue);
87
+ const t2 = this.native.children, e2 = this.value !== this.hoverValue && 0 !== this.hoverValue && void 0 !== this.hoverValue ? this.hoverValue : this.value;
88
+ for (let i = 0; i < t2.length; i++) {
89
+ const s = t2[i], a = s.querySelector("wje-icon:first-child"), r = s.querySelector("wje-icon:last-child"), o = e2 > i && e2 < i + 1;
90
+ if (i < e2 ? (s.classList.add("selected"), this.hasAttribute("selected") && "filled" === this.getAttribute("selected") && r.setAttribute("filled", "")) : (s.classList.remove("selected"), r.removeAttribute("filled")), o) {
91
+ const t3 = (100 * (e2 - i)).toFixed(2);
92
+ s.classList.add("half"), a.style.clipPath = `inset(0 0 0 ${t3}%)`, r.style.clipPath = `inset(0 ${100 - t3}% 0 0)`, r.removeAttribute("hidden");
93
+ } else s.classList.remove("half"), a.style.clipPath = "", r.style.clipPath = "", r.setAttribute("hidden", "");
94
+ s.setAttribute("data-index", i), s.setAttribute("data-rate", e2);
266
95
  }
267
96
  this.syncAria();
268
97
  }
269
- /**
270
- * Sync ARIA attributes on host.
271
- */
272
98
  syncAria() {
273
- this.setAriaState({
274
- role: "slider",
275
- valuemin: 0,
276
- valuemax: this.max,
277
- valuenow: this.value,
278
- disabled: this.hasAttribute("disabled"),
279
- readonly: this.hasAttribute("readonly")
280
- });
99
+ this.setAriaState({ role: "slider", valuemin: 0, valuemax: this.max, valuenow: this.value, disabled: this.hasAttribute("disabled"), readonly: this.hasAttribute("readonly") });
281
100
  }
282
- /**
283
- * Returns the icons for the rating component.
284
- * @param {number} index The index of the icon.
285
- * @returns {Element} The icon element.
286
- */
287
- getIcons(index) {
288
- let icon = document.createElement("wje-icon");
289
- icon.setAttribute("name", this.max ? this.icons[0] : this.icons[index]);
290
- if (this.hasAttribute("filled")) icon.setAttribute("filled", "");
291
- return icon;
101
+ getIcons(t2) {
102
+ let e2 = document.createElement("wje-icon");
103
+ return e2.setAttribute("name", this.max ? this.icons[0] : this.icons[t2]), this.hasAttribute("filled") && e2.setAttribute("filled", ""), e2;
292
104
  }
293
- /**
294
- * Returns the value from the x position.
295
- * @param {number} coordinate The x coordinate.
296
- * @returns {number} The value from the x position.
297
- */
298
- getValueFromXPosition(coordinate) {
299
- const { left, right, width } = this.native.getBoundingClientRect();
300
- const value = this.roundToPrecision((coordinate - left) / width * this.max, this.precision);
301
- return Math.min(Math.max(value, 0), this.max);
105
+ getValueFromXPosition(t2) {
106
+ const { left: e2, right: i, width: s } = this.native.getBoundingClientRect(), a = this.roundToPrecision((t2 - e2) / s * this.max, this.precision);
107
+ return Math.min(Math.max(a, 0), this.max);
302
108
  }
303
- /**
304
- * Rounds a given number to the nearest specified precision.
305
- * @param {number} numberToRound The number to be rounded.
306
- * @param {number} [precision] The precision to which the number should be rounded.
307
- * @returns {number} - The rounded number.
308
- * @example
309
- * roundToPrecision(2.3); // Returns 2.5
310
- * roundToPrecision(2.3, 0.1); // Returns 2.3
311
- * roundToPrecision(2.6, 1); // Returns 3
312
- */
313
- roundToPrecision(numberToRound, precision = 0.5) {
314
- const multiplier = 1 / precision;
315
- return Math.ceil(numberToRound * multiplier) / multiplier;
109
+ roundToPrecision(t2, e2 = 0.5) {
110
+ const i = 1 / e2;
111
+ return Math.ceil(t2 * i) / i;
316
112
  }
317
113
  }
318
- Rate.define("wje-rate", Rate);
114
+ e.define("wje-rate", e);
319
115
  export {
320
- Rate as default
116
+ e as default
321
117
  };
322
118
  //# sourceMappingURL=wje-rate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wje-rate.js","sources":["../packages/wje-rate/rate.element.js","../packages/wje-rate/rate.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Rate` is a custom web component that represents a rating component.\n * @summary This element represents a rating component.\n * @documentation https://elements.webjet.sk/components/rate\n * @status stable\n * @augments {WJElement}\n * @attribute {number} precision - The precision of the rating component.\n * @attribute {number} max - The maximum value of the rating component.\n * @attribute {Array<string>} icons - The icons of the rating component.\n * @csspart native - The native part of the rating component.\n * @cssproperty [--wje-rate-gap=.25rem] - Defines the spacing (gap) between individual items in the rating component. Accepts any valid CSS length unit (e.g., `px`, `rem`, `em`) to adjust the distance between rating elements.\n * @cssproperty [--wje-rate-color=var(--wje-color-contrast-11)] - Specifies the default color of the rating items. Accepts any valid CSS color value, including named colors, hex values, RGB, or CSS variables.\n * @cssproperty [--wje-rate-selected-color=var(--wje-color-danger-9)] - Sets the color for selected or highlighted rating items. This property helps visually distinguish selected ratings. Accepts any valid CSS color value.\n * @tag wje-rate\n */\n\nexport default class Rate extends WJElement {\n /**\n * Creates an instance of Rate.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the precision of the rating component.\n * @param {number} value The value to set.\n */\n set precision(value) {\n this.setAttribute('precision', value);\n }\n\n /**\n * Gets the precision of the rating component.\n * @returns {number} The value of the precision.\n */\n get precision() {\n return this.hasAttribute('precision') ? +this.getAttribute('precision') : 1;\n }\n\n /**\n * Sets the maximum value of the rating component.\n * @param {number} value The value to set.\n */\n set max(value) {\n this.setAttribute('max', value);\n }\n\n /**\n * Gets the maximum value of the rating component.\n * @returns {number} The value of the maximum value.\n */\n get max() {\n return this.hasAttribute('icons') ? this.icons.length : +this.getAttribute('max');\n }\n\n /**\n * Sets the icons of the rating component.\n * @param {Array<string>} value The value to set.\n */\n set icons(value) {\n return value;\n }\n\n /**\n * Gets the icons of the rating component.\n * @returns {Array<string>} The value of the icons.\n */\n get icons() {\n return this.hasAttribute('icons') ? JSON.parse(this.getAttribute('icons').replace(/'/g, '\"')) : ['star'];\n }\n\n /**\n * Sets the value of the rating component.\n * @param {number} value The value to set.\n */\n set value(value) {\n this.setAttribute('value', value);\n }\n\n /**\n * Gets the value of the rating component.\n * @returns {number} The value of the rating component.\n */\n get value() {\n return this.hasAttribute('value') ? +this.getAttribute('value') : 0;\n }\n\n /**\n * Sets the hover value of the rating component.\n * @type {string}\n */\n className = 'Rate';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['is-hover', 'value', 'max', 'disabled', 'readonly'];\n }\n\n /**\n * Called when an attribute changes.\n * @param {string} name The name of the attribute that changed.\n * @param {string} old The old value of the attribute.\n * @param {string} newName The new value of the attribute.\n */\n attributeChangedCallback(name, old, newName) {\n if (super.attributeChangedCallback) {\n super.attributeChangedCallback(name, old, newName);\n }\n\n if (name === 'is-hover') {\n // this.draw();\n }\n\n if (old !== newName && name !== 'is-hover') {\n this.syncAria();\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.syncAria();\n }\n\n /**\n * Draws the component for the rating component.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-rate');\n\n this.native = native;\n\n if (this.hasAttribute('icons')) {\n let icons = this.icons;\n for (let i = 0; i < icons.length; i++) {\n native.appendChild(this.createIcons(i));\n }\n } else {\n for (let i = 0; i < this.max; i++) {\n native.appendChild(this.createIcons(i));\n }\n }\n\n this.changeRate();\n\n fragment.appendChild(native);\n\n return fragment;\n }\n\n /**\n * Adds event listeners after the component is drawn.\n */\n afterDraw() {\n this.syncAria();\n if (this.hasAttribute('disabled') || this.hasAttribute('readonly')) {\n return;\n }\n\n this.addEventListener('mouseenter', this.onMouseEnter);\n this.addEventListener('mouseleave', this.onMouseLeave);\n this.addEventListener('mousemove', this.onMouseMove);\n this.addEventListener('touchstart', this.onTouchStart);\n this.addEventListener('touchend', this.onTouchEnd);\n this.addEventListener('touchmove', this.onTouchMove);\n this.addEventListener('click', this.onClick);\n }\n\n /**\n * Creates the icons for the rating component.\n * @param {number} i The index of the icon.\n * @returns {Element} The icon element.\n */\n createIcons(i) {\n let div = document.createElement('div');\n div.classList.add('wje-rate-icon');\n\n let icon = this.getIcons(i);\n let clone = icon.cloneNode(true);\n\n div.appendChild(icon);\n div.appendChild(clone);\n\n return div;\n }\n\n /**\n * Changes the rate of the rating component.\n */\n changeRate() {\n const icons = this.native.children;\n const rateValue =\n this.value !== this.hoverValue && this.hoverValue !== 0 && this.hoverValue !== undefined\n ? this.hoverValue\n : this.value;\n\n for (let i = 0; i < icons.length; i++) {\n const icon = icons[i];\n const firstIcon = icon.querySelector('wje-icon:first-child');\n const lastIcon = icon.querySelector('wje-icon:last-child');\n\n const isSelected = i < rateValue;\n const isPartial = rateValue > i && rateValue < i + 1;\n\n if (isSelected) {\n icon.classList.add('selected');\n if (this.hasAttribute('selected') && this.getAttribute('selected') === 'filled') {\n lastIcon.setAttribute('filled', '');\n }\n } else {\n icon.classList.remove('selected');\n lastIcon.removeAttribute('filled');\n }\n\n if (isPartial) {\n const percent = ((rateValue - i) * 100).toFixed(2);\n icon.classList.add('half');\n\n firstIcon.style.clipPath = `inset(0 0 0 ${percent}%)`;\n lastIcon.style.clipPath = `inset(0 ${100 - percent}% 0 0)`;\n\n lastIcon.removeAttribute('hidden');\n } else {\n icon.classList.remove('half');\n firstIcon.style.clipPath = ``;\n lastIcon.style.clipPath = ``;\n lastIcon.setAttribute('hidden', '');\n }\n\n icon.setAttribute('data-index', i);\n icon.setAttribute('data-rate', rateValue);\n }\n\n this.syncAria();\n }\n\n /**\n * Sync ARIA attributes on host.\n */\n syncAria() {\n this.setAriaState({\n role: 'slider',\n valuemin: 0,\n valuemax: this.max,\n valuenow: this.value,\n disabled: this.hasAttribute('disabled'),\n readonly: this.hasAttribute('readonly'),\n });\n }\n\n /**\n * Event handler for the mouse enter event.\n * @param {Event} e The event.\n */\n onMouseEnter = (e) => {\n e.preventDefault();\n\n this.hoverValue = this.getValueFromXPosition(e.clientX);\n this.changeRate();\n };\n\n /**\n * Event handler for the mouse leave event.\n * @param {Event} e The event.\n */\n onMouseLeave = (e) => {\n e.preventDefault();\n\n this.hoverValue = 0;\n this.changeRate();\n };\n\n /**\n * Event handler for the mouse move event.\n * @param {Event} e The event.\n */\n onMouseMove = (e) => {\n e.preventDefault();\n\n let newValue = +this.getValueFromXPosition(e.clientX);\n if (newValue !== +this.hoverValue) {\n this.hoverValue = newValue;\n this.changeRate();\n }\n };\n\n /**\n * Event handler for the touch start event.\n * @param {Event} e The event.\n */\n onTouchStart = (e) => {\n e.preventDefault();\n\n this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);\n this.changeRate();\n };\n\n /**\n * Event handler for the touch end event.\n * @param {Event} e The event.\n */\n onTouchEnd = (e) => {\n e.preventDefault();\n\n this.hoverValue = 0;\n this.changeRate();\n };\n\n /**\n * Event handler for the touch move event.\n * @param {Event} e The event.\n */\n onTouchMove = (e) => {\n e.preventDefault();\n\n this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);\n this.changeRate();\n };\n\n /**\n * Event handler for the click event.\n * @param {Event} e The event.\n */\n onClick = (e) => {\n e.preventDefault();\n\n this.value = +this.hoverValue;\n };\n\n /**\n * Returns the icons for the rating component.\n * @param {number} index The index of the icon.\n * @returns {Element} The icon element.\n */\n getIcons(index) {\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', this.max ? this.icons[0] : this.icons[index]);\n\n if (this.hasAttribute('filled')) icon.setAttribute('filled', '');\n\n return icon;\n }\n\n /**\n * Returns the value from the x position.\n * @param {number} coordinate The x coordinate.\n * @returns {number} The value from the x position.\n */\n getValueFromXPosition(coordinate) {\n const { left, right, width } = this.native.getBoundingClientRect();\n const value = this.roundToPrecision(((coordinate - left) / width) * this.max, this.precision);\n\n return Math.min(Math.max(value, 0), this.max);\n }\n\n /**\n * Rounds a given number to the nearest specified precision.\n * @param {number} numberToRound The number to be rounded.\n * @param {number} [precision] The precision to which the number should be rounded.\n * @returns {number} - The rounded number.\n * @example\n * roundToPrecision(2.3); // Returns 2.5\n * roundToPrecision(2.3, 0.1); // Returns 2.3\n * roundToPrecision(2.6, 1); // Returns 3\n */\n roundToPrecision(numberToRound, precision = 0.5) {\n const multiplier = 1 / precision;\n return Math.ceil(numberToRound * multiplier) / multiplier;\n }\n}\n","import Rate from './rate.element.js';\n\nexport default Rate;\n\nRate.define('wje-rate', Rate);\n"],"names":[],"mappings":";;;;;AAmBe,MAAM,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxC,cAAc;AACV,UAAK;AAuET;AAAA;AAAA;AAAA;AAAA,qCAAY;AAuLZ;AAAA;AAAA;AAAA;AAAA,wCAAe,CAAC,MAAM;AAClB,QAAE,eAAc;AAEhB,WAAK,aAAa,KAAK,sBAAsB,EAAE,OAAO;AACtD,WAAK,WAAU;AAAA,IACnB;AAMA;AAAA;AAAA;AAAA;AAAA,wCAAe,CAAC,MAAM;AAClB,QAAE,eAAc;AAEhB,WAAK,aAAa;AAClB,WAAK,WAAU;AAAA,IACnB;AAMA;AAAA;AAAA;AAAA;AAAA,uCAAc,CAAC,MAAM;AACjB,QAAE,eAAc;AAEhB,UAAI,WAAW,CAAC,KAAK,sBAAsB,EAAE,OAAO;AACpD,UAAI,aAAa,CAAC,KAAK,YAAY;AAC/B,aAAK,aAAa;AAClB,aAAK,WAAU;AAAA,MACnB;AAAA,IACJ;AAMA;AAAA;AAAA;AAAA;AAAA,wCAAe,CAAC,MAAM;AAClB,QAAE,eAAc;AAEhB,WAAK,aAAa,KAAK,sBAAsB,EAAE,QAAQ,CAAC,EAAE,OAAO;AACjE,WAAK,WAAU;AAAA,IACnB;AAMA;AAAA;AAAA;AAAA;AAAA,sCAAa,CAAC,MAAM;AAChB,QAAE,eAAc;AAEhB,WAAK,aAAa;AAClB,WAAK,WAAU;AAAA,IACnB;AAMA;AAAA;AAAA;AAAA;AAAA,uCAAc,CAAC,MAA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AAK,KAAK,gBAAgB,UAAU,IAAI;AAAA,EACnD;AACJ;ACtYA,KAAK,OAAO,YAAY,IAAI;"}
1
+ {"version":3,"file":"wje-rate.js","sources":["../packages/wje-rate/rate.element.js","../packages/wje-rate/rate.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Rate` is a custom web component that represents a rating component.\n * @summary This element represents a rating component.\n * @documentation https://elements.webjet.sk/components/rate\n * @status stable\n * @augments {WJElement}\n * @attribute {number} precision - The precision of the rating component.\n * @attribute {number} max - The maximum value of the rating component.\n * @attribute {Array<string>} icons - The icons of the rating component.\n * @csspart native - The native part of the rating component.\n * @cssproperty [--wje-rate-gap=.25rem] - Defines the spacing (gap) between individual items in the rating component. Accepts any valid CSS length unit (e.g., `px`, `rem`, `em`) to adjust the distance between rating elements.\n * @cssproperty [--wje-rate-color=var(--wje-color-contrast-11)] - Specifies the default color of the rating items. Accepts any valid CSS color value, including named colors, hex values, RGB, or CSS variables.\n * @cssproperty [--wje-rate-selected-color=var(--wje-color-danger-9)] - Sets the color for selected or highlighted rating items. This property helps visually distinguish selected ratings. Accepts any valid CSS color value.\n * @tag wje-rate\n */\n\nexport default class Rate extends WJElement {\n /**\n * Creates an instance of Rate.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the precision of the rating component.\n * @param {number} value The value to set.\n */\n set precision(value) {\n this.setAttribute('precision', value);\n }\n\n /**\n * Gets the precision of the rating component.\n * @returns {number} The value of the precision.\n */\n get precision() {\n return this.hasAttribute('precision') ? +this.getAttribute('precision') : 1;\n }\n\n /**\n * Sets the maximum value of the rating component.\n * @param {number} value The value to set.\n */\n set max(value) {\n this.setAttribute('max', value);\n }\n\n /**\n * Gets the maximum value of the rating component.\n * @returns {number} The value of the maximum value.\n */\n get max() {\n return this.hasAttribute('icons') ? this.icons.length : +this.getAttribute('max');\n }\n\n /**\n * Sets the icons of the rating component.\n * @param {Array<string>} value The value to set.\n */\n set icons(value) {\n return value;\n }\n\n /**\n * Gets the icons of the rating component.\n * @returns {Array<string>} The value of the icons.\n */\n get icons() {\n return this.hasAttribute('icons') ? JSON.parse(this.getAttribute('icons').replace(/'/g, '\"')) : ['star'];\n }\n\n /**\n * Sets the value of the rating component.\n * @param {number} value The value to set.\n */\n set value(value) {\n this.setAttribute('value', value);\n }\n\n /**\n * Gets the value of the rating component.\n * @returns {number} The value of the rating component.\n */\n get value() {\n return this.hasAttribute('value') ? +this.getAttribute('value') : 0;\n }\n\n /**\n * Sets the hover value of the rating component.\n * @type {string}\n */\n className = 'Rate';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['is-hover', 'value', 'max', 'disabled', 'readonly'];\n }\n\n /**\n * Called when an attribute changes.\n * @param {string} name The name of the attribute that changed.\n * @param {string} old The old value of the attribute.\n * @param {string} newName The new value of the attribute.\n */\n attributeChangedCallback(name, old, newName) {\n if (super.attributeChangedCallback) {\n super.attributeChangedCallback(name, old, newName);\n }\n\n if (name === 'is-hover') {\n // this.draw();\n }\n\n if (old !== newName && name !== 'is-hover') {\n this.syncAria();\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.syncAria();\n }\n\n /**\n * Draws the component for the rating component.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-rate');\n\n this.native = native;\n\n if (this.hasAttribute('icons')) {\n let icons = this.icons;\n for (let i = 0; i < icons.length; i++) {\n native.appendChild(this.createIcons(i));\n }\n } else {\n for (let i = 0; i < this.max; i++) {\n native.appendChild(this.createIcons(i));\n }\n }\n\n this.changeRate();\n\n fragment.appendChild(native);\n\n return fragment;\n }\n\n /**\n * Adds event listeners after the component is drawn.\n */\n afterDraw() {\n this.syncAria();\n if (this.hasAttribute('disabled') || this.hasAttribute('readonly')) {\n return;\n }\n\n this.addEventListener('mouseenter', this.onMouseEnter);\n this.addEventListener('mouseleave', this.onMouseLeave);\n this.addEventListener('mousemove', this.onMouseMove);\n this.addEventListener('touchstart', this.onTouchStart);\n this.addEventListener('touchend', this.onTouchEnd);\n this.addEventListener('touchmove', this.onTouchMove);\n this.addEventListener('click', this.onClick);\n }\n\n /**\n * Creates the icons for the rating component.\n * @param {number} i The index of the icon.\n * @returns {Element} The icon element.\n */\n createIcons(i) {\n let div = document.createElement('div');\n div.classList.add('wje-rate-icon');\n\n let icon = this.getIcons(i);\n let clone = icon.cloneNode(true);\n\n div.appendChild(icon);\n div.appendChild(clone);\n\n return div;\n }\n\n /**\n * Changes the rate of the rating component.\n */\n changeRate() {\n const icons = this.native.children;\n const rateValue =\n this.value !== this.hoverValue && this.hoverValue !== 0 && this.hoverValue !== undefined\n ? this.hoverValue\n : this.value;\n\n for (let i = 0; i < icons.length; i++) {\n const icon = icons[i];\n const firstIcon = icon.querySelector('wje-icon:first-child');\n const lastIcon = icon.querySelector('wje-icon:last-child');\n\n const isSelected = i < rateValue;\n const isPartial = rateValue > i && rateValue < i + 1;\n\n if (isSelected) {\n icon.classList.add('selected');\n if (this.hasAttribute('selected') && this.getAttribute('selected') === 'filled') {\n lastIcon.setAttribute('filled', '');\n }\n } else {\n icon.classList.remove('selected');\n lastIcon.removeAttribute('filled');\n }\n\n if (isPartial) {\n const percent = ((rateValue - i) * 100).toFixed(2);\n icon.classList.add('half');\n\n firstIcon.style.clipPath = `inset(0 0 0 ${percent}%)`;\n lastIcon.style.clipPath = `inset(0 ${100 - percent}% 0 0)`;\n\n lastIcon.removeAttribute('hidden');\n } else {\n icon.classList.remove('half');\n firstIcon.style.clipPath = ``;\n lastIcon.style.clipPath = ``;\n lastIcon.setAttribute('hidden', '');\n }\n\n icon.setAttribute('data-index', i);\n icon.setAttribute('data-rate', rateValue);\n }\n\n this.syncAria();\n }\n\n /**\n * Sync ARIA attributes on host.\n */\n syncAria() {\n this.setAriaState({\n role: 'slider',\n valuemin: 0,\n valuemax: this.max,\n valuenow: this.value,\n disabled: this.hasAttribute('disabled'),\n readonly: this.hasAttribute('readonly'),\n });\n }\n\n /**\n * Event handler for the mouse enter event.\n * @param {Event} e The event.\n */\n onMouseEnter = (e) => {\n e.preventDefault();\n\n this.hoverValue = this.getValueFromXPosition(e.clientX);\n this.changeRate();\n };\n\n /**\n * Event handler for the mouse leave event.\n * @param {Event} e The event.\n */\n onMouseLeave = (e) => {\n e.preventDefault();\n\n this.hoverValue = 0;\n this.changeRate();\n };\n\n /**\n * Event handler for the mouse move event.\n * @param {Event} e The event.\n */\n onMouseMove = (e) => {\n e.preventDefault();\n\n let newValue = +this.getValueFromXPosition(e.clientX);\n if (newValue !== +this.hoverValue) {\n this.hoverValue = newValue;\n this.changeRate();\n }\n };\n\n /**\n * Event handler for the touch start event.\n * @param {Event} e The event.\n */\n onTouchStart = (e) => {\n e.preventDefault();\n\n this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);\n this.changeRate();\n };\n\n /**\n * Event handler for the touch end event.\n * @param {Event} e The event.\n */\n onTouchEnd = (e) => {\n e.preventDefault();\n\n this.hoverValue = 0;\n this.changeRate();\n };\n\n /**\n * Event handler for the touch move event.\n * @param {Event} e The event.\n */\n onTouchMove = (e) => {\n e.preventDefault();\n\n this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);\n this.changeRate();\n };\n\n /**\n * Event handler for the click event.\n * @param {Event} e The event.\n */\n onClick = (e) => {\n e.preventDefault();\n\n this.value = +this.hoverValue;\n };\n\n /**\n * Returns the icons for the rating component.\n * @param {number} index The index of the icon.\n * @returns {Element} The icon element.\n */\n getIcons(index) {\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', this.max ? this.icons[0] : this.icons[index]);\n\n if (this.hasAttribute('filled')) icon.setAttribute('filled', '');\n\n return icon;\n }\n\n /**\n * Returns the value from the x position.\n * @param {number} coordinate The x coordinate.\n * @returns {number} The value from the x position.\n */\n getValueFromXPosition(coordinate) {\n const { left, right, width } = this.native.getBoundingClientRect();\n const value = this.roundToPrecision(((coordinate - left) / width) * this.max, this.precision);\n\n return Math.min(Math.max(value, 0), this.max);\n }\n\n /**\n * Rounds a given number to the nearest specified precision.\n * @param {number} numberToRound The number to be rounded.\n * @param {number} [precision] The precision to which the number should be rounded.\n * @returns {number} - The rounded number.\n * @example\n * roundToPrecision(2.3); // Returns 2.5\n * roundToPrecision(2.3, 0.1); // Returns 2.3\n * roundToPrecision(2.6, 1); // Returns 3\n */\n roundToPrecision(numberToRound, precision = 0.5) {\n const multiplier = 1 / precision;\n return Math.ceil(numberToRound * multiplier) / multiplier;\n }\n}\n","import Rate from './rate.element.js';\n\nexport default Rate;\n\nRate.define('wje-rate', Rate);\n"],"names":["Rate","WJElement","constructor","super","className","onMouseEnter","e","preventDefault","this","hoverValue","getValueFromXPosition","clientX","changeRate","onMouseLeave","onMouseMove","newValue","onTouchStart","touches","onTouchEnd","onTouchMove","onClick","value","setAttribute","precision","hasAttribute","getAttribute","max","icons","length","JSON","parse","replace","cssStyleSheet","observedAttributes","name","old","newName","attributeChangedCallback","syncAria","setupAttributes","isShadowRoot","draw","fragment","document","createDocumentFragment","native","createElement","classList","add","i","appendChild","createIcons","addEventListener","div","icon","getIcons","clone","cloneNode","children","rateValue","firstIcon","querySelector","lastIcon","isPartial","remove","removeAttribute","percent","toFixed","style","clipPath","setAriaState","role","valuemin","valuemax","valuenow","disabled","readonly","index","coordinate","left","right","width","getBoundingClientRect","roundToPrecision","Math","min","numberToRound","multiplier","ceil","define"],"mappings":";;;;AAmBe,MAAMA,UAAaC,EAAAA;AAAAA,EAK9B,cAAAC;AACIC,UAAAA;AAuEJC,qCAAY;AAuLZC,wCAAgBC,CAAAA,OAAAA;AACZA,MAAAA,GAAEC,eAAAA,GAEFC,KAAKC,aAAaD,KAAKE,sBA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AEA,EAAAA,IAAUzE,KAAKqC,OAAOqC,sBAAAA,GACrC7D,IAAQb,KAAK2E,kBAAmBL,KAAaC,MAAQE,IAASzE,KAAKkB,KAAKlB,KAAKe;AAEnF,WAAO6D,KAAKC,IAAID,KAAK1D,IAAIL,GAAO,CAAA,GAAIb,KAAKkB,GAAAA;AAAAA,EAC7C;AAAA,EAYA,iBAAiB4D,IAAe/D,KAAY,KAAA;AACxC,UAAMgE,IAAa,IAAIhE;AACvB,WAAO6D,KAAKI,KAAKF,KAAgBC,KAAcA;AAAAA,EACnD;AAAA;ACrYJvF,EAAKyF,OAAO,YAAYzF,CAAAA;"}
@@ -1,128 +1,53 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { Localizer } from "./localize.js";
5
- import WJElement from "./wje-element.js";
6
- class RelativeTime extends WJElement {
7
- /**
8
- * Creates an instance of RelativeTime.
9
- * @class
10
- */
4
+ import { Localizer as t } from "./localize.js";
5
+ import e from "./wje-element.js";
6
+ class i extends e {
11
7
  constructor() {
12
8
  super();
13
- /**
14
- * Sets the lang of the relative time component.
15
- * @type {string}
16
- */
17
9
  __publicField(this, "className", "RelativeTime");
18
- this.localizer = new Localizer(this);
10
+ this.localizer = new t(this);
19
11
  }
20
- /**
21
- * Sets the date of the relative time component.
22
- * @param value
23
- */
24
- set date(value) {
25
- this.setAttribute("date", value);
12
+ set date(t2) {
13
+ this.setAttribute("date", t2);
26
14
  }
27
- /**
28
- * Gets the date of the relative time component.
29
- * @returns {string}
30
- */
31
15
  get date() {
32
16
  return this.getAttribute("date");
33
17
  }
34
- /**
35
- * Sets the object date of the relative time component.
36
- * @param value
37
- */
38
- set objectDate(value) {
39
- this.setAttribute("object-date", value);
18
+ set objectDate(t2) {
19
+ this.setAttribute("object-date", t2);
40
20
  }
41
- /**
42
- * Gets the object date of the relative time component.
43
- * @returns {Date}
44
- */
45
21
  get objectDate() {
46
- let date = /* @__PURE__ */ new Date();
47
- let inputDate = this.date;
48
- if (!!inputDate && inputDate !== "") {
49
- inputDate = this.isISODate(inputDate) ? inputDate : +inputDate * 1e3;
50
- date = new Date(inputDate);
51
- }
52
- return date;
22
+ let t2 = /* @__PURE__ */ new Date(), e2 = this.date;
23
+ return e2 && "" !== e2 && (e2 = this.isISODate(e2) ? e2 : 1e3 * +e2, t2 = new Date(e2)), t2;
53
24
  }
54
- /**
55
- * Returns the list of attributes to observe for changes.
56
- * @static
57
- * @returns {Array<string>}
58
- */
59
25
  static get observedAttributes() {
60
26
  return ["date", "lang"];
61
27
  }
62
- attributeChangedCallback(name, oldValue, newValue) {
28
+ attributeChangedCallback(t2, e2, i2) {
63
29
  var _a;
64
- (_a = super.attributeChangedCallback) == null ? void 0 : _a.call(this, name, oldValue, newValue);
65
- if (oldValue === newValue) return;
66
- if (this.native) {
67
- this.native.innerText = this.getRelativeTimeString();
68
- if (this.date) this.native.setAttribute("datetime", this.date);
69
- else this.native.removeAttribute("datetime");
70
- }
30
+ (_a = super.attributeChangedCallback) == null ? void 0 : _a.call(this, t2, e2, i2), e2 !== i2 && this.native && (this.native.innerText = this.getRelativeTimeString(), this.date ? this.native.setAttribute("datetime", this.date) : this.native.removeAttribute("datetime"));
71
31
  }
72
- /**
73
- * Sets up the attributes for the component.
74
- */
75
32
  setupAttributes() {
76
- this.isShadowRoot = "open";
77
- this.setAriaState({ role: "status" });
33
+ this.isShadowRoot = "open", this.setAriaState({ role: "status" });
78
34
  }
79
- /**
80
- * Draws the component for the relative time.
81
- * @returns {DocumentFragment}
82
- */
83
35
  draw() {
84
- let fragment = document.createDocumentFragment();
85
- let element = document.createElement("div");
86
- element.setAttribute("part", "native");
87
- element.classList.add("native-relative-time");
88
- element.innerText = this.getRelativeTimeString();
89
- if (this.date) element.setAttribute("datetime", this.date);
90
- fragment.appendChild(element);
91
- this.native = element;
92
- return fragment;
36
+ let t2 = document.createDocumentFragment(), e2 = document.createElement("div");
37
+ return e2.setAttribute("part", "native"), e2.classList.add("native-relative-time"), e2.innerText = this.getRelativeTimeString(), this.date && e2.setAttribute("datetime", this.date), t2.appendChild(e2), this.native = e2, t2;
93
38
  }
94
- /**
95
- * Returns the relative time string for the given date.
96
- */
97
- getRelativeTimeString(lang = navigator.language) {
98
- if (this.objectDate.toString() === "Invalid Date" || this.objectDate.toString() === "NaN") {
99
- return "";
100
- }
101
- const timeMs = this.objectDate.getTime();
102
- const deltaSeconds = Math.round((timeMs - Date.now()) / 1e3);
103
- const cutoffs = [60, 3600, 86400, 86400 * 7, 86400 * 30, 86400 * 365, Infinity];
104
- const units = ["second", "minute", "hour", "day", "week", "month", "year"];
105
- const unitIndex = cutoffs.findIndex((cutoff) => cutoff > Math.abs(deltaSeconds));
106
- const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1;
107
- return this.localizer.relativeTime(
108
- this.getAttribute("lang"),
109
- Math.trunc(deltaSeconds / divisor),
110
- units[unitIndex],
111
- { numeric: "auto" }
112
- );
39
+ getRelativeTimeString(t2 = navigator.language) {
40
+ if ("Invalid Date" === this.objectDate.toString() || "NaN" === this.objectDate.toString()) return "";
41
+ const e2 = this.objectDate.getTime(), i2 = Math.round((e2 - Date.now()) / 1e3), a = [60, 3600, 86400, 604800, 2592e3, 31536e3, 1 / 0], r = a.findIndex((t3) => t3 > Math.abs(i2)), s = r ? a[r - 1] : 1;
42
+ return this.localizer.relativeTime(this.getAttribute("lang"), Math.trunc(i2 / s), ["second", "minute", "hour", "day", "week", "month", "year"][r], { numeric: "auto" });
113
43
  }
114
- /**
115
- * Checks if the given string is an ISO date.
116
- * @param {string} str The string to check.
117
- * @returns {boolean} True if the string is an ISO date, false otherwise.
118
- */
119
- isISODate(str) {
120
- const date = new Date(str);
121
- return !isNaN(date.getTime());
44
+ isISODate(t2) {
45
+ const e2 = new Date(t2);
46
+ return !isNaN(e2.getTime());
122
47
  }
123
48
  }
124
- RelativeTime.define("wje-relative-time", RelativeTime);
49
+ i.define("wje-relative-time", i);
125
50
  export {
126
- RelativeTime as default
51
+ i as default
127
52
  };
128
53
  //# sourceMappingURL=wje-relative-time.js.map