UNPKG

@liascript/exporter

Version:
1 lines 4.51 kB
!function(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},e={},i={},a=t.parcelRequire55a5;null==a&&((a=function(t){if(t in e)return e[t].exports;if(t in i){var a=i[t];delete i[t];var s={id:t,exports:{}};return e[t]=s,a.call(s.exports,s,s.exports),s.exports}var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(t,e){i[t]=e},t.parcelRequire55a5=a);var s,n,r=a("9Klpk"),l=a("3bWnf"),o=a("kb0qF"),u=a("fSF4h"),m=a("bWNdT");(n=s||(s={})).DateTime="datetime",n.List="list",n.Number="number",n.PluralRules="pluralrules",n.RelativeTime="relativetime",customElements.define("lia-format",function(t){"use strict";(0,o.default)(i,t);var e=(0,m.default)(i);function i(){var t;return(0,r.default)(this,i),(t=e.call(this)).span=document.createElement("span"),t.option={},t.value_="",t.format,t.locale,t}return(0,l.default)(i,[{key:"connectedCallback",value:function(){switch(this.attachShadow({mode:"open"}).appendChild(this.span),this.locale=this.get("locale")||void 0,this.format=this.get("format")||void 0,this.format){case"number":this.option={compactDisplay:this.get("compactDisplay"),currency:this.get("currency"),currencyDisplay:this.get("currencyDisplay"),currencySign:this.get("currencySign"),localeMatcher:this.get("localeMatcher"),maximumFractionDigits:this.get("maximumFractionDigits"),maximumSignificantDigits:this.get("maximumSignificantDigits"),minimumFractionDigits:this.get("minimumFractionDigits"),minimumIntegerDigits:this.get("minimumIntegerDigits"),minimumSignificantDigits:this.get("minimumSignificantDigits"),notation:this.get("notation"),numberingSystem:this.get("numberingSystem"),signDisplay:this.get("signDisplay"),style:this.get("localeStyle"),unit:this.get("unit"),unitDisplay:this.get("unitDisplay"),useGrouping:this.get("useGrouping")};break;case"datetime":this.option={calendar:this.get("calendar"),dateStyle:this.get("dateStyle"),day:this.get("day"),dayPeriod:this.get("dayPeriod"),era:this.get("era"),formatMatcher:this.get("formatMatcher"),fractionalSecondDigits:this.get("fractionalSecondDigits"),hour:this.get("hour"),hour12:this.get("hour12"),hourCycle:this.get("hourCycle"),localeMatcher:this.get("localeMatcher"),minute:this.get("minute"),month:this.get("month"),numberingSystem:this.get("numberingSystem"),second:this.get("second"),timeStyle:this.get("timeStyle"),timeZone:this.get("timeZone"),timeZoneName:this.get("timeZoneName"),weekday:this.get("weekday"),year:this.get("year")};break;case"relativetime":this.unit=this.get("unit")||void 0,this.option={localeMatcher:this.get("localeMatcher"),numeric:this.get("numeric"),style:this.get("localeStyle")};break;case"list":this.option={localeMatcher:this.get("localeMatcher"),style:this.get("localeStyle"),type:this.get("type")};break;case"pluralrules":this.option={localeMatcher:this.get("localeMatcher"),maximumFractionDigits:this.get("maximumFractionDigits"),maximumSignificantDigits:this.get("maximumSignificantDigits"),minimumFractionDigits:this.get("minimumFractionDigits"),minimumIntegerDigits:this.get("minimumIntegerDigits"),minimumSignificantDigits:this.get("minimumSignificantDigits"),type:this.get("type")};break;default:this.option={}}this.value_=this.textContent||"",this.view()}},{key:"view",value:function(){var t="";try{switch(this.format){case s.Number:t=new Intl.NumberFormat(this.locale,this.option).format(parseFloat(this.value_));break;case s.DateTime:t=new Intl.DateTimeFormat(this.locale,this.option).format(Date.parse(this.value_));break;case s.RelativeTime:t=new Intl.RelativeTimeFormat(this.locale,this.option).format(this.value_,this.unit);break;case s.List:t=new Intl.ListFormat(this.locale,this.option).format(JSON.parse(this.value_));break;case s.PluralRules:t=new Intl.PluralRules(this.locale,this.option).select(parseFloat(this.value_))}}catch(t){console.warn("intl-format: ",t.message)}this.span.innerText=t||this.value_}},{key:"get",value:function(t){var e=this.getAttribute(t);return null===e?void 0:e}},{key:"value",get:function(){return this.value_},set:function(t){this.value_!==t&&(this.value_=t,this.view())}},{key:"getFormat",value:function(){switch(this.get("format")){case s.DateTime:return s.DateTime;case s.List:return s.List;case s.Number:return s.Number;case s.PluralRules:return s.PluralRules;case s.RelativeTime:return s.RelativeTime}return null}},{key:"disconnectedCallback",value:function(){}}]),i}((0,u.default)(HTMLElement)))}();