diff --git a/README.md b/README.md index e9d6bef..dc0a1b8 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,8 @@ In the above example we only set the `entity:` for a tile that is enough to let | `state` | boolean | optional | false | The tile show extra state info like brightness for lights and last_changed for sensors on the tile you can also set an entity here and the state of this entity is shown on that place | | `statePath` | boolean | optional | false | In combination with `state` you can also display other values besided the entities state. for example you can set this to `attributes.brightness` to display the brightness of the entity you have set in `state` | | `hideState` | boolean | optional | false | When you do not wan't the last updated or brightness for lights is displayed you can hide the state by setting this to true | +| `timestampFormat` | string | optional | '[Klaar over] h [uur en ] mm [minuten]' | When you have a sensor with the device_class timestamp you can use the timestampFormat to format the timestamp to a readable date and time. Use text in [] brackets to add text | +| `timestampDiff` | boolean | optional | false | When you use a sensor with device_class timestamp and this display a timestamp in the future with the purpose to display in how many days/hours etc. the event takes place set this to true so it will calculate the different from now till the timestamp | | `tap_action` | number | optional | See [actions](#action-options) | can be used to customize the action on tap/click (lights and switches have already a tap action) | | `hold_action` | boolean | optional | See [actions](#action-options) | Set a custom action for hold, default it opens the more-info pop-up | | `double_tap_action` | boolean | optional | See [actions](#action-options) | Set a custom action for double tap. If no double tap is defined this will default trigger the tap action | diff --git a/dist/homekit-panel-card.js b/dist/homekit-panel-card.js index 589d385..d4b29fd 100644 --- a/dist/homekit-panel-card.js +++ b/dist/homekit-panel-card.js @@ -1,268 +1,22058 @@ -var t=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,e="[^\\s]+",i=/\[([^]*?)\]/gm;function n(t,e){for(var i=[],n=0,o=t.length;n-1?n:null}};function s(t){for(var e=[],i=1;i3?0:(t-t%10!=10?1:0)*t%10]}},c=s({},l),u=function(t,e){for(void 0===e&&(e=2),t=String(t);t.length0?"-":"+")+u(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)},Z:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+u(Math.floor(Math.abs(e)/60),2)+":"+u(Math.abs(e)%60,2)}},p=function(t){return+t-1},f=[null,"[1-9]\\d?"],g=[null,e],m=["isPm",e,function(t,e){var i=t.toLowerCase();return i===e.amPm[0]?0:i===e.amPm[1]?1:null}],v=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(t){var e=(t+"").match(/([+-]|\d\d)/gi);if(e){var i=60*+e[1]+parseInt(e[2],10);return"+"===e[0]?i:-i}return 0}],b=(o("monthNamesShort"),o("monthNames"),{default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",isoDate:"YYYY-MM-DD",isoDateTime:"YYYY-MM-DDTHH:mm:ssZ",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"});var y=function(e,n,o){if(void 0===n&&(n=b.default),void 0===o&&(o={}),"number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date pass to format");var r=[];n=(n=b[n]||n).replace(i,(function(t,e){return r.push(e),"@@@"}));var a=s(s({},c),o);return(n=n.replace(t,(function(t){return d[t](e,a)}))).replace(/@@@/g,(function(){return r.shift()}))},x=function(){try{(new Date).toLocaleDateString("i")}catch(t){return"RangeError"===t.name}return!1}()?function(t,e){return t.toLocaleDateString(e,{year:"numeric",month:"long",day:"numeric"})}:function(t){return y(t,"mediumDate")},w=function(){try{(new Date).toLocaleString("i")}catch(t){return"RangeError"===t.name}return!1}()?function(t,e){return t.toLocaleString(e,{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"2-digit"})}:function(t){return y(t,"haDateTime")},_=function(){try{(new Date).toLocaleTimeString("i")}catch(t){return"RangeError"===t.name}return!1}()?function(t,e){return t.toLocaleTimeString(e,{hour:"numeric",minute:"2-digit"})}:function(t){return y(t,"shortTime")};function S(t){return t.substr(0,t.indexOf("."))}function T(t,e,i){if("unknown"===e.state||"unavailable"===e.state)return t("state.default."+e.state);if(e.attributes.unit_of_measurement)return e.state+" "+e.attributes.unit_of_measurement;var n=function(t){return S(t.entity_id)}(e);if("input_datetime"===n){var o;if(!e.attributes.has_time)return o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),x(o,i);if(!e.attributes.has_date){var s=new Date;return o=new Date(s.getFullYear(),s.getMonth(),s.getDay(),e.attributes.hour,e.attributes.minute),_(o,i)}return o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),w(o,i)}return e.attributes.device_class&&t("component."+n+".state."+e.attributes.device_class+"."+e.state)||t("component."+n+".state._."+e.state)||e.state}var $=["closed","locked","off"],k=function(t,e,i,n){n=n||{},i=null==i?{}:i;var o=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return o.detail=i,t.dispatchEvent(o),o},z={alert:"hass:alert",automation:"hass:playlist-play",calendar:"hass:calendar",camera:"hass:video",climate:"hass:thermostat",configurator:"hass:settings",conversation:"hass:text-to-speech",device_tracker:"hass:account",fan:"hass:fan",group:"hass:google-circles-communities",history_graph:"hass:chart-line",homeassistant:"hass:home-assistant",homekit:"hass:home-automation",image_processing:"hass:image-filter-frames",input_boolean:"hass:drawing",input_datetime:"hass:calendar-clock",input_number:"hass:ray-vertex",input_select:"hass:format-list-bulleted",input_text:"hass:textbox",light:"hass:lightbulb",mailbox:"hass:mailbox",notify:"hass:comment-alert",person:"hass:account",plant:"hass:flower",proximity:"hass:apple-safari",remote:"hass:remote",scene:"hass:google-pages",script:"hass:file-document",sensor:"hass:eye",simple_alarm:"hass:bell",sun:"hass:white-balance-sunny",switch:"hass:flash",timer:"hass:timer",updater:"hass:cloud-upload",vacuum:"hass:robot-vacuum",water_heater:"hass:thermometer",weblink:"hass:open-in-new"};function E(t,e){if(t in z)return z[t];switch(t){case"alarm_control_panel":switch(e){case"armed_home":return"hass:bell-plus";case"armed_night":return"hass:bell-sleep";case"disarmed":return"hass:bell-outline";case"triggered":return"hass:bell-ring";default:return"hass:bell"}case"binary_sensor":return e&&"off"===e?"hass:radiobox-blank":"hass:checkbox-marked-circle";case"cover":return"closed"===e?"hass:window-closed":"hass:window-open";case"lock":return e&&"unlocked"===e?"hass:lock-open":"hass:lock";case"media_player":return e&&"off"!==e&&"idle"!==e?"hass:cast-connected":"hass:cast";case"zwave":switch(e){case"dead":return"hass:emoticon-dead";case"sleeping":return"hass:sleep";case"initializing":return"hass:timer-sand";default:return"hass:z-wave"}default:return console.warn("Unable to find icon for domain "+t+" ("+e+")"),"hass:bookmark"}}var C=function(t){k(window,"haptic",t)},M=function(t,e){return function(t,e,i){void 0===i&&(i=!0);var n,o=S(e),s="group"===o?"homeassistant":o;switch(o){case"lock":n=i?"unlock":"lock";break;case"cover":n=i?"open_cover":"close_cover";break;default:n=i?"turn_on":"turn_off"}return t.callService(s,n,{entity_id:e})}(t,e,$.includes(t.states[e].state))};function I(t,e){(function(t){return"string"==typeof t&&t.includes(".")&&1===parseFloat(t)})(t)&&(t="100%");var i=function(t){return"string"==typeof t&&t.includes("%")}(t);return t=360===e?t:Math.min(e,Math.max(0,parseFloat(t))),i&&(t=parseInt(String(t*e),10)/100),Math.abs(t-e)<1e-6?1:t=360===e?(t<0?t%e+e:t%e)/parseFloat(String(e)):t%e/parseFloat(String(e))}function P(t){return Math.min(1,Math.max(0,t))}function O(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function A(t){return t<=1?100*Number(t)+"%":t}function D(t){return 1===t.length?"0"+t:String(t)}function R(t,e,i){t=I(t,255),e=I(e,255),i=I(i,255);var n=Math.max(t,e,i),o=Math.min(t,e,i),s=0,r=0,a=(n+o)/2;if(n===o)r=0,s=0;else{var h=n-o;switch(r=a>.5?h/(2-n-o):h/(n+o),n){case t:s=(e-i)/h+(e1&&(i-=1),i<1/6?t+6*i*(e-t):i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}function N(t,e,i){t=I(t,255),e=I(e,255),i=I(i,255);var n=Math.max(t,e,i),o=Math.min(t,e,i),s=0,r=n,a=n-o,h=0===n?0:a/n;if(n===o)s=0;else{switch(n){case t:s=(e-i)/a+(e=0;return e||!n||!t.startsWith("hex")&&"name"!==t?("rgb"===t&&(i=this.toRgbString()),"prgb"===t&&(i=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(i=this.toHexString()),"hex3"===t&&(i=this.toHexString(!0)),"hex4"===t&&(i=this.toHex8String(!0)),"hex8"===t&&(i=this.toHex8String()),"name"===t&&(i=this.toName()),"hsl"===t&&(i=this.toHslString()),"hsv"===t&&(i=this.toHsvString()),i||this.toHexString()):"name"===t&&0===this.a?this.toName():this.toRgbString()},t.prototype.clone=function(){return new t(this.toString())},t.prototype.lighten=function(e){void 0===e&&(e=10);var i=this.toHsl();return i.l+=e/100,i.l=P(i.l),new t(i)},t.prototype.brighten=function(e){void 0===e&&(e=10);var i=this.toRgb();return i.r=Math.max(0,Math.min(255,i.r-Math.round(-e/100*255))),i.g=Math.max(0,Math.min(255,i.g-Math.round(-e/100*255))),i.b=Math.max(0,Math.min(255,i.b-Math.round(-e/100*255))),new t(i)},t.prototype.darken=function(e){void 0===e&&(e=10);var i=this.toHsl();return i.l-=e/100,i.l=P(i.l),new t(i)},t.prototype.tint=function(t){return void 0===t&&(t=10),this.mix("white",t)},t.prototype.shade=function(t){return void 0===t&&(t=10),this.mix("black",t)},t.prototype.desaturate=function(e){void 0===e&&(e=10);var i=this.toHsl();return i.s-=e/100,i.s=P(i.s),new t(i)},t.prototype.saturate=function(e){void 0===e&&(e=10);var i=this.toHsl();return i.s+=e/100,i.s=P(i.s),new t(i)},t.prototype.greyscale=function(){return this.desaturate(100)},t.prototype.spin=function(e){var i=this.toHsl(),n=(i.h+e)%360;return i.h=n<0?360+n:n,new t(i)},t.prototype.mix=function(e,i){void 0===i&&(i=50);var n=this.toRgb(),o=new t(e).toRgb(),s=i/100;return new t({r:(o.r-n.r)*s+n.r,g:(o.g-n.g)*s+n.g,b:(o.b-n.b)*s+n.b,a:(o.a-n.a)*s+n.a})},t.prototype.analogous=function(e,i){void 0===e&&(e=6),void 0===i&&(i=30);var n=this.toHsl(),o=360/i,s=[this];for(n.h=(n.h-(o*e>>1)+720)%360;--e;)n.h=(n.h+o)%360,s.push(new t(n));return s},t.prototype.complement=function(){var e=this.toHsl();return e.h=(e.h+180)%360,new t(e)},t.prototype.monochromatic=function(e){void 0===e&&(e=6);for(var i=this.toHsv(),n=i.h,o=i.s,s=i.v,r=[],a=1/e;e--;)r.push(new t({h:n,s:o,v:s})),s=(s+a)%1;return r},t.prototype.splitcomplement=function(){var e=this.toHsl(),i=e.h;return[this,new t({h:(i+72)%360,s:e.s,l:e.l}),new t({h:(i+216)%360,s:e.s,l:e.l})]},t.prototype.triad=function(){return this.polyad(3)},t.prototype.tetrad=function(){return this.polyad(4)},t.prototype.polyad=function(e){for(var i=this.toHsl(),n=i.h,o=[this],s=360/e,r=1;rsetTimeout(()=>e(new Error("timeout")),n))]).catch(t=>{if(!t.message||"timeout"!==t.message)throw t;return null})}(i,"$ ha-more-info-dialog");return n&&(n.large=e),n}const st="lovelace-player-device-id";function rt(){if(!localStorage[st]){const t=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[st]=fully.getDeviceId():localStorage[st]=`${t()}${t()}-${t()}${t()}`}return localStorage[st]}let at=rt();const ht=new URLSearchParams(window.location.search);var lt;ht.get("deviceID")&&null!==(lt=ht.get("deviceID"))&&("clear"===lt?localStorage.removeItem(st):localStorage[st]=lt,at=rt());let ct=window.cardHelpers;const ut=new Promise(async(t,e)=>{ct&&t();const i=async()=>{ct=await window.loadCardHelpers(),window.cardHelpers=ct,t()};window.loadCardHelpers?i():window.addEventListener("load",async()=>{!async function(){if(customElements.get("hui-view"))return!0;await customElements.whenDefined("partial-panel-resolver");const t=document.createElement("partial-panel-resolver");if(t.hass={panels:[{url_path:"tmp",component_name:"lovelace"}]},t._updateRoutes(),await t.routerOptions.routes.tmp.load(),!customElements.get("ha-panel-lovelace"))return!1;const e=document.createElement("ha-panel-lovelace");e.hass=et(),void 0===e.hass&&(await new Promise(t=>{window.addEventListener("connection-status",e=>{console.log(e),t()},{once:!0})}),e.hass=et()),e.panel={config:{mode:null}},e._fetchConfig()}(),window.loadCardHelpers&&i()})});function dt(t,e){const i={type:"error",error:t,origConfig:e},n=document.createElement("hui-error-card");return customElements.whenDefined("hui-error-card").then(()=>{const t=document.createElement("hui-error-card");t.setConfig(i),n.parentElement&&n.parentElement.replaceChild(t,n)}),ut.then(()=>{it("ll-rebuild",{},n)}),n}function pt(t,e){if(!e||"object"!=typeof e||!e.type)return dt(`No ${t} type configured`,e);let i=e.type;if(i=i.startsWith("custom:")?i.substr("custom:".length):`hui-${i}-${t}`,customElements.get(i))return function(t,e){let i=document.createElement(t);try{i.setConfig(JSON.parse(JSON.stringify(e)))}catch(t){i=dt(t,e)}return ut.then(()=>{it("ll-rebuild",{},i)}),i}(i,e);const n=dt(`Custom element doesn't exist: ${i}.`,e);n.style.display="None";const o=setTimeout(()=>{n.style.display=""},2e3);return customElements.whenDefined(i).then(()=>{clearTimeout(o),it("ll-rebuild",{},n)}),n}var ft="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function gt(t,e){return t(e={exports:{}},e.exports),e.exports}gt((function(t){ +var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g; +var twoDigitsOptional = "[1-9]\\d?"; +var twoDigits = "\\d\\d"; +var threeDigits = "\\d{3}"; +var fourDigits = "\\d{4}"; +var word = "[^\\s]+"; +var literal = /\[([^]*?)\]/gm; +function shorten(arr, sLen) { + var newArr = []; + for (var i = 0, len = arr.length; i < len; i++) { + newArr.push(arr[i].substr(0, sLen)); + } + return newArr; +} +var monthUpdate = function (arrName) { return function (v, i18n) { + var lowerCaseArr = i18n[arrName].map(function (v) { return v.toLowerCase(); }); + var index = lowerCaseArr.indexOf(v.toLowerCase()); + if (index > -1) { + return index; + } + return null; +}; }; +function assign(origObj) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + for (var _a = 0, args_1 = args; _a < args_1.length; _a++) { + var obj = args_1[_a]; + for (var key in obj) { + // @ts-ignore ex + origObj[key] = obj[key]; + } + } + return origObj; +} +var dayNames = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday" +]; +var monthNames = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" +]; +var monthNamesShort = shorten(monthNames, 3); +var dayNamesShort = shorten(dayNames, 3); +var defaultI18n = { + dayNamesShort: dayNamesShort, + dayNames: dayNames, + monthNamesShort: monthNamesShort, + monthNames: monthNames, + amPm: ["am", "pm"], + DoFn: function (dayOfMonth) { + return (dayOfMonth + + ["th", "st", "nd", "rd"][dayOfMonth % 10 > 3 + ? 0 + : ((dayOfMonth - (dayOfMonth % 10) !== 10 ? 1 : 0) * dayOfMonth) % 10]); + } +}; +var globalI18n = assign({}, defaultI18n); +var setGlobalDateI18n = function (i18n) { + return (globalI18n = assign(globalI18n, i18n)); +}; +var regexEscape = function (str) { + return str.replace(/[|\\{()[^$+*?.-]/g, "\\$&"); +}; +var pad = function (val, len) { + if (len === void 0) { len = 2; } + val = String(val); + while (val.length < len) { + val = "0" + val; + } + return val; +}; +var formatFlags = { + D: function (dateObj) { return String(dateObj.getDate()); }, + DD: function (dateObj) { return pad(dateObj.getDate()); }, + Do: function (dateObj, i18n) { + return i18n.DoFn(dateObj.getDate()); + }, + d: function (dateObj) { return String(dateObj.getDay()); }, + dd: function (dateObj) { return pad(dateObj.getDay()); }, + ddd: function (dateObj, i18n) { + return i18n.dayNamesShort[dateObj.getDay()]; + }, + dddd: function (dateObj, i18n) { + return i18n.dayNames[dateObj.getDay()]; + }, + M: function (dateObj) { return String(dateObj.getMonth() + 1); }, + MM: function (dateObj) { return pad(dateObj.getMonth() + 1); }, + MMM: function (dateObj, i18n) { + return i18n.monthNamesShort[dateObj.getMonth()]; + }, + MMMM: function (dateObj, i18n) { + return i18n.monthNames[dateObj.getMonth()]; + }, + YY: function (dateObj) { + return pad(String(dateObj.getFullYear()), 4).substr(2); + }, + YYYY: function (dateObj) { return pad(dateObj.getFullYear(), 4); }, + h: function (dateObj) { return String(dateObj.getHours() % 12 || 12); }, + hh: function (dateObj) { return pad(dateObj.getHours() % 12 || 12); }, + H: function (dateObj) { return String(dateObj.getHours()); }, + HH: function (dateObj) { return pad(dateObj.getHours()); }, + m: function (dateObj) { return String(dateObj.getMinutes()); }, + mm: function (dateObj) { return pad(dateObj.getMinutes()); }, + s: function (dateObj) { return String(dateObj.getSeconds()); }, + ss: function (dateObj) { return pad(dateObj.getSeconds()); }, + S: function (dateObj) { + return String(Math.round(dateObj.getMilliseconds() / 100)); + }, + SS: function (dateObj) { + return pad(Math.round(dateObj.getMilliseconds() / 10), 2); + }, + SSS: function (dateObj) { return pad(dateObj.getMilliseconds(), 3); }, + a: function (dateObj, i18n) { + return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1]; + }, + A: function (dateObj, i18n) { + return dateObj.getHours() < 12 + ? i18n.amPm[0].toUpperCase() + : i18n.amPm[1].toUpperCase(); + }, + ZZ: function (dateObj) { + var offset = dateObj.getTimezoneOffset(); + return ((offset > 0 ? "-" : "+") + + pad(Math.floor(Math.abs(offset) / 60) * 100 + (Math.abs(offset) % 60), 4)); + }, + Z: function (dateObj) { + var offset = dateObj.getTimezoneOffset(); + return ((offset > 0 ? "-" : "+") + + pad(Math.floor(Math.abs(offset) / 60), 2) + + ":" + + pad(Math.abs(offset) % 60, 2)); + } +}; +var monthParse = function (v) { return +v - 1; }; +var emptyDigits = [null, twoDigitsOptional]; +var emptyWord = [null, word]; +var amPm = [ + "isPm", + word, + function (v, i18n) { + var val = v.toLowerCase(); + if (val === i18n.amPm[0]) { + return 0; + } + else if (val === i18n.amPm[1]) { + return 1; + } + return null; + } +]; +var timezoneOffset = [ + "timezoneOffset", + "[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?", + function (v) { + var parts = (v + "").match(/([+-]|\d\d)/gi); + if (parts) { + var minutes = +parts[1] * 60 + parseInt(parts[2], 10); + return parts[0] === "+" ? minutes : -minutes; + } + return 0; + } +]; +var parseFlags = { + D: ["day", twoDigitsOptional], + DD: ["day", twoDigits], + Do: ["day", twoDigitsOptional + word, function (v) { return parseInt(v, 10); }], + M: ["month", twoDigitsOptional, monthParse], + MM: ["month", twoDigits, monthParse], + YY: [ + "year", + twoDigits, + function (v) { + var now = new Date(); + var cent = +("" + now.getFullYear()).substr(0, 2); + return +("" + (+v > 68 ? cent - 1 : cent) + v); + } + ], + h: ["hour", twoDigitsOptional, undefined, "isPm"], + hh: ["hour", twoDigits, undefined, "isPm"], + H: ["hour", twoDigitsOptional], + HH: ["hour", twoDigits], + m: ["minute", twoDigitsOptional], + mm: ["minute", twoDigits], + s: ["second", twoDigitsOptional], + ss: ["second", twoDigits], + YYYY: ["year", fourDigits], + S: ["millisecond", "\\d", function (v) { return +v * 100; }], + SS: ["millisecond", twoDigits, function (v) { return +v * 10; }], + SSS: ["millisecond", threeDigits], + d: emptyDigits, + dd: emptyDigits, + ddd: emptyWord, + dddd: emptyWord, + MMM: ["month", word, monthUpdate("monthNamesShort")], + MMMM: ["month", word, monthUpdate("monthNames")], + a: amPm, + A: amPm, + ZZ: timezoneOffset, + Z: timezoneOffset +}; +// Some common format strings +var globalMasks = { + default: "ddd MMM DD YYYY HH:mm:ss", + shortDate: "M/D/YY", + mediumDate: "MMM D, YYYY", + longDate: "MMMM D, YYYY", + fullDate: "dddd, MMMM D, YYYY", + isoDate: "YYYY-MM-DD", + isoDateTime: "YYYY-MM-DDTHH:mm:ssZ", + shortTime: "HH:mm", + mediumTime: "HH:mm:ss", + longTime: "HH:mm:ss.SSS" +}; +var setGlobalDateMasks = function (masks) { return assign(globalMasks, masks); }; +/*** + * Format a date + * @method format + * @param {Date|number} dateObj + * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate' + * @returns {string} Formatted date string + */ +var format = function (dateObj, mask, i18n) { + if (mask === void 0) { mask = globalMasks["default"]; } + if (i18n === void 0) { i18n = {}; } + if (typeof dateObj === "number") { + dateObj = new Date(dateObj); + } + if (Object.prototype.toString.call(dateObj) !== "[object Date]" || + isNaN(dateObj.getTime())) { + throw new Error("Invalid Date pass to format"); + } + mask = globalMasks[mask] || mask; + var literals = []; + // Make literals inactive by replacing them with @@@ + mask = mask.replace(literal, function ($0, $1) { + literals.push($1); + return "@@@"; + }); + var combinedI18nSettings = assign(assign({}, globalI18n), i18n); + // Apply formatting rules + mask = mask.replace(token, function ($0) { + return formatFlags[$0](dateObj, combinedI18nSettings); + }); + // Inline literal values back into the formatted value + return mask.replace(/@@@/g, function () { return literals.shift(); }); +}; +/** + * Parse a date string into a Javascript Date object / + * @method parse + * @param {string} dateStr Date string + * @param {string} format Date parse format + * @param {i18n} I18nSettingsOptional Full or subset of I18N settings + * @returns {Date|null} Returns Date object. Returns null what date string is invalid or doesn't match format + */ +function parse(dateStr, format, i18n) { + if (i18n === void 0) { i18n = {}; } + if (typeof format !== "string") { + throw new Error("Invalid format in fecha parse"); + } + // Check to see if the format is actually a mask + format = globalMasks[format] || format; + // Avoid regular expression denial of service, fail early for really long strings + // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS + if (dateStr.length > 1000) { + return null; + } + // Default to the beginning of the year. + var today = new Date(); + var dateInfo = { + year: today.getFullYear(), + month: 0, + day: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + isPm: null, + timezoneOffset: null + }; + var parseInfo = []; + var literals = []; + // Replace all the literals with @@@. Hopefully a string that won't exist in the format + var newFormat = format.replace(literal, function ($0, $1) { + literals.push(regexEscape($1)); + return "@@@"; + }); + var specifiedFields = {}; + var requiredFields = {}; + // Change every token that we find into the correct regex + newFormat = regexEscape(newFormat).replace(token, function ($0) { + var info = parseFlags[$0]; + var field = info[0], regex = info[1], requiredField = info[3]; + // Check if the person has specified the same field twice. This will lead to confusing results. + if (specifiedFields[field]) { + throw new Error("Invalid format. " + field + " specified twice in format"); + } + specifiedFields[field] = true; + // Check if there are any required fields. For instance, 12 hour time requires AM/PM specified + if (requiredField) { + requiredFields[requiredField] = true; + } + parseInfo.push(info); + return "(" + regex + ")"; + }); + // Check all the required fields are present + Object.keys(requiredFields).forEach(function (field) { + if (!specifiedFields[field]) { + throw new Error("Invalid format. " + field + " is required in specified format"); + } + }); + // Add back all the literals after + newFormat = newFormat.replace(/@@@/g, function () { return literals.shift(); }); + // Check if the date string matches the format. If it doesn't return null + var matches = dateStr.match(new RegExp(newFormat, "i")); + if (!matches) { + return null; + } + var combinedI18nSettings = assign(assign({}, globalI18n), i18n); + // For each match, call the parser function for that date part + for (var i = 1; i < matches.length; i++) { + var _a = parseInfo[i - 1], field = _a[0], parser = _a[2]; + var value = parser + ? parser(matches[i], combinedI18nSettings) + : +matches[i]; + // If the parser can't make sense of the value, return null + if (value == null) { + return null; + } + dateInfo[field] = value; + } + if (dateInfo.isPm === 1 && dateInfo.hour != null && +dateInfo.hour !== 12) { + dateInfo.hour = +dateInfo.hour + 12; + } + else if (dateInfo.isPm === 0 && +dateInfo.hour === 12) { + dateInfo.hour = 0; + } + var dateWithoutTZ = new Date(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute, dateInfo.second, dateInfo.millisecond); + var validateFields = [ + ["month", "getMonth"], + ["day", "getDate"], + ["hour", "getHours"], + ["minute", "getMinutes"], + ["second", "getSeconds"] + ]; + for (var i = 0, len = validateFields.length; i < len; i++) { + // Check to make sure the date field is within the allowed range. Javascript dates allows values + // outside the allowed range. If the values don't match the value was invalid + if (specifiedFields[validateFields[i][0]] && + dateInfo[validateFields[i][0]] !== dateWithoutTZ[validateFields[i][1]]()) { + return null; + } + } + if (dateInfo.timezoneOffset == null) { + return dateWithoutTZ; + } + return new Date(Date.UTC(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute - dateInfo.timezoneOffset, dateInfo.second, dateInfo.millisecond)); +} +var fecha = { + format: format, + parse: parse, + defaultI18n: defaultI18n, + setGlobalDateI18n: setGlobalDateI18n, + setGlobalDateMasks: setGlobalDateMasks +}; +//# sourceMappingURL=fecha.js.map + +var a=function(){try{(new Date).toLocaleDateString("i");}catch(e){return "RangeError"===e.name}return !1}()?function(e,t){return e.toLocaleDateString(t,{year:"numeric",month:"long",day:"numeric"})}:function(t){return fecha.format(t,"mediumDate")},r=function(){try{(new Date).toLocaleString("i");}catch(e){return "RangeError"===e.name}return !1}()?function(e,t){return e.toLocaleString(t,{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"2-digit"})}:function(t){return fecha.format(t,"haDateTime")},n=function(){try{(new Date).toLocaleTimeString("i");}catch(e){return "RangeError"===e.name}return !1}()?function(e,t){return e.toLocaleTimeString(t,{hour:"numeric",minute:"2-digit"})}:function(t){return fecha.format(t,"shortTime")};function d(e){return e.substr(0,e.indexOf("."))}function v(e){return d(e.entity_id)}function b(e,t,s){if("unknown"===t.state||"unavailable"===t.state)return e("state.default."+t.state);if(t.attributes.unit_of_measurement)return t.state+" "+t.attributes.unit_of_measurement;var i=v(t);if("input_datetime"===i){var o;if(!t.attributes.has_time)return o=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),a(o,s);if(!t.attributes.has_date){var c=new Date;return o=new Date(c.getFullYear(),c.getMonth(),c.getDay(),t.attributes.hour,t.attributes.minute),n(o,s)}return o=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),r(o,s)}return t.attributes.device_class&&e("component."+i+".state."+t.attributes.device_class+"."+t.state)||e("component."+i+".state._."+t.state)||t.state}var _="hass:bookmark",D=["closed","locked","off"],C=function(e,t,a,r){r=r||{},a=null==a?{}:a;var n=new Event(t,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return n.detail=a,e.dispatchEvent(n),n},N={alert:"hass:alert",automation:"hass:playlist-play",calendar:"hass:calendar",camera:"hass:video",climate:"hass:thermostat",configurator:"hass:settings",conversation:"hass:text-to-speech",device_tracker:"hass:account",fan:"hass:fan",group:"hass:google-circles-communities",history_graph:"hass:chart-line",homeassistant:"hass:home-assistant",homekit:"hass:home-automation",image_processing:"hass:image-filter-frames",input_boolean:"hass:drawing",input_datetime:"hass:calendar-clock",input_number:"hass:ray-vertex",input_select:"hass:format-list-bulleted",input_text:"hass:textbox",light:"hass:lightbulb",mailbox:"hass:mailbox",notify:"hass:comment-alert",person:"hass:account",plant:"hass:flower",proximity:"hass:apple-safari",remote:"hass:remote",scene:"hass:google-pages",script:"hass:file-document",sensor:"hass:eye",simple_alarm:"hass:bell",sun:"hass:white-balance-sunny",switch:"hass:flash",timer:"hass:timer",updater:"hass:cloud-upload",vacuum:"hass:robot-vacuum",water_heater:"hass:thermometer",weblink:"hass:open-in-new"};function O(e,t){if(e in N)return N[e];switch(e){case"alarm_control_panel":switch(t){case"armed_home":return "hass:bell-plus";case"armed_night":return "hass:bell-sleep";case"disarmed":return "hass:bell-outline";case"triggered":return "hass:bell-ring";default:return "hass:bell"}case"binary_sensor":return t&&"off"===t?"hass:radiobox-blank":"hass:checkbox-marked-circle";case"cover":return "closed"===t?"hass:window-closed":"hass:window-open";case"lock":return t&&"unlocked"===t?"hass:lock-open":"hass:lock";case"media_player":return t&&"off"!==t&&"idle"!==t?"hass:cast-connected":"hass:cast";case"zwave":switch(t){case"dead":return "hass:emoticon-dead";case"sleeping":return "hass:sleep";case"initializing":return "hass:timer-sand";default:return "hass:z-wave"}default:return console.warn("Unable to find icon for domain "+e+" ("+t+")"),_}}var z=function(e){C(window,"haptic",e);},F=function(e,t,a){void 0===a&&(a=!1),a?history.replaceState(null,"",t):history.pushState(null,"",t),C(window,"location-changed",{replace:a});},I=function(e,t,a){void 0===a&&(a=!0);var r,n=d(t),s="group"===n?"homeassistant":n;switch(n){case"lock":r=a?"unlock":"lock";break;case"cover":r=a?"open_cover":"close_cover";break;default:r=a?"turn_on":"turn_off";}return e.callService(s,r,{entity_id:t})},B=function(e,t){var a=D.includes(e.states[t].state);return I(e,t,a)};//# sourceMappingURL=index.m.js.map + +function bound01(n, max) { + if (isOnePointZero(n)) { + n = '100%'; + } + var processPercent = isPercentage(n); + n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n))); + if (processPercent) { + n = parseInt(String(n * max), 10) / 100; + } + if (Math.abs(n - max) < 0.000001) { + return 1; + } + if (max === 360) { + n = (n < 0 ? (n % max) + max : n % max) / parseFloat(String(max)); + } + else { + n = (n % max) / parseFloat(String(max)); + } + return n; +} +function clamp01(val) { + return Math.min(1, Math.max(0, val)); +} +function isOnePointZero(n) { + return typeof n === 'string' && n.includes('.') && parseFloat(n) === 1; +} +function isPercentage(n) { + return typeof n === 'string' && n.includes('%'); +} +function boundAlpha(a) { + a = parseFloat(a); + if (isNaN(a) || a < 0 || a > 1) { + a = 1; + } + return a; +} +function convertToPercentage(n) { + if (n <= 1) { + return Number(n) * 100 + "%"; + } + return n; +} +function pad2(c) { + return c.length === 1 ? '0' + c : String(c); +} + +function rgbToRgb(r, g, b) { + return { + r: bound01(r, 255) * 255, + g: bound01(g, 255) * 255, + b: bound01(b, 255) * 255, + }; +} +function rgbToHsl(r, g, b) { + r = bound01(r, 255); + g = bound01(g, 255); + b = bound01(b, 255); + var max = Math.max(r, g, b); + var min = Math.min(r, g, b); + var h = 0; + var s = 0; + var l = (max + min) / 2; + if (max === min) { + s = 0; + h = 0; + } + else { + var d = max - min; + s = l > 0.5 ? d / (2 - max - min) : d / (max + min); + switch (max) { + case r: + h = ((g - b) / d) + (g < b ? 6 : 0); + break; + case g: + h = ((b - r) / d) + 2; + break; + case b: + h = ((r - g) / d) + 4; + break; + } + h /= 6; + } + return { h: h, s: s, l: l }; +} +function hue2rgb(p, q, t) { + if (t < 0) { + t += 1; + } + if (t > 1) { + t -= 1; + } + if (t < 1 / 6) { + return p + ((q - p) * (6 * t)); + } + if (t < 1 / 2) { + return q; + } + if (t < 2 / 3) { + return p + ((q - p) * ((2 / 3) - t) * 6); + } + return p; +} +function hslToRgb(h, s, l) { + var r; + var g; + var b; + h = bound01(h, 360); + s = bound01(s, 100); + l = bound01(l, 100); + if (s === 0) { + g = l; + b = l; + r = l; + } + else { + var q = l < 0.5 ? (l * (1 + s)) : (l + s - (l * s)); + var p = (2 * l) - q; + r = hue2rgb(p, q, h + (1 / 3)); + g = hue2rgb(p, q, h); + b = hue2rgb(p, q, h - (1 / 3)); + } + return { r: r * 255, g: g * 255, b: b * 255 }; +} +function rgbToHsv(r, g, b) { + r = bound01(r, 255); + g = bound01(g, 255); + b = bound01(b, 255); + var max = Math.max(r, g, b); + var min = Math.min(r, g, b); + var h = 0; + var v = max; + var d = max - min; + var s = max === 0 ? 0 : d / max; + if (max === min) { + h = 0; + } + else { + switch (max) { + case r: + h = ((g - b) / d) + (g < b ? 6 : 0); + break; + case g: + h = ((b - r) / d) + 2; + break; + case b: + h = ((r - g) / d) + 4; + break; + } + h /= 6; + } + return { h: h, s: s, v: v }; +} +function hsvToRgb(h, s, v) { + h = bound01(h, 360) * 6; + s = bound01(s, 100); + v = bound01(v, 100); + var i = Math.floor(h); + var f = h - i; + var p = v * (1 - s); + var q = v * (1 - (f * s)); + var t = v * (1 - ((1 - f) * s)); + var mod = i % 6; + var r = [v, q, p, p, t, v][mod]; + var g = [t, v, v, q, p, p][mod]; + var b = [p, p, t, v, v, q][mod]; + return { r: r * 255, g: g * 255, b: b * 255 }; +} +function rgbToHex(r, g, b, allow3Char) { + var hex = [ + pad2(Math.round(r).toString(16)), + pad2(Math.round(g).toString(16)), + pad2(Math.round(b).toString(16)), + ]; + if (allow3Char && + hex[0].startsWith(hex[0].charAt(1)) && + hex[1].startsWith(hex[1].charAt(1)) && + hex[2].startsWith(hex[2].charAt(1))) { + return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0); + } + return hex.join(''); +} +function rgbaToHex(r, g, b, a, allow4Char) { + var hex = [ + pad2(Math.round(r).toString(16)), + pad2(Math.round(g).toString(16)), + pad2(Math.round(b).toString(16)), + pad2(convertDecimalToHex(a)), + ]; + if (allow4Char && + hex[0].startsWith(hex[0].charAt(1)) && + hex[1].startsWith(hex[1].charAt(1)) && + hex[2].startsWith(hex[2].charAt(1)) && + hex[3].startsWith(hex[3].charAt(1))) { + return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0); + } + return hex.join(''); +} +function convertDecimalToHex(d) { + return Math.round(parseFloat(d) * 255).toString(16); +} +function convertHexToDecimal(h) { + return parseIntFromHex(h) / 255; +} +function parseIntFromHex(val) { + return parseInt(val, 16); +} + +var names = { + aliceblue: '#f0f8ff', + antiquewhite: '#faebd7', + aqua: '#00ffff', + aquamarine: '#7fffd4', + azure: '#f0ffff', + beige: '#f5f5dc', + bisque: '#ffe4c4', + black: '#000000', + blanchedalmond: '#ffebcd', + blue: '#0000ff', + blueviolet: '#8a2be2', + brown: '#a52a2a', + burlywood: '#deb887', + cadetblue: '#5f9ea0', + chartreuse: '#7fff00', + chocolate: '#d2691e', + coral: '#ff7f50', + cornflowerblue: '#6495ed', + cornsilk: '#fff8dc', + crimson: '#dc143c', + cyan: '#00ffff', + darkblue: '#00008b', + darkcyan: '#008b8b', + darkgoldenrod: '#b8860b', + darkgray: '#a9a9a9', + darkgreen: '#006400', + darkgrey: '#a9a9a9', + darkkhaki: '#bdb76b', + darkmagenta: '#8b008b', + darkolivegreen: '#556b2f', + darkorange: '#ff8c00', + darkorchid: '#9932cc', + darkred: '#8b0000', + darksalmon: '#e9967a', + darkseagreen: '#8fbc8f', + darkslateblue: '#483d8b', + darkslategray: '#2f4f4f', + darkslategrey: '#2f4f4f', + darkturquoise: '#00ced1', + darkviolet: '#9400d3', + deeppink: '#ff1493', + deepskyblue: '#00bfff', + dimgray: '#696969', + dimgrey: '#696969', + dodgerblue: '#1e90ff', + firebrick: '#b22222', + floralwhite: '#fffaf0', + forestgreen: '#228b22', + fuchsia: '#ff00ff', + gainsboro: '#dcdcdc', + ghostwhite: '#f8f8ff', + gold: '#ffd700', + goldenrod: '#daa520', + gray: '#808080', + green: '#008000', + greenyellow: '#adff2f', + grey: '#808080', + honeydew: '#f0fff0', + hotpink: '#ff69b4', + indianred: '#cd5c5c', + indigo: '#4b0082', + ivory: '#fffff0', + khaki: '#f0e68c', + lavender: '#e6e6fa', + lavenderblush: '#fff0f5', + lawngreen: '#7cfc00', + lemonchiffon: '#fffacd', + lightblue: '#add8e6', + lightcoral: '#f08080', + lightcyan: '#e0ffff', + lightgoldenrodyellow: '#fafad2', + lightgray: '#d3d3d3', + lightgreen: '#90ee90', + lightgrey: '#d3d3d3', + lightpink: '#ffb6c1', + lightsalmon: '#ffa07a', + lightseagreen: '#20b2aa', + lightskyblue: '#87cefa', + lightslategray: '#778899', + lightslategrey: '#778899', + lightsteelblue: '#b0c4de', + lightyellow: '#ffffe0', + lime: '#00ff00', + limegreen: '#32cd32', + linen: '#faf0e6', + magenta: '#ff00ff', + maroon: '#800000', + mediumaquamarine: '#66cdaa', + mediumblue: '#0000cd', + mediumorchid: '#ba55d3', + mediumpurple: '#9370db', + mediumseagreen: '#3cb371', + mediumslateblue: '#7b68ee', + mediumspringgreen: '#00fa9a', + mediumturquoise: '#48d1cc', + mediumvioletred: '#c71585', + midnightblue: '#191970', + mintcream: '#f5fffa', + mistyrose: '#ffe4e1', + moccasin: '#ffe4b5', + navajowhite: '#ffdead', + navy: '#000080', + oldlace: '#fdf5e6', + olive: '#808000', + olivedrab: '#6b8e23', + orange: '#ffa500', + orangered: '#ff4500', + orchid: '#da70d6', + palegoldenrod: '#eee8aa', + palegreen: '#98fb98', + paleturquoise: '#afeeee', + palevioletred: '#db7093', + papayawhip: '#ffefd5', + peachpuff: '#ffdab9', + peru: '#cd853f', + pink: '#ffc0cb', + plum: '#dda0dd', + powderblue: '#b0e0e6', + purple: '#800080', + rebeccapurple: '#663399', + red: '#ff0000', + rosybrown: '#bc8f8f', + royalblue: '#4169e1', + saddlebrown: '#8b4513', + salmon: '#fa8072', + sandybrown: '#f4a460', + seagreen: '#2e8b57', + seashell: '#fff5ee', + sienna: '#a0522d', + silver: '#c0c0c0', + skyblue: '#87ceeb', + slateblue: '#6a5acd', + slategray: '#708090', + slategrey: '#708090', + snow: '#fffafa', + springgreen: '#00ff7f', + steelblue: '#4682b4', + tan: '#d2b48c', + teal: '#008080', + thistle: '#d8bfd8', + tomato: '#ff6347', + turquoise: '#40e0d0', + violet: '#ee82ee', + wheat: '#f5deb3', + white: '#ffffff', + whitesmoke: '#f5f5f5', + yellow: '#ffff00', + yellowgreen: '#9acd32', +}; + +function inputToRGB(color) { + var rgb = { r: 0, g: 0, b: 0 }; + var a = 1; + var s = null; + var v = null; + var l = null; + var ok = false; + var format = false; + if (typeof color === 'string') { + color = stringInputToObject(color); + } + if (typeof color === 'object') { + if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { + rgb = rgbToRgb(color.r, color.g, color.b); + ok = true; + format = String(color.r).substr(-1) === '%' ? 'prgb' : 'rgb'; + } + else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { + s = convertToPercentage(color.s); + v = convertToPercentage(color.v); + rgb = hsvToRgb(color.h, s, v); + ok = true; + format = 'hsv'; + } + else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) { + s = convertToPercentage(color.s); + l = convertToPercentage(color.l); + rgb = hslToRgb(color.h, s, l); + ok = true; + format = 'hsl'; + } + if (Object.prototype.hasOwnProperty.call(color, 'a')) { + a = color.a; + } + } + a = boundAlpha(a); + return { + ok: ok, + format: color.format || format, + r: Math.min(255, Math.max(rgb.r, 0)), + g: Math.min(255, Math.max(rgb.g, 0)), + b: Math.min(255, Math.max(rgb.b, 0)), + a: a, + }; +} +var CSS_INTEGER = '[-\\+]?\\d+%?'; +var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; +var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; +var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; +var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; +var matchers = { + CSS_UNIT: new RegExp(CSS_UNIT), + rgb: new RegExp('rgb' + PERMISSIVE_MATCH3), + rgba: new RegExp('rgba' + PERMISSIVE_MATCH4), + hsl: new RegExp('hsl' + PERMISSIVE_MATCH3), + hsla: new RegExp('hsla' + PERMISSIVE_MATCH4), + hsv: new RegExp('hsv' + PERMISSIVE_MATCH3), + hsva: new RegExp('hsva' + PERMISSIVE_MATCH4), + hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, + hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/, + hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, + hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/, +}; +function stringInputToObject(color) { + color = color.trim().toLowerCase(); + if (color.length === 0) { + return false; + } + var named = false; + if (names[color]) { + color = names[color]; + named = true; + } + else if (color === 'transparent') { + return { r: 0, g: 0, b: 0, a: 0, format: 'name' }; + } + var match = matchers.rgb.exec(color); + if (match) { + return { r: match[1], g: match[2], b: match[3] }; + } + match = matchers.rgba.exec(color); + if (match) { + return { r: match[1], g: match[2], b: match[3], a: match[4] }; + } + match = matchers.hsl.exec(color); + if (match) { + return { h: match[1], s: match[2], l: match[3] }; + } + match = matchers.hsla.exec(color); + if (match) { + return { h: match[1], s: match[2], l: match[3], a: match[4] }; + } + match = matchers.hsv.exec(color); + if (match) { + return { h: match[1], s: match[2], v: match[3] }; + } + match = matchers.hsva.exec(color); + if (match) { + return { h: match[1], s: match[2], v: match[3], a: match[4] }; + } + match = matchers.hex8.exec(color); + if (match) { + return { + r: parseIntFromHex(match[1]), + g: parseIntFromHex(match[2]), + b: parseIntFromHex(match[3]), + a: convertHexToDecimal(match[4]), + format: named ? 'name' : 'hex8', + }; + } + match = matchers.hex6.exec(color); + if (match) { + return { + r: parseIntFromHex(match[1]), + g: parseIntFromHex(match[2]), + b: parseIntFromHex(match[3]), + format: named ? 'name' : 'hex', + }; + } + match = matchers.hex4.exec(color); + if (match) { + return { + r: parseIntFromHex(match[1] + match[1]), + g: parseIntFromHex(match[2] + match[2]), + b: parseIntFromHex(match[3] + match[3]), + a: convertHexToDecimal(match[4] + match[4]), + format: named ? 'name' : 'hex8', + }; + } + match = matchers.hex3.exec(color); + if (match) { + return { + r: parseIntFromHex(match[1] + match[1]), + g: parseIntFromHex(match[2] + match[2]), + b: parseIntFromHex(match[3] + match[3]), + format: named ? 'name' : 'hex', + }; + } + return false; +} +function isValidCSSUnit(color) { + return Boolean(matchers.CSS_UNIT.exec(String(color))); +} + +var TinyColor = (function () { + function TinyColor(color, opts) { + if (color === void 0) { color = ''; } + if (opts === void 0) { opts = {}; } + var _a; + if (color instanceof TinyColor) { + return color; + } + this.originalInput = color; + var rgb = inputToRGB(color); + this.originalInput = color; + this.r = rgb.r; + this.g = rgb.g; + this.b = rgb.b; + this.a = rgb.a; + this.roundA = Math.round(100 * this.a) / 100; + this.format = (_a = opts.format, (_a !== null && _a !== void 0 ? _a : rgb.format)); + this.gradientType = opts.gradientType; + if (this.r < 1) { + this.r = Math.round(this.r); + } + if (this.g < 1) { + this.g = Math.round(this.g); + } + if (this.b < 1) { + this.b = Math.round(this.b); + } + this.isValid = rgb.ok; + } + TinyColor.prototype.isDark = function () { + return this.getBrightness() < 128; + }; + TinyColor.prototype.isLight = function () { + return !this.isDark(); + }; + TinyColor.prototype.getBrightness = function () { + var rgb = this.toRgb(); + return ((rgb.r * 299) + (rgb.g * 587) + (rgb.b * 114)) / 1000; + }; + TinyColor.prototype.getLuminance = function () { + var rgb = this.toRgb(); + var R; + var G; + var B; + var RsRGB = rgb.r / 255; + var GsRGB = rgb.g / 255; + var BsRGB = rgb.b / 255; + if (RsRGB <= 0.03928) { + R = RsRGB / 12.92; + } + else { + R = Math.pow((RsRGB + 0.055) / 1.055, 2.4); + } + if (GsRGB <= 0.03928) { + G = GsRGB / 12.92; + } + else { + G = Math.pow((GsRGB + 0.055) / 1.055, 2.4); + } + if (BsRGB <= 0.03928) { + B = BsRGB / 12.92; + } + else { + B = Math.pow((BsRGB + 0.055) / 1.055, 2.4); + } + return (0.2126 * R) + (0.7152 * G) + (0.0722 * B); + }; + TinyColor.prototype.getAlpha = function () { + return this.a; + }; + TinyColor.prototype.setAlpha = function (alpha) { + this.a = boundAlpha(alpha); + this.roundA = Math.round(100 * this.a) / 100; + return this; + }; + TinyColor.prototype.toHsv = function () { + var hsv = rgbToHsv(this.r, this.g, this.b); + return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a }; + }; + TinyColor.prototype.toHsvString = function () { + var hsv = rgbToHsv(this.r, this.g, this.b); + var h = Math.round(hsv.h * 360); + var s = Math.round(hsv.s * 100); + var v = Math.round(hsv.v * 100); + return this.a === 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this.roundA + ")"; + }; + TinyColor.prototype.toHsl = function () { + var hsl = rgbToHsl(this.r, this.g, this.b); + return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a }; + }; + TinyColor.prototype.toHslString = function () { + var hsl = rgbToHsl(this.r, this.g, this.b); + var h = Math.round(hsl.h * 360); + var s = Math.round(hsl.s * 100); + var l = Math.round(hsl.l * 100); + return this.a === 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this.roundA + ")"; + }; + TinyColor.prototype.toHex = function (allow3Char) { + if (allow3Char === void 0) { allow3Char = false; } + return rgbToHex(this.r, this.g, this.b, allow3Char); + }; + TinyColor.prototype.toHexString = function (allow3Char) { + if (allow3Char === void 0) { allow3Char = false; } + return '#' + this.toHex(allow3Char); + }; + TinyColor.prototype.toHex8 = function (allow4Char) { + if (allow4Char === void 0) { allow4Char = false; } + return rgbaToHex(this.r, this.g, this.b, this.a, allow4Char); + }; + TinyColor.prototype.toHex8String = function (allow4Char) { + if (allow4Char === void 0) { allow4Char = false; } + return '#' + this.toHex8(allow4Char); + }; + TinyColor.prototype.toRgb = function () { + return { + r: Math.round(this.r), + g: Math.round(this.g), + b: Math.round(this.b), + a: this.a, + }; + }; + TinyColor.prototype.toRgbString = function () { + var r = Math.round(this.r); + var g = Math.round(this.g); + var b = Math.round(this.b); + return this.a === 1 ? "rgb(" + r + ", " + g + ", " + b + ")" : "rgba(" + r + ", " + g + ", " + b + ", " + this.roundA + ")"; + }; + TinyColor.prototype.toPercentageRgb = function () { + var fmt = function (x) { return Math.round(bound01(x, 255) * 100) + "%"; }; + return { + r: fmt(this.r), + g: fmt(this.g), + b: fmt(this.b), + a: this.a, + }; + }; + TinyColor.prototype.toPercentageRgbString = function () { + var rnd = function (x) { return Math.round(bound01(x, 255) * 100); }; + return this.a === 1 ? + "rgb(" + rnd(this.r) + "%, " + rnd(this.g) + "%, " + rnd(this.b) + "%)" : + "rgba(" + rnd(this.r) + "%, " + rnd(this.g) + "%, " + rnd(this.b) + "%, " + this.roundA + ")"; + }; + TinyColor.prototype.toName = function () { + if (this.a === 0) { + return 'transparent'; + } + if (this.a < 1) { + return false; + } + var hex = '#' + rgbToHex(this.r, this.g, this.b, false); + for (var _i = 0, _a = Object.keys(names); _i < _a.length; _i++) { + var key = _a[_i]; + if (names[key] === hex) { + return key; + } + } + return false; + }; + TinyColor.prototype.toString = function (format) { + var formatSet = Boolean(format); + format = (format !== null && format !== void 0 ? format : this.format); + var formattedString = false; + var hasAlpha = this.a < 1 && this.a >= 0; + var needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); + if (needsAlphaFormat) { + if (format === 'name' && this.a === 0) { + return this.toName(); + } + return this.toRgbString(); + } + if (format === 'rgb') { + formattedString = this.toRgbString(); + } + if (format === 'prgb') { + formattedString = this.toPercentageRgbString(); + } + if (format === 'hex' || format === 'hex6') { + formattedString = this.toHexString(); + } + if (format === 'hex3') { + formattedString = this.toHexString(true); + } + if (format === 'hex4') { + formattedString = this.toHex8String(true); + } + if (format === 'hex8') { + formattedString = this.toHex8String(); + } + if (format === 'name') { + formattedString = this.toName(); + } + if (format === 'hsl') { + formattedString = this.toHslString(); + } + if (format === 'hsv') { + formattedString = this.toHsvString(); + } + return formattedString || this.toHexString(); + }; + TinyColor.prototype.clone = function () { + return new TinyColor(this.toString()); + }; + TinyColor.prototype.lighten = function (amount) { + if (amount === void 0) { amount = 10; } + var hsl = this.toHsl(); + hsl.l += amount / 100; + hsl.l = clamp01(hsl.l); + return new TinyColor(hsl); + }; + TinyColor.prototype.brighten = function (amount) { + if (amount === void 0) { amount = 10; } + var rgb = this.toRgb(); + rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100)))); + rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100)))); + rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100)))); + return new TinyColor(rgb); + }; + TinyColor.prototype.darken = function (amount) { + if (amount === void 0) { amount = 10; } + var hsl = this.toHsl(); + hsl.l -= amount / 100; + hsl.l = clamp01(hsl.l); + return new TinyColor(hsl); + }; + TinyColor.prototype.tint = function (amount) { + if (amount === void 0) { amount = 10; } + return this.mix('white', amount); + }; + TinyColor.prototype.shade = function (amount) { + if (amount === void 0) { amount = 10; } + return this.mix('black', amount); + }; + TinyColor.prototype.desaturate = function (amount) { + if (amount === void 0) { amount = 10; } + var hsl = this.toHsl(); + hsl.s -= amount / 100; + hsl.s = clamp01(hsl.s); + return new TinyColor(hsl); + }; + TinyColor.prototype.saturate = function (amount) { + if (amount === void 0) { amount = 10; } + var hsl = this.toHsl(); + hsl.s += amount / 100; + hsl.s = clamp01(hsl.s); + return new TinyColor(hsl); + }; + TinyColor.prototype.greyscale = function () { + return this.desaturate(100); + }; + TinyColor.prototype.spin = function (amount) { + var hsl = this.toHsl(); + var hue = (hsl.h + amount) % 360; + hsl.h = hue < 0 ? 360 + hue : hue; + return new TinyColor(hsl); + }; + TinyColor.prototype.mix = function (color, amount) { + if (amount === void 0) { amount = 50; } + var rgb1 = this.toRgb(); + var rgb2 = new TinyColor(color).toRgb(); + var p = amount / 100; + var rgba = { + r: ((rgb2.r - rgb1.r) * p) + rgb1.r, + g: ((rgb2.g - rgb1.g) * p) + rgb1.g, + b: ((rgb2.b - rgb1.b) * p) + rgb1.b, + a: ((rgb2.a - rgb1.a) * p) + rgb1.a, + }; + return new TinyColor(rgba); + }; + TinyColor.prototype.analogous = function (results, slices) { + if (results === void 0) { results = 6; } + if (slices === void 0) { slices = 30; } + var hsl = this.toHsl(); + var part = 360 / slices; + var ret = [this]; + for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results;) { + hsl.h = (hsl.h + part) % 360; + ret.push(new TinyColor(hsl)); + } + return ret; + }; + TinyColor.prototype.complement = function () { + var hsl = this.toHsl(); + hsl.h = (hsl.h + 180) % 360; + return new TinyColor(hsl); + }; + TinyColor.prototype.monochromatic = function (results) { + if (results === void 0) { results = 6; } + var hsv = this.toHsv(); + var h = hsv.h; + var s = hsv.s; + var v = hsv.v; + var res = []; + var modification = 1 / results; + while (results--) { + res.push(new TinyColor({ h: h, s: s, v: v })); + v = (v + modification) % 1; + } + return res; + }; + TinyColor.prototype.splitcomplement = function () { + var hsl = this.toHsl(); + var h = hsl.h; + return [ + this, + new TinyColor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }), + new TinyColor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }), + ]; + }; + TinyColor.prototype.triad = function () { + return this.polyad(3); + }; + TinyColor.prototype.tetrad = function () { + return this.polyad(4); + }; + TinyColor.prototype.polyad = function (n) { + var hsl = this.toHsl(); + var h = hsl.h; + var result = [this]; + var increment = 360 / n; + for (var i = 1; i < n; i++) { + result.push(new TinyColor({ h: (h + (i * increment)) % 360, s: hsl.s, l: hsl.l })); + } + return result; + }; + TinyColor.prototype.equals = function (color) { + return this.toRgbString() === new TinyColor(color).toRgbString(); + }; + return TinyColor; +}()); +function tinycolor(color, opts) { + if (color === void 0) { color = ''; } + if (opts === void 0) { opts = {}; } + return new TinyColor(color, opts); +} + +const LitElement = customElements.get('home-assistant-main') + ? Object.getPrototypeOf(customElements.get('home-assistant-main')) + : Object.getPrototypeOf(customElements.get('hui-view')); + +const html = LitElement.prototype.html; + +const css = LitElement.prototype.css; + +function hass() { + if(document.querySelector('hc-main')) + return document.querySelector('hc-main').hass; + + if(document.querySelector('home-assistant')) + return document.querySelector('home-assistant').hass; + + return undefined; +} +function provideHass(element) { + if(document.querySelector('hc-main')) + return document.querySelector('hc-main').provideHass(element); + + if(document.querySelector('home-assistant')) + return document.querySelector("home-assistant").provideHass(element); + + return undefined; +} +function lovelace_view() { + var root = document.querySelector("hc-main"); + if(root) { + root = root && root.shadowRoot; + root = root && root.querySelector("hc-lovelace"); + root = root && root.shadowRoot; + root = root && root.querySelector("hui-view") || root.querySelector("hui-panel-view"); + return root; + } + + root = document.querySelector("home-assistant"); + root = root && root.shadowRoot; + root = root && root.querySelector("home-assistant-main"); + root = root && root.shadowRoot; + root = root && root.querySelector("app-drawer-layout partial-panel-resolver"); + root = root && root.shadowRoot || root; + root = root && root.querySelector("ha-panel-lovelace"); + root = root && root.shadowRoot; + root = root && root.querySelector("hui-root"); + root = root && root.shadowRoot; + root = root && root.querySelector("ha-app-layout"); + root = root && root.querySelector("#view"); + root = root && root.firstElementChild; + return root; +} + +async function load_lovelace() { + if(customElements.get("hui-view")) return true; + + await customElements.whenDefined("partial-panel-resolver"); + const ppr = document.createElement("partial-panel-resolver"); + ppr.hass = {panels: [{ + url_path: "tmp", + "component_name": "lovelace", + }]}; + ppr._updateRoutes(); + await ppr.routerOptions.routes.tmp.load(); + if(!customElements.get("ha-panel-lovelace")) return false; + const p = document.createElement("ha-panel-lovelace"); + p.hass = hass(); + if(p.hass === undefined) { + await new Promise(resolve => { + window.addEventListener('connection-status', (ev) => { + console.log(ev); + resolve(); + }, {once: true}); + }); + p.hass = hass(); + } + p.panel = {config: {mode: null}}; + p._fetchConfig(); + return true; +} + +function fireEvent(ev, detail, entity=null) { + ev = new Event(ev, { + bubbles: true, + cancelable: false, + composed: true, + }); + ev.detail = detail || {}; + if(entity) { + entity.dispatchEvent(ev); + } else { + var root = lovelace_view(); + if (root) root.dispatchEvent(ev); + } +} + +async function _selectTree(root, path, all=false) { + let el = root; + if(typeof(path) === "string") { + path = path.split(/(\$| )/); + } + if(path[path.length-1] === "") + path.pop(); + for(const [i, p] of path.entries()) { + if(!p.trim().length) continue; + if(!el) return null; + if(el.localName && el.localName.includes("-")) + await customElements.whenDefined(el.localName); + if(el.updateComplete) + await el.updateComplete; + if(p === "$") + if(all && i == path.length-1) + el = [el.shadowRoot]; + else + el = el.shadowRoot; + else + if(all && i == path.length-1) + el = el.querySelectorAll(p); + else + el = el.querySelector(p); + } + return el; +} + +async function selectTree(root, path, all=false, timeout=10000) { + return Promise.race([ + _selectTree(root, path, all), + new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)) + ]).catch((err) => { + if(!err.message || err.message !== "timeout") + throw(err); + return null; + }); +} + +async function moreInfo(entity, large=false) { + const root = document.querySelector("hc-main") || document.querySelector("home-assistant"); + fireEvent("hass-more-info", {entityId: entity}, root); + const el = await selectTree(root, "$ ha-more-info-dialog"); + if(el) + el.large = large; + return el; +} + +const ID_STORAGE_KEY = 'lovelace-player-device-id'; +function _deviceID() { + if(!localStorage[ID_STORAGE_KEY]) + { + const s4 = () => { + return Math.floor((1+Math.random())*100000).toString(16).substring(1); + }; + if(window['fully'] && typeof fully.getDeviceId === "function") + localStorage[ID_STORAGE_KEY] = fully.getDeviceId(); + else + localStorage[ID_STORAGE_KEY] = `${s4()}${s4()}-${s4()}${s4()}`; + } + return localStorage[ID_STORAGE_KEY]; +} +let deviceID = _deviceID(); + +const setDeviceID = (id) => { + if(id === null) return; + if(id === "clear") { + localStorage.removeItem(ID_STORAGE_KEY); + } else { + localStorage[ID_STORAGE_KEY] = id; + } + deviceID = _deviceID(); +}; + +const params = new URLSearchParams(window.location.search); +if(params.get('deviceID')) { + setDeviceID(params.get('deviceID')); +} + +async function parseTemplate(hass, str, specialData = {}) { + if (!hass) hass = hass(); + if (typeof(specialData === "string")) specialData = {}; + specialData = Object.assign({ + user: hass.user.name, + browser: deviceID, + hash: location.hash.substr(1) || ' ', + }, + specialData); + + for (var k in specialData) { + var re = new RegExp(`\\{${k}\\}`, "g"); + str = str.replace(re, specialData[k]); + } + + return hass.callApi("POST", "template", {template: str}); +} + +const CUSTOM_TYPE_PREFIX = "custom:"; + +let helpers = window.cardHelpers; +const helperPromise = new Promise(async (resolve, reject) => { + if(helpers) resolve(); + + const updateHelpers = async () => { + helpers = await window.loadCardHelpers(); + window.cardHelpers = helpers; + resolve(); + }; + + if(window.loadCardHelpers) { + updateHelpers(); + } else { + // If loadCardHelpers didn't exist, force load lovelace and try once more. + window.addEventListener("load", async () => { + load_lovelace(); + if(window.loadCardHelpers) { + updateHelpers(); + } + }); + } +}); + +function errorElement(error, origConfig) { + const cfg = { + type: "error", + error, + origConfig, + }; + const el = document.createElement("hui-error-card"); + customElements.whenDefined("hui-error-card").then(() => { + const newel = document.createElement("hui-error-card"); + newel.setConfig(cfg); + if(el.parentElement) + el.parentElement.replaceChild(newel, el); + }); + helperPromise.then(() => { + fireEvent("ll-rebuild", {}, el); + }); + return el; +} + +function _createElement(tag, config) { + let el = document.createElement(tag); + try { + el.setConfig(JSON.parse(JSON.stringify(config))); + } catch (err) { + el = errorElement(err, config); + } + helperPromise.then(() => { + fireEvent("ll-rebuild", {}, el); + }); + return el; +} + +function createLovelaceElement(thing, config) { + if(!config || typeof config !== "object" || !config.type) + return errorElement(`No ${thing} type configured`, config); + + let tag = config.type; + if(tag.startsWith(CUSTOM_TYPE_PREFIX)) + tag = tag.substr(CUSTOM_TYPE_PREFIX.length); + else + tag = `hui-${tag}-${thing}`; + + if(customElements.get(tag)) + return _createElement(tag, config); + + const el = errorElement(`Custom element doesn't exist: ${tag}.`, config); + el.style.display = "None"; + + const timer = setTimeout(() => { + el.style.display = ""; + }, 2000); + + customElements.whenDefined(tag).then(() => { + clearTimeout(timer); + fireEvent("ll-rebuild", {}, el); + }); + + return el; +} + +function createCard(config) { + if(helpers) return helpers.createCardElement(config); + return createLovelaceElement('card', config); +} + +var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function commonjsRequire () { + throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); +} + +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; +} + +var hammer = createCommonjsModule(function (module) { /*! Hammer.JS - v2.0.7 - 2016-04-22 * http://hammerjs.github.io/ * * Copyright (c) 2016 Jorik Tangelder; * Licensed under the MIT license */ -!function(e,i,n,o){var s,r=["","webkit","Moz","MS","ms","o"],a=i.createElement("div"),h=Math.round,l=Math.abs,c=Date.now;function u(t,e,i){return setTimeout(b(t,i),e)}function d(t,e,i){return!!Array.isArray(t)&&(p(t,i[e],i),!0)}function p(t,e,i){var n;if(t)if(t.forEach)t.forEach(e,i);else if(void 0!==t.length)for(n=0;n\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",s=e.console&&(e.console.warn||e.console.log);return s&&s.call(e.console,o,n),t.apply(this,arguments)}}s="function"!=typeof Object.assign?function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),i=1;i-1}function $(t){return t.trim().split(/\s+/g)}function k(t,e,i){if(t.indexOf&&!i)return t.indexOf(e);for(var n=0;ni[e]})):n.sort()),n}function C(t,e){for(var i,n,o=e[0].toUpperCase()+e.slice(1),s=0;s1&&!i.firstMultiple?i.firstMultiple=L(e):1===o&&(i.firstMultiple=!1);var s=i.firstInput,r=i.firstMultiple,a=r?r.center:s.center,h=e.center=F(n);e.timeStamp=c(),e.deltaTime=e.timeStamp-s.timeStamp,e.angle=B(a,h),e.distance=q(a,h),function(t,e){var i=e.center,n=t.offsetDelta||{},o=t.prevDelta||{},s=t.prevInput||{};1!==e.eventType&&4!==s.eventType||(o=t.prevDelta={x:s.deltaX||0,y:s.deltaY||0},n=t.offsetDelta={x:i.x,y:i.y});e.deltaX=o.x+(i.x-n.x),e.deltaY=o.y+(i.y-n.y)}(i,e),e.offsetDirection=Y(e.deltaX,e.deltaY);var u=W(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=u.x,e.overallVelocityY=u.y,e.overallVelocity=l(u.x)>l(u.y)?u.x:u.y,e.scale=r?(d=r.pointers,p=n,q(p[0],p[1],R)/q(d[0],d[1],R)):1,e.rotation=r?function(t,e){return B(e[1],e[0],R)+B(t[1],t[0],R)}(r.pointers,n):0,e.maxPointers=i.prevInput?e.pointers.length>i.prevInput.maxPointers?e.pointers.length:i.prevInput.maxPointers:e.pointers.length,function(t,e){var i,n,o,s,r=t.lastInterval||e,a=e.timeStamp-r.timeStamp;if(8!=e.eventType&&(a>25||void 0===r.velocity)){var h=e.deltaX-r.deltaX,c=e.deltaY-r.deltaY,u=W(a,h,c);n=u.x,o=u.y,i=l(u.x)>l(u.y)?u.x:u.y,s=Y(h,c),t.lastInterval=e}else i=r.velocity,n=r.velocityX,o=r.velocityY,s=r.direction;e.velocity=i,e.velocityX=n,e.velocityY=o,e.direction=s}(i,e);var d,p;var f=t.element;S(e.srcEvent.target,f)&&(f=e.srcEvent.target);e.target=f}(t,i),t.emit("hammer.input",i),t.recognize(i),t.session.prevInput=i}function L(t){for(var e=[],i=0;i=l(e)?t<0?2:4:e<0?8:16}function q(t,e,i){i||(i=D);var n=e[i[0]]-t[i[0]],o=e[i[1]]-t[i[1]];return Math.sqrt(n*n+o*o)}function B(t,e,i){i||(i=D);var n=e[i[0]]-t[i[0]],o=e[i[1]]-t[i[1]];return 180*Math.atan2(o,n)/Math.PI}H.prototype={handler:function(){},init:function(){this.evEl&&w(this.element,this.evEl,this.domHandler),this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(I(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&_(this.element,this.evEl,this.domHandler),this.evTarget&&_(this.target,this.evTarget,this.domHandler),this.evWin&&_(I(this.element),this.evWin,this.domHandler)}};var j={mousedown:1,mousemove:2,mouseup:4};function V(){this.evEl="mousedown",this.evWin="mousemove mouseup",this.pressed=!1,H.apply(this,arguments)}v(V,H,{handler:function(t){var e=j[t.type];1&e&&0===t.button&&(this.pressed=!0),2&e&&1!==t.which&&(e=4),this.pressed&&(4&e&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:"mouse",srcEvent:t}))}});var J={pointerdown:1,pointermove:2,pointerup:4,pointercancel:8,pointerout:8},U={2:"touch",3:"pen",4:"mouse",5:"kinect"},X="pointerdown",G="pointermove pointerup pointercancel";function Z(){this.evEl=X,this.evWin=G,H.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}e.MSPointerEvent&&!e.PointerEvent&&(X="MSPointerDown",G="MSPointerMove MSPointerUp MSPointerCancel"),v(Z,H,{handler:function(t){var e=this.store,i=!1,n=t.type.toLowerCase().replace("ms",""),o=J[n],s=U[t.pointerType]||t.pointerType,r="touch"==s,a=k(e,t.pointerId,"pointerId");1&o&&(0===t.button||r)?a<0&&(e.push(t),a=e.length-1):12&o&&(i=!0),a<0||(e[a]=t,this.callback(this.manager,o,{pointers:e,changedPointers:[t],pointerType:s,srcEvent:t}),i&&e.splice(a,1))}});var Q={touchstart:1,touchmove:2,touchend:4,touchcancel:8};function K(){this.evTarget="touchstart",this.evWin="touchstart touchmove touchend touchcancel",this.started=!1,H.apply(this,arguments)}function tt(t,e){var i=z(t.touches),n=z(t.changedTouches);return 12&e&&(i=E(i.concat(n),"identifier",!0)),[i,n]}v(K,H,{handler:function(t){var e=Q[t.type];if(1===e&&(this.started=!0),this.started){var i=tt.call(this,t,e);12&e&&i[0].length-i[1].length==0&&(this.started=!1),this.callback(this.manager,e,{pointers:i[0],changedPointers:i[1],pointerType:"touch",srcEvent:t})}}});var et={touchstart:1,touchmove:2,touchend:4,touchcancel:8};function it(){this.evTarget="touchstart touchmove touchend touchcancel",this.targetIds={},H.apply(this,arguments)}function nt(t,e){var i=z(t.touches),n=this.targetIds;if(3&e&&1===i.length)return n[i[0].identifier]=!0,[i,i];var o,s,r=z(t.changedTouches),a=[],h=this.target;if(s=i.filter((function(t){return S(t.target,h)})),1===e)for(o=0;o-1&&n.splice(t,1)}),2500)}}function at(t){for(var e=t.srcEvent.clientX,i=t.srcEvent.clientY,n=0;n-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){return!!this.simultaneous[t.id]},emit:function(t){var e=this,i=this.state;function n(i){e.manager.emit(i,t)}i<8&&n(e.options.event+pt(i)),n(e.options.event),t.additionalEvent&&n(t.additionalEvent),i>=8&&n(e.options.event+pt(i))},tryEmit:function(t){if(this.canEmit())return this.emit(t);this.state=32},canEmit:function(){for(var t=0;te.threshold&&o&e.direction},attrTest:function(t){return mt.prototype.attrTest.call(this,t)&&(2&this.state||!(2&this.state)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=ft(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),v(bt,mt,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return["none"]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||2&this.state)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),v(yt,dt,{defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return["auto"]},process:function(t){var e=this.options,i=t.pointers.length===e.pointers,n=t.distancee.time;if(this._input=t,!n||!i||12&t.eventType&&!o)this.reset();else if(1&t.eventType)this.reset(),this._timer=u((function(){this.state=8,this.tryEmit()}),e.time,this);else if(4&t.eventType)return 8;return 32},reset:function(){clearTimeout(this._timer)},emit:function(t){8===this.state&&(t&&4&t.eventType?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=c(),this.manager.emit(this.options.event,this._input)))}}),v(xt,mt,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return["none"]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||2&this.state)}}),v(wt,mt,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:30,pointers:1},getTouchAction:function(){return vt.prototype.getTouchAction.call(this)},attrTest:function(t){var e,i=this.options.direction;return 30&i?e=t.overallVelocity:6&i?e=t.overallVelocityX:24&i&&(e=t.overallVelocityY),this._super.attrTest.call(this,t)&&i&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&l(e)>this.options.velocity&&4&t.eventType},emit:function(t){var e=ft(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),v(_t,dt,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return["manipulation"]},process:function(t){var e=this.options,i=t.pointers.length===e.pointers,n=t.distance