@bhsd/codemirror-css-color-picker 6.3.2 → 7.1.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 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,26 @@
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
- ![preview](https://replit.com/cdn-cgi/image/width=3840,quality=80/https://storage.googleapis.com/replit/images/1632627522442_46320608eaa3f0c58bebd5fe4a10efc2.gif)
8
-
9
- ### Usage
7
+ ## Usage
10
8
 
11
9
  ```ts
12
- import { basicSetup } from 'codemirror';
13
- import { EditorState } from '@codemirror/state';
14
- import { EditorView } from '@codemirror/view';
15
- import { css } from '@codemirror/lang-css';
16
- import { colorPicker, wrapperClassName } from '@bhsd/codemirror-css-color-picker';
10
+ import {EditorState} from '@codemirror/state';
11
+ import {EditorView} from '@codemirror/view';
12
+ import {css} from '@codemirror/lang-css';
13
+ import {colorPicker} from '@bhsd/codemirror-css-color-picker';
17
14
 
18
15
  new EditorView({
19
- parent: document.querySelector('#editor'),
20
- state: EditorState.create({
21
- doc: '.wow {\n color: #fff;\n}',
22
- extensions: [
23
- basicSetup,
24
- css(),
25
- colorPicker,
26
- EditorView.theme({
27
- [`.${wrapperClassName}`]: {
28
- outlineColor: 'transparent',
29
- },
30
- }),
31
- ],
32
- }),
16
+ parent: document.body,
17
+ state: EditorState.create({
18
+ doc: '.wow {\n\tcolor: #fff;\n}',
19
+ extensions: [
20
+ css(),
21
+ colorPicker,
22
+ ],
23
+ }),
33
24
  });
34
25
  ```
35
26
 
36
- ### Todos
27
+ ## Todos
37
28
 
38
- - Investigate solutions for alpha values. `input[type="color"]` doesn't support alpha values, we could show another number input next to it for the alpha value.
29
+ - 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.
@@ -0,0 +1,21 @@
1
+ import 'color-space/hsl.js';
2
+ import type { WidgetOptions, RGB, ColorData } from './types';
3
+ /**
4
+ * Parses a CSS color function call expression (including `rgb()`, `rgba()`, `hsl()`, `hsla()`)
5
+ * @param callExp the full text of the call expression, including function name and parentheses
6
+ */
7
+ export declare const parseCallExpression: (callExp: string) => ColorData | false | undefined;
8
+ /**
9
+ * Parses a hex color literal (e.g. `#ff0000`, `#f00`, `#ff000080`, `#f008`)
10
+ * @param colorLiteral the hex color literal text
11
+ */
12
+ export declare const parseColorLiteral: (colorLiteral: string) => ColorData | false;
13
+ /**
14
+ * Parses a named color (e.g. `red`, `blue`, `rebeccapurple`)
15
+ * @param colorName the named color text
16
+ * @param colors an object mapping color names to RGB values
17
+ */
18
+ export declare const parseNamedColor: (colorName: string, colors?: Record<string, RGB>) => ColorData | false;
19
+ export declare const getDelimiter: (legacy: boolean, spaced: boolean) => string;
20
+ export declare const alphaToString: (alpha: number, legacy: boolean, spaced: boolean) => string;
21
+ 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,6 @@
1
+ import type { DiscoverColors } from './types';
2
+ /**
3
+ * Discovers colors in CSS code
4
+ * @implements
5
+ */
6
+ export declare const discoverColorsInCSS: DiscoverColors;
package/dist/index.d.ts CHANGED
@@ -1,39 +1,14 @@
1
- import { ViewPlugin, DecorationSet, ViewUpdate } from '@codemirror/view';
2
- import { Text, Extension } from '@codemirror/state';
3
- import { Tree } from '@lezer/common';
4
-
5
- declare const namedColors: Map<string, string>;
6
-
7
- interface PickerState {
8
- from: number;
9
- to: number;
10
- alpha: string;
11
- colorType: ColorType;
12
- }
13
- interface WidgetOptions extends PickerState {
14
- color: string;
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 './types';
4
+ export { namedColors };
5
+ export type { DiscoverColors, WidgetOptions };
6
+ export declare const wrapperClassName = "cm-css-color-picker-wrapper";
7
+ /**
8
+ * Factory function to create a color picker plugin with the given options
9
+ * @param discoverColors the function to discover colors in a syntax node; return `false` to skip children
10
+ * @param colors an optional object of color names mapping to RGB values
11
+ */
12
+ export declare const makeColorPicker: (discoverColors: DiscoverColors, colors?: Record<string, RGB>) => Extension;
13
+ /** Default color picker plugin for CSS and HTML */
14
+ export declare const colorPicker: Extension;