2 lines
49 KiB
JavaScript
2 lines
49 KiB
JavaScript
|
!function(){"use strict";function t(t){return t.split("-").every(function(t){return/[a-z0-9]+/i.test(t)})}function e(e){return e?(Array.isArray(e)||(e=[e]),e.map(function(e){switch(void 0===e?"undefined":J(e)){case"string":break;case"object":e=e.toString();break;default:throw new TypeError("Locales should be strings, "+JSON.stringify(e)+" isn't.")}if(!t(e))throw new RangeError("The locale "+JSON.stringify(e)+" is not a structurally valid BCP 47 language tag.");return e}).reduce(function(t,e){return t.indexOf(e)<0&&t.push(e),t},[])):[]}function r(){return"undefined"!=typeof window&&window.navigator&&(window.navigator.userLanguage||window.navigator.language)||"en-US"}function n(t,e){do{if(t[e])return e;e=e.replace(/-?[^-]*$/,"")}while(e);return null}function i(t,e){var i=!0,o=!1,a=void 0;try{for(var s,u=e[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var l=s.value,c=n(t,l);if(c)return c}}catch(t){o=!0,a=t}finally{try{!i&&u.return&&u.return()}finally{if(o)throw a}}return n(t,r())}function o(t){var e=t.style;if(!e)return"cardinal";if(["cardinal","ordinal"].indexOf(e)<0)throw new RangeError("Not a valid plural syle: "+JSON.stringify(e));return e}function a(t){return(new Y).getResource(t)}function s(t,e){return Object.assign({},t,u(e))}function u(t){var e={},r=!0,n=!1,i=void 0;try{for(var o,a=Object.keys(t)[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var s=o.value;e[s]=t[s].value}}catch(t){n=!0,i=t}finally{try{!r&&a.return&&a.return()}finally{if(n)throw i}}return e}function l(t,e){var r=t.ctx;return e.reduce(function(t,e){return t+e.valueOf(r).length},0)}function c(t,e,r){return e[r]?e[r]:(t.errors.push(new RangeError("No default")),new et)}function h(t,e){var r=e.name,n=t.ctx,i=t.errors,o=n.messages.get(r);return o||(i.push(new ReferenceError("Unknown message: "+r)),new et(r))}function f(t,e){var r=e.name,n=t.ctx,i=t.errors,o=n.messages.get(r);return o?o.tags?o.tags.map(function(t){return new it(t)}):(i.push(new RangeError('No tags in message "'+r+'"')),new et(r)):(i.push(new ReferenceError("Unknown message: "+r)),new et(r))}function v(t,e){var r=e.id,n=e.key,i=h(t,r);if(i instanceof et)return i;var o=t.ctx,a=t.errors,s=y(t,n);if(function(t){return Array.isArray(t)&&"sel"===t[0].type&&null===t[0].exp}(i.val)){var u=!0,l=!1,c=void 0;try{for(var f,v=i.val[0].vars[Symbol.iterator]();!(u=(f=v.next()).done);u=!0){var d=f.value,g=y(t,d.key);if(s.match(o,g))return d}}catch(t){l=!0,c=t}finally{try{!u&&v.return&&v.return()}finally{if(l)throw c}}}return a.push(new ReferenceError("Unknown variant: "+s.valueOf(o))),y(t,i)}function d(t,e){var r=e.id,n=e.name,i=h(t,r);if(i instanceof et)return i;if(i.attrs)for(var o in i.attrs)if(n===o)return i.attrs[n];return t.errors.push(new ReferenceError("Unknown attribute: "+n)),y(t,i)}function g(t,e){var r=e.exp,n=e.vars,i=e.def;if(null===r)return c(t,n,i);var o="ref"===r.type?f(t,r):y(t,r);if(o instanceof et)return c(t,n,i);var a=!0,s=!1,u=void 0;try{for(var l,h=n[Symbol.iterator]();!(a=(l=h.next()).done);a=!0){var v=l.value,d=y(t,v.key);if(d instanceof rt||d instanceof it){var g=t.ctx;if(d.match(g,o))return v}}}catch(t){s=!0,u=t}finally{try{!a&&h.return&&h.return()}finally{if(s)throw u}}return c(t,n,i)}function y(t,e){if("string"==typeof e||e instanceof et)return e;if(Array.isArray(e))return w(t,e);switch(e.type){case"sym":return new it(e.name);case"num":return new rt(e.val);case"ext":return m(t,e);case"fun":return p(t,e);case"call":return b(t,e);case"ref":return y(t,h(t,e));case"attr":return y(t,d(t,e));case"var":return y(t,v(t,e));case"sel":return y(t,g(t,e));case void 0:if(void 0!==e.val)return y(t,e.val);return t.errors.push(new RangeError("No value")),new et;default:return new et}}function m(t,e){var r=e.name,n=t.args,i=t.errors;if(!n||!n.hasOwnProperty(r))return i.push(new ReferenceError("Unknown external: "+r)),new et(r);var o=n[r];if(o instanceof tt)return o;switch(void 0===o?"undefined":J(o)){case"string":return o;case"number":return new rt(o);case"object":if(o instanceof Date)return new nt(o);default:return i.push(new TypeError("Unsupported external type: "+r+", "+(void 0===o?"und
|
||
|
;if("ref"!==t.type)return t;if("."===this._source[this._index]){this._index++;var e=this.getIdentifier();return this._index++,{type:"attr",id:t,name:e}}if("["===this._source[this._index]){this._index++;var r=this.getVariantKey();return this._index++,{type:"var",id:t,key:r}}if("("===this._source[this._index]){this._index++;var n=this.getCallArgs();return this._index++,t.type="fun",{type:"call",fun:t,args:n}}return t}},{key:"getCallArgs",value:function(){var t=[];if(")"===this._source[this._index])return t;for(;this._index<this._length;){this.getLineWS();var e=this.getSelectorExpression();if("ref"!==e.type||void 0!==e.namespace)t.push(e);else if(this.getLineWS(),":"===this._source[this._index]){this._index++,this.getLineWS();var r=this.getSelectorExpression();if("string"!=typeof r&&!Array.isArray(r)&&"num"!==r.type)throw this._index=this._source.lastIndexOf(":",this._index)+1,this.error("Expected string in quotes, number.");t.push({type:"narg",name:e.name,val:r})}else t.push(e);if(this.getLineWS(),")"===this._source[this._index])break;if(","!==this._source[this._index])throw this.error('Expected "," or ")"');this._index++}return t}},{key:"getNumber",value:function(){var t="",e=this._source.charCodeAt(this._index);if(45===e&&(t+="-",e=this._source.charCodeAt(++this._index)),e<48||e>57)throw this.error('Unknown literal "'+t+'"');for(;e>=48&&e<=57;)t+=this._source[this._index++],e=this._source.charCodeAt(this._index);if(46===e){if(t+=this._source[this._index++],(e=this._source.charCodeAt(this._index))<48||e>57)throw this.error('Unknown literal "'+t+'"');for(;e>=48&&e<=57;)t+=this._source[this._index++],e=this._source.charCodeAt(this._index)}return{type:"num",val:t}}},{key:"getAttributes",value:function(){for(var t={};this._index<this._length;){if("."!==this._source[this._index])break;this._index++;var e=this.getIdentifier();this.getLineWS(),this._index++,this.getLineWS();var r=this.getPattern();t[e]="string"==typeof r?r:{val:r},this.getWS()}return t}},{key:"getTags",value:function(){for(var t=[];this._index<this._length;){if("#"!==this._source[this._index])break;this._index++;var e=this.getSymbol();t.push(e.name),this.getWS()}return t}},{key:"getVariants",value:function(){for(var t=[],e=0,r=void 0;this._index<this._length;){var n=this._source[this._index];if(("["!==n||"["===this._source[this._index+1])&&"*"!==n)break;if("*"===n&&(this._index++,r=e),"["!==this._source[this._index])throw this.error('Expected "["');this._index++;var i=this.getVariantKey();this.getLineWS();var o={key:i,val:this.getPattern()};t[e++]=o,this.getWS()}return[t,r]}},{key:"getVariantKey",value:function(){var t=this._source.charCodeAt(this._index),e=void 0;if(e=t>=48&&t<=57||45===t?this.getNumber():this.getSymbol(),"]"!==this._source[this._index])throw this.error('Expected "]"');return this._index++,e}},{key:"getLiteral",value:function(){var t=this._source.charCodeAt(this._index);return t>=48&&t<=57||45===t?this.getNumber():34===t?this.getString():36===t?(this._index++,{type:"ext",name:this.getIdentifier()}):{type:"ref",name:this.getIdentifier()}}},{key:"getComment",value:function(){for(var t=this._source.indexOf("\n",this._index);-1!==t&&"/"===this._source[t+1]&&"/"===this._source[t+2]&&(this._index=t+3,-1!==(t=this._source.indexOf("\n",this._index))););this._index=-1===t?this._length:t+1}},{key:"error",value:function(t){return new SyntaxError(t)}},{key:"_findNextEntryStart",value:function(){for(var t=this._index;;){if(0===t||"\n"===this._source[t-1]){var e=this._source.charCodeAt(t);if(e>=97&&e<=122||e>=65&&e<=90||95===e||47===e||91===e)break}if(-1===(t=this._source.indexOf("\n",t)))break;t++}return t}}]),t}(),tt=function(){function t(e,r){K(this,t),this.value=e,this.opts=r}return B(t,[{key:"valueOf",value:function(){throw new Error("Subclasses of FluentType must implement valueOf.")}}]),t}(),et=function(t){function e(){return K(this,e),Z(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return X(e,t),B(e,[{key:"valueOf",value:function(){return this.value||"???"}}]),e}(tt),rt=function(t){function e(t,r){return K(this,e),Z(this,(e.__p
|