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

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

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