@daybrush/utils
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -29,1 +29,2 @@ import { IArrayFormat, IObject } from "./types"; | ||
export declare const requestAnimationFrame: (callback: FrameRequestCallback) => number; | ||
export declare const cancelAnimationFrame: (handle: number) => void; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/daybrush/utils | ||
@version 0.8.0 | ||
@version 0.9.0 | ||
*/ | ||
@@ -547,3 +547,3 @@ /** | ||
var firstTime = now(); | ||
var raf = IS_WINDOW && (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame); | ||
var raf = IS_WINDOW && (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame); | ||
return raf ? raf.bind(window) : function (callback) { | ||
@@ -557,3 +557,27 @@ var currTime = now(); | ||
}(); | ||
/** | ||
* window.cancelAnimationFrame() method with cross browser. | ||
* @function | ||
* @memberof CrossBrowser | ||
* @param {number} handle - the id obtained through requestAnimationFrame method | ||
* @return {void} | ||
* @example | ||
import { requestAnimationFrame, cancelAnimationFrame } from "@daybrush/utils"; | ||
const id = requestAnimationFrame((timestamp) => { | ||
console.log(timestamp); | ||
}); | ||
cancelAnimationFrame(id); | ||
*/ | ||
var cancelAnimationFrame = | ||
/*#__PURE__*/ | ||
function () { | ||
var caf = IS_WINDOW && (window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.msCancelAnimationFrame); | ||
return caf ? caf.bind(window) : function (handle) { | ||
clearTimeout(handle); | ||
}; | ||
}(); | ||
/** | ||
@@ -880,3 +904,3 @@ * @namespace | ||
export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, doc as document, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isFunction, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, requestAnimationFrame, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent }; | ||
export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, doc as document, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isFunction, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, requestAnimationFrame, cancelAnimationFrame, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent }; | ||
//# sourceMappingURL=utils.esm.js.map |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/daybrush/utils | ||
@version 0.8.0 | ||
@version 0.9.0 | ||
*/ | ||
@@ -553,3 +553,3 @@ (function (global, factory) { | ||
var firstTime = now(); | ||
var raf = IS_WINDOW && (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame); | ||
var raf = IS_WINDOW && (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame); | ||
return raf ? raf.bind(window) : function (callback) { | ||
@@ -563,3 +563,27 @@ var currTime = now(); | ||
}(); | ||
/** | ||
* window.cancelAnimationFrame() method with cross browser. | ||
* @function | ||
* @memberof CrossBrowser | ||
* @param {number} handle - the id obtained through requestAnimationFrame method | ||
* @return {void} | ||
* @example | ||
import { requestAnimationFrame, cancelAnimationFrame } from "@daybrush/utils"; | ||
const id = requestAnimationFrame((timestamp) => { | ||
console.log(timestamp); | ||
}); | ||
cancelAnimationFrame(id); | ||
*/ | ||
var cancelAnimationFrame = | ||
/*#__PURE__*/ | ||
function () { | ||
var caf = IS_WINDOW && (window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.msCancelAnimationFrame); | ||
return caf ? caf.bind(window) : function (handle) { | ||
clearTimeout(handle); | ||
}; | ||
}(); | ||
/** | ||
@@ -928,2 +952,3 @@ * @namespace | ||
requestAnimationFrame: requestAnimationFrame, | ||
cancelAnimationFrame: cancelAnimationFrame, | ||
$: $, | ||
@@ -930,0 +955,0 @@ hasClass: hasClass, |
@@ -7,5 +7,5 @@ /* | ||
repository: https://github.com/daybrush/utils | ||
@version 0.8.0 | ||
@version 0.9.0 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.utils=t()}(this,function(){"use strict";var u="rgb",c="rgba",f="hsl",l="hsla",e=[u,c,f,l],t="function",n="object",r="string",a="undefined",i=typeof window!==a,o=typeof document!==a&&document,s=["webkit","ms","moz","o"],m=function(e){if(!o)return"";var t=(o.body||o.documentElement).style,n=s.length;if(typeof t[e]!==a)return e;for(var r=0;r<n;++r){var i="-"+s[r]+"-"+e;if(typeof t[i]!==a)return i}return""},d=m("transform"),p=m("filter"),v=m("animation"),h=v.replace("animation","keyframes");function g(e){var t=e.match(/("[^"]*"|'[^']*'|[^,\s()]*\((?:[^()]*|\([^()]*\))*\)[^,\s()]*|[^,])+/g);return t?t.map(function(e){return e.trim()}):[]}function A(e){var t=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(e);return!t||t.length<4?{}:{prefix:t[1],value:t[2],suffix:t[3]}}function w(){return Date.now?Date.now():(new Date).getTime()}var y=function(){var n=w(),e=i&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame);return e?e.bind(window):function(e){var t=w();return window.setTimeout(function(){e(t-n)},1e3/60)}}();function R(e){return e.replace("#","")}function N(e){var t=R(e),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16),a=parseInt(t.substring(6,8),16)/255;return isNaN(a)&&(a=1),[n,r,i,a]}function S(e){var t=e.charAt(1),n=e.charAt(2),r=e.charAt(3),i=e.charAt(4);return["#",t,t,n,n,r,r,i,i].join("")}function b(e){var t=e[0],n=e[1],r=e[2];t<0&&(t+=360*Math.floor((Math.abs(t)+360)/360)),t%=360;var i,a=(1-Math.abs(2*r-1))*n,o=a*(1-Math.abs(t/60%2-1)),s=r-a/2;return t<60?i=[a,o,0]:t<120?i=[o,a,0]:t<180?i=[0,a,o]:t<240?i=[0,o,a]:t<300?i=[o,0,a]:t<360&&(i=[a,0,o]),[Math.round(255*(i[0]+s)),Math.round(255*(i[1]+s)),Math.round(255*(i[2]+s)),3<e.length?e[3]:1]}return{RGB:u,RGBA:c,HSL:f,HSLA:l,COLOR_MODELS:e,FUNCTION:t,PROPERTY:"property",ARRAY:"array",OBJECT:n,STRING:r,NUMBER:"number",UNDEFINED:a,IS_WINDOW:i,document:o,getCrossBrowserProperty:m,TRANSFORM:d,FILTER:p,ANIMATION:v,KEYFRAMES:h,cutHex:R,hexToRGBA:N,toFullHex:S,hslToRGBA:b,stringToRGBA:function(e){if("#"===e.charAt(0))return 4===e.length||5===e.length?N(S(e)):N(e);if(-1!==e.indexOf("(")){var t=A(e),n=t.prefix,r=t.value;if(!n||!r)return;var i=g(r),a=[],o=i.length;switch(n){case u:case c:for(var s=0;s<o;++s)a[s]=parseFloat(i[s]);return a;case f:case l:for(s=0;s<o;++s)-1!==i[s].indexOf("%")?a[s]=parseFloat(i[s])/100:a[s]=parseFloat(i[s]);return b(a)}}},dot:function(e,t,n,r){return(e*r+t*n)/(n+r)},isUndefined:function(e){return typeof e===a},isObject:function(e){return e&&typeof e===n},isArray:function(e){return Array.isArray(e)},isString:function(e){return typeof e===r},isFunction:function(e){return typeof e===t},splitSpace:function(e){return e.match(/("[^"]*")|('[^']*')|([^\s()]*(?:\((?:[^()]*|\([^()]*\))*\))[^\s()]*)|\S+/g)||[]},splitComma:g,splitBracket:A,splitUnit:function(e){var t=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(e);if(!t)return{prefix:"",unit:"",value:NaN};var n=t[1],r=t[2];return{prefix:n,unit:t[3],value:parseFloat(r)}},camelize:function(e){return e.replace(/[\s-_]([a-z])/g,function(e,t){return t.toUpperCase()})},decamelize:function(e,r){return void 0===r&&(r="-"),e.replace(/([a-z])([A-Z])/g,function(e,t,n){return""+t+r+n.toLowerCase()})},toArray:function(e){return[].slice.call(e)},now:w,requestAnimationFrame:y,$:function(e,t){return t?o.querySelectorAll(e):o.querySelector(e)},hasClass:function(e,t){return e.classList?e.classList.contains(t):!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){e.classList?e.classList.add(t):e.className+=" "+t},removeClass:function(e,t){if(e.classList)e.classList.remove(t);else{var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}},fromCSS:function(e,t){if(!e||!t||!t.length)return{};var n;if(e instanceof Element)n=e;else{if(!e.length)return{};n=e[0]}for(var r={},i=window.getComputedStyle(n),a=t.length,o=0;o<a;++o)r[t[o]]=i[t[o]];return r},addEvent:function(e,t,n,r){e.addEventListener(t,n,r)},removeEvent:function(e,t,n){e.removeEventListener(t,n)}}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.utils=n()}(this,function(){"use strict";var s="rgb",c="rgba",f="hsl",l="hsla",e=[s,c,f,l],n="function",t="object",r="string",a="undefined",i=typeof window!==a,o=typeof document!==a&&document,u=["webkit","ms","moz","o"],m=function(e){if(!o)return"";var n=(o.body||o.documentElement).style,t=u.length;if(typeof n[e]!==a)return e;for(var r=0;r<t;++r){var i="-"+u[r]+"-"+e;if(typeof n[i]!==a)return i}return""},d=m("transform"),p=m("filter"),w=m("animation"),v=w.replace("animation","keyframes");function A(e){var n=e.match(/("[^"]*"|'[^']*'|[^,\s()]*\((?:[^()]*|\([^()]*\))*\)[^,\s()]*|[^,])+/g);return n?n.map(function(e){return e.trim()}):[]}function h(e){var n=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(e);return!n||n.length<4?{}:{prefix:n[1],value:n[2],suffix:n[3]}}function g(){return Date.now?Date.now():(new Date).getTime()}var y=function(){var t=g(),e=i&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return e?e.bind(window):function(e){var n=g();return window.setTimeout(function(){e(n-t)},1e3/60)}}();function F(e){return e.replace("#","")}function R(e){var n=F(e),t=parseInt(n.substring(0,2),16),r=parseInt(n.substring(2,4),16),i=parseInt(n.substring(4,6),16),a=parseInt(n.substring(6,8),16)/255;return isNaN(a)&&(a=1),[t,r,i,a]}function b(e){var n=e.charAt(1),t=e.charAt(2),r=e.charAt(3),i=e.charAt(4);return["#",n,n,t,t,r,r,i,i].join("")}function N(e){var n=e[0],t=e[1],r=e[2];n<0&&(n+=360*Math.floor((Math.abs(n)+360)/360)),n%=360;var i,a=(1-Math.abs(2*r-1))*t,o=a*(1-Math.abs(n/60%2-1)),u=r-a/2;return n<60?i=[a,o,0]:n<120?i=[o,a,0]:n<180?i=[0,a,o]:n<240?i=[0,o,a]:n<300?i=[o,0,a]:n<360&&(i=[a,0,o]),[Math.round(255*(i[0]+u)),Math.round(255*(i[1]+u)),Math.round(255*(i[2]+u)),3<e.length?e[3]:1]}return{RGB:s,RGBA:c,HSL:f,HSLA:l,COLOR_MODELS:e,FUNCTION:n,PROPERTY:"property",ARRAY:"array",OBJECT:t,STRING:r,NUMBER:"number",UNDEFINED:a,IS_WINDOW:i,document:o,getCrossBrowserProperty:m,TRANSFORM:d,FILTER:p,ANIMATION:w,KEYFRAMES:v,cutHex:F,hexToRGBA:R,toFullHex:b,hslToRGBA:N,stringToRGBA:function(e){if("#"===e.charAt(0))return 4===e.length||5===e.length?R(b(e)):R(e);if(-1!==e.indexOf("(")){var n=h(e),t=n.prefix,r=n.value;if(!t||!r)return;var i=A(r),a=[],o=i.length;switch(t){case s:case c:for(var u=0;u<o;++u)a[u]=parseFloat(i[u]);return a;case f:case l:for(u=0;u<o;++u)-1!==i[u].indexOf("%")?a[u]=parseFloat(i[u])/100:a[u]=parseFloat(i[u]);return N(a)}}},dot:function(e,n,t,r){return(e*r+n*t)/(t+r)},isUndefined:function(e){return typeof e===a},isObject:function(e){return e&&typeof e===t},isArray:function(e){return Array.isArray(e)},isString:function(e){return typeof e===r},isFunction:function(e){return typeof e===n},splitSpace:function(e){return e.match(/("[^"]*")|('[^']*')|([^\s()]*(?:\((?:[^()]*|\([^()]*\))*\))[^\s()]*)|\S+/g)||[]},splitComma:A,splitBracket:h,splitUnit:function(e){var n=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(e);if(!n)return{prefix:"",unit:"",value:NaN};var t=n[1],r=n[2];return{prefix:t,unit:n[3],value:parseFloat(r)}},camelize:function(e){return e.replace(/[\s-_]([a-z])/g,function(e,n){return n.toUpperCase()})},decamelize:function(e,r){return void 0===r&&(r="-"),e.replace(/([a-z])([A-Z])/g,function(e,n,t){return""+n+r+t.toLowerCase()})},toArray:function(e){return[].slice.call(e)},now:g,requestAnimationFrame:y,cancelAnimationFrame:function(){var e=i&&(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame);return e?e.bind(window):function(e){clearTimeout(e)}}(),$:function(e,n){return n?o.querySelectorAll(e):o.querySelector(e)},hasClass:function(e,n){return e.classList?e.classList.contains(n):!!e.className.match(new RegExp("(\\s|^)"+n+"(\\s|$)"))},addClass:function(e,n){e.classList?e.classList.add(n):e.className+=" "+n},removeClass:function(e,n){if(e.classList)e.classList.remove(n);else{var t=new RegExp("(\\s|^)"+n+"(\\s|$)");e.className=e.className.replace(t," ")}},fromCSS:function(e,n){if(!e||!n||!n.length)return{};var t;if(e instanceof Element)t=e;else{if(!e.length)return{};t=e[0]}for(var r={},i=window.getComputedStyle(t),a=n.length,o=0;o<a;++o)r[n[o]]=i[n[o]];return r},addEvent:function(e,n,t,r){e.addEventListener(n,t,r)},removeEvent:function(e,n,t){e.removeEventListener(n,t)}}}); | ||
//# sourceMappingURL=utils.min.js.map |
{ | ||
"name": "@daybrush/utils", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "utils for daybrush", | ||
@@ -25,2 +25,3 @@ "main": "dist/utils.js", | ||
"requestAnimationFrame", | ||
"cancelAnimationFrame", | ||
"transform", | ||
@@ -27,0 +28,0 @@ "filter", |
@@ -268,5 +268,5 @@ import { UNDEFINED, STRING, OBJECT, FUNCTION, IS_WINDOW } from "./consts"; | ||
const firstTime = now(); | ||
const raf = IS_WINDOW && | ||
(window.requestAnimationFrame || window.webkitRequestAnimationFrame || | ||
(window as any).mozRequestAnimationFrame); | ||
const raf = IS_WINDOW | ||
&& (window.requestAnimationFrame || window.webkitRequestAnimationFrame | ||
|| (window as any).mozRequestAnimationFrame || (window as any).msRequestAnimationFrame); | ||
@@ -281,1 +281,26 @@ return raf ? (raf.bind(window) as (callback: FrameRequestCallback) => number) : ((callback: FrameRequestCallback) => { | ||
})(); | ||
/** | ||
* window.cancelAnimationFrame() method with cross browser. | ||
* @function | ||
* @memberof CrossBrowser | ||
* @param {number} handle - the id obtained through requestAnimationFrame method | ||
* @return {void} | ||
* @example | ||
import { requestAnimationFrame, cancelAnimationFrame } from "@daybrush/utils"; | ||
const id = requestAnimationFrame((timestamp) => { | ||
console.log(timestamp); | ||
}); | ||
cancelAnimationFrame(id); | ||
*/ | ||
export const cancelAnimationFrame = /*#__PURE__*/(() => { | ||
const caf = IS_WINDOW | ||
&& (window.cancelAnimationFrame || window.webkitCancelAnimationFrame | ||
|| (window as any).mozCancelAnimationFrame || (window as any).msCancelAnimationFrame); | ||
return caf | ||
? caf.bind(window) as (handle: number) => void | ||
: ((handle: number) => { clearTimeout(handle); }); | ||
})(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191587
2683