@tabler/core 1.0.0-beta18 → 1.0.0-beta19

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 (46) hide show
  1. package/dist/css/demo.css +2 -2
  2. package/dist/css/demo.min.css +2 -2
  3. package/dist/css/demo.rtl.css +2 -2
  4. package/dist/css/demo.rtl.min.css +2 -2
  5. package/dist/css/tabler-flags.css +2 -2
  6. package/dist/css/tabler-flags.min.css +2 -2
  7. package/dist/css/tabler-flags.rtl.css +2 -2
  8. package/dist/css/tabler-flags.rtl.min.css +2 -2
  9. package/dist/css/tabler-payments.css +2 -2
  10. package/dist/css/tabler-payments.min.css +2 -2
  11. package/dist/css/tabler-payments.rtl.css +2 -2
  12. package/dist/css/tabler-payments.rtl.min.css +2 -2
  13. package/dist/css/tabler-social.css +2 -2
  14. package/dist/css/tabler-social.min.css +2 -2
  15. package/dist/css/tabler-social.rtl.css +2 -2
  16. package/dist/css/tabler-social.rtl.min.css +2 -2
  17. package/dist/css/tabler-vendors.css +19 -2
  18. package/dist/css/tabler-vendors.min.css +3 -3
  19. package/dist/css/tabler-vendors.rtl.css +19 -2
  20. package/dist/css/tabler-vendors.rtl.min.css +3 -3
  21. package/dist/css/tabler.css +36 -31
  22. package/dist/css/tabler.min.css +4 -4
  23. package/dist/css/tabler.rtl.css +36 -31
  24. package/dist/css/tabler.rtl.min.css +4 -4
  25. package/dist/js/demo-theme.js +2 -2
  26. package/dist/js/demo-theme.min.js +2 -2
  27. package/dist/js/demo.js +2 -2
  28. package/dist/js/demo.min.js +2 -2
  29. package/dist/js/tabler.esm.js +2 -2
  30. package/dist/js/tabler.esm.min.js +3 -3
  31. package/dist/js/tabler.js +2 -2
  32. package/dist/js/tabler.min.js +4 -4
  33. package/dist/libs/star-rating.js/dist/star-rating.cjs.js +481 -0
  34. package/dist/libs/star-rating.js/dist/star-rating.css +220 -0
  35. package/dist/libs/star-rating.js/dist/star-rating.esm.js +479 -0
  36. package/dist/libs/star-rating.js/dist/star-rating.esm.min.js +1 -0
  37. package/dist/libs/star-rating.js/dist/star-rating.js +491 -0
  38. package/dist/libs/star-rating.js/dist/star-rating.min.css +8 -0
  39. package/dist/libs/star-rating.js/dist/star-rating.min.js +8 -0
  40. package/package.json +9 -3
  41. package/src/scss/_variables.scss +1 -1
  42. package/src/scss/layout/_navbar.scss +1 -70
  43. package/src/scss/tabler-vendors.scss +1 -0
  44. package/src/scss/ui/_grid.scss +2 -2
  45. package/src/scss/ui/_tables.scss +12 -11
  46. package/src/scss/vendor/_stars-rating.scss +20 -0
@@ -0,0 +1,479 @@
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+
7
+ function _defineProperties(target, props) {
8
+ for (var i = 0; i < props.length; i++) {
9
+ var descriptor = props[i];
10
+ descriptor.enumerable = descriptor.enumerable || false;
11
+ descriptor.configurable = true;
12
+ if ("value" in descriptor) descriptor.writable = true;
13
+ Object.defineProperty(target, descriptor.key, descriptor);
14
+ }
15
+ }
16
+
17
+ function _createClass(Constructor, protoProps, staticProps) {
18
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
19
+ if (staticProps) _defineProperties(Constructor, staticProps);
20
+ return Constructor;
21
+ }
22
+
23
+ var defaults = {
24
+ classNames: {
25
+ active: 'gl-active',
26
+ base: 'gl-star-rating',
27
+ selected: 'gl-selected'
28
+ },
29
+ clearable: true,
30
+ maxStars: 10,
31
+ prebuilt: false,
32
+ stars: null,
33
+ tooltip: 'Select a Rating'
34
+ };
35
+
36
+ var addRemoveClass = function addRemoveClass(el, bool, className) {
37
+ el.classList[bool ? 'add' : 'remove'](className);
38
+ };
39
+ var createSpanEl = function createSpanEl(attributes) {
40
+ var el = document.createElement('span');
41
+ attributes = attributes || {};
42
+
43
+ for (var key in attributes) {
44
+ el.setAttribute(key, attributes[key]);
45
+ }
46
+
47
+ return el;
48
+ };
49
+ var inRange = function inRange(value, min, max) {
50
+ return /^\d+$/.test(value) && min <= value && value <= max;
51
+ };
52
+ var insertSpanEl = function insertSpanEl(el, after, attributes) {
53
+ var newEl = createSpanEl(attributes);
54
+ el.parentNode.insertBefore(newEl, after ? el.nextSibling : el);
55
+ return newEl;
56
+ };
57
+ var merge = function merge() {
58
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
59
+ args[_key] = arguments[_key];
60
+ }
61
+
62
+ // adapted from https://github.com/firstandthird/aug
63
+ var results = {};
64
+ args.forEach(function (prop) {
65
+ Object.keys(prop || {}).forEach(function (propName) {
66
+ if (args[0][propName] === undefined) return; // restrict keys to the defaults
67
+
68
+ var propValue = prop[propName];
69
+
70
+ if (type(propValue) === 'Object' && type(results[propName]) === 'Object') {
71
+ results[propName] = merge(results[propName], propValue);
72
+ return;
73
+ }
74
+
75
+ results[propName] = propValue;
76
+ });
77
+ });
78
+ return results;
79
+ };
80
+ var type = function type(value) {
81
+ return {}.toString.call(value).slice(8, -1);
82
+ };
83
+ var values = function values(selectEl) {
84
+ var values = [];
85
+ [].forEach.call(selectEl.options, function (el) {
86
+ var value = parseInt(el.value, 10) || 0;
87
+
88
+ if (value > 0) {
89
+ values.push({
90
+ index: el.index,
91
+ text: el.text,
92
+ value: value
93
+ });
94
+ }
95
+ });
96
+ return values.sort(function (a, b) {
97
+ return a.value - b.value;
98
+ });
99
+ };
100
+
101
+ var Widget = /*#__PURE__*/function () {
102
+ function Widget(el, props) {
103
+ _classCallCheck(this, Widget);
104
+
105
+ // (HTMLElement, object):void
106
+ this.direction = window.getComputedStyle(el, null).getPropertyValue('direction');
107
+ this.el = el;
108
+ this.events = {
109
+ change: this.onChange.bind(this),
110
+ keydown: this.onKeyDown.bind(this),
111
+ mousedown: this.onPointerDown.bind(this),
112
+ mouseleave: this.onPointerLeave.bind(this),
113
+ mousemove: this.onPointerMove.bind(this),
114
+ reset: this.onReset.bind(this),
115
+ touchend: this.onPointerDown.bind(this),
116
+ touchmove: this.onPointerMove.bind(this)
117
+ };
118
+ this.indexActive = null; // the active span index
119
+
120
+ this.indexSelected = null; // the selected span index
121
+
122
+ this.props = props;
123
+ this.tick = null;
124
+ this.ticking = false;
125
+ this.values = values(el);
126
+ this.widgetEl = null;
127
+
128
+ if (this.el.widget) {
129
+ this.el.widget.destroy(); // remove any stale event listeners
130
+ }
131
+
132
+ if (inRange(this.values.length, 1, this.props.maxStars)) {
133
+ this.build();
134
+ } else {
135
+ this.destroy();
136
+ }
137
+ }
138
+
139
+ _createClass(Widget, [{
140
+ key: "build",
141
+ value: function build() {
142
+ // ():void
143
+ this.destroy();
144
+ this.buildWidget();
145
+ this.selectValue(this.indexSelected = this.selected(), false); // set the initial value but do not trigger change event
146
+
147
+ this.handleEvents('add');
148
+ this.el.widget = this; // store a reference to this widget on the SELECT so that we can remove stale event listeners
149
+ }
150
+ }, {
151
+ key: "buildWidget",
152
+ value: function buildWidget() {
153
+ var _this = this;
154
+
155
+ // ():void
156
+ var parentEl, widgetEl;
157
+
158
+ if (this.props.prebuilt) {
159
+ parentEl = this.el.parentNode;
160
+ widgetEl = parentEl.querySelector('.' + this.props.classNames.base + '--stars');
161
+ } else {
162
+ parentEl = insertSpanEl(this.el, false, {
163
+ "class": this.props.classNames.base
164
+ });
165
+ parentEl.appendChild(this.el);
166
+ widgetEl = insertSpanEl(this.el, true, {
167
+ "class": this.props.classNames.base + '--stars'
168
+ });
169
+ this.values.forEach(function (item, index) {
170
+ var el = createSpanEl({
171
+ 'data-index': index,
172
+ 'data-value': item.value
173
+ });
174
+
175
+ if ('function' === typeof _this.props.stars) {
176
+ _this.props.stars.call(_this, el, item, index);
177
+ }
178
+
179
+ [].forEach.call(el.children, function (el) {
180
+ return el.style.pointerEvents = 'none';
181
+ });
182
+ widgetEl.innerHTML += el.outerHTML;
183
+ });
184
+ }
185
+
186
+ parentEl.dataset.starRating = '';
187
+ parentEl.classList.add(this.props.classNames.base + '--' + this.direction);
188
+
189
+ if (this.props.tooltip) {
190
+ widgetEl.setAttribute('role', 'tooltip');
191
+ }
192
+
193
+ this.widgetEl = widgetEl;
194
+ }
195
+ }, {
196
+ key: "changeIndexTo",
197
+ value: function changeIndexTo(index, force) {
198
+ var _this2 = this;
199
+
200
+ // (int):void
201
+ if (this.indexActive !== index || force) {
202
+ [].forEach.call(this.widgetEl.children, function (el, i) {
203
+ // i starts at zero
204
+ addRemoveClass(el, i <= index, _this2.props.classNames.active);
205
+ addRemoveClass(el, i === _this2.indexSelected, _this2.props.classNames.selected);
206
+ });
207
+ this.widgetEl.setAttribute('data-rating', index + 1);
208
+
209
+ if ('function' !== typeof this.props.stars && !this.props.prebuilt) {
210
+ // @v3 compat
211
+ this.widgetEl.classList.remove('s' + 10 * (this.indexActive + 1));
212
+ this.widgetEl.classList.add('s' + 10 * (index + 1));
213
+ }
214
+
215
+ if (this.props.tooltip) {
216
+ var _this$values$index;
217
+
218
+ var label = index < 0 ? this.props.tooltip : (_this$values$index = this.values[index]) === null || _this$values$index === void 0 ? void 0 : _this$values$index.text;
219
+ this.widgetEl.setAttribute('aria-label', label);
220
+ }
221
+
222
+ this.indexActive = index;
223
+ }
224
+
225
+ this.ticking = false;
226
+ }
227
+ }, {
228
+ key: "destroy",
229
+ value: function destroy() {
230
+ // ():void
231
+ this.indexActive = null; // the active span index
232
+
233
+ this.indexSelected = this.selected(); // the selected span index
234
+
235
+ var parentEl = this.el.parentNode;
236
+
237
+ if (parentEl.classList.contains(this.props.classNames.base)) {
238
+ if (this.props.prebuilt) {
239
+ this.widgetEl = parentEl.querySelector('.' + this.props.classNames.base + '--stars');
240
+ parentEl.classList.remove(this.props.classNames.base + '--' + this.direction);
241
+ delete parentEl.dataset.starRating;
242
+ } else {
243
+ parentEl.parentNode.replaceChild(this.el, parentEl);
244
+ }
245
+
246
+ this.handleEvents('remove');
247
+ }
248
+
249
+ delete this.el.widget; // remove the widget reference
250
+ }
251
+ }, {
252
+ key: "eventListener",
253
+ value: function eventListener(el, action, events, items) {
254
+ var _this3 = this;
255
+
256
+ // (HTMLElement, string, array, object):void
257
+ events.forEach(function (ev) {
258
+ return el[action + 'EventListener'](ev, _this3.events[ev], items || false);
259
+ });
260
+ }
261
+ }, {
262
+ key: "handleEvents",
263
+ value: function handleEvents(action) {
264
+ // (string):void
265
+ var formEl = this.el.closest('form');
266
+
267
+ if (formEl && formEl.tagName === 'FORM') {
268
+ this.eventListener(formEl, action, ['reset']);
269
+ }
270
+
271
+ this.eventListener(this.el, action, ['change']); // always trigger the change event, even when SELECT is disabled
272
+
273
+ if ('add' === action && this.el.disabled) return;
274
+ this.eventListener(this.el, action, ['keydown']);
275
+ this.eventListener(this.widgetEl, action, ['mousedown', 'mouseleave', 'mousemove', 'touchend', 'touchmove'], false);
276
+ }
277
+ }, {
278
+ key: "indexFromEvent",
279
+ value: function indexFromEvent(ev) {
280
+ var _ev$touches, _ev$changedTouches;
281
+
282
+ // (MouseEvent|TouchEvent):void
283
+ var origin = ((_ev$touches = ev.touches) === null || _ev$touches === void 0 ? void 0 : _ev$touches[0]) || ((_ev$changedTouches = ev.changedTouches) === null || _ev$changedTouches === void 0 ? void 0 : _ev$changedTouches[0]) || ev;
284
+ var el = document.elementFromPoint(origin.clientX, origin.clientY);
285
+
286
+ if (el.parentNode === this.widgetEl) {
287
+ return [].slice.call(el.parentNode.children).indexOf(el);
288
+ }
289
+
290
+ return this.indexActive;
291
+ }
292
+ }, {
293
+ key: "onChange",
294
+ value: function onChange() {
295
+ // ():void
296
+ this.changeIndexTo(this.selected(), true);
297
+ }
298
+ }, {
299
+ key: "onKeyDown",
300
+ value: function onKeyDown(ev) {
301
+ // (KeyboardEvent):void
302
+ var key = ev.key.slice(5);
303
+ if (!~['Left', 'Right'].indexOf(key)) return;
304
+ ev.preventDefault();
305
+ var increment = key === 'Left' ? -1 : 1;
306
+
307
+ if (this.direction === 'rtl') {
308
+ increment *= -1;
309
+ }
310
+
311
+ var maxIndex = this.values.length - 1;
312
+ var minIndex = -1;
313
+ var index = Math.min(Math.max(this.selected() + increment, minIndex), maxIndex);
314
+ this.selectValue(index, true); // trigger change event
315
+ }
316
+ }, {
317
+ key: "onPointerDown",
318
+ value: function onPointerDown(ev) {
319
+ // (MouseEvent|TouchEvent):void
320
+ ev.preventDefault(); // this.el.focus(); // highlight the rating field
321
+
322
+ var index = this.indexFromEvent(ev);
323
+
324
+ if (this.props.clearable && index === this.indexSelected) {
325
+ index = -1; // remove the value
326
+ }
327
+
328
+ this.selectValue(index, true); // trigger change event
329
+ }
330
+ }, {
331
+ key: "onPointerLeave",
332
+ value: function onPointerLeave(ev) {
333
+ var _this4 = this;
334
+
335
+ // (MouseEvent):void
336
+ ev.preventDefault();
337
+ cancelAnimationFrame(this.tick);
338
+ requestAnimationFrame(function () {
339
+ return _this4.changeIndexTo(_this4.indexSelected);
340
+ });
341
+ }
342
+ }, {
343
+ key: "onPointerMove",
344
+ value: function onPointerMove(ev) {
345
+ var _this5 = this;
346
+
347
+ // (MouseEvent|TouchEvent):void
348
+ ev.preventDefault();
349
+
350
+ if (!this.ticking) {
351
+ this.tick = requestAnimationFrame(function () {
352
+ return _this5.changeIndexTo(_this5.indexFromEvent(ev));
353
+ });
354
+ this.ticking = true;
355
+ }
356
+ }
357
+ }, {
358
+ key: "onReset",
359
+ value: function onReset() {
360
+ var _this$el$querySelecto;
361
+
362
+ // ():void
363
+ var index = this.valueIndex((_this$el$querySelecto = this.el.querySelector('[selected]')) === null || _this$el$querySelecto === void 0 ? void 0 : _this$el$querySelecto.value);
364
+ this.selectValue(index || -1, false); // do not trigger change event
365
+ }
366
+ }, {
367
+ key: "selected",
368
+ value: function selected() {
369
+ // ():int
370
+ return this.valueIndex(this.el.value); // get the selected span index
371
+ }
372
+ }, {
373
+ key: "selectValue",
374
+ value: function selectValue(index, triggerChangeEvent) {
375
+ var _this$values$index2;
376
+
377
+ // (int, bool):void
378
+ this.el.value = ((_this$values$index2 = this.values[index]) === null || _this$values$index2 === void 0 ? void 0 : _this$values$index2.value) || ''; // first set the new value
379
+
380
+ this.indexSelected = this.selected(); // get the actual index from the selected value
381
+
382
+ if (false === triggerChangeEvent) {
383
+ this.changeIndexTo(this.selected(), true);
384
+ } else {
385
+ this.el.dispatchEvent(new Event('change'));
386
+ }
387
+ }
388
+ }, {
389
+ key: "valueIndex",
390
+ value: function valueIndex(value) {
391
+ return this.values.findIndex(function (val) {
392
+ return val.value === +value;
393
+ });
394
+ }
395
+ }]);
396
+
397
+ return Widget;
398
+ }();
399
+
400
+ var StarRating = /*#__PURE__*/function () {
401
+ function StarRating(selector, props) {
402
+ _classCallCheck(this, StarRating);
403
+
404
+ // (HTMLSelectElement|NodeList|string, object):void
405
+ this.destroy = this.destroy.bind(this);
406
+ this.props = props;
407
+ this.rebuild = this.rebuild.bind(this);
408
+ this.selector = selector;
409
+ this.widgets = [];
410
+ this.build();
411
+ }
412
+
413
+ _createClass(StarRating, [{
414
+ key: "build",
415
+ value: function build() {
416
+ var _this = this;
417
+
418
+ // (HTMLSelectElement|NodeList|string, object):void
419
+ this.queryElements(this.selector).forEach(function (el) {
420
+ var options = merge(defaults, _this.props, JSON.parse(el.getAttribute('data-options')));
421
+
422
+ if ('SELECT' === el.tagName && !el.widget) {
423
+ // check for an existing Widget reference
424
+ if (!options.prebuilt && el.parentNode.classList.contains(options.classNames.base)) {
425
+ _this.unwrap(el);
426
+ }
427
+
428
+ _this.widgets.push(new Widget(el, options));
429
+ }
430
+ });
431
+ }
432
+ }, {
433
+ key: "destroy",
434
+ value: function destroy() {
435
+ // ():void
436
+ this.widgets.forEach(function (widget) {
437
+ return widget.destroy();
438
+ });
439
+ this.widgets = [];
440
+ }
441
+ }, {
442
+ key: "queryElements",
443
+ value: function queryElements(selector) {
444
+ // (HTMLSelectElement|NodeList|string):array
445
+ if ('HTMLSelectElement' === type(selector)) {
446
+ return [selector];
447
+ }
448
+
449
+ if ('NodeList' === type(selector)) {
450
+ return [].slice.call(selector);
451
+ }
452
+
453
+ if ('String' === type(selector)) {
454
+ return [].slice.call(document.querySelectorAll(selector));
455
+ }
456
+
457
+ return [];
458
+ }
459
+ }, {
460
+ key: "rebuild",
461
+ value: function rebuild() {
462
+ // ():void
463
+ this.destroy();
464
+ this.build();
465
+ }
466
+ }, {
467
+ key: "unwrap",
468
+ value: function unwrap(el) {
469
+ var removeEl = el.parentNode;
470
+ var parentEl = removeEl.parentNode;
471
+ parentEl.insertBefore(el, removeEl);
472
+ parentEl.removeChild(removeEl);
473
+ }
474
+ }]);
475
+
476
+ return StarRating;
477
+ }();
478
+
479
+ export default StarRating;
@@ -0,0 +1 @@
1
+ function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var i=0;i<t.length;i++){var s=t[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function i(e,i,s){return i&&t(e.prototype,i),s&&t(e,s),e}var s={classNames:{active:"gl-active",base:"gl-star-rating",selected:"gl-selected"},clearable:!0,maxStars:10,prebuilt:!1,stars:null,tooltip:"Select a Rating"},n=function(e,t,i){e.classList[t?"add":"remove"](i)},a=function(e){var t=document.createElement("span");for(var i in e=e||{})t.setAttribute(i,e[i]);return t},l=function(e,t,i){var s=a(i);return e.parentNode.insertBefore(s,t?e.nextSibling:e),s},r=function e(){for(var t=arguments.length,i=new Array(t),s=0;s<t;s++)i[s]=arguments[s];var n={};return i.forEach((function(t){Object.keys(t||{}).forEach((function(s){if(void 0!==i[0][s]){var a=t[s];"Object"!==o(a)||"Object"!==o(n[s])?n[s]=a:n[s]=e(n[s],a)}}))})),n},o=function(e){return{}.toString.call(e).slice(8,-1)},h=function(){function t(i,s){var n,a,l;e(this,t),this.direction=window.getComputedStyle(i,null).getPropertyValue("direction"),this.el=i,this.events={change:this.onChange.bind(this),keydown:this.onKeyDown.bind(this),mousedown:this.onPointerDown.bind(this),mouseleave:this.onPointerLeave.bind(this),mousemove:this.onPointerMove.bind(this),reset:this.onReset.bind(this),touchend:this.onPointerDown.bind(this),touchmove:this.onPointerMove.bind(this)},this.indexActive=null,this.indexSelected=null,this.props=s,this.tick=null,this.ticking=!1,this.values=function(e){var t=[];return[].forEach.call(e.options,(function(e){var i=parseInt(e.value,10)||0;i>0&&t.push({index:e.index,text:e.text,value:i})})),t.sort((function(e,t){return e.value-t.value}))}(i),this.widgetEl=null,this.el.widget&&this.el.widget.destroy(),n=this.values.length,a=1,l=this.props.maxStars,/^\d+$/.test(n)&&a<=n&&n<=l?this.build():this.destroy()}return i(t,[{key:"build",value:function(){this.destroy(),this.buildWidget(),this.selectValue(this.indexSelected=this.selected(),!1),this.handleEvents("add"),this.el.widget=this}},{key:"buildWidget",value:function(){var e,t,i=this;this.props.prebuilt?(e=this.el.parentNode,t=e.querySelector("."+this.props.classNames.base+"--stars")):((e=l(this.el,!1,{class:this.props.classNames.base})).appendChild(this.el),t=l(this.el,!0,{class:this.props.classNames.base+"--stars"}),this.values.forEach((function(e,s){var n=a({"data-index":s,"data-value":e.value});"function"==typeof i.props.stars&&i.props.stars.call(i,n,e,s),[].forEach.call(n.children,(function(e){return e.style.pointerEvents="none"})),t.innerHTML+=n.outerHTML}))),e.dataset.starRating="",e.classList.add(this.props.classNames.base+"--"+this.direction),this.props.tooltip&&t.setAttribute("role","tooltip"),this.widgetEl=t}},{key:"changeIndexTo",value:function(e,t){var i=this;if(this.indexActive!==e||t){if([].forEach.call(this.widgetEl.children,(function(t,s){n(t,s<=e,i.props.classNames.active),n(t,s===i.indexSelected,i.props.classNames.selected)})),this.widgetEl.setAttribute("data-rating",e+1),"function"==typeof this.props.stars||this.props.prebuilt||(this.widgetEl.classList.remove("s"+10*(this.indexActive+1)),this.widgetEl.classList.add("s"+10*(e+1))),this.props.tooltip){var s,a=e<0?this.props.tooltip:null===(s=this.values[e])||void 0===s?void 0:s.text;this.widgetEl.setAttribute("aria-label",a)}this.indexActive=e}this.ticking=!1}},{key:"destroy",value:function(){this.indexActive=null,this.indexSelected=this.selected();var e=this.el.parentNode;e.classList.contains(this.props.classNames.base)&&(this.props.prebuilt?(this.widgetEl=e.querySelector("."+this.props.classNames.base+"--stars"),e.classList.remove(this.props.classNames.base+"--"+this.direction),delete e.dataset.starRating):e.parentNode.replaceChild(this.el,e),this.handleEvents("remove")),delete this.el.widget}},{key:"eventListener",value:function(e,t,i,s){var n=this;i.forEach((function(i){return e[t+"EventListener"](i,n.events[i],s||!1)}))}},{key:"handleEvents",value:function(e){var t=this.el.closest("form");t&&"FORM"===t.tagName&&this.eventListener(t,e,["reset"]),this.eventListener(this.el,e,["change"]),"add"===e&&this.el.disabled||(this.eventListener(this.el,e,["keydown"]),this.eventListener(this.widgetEl,e,["mousedown","mouseleave","mousemove","touchend","touchmove"],!1))}},{key:"indexFromEvent",value:function(e){var t,i,s=(null===(t=e.touches)||void 0===t?void 0:t[0])||(null===(i=e.changedTouches)||void 0===i?void 0:i[0])||e,n=document.elementFromPoint(s.clientX,s.clientY);return n.parentNode===this.widgetEl?[].slice.call(n.parentNode.children).indexOf(n):this.indexActive}},{key:"onChange",value:function(){this.changeIndexTo(this.selected(),!0)}},{key:"onKeyDown",value:function(e){var t=e.key.slice(5);if(~["Left","Right"].indexOf(t)){var i="Left"===t?-1:1;"rtl"===this.direction&&(i*=-1);var s=this.values.length-1,n=Math.min(Math.max(this.selected()+i,-1),s);this.selectValue(n,!0)}}},{key:"onPointerDown",value:function(e){e.preventDefault();var t=this.indexFromEvent(e);this.props.clearable&&t===this.indexSelected&&(t=-1),this.selectValue(t,!0)}},{key:"onPointerLeave",value:function(e){var t=this;e.preventDefault(),cancelAnimationFrame(this.tick),requestAnimationFrame((function(){return t.changeIndexTo(t.indexSelected)}))}},{key:"onPointerMove",value:function(e){var t=this;e.preventDefault(),this.ticking||(this.tick=requestAnimationFrame((function(){return t.changeIndexTo(t.indexFromEvent(e))})),this.ticking=!0)}},{key:"onReset",value:function(){var e,t=this.valueIndex(null===(e=this.el.querySelector("[selected]"))||void 0===e?void 0:e.value);this.selectValue(t||-1,!1)}},{key:"selected",value:function(){return this.valueIndex(this.el.value)}},{key:"selectValue",value:function(e,t){var i;this.el.value=(null===(i=this.values[e])||void 0===i?void 0:i.value)||"",this.indexSelected=this.selected(),!1===t?this.changeIndexTo(this.selected(),!0):this.el.dispatchEvent(new Event("change"))}},{key:"valueIndex",value:function(e){return this.values.findIndex((function(t){return t.value===+e}))}}]),t}(),u=function(){function t(i,s){e(this,t),this.destroy=this.destroy.bind(this),this.props=s,this.rebuild=this.rebuild.bind(this),this.selector=i,this.widgets=[],this.build()}return i(t,[{key:"build",value:function(){var e=this;this.queryElements(this.selector).forEach((function(t){var i=r(s,e.props,JSON.parse(t.getAttribute("data-options")));"SELECT"!==t.tagName||t.widget||(!i.prebuilt&&t.parentNode.classList.contains(i.classNames.base)&&e.unwrap(t),e.widgets.push(new h(t,i)))}))}},{key:"destroy",value:function(){this.widgets.forEach((function(e){return e.destroy()})),this.widgets=[]}},{key:"queryElements",value:function(e){return"HTMLSelectElement"===o(e)?[e]:"NodeList"===o(e)?[].slice.call(e):"String"===o(e)?[].slice.call(document.querySelectorAll(e)):[]}},{key:"rebuild",value:function(){this.destroy(),this.build()}},{key:"unwrap",value:function(e){var t=e.parentNode,i=t.parentNode;i.insertBefore(e,t),i.removeChild(t)}}]),t}();export default u;