@hellotext/hellotext 2.1.2 → 2.1.3

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 (44) hide show
  1. package/dist/hellotext.js +1 -1
  2. package/lib/api/forms.cjs +2 -1
  3. package/lib/api/forms.js +2 -1
  4. package/lib/api/webchat/messages.cjs +4 -3
  5. package/lib/api/webchat/messages.js +4 -2
  6. package/lib/api/webchats.cjs +2 -0
  7. package/lib/api/webchats.js +3 -1
  8. package/lib/builders/logo_builder.cjs +1 -1
  9. package/lib/builders/logo_builder.js +1 -1
  10. package/lib/controllers/webchat/emoji_picker_controller.cjs +6 -6
  11. package/lib/controllers/webchat/emoji_picker_controller.js +5 -14
  12. package/lib/controllers/webchat_controller.cjs +34 -6
  13. package/lib/controllers/webchat_controller.js +34 -6
  14. package/lib/core/configuration/locale.cjs +87 -0
  15. package/lib/core/configuration/locale.js +81 -0
  16. package/lib/core/configuration.cjs +10 -0
  17. package/lib/core/configuration.js +10 -0
  18. package/lib/core/index.cjs +15 -1
  19. package/lib/core/index.js +4 -2
  20. package/lib/locales/en.cjs +1 -1
  21. package/lib/locales/en.js +1 -1
  22. package/lib/locales/es.cjs +1 -1
  23. package/lib/locales/es.js +1 -1
  24. package/lib/models/business.cjs +11 -0
  25. package/lib/models/business.js +11 -0
  26. package/lib/models/form_collection.cjs +1 -0
  27. package/lib/models/form_collection.js +2 -1
  28. package/lib/models/index.cjs +4 -4
  29. package/lib/models/index.js +4 -4
  30. package/package.json +2 -1
  31. package/src/api/forms.js +3 -1
  32. package/src/api/webchat/messages.js +8 -6
  33. package/src/api/webchats.js +3 -1
  34. package/src/builders/logo_builder.js +1 -1
  35. package/src/controllers/webchat/emoji_picker_controller.js +9 -15
  36. package/src/controllers/webchat_controller.js +32 -10
  37. package/src/core/configuration/locale.js +50 -0
  38. package/src/core/configuration.js +10 -0
  39. package/src/core/index.js +3 -1
  40. package/src/locales/en.js +4 -4
  41. package/src/locales/es.js +4 -4
  42. package/src/models/business.js +12 -0
  43. package/src/models/form_collection.js +2 -1
  44. package/src/models/index.js +3 -3
package/lib/api/forms.cjs CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _hellotext = _interopRequireDefault(require("../hellotext"));
8
7
  var _core = require("../core");
8
+ var _hellotext = _interopRequireDefault(require("../hellotext"));
9
9
  var _response = require("./response");
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -27,6 +27,7 @@ let FormsAPI = /*#__PURE__*/function () {
27
27
  value: async function get(id) {
28
28
  const url = new URL(`${this.endpoint}/${id}`);
29
29
  url.searchParams.append('session', _hellotext.default.session);
30
+ url.searchParams.append('locale', _core.Locale.toString());
30
31
  return fetch(url, {
31
32
  method: 'GET',
32
33
  headers: _hellotext.default.headers
package/lib/api/forms.js CHANGED
@@ -8,8 +8,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
8
8
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
10
  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); }
11
+ import { Configuration, Locale } from '../core';
11
12
  import Hellotext from '../hellotext';
12
- import { Configuration } from '../core';
13
13
  import { Response } from './response';
14
14
  var FormsAPI = /*#__PURE__*/function () {
15
15
  function FormsAPI() {
@@ -26,6 +26,7 @@ var FormsAPI = /*#__PURE__*/function () {
26
26
  var _get = _asyncToGenerator(function* (id) {
27
27
  var url = new URL("".concat(this.endpoint, "/").concat(id));
28
28
  url.searchParams.append('session', Hellotext.session);
29
+ url.searchParams.append('locale', Locale.toString());
29
30
  return fetch(url, {
30
31
  method: 'GET',
31
32
  headers: Hellotext.headers
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _hellotext = _interopRequireDefault(require("../../hellotext"));
8
7
  var _core = require("../../core");
8
+ var _hellotext = _interopRequireDefault(require("../../hellotext"));
9
9
  var _response = require("../response");
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -44,8 +44,9 @@ let WebchatMessagesAPI = /*#__PURE__*/function () {
44
44
  }
45
45
  }, {
46
46
  key: "markAsSeen",
47
- value: function markAsSeen() {
48
- fetch(this.url + '/seen', {
47
+ value: function markAsSeen(messageId = null) {
48
+ const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
49
+ fetch(url, {
49
50
  method: 'PATCH',
50
51
  headers: _hellotext.default.headers,
51
52
  body: JSON.stringify({
@@ -5,8 +5,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
5
5
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
7
  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); }
8
- import Hellotext from '../../hellotext';
9
8
  import { Configuration } from '../../core';
9
+ import Hellotext from '../../hellotext';
10
10
  import { Response } from '../response';
11
11
  var WebchatMessagesAPI = /*#__PURE__*/function () {
12
12
  function WebchatMessagesAPI(webchatId) {
@@ -53,7 +53,9 @@ var WebchatMessagesAPI = /*#__PURE__*/function () {
53
53
  }, {
54
54
  key: "markAsSeen",
55
55
  value: function markAsSeen() {
56
- fetch(this.url + '/seen', {
56
+ var messageId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
57
+ var url = messageId ? this.url + "/".concat(messageId) : this.url + '/seen';
58
+ fetch(url, {
57
59
  method: 'PATCH',
58
60
  headers: Hellotext.headers,
59
61
  body: JSON.stringify({
@@ -26,6 +26,7 @@ let WebchatsAPI = /*#__PURE__*/function () {
26
26
  value: async function get(id) {
27
27
  const url = new URL(`${this.endpoint}/${id}`);
28
28
  url.searchParams.append('session', _hellotext.default.session);
29
+ url.searchParams.append('locale', _core.Locale.toString());
29
30
  Object.entries(_core.Configuration.webchat.style).forEach(([key, value]) => {
30
31
  url.searchParams.append(`style[${key}]`, value);
31
32
  });
@@ -37,6 +38,7 @@ let WebchatsAPI = /*#__PURE__*/function () {
37
38
  const data = await response.json();
38
39
  if (!_hellotext.default.business.data) {
39
40
  _hellotext.default.business.setData(data.business);
41
+ _hellotext.default.business.setLocale(data.locale);
40
42
  }
41
43
  return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
42
44
  }
@@ -5,7 +5,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
5
5
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
7
  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); }
8
- import { Configuration } from '../core';
8
+ import { Configuration, Locale } from '../core';
9
9
  import Hellotext from '../hellotext';
10
10
  var WebchatsAPI = /*#__PURE__*/function () {
11
11
  function WebchatsAPI() {
@@ -22,6 +22,7 @@ var WebchatsAPI = /*#__PURE__*/function () {
22
22
  var _get = _asyncToGenerator(function* (id) {
23
23
  var url = new URL("".concat(this.endpoint, "/").concat(id));
24
24
  url.searchParams.append('session', Hellotext.session);
25
+ url.searchParams.append('locale', Locale.toString());
25
26
  Object.entries(Configuration.webchat.style).forEach(_ref => {
26
27
  var [key, value] = _ref;
27
28
  url.searchParams.append("style[".concat(key, "]"), value);
@@ -34,6 +35,7 @@ var WebchatsAPI = /*#__PURE__*/function () {
34
35
  var data = yield response.json();
35
36
  if (!Hellotext.business.data) {
36
37
  Hellotext.business.setData(data.business);
38
+ Hellotext.business.setLocale(data.locale);
37
39
  }
38
40
  return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
39
41
  });
@@ -35,7 +35,7 @@ function _template2() {
35
35
  return `
36
36
  <div data-logo-container>
37
37
  <small>${_hellotext.default.business.locale.white_label.powered_by}</small>
38
-
38
+
39
39
  <a href="${url}" rel="noreferrer" target="_blank">
40
40
  <svg data-hello-brand viewBox="0 0 224 43" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
41
41
  <title>Hellotext</title>
@@ -24,7 +24,7 @@ var LogoBuilder = /*#__PURE__*/function () {
24
24
  }();
25
25
  function _template2() {
26
26
  var url = "https://www.hellotext.com?hello_session=".concat(Hellotext.session);
27
- return "\n <div data-logo-container>\n <small>".concat(Hellotext.business.locale.white_label.powered_by, "</small>\n \n <a href=\"").concat(url, "\" rel=\"noreferrer\" target=\"_blank\">\n <svg data-hello-brand viewBox=\"0 0 224 43\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Hellotext</title>\n <path d=\"M28.2760919,19.3224299 L28.2760919,31.1946615 C28.2760919,32.2088722 27.5005873,32.9844452 26.4864658,32.9844452 L21.0579334,32.9844452 C20.043812,32.9844452 19.2683073,32.2088722 19.2683073,31.1946615 L19.2683073,19.9786839 C19.2683073,16.7570733 17.4190271,14.7883113 14.4959712,14.7883113 C11.0360274,14.7883113 8.76916774,17.11503 8.76916774,21.1122135 L8.76916774,31.3139804 C8.76916774,32.3281911 7.99366311,33.1037641 6.97954167,33.1037641 L1.78962607,33.1037641 C0.77550463,33.1037641 0,32.3281911 0,31.3139804 L0,3.45301476 C0,2.43880402 0.77550463,1.6632311 1.78962607,1.6632311 L6.97954167,1.6632311 C7.99366311,1.6632311 8.76916774,2.43880402 8.76916774,3.45301476 L8.76916774,9.06100356 L8.11297151,16.3991166 L8.70951354,16.458776 C9.78328918,11.6860196 13.5415039,8.52406846 18.4331485,8.52406846 C24.3389145,8.52406846 28.2760919,12.8195492 28.2760919,19.3224299 Z M61.1455574,26.3622456 C58.9980061,30.7173858 53.6291279,33.5213803 47.0671656,33.5213803 C37.9997269,33.5213803 31.4377646,28.2116887 31.4377646,20.7542568 C31.4377646,13.6547816 37.2838764,8.52406846 46.0530442,8.52406846 C53.7484363,8.52406846 59.1769687,12.4615925 59.8928191,18.8451542 C60.0121275,19.9190244 59.1769687,20.8735757 58.103193,20.8735757 L40.1472781,20.8735757 C40.4455492,24.8110998 43.1299883,27.2571374 47.186474,27.2571374 C50.2288383,27.2571374 52.8536232,25.7656511 54.1660157,23.4389323 C54.5835951,22.6633594 55.5380623,22.3054026 56.3732212,22.6036999 L60.1314359,23.9758674 C61.0859032,24.2741647 61.622791,25.4076943 61.1455574,26.3622456 Z M40.5648576,17.3536679 L50.706072,17.2343489 C50.0498757,14.7286518 48.3795581,13.5354627 45.8740816,13.5354627 C43.3089509,13.5354627 41.4000164,14.9672896 40.5648576,17.3536679 Z M120.143563,20.9928946 C120.143563,28.2116887 113.641255,33.4617208 104.693125,33.4617208 C95.8046489,33.4617208 89.361995,28.2116887 89.361995,20.9928946 C89.361995,13.7741005 95.8046489,8.52406846 104.693125,8.52406846 C113.641255,8.52406846 120.143563,13.7741005 120.143563,20.9928946 Z M111.076125,21.1122135 C111.076125,17.2940084 108.45134,14.7883113 104.633471,14.7883113 C100.93491,14.7883113 98.3697796,17.2940084 98.3697796,20.9332352 C98.3697796,24.7514403 100.994564,27.2571374 104.812433,27.2571374 C108.570648,27.2571374 111.076125,24.7514403 111.076125,21.1122135 Z M141.559422,26.8395213 C141.261151,25.5866727 139.82945,25.0497376 138.815329,25.8253105 C137.443282,26.8395213 136.190544,27.2571374 134.99746,27.2571374 C132.909563,27.2571374 131.835787,26.0042889 131.835787,23.796889 L131.835787,13.9530789 L139.471525,13.9530789 C140.24703,13.9530789 140.903226,13.2968249 140.903226,12.521252 L140.903226,10.4928305 C140.903226,9.71725757 140.24703,9.06100356 139.471525,9.06100356 L131.835787,9.06100356 L131.835787,3.45301476 C131.835787,2.43880402 131.060282,1.6632311 130.046161,1.6632311 L125.214171,1.6632311 C124.200049,1.6632311 123.424545,2.43880402 123.424545,3.45301476 L123.424545,9.06100356 L123.424545,13.9530789 L123.424545,24.7514403 C123.424545,30.2401102 127.182759,33.5213803 133.565759,33.5213803 C136.727432,33.5213803 139.471525,32.6861479 141.499768,31.0753426 C142.036656,30.6577264 142.275272,29.9418129 142.09631,29.2855589 L141.559422,26.8395213 Z M173.414766,26.3622456 C171.267215,30.7173858 165.898337,33.5213803 159.336374,33.5213803 C150.268936,33.5213803 143.706973,28.2116887 143.706973,20.7542568 C143.706973,13.6547816 149.553085,8.52406846 158.322253,8.52406846 C166.017645,8.52406846 171.446177,12.4615925 172.162028,18.8451542 C172.281336,19.9190244 171.446177,20.8735757 170.372402,20.8735757 L152.416487,20.8735757 C152.714758,24.8110998 155.399197,27.2571374 159.455683,27.2571374 C162.498047,27.2571374 165.122832,25.7656511 166.435224,23.4389323 C166.852804,22.6633594 167.807271,22.3054026 168.64243,22.6036999 L172.400645,23.9758674 C173.414766,24.2741647 173.892,25.4076943 173.414766,26.3622456 Z M152.834066,17.3536679 L162.975281,17.2343489 C162.319084,14.7286518 160.648767,13.5354627 158.14329,13.5354627 C155.637814,13.5354627 153.669225,14.9672896 152.834066,17.3536679 Z M192.862036,20.8139163 L201.094316,12.0439763 C202.168092,10.9104467 201.332933,9.00134411 199.781923,9.00134411 L194.711316,9.00134411 C194.174428,9.00134411 193.637541,9.23998193 193.279615,9.71725757 L188.507279,15.8621815 L183.734943,9.71725757 C183.377018,9.29964138 182.899784,9.00134411 182.303242,9.00134411 L177.113327,9.00134411 C175.562317,9.00134411 174.727159,10.8507872 175.800934,12.0439763 L184.092868,20.8735757 L175.502663,30.0014724 C174.428888,31.135002 175.204392,33.0441046 176.815056,33.0441046 L181.945317,33.0441046 C182.482205,33.0441046 183.019093,32.8054668 183.377018,32.3878506 L188.447625,25.9446294 L193.577886,32.3878506 C193.935812,32.8054668 194.413045,33.0441046 194.949933,33.0441046 L200.139849,33.0441046 C201.690858,33.0441046 202.526017,31.1946615 201.452241,30.0611318 L192.862036,20.8139163 Z M223.941875,29.2258995 L223.345333,26.8395213 C223.047062,25.5866727 221.615362,25.0497376 220.60124,25.8253105 C219.229193,26.8395213 217.976455,27.2571374 216.783371,27.2571374 C214.695474,27.2571374 213.621698,26.0042889 213.621698,23.796889 L213.621698,13.9530789 L221.257436,13.9530789 C222.032941,13.9530789 222.689137,13.2968249 222.689137,12.521252 L222.689137,10.4928305 C222.689137,9.71725757 222.032941,9.06100356 221.257436,9.06100356 L213.621698,9.06100356 L213.621698,3.45301476 C213.621698,2.43880402 212.846194,1.6632311 211.832072,1.6632311 L207.000082,1.6632311 C205.985961,1.6632311 205.210456,2.43880402 205.210456,3.45301476 L205.210456,9.06100356 L205.210456,13.9530789 L205.210456,24.7514403 C205.210456,30.2401102 208.968671,33.5213803 215.35167,33.5213803 C218.513343,33.5213803 221.257436,32.6861479 223.285679,31.0753426 C223.882221,30.5980669 224.120838,29.8821535 223.941875,29.2258995 Z M77.6697714,6.01837134 C78.2663134,5.30245788 78.2663134,4.22858768 77.6101172,3.57233367 L74.5677529,0.529701449 C73.8519024,-0.186212015 72.6588184,-0.186212015 71.942968,0.589360904 C61.3841742,12.4615925 61.3841742,30.5384075 71.942968,42.4106391 C72.5991642,43.186212 73.8519024,43.186212 74.5677529,42.4702986 L77.6101172,39.4276663 C78.2663134,38.7714123 78.3259676,37.6975421 77.6697714,36.9816287 C69.9147251,28.1520293 69.9147251,14.8479707 77.6697714,6.01837134 Z M87.1547896,10.6718089 L84.1124252,7.62917663 C83.3965748,6.91326317 82.1438366,6.91326317 81.4876403,7.74849554 C78.2663134,11.6263601 76.4766873,16.458776 76.4766873,21.5298297 C76.4766873,26.6008834 78.2663134,31.4332993 81.4876403,35.3111639 C82.1438366,36.0867368 83.3965748,36.1463963 84.1124252,35.4304828 L87.1547896,32.3878506 C87.8109858,31.7315966 87.87064,30.7173858 87.3337522,30.0611318 C85.4248177,27.6747536 84.351042,24.6917809 84.351042,21.5894892 C84.351042,18.4871975 85.3651635,15.5042247 87.3337522,13.1178465 C87.87064,12.3422736 87.8109858,11.3280629 87.1547896,10.6718089 Z\" id=\"hellotext\" fill=\"currentColor\"></path>\n </svg>\n </a>\n </div>\n ");
27
+ return "\n <div data-logo-container>\n <small>".concat(Hellotext.business.locale.white_label.powered_by, "</small>\n\n <a href=\"").concat(url, "\" rel=\"noreferrer\" target=\"_blank\">\n <svg data-hello-brand viewBox=\"0 0 224 43\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Hellotext</title>\n <path d=\"M28.2760919,19.3224299 L28.2760919,31.1946615 C28.2760919,32.2088722 27.5005873,32.9844452 26.4864658,32.9844452 L21.0579334,32.9844452 C20.043812,32.9844452 19.2683073,32.2088722 19.2683073,31.1946615 L19.2683073,19.9786839 C19.2683073,16.7570733 17.4190271,14.7883113 14.4959712,14.7883113 C11.0360274,14.7883113 8.76916774,17.11503 8.76916774,21.1122135 L8.76916774,31.3139804 C8.76916774,32.3281911 7.99366311,33.1037641 6.97954167,33.1037641 L1.78962607,33.1037641 C0.77550463,33.1037641 0,32.3281911 0,31.3139804 L0,3.45301476 C0,2.43880402 0.77550463,1.6632311 1.78962607,1.6632311 L6.97954167,1.6632311 C7.99366311,1.6632311 8.76916774,2.43880402 8.76916774,3.45301476 L8.76916774,9.06100356 L8.11297151,16.3991166 L8.70951354,16.458776 C9.78328918,11.6860196 13.5415039,8.52406846 18.4331485,8.52406846 C24.3389145,8.52406846 28.2760919,12.8195492 28.2760919,19.3224299 Z M61.1455574,26.3622456 C58.9980061,30.7173858 53.6291279,33.5213803 47.0671656,33.5213803 C37.9997269,33.5213803 31.4377646,28.2116887 31.4377646,20.7542568 C31.4377646,13.6547816 37.2838764,8.52406846 46.0530442,8.52406846 C53.7484363,8.52406846 59.1769687,12.4615925 59.8928191,18.8451542 C60.0121275,19.9190244 59.1769687,20.8735757 58.103193,20.8735757 L40.1472781,20.8735757 C40.4455492,24.8110998 43.1299883,27.2571374 47.186474,27.2571374 C50.2288383,27.2571374 52.8536232,25.7656511 54.1660157,23.4389323 C54.5835951,22.6633594 55.5380623,22.3054026 56.3732212,22.6036999 L60.1314359,23.9758674 C61.0859032,24.2741647 61.622791,25.4076943 61.1455574,26.3622456 Z M40.5648576,17.3536679 L50.706072,17.2343489 C50.0498757,14.7286518 48.3795581,13.5354627 45.8740816,13.5354627 C43.3089509,13.5354627 41.4000164,14.9672896 40.5648576,17.3536679 Z M120.143563,20.9928946 C120.143563,28.2116887 113.641255,33.4617208 104.693125,33.4617208 C95.8046489,33.4617208 89.361995,28.2116887 89.361995,20.9928946 C89.361995,13.7741005 95.8046489,8.52406846 104.693125,8.52406846 C113.641255,8.52406846 120.143563,13.7741005 120.143563,20.9928946 Z M111.076125,21.1122135 C111.076125,17.2940084 108.45134,14.7883113 104.633471,14.7883113 C100.93491,14.7883113 98.3697796,17.2940084 98.3697796,20.9332352 C98.3697796,24.7514403 100.994564,27.2571374 104.812433,27.2571374 C108.570648,27.2571374 111.076125,24.7514403 111.076125,21.1122135 Z M141.559422,26.8395213 C141.261151,25.5866727 139.82945,25.0497376 138.815329,25.8253105 C137.443282,26.8395213 136.190544,27.2571374 134.99746,27.2571374 C132.909563,27.2571374 131.835787,26.0042889 131.835787,23.796889 L131.835787,13.9530789 L139.471525,13.9530789 C140.24703,13.9530789 140.903226,13.2968249 140.903226,12.521252 L140.903226,10.4928305 C140.903226,9.71725757 140.24703,9.06100356 139.471525,9.06100356 L131.835787,9.06100356 L131.835787,3.45301476 C131.835787,2.43880402 131.060282,1.6632311 130.046161,1.6632311 L125.214171,1.6632311 C124.200049,1.6632311 123.424545,2.43880402 123.424545,3.45301476 L123.424545,9.06100356 L123.424545,13.9530789 L123.424545,24.7514403 C123.424545,30.2401102 127.182759,33.5213803 133.565759,33.5213803 C136.727432,33.5213803 139.471525,32.6861479 141.499768,31.0753426 C142.036656,30.6577264 142.275272,29.9418129 142.09631,29.2855589 L141.559422,26.8395213 Z M173.414766,26.3622456 C171.267215,30.7173858 165.898337,33.5213803 159.336374,33.5213803 C150.268936,33.5213803 143.706973,28.2116887 143.706973,20.7542568 C143.706973,13.6547816 149.553085,8.52406846 158.322253,8.52406846 C166.017645,8.52406846 171.446177,12.4615925 172.162028,18.8451542 C172.281336,19.9190244 171.446177,20.8735757 170.372402,20.8735757 L152.416487,20.8735757 C152.714758,24.8110998 155.399197,27.2571374 159.455683,27.2571374 C162.498047,27.2571374 165.122832,25.7656511 166.435224,23.4389323 C166.852804,22.6633594 167.807271,22.3054026 168.64243,22.6036999 L172.400645,23.9758674 C173.414766,24.2741647 173.892,25.4076943 173.414766,26.3622456 Z M152.834066,17.3536679 L162.975281,17.2343489 C162.319084,14.7286518 160.648767,13.5354627 158.14329,13.5354627 C155.637814,13.5354627 153.669225,14.9672896 152.834066,17.3536679 Z M192.862036,20.8139163 L201.094316,12.0439763 C202.168092,10.9104467 201.332933,9.00134411 199.781923,9.00134411 L194.711316,9.00134411 C194.174428,9.00134411 193.637541,9.23998193 193.279615,9.71725757 L188.507279,15.8621815 L183.734943,9.71725757 C183.377018,9.29964138 182.899784,9.00134411 182.303242,9.00134411 L177.113327,9.00134411 C175.562317,9.00134411 174.727159,10.8507872 175.800934,12.0439763 L184.092868,20.8735757 L175.502663,30.0014724 C174.428888,31.135002 175.204392,33.0441046 176.815056,33.0441046 L181.945317,33.0441046 C182.482205,33.0441046 183.019093,32.8054668 183.377018,32.3878506 L188.447625,25.9446294 L193.577886,32.3878506 C193.935812,32.8054668 194.413045,33.0441046 194.949933,33.0441046 L200.139849,33.0441046 C201.690858,33.0441046 202.526017,31.1946615 201.452241,30.0611318 L192.862036,20.8139163 Z M223.941875,29.2258995 L223.345333,26.8395213 C223.047062,25.5866727 221.615362,25.0497376 220.60124,25.8253105 C219.229193,26.8395213 217.976455,27.2571374 216.783371,27.2571374 C214.695474,27.2571374 213.621698,26.0042889 213.621698,23.796889 L213.621698,13.9530789 L221.257436,13.9530789 C222.032941,13.9530789 222.689137,13.2968249 222.689137,12.521252 L222.689137,10.4928305 C222.689137,9.71725757 222.032941,9.06100356 221.257436,9.06100356 L213.621698,9.06100356 L213.621698,3.45301476 C213.621698,2.43880402 212.846194,1.6632311 211.832072,1.6632311 L207.000082,1.6632311 C205.985961,1.6632311 205.210456,2.43880402 205.210456,3.45301476 L205.210456,9.06100356 L205.210456,13.9530789 L205.210456,24.7514403 C205.210456,30.2401102 208.968671,33.5213803 215.35167,33.5213803 C218.513343,33.5213803 221.257436,32.6861479 223.285679,31.0753426 C223.882221,30.5980669 224.120838,29.8821535 223.941875,29.2258995 Z M77.6697714,6.01837134 C78.2663134,5.30245788 78.2663134,4.22858768 77.6101172,3.57233367 L74.5677529,0.529701449 C73.8519024,-0.186212015 72.6588184,-0.186212015 71.942968,0.589360904 C61.3841742,12.4615925 61.3841742,30.5384075 71.942968,42.4106391 C72.5991642,43.186212 73.8519024,43.186212 74.5677529,42.4702986 L77.6101172,39.4276663 C78.2663134,38.7714123 78.3259676,37.6975421 77.6697714,36.9816287 C69.9147251,28.1520293 69.9147251,14.8479707 77.6697714,6.01837134 Z M87.1547896,10.6718089 L84.1124252,7.62917663 C83.3965748,6.91326317 82.1438366,6.91326317 81.4876403,7.74849554 C78.2663134,11.6263601 76.4766873,16.458776 76.4766873,21.5298297 C76.4766873,26.6008834 78.2663134,31.4332993 81.4876403,35.3111639 C82.1438366,36.0867368 83.3965748,36.1463963 84.1124252,35.4304828 L87.1547896,32.3878506 C87.8109858,31.7315966 87.87064,30.7173858 87.3337522,30.0611318 C85.4248177,27.6747536 84.351042,24.6917809 84.351042,21.5894892 C84.351042,18.4871975 85.3651635,15.5042247 87.3337522,13.1178465 C87.87064,12.3422736 87.8109858,11.3280629 87.1547896,10.6718089 Z\" id=\"hellotext\" fill=\"currentColor\"></path>\n </svg>\n </a>\n </div>\n ");
28
28
  }
29
29
  Object.defineProperty(LogoBuilder, _template, {
30
30
  value: _template2
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _stimulus = require("@hotwired/stimulus");
8
7
  var _dom = require("@floating-ui/dom");
8
+ var _stimulus = require("@hotwired/stimulus");
9
+ var _en = _interopRequireDefault(require("@emoji-mart/data/i18n/en.json"));
10
+ var _es = _interopRequireDefault(require("@emoji-mart/data/i18n/es.json"));
9
11
  var _emojiMart = require("emoji-mart");
10
12
  var _usePopover = require("../mixins/usePopover");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
15
  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); } }
13
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -78,10 +81,7 @@ let _default = /*#__PURE__*/function (_Controller) {
78
81
  skinTonePosition: 'none',
79
82
  emojiSize: this.sizeValue,
80
83
  perLine: this.perLineValue,
81
- data: async () => {
82
- const response = await fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
83
- return response.json();
84
- }
84
+ i18n: Hellotext.business.locale === 'es' ? _es.default : _en.default
85
85
  });
86
86
  }
87
87
  }, {
@@ -101,7 +101,7 @@ _default.targets = ['button', 'popover'];
101
101
  _default.values = {
102
102
  placement: {
103
103
  type: String,
104
- default: "bottom-end"
104
+ default: 'bottom-end'
105
105
  },
106
106
  open: {
107
107
  type: Boolean,
@@ -1,5 +1,3 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
2
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
3
1
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
2
  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); } }
5
3
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -14,8 +12,10 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
14
12
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
13
  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; } }
16
14
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ import { autoPlacement, offset, shift } from '@floating-ui/dom';
17
16
  import { Controller } from '@hotwired/stimulus';
18
- import { computePosition, autoUpdate, shift, autoPlacement, offset } from '@floating-ui/dom';
17
+ import en from '@emoji-mart/data/i18n/en.json';
18
+ import es from '@emoji-mart/data/i18n/es.json';
19
19
  import { Picker } from 'emoji-mart';
20
20
  import { usePopover } from '../mixins/usePopover';
21
21
  var _default = /*#__PURE__*/function (_Controller) {
@@ -74,16 +74,7 @@ var _default = /*#__PURE__*/function (_Controller) {
74
74
  skinTonePosition: 'none',
75
75
  emojiSize: this.sizeValue,
76
76
  perLine: this.perLineValue,
77
- data: function () {
78
- var _data = _asyncToGenerator(function* () {
79
- var response = yield fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
80
- return response.json();
81
- });
82
- function data() {
83
- return _data.apply(this, arguments);
84
- }
85
- return data;
86
- }()
77
+ i18n: Hellotext.business.locale === 'es' ? es : en
87
78
  });
88
79
  }
89
80
  }, {
@@ -102,7 +93,7 @@ _default.targets = ['button', 'popover'];
102
93
  _default.values = {
103
94
  placement: {
104
95
  type: String,
105
- default: "bottom-end"
96
+ default: 'bottom-end'
106
97
  },
107
98
  open: {
108
99
  type: Boolean,
@@ -9,6 +9,7 @@ var _stimulus = require("@hotwired/stimulus");
9
9
  var _messages = _interopRequireDefault(require("../api/webchat/messages"));
10
10
  var _webchat_channel = _interopRequireDefault(require("../channels/webchat_channel"));
11
11
  var _hellotext = _interopRequireDefault(require("../hellotext"));
12
+ var _core = require("../core");
12
13
  var _webchat = require("../core/configuration/webchat");
13
14
  var _logo_builder = require("../builders/logo_builder");
14
15
  var _usePopover = require("./mixins/usePopover");
@@ -67,7 +68,7 @@ let _default = /*#__PURE__*/function (_Controller) {
67
68
  if (!_hellotext.default.business.features.white_label) {
68
69
  this.toolbarTarget.appendChild(_logo_builder.LogoBuilder.build());
69
70
  }
70
- if (localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened') {
71
+ if (this.shouldOpenOnMount) {
71
72
  this.openValue = true;
72
73
  }
73
74
  _hellotext.default.eventEmitter.dispatch('webchat:mounted');
@@ -164,10 +165,20 @@ let _default = /*#__PURE__*/function (_Controller) {
164
165
  this.openValue = false;
165
166
  }
166
167
  }
168
+ }, {
169
+ key: "closePopover",
170
+ value: function closePopover() {
171
+ this.popoverTarget.classList.add(...this.fadeOutClasses);
172
+ setTimeout(() => {
173
+ this.openValue = false;
174
+ }, 250);
175
+ }
167
176
  }, {
168
177
  key: "onPopoverOpened",
169
178
  value: function onPopoverOpened() {
170
- this.inputTarget.focus();
179
+ if (!this.onMobile) {
180
+ this.inputTarget.focus();
181
+ }
171
182
  if (!this.scrolled) {
172
183
  requestAnimationFrame(() => {
173
184
  this.messagesContainerTarget.scroll({
@@ -188,9 +199,6 @@ let _default = /*#__PURE__*/function (_Controller) {
188
199
  key: "onPopoverClosed",
189
200
  value: function onPopoverClosed() {
190
201
  _hellotext.default.eventEmitter.dispatch('webchat:closed');
191
- setTimeout(() => {
192
- this.inputTarget.value = '';
193
- });
194
202
  localStorage.setItem(`hellotext--webchat--${this.idValue}`, 'closed');
195
203
  }
196
204
  }, {
@@ -221,6 +229,7 @@ let _default = /*#__PURE__*/function (_Controller) {
221
229
  key: "onMessageReceived",
222
230
  value: function onMessageReceived(message) {
223
231
  const {
232
+ id,
224
233
  body,
225
234
  attachments
226
235
  } = message;
@@ -247,7 +256,10 @@ let _default = /*#__PURE__*/function (_Controller) {
247
256
  behavior: 'smooth'
248
257
  });
249
258
  this.setOfflineTimeout();
250
- if (this.openValue) return;
259
+ if (this.openValue) {
260
+ this.messagesAPI.markAsSeen(id);
261
+ return;
262
+ }
251
263
  this.unreadCounterTarget.style.display = 'flex';
252
264
  const unreadCount = (parseInt(this.unreadCounterTarget.innerText) || 0) + 1;
253
265
  this.unreadCounterTarget.innerText = unreadCount > 99 ? '99+' : unreadCount;
@@ -291,6 +303,7 @@ let _default = /*#__PURE__*/function (_Controller) {
291
303
  formData.append('message[attachments][]', file);
292
304
  });
293
305
  formData.append('session', _hellotext.default.session);
306
+ formData.append('locale', _core.Locale.toString());
294
307
  const element = this.messageTemplateTarget.cloneNode(true);
295
308
  element.id = `hellotext--webchat--${this.idValue}--message--${Date.now()}`;
296
309
  element.classList.add('received');
@@ -459,6 +472,16 @@ let _default = /*#__PURE__*/function (_Controller) {
459
472
  padding: 24
460
473
  }), (0, _dom.flip)()];
461
474
  }
475
+ }, {
476
+ key: "shouldOpenOnMount",
477
+ get: function () {
478
+ return localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened' && !this.onMobile;
479
+ }
480
+ }, {
481
+ key: "onMobile",
482
+ get: function () {
483
+ return window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches;
484
+ }
462
485
  }]);
463
486
  return _default;
464
487
  }(_stimulus.Controller);
@@ -487,6 +510,11 @@ _default.values = {
487
510
  nextPage: {
488
511
  type: Number,
489
512
  default: undefined
513
+ },
514
+ fullScreenThreshold: {
515
+ type: Number,
516
+ default: 1024
490
517
  }
491
518
  };
519
+ _default.classes = ['fadeOut'];
492
520
  _default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'onlineStatus', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter'];
@@ -22,6 +22,7 @@ import { Controller } from '@hotwired/stimulus';
22
22
  import WebchatMessagesAPI from '../api/webchat/messages';
23
23
  import WebchatChannel from '../channels/webchat_channel';
24
24
  import Hellotext from '../hellotext';
25
+ import { Locale } from '../core';
25
26
  import { Webchat as WebchatConfiguration, behaviors } from '../core/configuration/webchat';
26
27
  import { LogoBuilder } from '../builders/logo_builder';
27
28
  import { usePopover } from './mixins/usePopover';
@@ -65,7 +66,7 @@ var _default = /*#__PURE__*/function (_Controller) {
65
66
  if (!Hellotext.business.features.white_label) {
66
67
  this.toolbarTarget.appendChild(LogoBuilder.build());
67
68
  }
68
- if (localStorage.getItem("hellotext--webchat--".concat(this.idValue)) === 'opened') {
69
+ if (this.shouldOpenOnMount) {
69
70
  this.openValue = true;
70
71
  }
71
72
  Hellotext.eventEmitter.dispatch('webchat:mounted');
@@ -168,10 +169,20 @@ var _default = /*#__PURE__*/function (_Controller) {
168
169
  this.openValue = false;
169
170
  }
170
171
  }
172
+ }, {
173
+ key: "closePopover",
174
+ value: function closePopover() {
175
+ this.popoverTarget.classList.add(...this.fadeOutClasses);
176
+ setTimeout(() => {
177
+ this.openValue = false;
178
+ }, 250);
179
+ }
171
180
  }, {
172
181
  key: "onPopoverOpened",
173
182
  value: function onPopoverOpened() {
174
- this.inputTarget.focus();
183
+ if (!this.onMobile) {
184
+ this.inputTarget.focus();
185
+ }
175
186
  if (!this.scrolled) {
176
187
  requestAnimationFrame(() => {
177
188
  this.messagesContainerTarget.scroll({
@@ -192,9 +203,6 @@ var _default = /*#__PURE__*/function (_Controller) {
192
203
  key: "onPopoverClosed",
193
204
  value: function onPopoverClosed() {
194
205
  Hellotext.eventEmitter.dispatch('webchat:closed');
195
- setTimeout(() => {
196
- this.inputTarget.value = '';
197
- });
198
206
  localStorage.setItem("hellotext--webchat--".concat(this.idValue), 'closed');
199
207
  }
200
208
  }, {
@@ -225,6 +233,7 @@ var _default = /*#__PURE__*/function (_Controller) {
225
233
  key: "onMessageReceived",
226
234
  value: function onMessageReceived(message) {
227
235
  var {
236
+ id,
228
237
  body,
229
238
  attachments
230
239
  } = message;
@@ -250,7 +259,10 @@ var _default = /*#__PURE__*/function (_Controller) {
250
259
  behavior: 'smooth'
251
260
  });
252
261
  this.setOfflineTimeout();
253
- if (this.openValue) return;
262
+ if (this.openValue) {
263
+ this.messagesAPI.markAsSeen(id);
264
+ return;
265
+ }
254
266
  this.unreadCounterTarget.style.display = 'flex';
255
267
  var unreadCount = (parseInt(this.unreadCounterTarget.innerText) || 0) + 1;
256
268
  this.unreadCounterTarget.innerText = unreadCount > 99 ? '99+' : unreadCount;
@@ -295,6 +307,7 @@ var _default = /*#__PURE__*/function (_Controller) {
295
307
  formData.append('message[attachments][]', file);
296
308
  });
297
309
  formData.append('session', Hellotext.session);
310
+ formData.append('locale', Locale.toString());
298
311
  var element = this.messageTemplateTarget.cloneNode(true);
299
312
  element.id = "hellotext--webchat--".concat(this.idValue, "--message--").concat(Date.now());
300
313
  element.classList.add('received');
@@ -470,6 +483,16 @@ var _default = /*#__PURE__*/function (_Controller) {
470
483
  padding: 24
471
484
  }), flip()];
472
485
  }
486
+ }, {
487
+ key: "shouldOpenOnMount",
488
+ get: function get() {
489
+ return localStorage.getItem("hellotext--webchat--".concat(this.idValue)) === 'opened' && !this.onMobile;
490
+ }
491
+ }, {
492
+ key: "onMobile",
493
+ get: function get() {
494
+ return window.matchMedia("(max-width: ".concat(this.fullScreenThresholdValue, "px)")).matches;
495
+ }
473
496
  }]);
474
497
  return _default;
475
498
  }(Controller);
@@ -497,7 +520,12 @@ _default.values = {
497
520
  nextPage: {
498
521
  type: Number,
499
522
  default: undefined
523
+ },
524
+ fullScreenThreshold: {
525
+ type: Number,
526
+ default: 1024
500
527
  }
501
528
  };
529
+ _default.classes = ['fadeOut'];
502
530
  _default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'onlineStatus', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter'];
503
531
  export { _default as default };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Locale = void 0;
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
+ 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); }
12
+ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
13
+ var id = 0;
14
+ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
15
+ var _fromHtmlLangProperty = /*#__PURE__*/_classPrivateFieldLooseKey("fromHtmlLangProperty");
16
+ var _fromMetaTag = /*#__PURE__*/_classPrivateFieldLooseKey("fromMetaTag");
17
+ var _fromBrowserLanguage = /*#__PURE__*/_classPrivateFieldLooseKey("fromBrowserLanguage");
18
+ /**
19
+ * @class Locale
20
+ * @classdesc
21
+ * Handles locale detection and configuration for the Hellotext library.
22
+ * Provides automatic locale detection from HTML lang attribute, meta tags,
23
+ * and browser language with fallback to 'en'.
24
+ */
25
+ let Locale = /*#__PURE__*/function () {
26
+ function Locale() {
27
+ _classCallCheck(this, Locale);
28
+ }
29
+ _createClass(Locale, null, [{
30
+ key: "identifier",
31
+ get:
32
+ /**
33
+ * Gets the effective locale identifier.
34
+ * Falls back to auto-detection if not explicitly set.
35
+ * @returns {string} The locale identifier
36
+ */
37
+ function () {
38
+ if (this._identifier) return this._identifier;
39
+ return _classPrivateFieldLooseBase(this, _fromHtmlLangProperty)[_fromHtmlLangProperty] || _classPrivateFieldLooseBase(this, _fromMetaTag)[_fromMetaTag] || _classPrivateFieldLooseBase(this, _fromBrowserLanguage)[_fromBrowserLanguage] || 'en';
40
+ }
41
+
42
+ /**
43
+ * Returns the locale identifier as a string.
44
+ * @returns {string} The locale identifier
45
+ */,
46
+ set:
47
+ /**
48
+ * Sets the locale identifier explicitly.
49
+ * @param {string} value - The locale identifier (e.g., 'en', 'es')
50
+ */
51
+ function (value) {
52
+ this._identifier = value;
53
+ }
54
+ }, {
55
+ key: "toString",
56
+ value: function toString() {
57
+ return this.identifier;
58
+ }
59
+ }]);
60
+ return Locale;
61
+ }();
62
+ exports.Locale = Locale;
63
+ function _get_fromHtmlLangProperty() {
64
+ var _document, _document$documentEle;
65
+ return (_document = document) === null || _document === void 0 ? void 0 : (_document$documentEle = _document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.lang;
66
+ }
67
+ function _get_fromMetaTag() {
68
+ var _document2, _document2$querySelec;
69
+ return (_document2 = document) === null || _document2 === void 0 ? void 0 : (_document2$querySelec = _document2.querySelector('meta[name="locale"]')) === null || _document2$querySelec === void 0 ? void 0 : _document2$querySelec.content;
70
+ }
71
+ function _get_fromBrowserLanguage() {
72
+ var _navigator, _navigator$language;
73
+ return (_navigator = navigator) === null || _navigator === void 0 ? void 0 : (_navigator$language = _navigator.language) === null || _navigator$language === void 0 ? void 0 : _navigator$language.split('-')[0]; // Extract primary language
74
+ }
75
+ Object.defineProperty(Locale, _fromBrowserLanguage, {
76
+ get: _get_fromBrowserLanguage,
77
+ set: void 0
78
+ });
79
+ Object.defineProperty(Locale, _fromMetaTag, {
80
+ get: _get_fromMetaTag,
81
+ set: void 0
82
+ });
83
+ Object.defineProperty(Locale, _fromHtmlLangProperty, {
84
+ get: _get_fromHtmlLangProperty,
85
+ set: void 0
86
+ });
87
+ Locale._identifier = void 0;
@@ -0,0 +1,81 @@
1
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
+ 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); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
+ 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); }
6
+ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
7
+ var id = 0;
8
+ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
9
+ var _fromHtmlLangProperty = /*#__PURE__*/_classPrivateFieldLooseKey("fromHtmlLangProperty");
10
+ var _fromMetaTag = /*#__PURE__*/_classPrivateFieldLooseKey("fromMetaTag");
11
+ var _fromBrowserLanguage = /*#__PURE__*/_classPrivateFieldLooseKey("fromBrowserLanguage");
12
+ /**
13
+ * @class Locale
14
+ * @classdesc
15
+ * Handles locale detection and configuration for the Hellotext library.
16
+ * Provides automatic locale detection from HTML lang attribute, meta tags,
17
+ * and browser language with fallback to 'en'.
18
+ */
19
+ var Locale = /*#__PURE__*/function () {
20
+ function Locale() {
21
+ _classCallCheck(this, Locale);
22
+ }
23
+ _createClass(Locale, null, [{
24
+ key: "identifier",
25
+ get:
26
+ /**
27
+ * Gets the effective locale identifier.
28
+ * Falls back to auto-detection if not explicitly set.
29
+ * @returns {string} The locale identifier
30
+ */
31
+ function get() {
32
+ if (this._identifier) return this._identifier;
33
+ return _classPrivateFieldLooseBase(this, _fromHtmlLangProperty)[_fromHtmlLangProperty] || _classPrivateFieldLooseBase(this, _fromMetaTag)[_fromMetaTag] || _classPrivateFieldLooseBase(this, _fromBrowserLanguage)[_fromBrowserLanguage] || 'en';
34
+ }
35
+
36
+ /**
37
+ * Returns the locale identifier as a string.
38
+ * @returns {string} The locale identifier
39
+ */,
40
+ set:
41
+ /**
42
+ * Sets the locale identifier explicitly.
43
+ * @param {string} value - The locale identifier (e.g., 'en', 'es')
44
+ */
45
+ function set(value) {
46
+ this._identifier = value;
47
+ }
48
+ }, {
49
+ key: "toString",
50
+ value: function toString() {
51
+ return this.identifier;
52
+ }
53
+ }]);
54
+ return Locale;
55
+ }();
56
+ function _get_fromHtmlLangProperty() {
57
+ var _document, _document$documentEle;
58
+ return (_document = document) === null || _document === void 0 ? void 0 : (_document$documentEle = _document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.lang;
59
+ }
60
+ function _get_fromMetaTag() {
61
+ var _document2, _document2$querySelec;
62
+ return (_document2 = document) === null || _document2 === void 0 ? void 0 : (_document2$querySelec = _document2.querySelector('meta[name="locale"]')) === null || _document2$querySelec === void 0 ? void 0 : _document2$querySelec.content;
63
+ }
64
+ function _get_fromBrowserLanguage() {
65
+ var _navigator, _navigator$language;
66
+ return (_navigator = navigator) === null || _navigator === void 0 ? void 0 : (_navigator$language = _navigator.language) === null || _navigator$language === void 0 ? void 0 : _navigator$language.split('-')[0]; // Extract primary language
67
+ }
68
+ Object.defineProperty(Locale, _fromBrowserLanguage, {
69
+ get: _get_fromBrowserLanguage,
70
+ set: void 0
71
+ });
72
+ Object.defineProperty(Locale, _fromMetaTag, {
73
+ get: _get_fromMetaTag,
74
+ set: void 0
75
+ });
76
+ Object.defineProperty(Locale, _fromHtmlLangProperty, {
77
+ get: _get_fromHtmlLangProperty,
78
+ set: void 0
79
+ });
80
+ Locale._identifier = void 0;
81
+ export { Locale };