Skip to content

Commit

Permalink
add vscode theme
Browse files Browse the repository at this point in the history
  • Loading branch information
easylogic committed Jan 20, 2020
1 parent 3870d4e commit 0cffa4d
Show file tree
Hide file tree
Showing 35 changed files with 3,377 additions and 1,736 deletions.
230 changes: 158 additions & 72 deletions addon/codemirror-colorpicker.css

Large diffs are not rendered by default.

1,694 changes: 955 additions & 739 deletions addon/codemirror-colorpicker.js

Large diffs are not rendered by default.

230 changes: 158 additions & 72 deletions dist/codemirror-colorpicker.css

Large diffs are not rendered by default.

1,771 changes: 994 additions & 777 deletions dist/codemirror-colorpicker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/codemirror-colorpicker.min.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@ <h3>Mini Style</h3>
<h3>Mini Vertical Style</h3>
<div class="colorpicker-style" data-type="mini-vertical"></div>
</div>

<div class="colorpicker-type">
<h3>VSCode Style</h3>
<div class="colorpicker-style" data-type="vscode"></div>
</div>


<!-- <div class="colorpicker-type">
Expand Down Expand Up @@ -1015,7 +1020,7 @@ <h1 class="title">Default Html Sample </h1>
colorpicker : {
mode : 'edit',
hideDelay: 0,
type: 'macos',
type: 'vscode',
onHide: function (color) {
console.log('hide', color)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codemirror-colorpicker",
"version": "1.9.53",
"version": "1.9.66",
"description": "simple colorpicker used anywhere",
"main": "./dist/codemirror-colorpicker.js",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/colorpicker/BaseBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class BaseBox extends UIElement {
this.refreshColorUI(e);
}

onDragMove (e) {
onDragMove (e) {
if (this.isDown) {
this.refreshColorUI(e);
}
Expand All @@ -80,7 +80,6 @@ export default class BaseBox extends UIElement {
this.$store.emit('lastUpdateColor');
this.isDown = false
}

}


Expand Down
4 changes: 4 additions & 0 deletions src/colorpicker/BaseColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ export default class BaseColorPicker extends UIElement {
}
}

'keyup.isAbsolute.escape $root' (e) {
this.hide();
}

'mouseover.isAbsolute $root' (e) {
clearTimeout(this.timerCloseColorPicker);
// this.__isMouseDown = true;
Expand Down
4 changes: 4 additions & 0 deletions src/colorpicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MiniColorPicker from './mini/index'
import MiniVerticalColorPicker from './mini-vertical/index'
import RingColorPicker from './ring/index'
import XDColorPicker from './xd/index'
import VSCodePicker from './vscode/index'

export default {
create (opts) {
Expand All @@ -16,6 +17,8 @@ export default {
return new RingColorPicker(opts);
case 'mini':
return new MiniColorPicker(opts);
case 'vscode':
return new VSCodePicker(opts);
case 'mini-vertical':
return new MiniVerticalColorPicker(opts);
case 'sketch':
Expand All @@ -29,5 +32,6 @@ export default {
MacOSColorPicker,
RingColorPicker,
MiniColorPicker,
VSCodePicker,
MiniVerticalColorPicker
}
11 changes: 5 additions & 6 deletions src/colorpicker/module/ColorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ export default class ColorManager extends BaseModule {

$store.alpha = isUndefined(colorObj.a) ? $store.alpha : colorObj.a;
$store.format = colorObj.type != 'hsv' ? (colorObj.type || $store.format) : $store.format;

if ($store.format == 'hex' && $store.alpha < 1) {
$store.format = 'rgb';
}


if (colorObj.type == 'hsl') {
$store.hsl = Object.assign($store.hsl, colorObj);
$store.rgb = Color.HSLtoRGB($store.hsl);
Expand Down Expand Up @@ -80,7 +76,10 @@ export default class ColorManager extends BaseModule {
'/toString' ($store, type) {
type = type || $store.format
var colorObj = $store[type] || $store.rgb
return Color.format(Object.assign({}, colorObj, {a: $store.alpha} ), type);
return Color.format({
...colorObj,
a: $store.alpha
}, type);
}

'/toColor' ($store, type) {
Expand Down
56 changes: 33 additions & 23 deletions src/colorpicker/ui/ColorInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const source = 'chromedevtool-information';
export default class ColorInformation extends UIElement {

template () {
return `
return /*html*/`
<div class="information hex">
<div ref="$informationChange" class="information-change">
<button ref="$formatChangeButton" type="button" class="format-change-button arrow-button"></button>
Expand Down Expand Up @@ -68,9 +68,10 @@ export default class ColorInformation extends UIElement {
initFormat () {
var current_format = this.format || 'hex';

this.$el.removeClass('hex');
this.$el.removeClass('rgb');
this.$el.removeClass('hsl');
['hex', 'rgb', 'hsl'].filter(it => it !== current_format).forEach(formatString => {
this.$el.removeClass(formatString);
})

this.$el.addClass(current_format);
}

Expand All @@ -83,26 +84,29 @@ export default class ColorInformation extends UIElement {
} else if (current_format == 'rgb') {
next_format = 'hsl';
} else if (current_format == 'hsl') {
if (this.$store.alpha == 1) {
next_format = 'hex';
} else {
next_format = 'rgb';
}
next_format = 'hex';
}

this.$el.removeClass(current_format);
this.$el.addClass(next_format);
this.format = next_format;
this.initFormat();

this.$store.dispatch('/changeFormat', this.format);
this.$store.emit('lastUpdateColor')
this.$store.emit('lastUpdateColor')
}

goToFormat(to_format) {
this.format = to_format;
if (to_format === 'rgb' || to_format === 'hsl') {
this.initFormat();
}

this.$store.dispatch('/changeFormat', this.format);
}

getFormat () {
return this.format || 'hex';
}


checkNumberKey(e) {
var code = e.which,
isExcept = false;
Expand All @@ -129,7 +133,7 @@ export default class ColorInformation extends UIElement {
a : this.refs.$rgb_a.float(),
source
})
this.$store.emit('lastUpdateColor')
this.$store.emit('lastUpdateColor')
}

changeHslColor () {
Expand All @@ -140,8 +144,8 @@ export default class ColorInformation extends UIElement {
l : this.refs.$hsl_l.int(),
a : this.refs.$hsl_a.float(),
source
})
this.$store.emit('lastUpdateColor')
})
this.$store.emit('lastUpdateColor')
}

'@changeColor' (sourceType) {
Expand All @@ -161,17 +165,11 @@ export default class ColorInformation extends UIElement {
'input $hsl_s' (e) { this.changeHslColor(); }
'input $hsl_l' (e) { this.changeHslColor(); }
'input $hsl_a' (e) { this.changeHslColor(); }

'keydown $hexCode' (e) {
if(e.which < 65 || e.which > 70) {
return this.checkNumberKey(e);
}
}

'keyup $hexCode' (e) {
var code = this.refs.$hexCode.val();

if(code.charAt(0) == '#' && code.length == 7) {
if(code.charAt(0) == '#' && (code.length == 7 || code.length === 9)) {
this.$store.dispatch('/changeColor', code, source)
this.$store.emit('lastUpdateColor')
}
Expand All @@ -181,6 +179,18 @@ export default class ColorInformation extends UIElement {
this.nextFormat();
}

'click $el .information-item.hex .input-field .title' (e) {
this.goToFormat('hex');
}

'click $el .information-item.rgb .input-field .title' (e) {
this.goToFormat('hsl');
}

'click $el .information-item.hsl .input-field .title' (e) {
this.goToFormat('rgb');
}

setRGBInput() {
this.refs.$rgb_r.val(this.$store.rgb.r);
this.refs.$rgb_g.val(this.$store.rgb.g);
Expand Down
7 changes: 3 additions & 4 deletions src/colorpicker/ui/ColorPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ export default class ColorPalette extends UIElement {
mousedown (e) {
this.isDown = true;
this.setMainColor(e);
}

}

'touchend document' (e) {
if (this.isDown) {
Expand All @@ -126,6 +125,6 @@ export default class ColorPalette extends UIElement {
e.preventDefault()
this.isDown = true;
this.setMainColor(e);
}

}
}
2 changes: 1 addition & 1 deletion src/colorpicker/ui/CurrentColorSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class CurrentColorSets extends UIElement {

'click $colorSetsColorList .color-item' (e) {
this.$store.dispatch('/changeColor', e.$delegateTarget.attr('data-color'));
this.$store.emit('lastUpdateColor')
this.$store.emit('lastUpdateColor')
}

}
2 changes: 1 addition & 1 deletion src/colorpicker/ui/control/Opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class Opacity extends BaseSlider {
<div class="opacity">
<div ref="$container" class="opacity-container">
<div ref="$colorbar" class="color-bar"></div>
<div ref="$bar" class="drag-bar2"></div>
<div ref="$bar" class="drag-bar"></div>
</div>
</div>
`
Expand Down
40 changes: 40 additions & 0 deletions src/colorpicker/vscode/ColorControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Hue from '../ui/control/VerticalHue';
import Opacity from '../ui/control/VerticalOpacity'
import UIElement from '../UIElement';

const source = 'mini-control';

export default class ColorControl extends UIElement {

components () {
return { Hue, Opacity }
}

template () {
return /*html*/`
<div class="control">
<div target="Opacity" ></div>
<div target="Hue" ></div>
</div>
`
}

refresh () {
this.setColorUI();
}

setColorUI() {
this.Hue.setColorUI()
this.Opacity.setColorUI()
}

'@changeColor' (sourceType) {
if (source != sourceType) {
this.refresh()
}
}

'@initColor' () { this.refresh() }

}

83 changes: 83 additions & 0 deletions src/colorpicker/vscode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import BaseColorPicker from '../BaseColorPicker'

import ColorControl from './ColorControl'
import ColorPalette from '../ui/ColorPalette'
import Color from '../../util/Color'

export default class VSCodePicker extends BaseColorPicker {

template () {
return /*html*/`
<div class='colorpicker-body'>
<div class='color-view'>
<div class='color-view-container' ref="$colorview"></div>
</div>
<div class='color-tool'>
<div target="palette"></div>
<div target="control"></div>
</div>
</div>
`
}

components() {
return {
palette: ColorPalette,
control: ColorControl
}
}

initColorWithoutChangeEvent (color) {
console.log(color);
this.$store.dispatch('/initColor', color);
this.refresh();
}

setBackgroundColor () {
var color = this.$store.dispatch('/toColor')
var rgb = this.$store.rgb;
var bValue = Color.brightness(rgb.r,rgb.g,rgb.b);

this.refs.$colorview.css({
"background-color": color,
'color': bValue > 127 ? 'black': 'white'
});
this.refs.$colorview.html(color);
}

'click $colorview' (e) {
this.nextFormat()
}

nextFormat() {
var current_format = this.$store.format || 'hex';

var next_format = 'hex';
if (current_format == 'hex') {
next_format = 'rgb';
} else if (current_format == 'rgb') {
next_format = 'hsl';
} else if (current_format == 'hsl') {
next_format = 'hex';
}

this.$store.dispatch('/changeFormat', next_format);
this.$store.emit('lastUpdateColor')
this.refresh();
}

refresh () {
this.setBackgroundColor()
}

'@changeColor' () {
this.refresh()
}

'@initColor' () {
this.refresh()
}



}
1 change: 1 addition & 0 deletions src/scss/colorpicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
@import './themes/mini-vertical';
@import './themes/ring';
@import './themes/xd';
@import './themes/vscode';
}

@import './component/colorsets-contextmenu';
Loading

0 comments on commit 0cffa4d

Please sign in to comment.