@bhsd/codemirror-css-color-picker 6.3.2 → 7.0.0
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/LICENSE +21 -0
- package/README.md +17 -24
- package/dist/color.d.ts +5 -0
- package/dist/css.d.ts +42 -0
- package/dist/index.d.ts +15 -39
- package/dist/index.js +389 -586
- package/package.json +70 -38
- package/dist/index.cjs +0 -615
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,35 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
A CodeMirror extension that adds a color picker input next to CSS color values. This is a fork of [@replit/codemirror-css-color-picker](https://www.npmjs.com/package/@replit/codemirror-css-color-picker).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Usage
|
|
7
|
+
## Usage
|
|
10
8
|
|
|
11
9
|
```ts
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
10
|
+
import {basicSetup} from 'codemirror';
|
|
11
|
+
import {EditorState} from '@codemirror/state';
|
|
12
|
+
import {EditorView} from '@codemirror/view';
|
|
13
|
+
import {css} from '@codemirror/lang-css';
|
|
14
|
+
import {colorPicker} from '@bhsd/codemirror-css-color-picker';
|
|
17
15
|
|
|
18
16
|
new EditorView({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
outlineColor: 'transparent',
|
|
29
|
-
},
|
|
30
|
-
}),
|
|
31
|
-
],
|
|
32
|
-
}),
|
|
17
|
+
parent: document.querySelector('#editor'),
|
|
18
|
+
state: EditorState.create({
|
|
19
|
+
doc: '.wow {\n\tcolor: #fff;\n}',
|
|
20
|
+
extensions: [
|
|
21
|
+
basicSetup,
|
|
22
|
+
css(),
|
|
23
|
+
colorPicker,
|
|
24
|
+
],
|
|
25
|
+
}),
|
|
33
26
|
});
|
|
34
27
|
```
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
## Todos
|
|
37
30
|
|
|
38
|
-
- Investigate solutions for alpha values. `input[type="color"]`
|
|
31
|
+
- Investigate solutions for alpha values. `input[type="color"]` does not support alpha values. We could show another number input next to it for the alpha value.
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import 'color-space/hsl.js';
|
|
2
|
+
import type { WidgetOptions, RGB } from './css';
|
|
3
|
+
export declare const getDelimiter: (legacy: boolean, spaced: boolean) => string;
|
|
4
|
+
export declare const alphaToString: (alpha: number, legacy: boolean, spaced: boolean) => string;
|
|
5
|
+
export declare const colorToString: ({ color, alpha, colorType, legacy, spaced }: WidgetOptions, value: string, colors?: Record<string, RGB>) => string | false;
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Text } from '@codemirror/state';
|
|
2
|
+
import type { Tree, SyntaxNodeRef } from '@lezer/common';
|
|
3
|
+
export type RGB = [number, number, number];
|
|
4
|
+
export interface WidgetOptions {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
/** RGB component values, each in the range 0-255 */
|
|
8
|
+
color: RGB;
|
|
9
|
+
alpha: number;
|
|
10
|
+
colorType: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hex' | 'named';
|
|
11
|
+
legacy: boolean;
|
|
12
|
+
spaced: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Discovers colors in the syntax node, returning the options for the color picker widgets if colors are found,
|
|
16
|
+
* or `false` if the children of the syntax node can be skipped.
|
|
17
|
+
* @param tree Lezer syntax tree
|
|
18
|
+
* @param node the syntax node to check for colors
|
|
19
|
+
* @param doc the editor document
|
|
20
|
+
*/
|
|
21
|
+
export type DiscoverColors = (tree: Tree, node: SyntaxNodeRef, doc: Text) => WidgetOptions | WidgetOptions[] | false | undefined;
|
|
22
|
+
export type ColorData = Omit<WidgetOptions, 'from' | 'to'>;
|
|
23
|
+
/**
|
|
24
|
+
* Discovers colors in CSS code
|
|
25
|
+
* @implements
|
|
26
|
+
*/
|
|
27
|
+
export declare const discoverColorsInCSS: DiscoverColors;
|
|
28
|
+
/**
|
|
29
|
+
* Parses a CSS color function call expression (including `rgb()`, `rgba()`, `hsl()`, `hsla()`)
|
|
30
|
+
* @param callExp the full text of the call expression, including function name and parentheses
|
|
31
|
+
*/
|
|
32
|
+
export declare const parseCallExpression: (callExp: string) => ColorData | false | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Parses a hex color literal (e.g. `#ff0000`, `#f00`, `#ff000080`, `#f008`)
|
|
35
|
+
* @param colorLiteral the hex color literal text
|
|
36
|
+
*/
|
|
37
|
+
export declare const parseColorLiteral: (colorLiteral: string) => ColorData | false;
|
|
38
|
+
/**
|
|
39
|
+
* Parses a named color (e.g. `red`, `blue`, `rebeccapurple`)
|
|
40
|
+
* @param colorName the named color text
|
|
41
|
+
*/
|
|
42
|
+
export declare const parseNamedColor: (colorName: string) => ColorData | false;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type ColorData = Omit<WidgetOptions, 'from' | 'to'>;
|
|
17
|
-
declare enum ColorType {
|
|
18
|
-
rgb = "RGB",
|
|
19
|
-
hex = "HEX",
|
|
20
|
-
named = "NAMED",
|
|
21
|
-
hsl = "HSL"
|
|
22
|
-
}
|
|
23
|
-
declare function discoverColorsInCSS(syntaxTree: Tree, from: number, to: number, typeName: string, doc: Text, language?: string): WidgetOptions | Array<WidgetOptions> | null;
|
|
24
|
-
declare function parseCallExpression(callExp: string): ColorData | null;
|
|
25
|
-
declare function parseColorLiteral(colorLiteral: string): ColorData | null;
|
|
26
|
-
declare function parseNamedColor(colorName: string): ColorData | null;
|
|
27
|
-
declare const wrapperClassName = "cm-css-color-picker-wrapper";
|
|
28
|
-
declare const colorPickerTheme: Extension;
|
|
29
|
-
interface IFactoryOptions {
|
|
30
|
-
discoverColors: typeof discoverColorsInCSS;
|
|
31
|
-
namedColors?: Map<string, string>;
|
|
32
|
-
}
|
|
33
|
-
declare const makeColorPicker: (options: IFactoryOptions) => ViewPlugin<{
|
|
34
|
-
decorations: DecorationSet;
|
|
35
|
-
update(update: ViewUpdate): void;
|
|
36
|
-
}, undefined>;
|
|
37
|
-
declare const colorPicker: Extension;
|
|
38
|
-
|
|
39
|
-
export { ColorData, ColorType, WidgetOptions, colorPicker, colorPickerTheme, discoverColorsInCSS, makeColorPicker, namedColors, parseCallExpression, parseColorLiteral, parseNamedColor, wrapperClassName };
|
|
1
|
+
import namedColors from 'color-name';
|
|
2
|
+
import type { Extension } from '@codemirror/state';
|
|
3
|
+
import type { DiscoverColors, WidgetOptions, RGB } from './css';
|
|
4
|
+
export { parseCallExpression, parseColorLiteral, parseNamedColor } from './css.js';
|
|
5
|
+
export { namedColors };
|
|
6
|
+
export type { DiscoverColors, WidgetOptions };
|
|
7
|
+
export declare const wrapperClassName = "cm-css-color-picker-wrapper";
|
|
8
|
+
/**
|
|
9
|
+
* Factory function to create a color picker plugin with the given options
|
|
10
|
+
* @param discoverColors the function to discover colors in a syntax node; return `false` to skip children
|
|
11
|
+
* @param colors an optional object of color names mapping to RGB values
|
|
12
|
+
*/
|
|
13
|
+
export declare const makeColorPicker: (discoverColors: DiscoverColors, colors?: Record<string, RGB>) => Extension;
|
|
14
|
+
/** Default color picker plugin for CSS and HTML */
|
|
15
|
+
export declare const colorPicker: Extension;
|