@hellotext/hellotext 2.5.7 → 2.5.8

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 (102) hide show
  1. package/README.md +0 -25
  2. package/dist/hellotext.js +1 -1
  3. package/index.d.ts +0 -6
  4. package/lib/api/acks.cjs +17 -31
  5. package/lib/api/acks.js +17 -42
  6. package/lib/api/businesses.cjs +14 -28
  7. package/lib/api/businesses.js +13 -36
  8. package/lib/api/events.cjs +26 -40
  9. package/lib/api/events.js +28 -52
  10. package/lib/api/forms.cjs +24 -40
  11. package/lib/api/forms.js +24 -57
  12. package/lib/api/identifications.cjs +15 -29
  13. package/lib/api/identifications.js +15 -40
  14. package/lib/api/index.cjs +25 -51
  15. package/lib/api/index.js +27 -54
  16. package/lib/api/push/identities.cjs +30 -46
  17. package/lib/api/push/identities.js +30 -63
  18. package/lib/api/response.cjs +30 -52
  19. package/lib/api/response.js +31 -60
  20. package/lib/api/submissions.cjs +18 -34
  21. package/lib/api/submissions.js +18 -48
  22. package/lib/api/webchat/messages.cjs +44 -64
  23. package/lib/api/webchat/messages.js +44 -80
  24. package/lib/api/webchats.cjs +37 -56
  25. package/lib/api/webchats.js +37 -65
  26. package/lib/api/whatsapp_widgets.cjs +49 -72
  27. package/lib/api/whatsapp_widgets.js +48 -91
  28. package/lib/builders/input_builder.cjs +36 -48
  29. package/lib/builders/input_builder.js +36 -48
  30. package/lib/builders/logo_builder.cjs +10 -29
  31. package/lib/builders/logo_builder.js +20 -28
  32. package/lib/channels/application_channel.cjs +136 -178
  33. package/lib/channels/application_channel.js +137 -180
  34. package/lib/channels/webchat_channel.cjs +125 -170
  35. package/lib/channels/webchat_channel.js +125 -170
  36. package/lib/controllers/form_controller.cjs +82 -121
  37. package/lib/controllers/form_controller.js +82 -130
  38. package/lib/controllers/message_controller.cjs +211 -282
  39. package/lib/controllers/message_controller.js +209 -284
  40. package/lib/controllers/mixins/usePopover.cjs +3 -6
  41. package/lib/controllers/mixins/usePopover.js +17 -22
  42. package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
  43. package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
  44. package/lib/controllers/webchat/useBehaviour.js +5 -5
  45. package/lib/controllers/webchat/useOpeningSequence.js +6 -6
  46. package/lib/controllers/webchat/useTeaser.js +9 -9
  47. package/lib/controllers/webchat_controller.cjs +916 -1088
  48. package/lib/controllers/webchat_controller.js +926 -1152
  49. package/lib/core/configuration/forms.cjs +21 -35
  50. package/lib/core/configuration/forms.js +20 -35
  51. package/lib/core/configuration/locale.cjs +36 -71
  52. package/lib/core/configuration/locale.js +36 -70
  53. package/lib/core/configuration/push.cjs +9 -21
  54. package/lib/core/configuration/push.js +8 -20
  55. package/lib/core/configuration/webchat.cjs +142 -182
  56. package/lib/core/configuration/webchat.js +145 -189
  57. package/lib/core/configuration/whatsapp.cjs +76 -102
  58. package/lib/core/configuration/whatsapp.js +76 -105
  59. package/lib/core/configuration.cjs +60 -78
  60. package/lib/core/configuration.js +59 -78
  61. package/lib/core/event.cjs +36 -59
  62. package/lib/core/event.js +35 -61
  63. package/lib/core/sanitize_html.js +4 -4
  64. package/lib/errors/invalid_event.cjs +5 -26
  65. package/lib/errors/invalid_event.js +5 -26
  66. package/lib/errors/not_initialized_error.cjs +5 -26
  67. package/lib/errors/not_initialized_error.js +5 -26
  68. package/lib/hellotext.cjs +185 -223
  69. package/lib/hellotext.js +188 -247
  70. package/lib/index.js +1 -1
  71. package/lib/models/business.cjs +114 -152
  72. package/lib/models/business.js +117 -162
  73. package/lib/models/cookies.cjs +34 -51
  74. package/lib/models/cookies.js +34 -51
  75. package/lib/models/fingerprint.cjs +8 -23
  76. package/lib/models/fingerprint.js +25 -58
  77. package/lib/models/form.cjs +106 -142
  78. package/lib/models/form.js +105 -153
  79. package/lib/models/form_collection.cjs +63 -101
  80. package/lib/models/form_collection.js +61 -107
  81. package/lib/models/page.cjs +106 -129
  82. package/lib/models/page.js +106 -131
  83. package/lib/models/push.cjs +278 -322
  84. package/lib/models/push.js +284 -357
  85. package/lib/models/query.cjs +21 -41
  86. package/lib/models/query.js +21 -41
  87. package/lib/models/session.cjs +33 -65
  88. package/lib/models/session.js +30 -63
  89. package/lib/models/user.cjs +29 -51
  90. package/lib/models/user.js +29 -51
  91. package/lib/models/utm.cjs +15 -27
  92. package/lib/models/utm.js +17 -32
  93. package/lib/models/webchat.cjs +52 -76
  94. package/lib/models/webchat.js +52 -90
  95. package/lib/models/whatsapp_widget.cjs +41 -59
  96. package/lib/models/whatsapp_widget.js +41 -73
  97. package/lib/vanilla.cjs +4 -7
  98. package/lib/vanilla.js +2 -1
  99. package/package.json +1 -9
  100. package/src/index.bundle.js +0 -1
  101. package/src/vanilla.js +2 -1
  102. package/styles/index.css +0 -30
@@ -1,292 +1,217 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
8
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
13
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
1
  import { Controller } from '@hotwired/stimulus';
17
2
  import Hellotext from '../hellotext';
18
- var _default = /*#__PURE__*/function (_Controller) {
19
- _inherits(_default, _Controller);
20
- var _super = _createSuper(_default);
21
- function _default() {
22
- _classCallCheck(this, _default);
23
- return _super.apply(this, arguments);
3
+ export default class extends Controller {
4
+ static values = {
5
+ fadeDistance: {
6
+ type: Number,
7
+ default: 64
8
+ },
9
+ id: String,
10
+ kind: String,
11
+ pageStartOffset: {
12
+ type: Number,
13
+ default: 0
14
+ },
15
+ utm: Object
16
+ };
17
+ static targets = ['carouselContainer', 'leftFade', 'rightFade', 'carouselCard'];
18
+ connect() {
19
+ this.updateFades();
20
+ this.observeContainerSize();
24
21
  }
25
- _createClass(_default, [{
26
- key: "connect",
27
- value: function connect() {
28
- this.updateFades();
29
- this.observeContainerSize();
30
- }
31
- }, {
32
- key: "disconnect",
33
- value: function disconnect() {
34
- var _this$resizeObserver;
35
- (_this$resizeObserver = this.resizeObserver) === null || _this$resizeObserver === void 0 ? void 0 : _this$resizeObserver.disconnect();
36
- }
37
- }, {
38
- key: "setId",
39
- value: function setId(_ref) {
40
- var {
41
- detail: id
42
- } = _ref;
43
- this.idValue = id;
44
- this.element.id = id;
45
- }
46
- }, {
47
- key: "onScroll",
48
- value: function onScroll() {
49
- this.updateFades();
50
- }
51
- }, {
52
- key: "quickReply",
53
- value: function quickReply(_ref2) {
54
- var {
55
- currentTarget
56
- } = _ref2;
57
- var card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
58
- var messageElement = currentTarget.closest('[data-controller~="hellotext--message"]');
59
- var body = currentTarget.dataset.text || currentTarget.textContent.trim();
60
- this.dispatch('quickReply', {
61
- detail: {
62
- id: this.idValue,
63
- product: card === null || card === void 0 ? void 0 : card.dataset.id,
64
- buttonId: currentTarget.dataset.id,
65
- body,
66
- cardElement: card || messageElement || currentTarget
67
- }
68
- });
69
- }
70
- }, {
71
- key: "addToCart",
72
- value: function addToCart(_ref3) {
73
- var {
74
- currentTarget
75
- } = _ref3;
76
- var card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
77
- var {
78
- id,
79
- reference,
80
- source
81
- } = card.dataset;
82
- var item = {
83
- product: id,
84
- quantity: 1
85
- };
86
- if (this.hasUtmValue) Hellotext.page.utm.save(this.utmValue);
87
- Hellotext.eventEmitter.dispatch('cart.added', {
88
- object_parameters: {
89
- items: [_objectSpread(_objectSpread(_objectSpread({}, item), reference && {
22
+ disconnect() {
23
+ this.resizeObserver?.disconnect();
24
+ }
25
+ setId({
26
+ detail: id
27
+ }) {
28
+ this.idValue = id;
29
+ this.element.id = id;
30
+ }
31
+ onScroll() {
32
+ this.updateFades();
33
+ }
34
+ quickReply({
35
+ currentTarget
36
+ }) {
37
+ const card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
38
+ const messageElement = currentTarget.closest('[data-controller~="hellotext--message"]');
39
+ const body = currentTarget.dataset.text || currentTarget.textContent.trim();
40
+ this.dispatch('quickReply', {
41
+ detail: {
42
+ id: this.idValue,
43
+ product: card?.dataset.id,
44
+ buttonId: currentTarget.dataset.id,
45
+ body,
46
+ cardElement: card || messageElement || currentTarget
47
+ }
48
+ });
49
+ }
50
+ addToCart({
51
+ currentTarget
52
+ }) {
53
+ const card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
54
+ const {
55
+ id,
56
+ reference,
57
+ source
58
+ } = card.dataset;
59
+ const item = {
60
+ product: id,
61
+ quantity: 1
62
+ };
63
+ if (this.hasUtmValue) Hellotext.page.utm.save(this.utmValue);
64
+ Hellotext.eventEmitter.dispatch('cart.added', {
65
+ object_parameters: {
66
+ items: [{
67
+ ...item,
68
+ ...(reference && {
90
69
  reference
91
- }), source && {
70
+ }),
71
+ ...(source && {
92
72
  source
93
- })]
94
- },
95
- source: {
96
- kind: this.kindValue,
97
- message_id: this.idValue,
98
- button_id: currentTarget.dataset.id
99
- }
100
- });
101
- }
102
- }, {
103
- key: "moveToLeft",
104
- value: function moveToLeft() {
105
- if (!this.hasCarouselContainerTarget) return;
106
- var nextScrollLeft = this.getPreviousPageScrollLeft();
107
- var scrollAmount = this.carouselContainerTarget.scrollLeft - nextScrollLeft;
108
- if (scrollAmount < 1) return;
109
- this.carouselContainerTarget.scrollBy({
110
- left: -scrollAmount,
111
- behavior: 'smooth'
112
- });
113
- }
114
- }, {
115
- key: "moveToRight",
116
- value: function moveToRight() {
117
- if (!this.hasCarouselContainerTarget) return;
118
- var nextScrollLeft = this.getNextPageScrollLeft();
119
- var scrollAmount = nextScrollLeft - this.carouselContainerTarget.scrollLeft;
120
- if (scrollAmount < 1) return;
121
- this.carouselContainerTarget.scrollBy({
122
- left: scrollAmount,
123
- behavior: 'smooth'
124
- });
125
- }
126
- }, {
127
- key: "getScrollAmount",
128
- value: function getScrollAmount() {
129
- return this.getCardScrollAmount();
130
- }
131
- }, {
132
- key: "getCardScrollAmount",
133
- value: function getCardScrollAmount() {
134
- var firstCard = this.carouselContainerTarget.querySelector('.message__carousel_card');
135
- if (!firstCard) {
136
- return 280; // Fallback to default desktop card width
137
- }
138
-
139
- var cardWidth = firstCard.offsetWidth;
140
- return cardWidth + this.getGap();
141
- }
142
- }, {
143
- key: "getPageScrollAmount",
144
- value: function getPageScrollAmount() {
145
- var scrollAmount = this.carouselContainerTarget.clientWidth - this.getGap();
146
- return scrollAmount > 0 ? scrollAmount : this.getCardScrollAmount();
147
- }
148
- }, {
149
- key: "getNextPageScrollLeft",
150
- value: function getNextPageScrollLeft() {
151
- var currentScrollLeft = this.getCurrentScrollLeft();
152
- var viewportRight = currentScrollLeft + this.carouselContainerTarget.clientWidth;
153
- var cardMetrics = this.getCardMetrics();
154
- var nextCard = cardMetrics.find(card => card.end > viewportRight + 1);
155
- var targetScrollLeft = nextCard ? this.getPageAlignedScrollLeft(nextCard.start) : currentScrollLeft + this.getPageScrollAmount();
156
- var fallbackScrollLeft = currentScrollLeft + this.getPageScrollAmount();
157
- return this.clampScrollLeft(targetScrollLeft > currentScrollLeft + 1 ? targetScrollLeft : fallbackScrollLeft);
158
- }
159
- }, {
160
- key: "getPreviousPageScrollLeft",
161
- value: function getPreviousPageScrollLeft() {
162
- var _ref4, _previousPageCard$sta;
163
- var currentScrollLeft = this.getCurrentScrollLeft();
164
- if (currentScrollLeft <= 1) return 0;
165
- var targetThreshold = Math.max(currentScrollLeft - this.getPageScrollAmount(), 0);
166
- if (targetThreshold <= 1) return 0;
167
- var cardMetrics = this.getCardMetrics();
168
- var previousPageCard = cardMetrics.find(card => card.start >= targetThreshold - 1 && card.start < currentScrollLeft - 1);
169
- var previousCard = [...cardMetrics].reverse().find(card => card.start < currentScrollLeft - 1);
170
- return this.getPageAlignedScrollLeft((_ref4 = (_previousPageCard$sta = previousPageCard === null || previousPageCard === void 0 ? void 0 : previousPageCard.start) !== null && _previousPageCard$sta !== void 0 ? _previousPageCard$sta : previousCard === null || previousCard === void 0 ? void 0 : previousCard.start) !== null && _ref4 !== void 0 ? _ref4 : 0);
171
- }
172
- }, {
173
- key: "getPageAlignedScrollLeft",
174
- value: function getPageAlignedScrollLeft(cardStart) {
175
- var pageStartOffset = this.getPageStartOffset();
176
- if (cardStart <= pageStartOffset + 1) return 0;
177
- return this.clampScrollLeft(cardStart - pageStartOffset);
178
- }
179
- }, {
180
- key: "getCardMetrics",
181
- value: function getCardMetrics() {
182
- return Array.from(this.carouselContainerTarget.querySelectorAll('.message__carousel_card')).map(card => {
183
- var start = this.getCardScrollLeft(card);
184
- return {
185
- start,
186
- end: start + card.offsetWidth
187
- };
188
- });
189
- }
190
- }, {
191
- key: "getCardScrollLeft",
192
- value: function getCardScrollLeft(card) {
193
- var cardRect = card.getBoundingClientRect();
194
- var containerRect = this.carouselContainerTarget.getBoundingClientRect();
195
- if (cardRect.left || cardRect.width || containerRect.left || containerRect.width) {
196
- return cardRect.left - containerRect.left + this.carouselContainerTarget.scrollLeft;
73
+ })
74
+ }]
75
+ },
76
+ source: {
77
+ kind: this.kindValue,
78
+ message_id: this.idValue,
79
+ button_id: currentTarget.dataset.id
197
80
  }
198
- return card.offsetLeft || 0;
199
- }
200
- }, {
201
- key: "getCurrentScrollLeft",
202
- value: function getCurrentScrollLeft() {
203
- return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft);
204
- }
205
- }, {
206
- key: "clampScrollLeft",
207
- value: function clampScrollLeft(scrollLeft) {
208
- var maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
209
- return Math.min(Math.max(scrollLeft, 0), maxScroll);
210
- }
211
- }, {
212
- key: "getGap",
213
- value: function getGap() {
214
- var styles = window.getComputedStyle(this.carouselContainerTarget);
215
- var gap = Number.parseFloat(styles.columnGap || styles.gap);
216
- return Number.isFinite(gap) ? gap : 16;
217
- }
218
- }, {
219
- key: "getFadeDistance",
220
- value: function getFadeDistance() {
221
- return Number.isFinite(this.fadeDistanceValue) ? this.fadeDistanceValue : 64;
222
- }
223
- }, {
224
- key: "getPageStartOffset",
225
- value: function getPageStartOffset() {
226
- return Number.isFinite(this.pageStartOffsetValue) ? this.pageStartOffsetValue : 0;
227
- }
228
- }, {
229
- key: "observeContainerSize",
230
- value: function observeContainerSize() {
231
- if (!this.hasCarouselContainerTarget || !window.ResizeObserver) return;
232
- this.resizeObserver = new ResizeObserver(() => this.updateFades());
233
- this.resizeObserver.observe(this.carouselContainerTarget);
234
- }
235
- }, {
236
- key: "updateFades",
237
- value: function updateFades() {
238
- if (!this.hasCarouselContainerTarget) return;
239
- var maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
240
- if (maxScroll <= 1) {
241
- this.hideFade(this.leftFadeTarget);
242
- this.hideFade(this.rightFadeTarget);
243
- return;
244
- }
245
- var scrollLeft = Math.min(Math.max(this.carouselContainerTarget.scrollLeft, 0), maxScroll);
246
- var fadeDistance = this.getFadeDistance();
247
- this.setFadeOpacity(this.leftFadeTarget, scrollLeft / fadeDistance);
248
- this.setFadeOpacity(this.rightFadeTarget, (maxScroll - scrollLeft) / fadeDistance);
249
- }
250
- }, {
251
- key: "setFadeOpacity",
252
- value: function setFadeOpacity(fadeTarget, opacity) {
253
- var clampedOpacity = Math.min(Math.max(opacity, 0), 1);
254
- if (clampedOpacity <= 0.05) {
255
- this.hideFade(fadeTarget);
256
- return;
257
- }
258
- fadeTarget.classList.remove('hidden');
259
- fadeTarget.removeAttribute('disabled');
260
- fadeTarget.removeAttribute('tabindex');
261
- fadeTarget.setAttribute('aria-hidden', 'false');
262
- fadeTarget.style.opacity = clampedOpacity.toFixed(3);
263
- fadeTarget.style.pointerEvents = 'auto';
81
+ });
82
+ }
83
+ moveToLeft() {
84
+ if (!this.hasCarouselContainerTarget) return;
85
+ const nextScrollLeft = this.getPreviousPageScrollLeft();
86
+ const scrollAmount = this.carouselContainerTarget.scrollLeft - nextScrollLeft;
87
+ if (scrollAmount < 1) return;
88
+ this.carouselContainerTarget.scrollBy({
89
+ left: -scrollAmount,
90
+ behavior: 'smooth'
91
+ });
92
+ }
93
+ moveToRight() {
94
+ if (!this.hasCarouselContainerTarget) return;
95
+ const nextScrollLeft = this.getNextPageScrollLeft();
96
+ const scrollAmount = nextScrollLeft - this.carouselContainerTarget.scrollLeft;
97
+ if (scrollAmount < 1) return;
98
+ this.carouselContainerTarget.scrollBy({
99
+ left: scrollAmount,
100
+ behavior: 'smooth'
101
+ });
102
+ }
103
+ getScrollAmount() {
104
+ return this.getCardScrollAmount();
105
+ }
106
+ getCardScrollAmount() {
107
+ const firstCard = this.carouselContainerTarget.querySelector('.message__carousel_card');
108
+ if (!firstCard) {
109
+ return 280; // Fallback to default desktop card width
264
110
  }
265
- }, {
266
- key: "hideFade",
267
- value: function hideFade(fadeTarget) {
268
- fadeTarget.style.opacity = '0';
269
- fadeTarget.style.pointerEvents = 'none';
270
- fadeTarget.setAttribute('aria-hidden', 'true');
271
- fadeTarget.setAttribute('tabindex', '-1');
272
- if ('disabled' in fadeTarget) fadeTarget.disabled = true;
273
- fadeTarget.classList.add('hidden');
111
+
112
+ const cardWidth = firstCard.offsetWidth;
113
+ return cardWidth + this.getGap();
114
+ }
115
+ getPageScrollAmount() {
116
+ const scrollAmount = this.carouselContainerTarget.clientWidth - this.getGap();
117
+ return scrollAmount > 0 ? scrollAmount : this.getCardScrollAmount();
118
+ }
119
+ getNextPageScrollLeft() {
120
+ const currentScrollLeft = this.getCurrentScrollLeft();
121
+ const viewportRight = currentScrollLeft + this.carouselContainerTarget.clientWidth;
122
+ const cardMetrics = this.getCardMetrics();
123
+ const nextCard = cardMetrics.find(card => card.end > viewportRight + 1);
124
+ const targetScrollLeft = nextCard ? this.getPageAlignedScrollLeft(nextCard.start) : currentScrollLeft + this.getPageScrollAmount();
125
+ const fallbackScrollLeft = currentScrollLeft + this.getPageScrollAmount();
126
+ return this.clampScrollLeft(targetScrollLeft > currentScrollLeft + 1 ? targetScrollLeft : fallbackScrollLeft);
127
+ }
128
+ getPreviousPageScrollLeft() {
129
+ const currentScrollLeft = this.getCurrentScrollLeft();
130
+ if (currentScrollLeft <= 1) return 0;
131
+ const targetThreshold = Math.max(currentScrollLeft - this.getPageScrollAmount(), 0);
132
+ if (targetThreshold <= 1) return 0;
133
+ const cardMetrics = this.getCardMetrics();
134
+ const previousPageCard = cardMetrics.find(card => card.start >= targetThreshold - 1 && card.start < currentScrollLeft - 1);
135
+ const previousCard = [...cardMetrics].reverse().find(card => card.start < currentScrollLeft - 1);
136
+ return this.getPageAlignedScrollLeft(previousPageCard?.start ?? previousCard?.start ?? 0);
137
+ }
138
+ getPageAlignedScrollLeft(cardStart) {
139
+ const pageStartOffset = this.getPageStartOffset();
140
+ if (cardStart <= pageStartOffset + 1) return 0;
141
+ return this.clampScrollLeft(cardStart - pageStartOffset);
142
+ }
143
+ getCardMetrics() {
144
+ return Array.from(this.carouselContainerTarget.querySelectorAll('.message__carousel_card')).map(card => {
145
+ const start = this.getCardScrollLeft(card);
146
+ return {
147
+ start,
148
+ end: start + card.offsetWidth
149
+ };
150
+ });
151
+ }
152
+ getCardScrollLeft(card) {
153
+ const cardRect = card.getBoundingClientRect();
154
+ const containerRect = this.carouselContainerTarget.getBoundingClientRect();
155
+ if (cardRect.left || cardRect.width || containerRect.left || containerRect.width) {
156
+ return cardRect.left - containerRect.left + this.carouselContainerTarget.scrollLeft;
274
157
  }
275
- }]);
276
- return _default;
277
- }(Controller);
278
- _default.values = {
279
- fadeDistance: {
280
- type: Number,
281
- default: 64
282
- },
283
- id: String,
284
- kind: String,
285
- pageStartOffset: {
286
- type: Number,
287
- default: 0
288
- },
289
- utm: Object
290
- };
291
- _default.targets = ['carouselContainer', 'leftFade', 'rightFade', 'carouselCard'];
292
- export { _default as default };
158
+ return card.offsetLeft || 0;
159
+ }
160
+ getCurrentScrollLeft() {
161
+ return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft);
162
+ }
163
+ clampScrollLeft(scrollLeft) {
164
+ const maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
165
+ return Math.min(Math.max(scrollLeft, 0), maxScroll);
166
+ }
167
+ getGap() {
168
+ const styles = window.getComputedStyle(this.carouselContainerTarget);
169
+ const gap = Number.parseFloat(styles.columnGap || styles.gap);
170
+ return Number.isFinite(gap) ? gap : 16;
171
+ }
172
+ getFadeDistance() {
173
+ return Number.isFinite(this.fadeDistanceValue) ? this.fadeDistanceValue : 64;
174
+ }
175
+ getPageStartOffset() {
176
+ return Number.isFinite(this.pageStartOffsetValue) ? this.pageStartOffsetValue : 0;
177
+ }
178
+ observeContainerSize() {
179
+ if (!this.hasCarouselContainerTarget || !window.ResizeObserver) return;
180
+ this.resizeObserver = new ResizeObserver(() => this.updateFades());
181
+ this.resizeObserver.observe(this.carouselContainerTarget);
182
+ }
183
+ updateFades() {
184
+ if (!this.hasCarouselContainerTarget) return;
185
+ const maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
186
+ if (maxScroll <= 1) {
187
+ this.hideFade(this.leftFadeTarget);
188
+ this.hideFade(this.rightFadeTarget);
189
+ return;
190
+ }
191
+ const scrollLeft = Math.min(Math.max(this.carouselContainerTarget.scrollLeft, 0), maxScroll);
192
+ const fadeDistance = this.getFadeDistance();
193
+ this.setFadeOpacity(this.leftFadeTarget, scrollLeft / fadeDistance);
194
+ this.setFadeOpacity(this.rightFadeTarget, (maxScroll - scrollLeft) / fadeDistance);
195
+ }
196
+ setFadeOpacity(fadeTarget, opacity) {
197
+ const clampedOpacity = Math.min(Math.max(opacity, 0), 1);
198
+ if (clampedOpacity <= 0.05) {
199
+ this.hideFade(fadeTarget);
200
+ return;
201
+ }
202
+ fadeTarget.classList.remove('hidden');
203
+ fadeTarget.removeAttribute('disabled');
204
+ fadeTarget.removeAttribute('tabindex');
205
+ fadeTarget.setAttribute('aria-hidden', 'false');
206
+ fadeTarget.style.opacity = clampedOpacity.toFixed(3);
207
+ fadeTarget.style.pointerEvents = 'auto';
208
+ }
209
+ hideFade(fadeTarget) {
210
+ fadeTarget.style.opacity = '0';
211
+ fadeTarget.style.pointerEvents = 'none';
212
+ fadeTarget.setAttribute('aria-hidden', 'true');
213
+ fadeTarget.setAttribute('tabindex', '-1');
214
+ if ('disabled' in fadeTarget) fadeTarget.disabled = true;
215
+ fadeTarget.classList.add('hidden');
216
+ }
217
+ }
@@ -9,16 +9,14 @@ var _core = require("../../core");
9
9
  const usePopover = controller => {
10
10
  Object.assign(controller, {
11
11
  show() {
12
- var _this$cancelBehaviour;
13
- (_this$cancelBehaviour = this.cancelBehaviourOpen) === null || _this$cancelBehaviour === void 0 ? void 0 : _this$cancelBehaviour.call(this);
12
+ this.cancelBehaviourOpen?.();
14
13
  this.openValue = true;
15
14
  },
16
15
  hide() {
17
16
  this.openValue = false;
18
17
  },
19
18
  toggle() {
20
- var _this$cancelBehaviour2;
21
- (_this$cancelBehaviour2 = this.cancelBehaviourOpen) === null || _this$cancelBehaviour2 === void 0 ? void 0 : _this$cancelBehaviour2.call(this);
19
+ this.cancelBehaviourOpen?.();
22
20
  this.openValue = !this.openValue;
23
21
  },
24
22
  setupFloatingUI({
@@ -48,8 +46,7 @@ const usePopover = controller => {
48
46
  openValueChanged() {
49
47
  if (this.disabledValue) return;
50
48
  if (this.openValue) {
51
- var _this$preparePopoverO;
52
- (_this$preparePopoverO = this.preparePopoverOpenAnimation) === null || _this$preparePopoverO === void 0 ? void 0 : _this$preparePopoverO.call(this);
49
+ this.preparePopoverOpenAnimation?.();
53
50
  this.popoverTarget.showPopover();
54
51
  this.popoverTarget.setAttribute('aria-expanded', 'true');
55
52
  if (this['onPopoverOpened']) {
@@ -1,40 +1,36 @@
1
1
  import { autoUpdate, computePosition } from '@floating-ui/dom';
2
2
  import { Configuration } from '../../core';
3
- export var usePopover = controller => {
3
+ export const usePopover = controller => {
4
4
  Object.assign(controller, {
5
5
  show() {
6
- var _this$cancelBehaviour;
7
- (_this$cancelBehaviour = this.cancelBehaviourOpen) === null || _this$cancelBehaviour === void 0 ? void 0 : _this$cancelBehaviour.call(this);
6
+ this.cancelBehaviourOpen?.();
8
7
  this.openValue = true;
9
8
  },
10
9
  hide() {
11
10
  this.openValue = false;
12
11
  },
13
12
  toggle() {
14
- var _this$cancelBehaviour2;
15
- (_this$cancelBehaviour2 = this.cancelBehaviourOpen) === null || _this$cancelBehaviour2 === void 0 ? void 0 : _this$cancelBehaviour2.call(this);
13
+ this.cancelBehaviourOpen?.();
16
14
  this.openValue = !this.openValue;
17
15
  },
18
- setupFloatingUI(_ref) {
19
- var {
20
- trigger,
21
- popover,
22
- strategy
23
- } = _ref;
16
+ setupFloatingUI({
17
+ trigger,
18
+ popover,
19
+ strategy
20
+ }) {
24
21
  this.floatingUICleanup = autoUpdate(trigger, popover, () => {
25
22
  computePosition(trigger, popover, {
26
23
  placement: this.placementValue,
27
24
  middleware: this.middlewares,
28
25
  strategy: strategy || Configuration.webchat.strategy
29
- }).then(_ref2 => {
30
- var {
31
- x,
32
- y,
33
- strategy
34
- } = _ref2;
35
- var newStyle = {
36
- left: "".concat(x, "px"),
37
- top: "".concat(y, "px"),
26
+ }).then(({
27
+ x,
28
+ y,
29
+ strategy
30
+ }) => {
31
+ const newStyle = {
32
+ left: `${x}px`,
33
+ top: `${y}px`,
38
34
  position: strategy
39
35
  };
40
36
  Object.assign(popover.style, newStyle);
@@ -44,8 +40,7 @@ export var usePopover = controller => {
44
40
  openValueChanged() {
45
41
  if (this.disabledValue) return;
46
42
  if (this.openValue) {
47
- var _this$preparePopoverO;
48
- (_this$preparePopoverO = this.preparePopoverOpenAnimation) === null || _this$preparePopoverO === void 0 ? void 0 : _this$preparePopoverO.call(this);
43
+ this.preparePopoverOpenAnimation?.();
49
44
  this.popoverTarget.showPopover();
50
45
  this.popoverTarget.setAttribute('aria-expanded', 'true');
51
46
  if (this['onPopoverOpened']) {