fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

42
node_modules/tannin/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,42 @@
## 1.2.0 (2020-03-07)
New Features
- Add TypeScript definitions
## 1.1.1 (2019-11-27)
Internal
- Update project inter-dependencies
## 1.1.0 (2019-03-07)
New Features
- Domain `plural_forms` can now be passed as a function.
Internal
- Add `repository.directory` to `package.json`
## 1.0.2 (2019-01-19)
Documentation
- Correct documentation unpkg links
Internal
- Use Lerna for managing mono-repo
## 1.0.1 (2018-11-04)
Bug Fixes
- Fix global constructor name from `new tannin` to corrected `new Tannin` in browser distributions.
- Fix dependencies pointers from local filesystem to npm copies.
## 1.0.0 (2018-11-04)
- Initial release

7
node_modules/tannin/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,7 @@
[The MIT License (MIT)](https://opensource.org/licenses/MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

142
node_modules/tannin/README.md generated vendored Normal file
View File

@@ -0,0 +1,142 @@
Tannin
======
Tannin is a [gettext](https://www.gnu.org/software/gettext/) localization library.
Inspired by [Jed](https://github.com/messageformat/Jed), it is built to be largely compatible with Jed-formatted locale data, and even offers a [Jed drop-in replacement compatibility shim](#jed-compatibility) to easily convert an existing project. Contrasted with Jed, it is more heavily optimized for performance and bundle size. While Jed works well with one-off translations, it suffers in single-page applications with repeated rendering of elements. Using Tannin, you can expect a bundle size **20% that of Jed** (**980 bytes gzipped**) and upwards of **330x better performance** ([see benchmarks](#benchmarks)). It does so without sacrificing the safety of plural forms evaluation, using a hand-crafted expression parser in place of the verbose compiled grammar included in Jed.
Furthermore, the project is architected as a mono-repo, published on npm under the `@tannin` scope. These modules can be used standalone, with or without Tannin. For example, you may find value in [`@tannin/compile`](https://www.npmjs.com/package/@tannin/compile) for creating an expression evaluator, or [`@tannin/sprintf`](https://www.npmjs.com/package/@tannin/sprintf) as a minimal [printf](https://en.wikipedia.org/wiki/Printf_format_string) string formatter.
The following modules are available:
- [`tannin`](https://www.npmjs.com/package/tannin)
- [`@tannin/compat`](https://www.npmjs.com/package/@tannin/compat)
- [`@tannin/compile`](https://www.npmjs.com/package/@tannin/compile)
- [`@tannin/evaluate`](https://www.npmjs.com/package/@tannin/evaluate)
- [`@tannin/plural-forms`](https://www.npmjs.com/package/@tannin/plural-forms)
- [`@tannin/compat`](https://www.npmjs.com/package/@tannin/compat)
- [`@tannin/postfix`](https://www.npmjs.com/package/@tannin/postfix)
- [`@tannin/sprintf`](https://www.npmjs.com/package/@tannin/sprintf)
## Installation
Using [npm](https://www.npmjs.com/) as a package manager:
```
npm install tannin
```
Otherwise, download a pre-built copy from unpkg:
[https://unpkg.com/tannin/dist/tannin.min.js](https://unpkg.com/tannin/dist/tannin.min.js)
## Usage
Construct a new instance of `Tannin`, passing locale data in the form of a [Jed-formatted JSON object](http://messageformat.github.io/Jed/).
The returned `Tannin` instance includes the fully-qualified `dcnpgettext` function to retrieve a translated string.
```js
import Tannin from 'tannin';
const i18n = new Tannin( {
the_domain: {
'': {
domain: 'the_domain',
lang: 'en',
plural_forms: 'nplurals=2; plural=(n != 1);',
},
example: [ 'singular translation', 'plural translation' ],
},
} );
i18n.dcnpgettext( 'the_domain', undefined, 'example' );
// ⇒ 'singular translation'
```
Tannin accepts `plural_forms` both as a standard [gettext plural forms string](https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html) or as a function which, given a number, should return the (zero-based) plural form index. Providing `plural_forms` as a function can yield a performance gain of approximately 8x for plural evaluation.
For example, consider the following "default" English (untranslated) initialization:
```js
const i18n = new Tannin( {
messages: {
'': {
domain: 'messages',
plural_forms: ( n ) => n === 1 ? 0 : 1,
},
},
} );
i18n.dcnpgettext( 'messages', undefined, 'example', 'examples', 1 );
// ⇒ 'example'
i18n.dcnpgettext( 'messages', undefined, 'example', 'examples', 2 );
// ⇒ 'examples'
```
## Jed Compatibility
For a more human-friendly API, or to more easily transition an existing project, consider using [`@tannin/compat`](https://www.npmjs.com/package/@tannin/compat) as a drop-in replacement for Jed.
```js
import Jed from '@tannin/compat';
const i18n = new Jed( {
locale_data: {
the_domain: {
'': {
domain: 'the_domain',
lang: 'en',
plural_forms: 'nplurals=2; plural=(n != 1);',
},
example: [ 'singular translation', 'plural translation' ],
},
},
domain: 'the_domain',
} );
i18n.translate( 'example' ).fetch();
// ⇒ 'singular translation'
```
## Benchmarks
The following benchmarks are performed in Node 10.16.0 on a MacBook Pro (2019), 2.4 GHz 8-Core Intel Core i9, 32 GB 2400 MHz DDR4 RAM.
```
Singular
---
Tannin x 216,670,213 ops/sec ±0.73% (90 runs sampled)
Tannin (Optimized Default) x 219,477,869 ops/sec ±0.32% (96 runs sampled)
Jed x 58,730,499 ops/sec ±0.34% (96 runs sampled)
Singular (Untranslated)
---
Tannin x 75,835,743 ops/sec ±1.26% (96 runs sampled)
Tannin (Optimized Default) x 76,474,169 ops/sec ±0.61% (92 runs sampled)
Jed x 241,632 ops/sec ±0.73% (96 runs sampled)
Plural
---
Tannin x 7,108,006 ops/sec ±0.96% (95 runs sampled)
Tannin (Optimized Default) x 51,658,190 ops/sec ±1.25% (94 runs sampled)
Jed x 236,797 ops/sec ±0.98% (97 runs sampled)
```
To run benchmarks on your own machine:
```
git clone https://github.com/aduth/tannin.git
cd tannin
npm install
node packages/tannin/benchmark
```
## License
Copyright 2019-2020 Andrew Duthie
Released under the [MIT License](https://opensource.org/licenses/MIT).

219
node_modules/tannin/build/index.js generated vendored Normal file
View File

@@ -0,0 +1,219 @@
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var pluralForms = _interopDefault(require('@tannin/plural-forms'));
/**
* Tannin constructor options.
*
* @typedef {Object} TanninOptions
*
* @property {string} [contextDelimiter] Joiner in string lookup with context.
* @property {Function} [onMissingKey] Callback to invoke when key missing.
*/
/**
* Domain metadata.
*
* @typedef {Object} TanninDomainMetadata
*
* @property {string} [domain] Domain name.
* @property {string} [lang] Language code.
* @property {(string|Function)} [plural_forms] Plural forms expression or
* function evaluator.
*/
/**
* Domain translation pair respectively representing the singular and plural
* translation.
*
* @typedef {[string,string]} TanninTranslation
*/
/**
* Locale data domain. The key is used as reference for lookup, the value an
* array of two string entries respectively representing the singular and plural
* translation.
*
* @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
*/
/**
* Jed-formatted locale data.
*
* @see http://messageformat.github.io/Jed/
*
* @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
*/
/**
* Default Tannin constructor options.
*
* @type {TanninOptions}
*/
var DEFAULT_OPTIONS = {
contextDelimiter: '\u0004',
onMissingKey: null,
};
/**
* Given a specific locale data's config `plural_forms` value, returns the
* expression.
*
* @example
*
* ```
* getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
* ```
*
* @param {string} pf Locale data plural forms.
*
* @return {string} Plural forms expression.
*/
function getPluralExpression( pf ) {
var parts, i, part;
parts = pf.split( ';' );
for ( i = 0; i < parts.length; i++ ) {
part = parts[ i ].trim();
if ( part.indexOf( 'plural=' ) === 0 ) {
return part.substr( 7 );
}
}
}
/**
* Tannin constructor.
*
* @class
*
* @param {TanninLocaleData} data Jed-formatted locale data.
* @param {TanninOptions} [options] Tannin options.
*/
function Tannin( data, options ) {
var key;
/**
* Jed-formatted locale data.
*
* @name Tannin#data
* @type {TanninLocaleData}
*/
this.data = data;
/**
* Plural forms function cache, keyed by plural forms string.
*
* @name Tannin#pluralForms
* @type {Object<string,Function>}
*/
this.pluralForms = {};
/**
* Effective options for instance, including defaults.
*
* @name Tannin#options
* @type {TanninOptions}
*/
this.options = {};
for ( key in DEFAULT_OPTIONS ) {
this.options[ key ] = options !== undefined && key in options
? options[ key ]
: DEFAULT_OPTIONS[ key ];
}
}
/**
* Returns the plural form index for the given domain and value.
*
* @param {string} domain Domain on which to calculate plural form.
* @param {number} n Value for which plural form is to be calculated.
*
* @return {number} Plural form index.
*/
Tannin.prototype.getPluralForm = function( domain, n ) {
var getPluralForm = this.pluralForms[ domain ],
config, plural, pf;
if ( ! getPluralForm ) {
config = this.data[ domain ][ '' ];
pf = (
config[ 'Plural-Forms' ] ||
config[ 'plural-forms' ] ||
// Ignore reason: As known, there's no way to document the empty
// string property on a key to guarantee this as metadata.
// @ts-ignore
config.plural_forms
);
if ( typeof pf !== 'function' ) {
plural = getPluralExpression(
config[ 'Plural-Forms' ] ||
config[ 'plural-forms' ] ||
// Ignore reason: As known, there's no way to document the empty
// string property on a key to guarantee this as metadata.
// @ts-ignore
config.plural_forms
);
pf = pluralForms( plural );
}
getPluralForm = this.pluralForms[ domain ] = pf;
}
return getPluralForm( n );
};
/**
* Translate a string.
*
* @param {string} domain Translation domain.
* @param {string|void} context Context distinguishing terms of the same name.
* @param {string} singular Primary key for translation lookup.
* @param {string=} plural Fallback value used for non-zero plural
* form index.
* @param {number=} n Value to use in calculating plural form.
*
* @return {string} Translated string.
*/
Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
var index, key, entry;
if ( n === undefined ) {
// Default to singular.
index = 0;
} else {
// Find index by evaluating plural form for value.
index = this.getPluralForm( domain, n );
}
key = singular;
// If provided, context is prepended to key with delimiter.
if ( context ) {
key = context + this.options.contextDelimiter + singular;
}
entry = this.data[ domain ][ key ];
// Verify not only that entry exists, but that the intended index is within
// range and non-empty.
if ( entry && entry[ index ] ) {
return entry[ index ];
}
if ( this.options.onMissingKey ) {
this.options.onMissingKey( singular, domain );
}
// If entry not found, fall back to singular vs. plural with zero index
// representing the singular value.
return index === 0 ? singular : plural;
};
module.exports = Tannin;

498
node_modules/tannin/dist/tannin.js generated vendored Normal file
View File

@@ -0,0 +1,498 @@
var Tannin = (function () {
'use strict';
var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
/**
* Operator precedence mapping.
*
* @type {Object}
*/
PRECEDENCE = {
'(': 9,
'!': 8,
'*': 7,
'/': 7,
'%': 7,
'+': 6,
'-': 6,
'<': 5,
'<=': 5,
'>': 5,
'>=': 5,
'==': 4,
'!=': 4,
'&&': 3,
'||': 2,
'?': 1,
'?:': 1,
};
/**
* Characters which signal pair opening, to be terminated by terminators.
*
* @type {string[]}
*/
OPENERS = [ '(', '?' ];
/**
* Characters which signal pair termination, the value an array with the
* opener as its first member. The second member is an optional operator
* replacement to push to the stack.
*
* @type {string[]}
*/
TERMINATORS = {
')': [ '(' ],
':': [ '?', '?:' ],
};
/**
* Pattern matching operators and openers.
*
* @type {RegExp}
*/
PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
/**
* Given a C expression, returns the equivalent postfix (Reverse Polish)
* notation terms as an array.
*
* If a postfix string is desired, simply `.join( ' ' )` the result.
*
* @example
*
* ```js
* import postfix from '@tannin/postfix';
*
* postfix( 'n > 1' );
* // ⇒ [ 'n', '1', '>' ]
* ```
*
* @param {string} expression C expression.
*
* @return {string[]} Postfix terms.
*/
function postfix( expression ) {
var terms = [],
stack = [],
match, operator, term, element;
while ( ( match = expression.match( PATTERN ) ) ) {
operator = match[ 0 ];
// Term is the string preceding the operator match. It may contain
// whitespace, and may be empty (if operator is at beginning).
term = expression.substr( 0, match.index ).trim();
if ( term ) {
terms.push( term );
}
while ( ( element = stack.pop() ) ) {
if ( TERMINATORS[ operator ] ) {
if ( TERMINATORS[ operator ][ 0 ] === element ) {
// Substitution works here under assumption that because
// the assigned operator will no longer be a terminator, it
// will be pushed to the stack during the condition below.
operator = TERMINATORS[ operator ][ 1 ] || operator;
break;
}
} else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) {
// Push to stack if either an opener or when pop reveals an
// element of lower precedence.
stack.push( element );
break;
}
// For each popped from stack, push to terms.
terms.push( element );
}
if ( ! TERMINATORS[ operator ] ) {
stack.push( operator );
}
// Slice matched fragment from expression to continue match.
expression = expression.substr( match.index + operator.length );
}
// Push remainder of operand, if exists, to terms.
expression = expression.trim();
if ( expression ) {
terms.push( expression );
}
// Pop remaining items from stack into terms.
return terms.concat( stack.reverse() );
}
/**
* Operator callback functions.
*
* @type {Object}
*/
var OPERATORS = {
'!': function( a ) {
return ! a;
},
'*': function( a, b ) {
return a * b;
},
'/': function( a, b ) {
return a / b;
},
'%': function( a, b ) {
return a % b;
},
'+': function( a, b ) {
return a + b;
},
'-': function( a, b ) {
return a - b;
},
'<': function( a, b ) {
return a < b;
},
'<=': function( a, b ) {
return a <= b;
},
'>': function( a, b ) {
return a > b;
},
'>=': function( a, b ) {
return a >= b;
},
'==': function( a, b ) {
return a === b;
},
'!=': function( a, b ) {
return a !== b;
},
'&&': function( a, b ) {
return a && b;
},
'||': function( a, b ) {
return a || b;
},
'?:': function( a, b, c ) {
if ( a ) {
throw b;
}
return c;
},
};
/**
* Given an array of postfix terms and operand variables, returns the result of
* the postfix evaluation.
*
* @example
*
* ```js
* import evaluate from '@tannin/evaluate';
*
* // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +'
* const terms = [ '3', '4', '5', '*', '6', '/', '+' ];
*
* evaluate( terms, {} );
* // ⇒ 6.333333333333334
* ```
*
* @param {string[]} postfix Postfix terms.
* @param {Object} variables Operand variables.
*
* @return {*} Result of evaluation.
*/
function evaluate( postfix, variables ) {
var stack = [],
i, j, args, getOperatorResult, term, value;
for ( i = 0; i < postfix.length; i++ ) {
term = postfix[ i ];
getOperatorResult = OPERATORS[ term ];
if ( getOperatorResult ) {
// Pop from stack by number of function arguments.
j = getOperatorResult.length;
args = Array( j );
while ( j-- ) {
args[ j ] = stack.pop();
}
try {
value = getOperatorResult.apply( null, args );
} catch ( earlyReturn ) {
return earlyReturn;
}
} else if ( variables.hasOwnProperty( term ) ) {
value = variables[ term ];
} else {
value = +term;
}
stack.push( value );
}
return stack[ 0 ];
}
/**
* Given a C expression, returns a function which can be called to evaluate its
* result.
*
* @example
*
* ```js
* import compile from '@tannin/compile';
*
* const evaluate = compile( 'n > 1' );
*
* evaluate( { n: 2 } );
* // ⇒ true
* ```
*
* @param {string} expression C expression.
*
* @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator.
*/
function compile( expression ) {
var terms = postfix( expression );
return function( variables ) {
return evaluate( terms, variables );
};
}
/**
* Given a C expression, returns a function which, when called with a value,
* evaluates the result with the value assumed to be the "n" variable of the
* expression. The result will be coerced to its numeric equivalent.
*
* @param {string} expression C expression.
*
* @return {Function} Evaluator function.
*/
function pluralForms( expression ) {
var evaluate = compile( expression );
return function( n ) {
return +evaluate( { n: n } );
};
}
/**
* Tannin constructor options.
*
* @typedef {Object} TanninOptions
*
* @property {string} [contextDelimiter] Joiner in string lookup with context.
* @property {Function} [onMissingKey] Callback to invoke when key missing.
*/
/**
* Domain metadata.
*
* @typedef {Object} TanninDomainMetadata
*
* @property {string} [domain] Domain name.
* @property {string} [lang] Language code.
* @property {(string|Function)} [plural_forms] Plural forms expression or
* function evaluator.
*/
/**
* Domain translation pair respectively representing the singular and plural
* translation.
*
* @typedef {[string,string]} TanninTranslation
*/
/**
* Locale data domain. The key is used as reference for lookup, the value an
* array of two string entries respectively representing the singular and plural
* translation.
*
* @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
*/
/**
* Jed-formatted locale data.
*
* @see http://messageformat.github.io/Jed/
*
* @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
*/
/**
* Default Tannin constructor options.
*
* @type {TanninOptions}
*/
var DEFAULT_OPTIONS = {
contextDelimiter: '\u0004',
onMissingKey: null,
};
/**
* Given a specific locale data's config `plural_forms` value, returns the
* expression.
*
* @example
*
* ```
* getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
* ```
*
* @param {string} pf Locale data plural forms.
*
* @return {string} Plural forms expression.
*/
function getPluralExpression( pf ) {
var parts, i, part;
parts = pf.split( ';' );
for ( i = 0; i < parts.length; i++ ) {
part = parts[ i ].trim();
if ( part.indexOf( 'plural=' ) === 0 ) {
return part.substr( 7 );
}
}
}
/**
* Tannin constructor.
*
* @class
*
* @param {TanninLocaleData} data Jed-formatted locale data.
* @param {TanninOptions} [options] Tannin options.
*/
function Tannin( data, options ) {
var key;
/**
* Jed-formatted locale data.
*
* @name Tannin#data
* @type {TanninLocaleData}
*/
this.data = data;
/**
* Plural forms function cache, keyed by plural forms string.
*
* @name Tannin#pluralForms
* @type {Object<string,Function>}
*/
this.pluralForms = {};
/**
* Effective options for instance, including defaults.
*
* @name Tannin#options
* @type {TanninOptions}
*/
this.options = {};
for ( key in DEFAULT_OPTIONS ) {
this.options[ key ] = options !== undefined && key in options
? options[ key ]
: DEFAULT_OPTIONS[ key ];
}
}
/**
* Returns the plural form index for the given domain and value.
*
* @param {string} domain Domain on which to calculate plural form.
* @param {number} n Value for which plural form is to be calculated.
*
* @return {number} Plural form index.
*/
Tannin.prototype.getPluralForm = function( domain, n ) {
var getPluralForm = this.pluralForms[ domain ],
config, plural, pf;
if ( ! getPluralForm ) {
config = this.data[ domain ][ '' ];
pf = (
config[ 'Plural-Forms' ] ||
config[ 'plural-forms' ] ||
// Ignore reason: As known, there's no way to document the empty
// string property on a key to guarantee this as metadata.
// @ts-ignore
config.plural_forms
);
if ( typeof pf !== 'function' ) {
plural = getPluralExpression(
config[ 'Plural-Forms' ] ||
config[ 'plural-forms' ] ||
// Ignore reason: As known, there's no way to document the empty
// string property on a key to guarantee this as metadata.
// @ts-ignore
config.plural_forms
);
pf = pluralForms( plural );
}
getPluralForm = this.pluralForms[ domain ] = pf;
}
return getPluralForm( n );
};
/**
* Translate a string.
*
* @param {string} domain Translation domain.
* @param {string|void} context Context distinguishing terms of the same name.
* @param {string} singular Primary key for translation lookup.
* @param {string=} plural Fallback value used for non-zero plural
* form index.
* @param {number=} n Value to use in calculating plural form.
*
* @return {string} Translated string.
*/
Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
var index, key, entry;
if ( n === undefined ) {
// Default to singular.
index = 0;
} else {
// Find index by evaluating plural form for value.
index = this.getPluralForm( domain, n );
}
key = singular;
// If provided, context is prepended to key with delimiter.
if ( context ) {
key = context + this.options.contextDelimiter + singular;
}
entry = this.data[ domain ][ key ];
// Verify not only that entry exists, but that the intended index is within
// range and non-empty.
if ( entry && entry[ index ] ) {
return entry[ index ];
}
if ( this.options.onMissingKey ) {
this.options.onMissingKey( singular, domain );
}
// If entry not found, fall back to singular vs. plural with zero index
// representing the singular value.
return index === 0 ? singular : plural;
};
return Tannin;
}());

1
node_modules/tannin/dist/tannin.min.js generated vendored Normal file
View File

@@ -0,0 +1 @@
var Tannin=function(){"use strict";var s,f,a,l;s={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},f=["(","?"],a={")":["("],":":["?","?:"]},l=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;var c={"!":function(r){return!r},"*":function(r,n){return r*n},"/":function(r,n){return r/n},"%":function(r,n){return r%n},"+":function(r,n){return r+n},"-":function(r,n){return r-n},"<":function(r,n){return r<n},"<=":function(r,n){return r<=n},">":function(r,n){return n<r},">=":function(r,n){return n<=r},"==":function(r,n){return r===n},"!=":function(r,n){return r!==n},"&&":function(r,n){return r&&n},"||":function(r,n){return r||n},"?:":function(r,n,t){if(r)throw n;return t}};function o(r){var n=function(r){for(var n,t,u,i,o=[],e=[];n=r.match(l);){for(t=n[0],(u=r.substr(0,n.index).trim())&&o.push(u);i=e.pop();){if(a[t]){if(a[t][0]===i){t=a[t][1]||t;break}}else if(0<=f.indexOf(i)||s[i]<s[t]){e.push(i);break}o.push(i)}a[t]||e.push(t),r=r.substr(n.index+t.length)}return(r=r.trim())&&o.push(r),o.concat(e.reverse())}(r);return function(r){return function(r,n){var t,u,i,o,e,s,f=[];for(t=0;t<r.length;t++){if(e=r[t],o=c[e]){for(u=o.length,i=Array(u);u--;)i[u]=f.pop();try{s=o.apply(null,i)}catch(r){return r}}else s=n.hasOwnProperty(e)?n[e]:+e;f.push(s)}return f[0]}(n,r)}}var u={contextDelimiter:"",onMissingKey:null};function r(r,n){var t;for(t in this.data=r,this.pluralForms={},this.options={},u)this.options[t]=void 0!==n&&t in n?n[t]:u[t]}return r.prototype.getPluralForm=function(r,n){var t,u,i=this.pluralForms[r];return i||("function"!=typeof(u=(t=this.data[r][""])["Plural-Forms"]||t["plural-forms"]||t.plural_forms)&&(u=function(r){var n=o(r);return function(r){return+n({n:r})}}(function(r){var n,t,u;for(n=r.split(";"),t=0;t<n.length;t++)if(0===(u=n[t].trim()).indexOf("plural="))return u.substr(7)}(t["Plural-Forms"]||t["plural-forms"]||t.plural_forms))),i=this.pluralForms[r]=u),i(n)},r.prototype.dcnpgettext=function(r,n,t,u,i){var o,e,s;return o=void 0===i?0:this.getPluralForm(r,i),e=t,n&&(e=n+this.options.contextDelimiter+t),(s=this.data[r][e])&&s[o]?s[o]:(this.options.onMissingKey&&this.options.onMissingKey(t,r),0===o?t:u)},r}();

109
node_modules/tannin/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,109 @@
/**
* Tannin constructor.
*
* @class
*
* @param {TanninLocaleData} data Jed-formatted locale data.
* @param {TanninOptions} [options] Tannin options.
*/
export default function Tannin(data: {
[domain: string]: {
[key: string]: TanninDomainMetadata | [string, string];
'': TanninDomainMetadata | [string, string];
};
}, options?: TanninOptions): void;
export default class Tannin {
/**
* Tannin constructor.
*
* @class
*
* @param {TanninLocaleData} data Jed-formatted locale data.
* @param {TanninOptions} [options] Tannin options.
*/
constructor(data: {
[domain: string]: {
[key: string]: TanninDomainMetadata | [string, string];
'': TanninDomainMetadata | [string, string];
};
}, options?: TanninOptions);
/**
* Jed-formatted locale data.
*
* @name Tannin#data
* @type {TanninLocaleData}
*/
data: TanninLocaleData;
/**
* Plural forms function cache, keyed by plural forms string.
*
* @name Tannin#pluralForms
* @type {Object<string,Function>}
*/
pluralForms: {
[x: string]: Function;
};
/**
* Effective options for instance, including defaults.
*
* @name Tannin#options
* @type {TanninOptions}
*/
options: TanninOptions;
getPluralForm(domain: string, n: number): number;
dcnpgettext(domain: string, context: string | void, singular: string, plural?: string, n?: number): string;
}
/**
* Tannin constructor options.
*/
export type TanninOptions = {
/**
* Joiner in string lookup with context.
*/
contextDelimiter?: string;
/**
* Callback to invoke when key missing.
*/
onMissingKey?: Function;
};
/**
* Domain metadata.
*/
export type TanninDomainMetadata = {
/**
* Domain name.
*/
domain?: string;
/**
* Language code.
*/
lang?: string;
/**
* Plural forms expression or
* function evaluator.
*/
plural_forms?: TimerHandler;
};
/**
* Domain translation pair respectively representing the singular and plural
* translation.
*/
export type TanninTranslation = [string, string];
/**
* Locale data domain. The key is used as reference for lookup, the value an
* array of two string entries respectively representing the singular and plural
* translation.
*/
export type TanninLocaleDomain = {
[key: string]: TanninDomainMetadata | [string, string];
'': TanninDomainMetadata | [string, string];
};
/**
* Jed-formatted locale data.
*/
export type TanninLocaleData = {
[domain: string]: {
[key: string]: TanninDomainMetadata | [string, string];
'': TanninDomainMetadata | [string, string];
};
};

213
node_modules/tannin/index.js generated vendored Normal file
View File

@@ -0,0 +1,213 @@
import pluralForms from '@tannin/plural-forms';
/**
* Tannin constructor options.
*
* @typedef {Object} TanninOptions
*
* @property {string} [contextDelimiter] Joiner in string lookup with context.
* @property {Function} [onMissingKey] Callback to invoke when key missing.
*/
/**
* Domain metadata.
*
* @typedef {Object} TanninDomainMetadata
*
* @property {string} [domain] Domain name.
* @property {string} [lang] Language code.
* @property {(string|Function)} [plural_forms] Plural forms expression or
* function evaluator.
*/
/**
* Domain translation pair respectively representing the singular and plural
* translation.
*
* @typedef {[string,string]} TanninTranslation
*/
/**
* Locale data domain. The key is used as reference for lookup, the value an
* array of two string entries respectively representing the singular and plural
* translation.
*
* @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
*/
/**
* Jed-formatted locale data.
*
* @see http://messageformat.github.io/Jed/
*
* @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
*/
/**
* Default Tannin constructor options.
*
* @type {TanninOptions}
*/
var DEFAULT_OPTIONS = {
contextDelimiter: '\u0004',
onMissingKey: null,
};
/**
* Given a specific locale data's config `plural_forms` value, returns the
* expression.
*
* @example
*
* ```
* getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
* ```
*
* @param {string} pf Locale data plural forms.
*
* @return {string} Plural forms expression.
*/
function getPluralExpression( pf ) {
var parts, i, part;
parts = pf.split( ';' );
for ( i = 0; i < parts.length; i++ ) {
part = parts[ i ].trim();
if ( part.indexOf( 'plural=' ) === 0 ) {
return part.substr( 7 );
}
}
}
/**
* Tannin constructor.
*
* @class
*
* @param {TanninLocaleData} data Jed-formatted locale data.
* @param {TanninOptions} [options] Tannin options.
*/
export default function Tannin( data, options ) {
var key;
/**
* Jed-formatted locale data.
*
* @name Tannin#data
* @type {TanninLocaleData}
*/
this.data = data;
/**
* Plural forms function cache, keyed by plural forms string.
*
* @name Tannin#pluralForms
* @type {Object<string,Function>}
*/
this.pluralForms = {};
/**
* Effective options for instance, including defaults.
*
* @name Tannin#options
* @type {TanninOptions}
*/
this.options = {};
for ( key in DEFAULT_OPTIONS ) {
this.options[ key ] = options !== undefined && key in options
? options[ key ]
: DEFAULT_OPTIONS[ key ];
}
}
/**
* Returns the plural form index for the given domain and value.
*
* @param {string} domain Domain on which to calculate plural form.
* @param {number} n Value for which plural form is to be calculated.
*
* @return {number} Plural form index.
*/
Tannin.prototype.getPluralForm = function( domain, n ) {
var getPluralForm = this.pluralForms[ domain ],
config, plural, pf;
if ( ! getPluralForm ) {
config = this.data[ domain ][ '' ];
pf = (
config[ 'Plural-Forms' ] ||
config[ 'plural-forms' ] ||
// Ignore reason: As known, there's no way to document the empty
// string property on a key to guarantee this as metadata.
// @ts-ignore
config.plural_forms
);
if ( typeof pf !== 'function' ) {
plural = getPluralExpression(
config[ 'Plural-Forms' ] ||
config[ 'plural-forms' ] ||
// Ignore reason: As known, there's no way to document the empty
// string property on a key to guarantee this as metadata.
// @ts-ignore
config.plural_forms
);
pf = pluralForms( plural );
}
getPluralForm = this.pluralForms[ domain ] = pf;
}
return getPluralForm( n );
};
/**
* Translate a string.
*
* @param {string} domain Translation domain.
* @param {string|void} context Context distinguishing terms of the same name.
* @param {string} singular Primary key for translation lookup.
* @param {string=} plural Fallback value used for non-zero plural
* form index.
* @param {number=} n Value to use in calculating plural form.
*
* @return {string} Translated string.
*/
Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
var index, key, entry;
if ( n === undefined ) {
// Default to singular.
index = 0;
} else {
// Find index by evaluating plural form for value.
index = this.getPluralForm( domain, n );
}
key = singular;
// If provided, context is prepended to key with delimiter.
if ( context ) {
key = context + this.options.contextDelimiter + singular;
}
entry = this.data[ domain ][ key ];
// Verify not only that entry exists, but that the intended index is within
// range and non-empty.
if ( entry && entry[ index ] ) {
return entry[ index ];
}
if ( this.options.onMissingKey ) {
this.options.onMissingKey( singular, domain );
}
// If entry not found, fall back to singular vs. plural with zero index
// representing the singular value.
return index === 0 ? singular : plural;
};

49
node_modules/tannin/package.json generated vendored Normal file
View File

@@ -0,0 +1,49 @@
{
"name": "tannin",
"version": "1.2.0",
"description": "gettext localization library compatible with Jed-formatted locale data",
"main": "build/index.js",
"module": "index.js",
"types": "index.d.ts",
"moduleName": "Tannin",
"scripts": {
"prepublishOnly": "cp ../../README.md README.md"
},
"keywords": [
"jed",
"gettext",
"localization",
"internationalization",
"l10n",
"i18n",
"translate"
],
"author": {
"name": "Andrew Duthie",
"email": "andrew@andrewduthie.com",
"url": "https://andrewduthie.com"
},
"homepage": "https://github.com/aduth/tannin",
"repository": {
"type": "git",
"url": "https://github.com/aduth/tannin.git",
"directory": "packages/tannin"
},
"bugs": {
"url": "https://github.com/aduth/tannin/issues"
},
"license": "MIT",
"files": [
"index.js",
"index.d.ts",
"build",
"dist"
],
"dependencies": {
"@tannin/plural-forms": "^1.1.0"
},
"publishConfig": {
"access": "public"
},
"gitHead": "cd1c7447843df7751c4abd1b92aee03fe56bfba4"
}