UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

3 lines (2 loc) • 7.15 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import{b as p}from"./YGX7CUXN.js";import{d}from"./TQRVWHPS.js";var E=new RegExp("\\.(0+)?$"),v=new RegExp("0+$"),l=class e{static{this.DECIMALS=100}static{this.ROUNDED=!0}static{this.SHIFT=BigInt("1"+"0".repeat(this.DECIMALS))}constructor(t){if(t instanceof e)return t;let[i,s]=T(t).split(".").concat("");this.value=BigInt(i+s.padEnd(e.DECIMALS,"0").slice(0,e.DECIMALS))+BigInt(e.ROUNDED&&s[e.DECIMALS]>="5"),this.isNegative=t.charAt(0)==="-"}static{this._divRound=(t,i)=>e.fromBigInt(t/i+(e.ROUNDED?t*BigInt(2)/i%BigInt(2):BigInt(0)))}static{this.fromBigInt=t=>Object.assign(Object.create(e.prototype),{value:t,isNegative:t<BigInt(0)})}getIntegersAndDecimals(){let t=this.value.toString().replace("-","").padStart(e.DECIMALS+1,"0"),i=t.slice(0,-e.DECIMALS),s=t.slice(-e.DECIMALS).replace(v,"");return{integers:i,decimals:s}}toString(){let{integers:t,decimals:i}=this.getIntegersAndDecimals();return`${this.isNegative?"-":""}${t}${i.length?"."+i:""}`}formatToParts(t){let{integers:i,decimals:s}=this.getIntegersAndDecimals(),n=t.numberFormatter.formatToParts(BigInt(i));return this.isNegative&&n.unshift({type:"minusSign",value:t.minusSign}),s.length&&(n.push({type:"decimal",value:t.decimal}),s.split("").forEach(r=>n.push({type:"fraction",value:r}))),n}format(t){let{integers:i,decimals:s}=this.getIntegersAndDecimals(),n=`${this.isNegative?t.minusSign:""}${t.numberFormatter.format(BigInt(i))}`,r=s.length?`${t.decimal}${s.split("").map(u=>t.numberFormatter.format(Number(u))).join("")}`:"";return`${n}${r}`}add(t){return e.fromBigInt(this.value+new e(t).value)}subtract(t){return e.fromBigInt(this.value-new e(t).value)}multiply(t){return e._divRound(this.value*new e(t).value,e.SHIFT)}divide(t){return e._divRound(this.value*e.SHIFT,new e(t).value)}};function $(e){return!(!e||isNaN(Number(e)))}function k(e){return!e||!B(e)?"":g(e,t=>{let i=!1,s=t.split("").filter((n,r)=>n.match(/\./g)&&!i?(i=!0,!0):n.match(/-/g)&&r===0?!0:p.includes(n)).join("");return $(s)?new l(s).toString():""})}var F=/^([-0])0+(?=\d)/,x=/(?!^\.)\.$/,A=/(?!^-)-/g,_=/^-\b0\b\.?0*$/,C=/0*$/,L=new Set(["e","E","-",",",".",...p]),z=e=>{let t=Array.from(e).filter(i=>L.has(i)).join("");return g(t,i=>{let s=i.replace(A,"").replace(x,"").replace(F,"$1");return $(s)?_.test(s)?s:R(s):i})};function R(e){let t=e.split(".")[1],i=new l(e).toString(),[s,n]=i.split(".");return t&&n!==t?`${s}.${t}`:i}function g(e,t){if(!e)return e;let i=e.toLowerCase().indexOf("e")+1;return i?e.replace(/[eE]*$/g,"").substring(0,i).concat(e.slice(i).replace(/[eE]/g,"")).split(/[eE]/).map((s,n)=>t(n===1?s.replace(/\./g,""):s)).join("e").replace(/^e/,"1e"):t(e)}function T(e){let t=e.split(/[eE]/);if(t.length===1)return e;let i=+e;if(Number.isSafeInteger(i))return`${i}`;let s=e.charAt(0)==="-",n=+t[1],r=t[0].split("."),u=(s?r[0].substring(1):r[0])||"",D=r[1]||"",w=(a,m)=>{let c=Math.abs(m)-a.length,h=c>0?`${"0".repeat(c)}${a}`:a;return`${h.slice(0,m)}.${h.slice(m)}`},N=(a,m)=>{let c=m>a.length?`${a}${"0".repeat(m-a.length)}`:a;return`${c.slice(0,m)}.${c.slice(m)}`},S=n>0?`${u}${N(D,n)}`:`${w(u,n)}${D}`;return`${s?"-":""}${S.charAt(0)==="."?"0":""}${S.replace(E,"").replace(F,"")}`}function B(e){return p.some(t=>e.includes(t))}function U(e,t,i){let s=t.split(".")[1];if(s){let n=s.match(C)[0];if(n&&i.delocalize(e).length!==t.length&&s.indexOf("e")===-1){let r=i.decimal;return e=e.includes(r)?e:`${e}${r}`,e.padEnd(e.length+n.length,i.localize("0"))}}return e}var J=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"}})),M=["arab","arabext","latn"],y=e=>M.includes(e),f=new Intl.NumberFormat().resolvedOptions().numberingSystem,O=f==="arab"||!y(f)?"latn":f,j=e=>y(e)?e:O;function K(e){switch(e){case"it-CH":return"de-CH";case"bs":return"sr-Latn-CS";default:return e}}var b=class{constructor(){this.delocalize=t=>this._numberFormatOptions?g(t,i=>this.#t(this.#e(i))):t,this.localize=t=>this._numberFormatOptions?g(t,i=>$(i.trim())?new l(i.trim()).format(this).replace(new RegExp(`[${this._actualGroup}]`,"g"),this._group):i):t}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(t){if(t.numberingSystem=j(t?.numberingSystem),t.locale=t?.locale||d,!this._numberFormatOptions&&t.locale===d&&t.numberingSystem===O&&Object.keys(t).length===2||JSON.stringify(this._numberFormatOptions)===JSON.stringify(t))return;this._numberFormatOptions=t,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 i=new Map(this._digits.map((n,r)=>[n,r])),s=new Intl.NumberFormat(this._numberFormatOptions.locale,{numberingSystem:this._numberFormatOptions.numberingSystem}).formatToParts(-123456789e-1);this._actualGroup=s.find(n=>n.type==="group").value,this._group=this._actualGroup.trim().length===0||this._actualGroup==" "?"\xA0":this._actualGroup,this._decimal=t.locale==="bs"||t.locale==="mk"?",":s.find(n=>n.type==="decimal").value,this._minusSign=s.find(n=>n.type==="minusSign").value,this._getDigitIndex=n=>i.get(n)}#t(t){return t.replace(new RegExp(`[${this._minusSign}]`,"g"),"-").replace(new RegExp(`[${this._digits.join("")}]`,"g"),this._getDigitIndex)}#e(t){if(this._group!==this._decimal)return t.replace(new RegExp(`[${this._group}]`,"g"),"").replace(new RegExp(`[${this._decimal}]`,"g"),".");let i=t.lastIndexOf(this._decimal);if(i===-1)return t;let s=t.slice(0,i).replace(new RegExp(`[${this._group}]`,"g"),""),n=t.slice(i+1);return`${s}.${n}`}},X=new b,o,I;function P(e={}){return Object.entries(e).sort(([t],[i])=>t.localeCompare(i)).map(t=>`${t[0]}-${t[1]}`).flat().join(":")}function q(e,t){o||(o=new Map),I!==e&&(o.clear(),I=e);let i=P(t),s=o.get(i);if(s)return s;let n=new Intl.DateTimeFormat(e,t);return o.set(i,n),n}export{l as a,$ as b,k as c,z as d,U as e,J as f,j as g,K as h,b as i,X as j,q as k};