MCPcopy
hub / github.com/GrapesJS/grapesjs / set

Function set

packages/core/src/utils/ColorPicker.ts:735–762  ·  view source on GitHub ↗
(color, ignoreFormatChange)

Source from the content-addressed store, hash-verified

733 }
734
735 function set(color, ignoreFormatChange) {
736 if (tinycolor.equals(color, get())) {
737 // Update UI just in case a validation error needs
738 // to be cleared.
739 updateUI();
740 return;
741 }
742
743 var newColor, newHsv;
744 if (!color && allowEmpty) {
745 isEmpty = true;
746 } else {
747 isEmpty = false;
748 isDefault = !color; // if no color is available an empty string will be passed. tinycolor will then set it to #000
749 newColor = tinycolor(color);
750 newHsv = newColor.toHsv();
751
752 currentHue = (newHsv.h % 360) / 360;
753 currentSaturation = newHsv.s;
754 currentValue = newHsv.v;
755 currentAlpha = newHsv.a;
756 }
757 updateUI();
758
759 if (newColor && newColor.isValid() && !ignoreFormatChange) {
760 currentPreferredFormat = opts.preferredFormat || newColor.getFormat();
761 }
762 }
763
764 function get(opts) {
765 opts = opts || {};

Callers 5

initializeFunction · 0.70
paletteElementClickFunction · 0.70
setFromTextInputFunction · 0.70
revertFunction · 0.70
spectrumFunction · 0.70

Calls 4

updateUIFunction · 0.85
tinycolorFunction · 0.85
equalsMethod · 0.80
getFunction · 0.70

Tested by

no test coverage detected