PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.1.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.1.0
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.1.0, at assets/dist/js/elementor-init.js

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