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.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / assets / dist / js / admin.js

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

1,646 lines 47.6 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 var _i18n = require("@wordpress/i18n");
5
6 var adminNotice = function adminNotice() {
7 var $ = jQuery;
8 $('.sellkit-notice.notice .notice-dismiss').on('click', function () {
9 var noticeKey = $(this).parents('.sellkit-notice').attr('data-key');
10 $(this).parents('.sellkit-notice').remove();
11 wp.ajax.post('sellkit_admin_notice_dismiss', {
12 key: noticeKey,
13 nonce: window.sellkitAdmin.nonce
14 });
15 });
16 var text = (0, _i18n.__)('Installing WooCommerce', 'sellkit');
17 $('.sellkit-notice').find('a[href="#install-woo"]').off().on('click', function () {
18 $(this).html('<span class="sellkit-notice-loading-icon">' + text + ' </span>').attr('disabled', 'disabled');
19 wp.ajax.post({
20 action: 'sellkit_install_woocommerce_plugin_by_notice',
21 nonce: window.sellkitAdmin.nonce
22 }).done(function () {
23 location.reload();
24 }).fail(function (result) {
25 if (result.includes('{"success":true}')) {
26 location.reload();
27 return;
28 }
29
30 $('.sellkit-notice').find('a[href="#install-woo"]').text((0, _i18n.__)('Failed, Try again.', 'sellkit'));
31 });
32 });
33 };
34
35 document.addEventListener('DOMContentLoaded', function () {
36 adminNotice();
37 });
38
39 },{"@wordpress/i18n":10}],2:[function(require,module,exports){
40 function _defineProperty(obj, key, value) {
41 if (key in obj) {
42 Object.defineProperty(obj, key, {
43 value: value,
44 enumerable: true,
45 configurable: true,
46 writable: true
47 });
48 } else {
49 obj[key] = value;
50 }
51
52 return obj;
53 }
54
55 module.exports = _defineProperty;
56 },{}],3:[function(require,module,exports){
57 function _interopRequireDefault(obj) {
58 return obj && obj.__esModule ? obj : {
59 "default": obj
60 };
61 }
62
63 module.exports = _interopRequireDefault;
64 },{}],4:[function(require,module,exports){
65 'use strict';
66
67 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
68
69 var postfix = _interopDefault(require('@tannin/postfix'));
70 var evaluate = _interopDefault(require('@tannin/evaluate'));
71
72 /**
73 * Given a C expression, returns a function which can be called to evaluate its
74 * result.
75 *
76 * @example
77 *
78 * ```js
79 * import compile from '@tannin/compile';
80 *
81 * const evaluate = compile( 'n > 1' );
82 *
83 * evaluate( { n: 2 } );
84 * // ⇒ true
85 * ```
86 *
87 * @param {string} expression C expression.
88 *
89 * @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator.
90 */
91 function compile( expression ) {
92 var terms = postfix( expression );
93
94 return function( variables ) {
95 return evaluate( terms, variables );
96 };
97 }
98
99 module.exports = compile;
100
101 },{"@tannin/evaluate":5,"@tannin/postfix":7}],5:[function(require,module,exports){
102 'use strict';
103
104 /**
105 * Operator callback functions.
106 *
107 * @type {Object}
108 */
109 var OPERATORS = {
110 '!': function( a ) {
111 return ! a;
112 },
113 '*': function( a, b ) {
114 return a * b;
115 },
116 '/': function( a, b ) {
117 return a / b;
118 },
119 '%': function( a, b ) {
120 return a % b;
121 },
122 '+': function( a, b ) {
123 return a + b;
124 },
125 '-': function( a, b ) {
126 return a - b;
127 },
128 '<': function( a, b ) {
129 return a < b;
130 },
131 '<=': function( a, b ) {
132 return a <= b;
133 },
134 '>': function( a, b ) {
135 return a > b;
136 },
137 '>=': function( a, b ) {
138 return a >= b;
139 },
140 '==': function( a, b ) {
141 return a === b;
142 },
143 '!=': function( a, b ) {
144 return a !== b;
145 },
146 '&&': function( a, b ) {
147 return a && b;
148 },
149 '||': function( a, b ) {
150 return a || b;
151 },
152 '?:': function( a, b, c ) {
153 if ( a ) {
154 throw b;
155 }
156
157 return c;
158 },
159 };
160
161 /**
162 * Given an array of postfix terms and operand variables, returns the result of
163 * the postfix evaluation.
164 *
165 * @example
166 *
167 * ```js
168 * import evaluate from '@tannin/evaluate';
169 *
170 * // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +'
171 * const terms = [ '3', '4', '5', '*', '6', '/', '+' ];
172 *
173 * evaluate( terms, {} );
174 * // ⇒ 6.333333333333334
175 * ```
176 *
177 * @param {string[]} postfix Postfix terms.
178 * @param {Object} variables Operand variables.
179 *
180 * @return {*} Result of evaluation.
181 */
182 function evaluate( postfix, variables ) {
183 var stack = [],
184 i, j, args, getOperatorResult, term, value;
185
186 for ( i = 0; i < postfix.length; i++ ) {
187 term = postfix[ i ];
188
189 getOperatorResult = OPERATORS[ term ];
190 if ( getOperatorResult ) {
191 // Pop from stack by number of function arguments.
192 j = getOperatorResult.length;
193 args = Array( j );
194 while ( j-- ) {
195 args[ j ] = stack.pop();
196 }
197
198 try {
199 value = getOperatorResult.apply( null, args );
200 } catch ( earlyReturn ) {
201 return earlyReturn;
202 }
203 } else if ( variables.hasOwnProperty( term ) ) {
204 value = variables[ term ];
205 } else {
206 value = +term;
207 }
208
209 stack.push( value );
210 }
211
212 return stack[ 0 ];
213 }
214
215 module.exports = evaluate;
216
217 },{}],6:[function(require,module,exports){
218 'use strict';
219
220 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
221
222 var compile = _interopDefault(require('@tannin/compile'));
223
224 /**
225 * Given a C expression, returns a function which, when called with a value,
226 * evaluates the result with the value assumed to be the "n" variable of the
227 * expression. The result will be coerced to its numeric equivalent.
228 *
229 * @param {string} expression C expression.
230 *
231 * @return {Function} Evaluator function.
232 */
233 function pluralForms( expression ) {
234 var evaluate = compile( expression );
235
236 return function( n ) {
237 return +evaluate( { n: n } );
238 };
239 }
240
241 module.exports = pluralForms;
242
243 },{"@tannin/compile":4}],7:[function(require,module,exports){
244 'use strict';
245
246 var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
247
248 /**
249 * Operator precedence mapping.
250 *
251 * @type {Object}
252 */
253 PRECEDENCE = {
254 '(': 9,
255 '!': 8,
256 '*': 7,
257 '/': 7,
258 '%': 7,
259 '+': 6,
260 '-': 6,
261 '<': 5,
262 '<=': 5,
263 '>': 5,
264 '>=': 5,
265 '==': 4,
266 '!=': 4,
267 '&&': 3,
268 '||': 2,
269 '?': 1,
270 '?:': 1,
271 };
272
273 /**
274 * Characters which signal pair opening, to be terminated by terminators.
275 *
276 * @type {string[]}
277 */
278 OPENERS = [ '(', '?' ];
279
280 /**
281 * Characters which signal pair termination, the value an array with the
282 * opener as its first member. The second member is an optional operator
283 * replacement to push to the stack.
284 *
285 * @type {string[]}
286 */
287 TERMINATORS = {
288 ')': [ '(' ],
289 ':': [ '?', '?:' ],
290 };
291
292 /**
293 * Pattern matching operators and openers.
294 *
295 * @type {RegExp}
296 */
297 PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
298
299 /**
300 * Given a C expression, returns the equivalent postfix (Reverse Polish)
301 * notation terms as an array.
302 *
303 * If a postfix string is desired, simply `.join( ' ' )` the result.
304 *
305 * @example
306 *
307 * ```js
308 * import postfix from '@tannin/postfix';
309 *
310 * postfix( 'n > 1' );
311 * // ⇒ [ 'n', '1', '>' ]
312 * ```
313 *
314 * @param {string} expression C expression.
315 *
316 * @return {string[]} Postfix terms.
317 */
318 function postfix( expression ) {
319 var terms = [],
320 stack = [],
321 match, operator, term, element;
322
323 while ( ( match = expression.match( PATTERN ) ) ) {
324 operator = match[ 0 ];
325
326 // Term is the string preceding the operator match. It may contain
327 // whitespace, and may be empty (if operator is at beginning).
328 term = expression.substr( 0, match.index ).trim();
329 if ( term ) {
330 terms.push( term );
331 }
332
333 while ( ( element = stack.pop() ) ) {
334 if ( TERMINATORS[ operator ] ) {
335 if ( TERMINATORS[ operator ][ 0 ] === element ) {
336 // Substitution works here under assumption that because
337 // the assigned operator will no longer be a terminator, it
338 // will be pushed to the stack during the condition below.
339 operator = TERMINATORS[ operator ][ 1 ] || operator;
340 break;
341 }
342 } else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) {
343 // Push to stack if either an opener or when pop reveals an
344 // element of lower precedence.
345 stack.push( element );
346 break;
347 }
348
349 // For each popped from stack, push to terms.
350 terms.push( element );
351 }
352
353 if ( ! TERMINATORS[ operator ] ) {
354 stack.push( operator );
355 }
356
357 // Slice matched fragment from expression to continue match.
358 expression = expression.substr( match.index + operator.length );
359 }
360
361 // Push remainder of operand, if exists, to terms.
362 expression = expression.trim();
363 if ( expression ) {
364 terms.push( expression );
365 }
366
367 // Pop remaining items from stack into terms.
368 return terms.concat( stack.reverse() );
369 }
370
371 module.exports = postfix;
372
373 },{}],8:[function(require,module,exports){
374 "use strict";
375
376 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
377
378 Object.defineProperty(exports, "__esModule", {
379 value: true
380 });
381 exports.createI18n = void 0;
382
383 var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
384
385 var _tannin = _interopRequireDefault(require("tannin"));
386
387 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; }
388
389 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; }
390
391 /**
392 * @typedef {Record<string,any>} LocaleData
393 */
394
395 /**
396 * Default locale data to use for Tannin domain when not otherwise provided.
397 * Assumes an English plural forms expression.
398 *
399 * @type {LocaleData}
400 */
401 var DEFAULT_LOCALE_DATA = {
402 '': {
403 /** @param {number} n */
404 plural_forms: function plural_forms(n) {
405 return n === 1 ? 0 : 1;
406 }
407 }
408 };
409 /**
410 * An i18n instance
411 *
412 * @typedef {Object} I18n
413 * @property {Function} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a
414 * Jed-formatted JSON object shape.
415 * @property {Function} __ Retrieve the translation of text.
416 * @property {Function} _x Retrieve translated string with gettext context.
417 * @property {Function} _n Translates and retrieves the singular or plural form based on the supplied
418 * number.
419 * @property {Function} _nx Translates and retrieves the singular or plural form based on the supplied
420 * number, with gettext context.
421 * @property {Function} isRTL Check if current locale is RTL.
422 */
423
424 /**
425 * Create an i18n instance
426 *
427 * @param {LocaleData} [initialData] Locale data configuration.
428 * @param {string} [initialDomain] Domain for which configuration applies.
429 * @return {I18n} I18n instance
430 */
431
432 var createI18n = function createI18n(initialData, initialDomain) {
433 /**
434 * The underlying instance of Tannin to which exported functions interface.
435 *
436 * @type {Tannin}
437 */
438 var tannin = new _tannin.default({});
439 /**
440 * Merges locale data into the Tannin instance by domain. Accepts data in a
441 * Jed-formatted JSON object shape.
442 *
443 * @see http://messageformat.github.io/Jed/
444 *
445 * @param {LocaleData} [data] Locale data configuration.
446 * @param {string} [domain] Domain for which configuration applies.
447 */
448
449 var setLocaleData = function setLocaleData(data) {
450 var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
451 tannin.data[domain] = _objectSpread({}, DEFAULT_LOCALE_DATA, {}, tannin.data[domain], {}, data); // Populate default domain configuration (supported locale date which omits
452 // a plural forms expression).
453
454 tannin.data[domain][''] = _objectSpread({}, DEFAULT_LOCALE_DATA[''], {}, tannin.data[domain]['']);
455 };
456 /**
457 * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
458 * otherwise previously assigned.
459 *
460 * @param {string|undefined} domain Domain to retrieve the translated text.
461 * @param {string|undefined} context Context information for the translators.
462 * @param {string} single Text to translate if non-plural. Used as
463 * fallback return value on a caught error.
464 * @param {string} [plural] The text to be used if the number is
465 * plural.
466 * @param {number} [number] The number to compare against to use
467 * either the singular or plural form.
468 *
469 * @return {string} The translated string.
470 */
471
472
473 var dcnpgettext = function dcnpgettext() {
474 var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
475 var context = arguments.length > 1 ? arguments[1] : undefined;
476 var single = arguments.length > 2 ? arguments[2] : undefined;
477 var plural = arguments.length > 3 ? arguments[3] : undefined;
478 var number = arguments.length > 4 ? arguments[4] : undefined;
479
480 if (!tannin.data[domain]) {
481 setLocaleData(undefined, domain);
482 }
483
484 return tannin.dcnpgettext(domain, context, single, plural, number);
485 };
486 /**
487 * Retrieve the translation of text.
488 *
489 * @see https://developer.wordpress.org/reference/functions/__/
490 *
491 * @param {string} text Text to translate.
492 * @param {string} [domain] Domain to retrieve the translated text.
493 *
494 * @return {string} Translated text.
495 */
496
497
498 var __ = function __(text, domain) {
499 return dcnpgettext(domain, undefined, text);
500 };
501 /**
502 * Retrieve translated string with gettext context.
503 *
504 * @see https://developer.wordpress.org/reference/functions/_x/
505 *
506 * @param {string} text Text to translate.
507 * @param {string} context Context information for the translators.
508 * @param {string} [domain] Domain to retrieve the translated text.
509 *
510 * @return {string} Translated context string without pipe.
511 */
512
513
514 var _x = function _x(text, context, domain) {
515 return dcnpgettext(domain, context, text);
516 };
517 /**
518 * Translates and retrieves the singular or plural form based on the supplied
519 * number.
520 *
521 * @see https://developer.wordpress.org/reference/functions/_n/
522 *
523 * @param {string} single The text to be used if the number is singular.
524 * @param {string} plural The text to be used if the number is plural.
525 * @param {number} number The number to compare against to use either the
526 * singular or plural form.
527 * @param {string} [domain] Domain to retrieve the translated text.
528 *
529 * @return {string} The translated singular or plural form.
530 */
531
532
533 var _n = function _n(single, plural, number, domain) {
534 return dcnpgettext(domain, undefined, single, plural, number);
535 };
536 /**
537 * Translates and retrieves the singular or plural form based on the supplied
538 * number, with gettext context.
539 *
540 * @see https://developer.wordpress.org/reference/functions/_nx/
541 *
542 * @param {string} single The text to be used if the number is singular.
543 * @param {string} plural The text to be used if the number is plural.
544 * @param {number} number The number to compare against to use either the
545 * singular or plural form.
546 * @param {string} context Context information for the translators.
547 * @param {string} [domain] Domain to retrieve the translated text.
548 *
549 * @return {string} The translated singular or plural form.
550 */
551
552
553 var _nx = function _nx(single, plural, number, context, domain) {
554 return dcnpgettext(domain, context, single, plural, number);
555 };
556 /**
557 * Check if current locale is RTL.
558 *
559 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
560 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
561 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
562 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
563 *
564 * @return {boolean} Whether locale is RTL.
565 */
566
567
568 var isRTL = function isRTL() {
569 return 'rtl' === _x('ltr', 'text direction');
570 };
571
572 if (initialData) {
573 setLocaleData(initialData, initialDomain);
574 }
575
576 return {
577 setLocaleData: setLocaleData,
578 __: __,
579 _x: _x,
580 _n: _n,
581 _nx: _nx,
582 isRTL: isRTL
583 };
584 };
585
586 exports.createI18n = createI18n;
587
588 },{"@babel/runtime/helpers/defineProperty":2,"@babel/runtime/helpers/interopRequireDefault":3,"tannin":15}],9:[function(require,module,exports){
589 "use strict";
590
591 Object.defineProperty(exports, "__esModule", {
592 value: true
593 });
594 exports.isRTL = exports._nx = exports._n = exports._x = exports.__ = exports.setLocaleData = void 0;
595
596 var _createI18n = require("./create-i18n");
597
598 /**
599 * Internal dependencies
600 */
601 var i18n = (0, _createI18n.createI18n)();
602 /*
603 * Comments in this file are duplicated from ./i18n due to
604 * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
605 */
606
607 /**
608 * @typedef {import('./create-i18n').LocaleData} LocaleData
609 */
610
611 /**
612 * Merges locale data into the Tannin instance by domain. Accepts data in a
613 * Jed-formatted JSON object shape.
614 *
615 * @see http://messageformat.github.io/Jed/
616 *
617 * @param {LocaleData} [data] Locale data configuration.
618 * @param {string} [domain] Domain for which configuration applies.
619 */
620
621 var setLocaleData = i18n.setLocaleData.bind(i18n);
622 /**
623 * Retrieve the translation of text.
624 *
625 * @see https://developer.wordpress.org/reference/functions/__/
626 *
627 * @param {string} text Text to translate.
628 * @param {string} [domain] Domain to retrieve the translated text.
629 *
630 * @return {string} Translated text.
631 */
632
633 exports.setLocaleData = setLocaleData;
634
635 var __ = i18n.__.bind(i18n);
636 /**
637 * Retrieve translated string with gettext context.
638 *
639 * @see https://developer.wordpress.org/reference/functions/_x/
640 *
641 * @param {string} text Text to translate.
642 * @param {string} context Context information for the translators.
643 * @param {string} [domain] Domain to retrieve the translated text.
644 *
645 * @return {string} Translated context string without pipe.
646 */
647
648
649 exports.__ = __;
650
651 var _x = i18n._x.bind(i18n);
652 /**
653 * Translates and retrieves the singular or plural form based on the supplied
654 * number.
655 *
656 * @see https://developer.wordpress.org/reference/functions/_n/
657 *
658 * @param {string} single The text to be used if the number is singular.
659 * @param {string} plural The text to be used if the number is plural.
660 * @param {number} number The number to compare against to use either the
661 * singular or plural form.
662 * @param {string} [domain] Domain to retrieve the translated text.
663 *
664 * @return {string} The translated singular or plural form.
665 */
666
667
668 exports._x = _x;
669
670 var _n = i18n._n.bind(i18n);
671 /**
672 * Translates and retrieves the singular or plural form based on the supplied
673 * number, with gettext context.
674 *
675 * @see https://developer.wordpress.org/reference/functions/_nx/
676 *
677 * @param {string} single The text to be used if the number is singular.
678 * @param {string} plural The text to be used if the number is plural.
679 * @param {number} number The number to compare against to use either the
680 * singular or plural form.
681 * @param {string} context Context information for the translators.
682 * @param {string} [domain] Domain to retrieve the translated text.
683 *
684 * @return {string} The translated singular or plural form.
685 */
686
687
688 exports._n = _n;
689
690 var _nx = i18n._nx.bind(i18n);
691 /**
692 * Check if current locale is RTL.
693 *
694 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
695 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
696 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
697 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
698 *
699 * @return {boolean} Whether locale is RTL.
700 */
701
702
703 exports._nx = _nx;
704 var isRTL = i18n.isRTL.bind(i18n);
705 exports.isRTL = isRTL;
706
707 },{"./create-i18n":8}],10:[function(require,module,exports){
708 "use strict";
709
710 Object.defineProperty(exports, "__esModule", {
711 value: true
712 });
713 var _exportNames = {
714 sprintf: true,
715 setLocaleData: true,
716 __: true,
717 _x: true,
718 _n: true,
719 _nx: true,
720 isRTL: true
721 };
722 Object.defineProperty(exports, "sprintf", {
723 enumerable: true,
724 get: function get() {
725 return _sprintf.sprintf;
726 }
727 });
728 Object.defineProperty(exports, "setLocaleData", {
729 enumerable: true,
730 get: function get() {
731 return _defaultI18n.setLocaleData;
732 }
733 });
734 Object.defineProperty(exports, "__", {
735 enumerable: true,
736 get: function get() {
737 return _defaultI18n.__;
738 }
739 });
740 Object.defineProperty(exports, "_x", {
741 enumerable: true,
742 get: function get() {
743 return _defaultI18n._x;
744 }
745 });
746 Object.defineProperty(exports, "_n", {
747 enumerable: true,
748 get: function get() {
749 return _defaultI18n._n;
750 }
751 });
752 Object.defineProperty(exports, "_nx", {
753 enumerable: true,
754 get: function get() {
755 return _defaultI18n._nx;
756 }
757 });
758 Object.defineProperty(exports, "isRTL", {
759 enumerable: true,
760 get: function get() {
761 return _defaultI18n.isRTL;
762 }
763 });
764
765 var _sprintf = require("./sprintf");
766
767 var _createI18n = require("./create-i18n");
768
769 Object.keys(_createI18n).forEach(function (key) {
770 if (key === "default" || key === "__esModule") return;
771 if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
772 Object.defineProperty(exports, key, {
773 enumerable: true,
774 get: function get() {
775 return _createI18n[key];
776 }
777 });
778 });
779
780 var _defaultI18n = require("./default-i18n");
781
782 },{"./create-i18n":8,"./default-i18n":9,"./sprintf":11}],11:[function(require,module,exports){
783 "use strict";
784
785 var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
786
787 Object.defineProperty(exports, "__esModule", {
788 value: true
789 });
790 exports.sprintf = sprintf;
791
792 var _memize = _interopRequireDefault(require("memize"));
793
794 var _sprintfJs = _interopRequireDefault(require("sprintf-js"));
795
796 /**
797 * External dependencies
798 */
799
800 /**
801 * Log to console, once per message; or more precisely, per referentially equal
802 * argument set. Because Jed throws errors, we log these to the console instead
803 * to avoid crashing the application.
804 *
805 * @param {...*} args Arguments to pass to `console.error`
806 */
807 var logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console
808
809 /**
810 * Returns a formatted string. If an error occurs in applying the format, the
811 * original format string is returned.
812 *
813 * @param {string} format The format of the string to generate.
814 * @param {...*} args Arguments to apply to the format.
815 *
816 * @see http://www.diveintojavascript.com/projects/javascript-sprintf
817 *
818 * @return {string} The formatted string.
819 */
820
821 function sprintf(format) {
822 try {
823 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
824 args[_key - 1] = arguments[_key];
825 }
826
827 return _sprintfJs.default.sprintf.apply(_sprintfJs.default, [format].concat(args));
828 } catch (error) {
829 logErrorOnce('sprintf error: \n\n' + error.toString());
830 return format;
831 }
832 }
833
834 },{"@babel/runtime/helpers/interopRequireDefault":3,"memize":13,"sprintf-js":12}],12:[function(require,module,exports){
835 /* global window, exports, define */
836
837 !function() {
838 'use strict'
839
840 var re = {
841 not_string: /[^s]/,
842 not_bool: /[^t]/,
843 not_type: /[^T]/,
844 not_primitive: /[^v]/,
845 number: /[diefg]/,
846 numeric_arg: /[bcdiefguxX]/,
847 json: /[j]/,
848 not_json: /[^j]/,
849 text: /^[^\x25]+/,
850 modulo: /^\x25{2}/,
851 placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
852 key: /^([a-z_][a-z_\d]*)/i,
853 key_access: /^\.([a-z_][a-z_\d]*)/i,
854 index_access: /^\[(\d+)\]/,
855 sign: /^[+-]/
856 }
857
858 function sprintf(key) {
859 // `arguments` is not an array, but should be fine for this call
860 return sprintf_format(sprintf_parse(key), arguments)
861 }
862
863 function vsprintf(fmt, argv) {
864 return sprintf.apply(null, [fmt].concat(argv || []))
865 }
866
867 function sprintf_format(parse_tree, argv) {
868 var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
869 for (i = 0; i < tree_length; i++) {
870 if (typeof parse_tree[i] === 'string') {
871 output += parse_tree[i]
872 }
873 else if (typeof parse_tree[i] === 'object') {
874 ph = parse_tree[i] // convenience purposes only
875 if (ph.keys) { // keyword argument
876 arg = argv[cursor]
877 for (k = 0; k < ph.keys.length; k++) {
878 if (arg == undefined) {
879 throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
880 }
881 arg = arg[ph.keys[k]]
882 }
883 }
884 else if (ph.param_no) { // positional argument (explicit)
885 arg = argv[ph.param_no]
886 }
887 else { // positional argument (implicit)
888 arg = argv[cursor++]
889 }
890
891 if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
892 arg = arg()
893 }
894
895 if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
896 throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
897 }
898
899 if (re.number.test(ph.type)) {
900 is_positive = arg >= 0
901 }
902
903 switch (ph.type) {
904 case 'b':
905 arg = parseInt(arg, 10).toString(2)
906 break
907 case 'c':
908 arg = String.fromCharCode(parseInt(arg, 10))
909 break
910 case 'd':
911 case 'i':
912 arg = parseInt(arg, 10)
913 break
914 case 'j':
915 arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
916 break
917 case 'e':
918 arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
919 break
920 case 'f':
921 arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
922 break
923 case 'g':
924 arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
925 break
926 case 'o':
927 arg = (parseInt(arg, 10) >>> 0).toString(8)
928 break
929 case 's':
930 arg = String(arg)
931 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
932 break
933 case 't':
934 arg = String(!!arg)
935 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
936 break
937 case 'T':
938 arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
939 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
940 break
941 case 'u':
942 arg = parseInt(arg, 10) >>> 0
943 break
944 case 'v':
945 arg = arg.valueOf()
946 arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
947 break
948 case 'x':
949 arg = (parseInt(arg, 10) >>> 0).toString(16)
950 break
951 case 'X':
952 arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
953 break
954 }
955 if (re.json.test(ph.type)) {
956 output += arg
957 }
958 else {
959 if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
960 sign = is_positive ? '+' : '-'
961 arg = arg.toString().replace(re.sign, '')
962 }
963 else {
964 sign = ''
965 }
966 pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
967 pad_length = ph.width - (sign + arg).length
968 pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
969 output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
970 }
971 }
972 }
973 return output
974 }
975
976 var sprintf_cache = Object.create(null)
977
978 function sprintf_parse(fmt) {
979 if (sprintf_cache[fmt]) {
980 return sprintf_cache[fmt]
981 }
982
983 var _fmt = fmt, match, parse_tree = [], arg_names = 0
984 while (_fmt) {
985 if ((match = re.text.exec(_fmt)) !== null) {
986 parse_tree.push(match[0])
987 }
988 else if ((match = re.modulo.exec(_fmt)) !== null) {
989 parse_tree.push('%')
990 }
991 else if ((match = re.placeholder.exec(_fmt)) !== null) {
992 if (match[2]) {
993 arg_names |= 1
994 var field_list = [], replacement_field = match[2], field_match = []
995 if ((field_match = re.key.exec(replacement_field)) !== null) {
996 field_list.push(field_match[1])
997 while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
998 if ((field_match = re.key_access.exec(replacement_field)) !== null) {
999 field_list.push(field_match[1])
1000 }
1001 else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
1002 field_list.push(field_match[1])
1003 }
1004 else {
1005 throw new SyntaxError('[sprintf] failed to parse named argument key')
1006 }
1007 }
1008 }
1009 else {
1010 throw new SyntaxError('[sprintf] failed to parse named argument key')
1011 }
1012 match[2] = field_list
1013 }
1014 else {
1015 arg_names |= 2
1016 }
1017 if (arg_names === 3) {
1018 throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
1019 }
1020
1021 parse_tree.push(
1022 {
1023 placeholder: match[0],
1024 param_no: match[1],
1025 keys: match[2],
1026 sign: match[3],
1027 pad_char: match[4],
1028 align: match[5],
1029 width: match[6],
1030 precision: match[7],
1031 type: match[8]
1032 }
1033 )
1034 }
1035 else {
1036 throw new SyntaxError('[sprintf] unexpected placeholder')
1037 }
1038 _fmt = _fmt.substring(match[0].length)
1039 }
1040 return sprintf_cache[fmt] = parse_tree
1041 }
1042
1043 /**
1044 * export to either browser or node.js
1045 */
1046 /* eslint-disable quote-props */
1047 if (typeof exports !== 'undefined') {
1048 exports['sprintf'] = sprintf
1049 exports['vsprintf'] = vsprintf
1050 }
1051 if (typeof window !== 'undefined') {
1052 window['sprintf'] = sprintf
1053 window['vsprintf'] = vsprintf
1054
1055 if (typeof define === 'function' && define['amd']) {
1056 define(function() {
1057 return {
1058 'sprintf': sprintf,
1059 'vsprintf': vsprintf
1060 }
1061 })
1062 }
1063 }
1064 /* eslint-enable quote-props */
1065 }(); // eslint-disable-line
1066
1067 },{}],13:[function(require,module,exports){
1068 (function (process){
1069 /**
1070 * Memize options object.
1071 *
1072 * @typedef MemizeOptions
1073 *
1074 * @property {number} [maxSize] Maximum size of the cache.
1075 */
1076
1077 /**
1078 * Internal cache entry.
1079 *
1080 * @typedef MemizeCacheNode
1081 *
1082 * @property {?MemizeCacheNode|undefined} [prev] Previous node.
1083 * @property {?MemizeCacheNode|undefined} [next] Next node.
1084 * @property {Array<*>} args Function arguments for cache
1085 * entry.
1086 * @property {*} val Function result.
1087 */
1088
1089 /**
1090 * Properties of the enhanced function for controlling cache.
1091 *
1092 * @typedef MemizeMemoizedFunction
1093 *
1094 * @property {()=>void} clear Clear the cache.
1095 */
1096
1097 /**
1098 * Accepts a function to be memoized, and returns a new memoized function, with
1099 * optional options.
1100 *
1101 * @template {Function} F
1102 *
1103 * @param {F} fn Function to memoize.
1104 * @param {MemizeOptions} [options] Options object.
1105 *
1106 * @return {F & MemizeMemoizedFunction} Memoized function.
1107 */
1108 function memize( fn, options ) {
1109 var size = 0;
1110
1111 /** @type {?MemizeCacheNode|undefined} */
1112 var head;
1113
1114 /** @type {?MemizeCacheNode|undefined} */
1115 var tail;
1116
1117 options = options || {};
1118
1119 function memoized( /* ...args */ ) {
1120 var node = head,
1121 len = arguments.length,
1122 args, i;
1123
1124 searchCache: while ( node ) {
1125 // Perform a shallow equality test to confirm that whether the node
1126 // under test is a candidate for the arguments passed. Two arrays
1127 // are shallowly equal if their length matches and each entry is
1128 // strictly equal between the two sets. Avoid abstracting to a
1129 // function which could incur an arguments leaking deoptimization.
1130
1131 // Check whether node arguments match arguments length
1132 if ( node.args.length !== arguments.length ) {
1133 node = node.next;
1134 continue;
1135 }
1136
1137 // Check whether node arguments match arguments values
1138 for ( i = 0; i < len; i++ ) {
1139 if ( node.args[ i ] !== arguments[ i ] ) {
1140 node = node.next;
1141 continue searchCache;
1142 }
1143 }
1144
1145 // At this point we can assume we've found a match
1146
1147 // Surface matched node to head if not already
1148 if ( node !== head ) {
1149 // As tail, shift to previous. Must only shift if not also
1150 // head, since if both head and tail, there is no previous.
1151 if ( node === tail ) {
1152 tail = node.prev;
1153 }
1154
1155 // Adjust siblings to point to each other. If node was tail,
1156 // this also handles new tail's empty `next` assignment.
1157 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
1158 if ( node.next ) {
1159 node.next.prev = node.prev;
1160 }
1161
1162 node.next = head;
1163 node.prev = null;
1164 /** @type {MemizeCacheNode} */ ( head ).prev = node;
1165 head = node;
1166 }
1167
1168 // Return immediately
1169 return node.val;
1170 }
1171
1172 // No cached value found. Continue to insertion phase:
1173
1174 // Create a copy of arguments (avoid leaking deoptimization)
1175 args = new Array( len );
1176 for ( i = 0; i < len; i++ ) {
1177 args[ i ] = arguments[ i ];
1178 }
1179
1180 node = {
1181 args: args,
1182
1183 // Generate the result from original function
1184 val: fn.apply( null, args ),
1185 };
1186
1187 // Don't need to check whether node is already head, since it would
1188 // have been returned above already if it was
1189
1190 // Shift existing head down list
1191 if ( head ) {
1192 head.prev = node;
1193 node.next = head;
1194 } else {
1195 // If no head, follows that there's no tail (at initial or reset)
1196 tail = node;
1197 }
1198
1199 // Trim tail if we're reached max size and are pending cache insertion
1200 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
1201 tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
1202 /** @type {MemizeCacheNode} */ ( tail ).next = null;
1203 } else {
1204 size++;
1205 }
1206
1207 head = node;
1208
1209 return node.val;
1210 }
1211
1212 memoized.clear = function() {
1213 head = null;
1214 tail = null;
1215 size = 0;
1216 };
1217
1218 if ( process.env.NODE_ENV === 'test' ) {
1219 // Cache is not exposed in the public API, but used in tests to ensure
1220 // expected list progression
1221 memoized.getCache = function() {
1222 return [ head, tail, size ];
1223 };
1224 }
1225
1226 // Ignore reason: There's not a clear solution to create an intersection of
1227 // the function with additional properties, where the goal is to retain the
1228 // function signature of the incoming argument and add control properties
1229 // on the return value.
1230
1231 // @ts-ignore
1232 return memoized;
1233 }
1234
1235 module.exports = memize;
1236
1237 }).call(this,require('_process'))
1238 },{"_process":14}],14:[function(require,module,exports){
1239 // shim for using process in browser
1240 var process = module.exports = {};
1241
1242 // cached from whatever global is present so that test runners that stub it
1243 // don't break things. But we need to wrap it in a try catch in case it is
1244 // wrapped in strict mode code which doesn't define any globals. It's inside a
1245 // function because try/catches deoptimize in certain engines.
1246
1247 var cachedSetTimeout;
1248 var cachedClearTimeout;
1249
1250 function defaultSetTimout() {
1251 throw new Error('setTimeout has not been defined');
1252 }
1253 function defaultClearTimeout () {
1254 throw new Error('clearTimeout has not been defined');
1255 }
1256 (function () {
1257 try {
1258 if (typeof setTimeout === 'function') {
1259 cachedSetTimeout = setTimeout;
1260 } else {
1261 cachedSetTimeout = defaultSetTimout;
1262 }
1263 } catch (e) {
1264 cachedSetTimeout = defaultSetTimout;
1265 }
1266 try {
1267 if (typeof clearTimeout === 'function') {
1268 cachedClearTimeout = clearTimeout;
1269 } else {
1270 cachedClearTimeout = defaultClearTimeout;
1271 }
1272 } catch (e) {
1273 cachedClearTimeout = defaultClearTimeout;
1274 }
1275 } ())
1276 function runTimeout(fun) {
1277 if (cachedSetTimeout === setTimeout) {
1278 //normal enviroments in sane situations
1279 return setTimeout(fun, 0);
1280 }
1281 // if setTimeout wasn't available but was latter defined
1282 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
1283 cachedSetTimeout = setTimeout;
1284 return setTimeout(fun, 0);
1285 }
1286 try {
1287 // when when somebody has screwed with setTimeout but no I.E. maddness
1288 return cachedSetTimeout(fun, 0);
1289 } catch(e){
1290 try {
1291 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1292 return cachedSetTimeout.call(null, fun, 0);
1293 } catch(e){
1294 // 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
1295 return cachedSetTimeout.call(this, fun, 0);
1296 }
1297 }
1298
1299
1300 }
1301 function runClearTimeout(marker) {
1302 if (cachedClearTimeout === clearTimeout) {
1303 //normal enviroments in sane situations
1304 return clearTimeout(marker);
1305 }
1306 // if clearTimeout wasn't available but was latter defined
1307 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
1308 cachedClearTimeout = clearTimeout;
1309 return clearTimeout(marker);
1310 }
1311 try {
1312 // when when somebody has screwed with setTimeout but no I.E. maddness
1313 return cachedClearTimeout(marker);
1314 } catch (e){
1315 try {
1316 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1317 return cachedClearTimeout.call(null, marker);
1318 } catch (e){
1319 // 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.
1320 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
1321 return cachedClearTimeout.call(this, marker);
1322 }
1323 }
1324
1325
1326
1327 }
1328 var queue = [];
1329 var draining = false;
1330 var currentQueue;
1331 var queueIndex = -1;
1332
1333 function cleanUpNextTick() {
1334 if (!draining || !currentQueue) {
1335 return;
1336 }
1337 draining = false;
1338 if (currentQueue.length) {
1339 queue = currentQueue.concat(queue);
1340 } else {
1341 queueIndex = -1;
1342 }
1343 if (queue.length) {
1344 drainQueue();
1345 }
1346 }
1347
1348 function drainQueue() {
1349 if (draining) {
1350 return;
1351 }
1352 var timeout = runTimeout(cleanUpNextTick);
1353 draining = true;
1354
1355 var len = queue.length;
1356 while(len) {
1357 currentQueue = queue;
1358 queue = [];
1359 while (++queueIndex < len) {
1360 if (currentQueue) {
1361 currentQueue[queueIndex].run();
1362 }
1363 }
1364 queueIndex = -1;
1365 len = queue.length;
1366 }
1367 currentQueue = null;
1368 draining = false;
1369 runClearTimeout(timeout);
1370 }
1371
1372 process.nextTick = function (fun) {
1373 var args = new Array(arguments.length - 1);
1374 if (arguments.length > 1) {
1375 for (var i = 1; i < arguments.length; i++) {
1376 args[i - 1] = arguments[i];
1377 }
1378 }
1379 queue.push(new Item(fun, args));
1380 if (queue.length === 1 && !draining) {
1381 runTimeout(drainQueue);
1382 }
1383 };
1384
1385 // v8 likes predictible objects
1386 function Item(fun, array) {
1387 this.fun = fun;
1388 this.array = array;
1389 }
1390 Item.prototype.run = function () {
1391 this.fun.apply(null, this.array);
1392 };
1393 process.title = 'browser';
1394 process.browser = true;
1395 process.env = {};
1396 process.argv = [];
1397 process.version = ''; // empty string to avoid regexp issues
1398 process.versions = {};
1399
1400 function noop() {}
1401
1402 process.on = noop;
1403 process.addListener = noop;
1404 process.once = noop;
1405 process.off = noop;
1406 process.removeListener = noop;
1407 process.removeAllListeners = noop;
1408 process.emit = noop;
1409 process.prependListener = noop;
1410 process.prependOnceListener = noop;
1411
1412 process.listeners = function (name) { return [] }
1413
1414 process.binding = function (name) {
1415 throw new Error('process.binding is not supported');
1416 };
1417
1418 process.cwd = function () { return '/' };
1419 process.chdir = function (dir) {
1420 throw new Error('process.chdir is not supported');
1421 };
1422 process.umask = function() { return 0; };
1423
1424 },{}],15:[function(require,module,exports){
1425 'use strict';
1426
1427 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
1428
1429 var pluralForms = _interopDefault(require('@tannin/plural-forms'));
1430
1431 /**
1432 * Tannin constructor options.
1433 *
1434 * @typedef {Object} TanninOptions
1435 *
1436 * @property {string} [contextDelimiter] Joiner in string lookup with context.
1437 * @property {Function} [onMissingKey] Callback to invoke when key missing.
1438 */
1439
1440 /**
1441 * Domain metadata.
1442 *
1443 * @typedef {Object} TanninDomainMetadata
1444 *
1445 * @property {string} [domain] Domain name.
1446 * @property {string} [lang] Language code.
1447 * @property {(string|Function)} [plural_forms] Plural forms expression or
1448 * function evaluator.
1449 */
1450
1451 /**
1452 * Domain translation pair respectively representing the singular and plural
1453 * translation.
1454 *
1455 * @typedef {[string,string]} TanninTranslation
1456 */
1457
1458 /**
1459 * Locale data domain. The key is used as reference for lookup, the value an
1460 * array of two string entries respectively representing the singular and plural
1461 * translation.
1462 *
1463 * @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
1464 */
1465
1466 /**
1467 * Jed-formatted locale data.
1468 *
1469 * @see http://messageformat.github.io/Jed/
1470 *
1471 * @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
1472 */
1473
1474 /**
1475 * Default Tannin constructor options.
1476 *
1477 * @type {TanninOptions}
1478 */
1479 var DEFAULT_OPTIONS = {
1480 contextDelimiter: '\u0004',
1481 onMissingKey: null,
1482 };
1483
1484 /**
1485 * Given a specific locale data's config `plural_forms` value, returns the
1486 * expression.
1487 *
1488 * @example
1489 *
1490 * ```
1491 * getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
1492 * ```
1493 *
1494 * @param {string} pf Locale data plural forms.
1495 *
1496 * @return {string} Plural forms expression.
1497 */
1498 function getPluralExpression( pf ) {
1499 var parts, i, part;
1500
1501 parts = pf.split( ';' );
1502
1503 for ( i = 0; i < parts.length; i++ ) {
1504 part = parts[ i ].trim();
1505 if ( part.indexOf( 'plural=' ) === 0 ) {
1506 return part.substr( 7 );
1507 }
1508 }
1509 }
1510
1511 /**
1512 * Tannin constructor.
1513 *
1514 * @class
1515 *
1516 * @param {TanninLocaleData} data Jed-formatted locale data.
1517 * @param {TanninOptions} [options] Tannin options.
1518 */
1519 function Tannin( data, options ) {
1520 var key;
1521
1522 /**
1523 * Jed-formatted locale data.
1524 *
1525 * @name Tannin#data
1526 * @type {TanninLocaleData}
1527 */
1528 this.data = data;
1529
1530 /**
1531 * Plural forms function cache, keyed by plural forms string.
1532 *
1533 * @name Tannin#pluralForms
1534 * @type {Object<string,Function>}
1535 */
1536 this.pluralForms = {};
1537
1538 /**
1539 * Effective options for instance, including defaults.
1540 *
1541 * @name Tannin#options
1542 * @type {TanninOptions}
1543 */
1544 this.options = {};
1545
1546 for ( key in DEFAULT_OPTIONS ) {
1547 this.options[ key ] = options !== undefined && key in options
1548 ? options[ key ]
1549 : DEFAULT_OPTIONS[ key ];
1550 }
1551 }
1552
1553 /**
1554 * Returns the plural form index for the given domain and value.
1555 *
1556 * @param {string} domain Domain on which to calculate plural form.
1557 * @param {number} n Value for which plural form is to be calculated.
1558 *
1559 * @return {number} Plural form index.
1560 */
1561 Tannin.prototype.getPluralForm = function( domain, n ) {
1562 var getPluralForm = this.pluralForms[ domain ],
1563 config, plural, pf;
1564
1565 if ( ! getPluralForm ) {
1566 config = this.data[ domain ][ '' ];
1567
1568 pf = (
1569 config[ 'Plural-Forms' ] ||
1570 config[ 'plural-forms' ] ||
1571 // Ignore reason: As known, there's no way to document the empty
1572 // string property on a key to guarantee this as metadata.
1573 // @ts-ignore
1574 config.plural_forms
1575 );
1576
1577 if ( typeof pf !== 'function' ) {
1578 plural = getPluralExpression(
1579 config[ 'Plural-Forms' ] ||
1580 config[ 'plural-forms' ] ||
1581 // Ignore reason: As known, there's no way to document the empty
1582 // string property on a key to guarantee this as metadata.
1583 // @ts-ignore
1584 config.plural_forms
1585 );
1586
1587 pf = pluralForms( plural );
1588 }
1589
1590 getPluralForm = this.pluralForms[ domain ] = pf;
1591 }
1592
1593 return getPluralForm( n );
1594 };
1595
1596 /**
1597 * Translate a string.
1598 *
1599 * @param {string} domain Translation domain.
1600 * @param {string|void} context Context distinguishing terms of the same name.
1601 * @param {string} singular Primary key for translation lookup.
1602 * @param {string=} plural Fallback value used for non-zero plural
1603 * form index.
1604 * @param {number=} n Value to use in calculating plural form.
1605 *
1606 * @return {string} Translated string.
1607 */
1608 Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
1609 var index, key, entry;
1610
1611 if ( n === undefined ) {
1612 // Default to singular.
1613 index = 0;
1614 } else {
1615 // Find index by evaluating plural form for value.
1616 index = this.getPluralForm( domain, n );
1617 }
1618
1619 key = singular;
1620
1621 // If provided, context is prepended to key with delimiter.
1622 if ( context ) {
1623 key = context + this.options.contextDelimiter + singular;
1624 }
1625
1626 entry = this.data[ domain ][ key ];
1627
1628 // Verify not only that entry exists, but that the intended index is within
1629 // range and non-empty.
1630 if ( entry && entry[ index ] ) {
1631 return entry[ index ];
1632 }
1633
1634 if ( this.options.onMissingKey ) {
1635 this.options.onMissingKey( singular, domain );
1636 }
1637
1638 // If entry not found, fall back to singular vs. plural with zero index
1639 // representing the singular value.
1640 return index === 0 ? singular : plural;
1641 };
1642
1643 module.exports = Tannin;
1644
1645 },{"@tannin/plural-forms":6}]},{},[1]);
1646