angular-material
Version:
This repository publishes the AngularJS Material v1.x library and localized installs using `npm`. You can find the component source-code for this library in the [AngularJS Material repository](https://github.com/angular/material).
7 lines • 3.07 kB
JavaScript
/*!
* AngularJS Material Design
* https://github.com/angular/material
* @license MIT
* v1.2.0-master-93518bb
*/
goog.provide("ngmaterial.components.colors"),goog.require("ngmaterial.core"),function(){"use strict";r.$inject=["$mdColors","$mdUtil","$log","$parse"],e.$inject=["$mdTheming","$mdUtil","$log"];var l=/^{((\s|,)*?["'a-zA-Z-]+?\s*?:\s*?(['"])[a-zA-Z0-9-.]*(['"]))+\s*}$/,i=null;function e(a,l,o){return i=i||Object.keys(a.PALETTES),{applyThemeColors:function(e,r){try{r&&e.css(function(e){var t={},a=e.hasOwnProperty("color");return angular.forEach(e,function(e,r){var o=u(e),n=-1<r.indexOf("background");t[r]=s(o),n&&!a&&(t.color=s(o,!0))}),t}(r))}catch(e){o.error(e.message)}},getThemeColor:function(e){return s(u(e))},hasTheme:function(e){return angular.isDefined(a.THEMES[e.split("-")[0]])}};function s(e,r){r=r||!1;var o=a.PALETTES[e.palette][e.hue];return o=r?o.contrast:o.value,l.supplant("rgba({0}, {1}, {2}, {3})",[o[0],o[1],o[2],o[3]||e.opacity])}function u(e){var r=e.split("-"),o=angular.isDefined(a.THEMES[r[0]])?r.splice(0,1)[0]:a.defaultTheme();return{theme:o,palette:function(e,r){var o=1<e.length&&-1!==i.indexOf(e[1]),n=e[0].replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();o&&(n=e[0]+"-"+e.splice(1,1));if(-1===i.indexOf(n)){var t=a.THEMES[r].colors[n];if(!t)throw new Error(l.supplant("mdColors: couldn't find '{palette}' in the palettes.",{palette:n}));n=t.name}return n}(r,o),hue:function(e,r){var o=a.THEMES[r].colors;if("hue"!==e[1])return e[1]||o[e[0]in o?e[0]:"primary"].hues.default;var n=parseInt(e.splice(2,1)[0],10);if(n<1||3<n)throw new Error(l.supplant("mdColors: 'hue-{hueNumber}' is not a valid hue, can be only 'hue-1', 'hue-2' and 'hue-3'",{hueNumber:n}));if(e[1]="hue-"+n,e[0]in o)return o[e[0]].hues[e[1]];throw new Error(l.supplant("mdColors: 'hue-x' can only be used with [{availableThemes}], but was used with '{usedTheme}'",{availableThemes:Object.keys(o).join(", "),usedTheme:e[0]}))}(r,o),opacity:r[2]||1}}}function r(c,a,m,h){return{restrict:"A",require:["^?mdTheme"],compile:function(e,t){var i=function(){var e=t.mdColors,r=-1<e.indexOf("::"),o=r||l.test(t.mdColors);t.mdColors=e.replace("::","");var n=angular.isDefined(t.mdColorsWatch);return!r&&!o&&(!n||a.parseAttributeBoolean(t.mdColorsWatch))}();return function(e,o,r,n){function t(o){"string"!=typeof o&&(o=""),r.mdColors||(r.mdColors="{}");var n=h(r.mdColors)(e);return a&&Object.keys(n).forEach(function(e){var r=n[e];c.hasTheme(r)||(n[e]=(o||a.$mdTheme)+"-"+r)}),s(n),n}var a=n[0],l={},s=function(e){if(!angular.equals(e,l)){var r=Object.keys(l);l.background&&!r.color&&r.push("color"),r.forEach(function(e){o.css(e,"")})}l=e},u=angular.noop;a&&(u=a.registerChanges(function(e){c.applyThemeColors(o,t(e))})),e.$on("$destroy",function(){u()});try{i?e.$watch(t,angular.bind(this,c.applyThemeColors,o),!0):c.applyThemeColors(o,t())}catch(e){m.error(e.message)}}}}}angular.module("material.components.colors",["material.core"]).directive("mdColors",r).service("$mdColors",e)}(),ngmaterial.components.colors=angular.module("material.components.colors");