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

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

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