@bhsd/codemirror-css-color-picker 7.0.0 → 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/README.md +1 -3
- package/dist/color.d.ts +17 -1
- package/dist/css.d.ts +1 -37
- package/dist/index.d.ts +1 -2
- package/dist/index.js +86 -81
- package/dist/types.d.ts +26 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,18 +7,16 @@ A CodeMirror extension that adds a color picker input next to CSS color values.
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import {basicSetup} from 'codemirror';
|
|
11
10
|
import {EditorState} from '@codemirror/state';
|
|
12
11
|
import {EditorView} from '@codemirror/view';
|
|
13
12
|
import {css} from '@codemirror/lang-css';
|
|
14
13
|
import {colorPicker} from '@bhsd/codemirror-css-color-picker';
|
|
15
14
|
|
|
16
15
|
new EditorView({
|
|
17
|
-
parent: document.
|
|
16
|
+
parent: document.body,
|
|
18
17
|
state: EditorState.create({
|
|
19
18
|
doc: '.wow {\n\tcolor: #fff;\n}',
|
|
20
19
|
extensions: [
|
|
21
|
-
basicSetup,
|
|
22
20
|
css(),
|
|
23
21
|
colorPicker,
|
|
24
22
|
],
|
package/dist/color.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import 'color-space/hsl.js';
|
|
2
|
-
import type { WidgetOptions, RGB } from './
|
|
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;
|
|
3
19
|
export declare const getDelimiter: (legacy: boolean, spaced: boolean) => string;
|
|
4
20
|
export declare const alphaToString: (alpha: number, legacy: boolean, spaced: boolean) => string;
|
|
5
21
|
export declare const colorToString: ({ color, alpha, colorType, legacy, spaced }: WidgetOptions, value: string, colors?: Record<string, RGB>) => string | false;
|
package/dist/css.d.ts
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
import type {
|
|
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'>;
|
|
1
|
+
import type { DiscoverColors } from './types';
|
|
23
2
|
/**
|
|
24
3
|
* Discovers colors in CSS code
|
|
25
4
|
* @implements
|
|
26
5
|
*/
|
|
27
6
|
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,7 +1,6 @@
|
|
|
1
1
|
import namedColors from 'color-name';
|
|
2
2
|
import type { Extension } from '@codemirror/state';
|
|
3
|
-
import type { DiscoverColors, WidgetOptions, RGB } from './
|
|
4
|
-
export { parseCallExpression, parseColorLiteral, parseNamedColor } from './css.js';
|
|
3
|
+
import type { DiscoverColors, WidgetOptions, RGB } from './types';
|
|
5
4
|
export { namedColors };
|
|
6
5
|
export type { DiscoverColors, WidgetOptions };
|
|
7
6
|
export declare const wrapperClassName = "cm-css-color-picker-wrapper";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,52 @@
|
|
|
1
1
|
import { EditorView, WidgetType, ViewPlugin, Decoration } from "@codemirror/view";
|
|
2
2
|
import { syntaxTree } from "@codemirror/language";
|
|
3
|
-
import
|
|
3
|
+
import namedColors from "color-name";
|
|
4
4
|
import { intToHex } from "@bhsd/common";
|
|
5
5
|
|
|
6
6
|
import { NodeProp } from "@lezer/common";
|
|
7
|
+
var discoverColorsInCSS = (tree, { from, to, name: typeName }, doc) => {
|
|
8
|
+
switch (typeName) {
|
|
9
|
+
case "UnquotedAttributeValue":
|
|
10
|
+
case "AttributeValue": {
|
|
11
|
+
const overlayTree = tree.resolveInner(from, 0).tree?.prop(NodeProp.mounted)?.tree;
|
|
12
|
+
if (overlayTree?.type.name !== "Styles") {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const ret = [], offset = from + (typeName === "AttributeValue" ? 1 : 0);
|
|
16
|
+
overlayTree.iterate({
|
|
17
|
+
from: 0,
|
|
18
|
+
to: overlayTree.length,
|
|
19
|
+
enter({ name, from: overlayFrom, to: overlayTo }) {
|
|
20
|
+
const widgetOptions = discoverColorsInCSS(
|
|
21
|
+
tree,
|
|
22
|
+
{
|
|
23
|
+
from: offset + overlayFrom,
|
|
24
|
+
to: offset + overlayTo,
|
|
25
|
+
name
|
|
26
|
+
},
|
|
27
|
+
doc
|
|
28
|
+
);
|
|
29
|
+
if (widgetOptions) {
|
|
30
|
+
if (Array.isArray(widgetOptions)) {
|
|
31
|
+
throw new Error("Unexpected nested overlays");
|
|
32
|
+
}
|
|
33
|
+
ret.push(widgetOptions);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return ret;
|
|
38
|
+
}
|
|
39
|
+
case "CallExpression":
|
|
40
|
+
case "ColorLiteral":
|
|
41
|
+
case "ValueName":
|
|
42
|
+
return { from, to };
|
|
43
|
+
default:
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
import rgb2 from "color-space/rgb.js";
|
|
49
|
+
import "color-space/hsl.js";
|
|
7
50
|
|
|
8
51
|
var names = {};
|
|
9
52
|
var color_parse_default = parse;
|
|
@@ -16,7 +59,6 @@ var baseHues = {
|
|
|
16
59
|
purple: 300
|
|
17
60
|
};
|
|
18
61
|
function parse(cstr) {
|
|
19
|
-
var _a, _b;
|
|
20
62
|
var m, parts = [], alpha = 1, space;
|
|
21
63
|
if (typeof cstr === "number") {
|
|
22
64
|
return { space: "rgb", values: [cstr >>> 16, (cstr & 65280) >>> 8, cstr & 255], alpha: 1 };
|
|
@@ -93,7 +135,7 @@ function parse(cstr) {
|
|
|
93
135
|
parts = cstr.match(/([0-9]+)/g).map(function(value) {
|
|
94
136
|
return parseFloat(value);
|
|
95
137
|
});
|
|
96
|
-
space =
|
|
138
|
+
space = cstr.match(/([a-z])/ig)?.join("")?.toLowerCase() || "rgb";
|
|
97
139
|
}
|
|
98
140
|
return {
|
|
99
141
|
space,
|
|
@@ -123,59 +165,10 @@ function rgba(color) {
|
|
|
123
165
|
return values;
|
|
124
166
|
}
|
|
125
167
|
|
|
126
|
-
import
|
|
127
|
-
var rgbCallExpRegex = /^rgba?\(\s
|
|
128
|
-
var hslCallExpRegex = /^hsla?\(\s
|
|
168
|
+
import { numToHex } from "@bhsd/common";
|
|
169
|
+
var rgbCallExpRegex = /^rgba?\(\s*(?:\d*\.)?\d+%?(?:\s|\s*,)\s*(?:\d*\.)?\d+%?(?:\s|\s*,)\s*(?:\d*\.)?\d+%?\s*(?:[,/]\s*(?:\d*\.)?\d+%?\s*)?\)$/iu;
|
|
170
|
+
var hslCallExpRegex = /^hsla?\(\s*(?:\d*\.)?\d+(?:deg|g?rad|turn)?(?:\s|\s*,)\s*(?:\d*\.)?\d+%?(?:\s|\s*,)\s*(?:\d*\.)?\d+%?\s*(?:[,/]\s*(?:\d*\.)?\d+%?\s*)?\)$/iu;
|
|
129
171
|
var hexRegex = /^#(?:[\da-f]{3,4}|(?:[\da-f]{2}){3,4})$/iu;
|
|
130
|
-
var discoverColorsInCSS = (tree, { from, to, name: typeName }, doc) => {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
let parse2;
|
|
133
|
-
switch (typeName) {
|
|
134
|
-
case "UnquotedAttributeValue":
|
|
135
|
-
case "AttributeValue": {
|
|
136
|
-
const overlayTree = (_b = (_a = tree.resolveInner(from, 0).tree) == null ? void 0 : _a.prop(NodeProp.mounted)) == null ? void 0 : _b.tree;
|
|
137
|
-
if ((overlayTree == null ? void 0 : overlayTree.type.name) !== "Styles") {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
const ret = [], offset = from + (typeName === "AttributeValue" ? 1 : 0);
|
|
141
|
-
overlayTree.iterate({
|
|
142
|
-
from: 0,
|
|
143
|
-
to: overlayTree.length,
|
|
144
|
-
enter({ name, from: overlayFrom, to: overlayTo }) {
|
|
145
|
-
const widgetOptions = discoverColorsInCSS(
|
|
146
|
-
tree,
|
|
147
|
-
{
|
|
148
|
-
from: offset + overlayFrom,
|
|
149
|
-
to: offset + overlayTo,
|
|
150
|
-
name
|
|
151
|
-
},
|
|
152
|
-
doc
|
|
153
|
-
);
|
|
154
|
-
if (widgetOptions) {
|
|
155
|
-
if (Array.isArray(widgetOptions)) {
|
|
156
|
-
throw new Error("Unexpected nested overlays");
|
|
157
|
-
}
|
|
158
|
-
ret.push(widgetOptions);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
return ret;
|
|
163
|
-
}
|
|
164
|
-
case "CallExpression":
|
|
165
|
-
parse2 = parseCallExpression;
|
|
166
|
-
break;
|
|
167
|
-
case "ColorLiteral":
|
|
168
|
-
parse2 = parseColorLiteral;
|
|
169
|
-
break;
|
|
170
|
-
case "ValueName":
|
|
171
|
-
parse2 = parseNamedColor;
|
|
172
|
-
break;
|
|
173
|
-
default:
|
|
174
|
-
return void 0;
|
|
175
|
-
}
|
|
176
|
-
const result = parse2(doc.sliceString(from, to));
|
|
177
|
-
return result && Object.assign({ from, to }, result);
|
|
178
|
-
};
|
|
179
172
|
var parseCallExpression = (callExp) => {
|
|
180
173
|
const fn = callExp.split("(", 1)[0].toLowerCase();
|
|
181
174
|
switch (fn) {
|
|
@@ -216,12 +209,12 @@ var parseColorLiteral = (colorLiteral) => {
|
|
|
216
209
|
spaced: false
|
|
217
210
|
};
|
|
218
211
|
};
|
|
219
|
-
var parseNamedColor = (colorName) => {
|
|
212
|
+
var parseNamedColor = (colorName, colors) => {
|
|
220
213
|
const lcName = colorName.toLowerCase();
|
|
221
|
-
if (!Object.
|
|
214
|
+
if (!colors || !Object.hasOwn(colors, lcName)) {
|
|
222
215
|
return false;
|
|
223
216
|
}
|
|
224
|
-
const color =
|
|
217
|
+
const color = colors[lcName];
|
|
225
218
|
return {
|
|
226
219
|
colorType: "named",
|
|
227
220
|
color,
|
|
@@ -230,14 +223,9 @@ var parseNamedColor = (colorName) => {
|
|
|
230
223
|
spaced: false
|
|
231
224
|
};
|
|
232
225
|
};
|
|
233
|
-
|
|
234
|
-
import rgb2 from "color-space/rgb.js";
|
|
235
|
-
import "color-space/hsl.js";
|
|
236
|
-
import { numToHex } from "@bhsd/common";
|
|
237
226
|
var getDelimiter = (legacy, spaced) => legacy ? `,${spaced ? " " : ""}` : " ";
|
|
238
227
|
var alphaToString = (alpha, legacy, spaced) => alpha === 1 ? "" : (legacy ? `,${spaced ? " " : ""}` : " / ") + String(alpha === 0 ? alpha : Number(alpha.toFixed(2)));
|
|
239
228
|
var colorToString = ({ color, alpha, colorType, legacy, spaced }, value, colors) => {
|
|
240
|
-
var _a;
|
|
241
229
|
const currentColor = rgba(value).slice(0, 3);
|
|
242
230
|
if (currentColor.every((c, i) => c === Math.round(color[i]))) {
|
|
243
231
|
return false;
|
|
@@ -254,14 +242,16 @@ var colorToString = ({ color, alpha, colorType, legacy, spaced }, value, colors)
|
|
|
254
242
|
}
|
|
255
243
|
case "named":
|
|
256
244
|
if (colors && alpha === 1) {
|
|
257
|
-
const colorName =
|
|
245
|
+
const colorName = Object.entries(colors).find(([, colorValues]) => colorValues.every((c, i) => c === currentColor[i]))?.[0];
|
|
258
246
|
if (colorName) {
|
|
259
247
|
return colorName;
|
|
260
248
|
}
|
|
261
249
|
}
|
|
262
250
|
// fall through
|
|
263
|
-
|
|
251
|
+
case "hex":
|
|
264
252
|
return value + (alpha === 1 ? "" : numToHex(alpha));
|
|
253
|
+
default:
|
|
254
|
+
throw new Error("Unknown color type");
|
|
265
255
|
}
|
|
266
256
|
};
|
|
267
257
|
|
|
@@ -283,7 +273,7 @@ var ColorPickerWidget = class extends WidgetType {
|
|
|
283
273
|
const picker = document.createElement("input");
|
|
284
274
|
picker.type = "color";
|
|
285
275
|
picker.value = `#${this.state.color.map((c) => intToHex(c)).join("")}`;
|
|
286
|
-
if (this.readonly) {
|
|
276
|
+
if (this.readonly || this.state.colorType === "unknown") {
|
|
287
277
|
picker.disabled = true;
|
|
288
278
|
}
|
|
289
279
|
pickerState.set(picker, this.state);
|
|
@@ -297,7 +287,7 @@ var ColorPickerWidget = class extends WidgetType {
|
|
|
297
287
|
return e.type !== "change";
|
|
298
288
|
}
|
|
299
289
|
};
|
|
300
|
-
var colorPickersDecorations = (view, discoverColors) => {
|
|
290
|
+
var colorPickersDecorations = (view, discoverColors, colors) => {
|
|
301
291
|
const widgets = [], { state, visibleRanges } = view, tree = syntaxTree(state);
|
|
302
292
|
for (const { from, to } of visibleRanges) {
|
|
303
293
|
tree.iterate({
|
|
@@ -309,6 +299,21 @@ var colorPickersDecorations = (view, discoverColors) => {
|
|
|
309
299
|
return widgetOptions;
|
|
310
300
|
}
|
|
311
301
|
for (const wo of Array.isArray(widgetOptions) ? widgetOptions : [widgetOptions]) {
|
|
302
|
+
if (wo.colorType !== "unknown") {
|
|
303
|
+
const value = state.sliceDoc(wo.from, wo.to);
|
|
304
|
+
let data;
|
|
305
|
+
if (value.includes("(")) {
|
|
306
|
+
data = parseCallExpression(value);
|
|
307
|
+
} else if (value.startsWith("#")) {
|
|
308
|
+
data = parseColorLiteral(value);
|
|
309
|
+
} else {
|
|
310
|
+
data = parseNamedColor(value, colors);
|
|
311
|
+
}
|
|
312
|
+
if (!data) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
Object.assign(wo, data);
|
|
316
|
+
}
|
|
312
317
|
widgets.push(
|
|
313
318
|
Decoration.widget({
|
|
314
319
|
widget: new ColorPickerWidget(wo, state.readOnly),
|
|
@@ -329,13 +334,15 @@ var colorPickerTheme = EditorView.baseTheme({
|
|
|
329
334
|
marginRight: "0.6ch",
|
|
330
335
|
height: "1em",
|
|
331
336
|
width: "1em",
|
|
332
|
-
transform: "translateY(
|
|
333
|
-
'
|
|
337
|
+
transform: "translateY(0.1em)",
|
|
338
|
+
'&>input[type="color"]': {
|
|
334
339
|
height: "100%",
|
|
335
340
|
width: "100%",
|
|
336
341
|
padding: 0,
|
|
342
|
+
appearance: "none",
|
|
337
343
|
border: "none",
|
|
338
|
-
|
|
344
|
+
borderRadius: 0,
|
|
345
|
+
outline: "1px solid #ddd",
|
|
339
346
|
"&:enabled": {
|
|
340
347
|
cursor: "pointer"
|
|
341
348
|
},
|
|
@@ -343,10 +350,12 @@ var colorPickerTheme = EditorView.baseTheme({
|
|
|
343
350
|
padding: 0
|
|
344
351
|
},
|
|
345
352
|
"&::-webkit-color-swatch": {
|
|
346
|
-
border: "none"
|
|
353
|
+
border: "none",
|
|
354
|
+
borderRadius: 0
|
|
347
355
|
},
|
|
348
356
|
"&::-moz-color-swatch": {
|
|
349
|
-
border: "none"
|
|
357
|
+
border: "none",
|
|
358
|
+
borderRadius: 0
|
|
350
359
|
}
|
|
351
360
|
}
|
|
352
361
|
}
|
|
@@ -357,14 +366,14 @@ var makeColorPicker = (discoverColors, colors) => [
|
|
|
357
366
|
/** @class */
|
|
358
367
|
constructor(view) {
|
|
359
368
|
this.readOnly = view.state.readOnly;
|
|
360
|
-
this.decorations = colorPickersDecorations(view, discoverColors);
|
|
369
|
+
this.decorations = colorPickersDecorations(view, discoverColors, colors);
|
|
361
370
|
}
|
|
362
371
|
/** @implements */
|
|
363
372
|
update({ docChanged, viewportChanged, view }) {
|
|
364
373
|
const { readOnly } = view.state;
|
|
365
374
|
if (docChanged || viewportChanged || readOnly !== this.readOnly) {
|
|
366
375
|
this.readOnly = readOnly;
|
|
367
|
-
this.decorations = colorPickersDecorations(view, discoverColors);
|
|
376
|
+
this.decorations = colorPickersDecorations(view, discoverColors, colors);
|
|
368
377
|
}
|
|
369
378
|
}
|
|
370
379
|
},
|
|
@@ -374,9 +383,8 @@ var makeColorPicker = (discoverColors, colors) => [
|
|
|
374
383
|
},
|
|
375
384
|
eventHandlers: {
|
|
376
385
|
change(e, view) {
|
|
377
|
-
var _a;
|
|
378
386
|
const target = e.target;
|
|
379
|
-
if (target.nodeName !== "INPUT" || target.type !== "color" || !
|
|
387
|
+
if (target.nodeName !== "INPUT" || target.type !== "color" || !target.parentElement?.classList.contains(wrapperClassName)) {
|
|
380
388
|
return false;
|
|
381
389
|
}
|
|
382
390
|
const state = pickerState.get(target), insert = colorToString(state, target.value, colors);
|
|
@@ -393,13 +401,10 @@ var makeColorPicker = (discoverColors, colors) => [
|
|
|
393
401
|
),
|
|
394
402
|
colorPickerTheme
|
|
395
403
|
];
|
|
396
|
-
var colorPicker = /* @__PURE__ */ makeColorPicker(discoverColorsInCSS,
|
|
404
|
+
var colorPicker = /* @__PURE__ */ makeColorPicker(discoverColorsInCSS, namedColors);
|
|
397
405
|
export {
|
|
398
406
|
colorPicker,
|
|
399
407
|
makeColorPicker,
|
|
400
|
-
|
|
401
|
-
parseCallExpression,
|
|
402
|
-
parseColorLiteral,
|
|
403
|
-
parseNamedColor,
|
|
408
|
+
namedColors,
|
|
404
409
|
wrapperClassName
|
|
405
410
|
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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 ColorData {
|
|
5
|
+
/** RGB component values, each in the range 0-255 */
|
|
6
|
+
color: RGB;
|
|
7
|
+
alpha: number;
|
|
8
|
+
colorType: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hex' | 'named' | 'unknown';
|
|
9
|
+
legacy: boolean;
|
|
10
|
+
spaced: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface WidgetOptions extends ColorData {
|
|
13
|
+
from: number;
|
|
14
|
+
to: number;
|
|
15
|
+
}
|
|
16
|
+
export type ColorDiscovery = Pick<WidgetOptions, 'from' | 'to'> | WidgetOptions & {
|
|
17
|
+
colorType: 'unknown';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Discovers colors in the syntax node, returning the options for the color picker widgets if colors are found,
|
|
21
|
+
* or `false` if the children of the syntax node can be skipped.
|
|
22
|
+
* @param tree Lezer syntax tree
|
|
23
|
+
* @param node the syntax node to check for colors
|
|
24
|
+
* @param doc the editor document
|
|
25
|
+
*/
|
|
26
|
+
export type DiscoverColors = (tree: Tree, node: SyntaxNodeRef, doc: Text) => ColorDiscovery | ColorDiscovery[] | false | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-css-color-picker",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Enables a color picker input next to CSS colors",
|
|
5
5
|
"homepage": "https://github.com/bhsd-harry/Codemirror-CSS-color-picker#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
30
30
|
"lint:md": "markdownlint-cli2 '**/*.md'",
|
|
31
31
|
"lint": "npm run lint:ts && npm run lint:md",
|
|
32
|
-
"build": "tsc && node build.js && gsed '/^\\/\\/ /d' build/index.js > dist/index.js",
|
|
32
|
+
"build": "tsc && node build.js && gsed '/^\\/\\/ /d' build/index.js > dist/index.js && eslint --no-config-lookup -c eslint.dist.mjs dist/index.js",
|
|
33
33
|
"build:test": "tsc --project test/tsconfig.json && npm test",
|
|
34
34
|
"test": "mocha"
|
|
35
35
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@codemirror/language": "^6.12.3",
|
|
39
39
|
"@codemirror/state": "^6.6.0",
|
|
40
40
|
"@codemirror/view": "^6.41.0",
|
|
41
|
-
"color-name": "
|
|
41
|
+
"color-name": "~2.0.2",
|
|
42
42
|
"color-space": "^2.3.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|