p-4ca93e87.js 5.8 KB

123456
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import{n as t}from"./p-5ae3b7c4.js";import{c as n}from"./p-8dc9be64.js";import{c as e,b as i}from"./p-96bf42e5.js";class s{constructor(t){if(t instanceof s)return t;const[n,e]=String(t).split(".").concat("");this.value=BigInt(n+e.padEnd(s.DECIMALS,"0").slice(0,s.DECIMALS))+BigInt(s.ROUNDED&&e[s.DECIMALS]>="5"),this.isNegative="-"===t.charAt(0)}static _divRound(t,n){return s.fromBigInt(t/n+(s.ROUNDED?t*BigInt(2)/n%BigInt(2):BigInt(0)))}static fromBigInt(t){return Object.assign(Object.create(s.prototype),{value:t})}toString(){const t=this.value.toString().replace(new RegExp("-","g"),"").padStart(s.DECIMALS+1,"0"),n=t.slice(0,-s.DECIMALS),e=t.slice(-s.DECIMALS).replace(/\.?0+$/,""),i=n.concat(e.length?"."+e:"");return`${this.isNegative?"-":""}${i}`}formatToParts(t){const n=this.value.toString().replace(new RegExp("-","g"),"").padStart(s.DECIMALS+1,"0"),e=n.slice(0,-s.DECIMALS),i=n.slice(-s.DECIMALS).replace(/\.?0+$/,""),r=t.formatToParts(BigInt(e));return this.isNegative&&r.unshift({type:"minusSign",value:R.minusSign}),i.length&&(r.push({type:"decimal",value:R.decimal}),i.split("").forEach((t=>r.push({type:"fraction",value:t})))),r}format(t){const n=this.value.toString().replace(new RegExp("-","g"),"").padStart(s.DECIMALS+1,"0"),e=n.slice(0,-s.DECIMALS),i=n.slice(-s.DECIMALS).replace(/\.?0+$/,"");return`${this.isNegative?R.minusSign:""}${t.format(BigInt(e))}${i.length?`${R.decimal}${t.format(BigInt(i))}`:""}`}add(t){return s.fromBigInt(this.value+new s(t).value)}subtract(t){return s.fromBigInt(this.value-new s(t).value)}multiply(t){return s._divRound(this.value*new s(t).value,s.SHIFT)}divide(t){return s._divRound(this.value*s.SHIFT,new s(t).value)}}function r(t){return!(!t||isNaN(Number(t)))}function u(n){return n&&(e=n,t.some((t=>e.includes(t))))?l(n,(n=>{let e=!1;const i=n.split("").filter(((n,i)=>n.match(/\./g)&&!e?(e=!0,!0):!(!n.match(/\-/g)||0!==i)||t.includes(n))).reduce(((t,n)=>t+n));return r(i)?new s(i).toString():""})):"";var e}s.DECIMALS=100,s.ROUNDED=!0,s.SHIFT=BigInt("1"+"0".repeat(s.DECIMALS));const a=/^([-0])0+(?=\d)/,o=/(?!^\.)\.$/,h=/(?!^-)-/g,g=/^-\b0\b\.?0*$/,c=t=>l(t,(t=>{const n=t.replace(h,"").replace(o,"").replace(a,"$1");return r(n)?g.test(n)?n:new s(n).toString():t}));function l(t,n){if(!t)return t;const e=t.toLowerCase().indexOf("e")+1;return e?t.replace(/[eE]*$/g,"").substring(0,e).concat(t.slice(e).replace(/[eE]/g,"")).split(/[eE]/).map(((t,e)=>n(1===e?t.replace(/\./g,""):t))).join("e").replace(/^e/,"1e"):n(t)}const m=["ar","bg","bs","ca","cs","da","de","de-CH","el","en","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","nb","nl","pl","pt","pt-PT","ro","ru","sk","sl","sr","sv","th","tr","uk","vi","zh-CN","zh-HK","zh-TW"],b=["arab","arabext","bali","beng","deva","fullwide","gujr","guru","hanidec","khmr","knda","laoo","latn","limb","mlym","mong","mymr","orya","tamldec","telu","thai","tibt"],d=t=>b.includes(t),p=(new Intl.NumberFormat).resolvedOptions().numberingSystem,f="arab"!==p&&d(p)?p:"latn",w=t=>d(t)?t:f;function $(t){return m.indexOf(t)>-1?t:t?"nb"===(t=t.toLowerCase())?"no":(t.includes("-")&&(t=t.replace(/(\w+)-(\w+)/,((t,n,e)=>`${n}-${e.toUpperCase()}`)),m.includes(t)||(t=t.split("-")[0])),m.includes(t)?t:"en"):"en"}const v=new Set;function I(t){B(t),0===v.size&&x.observe(document.documentElement,{attributes:!0,attributeFilter:["lang"],subtree:!0}),v.add(t)}function B(t){t.effectiveLocale=function(t){var n;return t.el.lang||t.locale||(null===(n=e(t.el,"[lang]"))||void 0===n?void 0:n.lang)||document.documentElement.lang||"en"}(t)}function E(t){v.delete(t),0===v.size&&x.disconnect()}const x=n("mutation",(t=>{t.forEach((t=>{const n=t.target;v.forEach((t=>{const s=!(!t.locale||t.el.lang),r=!i(n,t.el);if(s||r)return;const u=e(t.el,"[lang]");if(!u)return void(t.effectiveLocale="en");const a=u.lang;t.effectiveLocale=u.hasAttribute("lang")&&""===a?"en":a}))}))})),R=new class{constructor(){this.delocalize=t=>this._numberFormatOptions?l(t,(t=>t.trim().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))):t,this.localize=t=>this._numberFormatOptions?l(t,(t=>r(t.trim())?new s(t.trim()).format(this._numberFormatter).replace(new RegExp(`[${this._actualGroup}]`,"g"),this._group):t)):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.locale=$(null==t?void 0:t.locale),t.numberingSystem=w(null==t?void 0:t.numberingSystem),!this._numberFormatOptions&&"en"===t.locale&&t.numberingSystem===f&&2===Object.keys(t).length||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();const n=new Map(this._digits.map(((t,n)=>[t,n]))),e=new Intl.NumberFormat(this._numberFormatOptions.locale).formatToParts(-12345678.9);this._actualGroup=e.find((t=>"group"===t.type)).value,this._group=0===this._actualGroup.trim().length?" ":this._actualGroup,this._decimal=e.find((t=>"decimal"===t.type)).value,this._minusSign=e.find((t=>"minusSign"===t.type)).value,this._getDigitIndex=t=>n.get(t)}};export{f as a,w as b,I as c,E as d,$ as g,r as i,R as n,u as p,c as s,B as u}