mirror of
https://github.com/geode-sdk/geode.git
synced 2024-12-02 12:17:10 -05:00
6 lines
14 KiB
JavaScript
6 lines
14 KiB
JavaScript
|
/*!
|
||
|
* palettify v1.0.3
|
||
|
* (c) 2018 Dobromir Hristov
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.palettify=e()}(this,function(){"use strict";function t(t){switch(typeof t){case"string":case"number":case"boolean":return t;case"object":try{return null===t?"":JSON.stringify(t)}catch(t){return"{...}"}default:return""}}function e(t,n,r){if(void 0===r&&(r=0),"object"!=typeof t||null===t||void 0===t)return"";var o=n[r],a=t[o];return r===n.length-1?a:e(a,n,++r)}function n(t,n){return e(n,t.split("."))}function r(e,r,o){return void 0===r&&(r={}),void 0===o&&(o=n),"string"!=typeof e?e:e.replace(g,function(e,a){try{return t(o(a,r))}catch(e){return t(n(a,r))}})}function o(t){return!!t&&"object"==typeof t}function a(t){var e=Object.prototype.toString.call(t);return"[object RegExp]"===e||"[object Date]"===e||i(t)}function i(t){return t.$$typeof===m}function s(t){return Array.isArray(t)?[]:{}}function c(t,e){return e&&!0===e.clone&&d(t)?f(s(t),t,e):t}function u(t,e,n){var r=t.slice();return e.forEach(function(e,o){void 0===r[o]?r[o]=c(e,n):d(e)?r[o]=f(t[o],e,n):-1===t.indexOf(e)&&r.push(c(e,n))}),r}function l(t,e,n){var r={};return d(t)&&Object.keys(t).forEach(function(e){r[e]=c(t[e],n)}),Object.keys(e).forEach(function(o){d(e[o])&&t[o]?r[o]=f(t[o],e[o],n):r[o]=c(e[o],n)}),r}function f(t,e,n){var r=Array.isArray(e),o=Array.isArray(t),a=n||{arrayMerge:u};if(r===o)return r?(a.arrayMerge||u)(t,e,n):l(t,e,n);return c(e,n)}function p(){function t(t,e){var n=p(t);return new Promise(function(t){f(n)?t((new v).getPalette(n,e)):n.onload=function(){t((new v).getPalette(n,e))}})}function e(t,e){return t.map(function(t,r){var o=1;return Array.isArray(e)&&e[r]&&(o=e[r]),n(t,o)})}function n(t,e){return"rgba("+t[0]+", "+t[1]+", "+t[2]+", "+e+")"}function r(t){var e=t.target,n=t.styles,r=t.palette,o=t.staticCallback;void 0===o&&(o=null);var a=t.obj;for(var i in n)n.hasOwnProperty(i)&&(e.style[i]=y(n[i],r));o&&o.call(e,a,m.options)}function o(t,e,n,r){for(var o in e)e.hasOwnProperty(o)&&!n.hasOwnProperty(o)?t.style[o]="":n.hasOwnProperty(o)&&(t.style[o]=y(n[o],r))}function a(t){m.options=E(b,t,{clone:!0,arrayMerge:g}),Object.keys(m.options).forEach(function(t){if(m.options[t]instanceof Error)throw m.options[t]})}function i(t){return(299*t[0]+587*t[1]+114*t[2])/1e3}function s(t){return i(t)<170}function c(t,e){return t.map(function(t){return s(t)?e.light:e.dark})}function u(t){var e=document.createElement("a");return e.href=t,e}function l(t){return document.location.host!==u(t).host}function f(t){return!!t.complete&&(void 0===t.naturalWidth||0!==t.naturalWidth)}function p(t){var e=t,n="IMG"!==e.tagName,r=n?t.style.backgroundImage.replace("url(","").replace(")","").replace(/"/gi,""):t.src,o=l(r);if(!e)throw Error("Target is not an element",e);if(n||o&&!e.crossOrigin){if(n&&!e.style.backgroundImage)throw Error("Tag provided is not an image and does not have a background-image style attached to it.");e=new Image(t.naturalWidth,t.naturalHeight),o&&(e.crossOrigin="anonymous"),e.src=r}return e}function g(t,e,n){return e}var h=!1,d=null,b={selector:Error("Please provide \u0430 selector in your options."),eventTarget:Error("Please provide an eventTarget as a parent for your image in the options."),image:Error("Please provide an image to sample."),styleTarget:null,contrastColors:{light:"#fff",dark:"#000"},activeClass:"palettify--active",readyClass:"palettify--ready",colorsToExtract:3,enterEvent:"mouseenter",leaveEvent:"mouseleave",styles:{opacities:[.5,.5,.5],static:{},dynamic:{}},staticCallback:null,beforeEnterCallback:null,afterEnterCallback:null,beforeLeaveCallback:null,afterLeaveCallback:null,onReadyCallback:null},m={options:{},data:[],collectElements:function(){var t="";if(!(d="string"==typeof m.options.selector?document.querySelector(m.options.selector):m.options.selector))throw new Error("Selector "+m.options.selector+" does not exist");t=d.querySelectorAll(m.options.eventTarget),[].slice.call(t,0).forEach(function(t){var e=t.querySelector(m.options.image),n=!0===m.options.styleTarget?t:t.querySelector(m.options.st
|