PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.2
2.7.0 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 All 43 releases
sellkit / assets / dist / js / elementor-init.js

elementor-init.js in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.2.2, at assets/dist/js/elementor-init.js

2,688 lines 82.4 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"] = _default;
8
9 var _i18n = require("@wordpress/i18n");
10
11 /* eslint no-undef: 0 */
12 // Temporary turned off no undefined variable for localStorage
13 var $ = jQuery;
14 var wcCountries = JSON.parse(wc_country_select_params.countries);
15
16 function _default() {
17 var parent = $('#sellkit-checkout-multistep-inner-wrap');
18 var sidebar = $('.sellkit-checkout-right-column');
19 var first = $('.sellkit-multistep-checkout-first');
20 var second = $('.sellkit-multistep-checkout-second');
21 var third = $('.sellkit-multistep-checkout-third');
22 var breadcrumb = $('.sellkit-checkout-widget-breadcrumb-desktop, .sellkit-checkout-widget-breadcrumb-mobile');
23 $('.go-to-shipping').on('click', function () {
24 // Checks if required fields are filled.
25 var requiredFieldsError = checkRequiredFields();
26
27 if (true === requiredFieldsError) {
28 return;
29 }
30
31 secondStepHeader();
32 var secondTrigger = true;
33 first.hide();
34
35 if ($('.sellkit-one-page-shipping-methods').length > 0) {
36 second.show();
37 } else {
38 third.show();
39 secondTrigger = false;
40 }
41
42 if ($(window).width() > 600 && secondTrigger) {
43 sidebar.css('background-color', '#effdf5');
44 } //Fix Header & wrapper height.
45
46
47 parent.css('height', 'auto');
48 second.css('height', 'auto');
49 second.css('min-height', $('.sellkit-checkout-left-column').height());
50 $('.multistep-headers').css('height', 'auto'); // Manage Breadcrumb.
51
52 breadcrumb.find('.information').removeClass('current').addClass('blue-line');
53 breadcrumb.find('.shipping').addClass('current').removeClass('inactive');
54 });
55 $('.go-to-first').on('click', function () {
56 first.show();
57 third.hide();
58 second.hide();
59 parent.css('height', 'auto');
60 first.css('height', 'auto');
61 sidebar.css('background-color', '#ffffff'); // Manage Breadcrumb.
62
63 breadcrumb.find('.information').removeClass('blue-line').addClass('current');
64 breadcrumb.find('.shipping, .payment').removeClass('current').removeClass('blue-line').addClass('inactive');
65 });
66 $('.go-to-payment').on('click', function () {
67 // Checks if required fields are filled.
68 var requiredFieldsError = checkRequiredFields();
69
70 if (true === requiredFieldsError) {
71 return;
72 }
73
74 secondStepHeader();
75 second.hide();
76 first.hide();
77 third.show();
78 $('.sellkit-one-page-checkout-payment-heading').css('margin-top', '0px');
79 sidebar.css('background-color', '#ffffff'); //Fix Header & wrapper height.
80
81 parent.css('height', 'auto');
82 third.css('height', 'auto');
83 $('.multistep-headers').css('height', 'auto'); // Manage Breadcrumb.
84
85 breadcrumb.find('.shipping').addClass('blue-line').removeClass('current');
86 breadcrumb.find('.payment').addClass('current').removeClass('inactive');
87 });
88 $('.go-to-second , .go-to-second-header').on('click', function () {
89 // Checks if required fields are filled.
90 var requiredFieldsError = checkRequiredFields();
91
92 if (true === requiredFieldsError) {
93 return;
94 }
95
96 var secondTrigger = true;
97
98 if ($('.sellkit-one-page-shipping-methods').length > 0) {
99 second.show();
100 first.hide();
101 } else {
102 second.hide();
103 first.show();
104 secondTrigger = false;
105 }
106
107 third.hide();
108 parent.css('height', 'auto');
109 second.css('height', 'auto');
110 second.css('height', $('.sellkit-checkout-left-column').height());
111 $('.multistep-headers').css('height', 'auto');
112
113 if ($(window).width() > 600 && secondTrigger) {
114 sidebar.css('background-color', '#effdf5');
115 } // Manage Breadcrumb.
116
117
118 breadcrumb.find('.shipping').addClass('current').removeClass('blue-line');
119 breadcrumb.find('.payment').removeClass('current').addClass('inactive');
120 }); //Inject login wrapper & functionality.
121
122 emailProcess();
123 LoginProcess(); // Billing method toggle.
124
125 manageBillingMethod(); // Mobile summary.
126
127 mobileSummary(); // Breadcrumb click management.
128
129 breadcrumbLinks(); // Fix shipping & billing fields space issue.
130
131 fixFieldSpaceIssue(); // Fields focus.
132
133 organizeFieldsonLoad();
134 fieldFocus();
135 jQuery(document).ajaxComplete(function () {
136 // Run after ajax
137 sellkitCheckoutUpdateCartItem();
138 applyCoupon();
139 couponToggle();
140 }); //Run when page loads.
141
142 sellkitCheckoutUpdateCartItem(); // Apply coupon.
143
144 applyCoupon(); // Coupon toggle.
145
146 couponToggle(); // Postal code autocomplete.
147
148 sellkitPostalCodeAutocomplete(); // Klarma checkout integration.
149
150 sellkitKlarmaIntegration(); // Fix state change issue on load.
151
152 fixStateIssueOnLoad(); // Shipping & billing country & state update on change
153
154 fixClientCountryOnReload(); // Configure bundled products.
155
156 sellkitCheckoutConfigureBundleProducts(); // Order bump.
157
158 sellkitCheckoutOrderBump();
159 }
160
161 var emailProcess = function emailProcess() {
162 var emailField = $('#billing_email');
163 var searchIcon = $('.jupiter-checkout-widget-email-search');
164 var errorText = $('.sellkit-checkout-widget-email-error');
165 var emptyError = $('.sellkit-checkout-widget-email-empty');
166 var passwordWrap = $('.sellkit-checkout-widget-password-field');
167 var passwordField = passwordWrap.find('#register_pass');
168 var usernameWrap = $('.sellkit-checkout-widget-username-field');
169 var usernameField = usernameWrap.find('input');
170 var loginBtn = $('.login-wrapper');
171 var createBox = $('.create-desc');
172 var createCheck = $('#createaccount');
173 emailField.on('keyup', function () {
174 var _this = this;
175
176 setTimeout(function () {
177 var emailAddress = $(_this).val();
178
179 if (_.isEmpty(emailAddress)) {
180 emptyError.show().css('display', 'inline-block');
181 errorText.hide();
182 createBox.css('display', 'none');
183 passwordWrap.addClass('login_hidden_section');
184 usernameWrap.addClass('login_hidden_section');
185 loginBtn.addClass('login_hidden_section');
186 searchIcon.hide();
187 return;
188 }
189
190 var check = validateEmailAddress(emailAddress);
191 $('#createaccount').prop('checked', false);
192
193 if (false === check) {
194 errorText.show().css('display', 'inline-block');
195 emptyError.hide();
196 createBox.css('display', 'none');
197 passwordWrap.addClass('login_hidden_section');
198 usernameWrap.addClass('login_hidden_section');
199 loginBtn.addClass('login_hidden_section');
200 searchIcon.hide();
201 return;
202 }
203
204 emptyError.hide();
205 errorText.hide();
206 searchIcon.show().css('display', 'inline-block');
207 wp.ajax.post({
208 action: 'sellkit_checkout_ajax_handler',
209 sub_action: 'search_for_email',
210 email: emailAddress,
211 dataType: 'json',
212 nonce: sellkit_elementor.nonce
213 }).done(function () {
214 successResultEmailCheck();
215 }).fail(function () {
216 errorResultEmailCheck();
217 });
218 }, 500);
219 });
220 usernameField.on('keyup', function () {
221 var _this2 = this;
222
223 setTimeout(function () {
224 var userValue = $(_this2).val();
225 wp.ajax.post({
226 action: 'sellkit_checkout_ajax_handler',
227 sub_action: 'search_for_username',
228 user: userValue,
229 dataType: 'json',
230 nonce: sellkit_elementor.nonce
231 }).done(function () {
232 $('.sellkit-checkout-widget-username-error').hide();
233 }).fail(function () {
234 $('.sellkit-checkout-widget-username-error').show();
235 });
236 }, 500);
237 }); // If user is going to create account show password and username fields if exists.
238
239 createCheck.on('click', function () {
240 if ($(this).is(':checked')) {
241 if (passwordField.length > 0) {
242 passwordWrap.removeClass('login_hidden_section');
243 }
244
245 if (usernameField.length > 0) {
246 usernameWrap.removeClass('login_hidden_section');
247 }
248 } else {
249 usernameWrap.addClass('login_hidden_section');
250 passwordWrap.addClass('login_hidden_section');
251 }
252 });
253
254 var successResultEmailCheck = function successResultEmailCheck() {
255 createBox.css('display', 'none');
256 passwordWrap.removeClass('login_hidden_section');
257 usernameWrap.addClass('login_hidden_section');
258 loginBtn.removeClass('login_hidden_section');
259 searchIcon.hide();
260 };
261
262 var errorResultEmailCheck = function errorResultEmailCheck() {
263 createBox.css('display', 'flex');
264 passwordWrap.addClass('login_hidden_section');
265 usernameWrap.addClass('login_hidden_section');
266 loginBtn.addClass('login_hidden_section');
267 searchIcon.hide();
268 };
269 };
270
271 var validateEmailAddress = function validateEmailAddress(emailAddress) {
272 var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
273 return pattern.test(emailAddress);
274 };
275
276 var LoginProcess = function LoginProcess() {
277 var submitBtn = $('.login-submit');
278 var email = $('.login-mail');
279 var pass = $('.login-pass');
280 var result = $('.login-result');
281 submitBtn.on('click', function () {
282 if ('' === email.val() || '' === pass.val()) {
283 result.text((0, _i18n.__)('Both Field required.', 'sellkit')).css({
284 color: 'red'
285 });
286 return;
287 }
288
289 wp.ajax.post({
290 beforeSend: function beforeSend() {
291 $('.login-submit').css('opacity', '0.5');
292 },
293 action: 'sellkit_checkout_ajax_handler',
294 sub_action: 'auth_user',
295 email: email.val(),
296 pass: pass.val(),
297 nonce: sellkit_elementor.nonce
298 }).done(function () {
299 location.reload();
300 }).fail(function (response) {
301 $('.login-submit').css('opacity', '1');
302 $('.login-result').html(response).css({
303 color: 'red'
304 });
305 });
306 });
307 };
308
309 var secondStepHeader = function secondStepHeader() {
310 var email = $('#billing_email');
311 $('.multistep-headers > .info-a > div > .mail').text(email.val());
312 var countryValue = $('#shipping_country option:selected').text();
313 var state = $('#sellkit-shipping_state');
314 var postcode = $('#shipping_postcode');
315 var city = $('#shipping_city');
316 var addressA = $('#shipping_address_1');
317 var addressB = $('#shipping_address_2');
318 var finalAddress = postcode.val() ? ', ' + postcode.val() : '';
319 finalAddress += addressB.val() ? ', ' + addressB.val() : '';
320 finalAddress += addressA.val() ? ', ' + addressA.val() : '';
321 finalAddress += city.val() ? ', ' + city.val() : '';
322 finalAddress += state.val() ? ', ' + state.val() : '';
323 finalAddress += countryValue && !countryValue.includes('/') ? ', ' + countryValue : '';
324
325 if (',' === finalAddress.charAt(0)) {
326 finalAddress = finalAddress.substring(1);
327 }
328
329 $('.multistep-headers > .info-b > div > .address').text(finalAddress);
330 var method = $('#shipping_method').find('input[type=radio]:checked');
331 var methodTxt = method.siblings('label').text();
332 $('.multistep-headers > .info-c > div > .method').text(methodTxt);
333 };
334
335 var manageBillingMethod = function manageBillingMethod() {
336 var billingWrap = $('.sellkit-one-page-checkout-billing');
337 var methodA = billingWrap.find('.method-a');
338 var methodB = billingWrap.find('.method-b'); // Get shipping values.
339
340 var name = $('#shipping_first_name');
341 var last = $('#shipping_last_name');
342 var addressA = $('#shipping_address_1');
343 var addressB = $('#shipping_address_2');
344 var country = $('#shipping_country');
345 var state = $('#sellkit-shipping_state');
346 var postcode = $('#shipping_postcode');
347 var city = $('#shipping_city');
348 methodA.on('click', function () {
349 billingWrap.find('.woocommerce-billing-fields__field-wrapper').hide();
350 $('#billing_first_name').val(name.val());
351 $('#billing_last_name').val(last.val());
352 $('#billing_address_1').val(addressA.val());
353 $('#billing_address_2').val(addressB.val());
354 $('#billing_country').val(country.val()).trigger('change');
355 $('#sellkit-billing_state').val(state.val()).trigger('change');
356 $('#billing_postcode').val(postcode.val());
357 $('#billing_city').val(city.val());
358 });
359 methodB.on('click', function () {
360 $('.inner_wrapper').css('height', 'auto');
361 billingWrap.find('.woocommerce-billing-fields__field-wrapper').show();
362 });
363 };
364
365 var mobileSummary = function mobileSummary() {
366 if ($(window).width() < 600) {
367 $('#order_review').addClass('sellkit-mobile-multistep-order-summary');
368 }
369
370 var toggleBtn = $('.summary_toggle > .title, .summary_toggle > i, .summary_toggle > .icon');
371 var wrap = $('.summary_toggle');
372 toggleBtn.on('click', function () {
373 $('#order_review').toggle();
374
375 if ('Hide order summary' === toggleBtn.text()) {
376 wrap.find('.title').text((0, _i18n.__)('Show order summary', 'sellkit'));
377 wrap.find('i').addClass('fa-chevron-down').removeClass('fa-chevron-up');
378 wrap.css('border-bottom-width', '0px');
379 } else {
380 wrap.find('.title').text((0, _i18n.__)('Hide order summary', 'sellkit'));
381 wrap.find('i').addClass('fa-chevron-up').removeClass('fa-chevron-down');
382 wrap.css('border-bottom-width', '1px');
383 }
384
385 var parent = $('#sellkit-checkout-multistep-inner-wrap');
386 parent.css('height', 'auto');
387 });
388 };
389
390 var fieldFocus = function fieldFocus() {
391 var $fields = $('.sellkit-checkout-local-fields').find('input, select, hidden, textarea, #sellkit-billing_state ,#sellkit-shipping_state, .validate-email');
392 $fields.each(function () {
393 var _this3 = this;
394
395 var miniTitle = $(this).parent().parent().parent().find('.mini-title');
396 var $thisValue = $(this).val(); // On load.
397
398 if (!_.isEmpty($thisValue)) {
399 $(this).addClass('filled').removeClass('empty');
400 miniTitle.css({
401 display: 'flex'
402 });
403 } // On change/focusOut
404
405
406 $(this).on('change input focusout', function (e) {
407 var changedValue = $(_this3).val();
408
409 if (changedValue || $(_this3).find('option').length) {
410 $(_this3).addClass('filled');
411 $(_this3).removeClass('empty');
412 $(_this3).parents('.sellkit-widget-checkout-fields').find('.mini-title').css('display', 'flex');
413 } else {
414 $(_this3).addClass('empty');
415 $(_this3).removeClass('filled');
416 $(_this3).parents('.sellkit-widget-checkout-fields').find('.mini-title').hide();
417 } // On focusout validate fields.
418
419
420 if ('focusout' === e.type) {
421 FieldsMiniTitles($(_this3), 'focusout');
422 var parent = $(_this3).parent().parent().parent(); // Required validation. return if required field rule is not followed.
423
424 if (parent.hasClass('validate-required')) {
425 if ('INPUT' === _this3.nodeName && 'checkbox' === $(_this3).attr('type')) {
426 if (!_this3.checked) {
427 parent.find('.sellkit-required-validation').css('display', 'inline-flex');
428 return;
429 }
430 }
431
432 if (_.isEmpty($(_this3).val())) {
433 parent.find('.sellkit-required-validation').css('display', 'inline-flex');
434 return;
435 }
436
437 parent.find('.sellkit-required-validation').css('display', 'none');
438 } // Required validation of this field if exists, passed successfully. now postcode validation.
439
440
441 if (parent.hasClass('sellkit-checkout-fields-validation-postcode')) {
442 var postcodeVal = $(_this3).val();
443
444 if (_.isEmpty(postcodeVal)) {
445 return;
446 } // Check field type to get related country value. we can't validate without country code.
447
448
449 var postcodeName = $(_this3).attr('name');
450 var postcodeCountry = $('#billing_country');
451
452 if (postcodeName.includes('shipping')) {
453 postcodeCountry = $('#shipping_country');
454 } // Keep validating only if country field is present.
455
456
457 if (!postcodeCountry.length) {
458 return;
459 }
460
461 var countryCode = postcodeCountry.val();
462
463 if (_.isEmpty(countryCode)) {
464 parent.find('.sellkit-checkout-field-global-errors').show().text((0, _i18n.__)('Please select a country.', 'sellkit'));
465 return;
466 } else {
467 // eslint-disable-line
468 parent.find('.sellkit-checkout-field-global-errors').hide().text('');
469 }
470
471 parent.find('.sellkit-checkout-field-global-errors').hide().text('');
472 postcodeValidation(postcodeVal, countryCode, $(_this3));
473 } // Phone validation using woocommerce way.
474
475
476 if (parent.hasClass('sellkit-checkout-fields-validation-phone')) {
477 var phone = $(_this3).val();
478
479 if (_.isEmpty(phone)) {
480 return;
481 }
482
483 phoneNumberValidation(phone, $(_this3));
484 }
485 }
486
487 if ('change' === e.type && ('billing_country' === $(_this3).attr('id') || 'shipping_country' === $(_this3).attr('id'))) {
488 var _countryCode = $(_this3).val();
489
490 var states = wcCountries[_countryCode];
491 var state = 'sellkit-shipping_state';
492
493 if ('billing_country' === $(_this3).attr('id')) {
494 state = 'sellkit-billing_state';
495 }
496
497 var stateField = document.getElementById(state);
498 $(stateField).empty();
499
500 for (var keys in states) {
501 var option = document.createElement('option');
502 option.value = keys;
503 option.innerHTML = states[keys];
504 stateField.appendChild(option);
505 }
506 }
507 });
508 });
509 };
510
511 var breadcrumbLinks = function breadcrumbLinks() {
512 var $parent = $('.sellkit-checkout-widget-breadcrumb-mobile, .sellkit-checkout-widget-breadcrumb-desktop');
513 var detector = $('.sellkit-multistep-checkout-first');
514 $parent.find('.information').on('click', function () {
515 $('.go-to-first').click();
516 });
517 $parent.find('.shipping').on('click', function () {
518 var display = detector.css('display');
519
520 if ('none' === display) {
521 $('.go-to-second').click();
522 } else {
523 $('.go-to-shipping').click();
524 }
525 });
526 $parent.find('.payment').on('click', function () {
527 $('.go-to-payment').click();
528 $('.information').removeClass('current').addClass('inactive, blue-line');
529 });
530 };
531
532 var fixFieldSpaceIssue = function fixFieldSpaceIssue() {
533 $(function () {
534 var shippingFields = $('#customer_details .sellkit-widget-checkout-fields');
535 shippingFields.each(function (index) {
536 if ($(shippingFields[index + 1]).length) {
537 var next = $(shippingFields[index + 1]).offset().top;
538 var current = $(shippingFields[index]).offset().top;
539
540 if (next > current) {
541 $(shippingFields[index]).addClass('sellkit-checkout-excluded-wrapper-fields');
542 }
543 } else {
544 $(shippingFields[index]).addClass('sellkit-checkout-excluded-wrapper-fields');
545 }
546 });
547 });
548 };
549
550 var organizeFieldsonLoad = function organizeFieldsonLoad() {
551 $(function () {
552 var fields = $('.sellkit-widget-checkout-fields').find('input, select, textarea');
553 fields.each(function () {
554 var tag = this.nodeName;
555
556 if ('SELECT' === tag) {
557 $(this).parent().parent().parent().addClass('sellkit-checkout-field-select');
558 }
559
560 FieldsMiniTitles($(this), 'load');
561 });
562 });
563 $(document).on('mousemove change', function (e) {
564 var fields = $('.sellkit-widget-checkout-fields').find('input, select, textarea');
565 fields.each(function () {
566 var tag = this.nodeName;
567
568 if ('SELECT' === tag) {
569 $(this).parent().parent().parent().addClass('sellkit-checkout-field-select');
570 }
571
572 FieldsMiniTitles($(this), e.type);
573 });
574 });
575 };
576
577 var FieldsMiniTitles = function FieldsMiniTitles(field, event) {
578 if (field.attr('multiple')) {
579 field.addClass('filled');
580 field.removeClass('empty');
581 field.parents('.sellkit-widget-checkout-fields').find('.mini-title').css('display', 'flex');
582 return;
583 }
584
585 if (_.isEmpty(field.val())) {
586 field.addClass('empty');
587 field.removeClass('filled');
588 field.parents('.sellkit-widget-checkout-fields').find('.mini-title').css('display', 'none');
589 } else {
590 field.addClass('filled');
591 field.removeClass('empty');
592 field.parents('.sellkit-widget-checkout-fields').find('.mini-title').css('display', 'flex');
593 } // Hide wrapper if field is hidden
594
595
596 if ('hidden' === field.attr('type')) {
597 field.parents('.sellkit-widget-checkout-fields').addClass('sellkit-hide-completely');
598 }
599
600 if ('change' !== event) {
601 return;
602 } // Hide Billing state wrapper when these fields are hidden.
603
604
605 if ('billing_country' === field.attr('id')) {
606 var $state = document.getElementById('sellkit-billing_state');
607
608 if ('SELECT' === $state.nodeName && $('#sellkit-billing_state option').length < 1) {
609 var stateField = $('#sellkit-billing_state');
610 var parent = stateField.parent().parent().parent();
611 parent.removeClass('sellkit-checkout-field-select');
612 var placeholder = stateField.attr('placeholder');
613 var stateInput = document.createElement('input');
614 stateInput.setAttribute('type', 'text');
615 stateInput.setAttribute('id', 'sellkit-billing_state');
616 stateInput.setAttribute('name', 'billing_state');
617 stateInput.setAttribute('placeholder', placeholder); // Replace select field with text.
618
619 stateField.remove();
620 parent.find('.woocommerce-input-wrapper').append(stateInput);
621 }
622
623 var countryCode = field.val();
624 var states = wcCountries[countryCode];
625
626 if ('INPUT' === $state.nodeName && !_.isEmpty(states)) {
627 var _stateField = $('#sellkit-billing_state');
628
629 var _placeholder = _stateField.attr('placeholder');
630
631 var _parent = _stateField.parent().parent().parent();
632
633 _parent.addClass('sellkit-checkout-field-select');
634
635 if (_.isUndefined(_placeholder) || _.isEmpty(_placeholder)) {
636 _placeholder = (0, _i18n.__)('State', 'sellkit');
637 } // Replace text field with select field.
638
639
640 _stateField.remove();
641
642 var stateSelect = document.createElement('select');
643 stateSelect.setAttribute('name', 'billing_state');
644 stateSelect.setAttribute('id', 'sellkit-billing_state');
645 stateSelect.setAttribute('placeholder', _placeholder);
646 stateSelect.addEventListener('change', function () {
647 sellkitSetAddressDetails();
648 });
649
650 for (var keys in states) {
651 var option = document.createElement('option');
652 option.value = keys;
653 option.innerHTML = states[keys];
654 stateSelect.appendChild(option);
655 }
656
657 _parent.find('.woocommerce-input-wrapper').append(stateSelect);
658 }
659 } // Remove select icon when field is text for the shipping/billing state fields.
660
661
662 if ('shipping_country' === field.attr('id')) {
663 var _$state = document.getElementById('sellkit-shipping_state');
664
665 if ('SELECT' === _$state.nodeName && $('#sellkit-shipping_state option').length < 1) {
666 var _stateField2 = $('#sellkit-shipping_state');
667
668 var _parent2 = _stateField2.parent().parent().parent();
669
670 _parent2.removeClass('sellkit-checkout-field-select');
671
672 var _placeholder2 = _stateField2.attr('placeholder');
673
674 var _stateInput = document.createElement('input');
675
676 _stateInput.setAttribute('type', 'text');
677
678 _stateInput.setAttribute('id', 'sellkit-shipping_state');
679
680 _stateInput.setAttribute('name', 'shipping_state');
681
682 _stateInput.setAttribute('placeholder', _placeholder2); // Replace select field with text.
683
684
685 _stateField2.remove();
686
687 _parent2.find('.woocommerce-input-wrapper').append(_stateInput);
688 }
689
690 var _countryCode2 = field.val();
691
692 var _states = wcCountries[_countryCode2];
693
694 if ('INPUT' === _$state.nodeName && !_.isEmpty(_states)) {
695 var _stateField3 = $('#sellkit-shipping_state');
696
697 var _placeholder3 = _stateField3.attr('placeholder');
698
699 var _parent3 = _stateField3.parent().parent().parent();
700
701 _parent3.addClass('sellkit-checkout-field-select');
702
703 if (_.isUndefined(_placeholder3) || _.isEmpty(_placeholder3)) {
704 _placeholder3 = (0, _i18n.__)('State', 'sellkit');
705 } // Replace text field with select field.
706
707
708 _stateField3.remove();
709
710 var _stateSelect = document.createElement('select');
711
712 _stateSelect.setAttribute('name', 'shipping_state');
713
714 _stateSelect.setAttribute('id', 'sellkit-shipping_state');
715
716 _stateSelect.setAttribute('placeholder', _placeholder3);
717
718 _stateSelect.addEventListener('change', function () {
719 sellkitSetAddressDetails();
720 });
721
722 for (var _keys in _states) {
723 var _option = document.createElement('option');
724
725 _option.value = _keys;
726 _option.innerHTML = _states[_keys];
727
728 _stateSelect.appendChild(_option);
729 }
730
731 _parent3.find('.woocommerce-input-wrapper').append(_stateSelect);
732 }
733 }
734 };
735
736 var sellkitCheckoutUpdateCartItem = function sellkitCheckoutUpdateCartItem() {
737 $('.sellkit-one-page-checkout-product-qty').off('change').on('change', function () {
738 $(this).attr('readonly', true);
739 wp.ajax.post({
740 action: 'sellkit_checkout_ajax_handler',
741 sub_action: 'change_cart_item_qty',
742 qty: $(this).val(),
743 id: $(this).attr('data-id'),
744 mode: 'edit',
745 nonce: sellkit_elementor.nonce
746 }).always(function () {
747 $(document.body).trigger('update_checkout');
748 $('.sellkit-one-page-checkout-product-qty').attr('readonly', false);
749 });
750 });
751 $('.sellkit-one-page-pay-method').on('click', function () {
752 $('.sellkit_payment_box').hide();
753 $(this).parent().parent().next().show();
754 });
755 var count = $('.sellkit-checkout-widget-order-summary-tfoot').children().length;
756
757 if (count <= 3) {
758 $('.cart-subtotal td').css('padding-bottom', '8px');
759 $('.cart-subtotal th').css('padding-bottom', '8px');
760 }
761 };
762
763 var applyCoupon = function applyCoupon() {
764 $('.sellkit-apply-coupon').off('click').on('click', function () {
765 wp.ajax.post({
766 beforeSend: function beforeSend() {
767 $('.jx-apply-coupon').css('opacity', 0.5);
768 },
769 action: 'sellkit_checkout_ajax_handler',
770 sub_action: 'apply_coupon',
771 code: jQuery('.sellkit-custom-coupon-form').find('.jx-coupon').val(),
772 nonce: sellkit_elementor.nonce
773 }).done(function () {
774 $(document.body).trigger('update_checkout');
775 $('.jx-apply-coupon').css('opacity', 1);
776 }).fail(function () {
777 $('.jx-apply-coupon').css('opacity', 1);
778 });
779 });
780 };
781
782 var couponToggle = function couponToggle() {
783 if ($('.sellkit-coupon-toggle').length) {
784 $('.sellkit-custom-coupon-form').css('display', 'none');
785 }
786
787 $('.sellkit-coupon-toggle').off('click').on('click', function () {
788 var direction = 'row';
789 var status = $('.sellkit-custom-coupon-form').css('display');
790 var displayValue = '';
791
792 if ($(window).width() < 600) {
793 direction = 'column';
794 }
795
796 if ('none' === status) {
797 displayValue = 'inline-flex';
798 } else {
799 displayValue = 'none';
800 }
801
802 $('.sellkit-custom-coupon-form').css({
803 display: displayValue,
804 flexDirection: direction
805 });
806 });
807 };
808
809 var postcodeValidation = function postcodeValidation(postcode, country, element) {
810 var parentElement = element.attr('id');
811 wp.ajax.post({
812 action: 'sellkit_checkout_ajax_handler',
813 sub_action: 'validate_postcode',
814 post_code: postcode,
815 country_code: country,
816 parent: parentElement,
817 nonce: sellkit_elementor.nonce
818 }).done(function (response) {
819 var field = $('#' + response);
820 var parent = field.parent().parent().parent();
821 parent.find('.sellkit-checkout-field-global-errors').hide().text('');
822 }).fail(function (response) {
823 var field = $('#' + response);
824 var parent = field.parent().parent().parent();
825 parent.find('.sellkit-checkout-field-global-errors').show().text((0, _i18n.__)('Postcode is not valid.', 'sellkit'));
826 });
827 };
828
829 var phoneNumberValidation = function phoneNumberValidation(phone, element) {
830 var parentElement = element.attr('id');
831 wp.ajax.post({
832 action: 'sellkit_checkout_ajax_handler',
833 sub_action: 'validate_phone_number',
834 phone_number: phone,
835 parent: parentElement,
836 nonce: sellkit_elementor.nonce
837 }).done(function (response) {
838 var field = $('#' + response);
839 var parent = field.parent().parent().parent();
840 parent.find('.sellkit-checkout-field-global-errors').hide().text('');
841 }).fail(function (response) {
842 var field = $('#' + response);
843 var parent = field.parent().parent().parent();
844 parent.find('.sellkit-checkout-field-global-errors').show().text((0, _i18n.__)('Phone number is not valid.', 'sellkit'));
845 });
846 };
847
848 var sellkitPostalCodeAutocomplete = function sellkitPostalCodeAutocomplete() {
849 $('.post_code_autocomplete').find('input').on('paste focusout', function () {
850 var postcode = $(this).val();
851 var country = $('#shipping_country').val();
852 var state = $('#sellkit-shipping_state');
853 var city = $('#shipping_city');
854 var parent = $(this).parent().parent().parent();
855
856 if ('billing_postcode' === $(this).attr('id')) {
857 country = $('#billing_country').val();
858 state = $('#sellkit-billing_state');
859 city = $('#billing_city');
860 }
861
862 if (_.isEmpty(postcode) || _.isEmpty(country)) {
863 return;
864 }
865
866 wp.ajax.post({
867 action: 'sellkit_checkout_ajax_handler',
868 sub_action: 'sellkit_state_lookup_by_postcode',
869 country_value: country,
870 postcode_value: postcode,
871 nonce: sellkit_elementor.nonce
872 }).done(function (response) {
873 var body = response.body;
874 body = JSON.parse(body);
875 var placeCity = body.places[0]['place name'];
876 var placeState = body.places[0]['state abbreviation'];
877 setFields(placeCity, placeState);
878 }).fail(function (response) {
879 setError(response);
880 });
881
882 var setFields = function setFields(placeCity, placeState) {
883 state.val(placeState).addClass('filled');
884 city.val(placeCity).addClass('filled');
885 };
886
887 var setError = function setError(response) {
888 parent.find('.sellkit-checkout-field-global-errors').text(response);
889 };
890 });
891 };
892
893 var sellkitKlarmaIntegration = function sellkitKlarmaIntegration() {
894 $(document).ready(function () {
895 $('#sellkit-klarna-pay-button').on('click', function () {
896 $('#payment_method_kco').trigger('click');
897 });
898 });
899 }; // This also is supposed to update shipping method.
900
901
902 var fixClientCountryOnReload = function fixClientCountryOnReload() {
903 $('#shipping_country, #billing_country, #sellkit-shipping_state, #sellkit-billing_state').on('change', function () {
904 sellkitSetAddressDetails();
905 });
906 };
907
908 var sellkitSetAddressDetails = function sellkitSetAddressDetails() {
909 wp.ajax.post({
910 action: 'sellkit_checkout_ajax_handler',
911 sub_action: 'set_customer_details_ajax',
912 country: document.querySelector('#billing_country') ? document.getElementById('billing_country').value : '',
913 state: document.querySelector('#sellkit-billing_state') ? document.getElementById('sellkit-billing_state').value : '',
914 shipping_country: document.querySelector('#shipping_country') ? document.getElementById('shipping_country').value : '',
915 shipping_state: document.querySelector('#sellkit-shipping_state') ? document.getElementById('sellkit-shipping_state').value : '',
916 nonce: sellkit_elementor.nonce
917 }).always(function () {
918 $(document.body).trigger('update_checkout');
919 });
920 };
921
922 var fixStateIssueOnLoad = function fixStateIssueOnLoad() {
923 var primaryValue = '';
924
925 if (document.querySelector('#shipping_country')) {
926 primaryValue = $('#shipping_country').val();
927 $('#shipping_country').val($('#shipping_country option:eq(1)').val());
928 $('#shipping_country').val(primaryValue).trigger('change');
929 }
930
931 if (document.querySelector('#billing_country')) {
932 primaryValue = $('#billing_country').val();
933 $('#billing_country').val($('#billing_country option:eq(1)').val());
934 $('#billing_country').val(primaryValue).trigger('change');
935 }
936 };
937
938 var sellkitCheckoutConfigureBundleProducts = function sellkitCheckoutConfigureBundleProducts() {
939 var radioProducts = $('.sellkit-checkout-bundle-item');
940 radioProducts.off('change').on('change', function () {
941 $('.sellkit-checkout-bump-order-products').each(function () {
942 if ($(this).is(':checked')) {
943 $(this).trigger('click');
944 }
945 });
946 var product = $(this).val();
947 var quantity = $(this).parent().parent().find('.sellkit-checkout-single-bundle-item-quantity').val();
948 wp.ajax.post({
949 action: 'sellkit_checkout_ajax_handler',
950 sub_action: 'sellkit_checkout_modify_cart_by_bundle_products',
951 id: product,
952 qty: quantity,
953 type: 'radio',
954 nonce: sellkit_elementor.nonce
955 }).always(function () {
956 $(document.body).trigger('update_checkout');
957 });
958 });
959 };
960
961 var sellkitCheckoutOrderBump = function sellkitCheckoutOrderBump() {
962 $('.sellkit-checkout-bump-order-products').on('click', function () {
963 var subAction;
964
965 if ($(this).is(':checked')) {
966 subAction = 'add';
967 } else {
968 subAction = 'remove';
969 }
970
971 wp.ajax.post({
972 action: 'sellkit_checkout_ajax_handler',
973 sub_action: 'change_cart_item_qty',
974 qty: $(this).attr('data-qty'),
975 id: $(this).val(),
976 mode: subAction,
977 nonce: sellkit_elementor.nonce
978 }).always(function () {
979 $(document.body).trigger('update_checkout');
980 });
981 });
982 };
983
984 var checkRequiredFields = function checkRequiredFields() {
985 var fields = document.querySelectorAll('#sellkit-checkout-widget-shipping-fields > .validate-required');
986 var error = false;
987
988 if (fields.length < 1) {
989 return error;
990 }
991
992 fields.forEach(function (item) {
993 var target = $(item).find('input, select, textarea').val();
994
995 if ('' === target) {
996 error = true;
997 $(item).find('.sellkit-required-validation').css('display', 'inline-flex');
998 }
999 });
1000 return error;
1001 };
1002
1003 },{"@wordpress/i18n":12}],2:[function(require,module,exports){
1004 "use strict";
1005
1006 (function ($) {
1007 var SellkitFrontend = function SellkitFrontend() {
1008 var widgets = {
1009 'sellkit-product-images.default': require('./product-images')["default"],
1010 'sellkit-checkout.default': require('./checkout')["default"]
1011 };
1012
1013 function elementorInit() {
1014 for (var widget in widgets) {
1015 elementorFrontend.hooks.addAction("frontend/element_ready/".concat(widget), widgets[widget]);
1016 }
1017 }
1018
1019 this.init = function () {
1020 $(window).on('elementor/frontend/init', elementorInit);
1021 };
1022
1023 this.init();
1024 };
1025
1026 window.sellkitFrontend = new SellkitFrontend();
1027 })(jQuery);
1028
1029 },{"./checkout":1,"./product-images":3}],3:[function(require,module,exports){
1030 "use strict";
1031
1032 Object.defineProperty(exports, "__esModule", {
1033 value: true
1034 });
1035 exports["default"] = _default;
1036 var ProductImages = elementorModules.frontend.handlers.Base.extend({
1037 onInit: function onInit() {
1038 elementorModules.frontend.handlers.Base.prototype.onInit.apply(this, arguments);
1039
1040 if (document.body.classList.contains('elementor-editor-active')) {
1041 this.$element.find('.woocommerce-product-gallery').wc_product_gallery();
1042 }
1043
1044 var self = this;
1045
1046 if (typeof window.elementor === 'undefined') {
1047 return;
1048 }
1049
1050 window.elementor.channels.editor.on('change', function (controlView) {
1051 self.onElementChange(controlView.model.get('name'), controlView);
1052 });
1053 this.handleThumbnailBorderRadius(this.getElementSettings('thumbnail_border_radius'));
1054 },
1055 onElementChange: function onElementChange(propertyName, controlView) {
1056 if ('thumbnail_border_radius' === propertyName) {
1057 var borderRadius = controlView.container.settings.get('thumbnail_border_radius');
1058 this.handleThumbnailBorderRadius(borderRadius);
1059 }
1060 },
1061 handleThumbnailBorderRadius: function handleThumbnailBorderRadius(borderRadius) {
1062 var unit = borderRadius.unit;
1063 this.$element.find('.flex-control-nav li').css({
1064 'border-radius': borderRadius.top + unit + ' ' + borderRadius.right + unit + ' ' + borderRadius.bottom + unit + ' ' + borderRadius.left + unit
1065 });
1066 },
1067 bindEvents: function bindEvents() {
1068 this.$element.find('.woocommerce-product-gallery__image a').on('click', function (e) {
1069 e.stopImmediatePropagation();
1070 e.preventDefault();
1071 });
1072 }
1073 });
1074
1075 function _default($scope) {
1076 new ProductImages({
1077 $element: $scope
1078 });
1079 }
1080
1081 },{}],4:[function(require,module,exports){
1082 function _defineProperty(obj, key, value) {
1083 if (key in obj) {
1084 Object.defineProperty(obj, key, {
1085 value: value,
1086 enumerable: true,
1087 configurable: true,
1088 writable: true
1089 });
1090 } else {
1091 obj[key] = value;
1092 }
1093
1094 return obj;
1095 }
1096
1097 module.exports = _defineProperty;
1098 },{}],5:[function(require,module,exports){
1099 function _interopRequireDefault(obj) {
1100 return obj && obj.__esModule ? obj : {
1101 "default": obj
1102 };
1103 }
1104
1105 module.exports = _interopRequireDefault;
1106 },{}],6:[function(require,module,exports){
1107 'use strict';
1108
1109 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
1110
1111 var postfix = _interopDefault(require('@tannin/postfix'));
1112 var evaluate = _interopDefault(require('@tannin/evaluate'));
1113
1114 /**
1115 * Given a C expression, returns a function which can be called to evaluate its
1116 * result.
1117 *
1118 * @example
1119 *
1120 * ```js
1121 * import compile from '@tannin/compile';
1122 *
1123 * const evaluate = compile( 'n > 1' );
1124 *
1125 * evaluate( { n: 2 } );
1126 * // ⇒ true
1127 * ```
1128 *
1129 * @param {string} expression C expression.
1130 *
1131 * @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator.
1132 */
1133 function compile( expression ) {
1134 var terms = postfix( expression );
1135
1136 return function( variables ) {
1137 return evaluate( terms, variables );
1138 };
1139 }
1140
1141 module.exports = compile;
1142
1143 },{"@tannin/evaluate":7,"@tannin/postfix":9}],7:[function(require,module,exports){
1144 'use strict';
1145
1146 /**
1147 * Operator callback functions.
1148 *
1149 * @type {Object}
1150 */
1151 var OPERATORS = {
1152 '!': function( a ) {
1153 return ! a;
1154 },
1155 '*': function( a, b ) {
1156 return a * b;
1157 },
1158 '/': function( a, b ) {
1159 return a / b;
1160 },
1161 '%': function( a, b ) {
1162 return a % b;
1163 },
1164 '+': function( a, b ) {
1165 return a + b;
1166 },
1167 '-': function( a, b ) {
1168 return a - b;
1169 },
1170 '<': function( a, b ) {
1171 return a < b;
1172 },
1173 '<=': function( a, b ) {
1174 return a <= b;
1175 },
1176 '>': function( a, b ) {
1177 return a > b;
1178 },
1179 '>=': function( a, b ) {
1180 return a >= b;
1181 },
1182 '==': function( a, b ) {
1183 return a === b;
1184 },
1185 '!=': function( a, b ) {
1186 return a !== b;
1187 },
1188 '&&': function( a, b ) {
1189 return a && b;
1190 },
1191 '||': function( a, b ) {
1192 return a || b;
1193 },
1194 '?:': function( a, b, c ) {
1195 if ( a ) {
1196 throw b;
1197 }
1198
1199 return c;
1200 },
1201 };
1202
1203 /**
1204 * Given an array of postfix terms and operand variables, returns the result of
1205 * the postfix evaluation.
1206 *
1207 * @example
1208 *
1209 * ```js
1210 * import evaluate from '@tannin/evaluate';
1211 *
1212 * // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +'
1213 * const terms = [ '3', '4', '5', '*', '6', '/', '+' ];
1214 *
1215 * evaluate( terms, {} );
1216 * // ⇒ 6.333333333333334
1217 * ```
1218 *
1219 * @param {string[]} postfix Postfix terms.
1220 * @param {Object} variables Operand variables.
1221 *
1222 * @return {*} Result of evaluation.
1223 */
1224 function evaluate( postfix, variables ) {
1225 var stack = [],
1226 i, j, args, getOperatorResult, term, value;
1227
1228 for ( i = 0; i < postfix.length; i++ ) {
1229 term = postfix[ i ];
1230
1231 getOperatorResult = OPERATORS[ term ];
1232 if ( getOperatorResult ) {
1233 // Pop from stack by number of function arguments.
1234 j = getOperatorResult.length;
1235 args = Array( j );
1236 while ( j-- ) {
1237 args[ j ] = stack.pop();
1238 }
1239
1240 try {
1241 value = getOperatorResult.apply( null, args );
1242 } catch ( earlyReturn ) {
1243 return earlyReturn;
1244 }
1245 } else if ( variables.hasOwnProperty( term ) ) {
1246 value = variables[ term ];
1247 } else {
1248 value = +term;
1249 }
1250
1251 stack.push( value );
1252 }
1253
1254 return stack[ 0 ];
1255 }
1256
1257 module.exports = evaluate;
1258
1259 },{}],8:[function(require,module,exports){
1260 'use strict';
1261
1262 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
1263
1264 var compile = _interopDefault(require('@tannin/compile'));
1265
1266 /**
1267 * Given a C expression, returns a function which, when called with a value,
1268 * evaluates the result with the value assumed to be the "n" variable of the
1269 * expression. The result will be coerced to its numeric equivalent.
1270 *
1271 * @param {string} expression C expression.
1272 *
1273 * @return {Function} Evaluator function.
1274 */
1275 function pluralForms( expression ) {
1276 var evaluate = compile( expression );
1277
1278 return function( n ) {
1279 return +evaluate( { n: n } );
1280 };
1281 }
1282
1283 module.exports = pluralForms;
1284
1285 },{"@tannin/compile":6}],9:[function(require,module,exports){
1286 'use strict';
1287
1288 var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
1289
1290 /**
1291 * Operator precedence mapping.
1292 *
1293 * @type {Object}
1294 */
1295 PRECEDENCE = {
1296 '(': 9,
1297 '!': 8,
1298 '*': 7,
1299 '/': 7,
1300 '%': 7,
1301 '+': 6,
1302 '-': 6,
1303 '<': 5,
1304 '<=': 5,
1305 '>': 5,
1306 '>=': 5,
1307 '==': 4,
1308 '!=': 4,
1309 '&&': 3,
1310 '||': 2,
1311 '?': 1,
1312 '?:': 1,
1313 };
1314
1315 /**
1316 * Characters which signal pair opening, to be terminated by terminators.
1317 *
1318 * @type {string[]}
1319 */
1320 OPENERS = [ '(', '?' ];
1321
1322 /**
1323 * Characters which signal pair termination, the value an array with the
1324 * opener as its first member. The second member is an optional operator
1325 * replacement to push to the stack.
1326 *
1327 * @type {string[]}
1328 */
1329 TERMINATORS = {
1330 ')': [ '(' ],
1331 ':': [ '?', '?:' ],
1332 };
1333
1334 /**
1335 * Pattern matching operators and openers.
1336 *
1337 * @type {RegExp}
1338 */
1339 PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
1340
1341 /**
1342 * Given a C expression, returns the equivalent postfix (Reverse Polish)
1343 * notation terms as an array.
1344 *
1345 * If a postfix string is desired, simply `.join( ' ' )` the result.
1346 *
1347 * @example
1348 *
1349 * ```js
1350 * import postfix from '@tannin/postfix';
1351 *
1352 * postfix( 'n > 1' );
1353 * // ⇒ [ 'n', '1', '>' ]
1354 * ```
1355 *
1356 * @param {string} expression C expression.
1357 *
1358 * @return {string[]} Postfix terms.
1359 */
1360 function postfix( expression ) {
1361 var terms = [],
1362 stack = [],
1363 match, operator, term, element;
1364
1365 while ( ( match = expression.match( PATTERN ) ) ) {
1366 operator = match[ 0 ];
1367
1368 // Term is the string preceding the operator match. It may contain
1369 // whitespace, and may be empty (if operator is at beginning).
1370 term = expression.substr( 0, match.index ).trim();
1371 if ( term ) {
1372 terms.push( term );
1373 }
1374
1375 while ( ( element = stack.pop() ) ) {
1376 if ( TERMINATORS[ operator ] ) {
1377 if ( TERMINATORS[ operator ][ 0 ] === element ) {
1378 // Substitution works here under assumption that because
1379 // the assigned operator will no longer be a terminator, it
1380 // will be pushed to the stack during the condition below.
1381 operator = TERMINATORS[ operator ][ 1 ] || operator;
1382 break;
1383 }
1384 } else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) {
1385 // Push to stack if either an opener or when pop reveals an
1386 // element of lower precedence.
1387 stack.push( element );
1388 break;
1389 }
1390
1391 // For each popped from stack, push to terms.
1392 terms.push( element );
1393 }
1394
1395 if ( ! TERMINATORS[ operator ] ) {
1396 stack.push( operator );
1397 }
1398
1399 // Slice matched fragment from expression to continue match.
1400 expression = expression.substr( match.index + operator.length );
1401 }
1402
1403 // Push remainder of operand, if exists, to terms.
1404 expression = expression.trim();
1405 if ( expression ) {
1406 terms.push( expression );
1407 }
1408
1409 // Pop remaining items from stack into terms.
1410 return terms.concat( stack.reverse() );
1411 }
1412
1413 module.exports = postfix;
1414
1415 },{}],10:[function(require,module,exports){
1416 "use strict";
1417
1418 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
1419
1420 Object.defineProperty(exports, "__esModule", {
1421 value: true
1422 });
1423 exports.createI18n = void 0;
1424
1425 var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
1426
1427 var _tannin = _interopRequireDefault(require("tannin"));
1428
1429 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; }
1430
1431 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; }
1432
1433 /**
1434 * @typedef {Record<string,any>} LocaleData
1435 */
1436
1437 /**
1438 * Default locale data to use for Tannin domain when not otherwise provided.
1439 * Assumes an English plural forms expression.
1440 *
1441 * @type {LocaleData}
1442 */
1443 var DEFAULT_LOCALE_DATA = {
1444 '': {
1445 /** @param {number} n */
1446 plural_forms: function plural_forms(n) {
1447 return n === 1 ? 0 : 1;
1448 }
1449 }
1450 };
1451 /**
1452 * An i18n instance
1453 *
1454 * @typedef {Object} I18n
1455 * @property {Function} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a
1456 * Jed-formatted JSON object shape.
1457 * @property {Function} __ Retrieve the translation of text.
1458 * @property {Function} _x Retrieve translated string with gettext context.
1459 * @property {Function} _n Translates and retrieves the singular or plural form based on the supplied
1460 * number.
1461 * @property {Function} _nx Translates and retrieves the singular or plural form based on the supplied
1462 * number, with gettext context.
1463 * @property {Function} isRTL Check if current locale is RTL.
1464 */
1465
1466 /**
1467 * Create an i18n instance
1468 *
1469 * @param {LocaleData} [initialData] Locale data configuration.
1470 * @param {string} [initialDomain] Domain for which configuration applies.
1471 * @return {I18n} I18n instance
1472 */
1473
1474 var createI18n = function createI18n(initialData, initialDomain) {
1475 /**
1476 * The underlying instance of Tannin to which exported functions interface.
1477 *
1478 * @type {Tannin}
1479 */
1480 var tannin = new _tannin.default({});
1481 /**
1482 * Merges locale data into the Tannin instance by domain. Accepts data in a
1483 * Jed-formatted JSON object shape.
1484 *
1485 * @see http://messageformat.github.io/Jed/
1486 *
1487 * @param {LocaleData} [data] Locale data configuration.
1488 * @param {string} [domain] Domain for which configuration applies.
1489 */
1490
1491 var setLocaleData = function setLocaleData(data) {
1492 var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
1493 tannin.data[domain] = _objectSpread({}, DEFAULT_LOCALE_DATA, {}, tannin.data[domain], {}, data); // Populate default domain configuration (supported locale date which omits
1494 // a plural forms expression).
1495
1496 tannin.data[domain][''] = _objectSpread({}, DEFAULT_LOCALE_DATA[''], {}, tannin.data[domain]['']);
1497 };
1498 /**
1499 * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
1500 * otherwise previously assigned.
1501 *
1502 * @param {string|undefined} domain Domain to retrieve the translated text.
1503 * @param {string|undefined} context Context information for the translators.
1504 * @param {string} single Text to translate if non-plural. Used as
1505 * fallback return value on a caught error.
1506 * @param {string} [plural] The text to be used if the number is
1507 * plural.
1508 * @param {number} [number] The number to compare against to use
1509 * either the singular or plural form.
1510 *
1511 * @return {string} The translated string.
1512 */
1513
1514
1515 var dcnpgettext = function dcnpgettext() {
1516 var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
1517 var context = arguments.length > 1 ? arguments[1] : undefined;
1518 var single = arguments.length > 2 ? arguments[2] : undefined;
1519 var plural = arguments.length > 3 ? arguments[3] : undefined;
1520 var number = arguments.length > 4 ? arguments[4] : undefined;
1521
1522 if (!tannin.data[domain]) {
1523 setLocaleData(undefined, domain);
1524 }
1525
1526 return tannin.dcnpgettext(domain, context, single, plural, number);
1527 };
1528 /**
1529 * Retrieve the translation of text.
1530 *
1531 * @see https://developer.wordpress.org/reference/functions/__/
1532 *
1533 * @param {string} text Text to translate.
1534 * @param {string} [domain] Domain to retrieve the translated text.
1535 *
1536 * @return {string} Translated text.
1537 */
1538
1539
1540 var __ = function __(text, domain) {
1541 return dcnpgettext(domain, undefined, text);
1542 };
1543 /**
1544 * Retrieve translated string with gettext context.
1545 *
1546 * @see https://developer.wordpress.org/reference/functions/_x/
1547 *
1548 * @param {string} text Text to translate.
1549 * @param {string} context Context information for the translators.
1550 * @param {string} [domain] Domain to retrieve the translated text.
1551 *
1552 * @return {string} Translated context string without pipe.
1553 */
1554
1555
1556 var _x = function _x(text, context, domain) {
1557 return dcnpgettext(domain, context, text);
1558 };
1559 /**
1560 * Translates and retrieves the singular or plural form based on the supplied
1561 * number.
1562 *
1563 * @see https://developer.wordpress.org/reference/functions/_n/
1564 *
1565 * @param {string} single The text to be used if the number is singular.
1566 * @param {string} plural The text to be used if the number is plural.
1567 * @param {number} number The number to compare against to use either the
1568 * singular or plural form.
1569 * @param {string} [domain] Domain to retrieve the translated text.
1570 *
1571 * @return {string} The translated singular or plural form.
1572 */
1573
1574
1575 var _n = function _n(single, plural, number, domain) {
1576 return dcnpgettext(domain, undefined, single, plural, number);
1577 };
1578 /**
1579 * Translates and retrieves the singular or plural form based on the supplied
1580 * number, with gettext context.
1581 *
1582 * @see https://developer.wordpress.org/reference/functions/_nx/
1583 *
1584 * @param {string} single The text to be used if the number is singular.
1585 * @param {string} plural The text to be used if the number is plural.
1586 * @param {number} number The number to compare against to use either the
1587 * singular or plural form.
1588 * @param {string} context Context information for the translators.
1589 * @param {string} [domain] Domain to retrieve the translated text.
1590 *
1591 * @return {string} The translated singular or plural form.
1592 */
1593
1594
1595 var _nx = function _nx(single, plural, number, context, domain) {
1596 return dcnpgettext(domain, context, single, plural, number);
1597 };
1598 /**
1599 * Check if current locale is RTL.
1600 *
1601 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
1602 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
1603 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
1604 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
1605 *
1606 * @return {boolean} Whether locale is RTL.
1607 */
1608
1609
1610 var isRTL = function isRTL() {
1611 return 'rtl' === _x('ltr', 'text direction');
1612 };
1613
1614 if (initialData) {
1615 setLocaleData(initialData, initialDomain);
1616 }
1617
1618 return {
1619 setLocaleData: setLocaleData,
1620 __: __,
1621 _x: _x,
1622 _n: _n,
1623 _nx: _nx,
1624 isRTL: isRTL
1625 };
1626 };
1627
1628 exports.createI18n = createI18n;
1629
1630 },{"@babel/runtime/helpers/defineProperty":4,"@babel/runtime/helpers/interopRequireDefault":5,"tannin":17}],11:[function(require,module,exports){
1631 "use strict";
1632
1633 Object.defineProperty(exports, "__esModule", {
1634 value: true
1635 });
1636 exports.isRTL = exports._nx = exports._n = exports._x = exports.__ = exports.setLocaleData = void 0;
1637
1638 var _createI18n = require("./create-i18n");
1639
1640 /**
1641 * Internal dependencies
1642 */
1643 var i18n = (0, _createI18n.createI18n)();
1644 /*
1645 * Comments in this file are duplicated from ./i18n due to
1646 * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
1647 */
1648
1649 /**
1650 * @typedef {import('./create-i18n').LocaleData} LocaleData
1651 */
1652
1653 /**
1654 * Merges locale data into the Tannin instance by domain. Accepts data in a
1655 * Jed-formatted JSON object shape.
1656 *
1657 * @see http://messageformat.github.io/Jed/
1658 *
1659 * @param {LocaleData} [data] Locale data configuration.
1660 * @param {string} [domain] Domain for which configuration applies.
1661 */
1662
1663 var setLocaleData = i18n.setLocaleData.bind(i18n);
1664 /**
1665 * Retrieve the translation of text.
1666 *
1667 * @see https://developer.wordpress.org/reference/functions/__/
1668 *
1669 * @param {string} text Text to translate.
1670 * @param {string} [domain] Domain to retrieve the translated text.
1671 *
1672 * @return {string} Translated text.
1673 */
1674
1675 exports.setLocaleData = setLocaleData;
1676
1677 var __ = i18n.__.bind(i18n);
1678 /**
1679 * Retrieve translated string with gettext context.
1680 *
1681 * @see https://developer.wordpress.org/reference/functions/_x/
1682 *
1683 * @param {string} text Text to translate.
1684 * @param {string} context Context information for the translators.
1685 * @param {string} [domain] Domain to retrieve the translated text.
1686 *
1687 * @return {string} Translated context string without pipe.
1688 */
1689
1690
1691 exports.__ = __;
1692
1693 var _x = i18n._x.bind(i18n);
1694 /**
1695 * Translates and retrieves the singular or plural form based on the supplied
1696 * number.
1697 *
1698 * @see https://developer.wordpress.org/reference/functions/_n/
1699 *
1700 * @param {string} single The text to be used if the number is singular.
1701 * @param {string} plural The text to be used if the number is plural.
1702 * @param {number} number The number to compare against to use either the
1703 * singular or plural form.
1704 * @param {string} [domain] Domain to retrieve the translated text.
1705 *
1706 * @return {string} The translated singular or plural form.
1707 */
1708
1709
1710 exports._x = _x;
1711
1712 var _n = i18n._n.bind(i18n);
1713 /**
1714 * Translates and retrieves the singular or plural form based on the supplied
1715 * number, with gettext context.
1716 *
1717 * @see https://developer.wordpress.org/reference/functions/_nx/
1718 *
1719 * @param {string} single The text to be used if the number is singular.
1720 * @param {string} plural The text to be used if the number is plural.
1721 * @param {number} number The number to compare against to use either the
1722 * singular or plural form.
1723 * @param {string} context Context information for the translators.
1724 * @param {string} [domain] Domain to retrieve the translated text.
1725 *
1726 * @return {string} The translated singular or plural form.
1727 */
1728
1729
1730 exports._n = _n;
1731
1732 var _nx = i18n._nx.bind(i18n);
1733 /**
1734 * Check if current locale is RTL.
1735 *
1736 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
1737 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
1738 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
1739 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
1740 *
1741 * @return {boolean} Whether locale is RTL.
1742 */
1743
1744
1745 exports._nx = _nx;
1746 var isRTL = i18n.isRTL.bind(i18n);
1747 exports.isRTL = isRTL;
1748
1749 },{"./create-i18n":10}],12:[function(require,module,exports){
1750 "use strict";
1751
1752 Object.defineProperty(exports, "__esModule", {
1753 value: true
1754 });
1755 var _exportNames = {
1756 sprintf: true,
1757 setLocaleData: true,
1758 __: true,
1759 _x: true,
1760 _n: true,
1761 _nx: true,
1762 isRTL: true
1763 };
1764 Object.defineProperty(exports, "sprintf", {
1765 enumerable: true,
1766 get: function get() {
1767 return _sprintf.sprintf;
1768 }
1769 });
1770 Object.defineProperty(exports, "setLocaleData", {
1771 enumerable: true,
1772 get: function get() {
1773 return _defaultI18n.setLocaleData;
1774 }
1775 });
1776 Object.defineProperty(exports, "__", {
1777 enumerable: true,
1778 get: function get() {
1779 return _defaultI18n.__;
1780 }
1781 });
1782 Object.defineProperty(exports, "_x", {
1783 enumerable: true,
1784 get: function get() {
1785 return _defaultI18n._x;
1786 }
1787 });
1788 Object.defineProperty(exports, "_n", {
1789 enumerable: true,
1790 get: function get() {
1791 return _defaultI18n._n;
1792 }
1793 });
1794 Object.defineProperty(exports, "_nx", {
1795 enumerable: true,
1796 get: function get() {
1797 return _defaultI18n._nx;
1798 }
1799 });
1800 Object.defineProperty(exports, "isRTL", {
1801 enumerable: true,
1802 get: function get() {
1803 return _defaultI18n.isRTL;
1804 }
1805 });
1806
1807 var _sprintf = require("./sprintf");
1808
1809 var _createI18n = require("./create-i18n");
1810
1811 Object.keys(_createI18n).forEach(function (key) {
1812 if (key === "default" || key === "__esModule") return;
1813 if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
1814 Object.defineProperty(exports, key, {
1815 enumerable: true,
1816 get: function get() {
1817 return _createI18n[key];
1818 }
1819 });
1820 });
1821
1822 var _defaultI18n = require("./default-i18n");
1823
1824 },{"./create-i18n":10,"./default-i18n":11,"./sprintf":13}],13:[function(require,module,exports){
1825 "use strict";
1826
1827 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
1828
1829 Object.defineProperty(exports, "__esModule", {
1830 value: true
1831 });
1832 exports.sprintf = sprintf;
1833
1834 var _memize = _interopRequireDefault(require("memize"));
1835
1836 var _sprintfJs = _interopRequireDefault(require("sprintf-js"));
1837
1838 /**
1839 * External dependencies
1840 */
1841
1842 /**
1843 * Log to console, once per message; or more precisely, per referentially equal
1844 * argument set. Because Jed throws errors, we log these to the console instead
1845 * to avoid crashing the application.
1846 *
1847 * @param {...*} args Arguments to pass to `console.error`
1848 */
1849 var logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console
1850
1851 /**
1852 * Returns a formatted string. If an error occurs in applying the format, the
1853 * original format string is returned.
1854 *
1855 * @param {string} format The format of the string to generate.
1856 * @param {...*} args Arguments to apply to the format.
1857 *
1858 * @see http://www.diveintojavascript.com/projects/javascript-sprintf
1859 *
1860 * @return {string} The formatted string.
1861 */
1862
1863 function sprintf(format) {
1864 try {
1865 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1866 args[_key - 1] = arguments[_key];
1867 }
1868
1869 return _sprintfJs.default.sprintf.apply(_sprintfJs.default, [format].concat(args));
1870 } catch (error) {
1871 logErrorOnce('sprintf error: \n\n' + error.toString());
1872 return format;
1873 }
1874 }
1875
1876 },{"@babel/runtime/helpers/interopRequireDefault":5,"memize":15,"sprintf-js":14}],14:[function(require,module,exports){
1877 /* global window, exports, define */
1878
1879 !function() {
1880 'use strict'
1881
1882 var re = {
1883 not_string: /[^s]/,
1884 not_bool: /[^t]/,
1885 not_type: /[^T]/,
1886 not_primitive: /[^v]/,
1887 number: /[diefg]/,
1888 numeric_arg: /[bcdiefguxX]/,
1889 json: /[j]/,
1890 not_json: /[^j]/,
1891 text: /^[^\x25]+/,
1892 modulo: /^\x25{2}/,
1893 placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
1894 key: /^([a-z_][a-z_\d]*)/i,
1895 key_access: /^\.([a-z_][a-z_\d]*)/i,
1896 index_access: /^\[(\d+)\]/,
1897 sign: /^[+-]/
1898 }
1899
1900 function sprintf(key) {
1901 // `arguments` is not an array, but should be fine for this call
1902 return sprintf_format(sprintf_parse(key), arguments)
1903 }
1904
1905 function vsprintf(fmt, argv) {
1906 return sprintf.apply(null, [fmt].concat(argv || []))
1907 }
1908
1909 function sprintf_format(parse_tree, argv) {
1910 var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
1911 for (i = 0; i < tree_length; i++) {
1912 if (typeof parse_tree[i] === 'string') {
1913 output += parse_tree[i]
1914 }
1915 else if (typeof parse_tree[i] === 'object') {
1916 ph = parse_tree[i] // convenience purposes only
1917 if (ph.keys) { // keyword argument
1918 arg = argv[cursor]
1919 for (k = 0; k < ph.keys.length; k++) {
1920 if (arg == undefined) {
1921 throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
1922 }
1923 arg = arg[ph.keys[k]]
1924 }
1925 }
1926 else if (ph.param_no) { // positional argument (explicit)
1927 arg = argv[ph.param_no]
1928 }
1929 else { // positional argument (implicit)
1930 arg = argv[cursor++]
1931 }
1932
1933 if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
1934 arg = arg()
1935 }
1936
1937 if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
1938 throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
1939 }
1940
1941 if (re.number.test(ph.type)) {
1942 is_positive = arg >= 0
1943 }
1944
1945 switch (ph.type) {
1946 case 'b':
1947 arg = parseInt(arg, 10).toString(2)
1948 break
1949 case 'c':
1950 arg = String.fromCharCode(parseInt(arg, 10))
1951 break
1952 case 'd':
1953 case 'i':
1954 arg = parseInt(arg, 10)
1955 break
1956 case 'j':
1957 arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
1958 break
1959 case 'e':
1960 arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
1961 break
1962 case 'f':
1963 arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
1964 break
1965 case 'g':
1966 arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
1967 break
1968 case 'o':
1969 arg = (parseInt(arg, 10) >>> 0).toString(8)
1970 break
1971 case 's':
1972 arg = String(arg)
1973 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1974 break
1975 case 't':
1976 arg = String(!!arg)
1977 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1978 break
1979 case 'T':
1980 arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
1981 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1982 break
1983 case 'u':
1984 arg = parseInt(arg, 10) >>> 0
1985 break
1986 case 'v':
1987 arg = arg.valueOf()
1988 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
1989 break
1990 case 'x':
1991 arg = (parseInt(arg, 10) >>> 0).toString(16)
1992 break
1993 case 'X':
1994 arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
1995 break
1996 }
1997 if (re.json.test(ph.type)) {
1998 output += arg
1999 }
2000 else {
2001 if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
2002 sign = is_positive ? '+' : '-'
2003 arg = arg.toString().replace(re.sign, '')
2004 }
2005 else {
2006 sign = ''
2007 }
2008 pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
2009 pad_length = ph.width - (sign + arg).length
2010 pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
2011 output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
2012 }
2013 }
2014 }
2015 return output
2016 }
2017
2018 var sprintf_cache = Object.create(null)
2019
2020 function sprintf_parse(fmt) {
2021 if (sprintf_cache[fmt]) {
2022 return sprintf_cache[fmt]
2023 }
2024
2025 var _fmt = fmt, match, parse_tree = [], arg_names = 0
2026 while (_fmt) {
2027 if ((match = re.text.exec(_fmt)) !== null) {
2028 parse_tree.push(match[0])
2029 }
2030 else if ((match = re.modulo.exec(_fmt)) !== null) {
2031 parse_tree.push('%')
2032 }
2033 else if ((match = re.placeholder.exec(_fmt)) !== null) {
2034 if (match[2]) {
2035 arg_names |= 1
2036 var field_list = [], replacement_field = match[2], field_match = []
2037 if ((field_match = re.key.exec(replacement_field)) !== null) {
2038 field_list.push(field_match[1])
2039 while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
2040 if ((field_match = re.key_access.exec(replacement_field)) !== null) {
2041 field_list.push(field_match[1])
2042 }
2043 else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
2044 field_list.push(field_match[1])
2045 }
2046 else {
2047 throw new SyntaxError('[sprintf] failed to parse named argument key')
2048 }
2049 }
2050 }
2051 else {
2052 throw new SyntaxError('[sprintf] failed to parse named argument key')
2053 }
2054 match[2] = field_list
2055 }
2056 else {
2057 arg_names |= 2
2058 }
2059 if (arg_names === 3) {
2060 throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
2061 }
2062
2063 parse_tree.push(
2064 {
2065 placeholder: match[0],
2066 param_no: match[1],
2067 keys: match[2],
2068 sign: match[3],
2069 pad_char: match[4],
2070 align: match[5],
2071 width: match[6],
2072 precision: match[7],
2073 type: match[8]
2074 }
2075 )
2076 }
2077 else {
2078 throw new SyntaxError('[sprintf] unexpected placeholder')
2079 }
2080 _fmt = _fmt.substring(match[0].length)
2081 }
2082 return sprintf_cache[fmt] = parse_tree
2083 }
2084
2085 /**
2086 * export to either browser or node.js
2087 */
2088 /* eslint-disable quote-props */
2089 if (typeof exports !== 'undefined') {
2090 exports['sprintf'] = sprintf
2091 exports['vsprintf'] = vsprintf
2092 }
2093 if (typeof window !== 'undefined') {
2094 window['sprintf'] = sprintf
2095 window['vsprintf'] = vsprintf
2096
2097 if (typeof define === 'function' && define['amd']) {
2098 define(function() {
2099 return {
2100 'sprintf': sprintf,
2101 'vsprintf': vsprintf
2102 }
2103 })
2104 }
2105 }
2106 /* eslint-enable quote-props */
2107 }(); // eslint-disable-line
2108
2109 },{}],15:[function(require,module,exports){
2110 (function (process){
2111 /**
2112 * Memize options object.
2113 *
2114 * @typedef MemizeOptions
2115 *
2116 * @property {number} [maxSize] Maximum size of the cache.
2117 */
2118
2119 /**
2120 * Internal cache entry.
2121 *
2122 * @typedef MemizeCacheNode
2123 *
2124 * @property {?MemizeCacheNode|undefined} [prev] Previous node.
2125 * @property {?MemizeCacheNode|undefined} [next] Next node.
2126 * @property {Array<*>} args Function arguments for cache
2127 * entry.
2128 * @property {*} val Function result.
2129 */
2130
2131 /**
2132 * Properties of the enhanced function for controlling cache.
2133 *
2134 * @typedef MemizeMemoizedFunction
2135 *
2136 * @property {()=>void} clear Clear the cache.
2137 */
2138
2139 /**
2140 * Accepts a function to be memoized, and returns a new memoized function, with
2141 * optional options.
2142 *
2143 * @template {Function} F
2144 *
2145 * @param {F} fn Function to memoize.
2146 * @param {MemizeOptions} [options] Options object.
2147 *
2148 * @return {F & MemizeMemoizedFunction} Memoized function.
2149 */
2150 function memize( fn, options ) {
2151 var size = 0;
2152
2153 /** @type {?MemizeCacheNode|undefined} */
2154 var head;
2155
2156 /** @type {?MemizeCacheNode|undefined} */
2157 var tail;
2158
2159 options = options || {};
2160
2161 function memoized( /* ...args */ ) {
2162 var node = head,
2163 len = arguments.length,
2164 args, i;
2165
2166 searchCache: while ( node ) {
2167 // Perform a shallow equality test to confirm that whether the node
2168 // under test is a candidate for the arguments passed. Two arrays
2169 // are shallowly equal if their length matches and each entry is
2170 // strictly equal between the two sets. Avoid abstracting to a
2171 // function which could incur an arguments leaking deoptimization.
2172
2173 // Check whether node arguments match arguments length
2174 if ( node.args.length !== arguments.length ) {
2175 node = node.next;
2176 continue;
2177 }
2178
2179 // Check whether node arguments match arguments values
2180 for ( i = 0; i < len; i++ ) {
2181 if ( node.args[ i ] !== arguments[ i ] ) {
2182 node = node.next;
2183 continue searchCache;
2184 }
2185 }
2186
2187 // At this point we can assume we've found a match
2188
2189 // Surface matched node to head if not already
2190 if ( node !== head ) {
2191 // As tail, shift to previous. Must only shift if not also
2192 // head, since if both head and tail, there is no previous.
2193 if ( node === tail ) {
2194 tail = node.prev;
2195 }
2196
2197 // Adjust siblings to point to each other. If node was tail,
2198 // this also handles new tail's empty `next` assignment.
2199 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
2200 if ( node.next ) {
2201 node.next.prev = node.prev;
2202 }
2203
2204 node.next = head;
2205 node.prev = null;
2206 /** @type {MemizeCacheNode} */ ( head ).prev = node;
2207 head = node;
2208 }
2209
2210 // Return immediately
2211 return node.val;
2212 }
2213
2214 // No cached value found. Continue to insertion phase:
2215
2216 // Create a copy of arguments (avoid leaking deoptimization)
2217 args = new Array( len );
2218 for ( i = 0; i < len; i++ ) {
2219 args[ i ] = arguments[ i ];
2220 }
2221
2222 node = {
2223 args: args,
2224
2225 // Generate the result from original function
2226 val: fn.apply( null, args ),
2227 };
2228
2229 // Don't need to check whether node is already head, since it would
2230 // have been returned above already if it was
2231
2232 // Shift existing head down list
2233 if ( head ) {
2234 head.prev = node;
2235 node.next = head;
2236 } else {
2237 // If no head, follows that there's no tail (at initial or reset)
2238 tail = node;
2239 }
2240
2241 // Trim tail if we're reached max size and are pending cache insertion
2242 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
2243 tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
2244 /** @type {MemizeCacheNode} */ ( tail ).next = null;
2245 } else {
2246 size++;
2247 }
2248
2249 head = node;
2250
2251 return node.val;
2252 }
2253
2254 memoized.clear = function() {
2255 head = null;
2256 tail = null;
2257 size = 0;
2258 };
2259
2260 if ( process.env.NODE_ENV === 'test' ) {
2261 // Cache is not exposed in the public API, but used in tests to ensure
2262 // expected list progression
2263 memoized.getCache = function() {
2264 return [ head, tail, size ];
2265 };
2266 }
2267
2268 // Ignore reason: There's not a clear solution to create an intersection of
2269 // the function with additional properties, where the goal is to retain the
2270 // function signature of the incoming argument and add control properties
2271 // on the return value.
2272
2273 // @ts-ignore
2274 return memoized;
2275 }
2276
2277 module.exports = memize;
2278
2279 }).call(this,require('_process'))
2280 },{"_process":16}],16:[function(require,module,exports){
2281 // shim for using process in browser
2282 var process = module.exports = {};
2283
2284 // cached from whatever global is present so that test runners that stub it
2285 // don't break things. But we need to wrap it in a try catch in case it is
2286 // wrapped in strict mode code which doesn't define any globals. It's inside a
2287 // function because try/catches deoptimize in certain engines.
2288
2289 var cachedSetTimeout;
2290 var cachedClearTimeout;
2291
2292 function defaultSetTimout() {
2293 throw new Error('setTimeout has not been defined');
2294 }
2295 function defaultClearTimeout () {
2296 throw new Error('clearTimeout has not been defined');
2297 }
2298 (function () {
2299 try {
2300 if (typeof setTimeout === 'function') {
2301 cachedSetTimeout = setTimeout;
2302 } else {
2303 cachedSetTimeout = defaultSetTimout;
2304 }
2305 } catch (e) {
2306 cachedSetTimeout = defaultSetTimout;
2307 }
2308 try {
2309 if (typeof clearTimeout === 'function') {
2310 cachedClearTimeout = clearTimeout;
2311 } else {
2312 cachedClearTimeout = defaultClearTimeout;
2313 }
2314 } catch (e) {
2315 cachedClearTimeout = defaultClearTimeout;
2316 }
2317 } ())
2318 function runTimeout(fun) {
2319 if (cachedSetTimeout === setTimeout) {
2320 //normal enviroments in sane situations
2321 return setTimeout(fun, 0);
2322 }
2323 // if setTimeout wasn't available but was latter defined
2324 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
2325 cachedSetTimeout = setTimeout;
2326 return setTimeout(fun, 0);
2327 }
2328 try {
2329 // when when somebody has screwed with setTimeout but no I.E. maddness
2330 return cachedSetTimeout(fun, 0);
2331 } catch(e){
2332 try {
2333 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2334 return cachedSetTimeout.call(null, fun, 0);
2335 } catch(e){
2336 // 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
2337 return cachedSetTimeout.call(this, fun, 0);
2338 }
2339 }
2340
2341
2342 }
2343 function runClearTimeout(marker) {
2344 if (cachedClearTimeout === clearTimeout) {
2345 //normal enviroments in sane situations
2346 return clearTimeout(marker);
2347 }
2348 // if clearTimeout wasn't available but was latter defined
2349 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
2350 cachedClearTimeout = clearTimeout;
2351 return clearTimeout(marker);
2352 }
2353 try {
2354 // when when somebody has screwed with setTimeout but no I.E. maddness
2355 return cachedClearTimeout(marker);
2356 } catch (e){
2357 try {
2358 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2359 return cachedClearTimeout.call(null, marker);
2360 } catch (e){
2361 // 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.
2362 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
2363 return cachedClearTimeout.call(this, marker);
2364 }
2365 }
2366
2367
2368
2369 }
2370 var queue = [];
2371 var draining = false;
2372 var currentQueue;
2373 var queueIndex = -1;
2374
2375 function cleanUpNextTick() {
2376 if (!draining || !currentQueue) {
2377 return;
2378 }
2379 draining = false;
2380 if (currentQueue.length) {
2381 queue = currentQueue.concat(queue);
2382 } else {
2383 queueIndex = -1;
2384 }
2385 if (queue.length) {
2386 drainQueue();
2387 }
2388 }
2389
2390 function drainQueue() {
2391 if (draining) {
2392 return;
2393 }
2394 var timeout = runTimeout(cleanUpNextTick);
2395 draining = true;
2396
2397 var len = queue.length;
2398 while(len) {
2399 currentQueue = queue;
2400 queue = [];
2401 while (++queueIndex < len) {
2402 if (currentQueue) {
2403 currentQueue[queueIndex].run();
2404 }
2405 }
2406 queueIndex = -1;
2407 len = queue.length;
2408 }
2409 currentQueue = null;
2410 draining = false;
2411 runClearTimeout(timeout);
2412 }
2413
2414 process.nextTick = function (fun) {
2415 var args = new Array(arguments.length - 1);
2416 if (arguments.length > 1) {
2417 for (var i = 1; i < arguments.length; i++) {
2418 args[i - 1] = arguments[i];
2419 }
2420 }
2421 queue.push(new Item(fun, args));
2422 if (queue.length === 1 && !draining) {
2423 runTimeout(drainQueue);
2424 }
2425 };
2426
2427 // v8 likes predictible objects
2428 function Item(fun, array) {
2429 this.fun = fun;
2430 this.array = array;
2431 }
2432 Item.prototype.run = function () {
2433 this.fun.apply(null, this.array);
2434 };
2435 process.title = 'browser';
2436 process.browser = true;
2437 process.env = {};
2438 process.argv = [];
2439 process.version = ''; // empty string to avoid regexp issues
2440 process.versions = {};
2441
2442 function noop() {}
2443
2444 process.on = noop;
2445 process.addListener = noop;
2446 process.once = noop;
2447 process.off = noop;
2448 process.removeListener = noop;
2449 process.removeAllListeners = noop;
2450 process.emit = noop;
2451 process.prependListener = noop;
2452 process.prependOnceListener = noop;
2453
2454 process.listeners = function (name) { return [] }
2455
2456 process.binding = function (name) {
2457 throw new Error('process.binding is not supported');
2458 };
2459
2460 process.cwd = function () { return '/' };
2461 process.chdir = function (dir) {
2462 throw new Error('process.chdir is not supported');
2463 };
2464 process.umask = function() { return 0; };
2465
2466 },{}],17:[function(require,module,exports){
2467 'use strict';
2468
2469 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
2470
2471 var pluralForms = _interopDefault(require('@tannin/plural-forms'));
2472
2473 /**
2474 * Tannin constructor options.
2475 *
2476 * @typedef {Object} TanninOptions
2477 *
2478 * @property {string} [contextDelimiter] Joiner in string lookup with context.
2479 * @property {Function} [onMissingKey] Callback to invoke when key missing.
2480 */
2481
2482 /**
2483 * Domain metadata.
2484 *
2485 * @typedef {Object} TanninDomainMetadata
2486 *
2487 * @property {string} [domain] Domain name.
2488 * @property {string} [lang] Language code.
2489 * @property {(string|Function)} [plural_forms] Plural forms expression or
2490 * function evaluator.
2491 */
2492
2493 /**
2494 * Domain translation pair respectively representing the singular and plural
2495 * translation.
2496 *
2497 * @typedef {[string,string]} TanninTranslation
2498 */
2499
2500 /**
2501 * Locale data domain. The key is used as reference for lookup, the value an
2502 * array of two string entries respectively representing the singular and plural
2503 * translation.
2504 *
2505 * @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
2506 */
2507
2508 /**
2509 * Jed-formatted locale data.
2510 *
2511 * @see http://messageformat.github.io/Jed/
2512 *
2513 * @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
2514 */
2515
2516 /**
2517 * Default Tannin constructor options.
2518 *
2519 * @type {TanninOptions}
2520 */
2521 var DEFAULT_OPTIONS = {
2522 contextDelimiter: '\u0004',
2523 onMissingKey: null,
2524 };
2525
2526 /**
2527 * Given a specific locale data's config `plural_forms` value, returns the
2528 * expression.
2529 *
2530 * @example
2531 *
2532 * ```
2533 * getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
2534 * ```
2535 *
2536 * @param {string} pf Locale data plural forms.
2537 *
2538 * @return {string} Plural forms expression.
2539 */
2540 function getPluralExpression( pf ) {
2541 var parts, i, part;
2542
2543 parts = pf.split( ';' );
2544
2545 for ( i = 0; i < parts.length; i++ ) {
2546 part = parts[ i ].trim();
2547 if ( part.indexOf( 'plural=' ) === 0 ) {
2548 return part.substr( 7 );
2549 }
2550 }
2551 }
2552
2553 /**
2554 * Tannin constructor.
2555 *
2556 * @class
2557 *
2558 * @param {TanninLocaleData} data Jed-formatted locale data.
2559 * @param {TanninOptions} [options] Tannin options.
2560 */
2561 function Tannin( data, options ) {
2562 var key;
2563
2564 /**
2565 * Jed-formatted locale data.
2566 *
2567 * @name Tannin#data
2568 * @type {TanninLocaleData}
2569 */
2570 this.data = data;
2571
2572 /**
2573 * Plural forms function cache, keyed by plural forms string.
2574 *
2575 * @name Tannin#pluralForms
2576 * @type {Object<string,Function>}
2577 */
2578 this.pluralForms = {};
2579
2580 /**
2581 * Effective options for instance, including defaults.
2582 *
2583 * @name Tannin#options
2584 * @type {TanninOptions}
2585 */
2586 this.options = {};
2587
2588 for ( key in DEFAULT_OPTIONS ) {
2589 this.options[ key ] = options !== undefined && key in options
2590 ? options[ key ]
2591 : DEFAULT_OPTIONS[ key ];
2592 }
2593 }
2594
2595 /**
2596 * Returns the plural form index for the given domain and value.
2597 *
2598 * @param {string} domain Domain on which to calculate plural form.
2599 * @param {number} n Value for which plural form is to be calculated.
2600 *
2601 * @return {number} Plural form index.
2602 */
2603 Tannin.prototype.getPluralForm = function( domain, n ) {
2604 var getPluralForm = this.pluralForms[ domain ],
2605 config, plural, pf;
2606
2607 if ( ! getPluralForm ) {
2608 config = this.data[ domain ][ '' ];
2609
2610 pf = (
2611 config[ 'Plural-Forms' ] ||
2612 config[ 'plural-forms' ] ||
2613 // Ignore reason: As known, there's no way to document the empty
2614 // string property on a key to guarantee this as metadata.
2615 // @ts-ignore
2616 config.plural_forms
2617 );
2618
2619 if ( typeof pf !== 'function' ) {
2620 plural = getPluralExpression(
2621 config[ 'Plural-Forms' ] ||
2622 config[ 'plural-forms' ] ||
2623 // Ignore reason: As known, there's no way to document the empty
2624 // string property on a key to guarantee this as metadata.
2625 // @ts-ignore
2626 config.plural_forms
2627 );
2628
2629 pf = pluralForms( plural );
2630 }
2631
2632 getPluralForm = this.pluralForms[ domain ] = pf;
2633 }
2634
2635 return getPluralForm( n );
2636 };
2637
2638 /**
2639 * Translate a string.
2640 *
2641 * @param {string} domain Translation domain.
2642 * @param {string|void} context Context distinguishing terms of the same name.
2643 * @param {string} singular Primary key for translation lookup.
2644 * @param {string=} plural Fallback value used for non-zero plural
2645 * form index.
2646 * @param {number=} n Value to use in calculating plural form.
2647 *
2648 * @return {string} Translated string.
2649 */
2650 Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
2651 var index, key, entry;
2652
2653 if ( n === undefined ) {
2654 // Default to singular.
2655 index = 0;
2656 } else {
2657 // Find index by evaluating plural form for value.
2658 index = this.getPluralForm( domain, n );
2659 }
2660
2661 key = singular;
2662
2663 // If provided, context is prepended to key with delimiter.
2664 if ( context ) {
2665 key = context + this.options.contextDelimiter + singular;
2666 }
2667
2668 entry = this.data[ domain ][ key ];
2669
2670 // Verify not only that entry exists, but that the intended index is within
2671 // range and non-empty.
2672 if ( entry && entry[ index ] ) {
2673 return entry[ index ];
2674 }
2675
2676 if ( this.options.onMissingKey ) {
2677 this.options.onMissingKey( singular, domain );
2678 }
2679
2680 // If entry not found, fall back to singular vs. plural with zero index
2681 // representing the singular value.
2682 return index === 0 ? singular : plural;
2683 };
2684
2685 module.exports = Tannin;
2686
2687 },{"@tannin/plural-forms":8}]},{},[2]);
2688