UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

5 lines (4 loc) • 7.67 kB
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details. v3.2.1 */ import{b as p}from"./3FSOG4LN.js";var C=new RegExp("\\.(0+)?$"),A=new RegExp("0+$"),u=class t{static{this.DECIMALS=100}static{this.ROUNDED=!0}static{this.SHIFT=BigInt("1"+"0".repeat(this.DECIMALS))}constructor(e){if(e instanceof t)return e;let[s,n]=R(e).split(".").concat("");this.value=BigInt(s+n.padEnd(t.DECIMALS,"0").slice(0,t.DECIMALS))+BigInt(t.ROUNDED&&n[t.DECIMALS]>="5"),this.isNegative=e.charAt(0)==="-"}static{this._divRound=(e,s)=>t.fromBigInt(e/s+(t.ROUNDED?e*BigInt(2)/s%BigInt(2):BigInt(0)))}static{this.fromBigInt=e=>Object.assign(Object.create(t.prototype),{value:e,isNegative:e<BigInt(0)})}getIntegersAndDecimals(){let e=this.value.toString().replace("-","").padStart(t.DECIMALS+1,"0"),s=e.slice(0,-t.DECIMALS),n=e.slice(-t.DECIMALS).replace(A,"");return{integers:s,decimals:n}}toString(){let{integers:e,decimals:s}=this.getIntegersAndDecimals();return`${this.isNegative?"-":""}${e}${s.length?"."+s:""}`}formatToParts(e){let{integers:s,decimals:n}=this.getIntegersAndDecimals(),i=e.numberFormatter.formatToParts(BigInt(s));return this.isNegative&&i.unshift({type:"minusSign",value:e.minusSign}),n.length&&(i.push({type:"decimal",value:e.decimal}),n.split("").forEach(r=>i.push({type:"fraction",value:r}))),i}format(e){let{integers:s,decimals:n}=this.getIntegersAndDecimals(),i=`${this.isNegative?e.minusSign:""}${e.numberFormatter.format(BigInt(s))}`,r=n.length?`${e.decimal}${n.split("").map(l=>e.numberFormatter.format(Number(l))).join("")}`:"";return`${i}${r}`}add(e){return t.fromBigInt(this.value+new t(e).value)}subtract(e){return t.fromBigInt(this.value-new t(e).value)}multiply(e){return t._divRound(this.value*new t(e).value,t.SHIFT)}divide(e){return t._divRound(this.value*t.SHIFT,new t(e).value)}};function D(t){return!(!t||isNaN(Number(t)))}function U(t){return!t||!j(t)?"":g(t,e=>{let s=!1,n=e.split("").filter((i,r)=>i.match(/\./g)&&!s?(s=!0,!0):i.match(/-/g)&&r===0?!0:p.includes(i)).join("");return D(n)?new u(n).toString():""})}var F=/^([-0])0+(?=\d)/,T=/(?!^\.)\.$/,x=/(?!^-)-/g,L=/^-\b0\b\.?0*$/,_=/0*$/,B=new Set(["e","E","-",",",".",...p]),K=t=>{let e=Array.from(t).filter(s=>B.has(s)).join("");return g(e,s=>{let n=s.replace(x,"").replace(T,"").replace(F,"$1");return D(n)?L.test(n)?n:M(n):s})};function M(t){let e=t.split(".")[1],s=new u(t).toString(),[n,i]=s.split(".");return e&&i!==e?`${n}.${e}`:s}function g(t,e){if(!t)return t;let s=t.toLowerCase().indexOf("e")+1;return s?t.replace(/[eE]*$/g,"").substring(0,s).concat(t.slice(s).replace(/[eE]/g,"")).split(/[eE]/).map((n,i)=>e(i===1?n.replace(/\./g,""):n)).join("e").replace(/^e/,"1e"):e(t)}function R(t){let e=t.split(/[eE]/);if(e.length===1)return t;let s=+t;if(Number.isSafeInteger(s))return`${s}`;let n=t.charAt(0)==="-",i=+e[1],r=e[0].split("."),l=(n?r[0].substring(1):r[0])||"",S=r[1]||"",O=(a,m)=>{let c=Math.abs(m)-a.length,d=c>0?`${"0".repeat(c)}${a}`:a;return`${d.slice(0,m)}.${d.slice(m)}`},E=(a,m)=>{let c=m>a.length?`${a}${"0".repeat(m-a.length)}`:a;return`${c.slice(0,m)}.${c.slice(m)}`},I=i>0?`${l}${E(S,i)}`:`${O(l,i)}${S}`;return`${n?"-":""}${I.charAt(0)==="."?"0":""}${I.replace(C,"").replace(F,"")}`}function j(t){return p.some(e=>t.includes(e))}function J(t,e,s){let n=e.split(".")[1];if(n){let i=n.match(_)[0];if(i&&s.delocalize(t).length!==e.length&&n.indexOf("e")===-1){let r=s.decimal;return t=t.includes(r)?t:`${t}${r}`,t.padEnd(t.length+i.length,s.localize("0"))}}return t}var h="en",H=["ar","bg","bs","ca","cs","da","de","de-AT","de-CH","el",h,"en-AU","en-CA","en-GB","es","es-MX","et","fi","fr","fr-CH","he","hi","hr","hu","id","it","it-CH","ja","ko","lt","lv","mk","no","nl","pl","pt","pt-PT","ro","ru","sk","sl","sr","sv","th","tr","uk","vi","zh-CN","zh-HK","zh-TW"],X=new Map(Object.entries({bg:{am:"\u043F\u0440.\u043E\u0431.",pm:"\u0441\u043B.\u043E\u0431."},bs:{am:"prijepodne",pm:"popodne"},ca:{am:"a.\xA0m.",pm:"p.\xA0m."},cs:{am:"dop.",pm:"odp."},es:{am:"a.\xA0m.",pm:"p.\xA0m."},"es-mx":{am:"a.m.",pm:"p.m."},"es-MX":{am:"a.m.",pm:"p.m."},fi:{am:"ap.",pm:"ip."},he:{am:"\u05DC\u05E4\u05E0\u05D4\u05F4\u05E6",pm:"\u05D0\u05D7\u05D4\u05F4\u05E6"},hu:{am:"de. ",pm:"du."},lt:{am:"prie\u0161piet",pm:"popiet"},lv:{am:"priek\u0161pusdien\u0101",pm:"p\u0113cpusdien\u0101"},mk:{am:"\u043F\u0440\u0435\u0442\u043F\u043B.",pm:"\u043F\u043E\u043F\u043B."},no:{am:"a.m.",pm:"p.m."},nl:{am:"a.m.",pm:"p.m."},"pt-pt":{am:"da manh\xE3",pm:"da tarde"},"pt-PT":{am:"da manh\xE3",pm:"da tarde"},ro:{am:"a.m.",pm:"p.m."},sl:{am:"dop.",pm:"pop."},sv:{am:"fm",pm:"em"},th:{am:"\u0E01\u0E48\u0E2D\u0E19\u0E40\u0E17\u0E35\u0E48\u0E22\u0E07",pm:"\u0E2B\u0E25\u0E31\u0E07\u0E40\u0E17\u0E35\u0E48\u0E22\u0E07"},tr:{am:"\xD6\xD6",pm:"\xD6S"},uk:{am:"\u0434\u043F",pm:"\u043F\u043F"},vi:{am:"SA",pm:"CH"}})),k=["arab","arabext","latn"],f=[...H],w=t=>k.includes(t),b=new Intl.NumberFormat().resolvedOptions().numberingSystem,y=b==="arab"||!w(b)?"latn":b,P=t=>w(t)?t:y;function N(t){return t?f.includes(t)?t:(t=t.toLowerCase(),t.includes("-")&&(t=t.replace(/(\w+)-(\w+)/,(e,s,n)=>`${s}-${n.toUpperCase()}`),f.includes(t)||(t=t.split("-")[0])),t==="nb"||t==="nn"?"no":t==="zh"?"zh-CN":f.includes(t)?t:(console.warn(`Translations for the "${t}" locale are not available and will fall back to the default, English (en).`),h)):h}function W(t){switch(t){case"it-CH":return"de-CH";case"bs":return"bs-Cyrl";default:return t}}var $=class{constructor(){this.delocalize=e=>this._numberFormatOptions?g(e,s=>s.replace(new RegExp(`[${this._minusSign}]`,"g"),"-").replace(new RegExp(`[${this._group}]`,"g"),"").replace(new RegExp(`[${this._decimal}]`,"g"),".").replace(new RegExp(`[${this._digits.join("")}]`,"g"),this._getDigitIndex)):e,this.localize=e=>this._numberFormatOptions?g(e,s=>D(s.trim())?new u(s.trim()).format(this).replace(new RegExp(`[${this._actualGroup}]`,"g"),this._group):s):e}get group(){return this._group}get decimal(){return this._decimal}get minusSign(){return this._minusSign}get digits(){return this._digits}get numberFormatter(){return this._numberFormatter}get numberFormatOptions(){return this._numberFormatOptions}set numberFormatOptions(e){if(e.locale=N(e?.locale),e.numberingSystem=P(e?.numberingSystem),!this._numberFormatOptions&&e.locale===h&&e.numberingSystem===y&&Object.keys(e).length===2||JSON.stringify(this._numberFormatOptions)===JSON.stringify(e))return;this._numberFormatOptions=e,this._numberFormatter=new Intl.NumberFormat(this._numberFormatOptions.locale,this._numberFormatOptions),this._digits=[...new Intl.NumberFormat(this._numberFormatOptions.locale,{useGrouping:!1,numberingSystem:this._numberFormatOptions.numberingSystem}).format(9876543210)].reverse();let s=new Map(this._digits.map((i,r)=>[i,r])),n=new Intl.NumberFormat(this._numberFormatOptions.locale,{numberingSystem:this._numberFormatOptions.numberingSystem}).formatToParts(-123456789e-1);this._actualGroup=n.find(i=>i.type==="group").value,this._group=this._actualGroup.trim().length===0||this._actualGroup==" "?"\xA0":this._actualGroup,this._decimal=e.locale==="bs"||e.locale==="mk"?",":n.find(i=>i.type==="decimal").value,this._minusSign=n.find(i=>i.type==="minusSign").value,this._getDigitIndex=i=>s.get(i)}},q=new $,o,v;function Z(t={}){return Object.entries(t).sort(([e],[s])=>e.localeCompare(s)).map(e=>`${e[0]}-${e[1]}`).flat().join(":")}function Q(t,e){t=N(t),o||(o=new Map),v!==t&&(o.clear(),v=t);let s=Z(e),n=o.get(s);if(n)return n;let i=new Intl.DateTimeFormat(t,e);return o.set(s,i),i}export{u as a,D as b,U as c,K as d,J as e,X as f,P as g,N as h,W as i,$ as j,q as k,Q as l};