@urso/core 0.7.31 → 0.7.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/lib/helper.js +61 -0
package/package.json
CHANGED
package/src/js/lib/helper.js
CHANGED
|
@@ -599,6 +599,67 @@ class LibHelper {
|
|
|
599
599
|
|
|
600
600
|
return string
|
|
601
601
|
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Converts color number to object that contents RGB values
|
|
605
|
+
* @param { Number } color - color number
|
|
606
|
+
* @returns { Object }
|
|
607
|
+
*/
|
|
608
|
+
getRGB(color) {
|
|
609
|
+
return {
|
|
610
|
+
alpha: 16777215 < color ? color >>> 24 : 255,
|
|
611
|
+
red: color >> 16 & 255,
|
|
612
|
+
green: color >> 8 & 255,
|
|
613
|
+
blue: 255 & color
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Converts RGB values to 32 bit
|
|
619
|
+
* @param { Number } alpha
|
|
620
|
+
* @param { Number } red
|
|
621
|
+
* @param { Number } green
|
|
622
|
+
* @param { Number } blue
|
|
623
|
+
* @returns { Number }
|
|
624
|
+
*/
|
|
625
|
+
getColor32(alpha, red, green, blue) {
|
|
626
|
+
return alpha << 24 | red << 16 | green << 8 | blue;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Returns color interpolation depends on step value
|
|
631
|
+
* @param { Number } startColor
|
|
632
|
+
* @param { Number } targetColor
|
|
633
|
+
* @param { Number } step - intermediate value from 0 to 1
|
|
634
|
+
* @returns { Number }
|
|
635
|
+
*/
|
|
636
|
+
interpolateColor32(startColor, targetColor, step) {
|
|
637
|
+
if(startColor === targetColor)
|
|
638
|
+
return startColor;
|
|
639
|
+
|
|
640
|
+
const startColorRGB = this.getRGB(startColor);
|
|
641
|
+
const targetColorRGB = this.getRGB(targetColor);
|
|
642
|
+
const nextColorRGB = this.interpolateColorRGB(startColorRGB, targetColorRGB, step);
|
|
643
|
+
const color32 = this.getColor32(255, nextColorRGB.red, nextColorRGB.green, nextColorRGB.blue);
|
|
644
|
+
return 16777215 + color32;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Returns color interpolation as RGB object depends on step value
|
|
649
|
+
* @param { Object } startColorRGB - object that contents start values for red, green and blue
|
|
650
|
+
* @param { Object } targetColorRGB - object that contents target values for red, green and blue
|
|
651
|
+
* @param { Number } step - intermediate value from 0 to 1
|
|
652
|
+
* @returns { Object }
|
|
653
|
+
*/
|
|
654
|
+
interpolateColorRGB(startColorRGB, targetColorRGB, step) {
|
|
655
|
+
const nextRGB = {};
|
|
656
|
+
|
|
657
|
+
Object.keys(startColorRGB).forEach(color => {
|
|
658
|
+
nextRGB[color] = (targetColorRGB[color] - startColorRGB[color]) * step + startColorRGB[color];
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
return nextRGB;
|
|
662
|
+
}
|
|
602
663
|
}
|
|
603
664
|
|
|
604
665
|
module.exports = LibHelper;
|