PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.7.5
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.7.5
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / assets / dist / js / editor.js

editor.js in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.7.5, at assets/dist/js/editor.js

3,975 lines 165.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2 "use strict";
3
4 Object.defineProperty(exports, "__esModule", {
5 value: true
6 });
7 exports["default"] = void 0;
8
9 var _i18n = require("@wordpress/i18n");
10
11 var FileUploader = elementor.modules.controls.BaseMultiple.extend({
12 ui: function ui() {
13 var ui = elementor.modules.controls.BaseMultiple.prototype.ui.apply(this, arguments);
14 return _.extend(ui, {
15 fileUploader: 'sellkit-control-file-uploader',
16 fileUploaderInput: '.sellkit-control-file-uploader-input',
17 fileUploaderBtn: '.sellkit-control-file-uploader-button',
18 fileUploaderValue: '.sellkit-control-file-uploader-value',
19 fileUploaderRemoveBtn: '.sellkit-control-file-uploader-value .fa',
20 fileUploaderProgress: '.sellkit-control-file-uploader-progress',
21 fileUploaderWarning: '.sellkit-control-file-uploader-warning',
22 fileUploaderSizeWarning: '.sellkit-control-file-uploader-warning-size'
23 });
24 },
25 events: function events() {
26 var events = elementor.modules.controls.BaseMultiple.prototype.events.apply(this, arguments);
27 return _.extend(events, {
28 'change @ui.fileUploaderInput': 'onFileInputChange',
29 'click @ui.fileUploaderRemoveBtn': 'onFileRemove'
30 });
31 },
32 onFileInputChange: function onFileInputChange(event) {
33 var self = this;
34 this.hideWarnings();
35
36 if (event.target.files.length === 0) {
37 return;
38 }
39
40 if (!this.checkFileSize(event.target.files[0])) {
41 return;
42 }
43
44 var formData = new FormData();
45 formData.append('action', 'sellkit_control_file_upload');
46 formData.append('file', event.target.files[0]);
47 formData.append('nonce', window.sellkitNonceEditorFileUploader[0]);
48 this.showUploadProgress();
49 jQuery.ajax(this.ui.fileUploaderInput.data('ajax-url'), {
50 method: 'POST',
51 processData: false,
52 contentType: false,
53 global: false,
54 data: formData,
55 success: function success(res) {
56 if (res.success) {
57 self.setValue('files', [res.data]);
58 self.showFile(res.data.name);
59 } else {
60 self.ui.fileUploaderInput.val('');
61 self.ui.fileUploaderWarning.find('ul').append("<li class=\"error\">".concat(res.data, "</li>"));
62 self.ui.fileUploaderWarning.show();
63 self.showUploadBtn();
64 }
65 },
66 error: function error() {
67 self.ui.fileUploaderInput.val('');
68 self.ui.fileUploaderWarning.find('ul').append("<li class=\"error\">".concat((0, _i18n.__)('Something went wrong please try again.', 'sellkit'), "</li>"));
69 self.ui.fileUploaderWarning.show();
70 self.showUploadBtn();
71 }
72 });
73 },
74 onFileRemove: function onFileRemove(event) {
75 event.stopPropagation();
76 this.setValue('files', []);
77 this.ui.fileUploaderValue.hide();
78 this.ui.fileUploaderBtn.show();
79 this.ui.fileUploaderInput.val('');
80 },
81 hideWarnings: function hideWarnings() {
82 this.ui.fileUploaderWarning.hide();
83 this.ui.fileUploaderWarning.find('li').hide();
84 this.ui.fileUploaderWarning.find('li.error').remove();
85 },
86 checkFileSize: function checkFileSize(file) {
87 var uploadLimit = parseFloat(this.ui.fileUploaderInput.data('max-upload-limit'));
88
89 if (file.size > uploadLimit) {
90 this.ui.fileUploaderWarning.show();
91 this.ui.fileUploaderSizeWarning.show();
92 return false;
93 }
94
95 return true;
96 },
97 stripHash: function stripHash(filename) {
98 var ext = filename.split('.').pop();
99 var name = filename.replace('.' + ext, '');
100 name = name.split('__').shift();
101 return name + '.' + ext;
102 },
103 shortenFilename: function shortenFilename(filename) {
104 return filename.length > 15 ? filename.substr(0, 15) + '...' : filename;
105 },
106 showFile: function showFile(filename) {
107 this.ui.fileUploaderProgress.hide();
108 this.ui.fileUploaderBtn.hide();
109 filename = this.stripHash(filename);
110 this.ui.fileUploaderValue.find('> span:first-child').attr('title', filename).text(this.shortenFilename(filename));
111 this.ui.fileUploaderValue.css('display', 'flex');
112 },
113 showUploadBtn: function showUploadBtn() {
114 this.ui.fileUploaderValue.hide();
115 this.ui.fileUploaderProgress.hide();
116 this.ui.fileUploaderBtn.show();
117 },
118 showUploadProgress: function showUploadProgress() {
119 this.ui.fileUploaderValue.hide();
120 this.ui.fileUploaderBtn.hide();
121 this.ui.fileUploaderProgress.show();
122 },
123 onRender: function onRender() {
124 _.extend(elementor.modules.controls.BaseMultiple.prototype.onRender.apply(this, arguments));
125
126 var files = this.getControlValue('files');
127
128 if (!files || files.length === 0) {
129 return;
130 }
131
132 this.showFile(files[0].name);
133 }
134 });
135 var _default = FileUploader;
136 exports["default"] = _default;
137
138 },{"@wordpress/i18n":23}],2:[function(require,module,exports){
139 "use strict";
140
141 (function ($, window) {
142 var sellkitEditor = function sellkitEditor() {
143 var onElementorReady = function onElementorReady() {
144 if (typeof elementor.settings.editorPreferences === 'undefined') {
145 return;
146 } // Manage dark & light icons.
147
148
149 if ('dark' === elementor.settings.editorPreferences.model.attributes.ui_theme) {
150 $('#elementor-editor-wrapper').addClass('sellkit-editor-ui-dark');
151 } else {
152 $('#elementor-editor-wrapper').removeClass('sellkit-editor-ui-dark');
153 }
154 };
155
156 var onSettingsChange = function onSettingsChange() {
157 elementor.settings.editorPreferences.model.on('change', onElementorReady);
158 }; // Initialize controls JS.
159
160
161 var initControls = function initControls() {
162 var controls = {
163 file_uploader: require('./controls/file-uploader')["default"]
164 };
165
166 for (var control in controls) {
167 elementor.addControlView("sellkit_".concat(control), controls[control]);
168 }
169 }; // Initialize widget JS.
170
171
172 var initWidgets = function initWidgets() {
173 var widgets = {
174 'sellkit-checkout': require('./widgets/checkout')["default"],
175 'sellkit-optin': require('./widgets/optin/optin')["default"]
176 };
177
178 for (var widget in widgets) {
179 elementor.hooks.addAction("panel/open_editor/widget/".concat(widget), widgets[widget]);
180 }
181 }; // Some widgets require a rerender after preview loaded,
182 // to fully sync with their ajaxed settings AND\OR displaying shortcode contents.
183
184
185 function rerenderWidgets() {
186 if (!elementor.previewView || !elementor.previewView._getNestedViews) {
187 return;
188 }
189
190 var widgets = ['sellkit-checkout'];
191
192 var _loop = function _loop(widget) {
193 var views = elementor.previewView._getNestedViews().filter(function (view) {
194 return 'widget' === view.model.get('elType') && widgets[widget] === view.model.get('widgetType');
195 });
196
197 _.each(views, function (view) {
198 return view.renderHTML();
199 });
200 };
201
202 for (var widget in widgets) {
203 _loop(widget);
204 }
205 }
206
207 function onDocumentLoaded() {
208 setTimeout(rerenderWidgets, 0);
209 }
210
211 var onElementorInit = function onElementorInit() {
212 onElementorReady();
213 onSettingsChange();
214 initControls();
215 elementor.on('frontend:init', initWidgets);
216 elementor.on('document:loaded', onDocumentLoaded);
217 };
218
219 $(window).on('elementor:init', onElementorInit);
220 };
221
222 window.sellkitEditor = new sellkitEditor();
223 })(jQuery, window);
224
225 },{"./controls/file-uploader":1,"./widgets/checkout":3,"./widgets/optin/optin":13}],3:[function(require,module,exports){
226 "use strict";
227
228 Object.defineProperty(exports, "__esModule", {
229 value: true
230 });
231 exports["default"] = _default;
232
233 function _default() {
234 var $ = jQuery; // eslint-disable-next-line no-undef
235
236 var activeTheme = sellkitPromotion.activeTheme;
237
238 var initializeChange = function initializeChange() {
239 var $element = $('input[data-setting="place_order_btn_txt"');
240 var value = $element.val();
241 $element.val('');
242 $element.val(value).trigger('input');
243 };
244
245 var disableExpressOnFree = function disableExpressOnFree() {
246 var promotionParent = $('.elementor-control-checkout-express-promotion');
247 promotionParent.find('input').attr('disabled', 'disabled');
248 promotionParent.find('.elementor-control-title').on('click', function () {
249 window.open('https://getsellkit.com/pricing/?utm_source=wp-dashboard&utm_campaign=gopro&utm_medium=' + activeTheme, '_blank');
250 });
251 };
252
253 var init = function init() {
254 initializeChange();
255 disableExpressOnFree();
256 };
257
258 init();
259 }
260
261 },{}],4:[function(require,module,exports){
262 "use strict";
263
264 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
265
266 Object.defineProperty(exports, "__esModule", {
267 value: true
268 });
269 exports["default"] = _default;
270
271 var _crmBase = _interopRequireDefault(require("./crm-base"));
272
273 function _default(panel, model, view) {
274 var ActiveCampaign = _crmBase["default"].extend({
275 panel: panel,
276 model: model,
277 action: 'activecampaign',
278 add_additional_api_data: function add_additional_api_data(params) {
279 params["".concat(this.action, "_custom_api_url")] = this.getControlValue("".concat(this.action, "_custom_api_url"));
280 },
281 updateAdditionalControls: function updateAdditionalControls() {
282 if (!this.additionalData.hasOwnProperty('tags')) {
283 return;
284 }
285
286 var tagsControl = this.getControlView("".concat(this.action, "_tags"));
287 tagsControl.model.set('options', this.additionalData.tags);
288 tagsControl.render();
289 },
290 // Override to reflect changes of "custom_api_url" control.
291 onElementChange: function onElementChange(controlView) {
292 var setting = controlView.model.get('name');
293
294 switch (setting) {
295 case "".concat(this.action, "_api_key_source"):
296 case "".concat(this.action, "_custom_api_key"):
297 case "".concat(this.action, "_custom_api_url"):
298 this.ajaxUpdateList();
299 break;
300
301 case "".concat(this.action, "_list"):
302 var listId = this.getListId();
303
304 if (listId && !this.listOptions.hasOwnProperty(listId)) {
305 this.ajaxUpdateAdditionalData();
306 }
307
308 break;
309 }
310 }
311 });
312
313 new ActiveCampaign({
314 $element: view.$el
315 });
316 }
317
318 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],5:[function(require,module,exports){
319 "use strict";
320
321 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
322
323 Object.defineProperty(exports, "__esModule", {
324 value: true
325 });
326 exports["default"] = _default;
327
328 var _crmBase = _interopRequireDefault(require("./crm-base"));
329
330 function _default(panel, model, view) {
331 var ConvertKit = _crmBase["default"].extend({
332 panel: panel,
333 model: model,
334 action: 'convertkit',
335 updateAdditionalControls: function updateAdditionalControls() {
336 if (!this.additionalData.hasOwnProperty('tags')) {
337 return;
338 }
339
340 var tagsControl = this.getControlView("".concat(this.action, "_tags"));
341 tagsControl.model.set('options', this.additionalData.tags);
342 tagsControl.render();
343 }
344 });
345
346 new ConvertKit({
347 $element: view.$el
348 });
349 }
350
351 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],6:[function(require,module,exports){
352 "use strict";
353
354 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
355
356 Object.defineProperty(exports, "__esModule", {
357 value: true
358 });
359 exports["default"] = void 0;
360
361 var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
362
363 var _util = _interopRequireDefault(require("../../util"));
364
365 var _i18n = require("@wordpress/i18n");
366
367 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
368
369 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
370
371 var _default = _util["default"].extend({
372 panel: null,
373 model: null,
374 action: null,
375 listView: null,
376 listOptions: {
377 none: {
378 none: (0, _i18n.__)('Select...', 'sellkit')
379 },
380 fetching: {
381 fetching: (0, _i18n.__)('Fetching...', 'sellkit')
382 },
383 noList: {
384 noList: (0, _i18n.__)('Nothing found!', 'sellkit')
385 }
386 },
387 fieldNoneOption: {
388 '': (0, _i18n.__)('-NONE-', 'sellkit')
389 },
390 mappingRepeater: null,
391 localFields: {},
392 additionalData: [],
393 onInit: function onInit() {
394 elementor.channels.editor.on('section:activated', this.onSectionActivated);
395 elementor.channels.editor.on('change', this.onElementChange);
396 },
397 onDestroy: function onDestroy() {
398 elementor.channels.editor.off('change', this.onElementChange);
399 },
400 onSectionActivated: function onSectionActivated(activeSection, section) {
401 if (activeSection !== "section_".concat(this.action) || section.model.id !== this.model.get('id')) {
402 return;
403 }
404
405 this.init();
406 },
407 init: function init() {
408 this.localFields = _objectSpread(_objectSpread({}, this.fieldNoneOption), this.getFormFields());
409 this.listView = this.getControlView("".concat(this.action, "_list"));
410 this.mappingRepeater = this.getControlView("".concat(this.action, "_fields_mapping"));
411 this.ajaxUpdateList();
412 this.updateControls();
413 this.mappingRepeater.on('add:child', this.updateControls);
414 this.mappingRepeater.on('childview:click:remove', this.updateControls);
415 },
416 ajaxUpdateList: function ajaxUpdateList() {
417 var _this = this;
418
419 var currentValue = this.getControlValue("".concat(this.action, "_list"));
420 this.setListOptions(this.listOptions.fetching);
421 this.setListSelection('fetching');
422 this.addControlSpinner("".concat(this.action, "_list"));
423 var params = {};
424 params["".concat(this.action, "_api_key_source")] = this.getControlValue("".concat(this.action, "_api_key_source")) || 'default';
425 params["".concat(this.action, "_custom_api_key")] = this.getControlValue("".concat(this.action, "_custom_api_key"));
426 this.add_additional_api_data(params);
427 wp.ajax.send('sellkit_optin_editor', {
428 cache: false,
429 data: {
430 params: params,
431 nonce: window.sellkitNonceEditorOptin[0],
432 service: this.action,
433 request: 'get_list'
434 },
435 success: function success(response) {
436 _this.removeControlSpinner("".concat(_this.action, "_list"));
437
438 var lists = {};
439
440 if (response.success[0].lists.length === 0) {
441 _this.setListOptions(_this.listOptions.noList);
442
443 _this.setListSelection('noList');
444
445 return;
446 }
447
448 _.each(response.success[0].lists, function (list, id) {
449 lists[id] = list;
450 });
451
452 var options = _objectSpread(_objectSpread({}, _this.listOptions.none), lists);
453
454 _this.setListOptions(options);
455
456 if (options[currentValue]) {
457 _this.setListSelection(currentValue);
458
459 return;
460 }
461
462 if (_.isEmpty(_this.listView.$el.val())) {
463 _this.setListSelection('none');
464 }
465 },
466 error: function error() {
467 _this.removeControlSpinner("".concat(_this.action, "_list"));
468
469 _this.listView.$el.find('option').text((0, _i18n.__)('Error! nonce mismatch', 'sellkit'));
470
471 _this.listView.$el.find('select').attr('disabled', 'disabled');
472 }
473 });
474 },
475 ajaxUpdateAdditionalData: function ajaxUpdateAdditionalData() {
476 var _this2 = this;
477
478 var params = {};
479 params["".concat(this.action, "_api_key_source")] = this.getControlValue("".concat(this.action, "_api_key_source")) || 'default';
480 params["".concat(this.action, "_custom_api_key")] = this.getControlValue("".concat(this.action, "_custom_api_key"));
481 params.list_id = this.getListId();
482 this.add_additional_api_data(params);
483 this.toggleSpinner(true);
484 wp.ajax.send('sellkit_optin_editor', {
485 data: {
486 params: params,
487 nonce: window.sellkitNonceEditorOptin[0],
488 service: this.action,
489 request: 'get_additional_data'
490 },
491 success: function success(response) {
492 _this2.additionalData = response.success[0];
493
494 _this2.updateControls();
495 },
496 complete: function complete() {
497 return _this2.toggleSpinner(false);
498 }
499 });
500 },
501 updateControls: function updateControls() {
502 var _this3 = this;
503
504 this.mappingRepeater.children.each(function (row) {
505 row.children.each(function (control) {
506 var fieldModel = control.model;
507 var fieldName = fieldModel.get('name');
508
509 switch (fieldName) {
510 case 'remote_field':
511 if (!_this3.additionalData.hasOwnProperty('custom_fields')) {
512 break;
513 }
514
515 var currentOptions = fieldModel.get('options');
516
517 var newOptions = _objectSpread(_objectSpread(_objectSpread({}, _this3.fieldNoneOption), currentOptions), _this3.additionalData.custom_fields);
518
519 fieldModel.set('options', newOptions);
520 break;
521
522 case 'local_field':
523 fieldModel.set('options', _this3.localFields);
524 break;
525
526 default:
527 break;
528 }
529
530 control.render();
531 });
532
533 _this3.fixTitleField(row);
534 });
535 this.sortSelectOptions();
536 this.lockRequiredRemoteFields();
537 this.updateAdditionalControls();
538 },
539 onElementChange: function onElementChange(controlView) {
540 var setting = controlView.model.get('name');
541
542 switch (setting) {
543 case "".concat(this.action, "_api_key_source"):
544 case "".concat(this.action, "_custom_api_key"):
545 this.ajaxUpdateList();
546 break;
547
548 case "".concat(this.action, "_list"):
549 var listId = this.getListId();
550
551 if (listId && !this.listOptions.hasOwnProperty(listId)) {
552 this.ajaxUpdateAdditionalData();
553 }
554
555 break;
556 }
557 },
558 getListId: function getListId() {
559 return this.getControlValue("".concat(this.action, "_list"));
560 },
561 // Set Options of the "List" select control.
562 setListOptions: function setListOptions(options) {
563 this.listView.model.set('options', options);
564 this.listView.render(); // Sort options so that the "Select..." option comes first.
565
566 var select = this.listView.$el.find('select');
567 var firstOption = select.find('option[value="none"]');
568
569 if (!firstOption.length) {
570 return;
571 }
572
573 var helper = firstOption[0];
574 firstOption.remove();
575 select.prepend(helper);
576 },
577 setListSelection: function setListSelection(option) {
578 this.listView.$el.find('select').val(option).change();
579 },
580 // Sort mapping fields options so that the "-NONE-" option comes first.
581 sortSelectOptions: function sortSelectOptions() {
582 var selects = this.mappingRepeater.$el.find('select');
583
584 _.each(selects, function (select) {
585 var firstOption = jQuery(select).find('option[value=""]');
586
587 if (!firstOption.length) {
588 return;
589 }
590
591 var helper = firstOption[0];
592 firstOption.remove();
593 select.prepend(helper);
594 });
595 },
596 getFormFields: function getFormFields() {
597 var items = {};
598 var formFieldsRepeater = this.getElementSettings(this.model, 'fields');
599
600 _.each(formFieldsRepeater, function (item) {
601 items[item._id] = item.label;
602 });
603
604 return items;
605 },
606 // Find required remote fields, lock them, remove their repeater row styles, and add a star next to them.
607 lockRequiredRemoteFields: function lockRequiredRemoteFields() {
608 this.mappingRepeater.children.each(function (row) {
609 if (row.model.get('is_required')) {
610 var toolbar = row.$el.find('div.elementor-repeater-row-tools');
611 var controlWrapper = row.$el.find('div.elementor-repeater-row-controls');
612 var remoteField = row.$el.find('div.elementor-control-remote_field');
613 var localField = row.$el.find('div.elementor-control-local_field');
614 var localLabel = localField.find('label');
615 var newLabel = remoteField.find('select option:selected').text();
616 var starMark = '<span style="color:red">*</span>';
617 toolbar.hide();
618 controlWrapper.show();
619 controlWrapper.css('border', 'none');
620 remoteField.hide();
621 localLabel.html(newLabel + starMark);
622 localField.css('padding', '0');
623 }
624 });
625 },
626 // Set titles of repeater rows so that they show "label" of remote fields instead of their "key".
627 fixTitleField: function fixTitleField(rowView) {
628 if (rowView.data) {
629 rowView = rowView.data.rowView;
630 }
631
632 var remoteFieldSelect = rowView.$el.find('select[data-setting="remote_field"]');
633 var label = remoteFieldSelect.find("option[value=\"".concat(remoteFieldSelect.val(), "\"]")).first().text();
634 rowView.$el.find('div.elementor-repeater-row-item-title').text(label);
635 remoteFieldSelect.off('change', this.fixTitleField).change({
636 rowView: rowView
637 }, this.fixTitleField);
638 },
639 // While additional data about the selected list is being recieved,
640 // toggle a spinner and opaque its corresopnding fields.
641 toggleSpinner: function toggleSpinner(state) {
642 var containers = jQuery(".elementor-control.elementor-control-".concat(this.action, "_list")).nextAll();
643 containers.css('opacity', state ? 0.5 : 1);
644
645 if (state) {
646 var spinner = "\n\t\t\t\t<span style=\"position: absolute; top: 15px; right: 15px;\" class=\"elementor-control-spinner\">\n\t\t\t\t\t<span style=\"font-size: 20px\" class=\"fa fa-spinner fa-spin\"></span>\n\t\t\t\t\t&nbsp;\n\t\t\t\t</span>\n\t\t\t";
647 containers.first().prepend(spinner);
648 return;
649 }
650
651 containers.first().find('span.elementor-control-spinner').remove();
652 },
653 // Placed to be overridden if needed.
654
655 /* eslint-disable no-unused-vars */
656 add_additional_api_data: function add_additional_api_data(params) {},
657
658 /* eslint-enable no-unused-vars */
659 // Placed to be overridden if needed.
660 updateAdditionalControls: function updateAdditionalControls() {}
661 });
662
663 exports["default"] = _default;
664
665 },{"../../util":14,"@babel/runtime/helpers/defineProperty":15,"@babel/runtime/helpers/interopRequireDefault":16,"@wordpress/i18n":23}],7:[function(require,module,exports){
666 "use strict";
667
668 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
669
670 Object.defineProperty(exports, "__esModule", {
671 value: true
672 });
673 exports["default"] = _default;
674
675 var _crmBase = _interopRequireDefault(require("./crm-base"));
676
677 function _default(panel, model, view) {
678 var Drip = _crmBase["default"].extend({
679 panel: panel,
680 model: model,
681 action: 'drip',
682 updateAdditionalControls: function updateAdditionalControls() {
683 if (!this.additionalData.hasOwnProperty('tags')) {
684 return;
685 }
686
687 var tagsControl = this.getControlView("".concat(this.action, "_tags"));
688 tagsControl.model.set('options', this.additionalData.tags);
689 tagsControl.render();
690 }
691 });
692
693 new Drip({
694 $element: view.$el
695 });
696 }
697
698 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],8:[function(require,module,exports){
699 "use strict";
700
701 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
702
703 Object.defineProperty(exports, "__esModule", {
704 value: true
705 });
706 exports["default"] = _default;
707
708 var _crmBase = _interopRequireDefault(require("./crm-base"));
709
710 function _default(panel, model, view) {
711 var GetResponse = _crmBase["default"].extend({
712 panel: panel,
713 model: model,
714 action: 'getresponse',
715 updateAdditionalControls: function updateAdditionalControls() {
716 if (!this.additionalData.hasOwnProperty('tags')) {
717 return;
718 }
719
720 var tagsControl = this.getControlView("".concat(this.action, "_tags"));
721 tagsControl.model.set('options', this.additionalData.tags);
722 tagsControl.render();
723 }
724 });
725
726 new GetResponse({
727 $element: view.$el
728 });
729 }
730
731 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],9:[function(require,module,exports){
732 "use strict";
733
734 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
735
736 Object.defineProperty(exports, "__esModule", {
737 value: true
738 });
739 exports["default"] = _default;
740
741 var _crmBase = _interopRequireDefault(require("./crm-base"));
742
743 function _default(panel, model, view) {
744 var Growmatic = _crmBase["default"].extend({
745 panel: panel,
746 model: model,
747 action: 'growmatik',
748 updateAdditionalControls: function updateAdditionalControls() {
749 if (!this.additionalData.hasOwnProperty('tags')) {
750 return;
751 }
752
753 var tagsControl = this.getControlView("".concat(this.action, "_tags"));
754 tagsControl.model.set('options', this.additionalData.tags);
755 tagsControl.render();
756 }
757 });
758
759 new Growmatic({
760 $element: view.$el
761 });
762 }
763
764 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],10:[function(require,module,exports){
765 "use strict";
766
767 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
768
769 Object.defineProperty(exports, "__esModule", {
770 value: true
771 });
772 exports["default"] = _default;
773
774 var _crmBase = _interopRequireDefault(require("./crm-base"));
775
776 function _default(panel, model, view) {
777 var ConvertKit = _crmBase["default"].extend({
778 panel: panel,
779 model: model,
780 action: 'mailchimp',
781 // Override just to add spinner, since the request time is little heavier than other actions.
782 ajaxUpdateAdditionalData: function ajaxUpdateAdditionalData() {
783 this.addControlSpinner("".concat(this.action, "_tags"));
784 this.addControlSpinner("".concat(this.action, "_groups"));
785
786 _crmBase["default"].prototype.ajaxUpdateAdditionalData.apply(this, arguments);
787 },
788 updateAdditionalControls: function updateAdditionalControls() {
789 var _this = this;
790
791 this.removeControlSpinner("".concat(this.action, "_tags"));
792 this.removeControlSpinner("".concat(this.action, "_groups"));
793
794 _.each(['tags', 'groups'], function (control) {
795 if (!_this.additionalData.hasOwnProperty("".concat(control))) {
796 return;
797 }
798
799 var controlView = _this.getControlView("".concat(_this.action, "_").concat(control));
800
801 controlView.model.set('options', _this.additionalData["".concat(control)]);
802 controlView.render();
803 });
804 }
805 });
806
807 new ConvertKit({
808 $element: view.$el
809 });
810 }
811
812 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],11:[function(require,module,exports){
813 "use strict";
814
815 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
816
817 Object.defineProperty(exports, "__esModule", {
818 value: true
819 });
820 exports["default"] = _default;
821
822 var _crmBase = _interopRequireDefault(require("./crm-base"));
823
824 function _default(panel, model, view) {
825 var MailerLite = _crmBase["default"].extend({
826 panel: panel,
827 model: model,
828 action: 'mailerlite'
829 });
830
831 new MailerLite({
832 $element: view.$el
833 });
834 }
835
836 },{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],12:[function(require,module,exports){
837 "use strict";
838
839 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
840
841 Object.defineProperty(exports, "__esModule", {
842 value: true
843 });
844 exports["default"] = _default;
845
846 var _util = _interopRequireDefault(require("../../util"));
847
848 function _default(panel, model, view) {
849 var itiTel = _util["default"].extend({
850 panel: panel,
851 model: model,
852 view: view,
853 sectionName: 'section_form_fields',
854 countries: {},
855 onInit: function onInit() {
856 this.getCountries();
857 this.refresh();
858 elementor.channels.editor.on('section:activated', this.onSectionActivated);
859 },
860 onSectionActivated: function onSectionActivated(activeSection, section) {
861 if (activeSection !== this.sectionName || section.model.id !== model.get('id')) {
862 return;
863 }
864
865 this.refresh();
866 },
867 refresh: function refresh() {
868 var _this = this;
869
870 var fieldsRepeater = this.getControlView('fields');
871 this.select2s = [];
872 fieldsRepeater.children.each(function (row) {
873 var typeControl = row.children.find(function (option) {
874 return 'type' === option.model.get('name');
875 }).$el.find('select');
876 typeControl.off('change', _this.refresh).change(_this.refresh);
877
878 if ('tel' !== typeControl.val()) {
879 return;
880 }
881
882 var allowDropdownControl = row.children.find(function (option) {
883 return 'iti_tel_allow_dropdown' === option.model.get('name');
884 }).$el.find('input');
885 allowDropdownControl.off('change', _this.refresh).change(_this.refresh);
886 var allowDropdown = allowDropdownControl[0].checked;
887 var countrySelect2 = row.children.find(function (option) {
888 return 'iti_tel_country_include' === option.model.get('name');
889 });
890 countrySelect2.model.set('multiple', allowDropdown);
891 countrySelect2.model.set('options', _this.countries);
892 countrySelect2.render();
893 });
894 fieldsRepeater.off('add:child', this.refresh).on('add:child', this.refresh);
895 },
896 getCountries: function getCountries() {
897 var _this2 = this;
898
899 require('intl-tel-input');
900
901 _.each(window.intlTelInputGlobals.getCountryData(), function (country) {
902 _this2.countries[country.iso2] = country.name;
903 });
904 }
905 });
906
907 new itiTel({
908 $element: view.$el
909 });
910 }
911
912 },{"../../util":14,"@babel/runtime/helpers/interopRequireDefault":16,"intl-tel-input":27}],13:[function(require,module,exports){
913 "use strict";
914
915 Object.defineProperty(exports, "__esModule", {
916 value: true
917 });
918 exports["default"] = _default;
919
920 function _default(panel, model, view) {
921 var optinModules = {
922 activecampaign: require('./actions/activecampaign')["default"],
923 drip: require('./actions/drip')["default"],
924 convertkit: require('./actions/convertkit')["default"],
925 getresponse: require('./actions/getresponse')["default"],
926 growmatik: require('./actions/growmatik')["default"],
927 mailchimp: require('./actions/mailchimp')["default"],
928 mailerlite: require('./actions/mailerlite')["default"],
929 iti: require('./misc/intelligent-tel')["default"]
930 };
931
932 for (var module in optinModules) {
933 optinModules[module](panel, model, view);
934 }
935 }
936
937 },{"./actions/activecampaign":4,"./actions/convertkit":5,"./actions/drip":7,"./actions/getresponse":8,"./actions/growmatik":9,"./actions/mailchimp":10,"./actions/mailerlite":11,"./misc/intelligent-tel":12}],14:[function(require,module,exports){
938 "use strict";
939
940 Object.defineProperty(exports, "__esModule", {
941 value: true
942 });
943 exports["default"] = void 0;
944 var Module = elementorModules.editor.utils.Module.extend({
945 panel: null,
946 getControl: function getControl(propertyName) {
947 if (!this.panel) {
948 return;
949 }
950
951 var control = this.panel.getCurrentPageView().collection.findWhere({
952 name: propertyName
953 });
954 return control;
955 },
956 getControlView: function getControlView(propertyName) {
957 if (!this.panel) {
958 return;
959 }
960
961 var control = this.getControl(propertyName);
962 var view = this.panel.getCurrentPageView().children.findByModelCid(control.cid);
963 return view;
964 },
965 getControlValue: function getControlValue(id) {
966 return this.getControlView(id).getControlValue();
967 },
968 addControlSpinner: function addControlSpinner(name) {
969 var $el = this.getControlView(name).$el,
970 $input = $el.find(':input');
971
972 if ($input.attr('disabled') || $el.find('.elementor-control-spinner').length > 0) {
973 return;
974 }
975
976 $input.attr('disabled', true);
977 $el.find('.elementor-control-title').after('<span style="display:inline-flex" class="elementor-control-spinner"><span class="fa fa-spinner fa-spin"></span>&nbsp;</span>');
978 },
979 removeControlSpinner: function removeControlSpinner(name) {
980 var $el = this.getControlView(name).$el;
981 $el.find(':input').attr('disabled', false);
982 $el.find('.elementor-control-spinner').remove();
983 },
984 getElementSettings: function getElementSettings(model, name) {
985 if (!model) {
986 return null;
987 }
988
989 var value = model.get('settings').get(name);
990 return value instanceof window.Backbone.Collection ? value.toJSON() : value;
991 }
992 });
993 var _default = Module;
994 exports["default"] = _default;
995
996 },{}],15:[function(require,module,exports){
997 function _defineProperty(obj, key, value) {
998 if (key in obj) {
999 Object.defineProperty(obj, key, {
1000 value: value,
1001 enumerable: true,
1002 configurable: true,
1003 writable: true
1004 });
1005 } else {
1006 obj[key] = value;
1007 }
1008
1009 return obj;
1010 }
1011
1012 module.exports = _defineProperty;
1013 },{}],16:[function(require,module,exports){
1014 function _interopRequireDefault(obj) {
1015 return obj && obj.__esModule ? obj : {
1016 "default": obj
1017 };
1018 }
1019
1020 module.exports = _interopRequireDefault;
1021 },{}],17:[function(require,module,exports){
1022 'use strict';
1023
1024 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
1025
1026 var postfix = _interopDefault(require('@tannin/postfix'));
1027 var evaluate = _interopDefault(require('@tannin/evaluate'));
1028
1029 /**
1030 * Given a C expression, returns a function which can be called to evaluate its
1031 * result.
1032 *
1033 * @example
1034 *
1035 * ```js
1036 * import compile from '@tannin/compile';
1037 *
1038 * const evaluate = compile( 'n > 1' );
1039 *
1040 * evaluate( { n: 2 } );
1041 * // ⇒ true
1042 * ```
1043 *
1044 * @param {string} expression C expression.
1045 *
1046 * @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator.
1047 */
1048 function compile( expression ) {
1049 var terms = postfix( expression );
1050
1051 return function( variables ) {
1052 return evaluate( terms, variables );
1053 };
1054 }
1055
1056 module.exports = compile;
1057
1058 },{"@tannin/evaluate":18,"@tannin/postfix":20}],18:[function(require,module,exports){
1059 'use strict';
1060
1061 /**
1062 * Operator callback functions.
1063 *
1064 * @type {Object}
1065 */
1066 var OPERATORS = {
1067 '!': function( a ) {
1068 return ! a;
1069 },
1070 '*': function( a, b ) {
1071 return a * b;
1072 },
1073 '/': function( a, b ) {
1074 return a / b;
1075 },
1076 '%': function( a, b ) {
1077 return a % b;
1078 },
1079 '+': function( a, b ) {
1080 return a + b;
1081 },
1082 '-': function( a, b ) {
1083 return a - b;
1084 },
1085 '<': function( a, b ) {
1086 return a < b;
1087 },
1088 '<=': function( a, b ) {
1089 return a <= b;
1090 },
1091 '>': function( a, b ) {
1092 return a > b;
1093 },
1094 '>=': function( a, b ) {
1095 return a >= b;
1096 },
1097 '==': function( a, b ) {
1098 return a === b;
1099 },
1100 '!=': function( a, b ) {
1101 return a !== b;
1102 },
1103 '&&': function( a, b ) {
1104 return a && b;
1105 },
1106 '||': function( a, b ) {
1107 return a || b;
1108 },
1109 '?:': function( a, b, c ) {
1110 if ( a ) {
1111 throw b;
1112 }
1113
1114 return c;
1115 },
1116 };
1117
1118 /**
1119 * Given an array of postfix terms and operand variables, returns the result of
1120 * the postfix evaluation.
1121 *
1122 * @example
1123 *
1124 * ```js
1125 * import evaluate from '@tannin/evaluate';
1126 *
1127 * // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +'
1128 * const terms = [ '3', '4', '5', '*', '6', '/', '+' ];
1129 *
1130 * evaluate( terms, {} );
1131 * // ⇒ 6.333333333333334
1132 * ```
1133 *
1134 * @param {string[]} postfix Postfix terms.
1135 * @param {Object} variables Operand variables.
1136 *
1137 * @return {*} Result of evaluation.
1138 */
1139 function evaluate( postfix, variables ) {
1140 var stack = [],
1141 i, j, args, getOperatorResult, term, value;
1142
1143 for ( i = 0; i < postfix.length; i++ ) {
1144 term = postfix[ i ];
1145
1146 getOperatorResult = OPERATORS[ term ];
1147 if ( getOperatorResult ) {
1148 // Pop from stack by number of function arguments.
1149 j = getOperatorResult.length;
1150 args = Array( j );
1151 while ( j-- ) {
1152 args[ j ] = stack.pop();
1153 }
1154
1155 try {
1156 value = getOperatorResult.apply( null, args );
1157 } catch ( earlyReturn ) {
1158 return earlyReturn;
1159 }
1160 } else if ( variables.hasOwnProperty( term ) ) {
1161 value = variables[ term ];
1162 } else {
1163 value = +term;
1164 }
1165
1166 stack.push( value );
1167 }
1168
1169 return stack[ 0 ];
1170 }
1171
1172 module.exports = evaluate;
1173
1174 },{}],19:[function(require,module,exports){
1175 'use strict';
1176
1177 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
1178
1179 var compile = _interopDefault(require('@tannin/compile'));
1180
1181 /**
1182 * Given a C expression, returns a function which, when called with a value,
1183 * evaluates the result with the value assumed to be the "n" variable of the
1184 * expression. The result will be coerced to its numeric equivalent.
1185 *
1186 * @param {string} expression C expression.
1187 *
1188 * @return {Function} Evaluator function.
1189 */
1190 function pluralForms( expression ) {
1191 var evaluate = compile( expression );
1192
1193 return function( n ) {
1194 return +evaluate( { n: n } );
1195 };
1196 }
1197
1198 module.exports = pluralForms;
1199
1200 },{"@tannin/compile":17}],20:[function(require,module,exports){
1201 'use strict';
1202
1203 var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
1204
1205 /**
1206 * Operator precedence mapping.
1207 *
1208 * @type {Object}
1209 */
1210 PRECEDENCE = {
1211 '(': 9,
1212 '!': 8,
1213 '*': 7,
1214 '/': 7,
1215 '%': 7,
1216 '+': 6,
1217 '-': 6,
1218 '<': 5,
1219 '<=': 5,
1220 '>': 5,
1221 '>=': 5,
1222 '==': 4,
1223 '!=': 4,
1224 '&&': 3,
1225 '||': 2,
1226 '?': 1,
1227 '?:': 1,
1228 };
1229
1230 /**
1231 * Characters which signal pair opening, to be terminated by terminators.
1232 *
1233 * @type {string[]}
1234 */
1235 OPENERS = [ '(', '?' ];
1236
1237 /**
1238 * Characters which signal pair termination, the value an array with the
1239 * opener as its first member. The second member is an optional operator
1240 * replacement to push to the stack.
1241 *
1242 * @type {string[]}
1243 */
1244 TERMINATORS = {
1245 ')': [ '(' ],
1246 ':': [ '?', '?:' ],
1247 };
1248
1249 /**
1250 * Pattern matching operators and openers.
1251 *
1252 * @type {RegExp}
1253 */
1254 PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
1255
1256 /**
1257 * Given a C expression, returns the equivalent postfix (Reverse Polish)
1258 * notation terms as an array.
1259 *
1260 * If a postfix string is desired, simply `.join( ' ' )` the result.
1261 *
1262 * @example
1263 *
1264 * ```js
1265 * import postfix from '@tannin/postfix';
1266 *
1267 * postfix( 'n > 1' );
1268 * // ⇒ [ 'n', '1', '>' ]
1269 * ```
1270 *
1271 * @param {string} expression C expression.
1272 *
1273 * @return {string[]} Postfix terms.
1274 */
1275 function postfix( expression ) {
1276 var terms = [],
1277 stack = [],
1278 match, operator, term, element;
1279
1280 while ( ( match = expression.match( PATTERN ) ) ) {
1281 operator = match[ 0 ];
1282
1283 // Term is the string preceding the operator match. It may contain
1284 // whitespace, and may be empty (if operator is at beginning).
1285 term = expression.substr( 0, match.index ).trim();
1286 if ( term ) {
1287 terms.push( term );
1288 }
1289
1290 while ( ( element = stack.pop() ) ) {
1291 if ( TERMINATORS[ operator ] ) {
1292 if ( TERMINATORS[ operator ][ 0 ] === element ) {
1293 // Substitution works here under assumption that because
1294 // the assigned operator will no longer be a terminator, it
1295 // will be pushed to the stack during the condition below.
1296 operator = TERMINATORS[ operator ][ 1 ] || operator;
1297 break;
1298 }
1299 } else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) {
1300 // Push to stack if either an opener or when pop reveals an
1301 // element of lower precedence.
1302 stack.push( element );
1303 break;
1304 }
1305
1306 // For each popped from stack, push to terms.
1307 terms.push( element );
1308 }
1309
1310 if ( ! TERMINATORS[ operator ] ) {
1311 stack.push( operator );
1312 }
1313
1314 // Slice matched fragment from expression to continue match.
1315 expression = expression.substr( match.index + operator.length );
1316 }
1317
1318 // Push remainder of operand, if exists, to terms.
1319 expression = expression.trim();
1320 if ( expression ) {
1321 terms.push( expression );
1322 }
1323
1324 // Pop remaining items from stack into terms.
1325 return terms.concat( stack.reverse() );
1326 }
1327
1328 module.exports = postfix;
1329
1330 },{}],21:[function(require,module,exports){
1331 "use strict";
1332
1333 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
1334
1335 Object.defineProperty(exports, "__esModule", {
1336 value: true
1337 });
1338 exports.createI18n = void 0;
1339
1340 var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
1341
1342 var _tannin = _interopRequireDefault(require("tannin"));
1343
1344 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
1345
1346 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1347
1348 /**
1349 * @typedef {Record<string,any>} LocaleData
1350 */
1351
1352 /**
1353 * Default locale data to use for Tannin domain when not otherwise provided.
1354 * Assumes an English plural forms expression.
1355 *
1356 * @type {LocaleData}
1357 */
1358 var DEFAULT_LOCALE_DATA = {
1359 '': {
1360 /** @param {number} n */
1361 plural_forms: function plural_forms(n) {
1362 return n === 1 ? 0 : 1;
1363 }
1364 }
1365 };
1366 /**
1367 * An i18n instance
1368 *
1369 * @typedef {Object} I18n
1370 * @property {Function} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a
1371 * Jed-formatted JSON object shape.
1372 * @property {Function} __ Retrieve the translation of text.
1373 * @property {Function} _x Retrieve translated string with gettext context.
1374 * @property {Function} _n Translates and retrieves the singular or plural form based on the supplied
1375 * number.
1376 * @property {Function} _nx Translates and retrieves the singular or plural form based on the supplied
1377 * number, with gettext context.
1378 * @property {Function} isRTL Check if current locale is RTL.
1379 */
1380
1381 /**
1382 * Create an i18n instance
1383 *
1384 * @param {LocaleData} [initialData] Locale data configuration.
1385 * @param {string} [initialDomain] Domain for which configuration applies.
1386 * @return {I18n} I18n instance
1387 */
1388
1389 var createI18n = function createI18n(initialData, initialDomain) {
1390 /**
1391 * The underlying instance of Tannin to which exported functions interface.
1392 *
1393 * @type {Tannin}
1394 */
1395 var tannin = new _tannin.default({});
1396 /**
1397 * Merges locale data into the Tannin instance by domain. Accepts data in a
1398 * Jed-formatted JSON object shape.
1399 *
1400 * @see http://messageformat.github.io/Jed/
1401 *
1402 * @param {LocaleData} [data] Locale data configuration.
1403 * @param {string} [domain] Domain for which configuration applies.
1404 */
1405
1406 var setLocaleData = function setLocaleData(data) {
1407 var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
1408 tannin.data[domain] = _objectSpread({}, DEFAULT_LOCALE_DATA, {}, tannin.data[domain], {}, data); // Populate default domain configuration (supported locale date which omits
1409 // a plural forms expression).
1410
1411 tannin.data[domain][''] = _objectSpread({}, DEFAULT_LOCALE_DATA[''], {}, tannin.data[domain]['']);
1412 };
1413 /**
1414 * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
1415 * otherwise previously assigned.
1416 *
1417 * @param {string|undefined} domain Domain to retrieve the translated text.
1418 * @param {string|undefined} context Context information for the translators.
1419 * @param {string} single Text to translate if non-plural. Used as
1420 * fallback return value on a caught error.
1421 * @param {string} [plural] The text to be used if the number is
1422 * plural.
1423 * @param {number} [number] The number to compare against to use
1424 * either the singular or plural form.
1425 *
1426 * @return {string} The translated string.
1427 */
1428
1429
1430 var dcnpgettext = function dcnpgettext() {
1431 var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
1432 var context = arguments.length > 1 ? arguments[1] : undefined;
1433 var single = arguments.length > 2 ? arguments[2] : undefined;
1434 var plural = arguments.length > 3 ? arguments[3] : undefined;
1435 var number = arguments.length > 4 ? arguments[4] : undefined;
1436
1437 if (!tannin.data[domain]) {
1438 setLocaleData(undefined, domain);
1439 }
1440
1441 return tannin.dcnpgettext(domain, context, single, plural, number);
1442 };
1443 /**
1444 * Retrieve the translation of text.
1445 *
1446 * @see https://developer.wordpress.org/reference/functions/__/
1447 *
1448 * @param {string} text Text to translate.
1449 * @param {string} [domain] Domain to retrieve the translated text.
1450 *
1451 * @return {string} Translated text.
1452 */
1453
1454
1455 var __ = function __(text, domain) {
1456 return dcnpgettext(domain, undefined, text);
1457 };
1458 /**
1459 * Retrieve translated string with gettext context.
1460 *
1461 * @see https://developer.wordpress.org/reference/functions/_x/
1462 *
1463 * @param {string} text Text to translate.
1464 * @param {string} context Context information for the translators.
1465 * @param {string} [domain] Domain to retrieve the translated text.
1466 *
1467 * @return {string} Translated context string without pipe.
1468 */
1469
1470
1471 var _x = function _x(text, context, domain) {
1472 return dcnpgettext(domain, context, text);
1473 };
1474 /**
1475 * Translates and retrieves the singular or plural form based on the supplied
1476 * number.
1477 *
1478 * @see https://developer.wordpress.org/reference/functions/_n/
1479 *
1480 * @param {string} single The text to be used if the number is singular.
1481 * @param {string} plural The text to be used if the number is plural.
1482 * @param {number} number The number to compare against to use either the
1483 * singular or plural form.
1484 * @param {string} [domain] Domain to retrieve the translated text.
1485 *
1486 * @return {string} The translated singular or plural form.
1487 */
1488
1489
1490 var _n = function _n(single, plural, number, domain) {
1491 return dcnpgettext(domain, undefined, single, plural, number);
1492 };
1493 /**
1494 * Translates and retrieves the singular or plural form based on the supplied
1495 * number, with gettext context.
1496 *
1497 * @see https://developer.wordpress.org/reference/functions/_nx/
1498 *
1499 * @param {string} single The text to be used if the number is singular.
1500 * @param {string} plural The text to be used if the number is plural.
1501 * @param {number} number The number to compare against to use either the
1502 * singular or plural form.
1503 * @param {string} context Context information for the translators.
1504 * @param {string} [domain] Domain to retrieve the translated text.
1505 *
1506 * @return {string} The translated singular or plural form.
1507 */
1508
1509
1510 var _nx = function _nx(single, plural, number, context, domain) {
1511 return dcnpgettext(domain, context, single, plural, number);
1512 };
1513 /**
1514 * Check if current locale is RTL.
1515 *
1516 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
1517 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
1518 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
1519 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
1520 *
1521 * @return {boolean} Whether locale is RTL.
1522 */
1523
1524
1525 var isRTL = function isRTL() {
1526 return 'rtl' === _x('ltr', 'text direction');
1527 };
1528
1529 if (initialData) {
1530 setLocaleData(initialData, initialDomain);
1531 }
1532
1533 return {
1534 setLocaleData: setLocaleData,
1535 __: __,
1536 _x: _x,
1537 _n: _n,
1538 _nx: _nx,
1539 isRTL: isRTL
1540 };
1541 };
1542
1543 exports.createI18n = createI18n;
1544
1545 },{"@babel/runtime/helpers/defineProperty":15,"@babel/runtime/helpers/interopRequireDefault":16,"tannin":30}],22:[function(require,module,exports){
1546 "use strict";
1547
1548 Object.defineProperty(exports, "__esModule", {
1549 value: true
1550 });
1551 exports.isRTL = exports._nx = exports._n = exports._x = exports.__ = exports.setLocaleData = void 0;
1552
1553 var _createI18n = require("./create-i18n");
1554
1555 /**
1556 * Internal dependencies
1557 */
1558 var i18n = (0, _createI18n.createI18n)();
1559 /*
1560 * Comments in this file are duplicated from ./i18n due to
1561 * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
1562 */
1563
1564 /**
1565 * @typedef {import('./create-i18n').LocaleData} LocaleData
1566 */
1567
1568 /**
1569 * Merges locale data into the Tannin instance by domain. Accepts data in a
1570 * Jed-formatted JSON object shape.
1571 *
1572 * @see http://messageformat.github.io/Jed/
1573 *
1574 * @param {LocaleData} [data] Locale data configuration.
1575 * @param {string} [domain] Domain for which configuration applies.
1576 */
1577
1578 var setLocaleData = i18n.setLocaleData.bind(i18n);
1579 /**
1580 * Retrieve the translation of text.
1581 *
1582 * @see https://developer.wordpress.org/reference/functions/__/
1583 *
1584 * @param {string} text Text to translate.
1585 * @param {string} [domain] Domain to retrieve the translated text.
1586 *
1587 * @return {string} Translated text.
1588 */
1589
1590 exports.setLocaleData = setLocaleData;
1591
1592 var __ = i18n.__.bind(i18n);
1593 /**
1594 * Retrieve translated string with gettext context.
1595 *
1596 * @see https://developer.wordpress.org/reference/functions/_x/
1597 *
1598 * @param {string} text Text to translate.
1599 * @param {string} context Context information for the translators.
1600 * @param {string} [domain] Domain to retrieve the translated text.
1601 *
1602 * @return {string} Translated context string without pipe.
1603 */
1604
1605
1606 exports.__ = __;
1607
1608 var _x = i18n._x.bind(i18n);
1609 /**
1610 * Translates and retrieves the singular or plural form based on the supplied
1611 * number.
1612 *
1613 * @see https://developer.wordpress.org/reference/functions/_n/
1614 *
1615 * @param {string} single The text to be used if the number is singular.
1616 * @param {string} plural The text to be used if the number is plural.
1617 * @param {number} number The number to compare against to use either the
1618 * singular or plural form.
1619 * @param {string} [domain] Domain to retrieve the translated text.
1620 *
1621 * @return {string} The translated singular or plural form.
1622 */
1623
1624
1625 exports._x = _x;
1626
1627 var _n = i18n._n.bind(i18n);
1628 /**
1629 * Translates and retrieves the singular or plural form based on the supplied
1630 * number, with gettext context.
1631 *
1632 * @see https://developer.wordpress.org/reference/functions/_nx/
1633 *
1634 * @param {string} single The text to be used if the number is singular.
1635 * @param {string} plural The text to be used if the number is plural.
1636 * @param {number} number The number to compare against to use either the
1637 * singular or plural form.
1638 * @param {string} context Context information for the translators.
1639 * @param {string} [domain] Domain to retrieve the translated text.
1640 *
1641 * @return {string} The translated singular or plural form.
1642 */
1643
1644
1645 exports._n = _n;
1646
1647 var _nx = i18n._nx.bind(i18n);
1648 /**
1649 * Check if current locale is RTL.
1650 *
1651 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
1652 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
1653 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
1654 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
1655 *
1656 * @return {boolean} Whether locale is RTL.
1657 */
1658
1659
1660 exports._nx = _nx;
1661 var isRTL = i18n.isRTL.bind(i18n);
1662 exports.isRTL = isRTL;
1663
1664 },{"./create-i18n":21}],23:[function(require,module,exports){
1665 "use strict";
1666
1667 Object.defineProperty(exports, "__esModule", {
1668 value: true
1669 });
1670 var _exportNames = {
1671 sprintf: true,
1672 setLocaleData: true,
1673 __: true,
1674 _x: true,
1675 _n: true,
1676 _nx: true,
1677 isRTL: true
1678 };
1679 Object.defineProperty(exports, "sprintf", {
1680 enumerable: true,
1681 get: function get() {
1682 return _sprintf.sprintf;
1683 }
1684 });
1685 Object.defineProperty(exports, "setLocaleData", {
1686 enumerable: true,
1687 get: function get() {
1688 return _defaultI18n.setLocaleData;
1689 }
1690 });
1691 Object.defineProperty(exports, "__", {
1692 enumerable: true,
1693 get: function get() {
1694 return _defaultI18n.__;
1695 }
1696 });
1697 Object.defineProperty(exports, "_x", {
1698 enumerable: true,
1699 get: function get() {
1700 return _defaultI18n._x;
1701 }
1702 });
1703 Object.defineProperty(exports, "_n", {
1704 enumerable: true,
1705 get: function get() {
1706 return _defaultI18n._n;
1707 }
1708 });
1709 Object.defineProperty(exports, "_nx", {
1710 enumerable: true,
1711 get: function get() {
1712 return _defaultI18n._nx;
1713 }
1714 });
1715 Object.defineProperty(exports, "isRTL", {
1716 enumerable: true,
1717 get: function get() {
1718 return _defaultI18n.isRTL;
1719 }
1720 });
1721
1722 var _sprintf = require("./sprintf");
1723
1724 var _createI18n = require("./create-i18n");
1725
1726 Object.keys(_createI18n).forEach(function (key) {
1727 if (key === "default" || key === "__esModule") return;
1728 if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
1729 Object.defineProperty(exports, key, {
1730 enumerable: true,
1731 get: function get() {
1732 return _createI18n[key];
1733 }
1734 });
1735 });
1736
1737 var _defaultI18n = require("./default-i18n");
1738
1739 },{"./create-i18n":21,"./default-i18n":22,"./sprintf":24}],24:[function(require,module,exports){
1740 "use strict";
1741
1742 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
1743
1744 Object.defineProperty(exports, "__esModule", {
1745 value: true
1746 });
1747 exports.sprintf = sprintf;
1748
1749 var _memize = _interopRequireDefault(require("memize"));
1750
1751 var _sprintfJs = _interopRequireDefault(require("sprintf-js"));
1752
1753 /**
1754 * External dependencies
1755 */
1756
1757 /**
1758 * Log to console, once per message; or more precisely, per referentially equal
1759 * argument set. Because Jed throws errors, we log these to the console instead
1760 * to avoid crashing the application.
1761 *
1762 * @param {...*} args Arguments to pass to `console.error`
1763 */
1764 var logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console
1765
1766 /**
1767 * Returns a formatted string. If an error occurs in applying the format, the
1768 * original format string is returned.
1769 *
1770 * @param {string} format The format of the string to generate.
1771 * @param {...*} args Arguments to apply to the format.
1772 *
1773 * @see http://www.diveintojavascript.com/projects/javascript-sprintf
1774 *
1775 * @return {string} The formatted string.
1776 */
1777
1778 function sprintf(format) {
1779 try {
1780 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1781 args[_key - 1] = arguments[_key];
1782 }
1783
1784 return _sprintfJs.default.sprintf.apply(_sprintfJs.default, [format].concat(args));
1785 } catch (error) {
1786 logErrorOnce('sprintf error: \n\n' + error.toString());
1787 return format;
1788 }
1789 }
1790
1791 },{"@babel/runtime/helpers/interopRequireDefault":16,"memize":28,"sprintf-js":25}],25:[function(require,module,exports){
1792 /* global window, exports, define */
1793
1794 !function() {
1795 'use strict'
1796
1797 var re = {
1798 not_string: /[^s]/,
1799 not_bool: /[^t]/,
1800 not_type: /[^T]/,
1801 not_primitive: /[^v]/,
1802 number: /[diefg]/,
1803 numeric_arg: /[bcdiefguxX]/,
1804 json: /[j]/,
1805 not_json: /[^j]/,
1806 text: /^[^\x25]+/,
1807 modulo: /^\x25{2}/,
1808 placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
1809 key: /^([a-z_][a-z_\d]*)/i,
1810 key_access: /^\.([a-z_][a-z_\d]*)/i,
1811 index_access: /^\[(\d+)\]/,
1812 sign: /^[+-]/
1813 }
1814
1815 function sprintf(key) {
1816 // `arguments` is not an array, but should be fine for this call
1817 return sprintf_format(sprintf_parse(key), arguments)
1818 }
1819
1820 function vsprintf(fmt, argv) {
1821 return sprintf.apply(null, [fmt].concat(argv || []))
1822 }
1823
1824 function sprintf_format(parse_tree, argv) {
1825 var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
1826 for (i = 0; i < tree_length; i++) {
1827 if (typeof parse_tree[i] === 'string') {
1828 output += parse_tree[i]
1829 }
1830 else if (typeof parse_tree[i] === 'object') {
1831 ph = parse_tree[i] // convenience purposes only
1832 if (ph.keys) { // keyword argument
1833 arg = argv[cursor]
1834 for (k = 0; k < ph.keys.length; k++) {
1835 if (arg == undefined) {
1836 throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
1837 }
1838 arg = arg[ph.keys[k]]
1839 }
1840 }
1841 else if (ph.param_no) { // positional argument (explicit)
1842 arg = argv[ph.param_no]
1843 }
1844 else { // positional argument (implicit)
1845 arg = argv[cursor++]
1846 }
1847
1848 if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
1849 arg = arg()
1850 }
1851
1852 if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
1853 throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
1854 }
1855
1856 if (re.number.test(ph.type)) {
1857 is_positive = arg >= 0
1858 }
1859
1860 switch (ph.type) {
1861 case 'b':
1862 arg = parseInt(arg, 10).toString(2)
1863 break
1864 case 'c':
1865 arg = String.fromCharCode(parseInt(arg, 10))
1866 break
1867 case 'd':
1868 case 'i':
1869 arg = parseInt(arg, 10)
1870 break
1871 case 'j':
1872 arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
1873 break
1874 case 'e':
1875 arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
1876 break
1877 case 'f':
1878 arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
1879 break
1880 case 'g':
1881 arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
1882 break
1883 case 'o':
1884 arg = (parseInt(arg, 10) >>> 0).toString(8)
1885 break
1886 case 's':
1887 arg = String(arg)
1888 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1889 break
1890 case 't':
1891 arg = String(!!arg)
1892 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1893 break
1894 case 'T':
1895 arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
1896 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1897 break
1898 case 'u':
1899 arg = parseInt(arg, 10) >>> 0
1900 break
1901 case 'v':
1902 arg = arg.valueOf()
1903 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1904 break
1905 case 'x':
1906 arg = (parseInt(arg, 10) >>> 0).toString(16)
1907 break
1908 case 'X':
1909 arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
1910 break
1911 }
1912 if (re.json.test(ph.type)) {
1913 output += arg
1914 }
1915 else {
1916 if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
1917 sign = is_positive ? '+' : '-'
1918 arg = arg.toString().replace(re.sign, '')
1919 }
1920 else {
1921 sign = ''
1922 }
1923 pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
1924 pad_length = ph.width - (sign + arg).length
1925 pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
1926 output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
1927 }
1928 }
1929 }
1930 return output
1931 }
1932
1933 var sprintf_cache = Object.create(null)
1934
1935 function sprintf_parse(fmt) {
1936 if (sprintf_cache[fmt]) {
1937 return sprintf_cache[fmt]
1938 }
1939
1940 var _fmt = fmt, match, parse_tree = [], arg_names = 0
1941 while (_fmt) {
1942 if ((match = re.text.exec(_fmt)) !== null) {
1943 parse_tree.push(match[0])
1944 }
1945 else if ((match = re.modulo.exec(_fmt)) !== null) {
1946 parse_tree.push('%')
1947 }
1948 else if ((match = re.placeholder.exec(_fmt)) !== null) {
1949 if (match[2]) {
1950 arg_names |= 1
1951 var field_list = [], replacement_field = match[2], field_match = []
1952 if ((field_match = re.key.exec(replacement_field)) !== null) {
1953 field_list.push(field_match[1])
1954 while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
1955 if ((field_match = re.key_access.exec(replacement_field)) !== null) {
1956 field_list.push(field_match[1])
1957 }
1958 else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
1959 field_list.push(field_match[1])
1960 }
1961 else {
1962 throw new SyntaxError('[sprintf] failed to parse named argument key')
1963 }
1964 }
1965 }
1966 else {
1967 throw new SyntaxError('[sprintf] failed to parse named argument key')
1968 }
1969 match[2] = field_list
1970 }
1971 else {
1972 arg_names |= 2
1973 }
1974 if (arg_names === 3) {
1975 throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
1976 }
1977
1978 parse_tree.push(
1979 {
1980 placeholder: match[0],
1981 param_no: match[1],
1982 keys: match[2],
1983 sign: match[3],
1984 pad_char: match[4],
1985 align: match[5],
1986 width: match[6],
1987 precision: match[7],
1988 type: match[8]
1989 }
1990 )
1991 }
1992 else {
1993 throw new SyntaxError('[sprintf] unexpected placeholder')
1994 }
1995 _fmt = _fmt.substring(match[0].length)
1996 }
1997 return sprintf_cache[fmt] = parse_tree
1998 }
1999
2000 /**
2001 * export to either browser or node.js
2002 */
2003 /* eslint-disable quote-props */
2004 if (typeof exports !== 'undefined') {
2005 exports['sprintf'] = sprintf
2006 exports['vsprintf'] = vsprintf
2007 }
2008 if (typeof window !== 'undefined') {
2009 window['sprintf'] = sprintf
2010 window['vsprintf'] = vsprintf
2011
2012 if (typeof define === 'function' && define['amd']) {
2013 define(function() {
2014 return {
2015 'sprintf': sprintf,
2016 'vsprintf': vsprintf
2017 }
2018 })
2019 }
2020 }
2021 /* eslint-enable quote-props */
2022 }(); // eslint-disable-line
2023
2024 },{}],26:[function(require,module,exports){
2025 /*
2026 * International Telephone Input v17.0.16
2027 * https://github.com/jackocnr/intl-tel-input.git
2028 * Licensed under the MIT license
2029 */
2030
2031 // wrap in UMD
2032 (function(factory) {
2033 if (typeof module === "object" && module.exports) module.exports = factory(); else window.intlTelInput = factory();
2034 })(function(undefined) {
2035 "use strict";
2036 return function() {
2037 // Array of country objects for the flag dropdown.
2038 // Here is the criteria for the plugin to support a given country/territory
2039 // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
2040 // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes
2041 // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
2042 // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
2043 // Each country array has the following information:
2044 // [
2045 // Country name,
2046 // iso2 code,
2047 // International dial code,
2048 // Order (if >1 country with same dial code),
2049 // Area codes
2050 // ]
2051 var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1", 5, [ "684" ] ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1", 6, [ "264" ] ], [ "Antigua and Barbuda", "ag", "1", 7, [ "268" ] ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Ascension Island", "ac", "247" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1", 8, [ "242" ] ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1", 9, [ "246" ] ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1", 10, [ "441" ] ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1", 11, [ "284" ] ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1, [ "3", "4", "7" ] ], [ "Cayman Islands", "ky", "1", 12, [ "345" ] ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Christmas Island", "cx", "61", 2, [ "89164" ] ], [ "Cocos (Keeling) Islands", "cc", "61", 1, [ "89162" ] ], [ "Colombia", "co", "57" ], [ "Comoros (‫جزر الق�
2052 ر‬‎)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1", 13, [ "767" ] ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (‫�
2053 صر‬‎)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Eswatini", "sz", "268" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358", 0 ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1", 14, [ "473" ] ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1", 15, [ "671" ] ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1, [ "1481", "7781", "7839", "7911" ] ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (‫ایران‬‎)", "ir", "98" ], [ "Iraq (‫العراق‬‎)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2, [ "1624", "74576", "7524", "7924", "7624" ] ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1", 4, [ "876", "658" ] ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3, [ "1534", "7509", "7700", "7797", "7829", "7937" ] ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Каза�
2054 стан)", "kz", "7", 1, [ "33", "7" ] ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kosovo", "xk", "383" ], [ "Kuwait (‫الكويت‬‎)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (‫لبنان‬‎)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (‫ليبيا‬‎)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "North Macedonia (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (‫�
2055 وريتانيا‬‎)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mayotte", "yt", "262", 1, [ "269", "639" ] ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1", 16, [ "664" ] ], [ "Morocco (‫ال�
2056 غرب‬‎)", "ma", "212", 0 ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1", 17, [ "670" ] ], [ "Norway (Norge)", "no", "47", 0 ], [ "Oman (‫عُ�
2057 ان‬‎)", "om", "968" ], [ "Pakistan (‫پاکستان‬‎)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (‫فلسطين‬‎)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (‫قطر‬‎)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1", 18, [ "869" ] ], [ "Saint Lucia", "lc", "1", 19, [ "758" ] ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1", 20, [ "784" ] ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (‫ال�
2058
2059 لكة العربية السعودية‬‎)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1", 21, [ "721" ] ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (‫جنوب السودان‬‎)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්‍රී ලංකාව)", "lk", "94" ], [ "Sudan (‫السودان‬‎)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1, [ "79" ] ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (‫سوريا‬‎)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1", 22, [ "868" ] ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1", 23, [ "649" ] ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1", 24, [ "340" ] ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (‫الإ�
2060 ارات العربية ال�
2061 تحدة‬‎)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1, [ "06698" ] ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (‫الصحراء الغربية‬‎)", "eh", "212", 1, [ "5288", "5289" ] ], [ "Yemen (‫الي�
2062 ن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "�
2063 land Islands", "ax", "358", 1, [ "18" ] ] ];
2064 // loop over all of the countries above, restructuring the data to be objects with named keys
2065 for (var i = 0; i < allCountries.length; i++) {
2066 var c = allCountries[i];
2067 allCountries[i] = {
2068 name: c[0],
2069 iso2: c[1],
2070 dialCode: c[2],
2071 priority: c[3] || 0,
2072 areaCodes: c[4] || null
2073 };
2074 }
2075 "use strict";
2076 function _classCallCheck(instance, Constructor) {
2077 if (!(instance instanceof Constructor)) {
2078 throw new TypeError("Cannot call a class as a function");
2079 }
2080 }
2081 function _defineProperties(target, props) {
2082 for (var i = 0; i < props.length; i++) {
2083 var descriptor = props[i];
2084 descriptor.enumerable = descriptor.enumerable || false;
2085 descriptor.configurable = true;
2086 if ("value" in descriptor) descriptor.writable = true;
2087 Object.defineProperty(target, descriptor.key, descriptor);
2088 }
2089 }
2090 function _createClass(Constructor, protoProps, staticProps) {
2091 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
2092 if (staticProps) _defineProperties(Constructor, staticProps);
2093 return Constructor;
2094 }
2095 var intlTelInputGlobals = {
2096 getInstance: function getInstance(input) {
2097 var id = input.getAttribute("data-intl-tel-input-id");
2098 return window.intlTelInputGlobals.instances[id];
2099 },
2100 instances: {},
2101 // using a global like this allows us to mock it in the tests
2102 documentReady: function documentReady() {
2103 return document.readyState === "complete";
2104 }
2105 };
2106 if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
2107 // these vars persist through all instances of the plugin
2108 var id = 0;
2109 var defaults = {
2110 // whether or not to allow the dropdown
2111 allowDropdown: true,
2112 // if there is just a dial code in the input: remove it on blur
2113 autoHideDialCode: true,
2114 // add a placeholder in the input with an example number for the selected country
2115 autoPlaceholder: "polite",
2116 // modify the parentClass
2117 customContainer: "",
2118 // modify the auto placeholder
2119 customPlaceholder: null,
2120 // append menu to specified element
2121 dropdownContainer: null,
2122 // don't display these countries
2123 excludeCountries: [],
2124 // format the input value during initialisation and on setNumber
2125 formatOnDisplay: true,
2126 // geoIp lookup function
2127 geoIpLookup: null,
2128 // inject a hidden input with this name, and on submit, populate it with the result of getNumber
2129 hiddenInput: "",
2130 // initial country
2131 initialCountry: "",
2132 // localized country names e.g. { 'de': 'Deutschland' }
2133 localizedCountries: null,
2134 // don't insert international dial codes
2135 nationalMode: true,
2136 // display only these countries
2137 onlyCountries: [],
2138 // number type to use for placeholders
2139 placeholderNumberType: "MOBILE",
2140 // the countries at the top of the list. defaults to united states and united kingdom
2141 preferredCountries: [ "us", "gb" ],
2142 // display the country dial code next to the selected flag so it's not part of the typed number
2143 separateDialCode: false,
2144 // specify the path to the libphonenumber script to enable validation/formatting
2145 utilsScript: ""
2146 };
2147 // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
2148 var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
2149 // utility function to iterate over an object. can't use Object.entries or native forEach because
2150 // of IE11
2151 var forEachProp = function forEachProp(obj, callback) {
2152 var keys = Object.keys(obj);
2153 for (var i = 0; i < keys.length; i++) {
2154 callback(keys[i], obj[keys[i]]);
2155 }
2156 };
2157 // run a method on each instance of the plugin
2158 var forEachInstance = function forEachInstance(method) {
2159 forEachProp(window.intlTelInputGlobals.instances, function(key) {
2160 window.intlTelInputGlobals.instances[key][method]();
2161 });
2162 };
2163 // this is our plugin class that we will create an instance of
2164 // eslint-disable-next-line no-unused-vars
2165 var Iti = /*#__PURE__*/
2166 function() {
2167 function Iti(input, options) {
2168 var _this = this;
2169 _classCallCheck(this, Iti);
2170 this.id = id++;
2171 this.telInput = input;
2172 this.activeItem = null;
2173 this.highlightedItem = null;
2174 // process specified options / defaults
2175 // alternative to Object.assign, which isn't supported by IE11
2176 var customOptions = options || {};
2177 this.options = {};
2178 forEachProp(defaults, function(key, value) {
2179 _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value;
2180 });
2181 this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
2182 }
2183 _createClass(Iti, [ {
2184 key: "_init",
2185 value: function _init() {
2186 var _this2 = this;
2187 // if in nationalMode, disable options relating to dial codes
2188 if (this.options.nationalMode) this.options.autoHideDialCode = false;
2189 // if separateDialCode then doesn't make sense to A) insert dial code into input
2190 // (autoHideDialCode), and B) display national numbers (because we're displaying the country
2191 // dial code next to them)
2192 if (this.options.separateDialCode) {
2193 this.options.autoHideDialCode = this.options.nationalMode = false;
2194 }
2195 // we cannot just test screen size as some smartphones/website meta tags will report desktop
2196 // resolutions
2197 // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
2198 // rest of these declarations
2199 // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
2200 this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
2201 if (this.isMobile) {
2202 // trigger the mobile dropdown css
2203 document.body.classList.add("iti-mobile");
2204 // on mobile, we want a full screen dropdown, so we must append it to the body
2205 if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
2206 }
2207 // these promises get resolved when their individual requests complete
2208 // this way the dev can do something like iti.promise.then(...) to know when all requests are
2209 // complete
2210 if (typeof Promise !== "undefined") {
2211 var autoCountryPromise = new Promise(function(resolve, reject) {
2212 _this2.resolveAutoCountryPromise = resolve;
2213 _this2.rejectAutoCountryPromise = reject;
2214 });
2215 var utilsScriptPromise = new Promise(function(resolve, reject) {
2216 _this2.resolveUtilsScriptPromise = resolve;
2217 _this2.rejectUtilsScriptPromise = reject;
2218 });
2219 this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
2220 } else {
2221 // prevent errors when Promise doesn't exist
2222 this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function() {};
2223 this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function() {};
2224 }
2225 // in various situations there could be no country selected initially, but we need to be able
2226 // to assume this variable exists
2227 this.selectedCountryData = {};
2228 // process all the data: onlyCountries, excludeCountries, preferredCountries etc
2229 this._processCountryData();
2230 // generate the markup
2231 this._generateMarkup();
2232 // set the initial state of the input value and the selected flag
2233 this._setInitialState();
2234 // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
2235 this._initListeners();
2236 // utils script, and auto country
2237 this._initRequests();
2238 }
2239 }, {
2240 key: "_processCountryData",
2241 value: function _processCountryData() {
2242 // process onlyCountries or excludeCountries array if present
2243 this._processAllCountries();
2244 // process the countryCodes map
2245 this._processCountryCodes();
2246 // process the preferredCountries
2247 this._processPreferredCountries();
2248 // translate countries according to localizedCountries option
2249 if (this.options.localizedCountries) this._translateCountriesByLocale();
2250 // sort countries by name
2251 if (this.options.onlyCountries.length || this.options.localizedCountries) {
2252 this.countries.sort(this._countryNameSort);
2253 }
2254 }
2255 }, {
2256 key: "_addCountryCode",
2257 value: function _addCountryCode(iso2, countryCode, priority) {
2258 if (countryCode.length > this.countryCodeMaxLen) {
2259 this.countryCodeMaxLen = countryCode.length;
2260 }
2261 if (!this.countryCodes.hasOwnProperty(countryCode)) {
2262 this.countryCodes[countryCode] = [];
2263 }
2264 // bail if we already have this country for this countryCode
2265 for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
2266 if (this.countryCodes[countryCode][i] === iso2) return;
2267 }
2268 // check for undefined as 0 is falsy
2269 var index = priority !== undefined ? priority : this.countryCodes[countryCode].length;
2270 this.countryCodes[countryCode][index] = iso2;
2271 }
2272 }, {
2273 key: "_processAllCountries",
2274 value: function _processAllCountries() {
2275 if (this.options.onlyCountries.length) {
2276 var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
2277 return country.toLowerCase();
2278 });
2279 this.countries = allCountries.filter(function(country) {
2280 return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
2281 });
2282 } else if (this.options.excludeCountries.length) {
2283 var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
2284 return country.toLowerCase();
2285 });
2286 this.countries = allCountries.filter(function(country) {
2287 return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
2288 });
2289 } else {
2290 this.countries = allCountries;
2291 }
2292 }
2293 }, {
2294 key: "_translateCountriesByLocale",
2295 value: function _translateCountriesByLocale() {
2296 for (var i = 0; i < this.countries.length; i++) {
2297 var iso = this.countries[i].iso2.toLowerCase();
2298 if (this.options.localizedCountries.hasOwnProperty(iso)) {
2299 this.countries[i].name = this.options.localizedCountries[iso];
2300 }
2301 }
2302 }
2303 }, {
2304 key: "_countryNameSort",
2305 value: function _countryNameSort(a, b) {
2306 return a.name.localeCompare(b.name);
2307 }
2308 }, {
2309 key: "_processCountryCodes",
2310 value: function _processCountryCodes() {
2311 this.countryCodeMaxLen = 0;
2312 // here we store just dial codes
2313 this.dialCodes = {};
2314 // here we store "country codes" (both dial codes and their area codes)
2315 this.countryCodes = {};
2316 // first: add dial codes
2317 for (var i = 0; i < this.countries.length; i++) {
2318 var c = this.countries[i];
2319 if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
2320 this._addCountryCode(c.iso2, c.dialCode, c.priority);
2321 }
2322 // next: add area codes
2323 // this is a second loop over countries, to make sure we have all of the "root" countries
2324 // already in the map, so that we can access them, as each time we add an area code substring
2325 // to the map, we also need to include the "root" country's code, as that also matches
2326 for (var _i = 0; _i < this.countries.length; _i++) {
2327 var _c = this.countries[_i];
2328 // area codes
2329 if (_c.areaCodes) {
2330 var rootCountryCode = this.countryCodes[_c.dialCode][0];
2331 // for each area code
2332 for (var j = 0; j < _c.areaCodes.length; j++) {
2333 var areaCode = _c.areaCodes[j];
2334 // for each digit in the area code to add all partial matches as well
2335 for (var k = 1; k < areaCode.length; k++) {
2336 var partialDialCode = _c.dialCode + areaCode.substr(0, k);
2337 // start with the root country, as that also matches this dial code
2338 this._addCountryCode(rootCountryCode, partialDialCode);
2339 this._addCountryCode(_c.iso2, partialDialCode);
2340 }
2341 // add the full area code
2342 this._addCountryCode(_c.iso2, _c.dialCode + areaCode);
2343 }
2344 }
2345 }
2346 }
2347 }, {
2348 key: "_processPreferredCountries",
2349 value: function _processPreferredCountries() {
2350 this.preferredCountries = [];
2351 for (var i = 0; i < this.options.preferredCountries.length; i++) {
2352 var countryCode = this.options.preferredCountries[i].toLowerCase();
2353 var countryData = this._getCountryData(countryCode, false, true);
2354 if (countryData) this.preferredCountries.push(countryData);
2355 }
2356 }
2357 }, {
2358 key: "_createEl",
2359 value: function _createEl(name, attrs, container) {
2360 var el = document.createElement(name);
2361 if (attrs) forEachProp(attrs, function(key, value) {
2362 return el.setAttribute(key, value);
2363 });
2364 if (container) container.appendChild(el);
2365 return el;
2366 }
2367 }, {
2368 key: "_generateMarkup",
2369 value: function _generateMarkup() {
2370 // if autocomplete does not exist on the element and its form, then
2371 // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
2372 // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
2373 // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
2374 if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
2375 this.telInput.setAttribute("autocomplete", "off");
2376 }
2377 // containers (mostly for positioning)
2378 var parentClass = "iti";
2379 if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
2380 if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
2381 if (this.options.customContainer) {
2382 parentClass += " ";
2383 parentClass += this.options.customContainer;
2384 }
2385 var wrapper = this._createEl("div", {
2386 "class": parentClass
2387 });
2388 this.telInput.parentNode.insertBefore(wrapper, this.telInput);
2389 this.flagsContainer = this._createEl("div", {
2390 "class": "iti__flag-container"
2391 }, wrapper);
2392 wrapper.appendChild(this.telInput);
2393 // selected flag (displayed to left of input)
2394 this.selectedFlag = this._createEl("div", {
2395 "class": "iti__selected-flag",
2396 role: "combobox",
2397 "aria-controls": "iti-".concat(this.id, "__country-listbox"),
2398 "aria-owns": "iti-".concat(this.id, "__country-listbox"),
2399 "aria-expanded": "false"
2400 }, this.flagsContainer);
2401 this.selectedFlagInner = this._createEl("div", {
2402 "class": "iti__flag"
2403 }, this.selectedFlag);
2404 if (this.options.separateDialCode) {
2405 this.selectedDialCode = this._createEl("div", {
2406 "class": "iti__selected-dial-code"
2407 }, this.selectedFlag);
2408 }
2409 if (this.options.allowDropdown) {
2410 // make element focusable and tab navigable
2411 this.selectedFlag.setAttribute("tabindex", "0");
2412 this.dropdownArrow = this._createEl("div", {
2413 "class": "iti__arrow"
2414 }, this.selectedFlag);
2415 // country dropdown: preferred countries, then divider, then all countries
2416 this.countryList = this._createEl("ul", {
2417 "class": "iti__country-list iti__hide",
2418 id: "iti-".concat(this.id, "__country-listbox"),
2419 role: "listbox",
2420 "aria-label": "List of countries"
2421 });
2422 if (this.preferredCountries.length) {
2423 this._appendListItems(this.preferredCountries, "iti__preferred", true);
2424 this._createEl("li", {
2425 "class": "iti__divider",
2426 role: "separator",
2427 "aria-disabled": "true"
2428 }, this.countryList);
2429 }
2430 this._appendListItems(this.countries, "iti__standard");
2431 // create dropdownContainer markup
2432 if (this.options.dropdownContainer) {
2433 this.dropdown = this._createEl("div", {
2434 "class": "iti iti--container"
2435 });
2436 this.dropdown.appendChild(this.countryList);
2437 } else {
2438 this.flagsContainer.appendChild(this.countryList);
2439 }
2440 }
2441 if (this.options.hiddenInput) {
2442 var hiddenInputName = this.options.hiddenInput;
2443 var name = this.telInput.getAttribute("name");
2444 if (name) {
2445 var i = name.lastIndexOf("[");
2446 // if input name contains square brackets, then give the hidden input the same name,
2447 // replacing the contents of the last set of brackets with the given hiddenInput name
2448 if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
2449 }
2450 this.hiddenInput = this._createEl("input", {
2451 type: "hidden",
2452 name: hiddenInputName
2453 });
2454 wrapper.appendChild(this.hiddenInput);
2455 }
2456 }
2457 }, {
2458 key: "_appendListItems",
2459 value: function _appendListItems(countries, className, preferred) {
2460 // we create so many DOM elements, it is faster to build a temp string
2461 // and then add everything to the DOM in one go at the end
2462 var tmp = "";
2463 // for each country
2464 for (var i = 0; i < countries.length; i++) {
2465 var c = countries[i];
2466 var idSuffix = preferred ? "-preferred" : "";
2467 // open the list item
2468 tmp += "<li class='iti__country ".concat(className, "' tabIndex='-1' id='iti-").concat(this.id, "__item-").concat(c.iso2).concat(idSuffix, "' role='option' data-dial-code='").concat(c.dialCode, "' data-country-code='").concat(c.iso2, "' aria-selected='false'>");
2469 // add the flag
2470 tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
2471 // and the country name and dial code
2472 tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
2473 tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
2474 // close the list item
2475 tmp += "</li>";
2476 }
2477 this.countryList.insertAdjacentHTML("beforeend", tmp);
2478 }
2479 }, {
2480 key: "_setInitialState",
2481 value: function _setInitialState() {
2482 // fix firefox bug: when first load page (with input with value set to number with intl dial
2483 // code) and initialising plugin removes the dial code from the input, then refresh page,
2484 // and we try to init plugin again but this time on number without dial code so get grey flag
2485 var attributeValue = this.telInput.getAttribute("value");
2486 var inputValue = this.telInput.value;
2487 var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
2488 var val = useAttribute ? attributeValue : inputValue;
2489 var dialCode = this._getDialCode(val);
2490 var isRegionlessNanp = this._isRegionlessNanp(val);
2491 var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
2492 // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
2493 // flag, else fall back to the default country
2494 if (dialCode && !isRegionlessNanp) {
2495 this._updateFlagFromNumber(val);
2496 } else if (initialCountry !== "auto") {
2497 // see if we should select a flag
2498 if (initialCountry) {
2499 this._setFlag(initialCountry.toLowerCase());
2500 } else {
2501 if (dialCode && isRegionlessNanp) {
2502 // has intl dial code, is regionless nanp, and no initialCountry, so default to US
2503 this._setFlag("us");
2504 } else {
2505 // no dial code and no initialCountry, so default to first in list
2506 this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
2507 if (!val) {
2508 this._setFlag(this.defaultCountry);
2509 }
2510 }
2511 }
2512 // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
2513 if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) {
2514 this.telInput.value = "+".concat(this.selectedCountryData.dialCode);
2515 }
2516 }
2517 // NOTE: if initialCountry is set to auto, that will be handled separately
2518 // format - note this wont be run after _updateDialCode as that's only called if no val
2519 if (val) this._updateValFromNumber(val);
2520 }
2521 }, {
2522 key: "_initListeners",
2523 value: function _initListeners() {
2524 this._initKeyListeners();
2525 if (this.options.autoHideDialCode) this._initBlurListeners();
2526 if (this.options.allowDropdown) this._initDropdownListeners();
2527 if (this.hiddenInput) this._initHiddenInputListener();
2528 }
2529 }, {
2530 key: "_initHiddenInputListener",
2531 value: function _initHiddenInputListener() {
2532 var _this3 = this;
2533 this._handleHiddenInputSubmit = function() {
2534 _this3.hiddenInput.value = _this3.getNumber();
2535 };
2536 if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
2537 }
2538 }, {
2539 key: "_getClosestLabel",
2540 value: function _getClosestLabel() {
2541 var el = this.telInput;
2542 while (el && el.tagName !== "LABEL") {
2543 el = el.parentNode;
2544 }
2545 return el;
2546 }
2547 }, {
2548 key: "_initDropdownListeners",
2549 value: function _initDropdownListeners() {
2550 var _this4 = this;
2551 // hack for input nested inside label (which is valid markup): clicking the selected-flag to
2552 // open the dropdown would then automatically trigger a 2nd click on the input which would
2553 // close it again
2554 this._handleLabelClick = function(e) {
2555 // if the dropdown is closed, then focus the input, else ignore the click
2556 if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
2557 };
2558 var label = this._getClosestLabel();
2559 if (label) label.addEventListener("click", this._handleLabelClick);
2560 // toggle country dropdown on click
2561 this._handleClickSelectedFlag = function() {
2562 // only intercept this event if we're opening the dropdown
2563 // else let it bubble up to the top ("click-off-to-close" listener)
2564 // we cannot just stopPropagation as it may be needed to close another instance
2565 if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) {
2566 _this4._showDropdown();
2567 }
2568 };
2569 this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
2570 // open dropdown list if currently focused
2571 this._handleFlagsContainerKeydown = function(e) {
2572 var isDropdownHidden = _this4.countryList.classList.contains("iti__hide");
2573 if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) {
2574 // prevent form from being submitted if "ENTER" was pressed
2575 e.preventDefault();
2576 // prevent event from being handled again by document
2577 e.stopPropagation();
2578 _this4._showDropdown();
2579 }
2580 // allow navigation from dropdown to input on TAB
2581 if (e.key === "Tab") _this4._closeDropdown();
2582 };
2583 this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
2584 }
2585 }, {
2586 key: "_initRequests",
2587 value: function _initRequests() {
2588 var _this5 = this;
2589 // if the user has specified the path to the utils script, fetch it on window.load, else resolve
2590 if (this.options.utilsScript && !window.intlTelInputUtils) {
2591 // if the plugin is being initialised after the window.load event has already been fired
2592 if (window.intlTelInputGlobals.documentReady()) {
2593 window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
2594 } else {
2595 // wait until the load event so we don't block any other requests e.g. the flags image
2596 window.addEventListener("load", function() {
2597 window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
2598 });
2599 }
2600 } else this.resolveUtilsScriptPromise();
2601 if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
2602 }
2603 }, {
2604 key: "_loadAutoCountry",
2605 value: function _loadAutoCountry() {
2606 // 3 options:
2607 // 1) already loaded (we're done)
2608 // 2) not already started loading (start)
2609 // 3) already started loading (do nothing - just wait for loading callback to fire)
2610 if (window.intlTelInputGlobals.autoCountry) {
2611 this.handleAutoCountry();
2612 } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
2613 // don't do this twice!
2614 window.intlTelInputGlobals.startedLoadingAutoCountry = true;
2615 if (typeof this.options.geoIpLookup === "function") {
2616 this.options.geoIpLookup(function(countryCode) {
2617 window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase();
2618 // tell all instances the auto country is ready
2619 // TODO: this should just be the current instances
2620 // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
2621 // away (e.g. if they have already done the geo ip lookup somewhere else). Using
2622 // setTimeout means that the current thread of execution will finish before executing
2623 // this, which allows the plugin to finish initialising.
2624 setTimeout(function() {
2625 return forEachInstance("handleAutoCountry");
2626 });
2627 }, function() {
2628 return forEachInstance("rejectAutoCountryPromise");
2629 });
2630 }
2631 }
2632 }
2633 }, {
2634 key: "_initKeyListeners",
2635 value: function _initKeyListeners() {
2636 var _this6 = this;
2637 // update flag on keyup
2638 this._handleKeyupEvent = function() {
2639 if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
2640 _this6._triggerCountryChange();
2641 }
2642 };
2643 this.telInput.addEventListener("keyup", this._handleKeyupEvent);
2644 // update flag on cut/paste events (now supported in all major browsers)
2645 this._handleClipboardEvent = function() {
2646 // hack because "paste" event is fired before input is updated
2647 setTimeout(_this6._handleKeyupEvent);
2648 };
2649 this.telInput.addEventListener("cut", this._handleClipboardEvent);
2650 this.telInput.addEventListener("paste", this._handleClipboardEvent);
2651 }
2652 }, {
2653 key: "_cap",
2654 value: function _cap(number) {
2655 var max = this.telInput.getAttribute("maxlength");
2656 return max && number.length > max ? number.substr(0, max) : number;
2657 }
2658 }, {
2659 key: "_initBlurListeners",
2660 value: function _initBlurListeners() {
2661 var _this7 = this;
2662 // on blur or form submit: if just a dial code then remove it
2663 this._handleSubmitOrBlurEvent = function() {
2664 _this7._removeEmptyDialCode();
2665 };
2666 if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
2667 this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
2668 }
2669 }, {
2670 key: "_removeEmptyDialCode",
2671 value: function _removeEmptyDialCode() {
2672 if (this.telInput.value.charAt(0) === "+") {
2673 var numeric = this._getNumeric(this.telInput.value);
2674 // if just a plus, or if just a dial code
2675 if (!numeric || this.selectedCountryData.dialCode === numeric) {
2676 this.telInput.value = "";
2677 }
2678 }
2679 }
2680 }, {
2681 key: "_getNumeric",
2682 value: function _getNumeric(s) {
2683 return s.replace(/\D/g, "");
2684 }
2685 }, {
2686 key: "_trigger",
2687 value: function _trigger(name) {
2688 // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax
2689 var e = document.createEvent("Event");
2690 e.initEvent(name, true, true);
2691 // can bubble, and is cancellable
2692 this.telInput.dispatchEvent(e);
2693 }
2694 }, {
2695 key: "_showDropdown",
2696 value: function _showDropdown() {
2697 this.countryList.classList.remove("iti__hide");
2698 this.selectedFlag.setAttribute("aria-expanded", "true");
2699 this._setDropdownPosition();
2700 // update highlighting and scroll to active list item
2701 if (this.activeItem) {
2702 this._highlightListItem(this.activeItem, false);
2703 this._scrollTo(this.activeItem, true);
2704 }
2705 // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
2706 this._bindDropdownListeners();
2707 // update the arrow
2708 this.dropdownArrow.classList.add("iti__arrow--up");
2709 this._trigger("open:countrydropdown");
2710 }
2711 }, {
2712 key: "_toggleClass",
2713 value: function _toggleClass(el, className, shouldHaveClass) {
2714 if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
2715 }
2716 }, {
2717 key: "_setDropdownPosition",
2718 value: function _setDropdownPosition() {
2719 var _this8 = this;
2720 if (this.options.dropdownContainer) {
2721 this.options.dropdownContainer.appendChild(this.dropdown);
2722 }
2723 if (!this.isMobile) {
2724 var pos = this.telInput.getBoundingClientRect();
2725 // windowTop from https://stackoverflow.com/a/14384091/217866
2726 var windowTop = window.pageYOffset || document.documentElement.scrollTop;
2727 var inputTop = pos.top + windowTop;
2728 var dropdownHeight = this.countryList.offsetHeight;
2729 // dropdownFitsBelow = (dropdownBottom < windowBottom)
2730 var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
2731 var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
2732 // by default, the dropdown will be below the input. If we want to position it above the
2733 // input, we add the dropup class.
2734 this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove);
2735 // if dropdownContainer is enabled, calculate postion
2736 if (this.options.dropdownContainer) {
2737 // by default the dropdown will be directly over the input because it's not in the flow.
2738 // If we want to position it below, we need to add some extra top value.
2739 var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight;
2740 // calculate placement
2741 this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
2742 this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
2743 // close menu on window scroll
2744 this._handleWindowScroll = function() {
2745 return _this8._closeDropdown();
2746 };
2747 window.addEventListener("scroll", this._handleWindowScroll);
2748 }
2749 }
2750 }
2751 }, {
2752 key: "_getClosestListItem",
2753 value: function _getClosestListItem(target) {
2754 var el = target;
2755 while (el && el !== this.countryList && !el.classList.contains("iti__country")) {
2756 el = el.parentNode;
2757 }
2758 // if we reached the countryList element, then return null
2759 return el === this.countryList ? null : el;
2760 }
2761 }, {
2762 key: "_bindDropdownListeners",
2763 value: function _bindDropdownListeners() {
2764 var _this9 = this;
2765 // when mouse over a list item, just highlight that one
2766 // we add the class "highlight", so if they hit "enter" we know which one to select
2767 this._handleMouseoverCountryList = function(e) {
2768 // handle event delegation, as we're listening for this event on the countryList
2769 var listItem = _this9._getClosestListItem(e.target);
2770 if (listItem) _this9._highlightListItem(listItem, false);
2771 };
2772 this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
2773 // listen for country selection
2774 this._handleClickCountryList = function(e) {
2775 var listItem = _this9._getClosestListItem(e.target);
2776 if (listItem) _this9._selectListItem(listItem);
2777 };
2778 this.countryList.addEventListener("click", this._handleClickCountryList);
2779 // click off to close
2780 // (except when this initial opening click is bubbling up)
2781 // we cannot just stopPropagation as it may be needed to close another instance
2782 var isOpening = true;
2783 this._handleClickOffToClose = function() {
2784 if (!isOpening) _this9._closeDropdown();
2785 isOpening = false;
2786 };
2787 document.documentElement.addEventListener("click", this._handleClickOffToClose);
2788 // listen for up/down scrolling, enter to select, or letters to jump to country name.
2789 // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
2790 // just hit down and hold it to scroll down (no keyup event).
2791 // listen on the document because that's where key events are triggered if no input has focus
2792 var query = "";
2793 var queryTimer = null;
2794 this._handleKeydownOnDropdown = function(e) {
2795 // prevent down key from scrolling the whole page,
2796 // and enter key from submitting a form etc
2797 e.preventDefault();
2798 // up and down to navigate
2799 if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") _this9._handleUpDownKey(e.key); else if (e.key === "Enter") _this9._handleEnterKey(); else if (e.key === "Escape") _this9._closeDropdown(); else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
2800 // jump to countries that start with the query string
2801 if (queryTimer) clearTimeout(queryTimer);
2802 query += e.key.toLowerCase();
2803 _this9._searchForCountry(query);
2804 // if the timer hits 1 second, reset the query
2805 queryTimer = setTimeout(function() {
2806 query = "";
2807 }, 1e3);
2808 }
2809 };
2810 document.addEventListener("keydown", this._handleKeydownOnDropdown);
2811 }
2812 }, {
2813 key: "_handleUpDownKey",
2814 value: function _handleUpDownKey(key) {
2815 var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
2816 if (next) {
2817 // skip the divider
2818 if (next.classList.contains("iti__divider")) {
2819 next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling;
2820 }
2821 this._highlightListItem(next, true);
2822 }
2823 }
2824 }, {
2825 key: "_handleEnterKey",
2826 value: function _handleEnterKey() {
2827 if (this.highlightedItem) this._selectListItem(this.highlightedItem);
2828 }
2829 }, {
2830 key: "_searchForCountry",
2831 value: function _searchForCountry(query) {
2832 for (var i = 0; i < this.countries.length; i++) {
2833 if (this._startsWith(this.countries[i].name, query)) {
2834 var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2));
2835 // update highlighting and scroll
2836 this._highlightListItem(listItem, false);
2837 this._scrollTo(listItem, true);
2838 break;
2839 }
2840 }
2841 }
2842 }, {
2843 key: "_startsWith",
2844 value: function _startsWith(a, b) {
2845 return a.substr(0, b.length).toLowerCase() === b;
2846 }
2847 }, {
2848 key: "_updateValFromNumber",
2849 value: function _updateValFromNumber(originalNumber) {
2850 var number = originalNumber;
2851 if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
2852 var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+");
2853 var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
2854 var format = useNational ? NATIONAL : INTERNATIONAL;
2855 number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
2856 }
2857 number = this._beforeSetNumber(number);
2858 this.telInput.value = number;
2859 }
2860 }, {
2861 key: "_updateFlagFromNumber",
2862 value: function _updateFlagFromNumber(originalNumber) {
2863 // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
2864 // with a +1 so _getDialCode will be able to extract the area code
2865 // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
2866 // from the number), that means we're initialising the plugin with a number that already has a
2867 // dial code, so fine to ignore this bit
2868 var number = originalNumber;
2869 var selectedDialCode = this.selectedCountryData.dialCode;
2870 var isNanp = selectedDialCode === "1";
2871 if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
2872 if (number.charAt(0) !== "1") number = "1".concat(number);
2873 number = "+".concat(number);
2874 }
2875 // update flag if user types area code for another country
2876 if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
2877 number = "+".concat(selectedDialCode).concat(number);
2878 }
2879 // try and extract valid dial code from input
2880 var dialCode = this._getDialCode(number, true);
2881 var numeric = this._getNumeric(number);
2882 var countryCode = null;
2883 if (dialCode) {
2884 var countryCodes = this.countryCodes[this._getNumeric(dialCode)];
2885 // check if the right country is already selected. this should be false if the number is
2886 // longer than the matched dial code because in this case we need to make sure that if
2887 // there are multiple country matches, that the first one is selected (note: we could
2888 // just check that here, but it requires the same loop that we already have later)
2889 var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
2890 var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
2891 // only update the flag if:
2892 // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
2893 // AND
2894 // B) the right country is not already selected
2895 if (!isRegionlessNanpNumber && !alreadySelected) {
2896 // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first
2897 // non-empty index
2898 for (var j = 0; j < countryCodes.length; j++) {
2899 if (countryCodes[j]) {
2900 countryCode = countryCodes[j];
2901 break;
2902 }
2903 }
2904 }
2905 } else if (number.charAt(0) === "+" && numeric.length) {
2906 // invalid dial code, so empty
2907 // Note: use getNumeric here because the number has not been formatted yet, so could contain
2908 // bad chars
2909 countryCode = "";
2910 } else if (!number || number === "+") {
2911 // empty, or just a plus, so default
2912 countryCode = this.defaultCountry;
2913 }
2914 if (countryCode !== null) {
2915 return this._setFlag(countryCode);
2916 }
2917 return false;
2918 }
2919 }, {
2920 key: "_isRegionlessNanp",
2921 value: function _isRegionlessNanp(number) {
2922 var numeric = this._getNumeric(number);
2923 if (numeric.charAt(0) === "1") {
2924 var areaCode = numeric.substr(1, 3);
2925 return regionlessNanpNumbers.indexOf(areaCode) !== -1;
2926 }
2927 return false;
2928 }
2929 }, {
2930 key: "_highlightListItem",
2931 value: function _highlightListItem(listItem, shouldFocus) {
2932 var prevItem = this.highlightedItem;
2933 if (prevItem) prevItem.classList.remove("iti__highlight");
2934 this.highlightedItem = listItem;
2935 this.highlightedItem.classList.add("iti__highlight");
2936 if (shouldFocus) this.highlightedItem.focus();
2937 }
2938 }, {
2939 key: "_getCountryData",
2940 value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) {
2941 var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
2942 for (var i = 0; i < countryList.length; i++) {
2943 if (countryList[i].iso2 === countryCode) {
2944 return countryList[i];
2945 }
2946 }
2947 if (allowFail) {
2948 return null;
2949 }
2950 throw new Error("No country data for '".concat(countryCode, "'"));
2951 }
2952 }, {
2953 key: "_setFlag",
2954 value: function _setFlag(countryCode) {
2955 var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
2956 // do this first as it will throw an error and stop if countryCode is invalid
2957 this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
2958 // update the defaultCountry - we only need the iso2 from now on, so just store that
2959 if (this.selectedCountryData.iso2) {
2960 this.defaultCountry = this.selectedCountryData.iso2;
2961 }
2962 this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
2963 // update the selected country's title attribute
2964 var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
2965 this.selectedFlag.setAttribute("title", title);
2966 if (this.options.separateDialCode) {
2967 var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
2968 this.selectedDialCode.innerHTML = dialCode;
2969 // offsetWidth is zero if input is in a hidden container during initialisation
2970 var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
2971 // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
2972 this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
2973 }
2974 // and the input's placeholder
2975 this._updatePlaceholder();
2976 // update the active list item
2977 if (this.options.allowDropdown) {
2978 var prevItem = this.activeItem;
2979 if (prevItem) {
2980 prevItem.classList.remove("iti__active");
2981 prevItem.setAttribute("aria-selected", "false");
2982 }
2983 if (countryCode) {
2984 // check if there is a preferred item first, else fall back to standard
2985 var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode));
2986 nextItem.setAttribute("aria-selected", "true");
2987 nextItem.classList.add("iti__active");
2988 this.activeItem = nextItem;
2989 this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id"));
2990 }
2991 }
2992 // return if the flag has changed or not
2993 return prevCountry.iso2 !== countryCode;
2994 }
2995 }, {
2996 key: "_getHiddenSelectedFlagWidth",
2997 value: function _getHiddenSelectedFlagWidth() {
2998 // to get the right styling to apply, all we need is a shallow clone of the container,
2999 // and then to inject a deep clone of the selectedFlag element
3000 var containerClone = this.telInput.parentNode.cloneNode();
3001 containerClone.style.visibility = "hidden";
3002 document.body.appendChild(containerClone);
3003 var flagsContainerClone = this.flagsContainer.cloneNode();
3004 containerClone.appendChild(flagsContainerClone);
3005 var selectedFlagClone = this.selectedFlag.cloneNode(true);
3006 flagsContainerClone.appendChild(selectedFlagClone);
3007 var width = selectedFlagClone.offsetWidth;
3008 containerClone.parentNode.removeChild(containerClone);
3009 return width;
3010 }
3011 }, {
3012 key: "_updatePlaceholder",
3013 value: function _updatePlaceholder() {
3014 var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite";
3015 if (window.intlTelInputUtils && shouldSetPlaceholder) {
3016 var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
3017 var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
3018 placeholder = this._beforeSetNumber(placeholder);
3019 if (typeof this.options.customPlaceholder === "function") {
3020 placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
3021 }
3022 this.telInput.setAttribute("placeholder", placeholder);
3023 }
3024 }
3025 }, {
3026 key: "_selectListItem",
3027 value: function _selectListItem(listItem) {
3028 // update selected flag and active list item
3029 var flagChanged = this._setFlag(listItem.getAttribute("data-country-code"));
3030 this._closeDropdown();
3031 this._updateDialCode(listItem.getAttribute("data-dial-code"), true);
3032 // focus the input
3033 this.telInput.focus();
3034 // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
3035 // inserting dial code), who try to put the cursor at the beginning the first time
3036 var len = this.telInput.value.length;
3037 this.telInput.setSelectionRange(len, len);
3038 if (flagChanged) {
3039 this._triggerCountryChange();
3040 }
3041 }
3042 }, {
3043 key: "_closeDropdown",
3044 value: function _closeDropdown() {
3045 this.countryList.classList.add("iti__hide");
3046 this.selectedFlag.setAttribute("aria-expanded", "false");
3047 // update the arrow
3048 this.dropdownArrow.classList.remove("iti__arrow--up");
3049 // unbind key events
3050 document.removeEventListener("keydown", this._handleKeydownOnDropdown);
3051 document.documentElement.removeEventListener("click", this._handleClickOffToClose);
3052 this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
3053 this.countryList.removeEventListener("click", this._handleClickCountryList);
3054 // remove menu from container
3055 if (this.options.dropdownContainer) {
3056 if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
3057 if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
3058 }
3059 this._trigger("close:countrydropdown");
3060 }
3061 }, {
3062 key: "_scrollTo",
3063 value: function _scrollTo(element, middle) {
3064 var container = this.countryList;
3065 // windowTop from https://stackoverflow.com/a/14384091/217866
3066 var windowTop = window.pageYOffset || document.documentElement.scrollTop;
3067 var containerHeight = container.offsetHeight;
3068 var containerTop = container.getBoundingClientRect().top + windowTop;
3069 var containerBottom = containerTop + containerHeight;
3070 var elementHeight = element.offsetHeight;
3071 var elementTop = element.getBoundingClientRect().top + windowTop;
3072 var elementBottom = elementTop + elementHeight;
3073 var newScrollTop = elementTop - containerTop + container.scrollTop;
3074 var middleOffset = containerHeight / 2 - elementHeight / 2;
3075 if (elementTop < containerTop) {
3076 // scroll up
3077 if (middle) newScrollTop -= middleOffset;
3078 container.scrollTop = newScrollTop;
3079 } else if (elementBottom > containerBottom) {
3080 // scroll down
3081 if (middle) newScrollTop += middleOffset;
3082 var heightDifference = containerHeight - elementHeight;
3083 container.scrollTop = newScrollTop - heightDifference;
3084 }
3085 }
3086 }, {
3087 key: "_updateDialCode",
3088 value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) {
3089 var inputVal = this.telInput.value;
3090 // save having to pass this every time
3091 var newDialCode = "+".concat(newDialCodeBare);
3092 var newNumber;
3093 if (inputVal.charAt(0) === "+") {
3094 // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
3095 var prevDialCode = this._getDialCode(inputVal);
3096 if (prevDialCode) {
3097 // current number contains a valid dial code, so replace it
3098 newNumber = inputVal.replace(prevDialCode, newDialCode);
3099 } else {
3100 // current number contains an invalid dial code, so ditch it
3101 // (no way to determine where the invalid dial code ends and the rest of the number begins)
3102 newNumber = newDialCode;
3103 }
3104 } else if (this.options.nationalMode || this.options.separateDialCode) {
3105 // don't do anything
3106 return;
3107 } else {
3108 // nationalMode is disabled
3109 if (inputVal) {
3110 // there is an existing value with no dial code: prefix the new dial code
3111 newNumber = newDialCode + inputVal;
3112 } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
3113 // no existing value and either they've just selected a list item, or autoHideDialCode is
3114 // disabled: insert new dial code
3115 newNumber = newDialCode;
3116 } else {
3117 return;
3118 }
3119 }
3120 this.telInput.value = newNumber;
3121 }
3122 }, {
3123 key: "_getDialCode",
3124 value: function _getDialCode(number, includeAreaCode) {
3125 var dialCode = "";
3126 // only interested in international numbers (starting with a plus)
3127 if (number.charAt(0) === "+") {
3128 var numericChars = "";
3129 // iterate over chars
3130 for (var i = 0; i < number.length; i++) {
3131 var c = number.charAt(i);
3132 // if char is number (https://stackoverflow.com/a/8935649/217866)
3133 if (!isNaN(parseInt(c, 10))) {
3134 numericChars += c;
3135 // if current numericChars make a valid dial code
3136 if (includeAreaCode) {
3137 if (this.countryCodes[numericChars]) {
3138 // store the actual raw string (useful for matching later)
3139 dialCode = number.substr(0, i + 1);
3140 }
3141 } else {
3142 if (this.dialCodes[numericChars]) {
3143 dialCode = number.substr(0, i + 1);
3144 // if we're just looking for a dial code, we can break as soon as we find one
3145 break;
3146 }
3147 }
3148 // stop searching as soon as we can - in this case when we hit max len
3149 if (numericChars.length === this.countryCodeMaxLen) {
3150 break;
3151 }
3152 }
3153 }
3154 }
3155 return dialCode;
3156 }
3157 }, {
3158 key: "_getFullNumber",
3159 value: function _getFullNumber() {
3160 var val = this.telInput.value.trim();
3161 var dialCode = this.selectedCountryData.dialCode;
3162 var prefix;
3163 var numericVal = this._getNumeric(val);
3164 if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
3165 // when using separateDialCode, it is visible so is effectively part of the typed number
3166 prefix = "+".concat(dialCode);
3167 } else {
3168 prefix = "";
3169 }
3170 return prefix + val;
3171 }
3172 }, {
3173 key: "_beforeSetNumber",
3174 value: function _beforeSetNumber(originalNumber) {
3175 var number = originalNumber;
3176 if (this.options.separateDialCode) {
3177 var dialCode = this._getDialCode(number);
3178 // if there is a valid dial code
3179 if (dialCode) {
3180 // in case _getDialCode returned an area code as well
3181 dialCode = "+".concat(this.selectedCountryData.dialCode);
3182 // a lot of numbers will have a space separating the dial code and the main number, and
3183 // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
3184 // rid of it
3185 // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
3186 var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3187 number = number.substr(start);
3188 }
3189 }
3190 return this._cap(number);
3191 }
3192 }, {
3193 key: "_triggerCountryChange",
3194 value: function _triggerCountryChange() {
3195 this._trigger("countrychange");
3196 }
3197 }, {
3198 key: "handleAutoCountry",
3199 value: function handleAutoCountry() {
3200 if (this.options.initialCountry === "auto") {
3201 // we must set this even if there is an initial val in the input: in case the initial val is
3202 // invalid and they delete it - they should see their auto country
3203 this.defaultCountry = window.intlTelInputGlobals.autoCountry;
3204 // if there's no initial value in the input, then update the flag
3205 if (!this.telInput.value) {
3206 this.setCountry(this.defaultCountry);
3207 }
3208 this.resolveAutoCountryPromise();
3209 }
3210 }
3211 }, {
3212 key: "handleUtils",
3213 value: function handleUtils() {
3214 // if the request was successful
3215 if (window.intlTelInputUtils) {
3216 // if there's an initial value in the input, then format it
3217 if (this.telInput.value) {
3218 this._updateValFromNumber(this.telInput.value);
3219 }
3220 this._updatePlaceholder();
3221 }
3222 this.resolveUtilsScriptPromise();
3223 }
3224 }, {
3225 key: "destroy",
3226 value: function destroy() {
3227 var form = this.telInput.form;
3228 if (this.options.allowDropdown) {
3229 // make sure the dropdown is closed (and unbind listeners)
3230 this._closeDropdown();
3231 this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
3232 this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
3233 // label click hack
3234 var label = this._getClosestLabel();
3235 if (label) label.removeEventListener("click", this._handleLabelClick);
3236 }
3237 // unbind hiddenInput listeners
3238 if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
3239 // unbind autoHideDialCode listeners
3240 if (this.options.autoHideDialCode) {
3241 if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
3242 this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
3243 }
3244 // unbind key events, and cut/paste events
3245 this.telInput.removeEventListener("keyup", this._handleKeyupEvent);
3246 this.telInput.removeEventListener("cut", this._handleClipboardEvent);
3247 this.telInput.removeEventListener("paste", this._handleClipboardEvent);
3248 // remove attribute of id instance: data-intl-tel-input-id
3249 this.telInput.removeAttribute("data-intl-tel-input-id");
3250 // remove markup (but leave the original input)
3251 var wrapper = this.telInput.parentNode;
3252 wrapper.parentNode.insertBefore(this.telInput, wrapper);
3253 wrapper.parentNode.removeChild(wrapper);
3254 delete window.intlTelInputGlobals.instances[this.id];
3255 }
3256 }, {
3257 key: "getExtension",
3258 value: function getExtension() {
3259 if (window.intlTelInputUtils) {
3260 return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
3261 }
3262 return "";
3263 }
3264 }, {
3265 key: "getNumber",
3266 value: function getNumber(format) {
3267 if (window.intlTelInputUtils) {
3268 var iso2 = this.selectedCountryData.iso2;
3269 return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
3270 }
3271 return "";
3272 }
3273 }, {
3274 key: "getNumberType",
3275 value: function getNumberType() {
3276 if (window.intlTelInputUtils) {
3277 return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
3278 }
3279 return -99;
3280 }
3281 }, {
3282 key: "getSelectedCountryData",
3283 value: function getSelectedCountryData() {
3284 return this.selectedCountryData;
3285 }
3286 }, {
3287 key: "getValidationError",
3288 value: function getValidationError() {
3289 if (window.intlTelInputUtils) {
3290 var iso2 = this.selectedCountryData.iso2;
3291 return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
3292 }
3293 return -99;
3294 }
3295 }, {
3296 key: "isValidNumber",
3297 value: function isValidNumber() {
3298 var val = this._getFullNumber().trim();
3299 var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
3300 return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
3301 }
3302 }, {
3303 key: "setCountry",
3304 value: function setCountry(originalCountryCode) {
3305 var countryCode = originalCountryCode.toLowerCase();
3306 // check if already selected
3307 if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
3308 this._setFlag(countryCode);
3309 this._updateDialCode(this.selectedCountryData.dialCode, false);
3310 this._triggerCountryChange();
3311 }
3312 }
3313 }, {
3314 key: "setNumber",
3315 value: function setNumber(number) {
3316 // we must update the flag first, which updates this.selectedCountryData, which is used for
3317 // formatting the number before displaying it
3318 var flagChanged = this._updateFlagFromNumber(number);
3319 this._updateValFromNumber(number);
3320 if (flagChanged) {
3321 this._triggerCountryChange();
3322 }
3323 }
3324 }, {
3325 key: "setPlaceholderNumberType",
3326 value: function setPlaceholderNumberType(type) {
3327 this.options.placeholderNumberType = type;
3328 this._updatePlaceholder();
3329 }
3330 } ]);
3331 return Iti;
3332 }();
3333 /********************
3334 * STATIC METHODS
3335 ********************/
3336 // get the country data object
3337 intlTelInputGlobals.getCountryData = function() {
3338 return allCountries;
3339 };
3340 // inject a <script> element to load utils.js
3341 var injectScript = function injectScript(path, handleSuccess, handleFailure) {
3342 // inject a new script element into the page
3343 var script = document.createElement("script");
3344 script.onload = function() {
3345 forEachInstance("handleUtils");
3346 if (handleSuccess) handleSuccess();
3347 };
3348 script.onerror = function() {
3349 forEachInstance("rejectUtilsScriptPromise");
3350 if (handleFailure) handleFailure();
3351 };
3352 script.className = "iti-load-utils";
3353 script.async = true;
3354 script.src = path;
3355 document.body.appendChild(script);
3356 };
3357 // load the utils script
3358 intlTelInputGlobals.loadUtils = function(path) {
3359 // 2 options:
3360 // 1) not already started loading (start)
3361 // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
3362 // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
3363 if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
3364 // only do this once
3365 window.intlTelInputGlobals.startedLoadingUtilsScript = true;
3366 // if we have promises, then return a promise
3367 if (typeof Promise !== "undefined") {
3368 return new Promise(function(resolve, reject) {
3369 return injectScript(path, resolve, reject);
3370 });
3371 }
3372 injectScript(path);
3373 }
3374 return null;
3375 };
3376 // default options
3377 intlTelInputGlobals.defaults = defaults;
3378 // version
3379 intlTelInputGlobals.version = "17.0.16";
3380 // convenience wrapper
3381 return function(input, options) {
3382 var iti = new Iti(input, options);
3383 iti._init();
3384 input.setAttribute("data-intl-tel-input-id", iti.id);
3385 window.intlTelInputGlobals.instances[iti.id] = iti;
3386 return iti;
3387 };
3388 }();
3389 });
3390 },{}],27:[function(require,module,exports){
3391 /**
3392 * Exposing intl-tel-input as a component
3393 */
3394 module.exports = require("./build/js/intlTelInput");
3395
3396 },{"./build/js/intlTelInput":26}],28:[function(require,module,exports){
3397 (function (process){
3398 /**
3399 * Memize options object.
3400 *
3401 * @typedef MemizeOptions
3402 *
3403 * @property {number} [maxSize] Maximum size of the cache.
3404 */
3405
3406 /**
3407 * Internal cache entry.
3408 *
3409 * @typedef MemizeCacheNode
3410 *
3411 * @property {?MemizeCacheNode|undefined} [prev] Previous node.
3412 * @property {?MemizeCacheNode|undefined} [next] Next node.
3413 * @property {Array<*>} args Function arguments for cache
3414 * entry.
3415 * @property {*} val Function result.
3416 */
3417
3418 /**
3419 * Properties of the enhanced function for controlling cache.
3420 *
3421 * @typedef MemizeMemoizedFunction
3422 *
3423 * @property {()=>void} clear Clear the cache.
3424 */
3425
3426 /**
3427 * Accepts a function to be memoized, and returns a new memoized function, with
3428 * optional options.
3429 *
3430 * @template {Function} F
3431 *
3432 * @param {F} fn Function to memoize.
3433 * @param {MemizeOptions} [options] Options object.
3434 *
3435 * @return {F & MemizeMemoizedFunction} Memoized function.
3436 */
3437 function memize( fn, options ) {
3438 var size = 0;
3439
3440 /** @type {?MemizeCacheNode|undefined} */
3441 var head;
3442
3443 /** @type {?MemizeCacheNode|undefined} */
3444 var tail;
3445
3446 options = options || {};
3447
3448 function memoized( /* ...args */ ) {
3449 var node = head,
3450 len = arguments.length,
3451 args, i;
3452
3453 searchCache: while ( node ) {
3454 // Perform a shallow equality test to confirm that whether the node
3455 // under test is a candidate for the arguments passed. Two arrays
3456 // are shallowly equal if their length matches and each entry is
3457 // strictly equal between the two sets. Avoid abstracting to a
3458 // function which could incur an arguments leaking deoptimization.
3459
3460 // Check whether node arguments match arguments length
3461 if ( node.args.length !== arguments.length ) {
3462 node = node.next;
3463 continue;
3464 }
3465
3466 // Check whether node arguments match arguments values
3467 for ( i = 0; i < len; i++ ) {
3468 if ( node.args[ i ] !== arguments[ i ] ) {
3469 node = node.next;
3470 continue searchCache;
3471 }
3472 }
3473
3474 // At this point we can assume we've found a match
3475
3476 // Surface matched node to head if not already
3477 if ( node !== head ) {
3478 // As tail, shift to previous. Must only shift if not also
3479 // head, since if both head and tail, there is no previous.
3480 if ( node === tail ) {
3481 tail = node.prev;
3482 }
3483
3484 // Adjust siblings to point to each other. If node was tail,
3485 // this also handles new tail's empty `next` assignment.
3486 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
3487 if ( node.next ) {
3488 node.next.prev = node.prev;
3489 }
3490
3491 node.next = head;
3492 node.prev = null;
3493 /** @type {MemizeCacheNode} */ ( head ).prev = node;
3494 head = node;
3495 }
3496
3497 // Return immediately
3498 return node.val;
3499 }
3500
3501 // No cached value found. Continue to insertion phase:
3502
3503 // Create a copy of arguments (avoid leaking deoptimization)
3504 args = new Array( len );
3505 for ( i = 0; i < len; i++ ) {
3506 args[ i ] = arguments[ i ];
3507 }
3508
3509 node = {
3510 args: args,
3511
3512 // Generate the result from original function
3513 val: fn.apply( null, args ),
3514 };
3515
3516 // Don't need to check whether node is already head, since it would
3517 // have been returned above already if it was
3518
3519 // Shift existing head down list
3520 if ( head ) {
3521 head.prev = node;
3522 node.next = head;
3523 } else {
3524 // If no head, follows that there's no tail (at initial or reset)
3525 tail = node;
3526 }
3527
3528 // Trim tail if we're reached max size and are pending cache insertion
3529 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
3530 tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
3531 /** @type {MemizeCacheNode} */ ( tail ).next = null;
3532 } else {
3533 size++;
3534 }
3535
3536 head = node;
3537
3538 return node.val;
3539 }
3540
3541 memoized.clear = function() {
3542 head = null;
3543 tail = null;
3544 size = 0;
3545 };
3546
3547 if ( process.env.NODE_ENV === 'test' ) {
3548 // Cache is not exposed in the public API, but used in tests to ensure
3549 // expected list progression
3550 memoized.getCache = function() {
3551 return [ head, tail, size ];
3552 };
3553 }
3554
3555 // Ignore reason: There's not a clear solution to create an intersection of
3556 // the function with additional properties, where the goal is to retain the
3557 // function signature of the incoming argument and add control properties
3558 // on the return value.
3559
3560 // @ts-ignore
3561 return memoized;
3562 }
3563
3564 module.exports = memize;
3565
3566 }).call(this,require('_process'))
3567 },{"_process":29}],29:[function(require,module,exports){
3568 // shim for using process in browser
3569 var process = module.exports = {};
3570
3571 // cached from whatever global is present so that test runners that stub it
3572 // don't break things. But we need to wrap it in a try catch in case it is
3573 // wrapped in strict mode code which doesn't define any globals. It's inside a
3574 // function because try/catches deoptimize in certain engines.
3575
3576 var cachedSetTimeout;
3577 var cachedClearTimeout;
3578
3579 function defaultSetTimout() {
3580 throw new Error('setTimeout has not been defined');
3581 }
3582 function defaultClearTimeout () {
3583 throw new Error('clearTimeout has not been defined');
3584 }
3585 (function () {
3586 try {
3587 if (typeof setTimeout === 'function') {
3588 cachedSetTimeout = setTimeout;
3589 } else {
3590 cachedSetTimeout = defaultSetTimout;
3591 }
3592 } catch (e) {
3593 cachedSetTimeout = defaultSetTimout;
3594 }
3595 try {
3596 if (typeof clearTimeout === 'function') {
3597 cachedClearTimeout = clearTimeout;
3598 } else {
3599 cachedClearTimeout = defaultClearTimeout;
3600 }
3601 } catch (e) {
3602 cachedClearTimeout = defaultClearTimeout;
3603 }
3604 } ())
3605 function runTimeout(fun) {
3606 if (cachedSetTimeout === setTimeout) {
3607 //normal enviroments in sane situations
3608 return setTimeout(fun, 0);
3609 }
3610 // if setTimeout wasn't available but was latter defined
3611 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
3612 cachedSetTimeout = setTimeout;
3613 return setTimeout(fun, 0);
3614 }
3615 try {
3616 // when when somebody has screwed with setTimeout but no I.E. maddness
3617 return cachedSetTimeout(fun, 0);
3618 } catch(e){
3619 try {
3620 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
3621 return cachedSetTimeout.call(null, fun, 0);
3622 } catch(e){
3623 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
3624 return cachedSetTimeout.call(this, fun, 0);
3625 }
3626 }
3627
3628
3629 }
3630 function runClearTimeout(marker) {
3631 if (cachedClearTimeout === clearTimeout) {
3632 //normal enviroments in sane situations
3633 return clearTimeout(marker);
3634 }
3635 // if clearTimeout wasn't available but was latter defined
3636 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
3637 cachedClearTimeout = clearTimeout;
3638 return clearTimeout(marker);
3639 }
3640 try {
3641 // when when somebody has screwed with setTimeout but no I.E. maddness
3642 return cachedClearTimeout(marker);
3643 } catch (e){
3644 try {
3645 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
3646 return cachedClearTimeout.call(null, marker);
3647 } catch (e){
3648 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
3649 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
3650 return cachedClearTimeout.call(this, marker);
3651 }
3652 }
3653
3654
3655
3656 }
3657 var queue = [];
3658 var draining = false;
3659 var currentQueue;
3660 var queueIndex = -1;
3661
3662 function cleanUpNextTick() {
3663 if (!draining || !currentQueue) {
3664 return;
3665 }
3666 draining = false;
3667 if (currentQueue.length) {
3668 queue = currentQueue.concat(queue);
3669 } else {
3670 queueIndex = -1;
3671 }
3672 if (queue.length) {
3673 drainQueue();
3674 }
3675 }
3676
3677 function drainQueue() {
3678 if (draining) {
3679 return;
3680 }
3681 var timeout = runTimeout(cleanUpNextTick);
3682 draining = true;
3683
3684 var len = queue.length;
3685 while(len) {
3686 currentQueue = queue;
3687 queue = [];
3688 while (++queueIndex < len) {
3689 if (currentQueue) {
3690 currentQueue[queueIndex].run();
3691 }
3692 }
3693 queueIndex = -1;
3694 len = queue.length;
3695 }
3696 currentQueue = null;
3697 draining = false;
3698 runClearTimeout(timeout);
3699 }
3700
3701 process.nextTick = function (fun) {
3702 var args = new Array(arguments.length - 1);
3703 if (arguments.length > 1) {
3704 for (var i = 1; i < arguments.length; i++) {
3705 args[i - 1] = arguments[i];
3706 }
3707 }
3708 queue.push(new Item(fun, args));
3709 if (queue.length === 1 && !draining) {
3710 runTimeout(drainQueue);
3711 }
3712 };
3713
3714 // v8 likes predictible objects
3715 function Item(fun, array) {
3716 this.fun = fun;
3717 this.array = array;
3718 }
3719 Item.prototype.run = function () {
3720 this.fun.apply(null, this.array);
3721 };
3722 process.title = 'browser';
3723 process.browser = true;
3724 process.env = {};
3725 process.argv = [];
3726 process.version = ''; // empty string to avoid regexp issues
3727 process.versions = {};
3728
3729 function noop() {}
3730
3731 process.on = noop;
3732 process.addListener = noop;
3733 process.once = noop;
3734 process.off = noop;
3735 process.removeListener = noop;
3736 process.removeAllListeners = noop;
3737 process.emit = noop;
3738 process.prependListener = noop;
3739 process.prependOnceListener = noop;
3740
3741 process.listeners = function (name) { return [] }
3742
3743 process.binding = function (name) {
3744 throw new Error('process.binding is not supported');
3745 };
3746
3747 process.cwd = function () { return '/' };
3748 process.chdir = function (dir) {
3749 throw new Error('process.chdir is not supported');
3750 };
3751 process.umask = function() { return 0; };
3752
3753 },{}],30:[function(require,module,exports){
3754 'use strict';
3755
3756 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
3757
3758 var pluralForms = _interopDefault(require('@tannin/plural-forms'));
3759
3760 /**
3761 * Tannin constructor options.
3762 *
3763 * @typedef {Object} TanninOptions
3764 *
3765 * @property {string} [contextDelimiter] Joiner in string lookup with context.
3766 * @property {Function} [onMissingKey] Callback to invoke when key missing.
3767 */
3768
3769 /**
3770 * Domain metadata.
3771 *
3772 * @typedef {Object} TanninDomainMetadata
3773 *
3774 * @property {string} [domain] Domain name.
3775 * @property {string} [lang] Language code.
3776 * @property {(string|Function)} [plural_forms] Plural forms expression or
3777 * function evaluator.
3778 */
3779
3780 /**
3781 * Domain translation pair respectively representing the singular and plural
3782 * translation.
3783 *
3784 * @typedef {[string,string]} TanninTranslation
3785 */
3786
3787 /**
3788 * Locale data domain. The key is used as reference for lookup, the value an
3789 * array of two string entries respectively representing the singular and plural
3790 * translation.
3791 *
3792 * @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
3793 */
3794
3795 /**
3796 * Jed-formatted locale data.
3797 *
3798 * @see http://messageformat.github.io/Jed/
3799 *
3800 * @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
3801 */
3802
3803 /**
3804 * Default Tannin constructor options.
3805 *
3806 * @type {TanninOptions}
3807 */
3808 var DEFAULT_OPTIONS = {
3809 contextDelimiter: '\u0004',
3810 onMissingKey: null,
3811 };
3812
3813 /**
3814 * Given a specific locale data's config `plural_forms` value, returns the
3815 * expression.
3816 *
3817 * @example
3818 *
3819 * ```
3820 * getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
3821 * ```
3822 *
3823 * @param {string} pf Locale data plural forms.
3824 *
3825 * @return {string} Plural forms expression.
3826 */
3827 function getPluralExpression( pf ) {
3828 var parts, i, part;
3829
3830 parts = pf.split( ';' );
3831
3832 for ( i = 0; i < parts.length; i++ ) {
3833 part = parts[ i ].trim();
3834 if ( part.indexOf( 'plural=' ) === 0 ) {
3835 return part.substr( 7 );
3836 }
3837 }
3838 }
3839
3840 /**
3841 * Tannin constructor.
3842 *
3843 * @class
3844 *
3845 * @param {TanninLocaleData} data Jed-formatted locale data.
3846 * @param {TanninOptions} [options] Tannin options.
3847 */
3848 function Tannin( data, options ) {
3849 var key;
3850
3851 /**
3852 * Jed-formatted locale data.
3853 *
3854 * @name Tannin#data
3855 * @type {TanninLocaleData}
3856 */
3857 this.data = data;
3858
3859 /**
3860 * Plural forms function cache, keyed by plural forms string.
3861 *
3862 * @name Tannin#pluralForms
3863 * @type {Object<string,Function>}
3864 */
3865 this.pluralForms = {};
3866
3867 /**
3868 * Effective options for instance, including defaults.
3869 *
3870 * @name Tannin#options
3871 * @type {TanninOptions}
3872 */
3873 this.options = {};
3874
3875 for ( key in DEFAULT_OPTIONS ) {
3876 this.options[ key ] = options !== undefined && key in options
3877 ? options[ key ]
3878 : DEFAULT_OPTIONS[ key ];
3879 }
3880 }
3881
3882 /**
3883 * Returns the plural form index for the given domain and value.
3884 *
3885 * @param {string} domain Domain on which to calculate plural form.
3886 * @param {number} n Value for which plural form is to be calculated.
3887 *
3888 * @return {number} Plural form index.
3889 */
3890 Tannin.prototype.getPluralForm = function( domain, n ) {
3891 var getPluralForm = this.pluralForms[ domain ],
3892 config, plural, pf;
3893
3894 if ( ! getPluralForm ) {
3895 config = this.data[ domain ][ '' ];
3896
3897 pf = (
3898 config[ 'Plural-Forms' ] ||
3899 config[ 'plural-forms' ] ||
3900 // Ignore reason: As known, there's no way to document the empty
3901 // string property on a key to guarantee this as metadata.
3902 // @ts-ignore
3903 config.plural_forms
3904 );
3905
3906 if ( typeof pf !== 'function' ) {
3907 plural = getPluralExpression(
3908 config[ 'Plural-Forms' ] ||
3909 config[ 'plural-forms' ] ||
3910 // Ignore reason: As known, there's no way to document the empty
3911 // string property on a key to guarantee this as metadata.
3912 // @ts-ignore
3913 config.plural_forms
3914 );
3915
3916 pf = pluralForms( plural );
3917 }
3918
3919 getPluralForm = this.pluralForms[ domain ] = pf;
3920 }
3921
3922 return getPluralForm( n );
3923 };
3924
3925 /**
3926 * Translate a string.
3927 *
3928 * @param {string} domain Translation domain.
3929 * @param {string|void} context Context distinguishing terms of the same name.
3930 * @param {string} singular Primary key for translation lookup.
3931 * @param {string=} plural Fallback value used for non-zero plural
3932 * form index.
3933 * @param {number=} n Value to use in calculating plural form.
3934 *
3935 * @return {string} Translated string.
3936 */
3937 Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
3938 var index, key, entry;
3939
3940 if ( n === undefined ) {
3941 // Default to singular.
3942 index = 0;
3943 } else {
3944 // Find index by evaluating plural form for value.
3945 index = this.getPluralForm( domain, n );
3946 }
3947
3948 key = singular;
3949
3950 // If provided, context is prepended to key with delimiter.
3951 if ( context ) {
3952 key = context + this.options.contextDelimiter + singular;
3953 }
3954
3955 entry = this.data[ domain ][ key ];
3956
3957 // Verify not only that entry exists, but that the intended index is within
3958 // range and non-empty.
3959 if ( entry && entry[ index ] ) {
3960 return entry[ index ];
3961 }
3962
3963 if ( this.options.onMissingKey ) {
3964 this.options.onMissingKey( singular, domain );
3965 }
3966
3967 // If entry not found, fall back to singular vs. plural with zero index
3968 // representing the singular value.
3969 return index === 0 ? singular : plural;
3970 };
3971
3972 module.exports = Tannin;
3973
3974 },{"@tannin/plural-forms":19}]},{},[2]);
3975