@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 +21 -0
- package/README.md +15 -24
- package/dist/color.d.ts +21 -0
- package/dist/css.d.ts +6 -0
- package/dist/index.d.ts +14 -39
- package/dist/index.js +395 -587
- package/dist/types.d.ts +26 -0
- package/package.json +70 -38
- package/dist/index.cjs +0 -615
package/dist/index.js
CHANGED
|
@@ -1,602 +1,410 @@
|
|
|
1
|
-
import { EditorView, ViewPlugin, Decoration
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { EditorView, WidgetType, ViewPlugin, Decoration } from "@codemirror/view";
|
|
2
|
+
import { syntaxTree } from "@codemirror/language";
|
|
3
|
+
import namedColors from "color-name";
|
|
4
|
+
import { intToHex } from "@bhsd/common";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
['darkgreen', '#006400'],
|
|
32
|
-
['darkgrey', '#a9a9a9'],
|
|
33
|
-
['darkkhaki', '#bdb76b'],
|
|
34
|
-
['darkmagenta', '#8b008b'],
|
|
35
|
-
['darkolivegreen', '#556b2f'],
|
|
36
|
-
['darkorange', '#ff8c00'],
|
|
37
|
-
['darkorchid', '#9932cc'],
|
|
38
|
-
['darkred', '#8b0000'],
|
|
39
|
-
['darksalmon', '#e9967a'],
|
|
40
|
-
['darkseagreen', '#8fbc8f'],
|
|
41
|
-
['darkslateblue', '#483d8b'],
|
|
42
|
-
['darkslategray', '#2f4f4f'],
|
|
43
|
-
['darkslategrey', '#2f4f4f'],
|
|
44
|
-
['darkturquoise', '#00ced1'],
|
|
45
|
-
['darkviolet', '#9400d3'],
|
|
46
|
-
['deeppink', '#ff1493'],
|
|
47
|
-
['deepskyblue', '#00bfff'],
|
|
48
|
-
['dimgray', '#696969'],
|
|
49
|
-
['dimgrey', '#696969'],
|
|
50
|
-
['dodgerblue', '#1e90ff'],
|
|
51
|
-
['firebrick', '#b22222'],
|
|
52
|
-
['floralwhite', '#fffaf0'],
|
|
53
|
-
['forestgreen', '#228b22'],
|
|
54
|
-
['fuchsia', '#ff00ff'],
|
|
55
|
-
['gainsboro', '#dcdcdc'],
|
|
56
|
-
['ghostwhite', '#f8f8ff'],
|
|
57
|
-
['goldenrod', '#daa520'],
|
|
58
|
-
['gold', '#ffd700'],
|
|
59
|
-
['gray', '#808080'],
|
|
60
|
-
['green', '#008000'],
|
|
61
|
-
['greenyellow', '#adff2f'],
|
|
62
|
-
['grey', '#808080'],
|
|
63
|
-
['honeydew', '#f0fff0'],
|
|
64
|
-
['hotpink', '#ff69b4'],
|
|
65
|
-
['indianred', '#cd5c5c'],
|
|
66
|
-
['indigo', '#4b0082'],
|
|
67
|
-
['ivory', '#fffff0'],
|
|
68
|
-
['khaki', '#f0e68c'],
|
|
69
|
-
['lavenderblush', '#fff0f5'],
|
|
70
|
-
['lavender', '#e6e6fa'],
|
|
71
|
-
['lawngreen', '#7cfc00'],
|
|
72
|
-
['lemonchiffon', '#fffacd'],
|
|
73
|
-
['lightblue', '#add8e6'],
|
|
74
|
-
['lightcoral', '#f08080'],
|
|
75
|
-
['lightcyan', '#e0ffff'],
|
|
76
|
-
['lightgoldenrodyellow', '#fafad2'],
|
|
77
|
-
['lightgray', '#d3d3d3'],
|
|
78
|
-
['lightgreen', '#90ee90'],
|
|
79
|
-
['lightgrey', '#d3d3d3'],
|
|
80
|
-
['lightpink', '#ffb6c1'],
|
|
81
|
-
['lightsalmon', '#ffa07a'],
|
|
82
|
-
['lightseagreen', '#20b2aa'],
|
|
83
|
-
['lightskyblue', '#87cefa'],
|
|
84
|
-
['lightslategray', '#778899'],
|
|
85
|
-
['lightslategrey', '#778899'],
|
|
86
|
-
['lightsteelblue', '#b0c4de'],
|
|
87
|
-
['lightyellow', '#ffffe0'],
|
|
88
|
-
['lime', '#00ff00'],
|
|
89
|
-
['limegreen', '#32cd32'],
|
|
90
|
-
['linen', '#faf0e6'],
|
|
91
|
-
['magenta', '#ff00ff'],
|
|
92
|
-
['maroon', '#800000'],
|
|
93
|
-
['mediumaquamarine', '#66cdaa'],
|
|
94
|
-
['mediumblue', '#0000cd'],
|
|
95
|
-
['mediumorchid', '#ba55d3'],
|
|
96
|
-
['mediumpurple', '#9370db'],
|
|
97
|
-
['mediumseagreen', '#3cb371'],
|
|
98
|
-
['mediumslateblue', '#7b68ee'],
|
|
99
|
-
['mediumspringgreen', '#00fa9a'],
|
|
100
|
-
['mediumturquoise', '#48d1cc'],
|
|
101
|
-
['mediumvioletred', '#c71585'],
|
|
102
|
-
['midnightblue', '#191970'],
|
|
103
|
-
['mintcream', '#f5fffa'],
|
|
104
|
-
['mistyrose', '#ffe4e1'],
|
|
105
|
-
['moccasin', '#ffe4b5'],
|
|
106
|
-
['navajowhite', '#ffdead'],
|
|
107
|
-
['navy', '#000080'],
|
|
108
|
-
['oldlace', '#fdf5e6'],
|
|
109
|
-
['olive', '#808000'],
|
|
110
|
-
['olivedrab', '#6b8e23'],
|
|
111
|
-
['orange', '#ffa500'],
|
|
112
|
-
['orangered', '#ff4500'],
|
|
113
|
-
['orchid', '#da70d6'],
|
|
114
|
-
['palegoldenrod', '#eee8aa'],
|
|
115
|
-
['palegreen', '#98fb98'],
|
|
116
|
-
['paleturquoise', '#afeeee'],
|
|
117
|
-
['palevioletred', '#db7093'],
|
|
118
|
-
['papayawhip', '#ffefd5'],
|
|
119
|
-
['peachpuff', '#ffdab9'],
|
|
120
|
-
['peru', '#cd853f'],
|
|
121
|
-
['pink', '#ffc0cb'],
|
|
122
|
-
['plum', '#dda0dd'],
|
|
123
|
-
['powderblue', '#b0e0e6'],
|
|
124
|
-
['purple', '#800080'],
|
|
125
|
-
['rebeccapurple', '#663399'],
|
|
126
|
-
['red', '#ff0000'],
|
|
127
|
-
['rosybrown', '#bc8f8f'],
|
|
128
|
-
['royalblue', '#4169e1'],
|
|
129
|
-
['saddlebrown', '#8b4513'],
|
|
130
|
-
['salmon', '#fa8072'],
|
|
131
|
-
['sandybrown', '#f4a460'],
|
|
132
|
-
['seagreen', '#2e8b57'],
|
|
133
|
-
['seashell', '#fff5ee'],
|
|
134
|
-
['sienna', '#a0522d'],
|
|
135
|
-
['silver', '#c0c0c0'],
|
|
136
|
-
['skyblue', '#87ceeb'],
|
|
137
|
-
['slateblue', '#6a5acd'],
|
|
138
|
-
['slategray', '#708090'],
|
|
139
|
-
['slategrey', '#708090'],
|
|
140
|
-
['snow', '#fffafa'],
|
|
141
|
-
['springgreen', '#00ff7f'],
|
|
142
|
-
['steelblue', '#4682b4'],
|
|
143
|
-
['tan', '#d2b48c'],
|
|
144
|
-
['teal', '#008080'],
|
|
145
|
-
['thistle', '#d8bfd8'],
|
|
146
|
-
['tomato', '#ff6347'],
|
|
147
|
-
['turquoise', '#40e0d0'],
|
|
148
|
-
['violet', '#ee82ee'],
|
|
149
|
-
['wheat', '#f5deb3'],
|
|
150
|
-
['white', '#ffffff'],
|
|
151
|
-
['whitesmoke', '#f5f5f5'],
|
|
152
|
-
['yellow', '#ffff00'],
|
|
153
|
-
['yellowgreen', '#9acd32'],
|
|
154
|
-
]);
|
|
155
|
-
|
|
156
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
157
|
-
var t = {};
|
|
158
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
159
|
-
t[p] = s[p];
|
|
160
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
161
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
162
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
163
|
-
t[p[i]] = s[p[i]];
|
|
164
|
-
}
|
|
165
|
-
return t;
|
|
166
|
-
};
|
|
167
|
-
const pickerState = /*@__PURE__*/new WeakMap();
|
|
168
|
-
var ColorType = /*@__PURE__*/(function (ColorType) {
|
|
169
|
-
ColorType["rgb"] = "RGB";
|
|
170
|
-
ColorType["hex"] = "HEX";
|
|
171
|
-
ColorType["named"] = "NAMED";
|
|
172
|
-
ColorType["hsl"] = "HSL";
|
|
173
|
-
return ColorType})(ColorType || (ColorType = {}));
|
|
174
|
-
const rgbCallExpRegex = /rgba?\(\s*(\d{1,3}%?)\s*[,\s]\s*(\d{1,3}%?)\s*[,\s]\s*(\d{1,3}%?)\s*([,/]\s*0?\.?\d+%?)?\s*\)/;
|
|
175
|
-
const hslCallExpRegex = /hsla?\(\s*(\d{1,3})(?:deg)?\s*[,\s]\s*(\d{1,3})%?\s*[,\s]\s*(\d{1,3})%?\s*([,/]\s*0?\.?\d+%?)?\s*\)/;
|
|
176
|
-
const hexRegex = /(^|\b)(#[0-9a-f]{3,9})(\b|$)/i;
|
|
177
|
-
function discoverColorsInCSS(syntaxTree, from, to, typeName, doc, language) {
|
|
178
|
-
var _a;
|
|
179
|
-
switch (typeName) {
|
|
180
|
-
case 'AttributeValue': {
|
|
181
|
-
const innerTree = syntaxTree.resolveInner(from, 0).tree;
|
|
182
|
-
if (!innerTree) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
const overlayTree = (_a = innerTree.prop(NodeProp.mounted)) === null || _a === void 0 ? void 0 : _a.tree;
|
|
186
|
-
if ((overlayTree === null || overlayTree === void 0 ? void 0 : overlayTree.type.name) !== 'Styles') {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
const ret = [];
|
|
190
|
-
overlayTree.iterate({
|
|
191
|
-
from: 0,
|
|
192
|
-
to: overlayTree.length,
|
|
193
|
-
enter: ({ type, from: overlayFrom, to: overlayTo }) => {
|
|
194
|
-
const maybeWidgetOptions = discoverColorsInCSS(syntaxTree,
|
|
195
|
-
// We add one because the tree doesn't include the
|
|
196
|
-
// quotation mark from the style tag
|
|
197
|
-
from + 1 + overlayFrom, from + 1 + overlayTo, type.name, doc);
|
|
198
|
-
if (maybeWidgetOptions) {
|
|
199
|
-
if (Array.isArray(maybeWidgetOptions)) {
|
|
200
|
-
throw new Error('Unexpected nested overlays');
|
|
201
|
-
}
|
|
202
|
-
ret.push(maybeWidgetOptions);
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
return ret;
|
|
207
|
-
}
|
|
208
|
-
case 'CallExpression': {
|
|
209
|
-
const callExp = doc.sliceString(from, to);
|
|
210
|
-
const result = parseCallExpression(callExp);
|
|
211
|
-
if (!result) {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
return Object.assign(Object.assign({}, result), { from,
|
|
215
|
-
to });
|
|
216
|
-
}
|
|
217
|
-
case 'ColorLiteral': {
|
|
218
|
-
const result = parseColorLiteral(doc.sliceString(from, to));
|
|
219
|
-
if (!result) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
return Object.assign(Object.assign({}, result), { from,
|
|
223
|
-
to });
|
|
224
|
-
}
|
|
225
|
-
case 'ValueName': {
|
|
226
|
-
const colorName = doc.sliceString(from, to);
|
|
227
|
-
const result = parseNamedColor(colorName);
|
|
228
|
-
if (!result) {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
return Object.assign(Object.assign({}, result), { from,
|
|
232
|
-
to });
|
|
233
|
-
}
|
|
234
|
-
default:
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function parseCallExpression(callExp) {
|
|
239
|
-
const fn = callExp.slice(0, 3);
|
|
240
|
-
switch (fn) {
|
|
241
|
-
case 'rgb': {
|
|
242
|
-
const match = rgbCallExpRegex.exec(callExp);
|
|
243
|
-
if (!match) {
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
const [_, r, g, b, a] = match;
|
|
247
|
-
const color = rgbToHex(r, g, b);
|
|
248
|
-
return {
|
|
249
|
-
colorType: ColorType.rgb,
|
|
250
|
-
color,
|
|
251
|
-
alpha: (a === null || a === void 0 ? void 0 : a.replace(/^\//, ',')) || '',
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
case 'hsl': {
|
|
255
|
-
const match = hslCallExpRegex.exec(callExp);
|
|
256
|
-
if (!match) {
|
|
257
|
-
return null;
|
|
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");
|
|
258
32
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return {
|
|
262
|
-
colorType: ColorType.hsl,
|
|
263
|
-
color,
|
|
264
|
-
alpha: (a === null || a === void 0 ? void 0 : a.replace(/^\//, ',')) || '',
|
|
265
|
-
};
|
|
33
|
+
ret.push(widgetOptions);
|
|
34
|
+
}
|
|
266
35
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function parseColorLiteral(colorLiteral) {
|
|
272
|
-
const match = hexRegex.exec(colorLiteral);
|
|
273
|
-
if (!match) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
const [color, alpha] = toFullHex(colorLiteral);
|
|
277
|
-
return {
|
|
278
|
-
colorType: ColorType.hex,
|
|
279
|
-
color,
|
|
280
|
-
alpha,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
function parseNamedColor(colorName) {
|
|
284
|
-
const color = namedColors.get(colorName);
|
|
285
|
-
if (!color) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
colorType: ColorType.named,
|
|
290
|
-
color,
|
|
291
|
-
alpha: '',
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
function colorPickersDecorations(view, discoverColors) {
|
|
295
|
-
const widgets = [];
|
|
296
|
-
const st = syntaxTree(view.state);
|
|
297
|
-
for (const range of view.visibleRanges) {
|
|
298
|
-
st.iterate({
|
|
299
|
-
from: range.from,
|
|
300
|
-
to: range.to,
|
|
301
|
-
enter: ({ type, from, to }) => {
|
|
302
|
-
var _a;
|
|
303
|
-
const maybeWidgetOptions = discoverColors(st, from, to, type.name, view.state.doc, (_a = view.state.facet(language)) === null || _a === void 0 ? void 0 : _a.name);
|
|
304
|
-
if (!maybeWidgetOptions) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
if (!Array.isArray(maybeWidgetOptions)) {
|
|
308
|
-
widgets.push(Decoration.widget({
|
|
309
|
-
widget: new ColorPickerWidget(maybeWidgetOptions),
|
|
310
|
-
side: 1,
|
|
311
|
-
}).range(maybeWidgetOptions.from));
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
for (const wo of maybeWidgetOptions) {
|
|
315
|
-
widgets.push(Decoration.widget({
|
|
316
|
-
widget: new ColorPickerWidget(wo),
|
|
317
|
-
side: 1,
|
|
318
|
-
}).range(wo.from));
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
return Decoration.set(widgets);
|
|
324
|
-
}
|
|
325
|
-
function toFullHex(color) {
|
|
326
|
-
if (color.length === 4) {
|
|
327
|
-
// 3-char hex
|
|
328
|
-
return [
|
|
329
|
-
`#${color[1].repeat(2)}${color[2].repeat(2)}${color[3].repeat(2)}`,
|
|
330
|
-
'',
|
|
331
|
-
];
|
|
332
|
-
}
|
|
333
|
-
if (color.length === 5) {
|
|
334
|
-
// 4-char hex (alpha)
|
|
335
|
-
return [
|
|
336
|
-
`#${color[1].repeat(2)}${color[2].repeat(2)}${color[3].repeat(2)}`,
|
|
337
|
-
color[4].repeat(2),
|
|
338
|
-
];
|
|
339
|
-
}
|
|
340
|
-
if (color.length === 9) {
|
|
341
|
-
// 8-char hex (alpha)
|
|
342
|
-
return [`#${color.slice(1, -2)}`, color.slice(-2)];
|
|
343
|
-
}
|
|
344
|
-
return [color, ''];
|
|
345
|
-
}
|
|
346
|
-
function rgbComponentToHex(component) {
|
|
347
|
-
let numericValue;
|
|
348
|
-
if (component.endsWith('%')) {
|
|
349
|
-
// 0-100%
|
|
350
|
-
const percent = Number(component.slice(0, -1));
|
|
351
|
-
numericValue = Math.round((percent / 100) * 255.0);
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
numericValue = Number(component); // assume 0-255
|
|
355
|
-
}
|
|
356
|
-
return decimalToHex(numericValue);
|
|
357
|
-
}
|
|
358
|
-
function decimalToHex(decimal) {
|
|
359
|
-
const hex = decimal.toString(16);
|
|
360
|
-
return hex.length === 1 ? '0' + hex : hex;
|
|
361
|
-
}
|
|
362
|
-
function hexToRGBComponents(hex) {
|
|
363
|
-
const r = hex.slice(1, 3);
|
|
364
|
-
const g = hex.slice(3, 5);
|
|
365
|
-
const b = hex.slice(5, 7);
|
|
366
|
-
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16)];
|
|
367
|
-
}
|
|
368
|
-
function rgbToHex(r, g, b) {
|
|
369
|
-
return `#${rgbComponentToHex(r)}${rgbComponentToHex(g)}${rgbComponentToHex(b)}`;
|
|
370
|
-
}
|
|
371
|
-
function hslToHex(h, s, l) {
|
|
372
|
-
const sFloat = Number(s) / 100;
|
|
373
|
-
const lFloat = Number(l) / 100;
|
|
374
|
-
const [r, g, b] = hslToRGB(Number(h), sFloat, lFloat);
|
|
375
|
-
return `#${decimalToHex(r)}${decimalToHex(g)}${decimalToHex(b)}`;
|
|
376
|
-
}
|
|
377
|
-
function hslToRGB(hue, saturation, luminance) {
|
|
378
|
-
// If there is no Saturation it means that it’s a shade of grey.
|
|
379
|
-
// So in that case we just need to convert the Luminance and set R,G and B to that level.
|
|
380
|
-
if (saturation === 0) {
|
|
381
|
-
const value = Math.round(luminance * 255);
|
|
382
|
-
return [value, value, value];
|
|
383
|
-
}
|
|
384
|
-
let temp1;
|
|
385
|
-
// If Luminance is smaller then 0.5 (50%) then temporary_1 = Luminance x (1.0+Saturation)
|
|
386
|
-
if (luminance < 0.5) {
|
|
387
|
-
temp1 = luminance * (1.0 + saturation);
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
// If Luminance is equal or larger then 0.5 (50%) then temporary_1 = Luminance + Saturation – Luminance x Saturation
|
|
391
|
-
temp1 = luminance + saturation - luminance * saturation;
|
|
392
|
-
}
|
|
393
|
-
// temporary_2 = 2 x Luminance – temporary _1
|
|
394
|
-
const temp2 = 2 * luminance - temp1;
|
|
395
|
-
// The next step is to convert the 360 degrees in a circle to 1 by dividing the angle by 360.
|
|
396
|
-
hue = hue / 360.0;
|
|
397
|
-
// And now we need another temporary variable for each color channel, temporary_R, temporary_G and temporary_B.
|
|
398
|
-
// All values need to be between 0 and 1. In our case all the values are between 0 and 1
|
|
399
|
-
const tempR = clamp(hue + 0.333);
|
|
400
|
-
const tempG = hue;
|
|
401
|
-
const tempB = clamp(hue - 0.333);
|
|
402
|
-
const red = hueToRGB(temp1, temp2, tempR);
|
|
403
|
-
const green = hueToRGB(temp1, temp2, tempG);
|
|
404
|
-
const blue = hueToRGB(temp1, temp2, tempB);
|
|
405
|
-
return [
|
|
406
|
-
Math.round(red * 255),
|
|
407
|
-
Math.round(green * 255),
|
|
408
|
-
Math.round(blue * 255),
|
|
409
|
-
];
|
|
410
|
-
}
|
|
411
|
-
// If you get a negative value you need to add 1 to it.
|
|
412
|
-
// If you get a value above 1 you need to subtract 1 from it.
|
|
413
|
-
function clamp(num) {
|
|
414
|
-
if (num < 0) {
|
|
415
|
-
return num + 1;
|
|
416
|
-
}
|
|
417
|
-
if (num > 1) {
|
|
418
|
-
return num - 1;
|
|
419
|
-
}
|
|
420
|
-
return num;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Now we need to do up to 3 tests to select the correct formula for each color channel. Let’s start with Red.
|
|
424
|
-
*
|
|
425
|
-
* test 1 – If 6 x temporary_R is smaller then 1, Red = temporary_2 + (temporary_1 – temporary_2) x 6 x temporary_R
|
|
426
|
-
* In the case the first test is larger then 1 check the following
|
|
427
|
-
*
|
|
428
|
-
* test 2 – If 2 x temporary_R is smaller then 1, Red = temporary_1
|
|
429
|
-
* In the case the second test also is larger then 1 do the following
|
|
430
|
-
*
|
|
431
|
-
* test 3 – If 3 x temporary_R is smaller then 2, Red = temporary_2 + (temporary_1 – temporary_2) x (0.666 – temporary_R) x 6
|
|
432
|
-
* In the case the third test also is larger then 2 you do the following
|
|
433
|
-
*
|
|
434
|
-
* Red = temporary_2
|
|
435
|
-
*/
|
|
436
|
-
function hueToRGB(temp1, temp2, tempHue) {
|
|
437
|
-
if (6 * tempHue < 1) {
|
|
438
|
-
return temp2 + (temp1 - temp2) * 6 * tempHue;
|
|
439
|
-
}
|
|
440
|
-
if (2 * tempHue < 1) {
|
|
441
|
-
return temp1;
|
|
442
|
-
}
|
|
443
|
-
if (3 * tempHue < 2) {
|
|
444
|
-
return temp2 + (temp1 - temp2) * (0.666 - tempHue) * 6;
|
|
445
|
-
}
|
|
446
|
-
return temp2;
|
|
447
|
-
}
|
|
448
|
-
// https://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/
|
|
449
|
-
function rgbToHSL(r, g, b) {
|
|
450
|
-
const redPercent = r / 255;
|
|
451
|
-
const greenPercent = g / 255;
|
|
452
|
-
const bluePercent = b / 255;
|
|
453
|
-
const min = Math.min(redPercent, greenPercent, bluePercent);
|
|
454
|
-
const max = Math.max(redPercent, greenPercent, bluePercent);
|
|
455
|
-
const luminance = (max + min) / 2;
|
|
456
|
-
// If the min and max value are the same, it means that there is no saturation. ...
|
|
457
|
-
// If there is no Saturation, we don’t need to calculate the Hue. So we set it to 0 degrees.
|
|
458
|
-
if (max === min) {
|
|
459
|
-
return [0, 0, luminance];
|
|
460
|
-
}
|
|
461
|
-
let saturation;
|
|
462
|
-
// If Luminance is less or equal to 0.5, then Saturation = (max-min)/(max+min)
|
|
463
|
-
if (luminance <= 0.5) {
|
|
464
|
-
saturation = (max - min) / (max + min);
|
|
36
|
+
});
|
|
37
|
+
return ret;
|
|
465
38
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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";
|
|
50
|
+
|
|
51
|
+
var names = {};
|
|
52
|
+
var color_parse_default = parse;
|
|
53
|
+
var baseHues = {
|
|
54
|
+
red: 0,
|
|
55
|
+
orange: 60,
|
|
56
|
+
yellow: 120,
|
|
57
|
+
green: 180,
|
|
58
|
+
blue: 240,
|
|
59
|
+
purple: 300
|
|
60
|
+
};
|
|
61
|
+
function parse(cstr) {
|
|
62
|
+
var m, parts = [], alpha = 1, space;
|
|
63
|
+
if (typeof cstr === "number") {
|
|
64
|
+
return { space: "rgb", values: [cstr >>> 16, (cstr & 65280) >>> 8, cstr & 255], alpha: 1 };
|
|
65
|
+
}
|
|
66
|
+
if (typeof cstr === "number") return { space: "rgb", values: [cstr >>> 16, (cstr & 65280) >>> 8, cstr & 255], alpha: 1 };
|
|
67
|
+
cstr = String(cstr).toLowerCase();
|
|
68
|
+
if (names[cstr]) {
|
|
69
|
+
parts = names[cstr].slice();
|
|
70
|
+
space = "rgb";
|
|
71
|
+
} else if (cstr === "transparent") {
|
|
72
|
+
alpha = 0;
|
|
73
|
+
space = "rgb";
|
|
74
|
+
parts = [0, 0, 0];
|
|
75
|
+
} else if (cstr[0] === "#") {
|
|
76
|
+
var base = cstr.slice(1);
|
|
77
|
+
var size = base.length;
|
|
78
|
+
var isShort = size <= 4;
|
|
79
|
+
alpha = 1;
|
|
80
|
+
if (isShort) {
|
|
81
|
+
parts = [
|
|
82
|
+
parseInt(base[0] + base[0], 16),
|
|
83
|
+
parseInt(base[1] + base[1], 16),
|
|
84
|
+
parseInt(base[2] + base[2], 16)
|
|
85
|
+
];
|
|
86
|
+
if (size === 4) {
|
|
87
|
+
alpha = parseInt(base[3] + base[3], 16) / 255;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
parts = [
|
|
91
|
+
parseInt(base[0] + base[1], 16),
|
|
92
|
+
parseInt(base[2] + base[3], 16),
|
|
93
|
+
parseInt(base[4] + base[5], 16)
|
|
94
|
+
];
|
|
95
|
+
if (size === 8) {
|
|
96
|
+
alpha = parseInt(base[6] + base[7], 16) / 255;
|
|
97
|
+
}
|
|
487
98
|
}
|
|
488
|
-
|
|
99
|
+
if (!parts[0]) parts[0] = 0;
|
|
100
|
+
if (!parts[1]) parts[1] = 0;
|
|
101
|
+
if (!parts[2]) parts[2] = 0;
|
|
102
|
+
space = "rgb";
|
|
103
|
+
} else if (m = /^((?:rgba?|hs[lvb]a?|hwba?|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms|oklch|oklab|color))\s*\(([^\)]*)\)/.exec(cstr)) {
|
|
104
|
+
var name = m[1];
|
|
105
|
+
space = name.replace(/a$/, "");
|
|
106
|
+
var dims = space === "cmyk" ? 4 : space === "gray" ? 1 : 3;
|
|
107
|
+
parts = m[2].trim().split(/\s*[,\/]\s*|\s+/);
|
|
108
|
+
if (space === "color") space = parts.shift();
|
|
109
|
+
parts = parts.map(function(x, i) {
|
|
110
|
+
if (x[x.length - 1] === "%") {
|
|
111
|
+
x = parseFloat(x) / 100;
|
|
112
|
+
if (i === 3) return x;
|
|
113
|
+
if (space === "rgb") return x * 255;
|
|
114
|
+
if (space[0] === "h") return x * 100;
|
|
115
|
+
if (space[0] === "l" && !i) return x * 100;
|
|
116
|
+
if (space === "lab") return x * 125;
|
|
117
|
+
if (space === "lch") return i < 2 ? x * 150 : x * 360;
|
|
118
|
+
if (space[0] === "o" && !i) return x;
|
|
119
|
+
if (space === "oklab") return x * 0.4;
|
|
120
|
+
if (space === "oklch") return i < 2 ? x * 0.4 : x * 360;
|
|
121
|
+
return x;
|
|
122
|
+
}
|
|
123
|
+
if (space[i] === "h" || i === 2 && space[space.length - 1] === "h") {
|
|
124
|
+
if (baseHues[x] !== void 0) return baseHues[x];
|
|
125
|
+
if (x.endsWith("deg")) return parseFloat(x);
|
|
126
|
+
if (x.endsWith("turn")) return parseFloat(x) * 360;
|
|
127
|
+
if (x.endsWith("grad")) return parseFloat(x) * 360 / 400;
|
|
128
|
+
if (x.endsWith("rad")) return parseFloat(x) * 180 / Math.PI;
|
|
129
|
+
}
|
|
130
|
+
if (x === "none") return 0;
|
|
131
|
+
return parseFloat(x);
|
|
132
|
+
});
|
|
133
|
+
alpha = parts.length > dims ? parts.pop() : 1;
|
|
134
|
+
} else if (/[0-9](?:\s|\/|,)/.test(cstr)) {
|
|
135
|
+
parts = cstr.match(/([0-9]+)/g).map(function(value) {
|
|
136
|
+
return parseFloat(value);
|
|
137
|
+
});
|
|
138
|
+
space = cstr.match(/([a-z])/ig)?.join("")?.toLowerCase() || "rgb";
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
space,
|
|
142
|
+
values: parts,
|
|
143
|
+
alpha
|
|
144
|
+
};
|
|
489
145
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const wrapper = document.createElement('span');
|
|
511
|
-
wrapper.appendChild(picker);
|
|
512
|
-
wrapper.className = wrapperClassName;
|
|
513
|
-
return wrapper;
|
|
514
|
-
}
|
|
515
|
-
ignoreEvent() {
|
|
516
|
-
return false;
|
|
517
|
-
}
|
|
146
|
+
|
|
147
|
+
import rgb from "color-space/rgb.js";
|
|
148
|
+
import hsl from "color-space/hsl.js";
|
|
149
|
+
function rgba(color) {
|
|
150
|
+
if (Array.isArray(color) && color.raw) color = String.raw(...arguments);
|
|
151
|
+
if (color instanceof Number) color = +color;
|
|
152
|
+
var values, i, l;
|
|
153
|
+
var parsed = color_parse_default(color);
|
|
154
|
+
if (!parsed.space) return [];
|
|
155
|
+
const min = parsed.space[0] === "h" ? hsl.min : rgb.min;
|
|
156
|
+
const max = parsed.space[0] === "h" ? hsl.max : rgb.max;
|
|
157
|
+
values = Array(3);
|
|
158
|
+
values[0] = Math.min(Math.max(parsed.values[0], min[0]), max[0]);
|
|
159
|
+
values[1] = Math.min(Math.max(parsed.values[1], min[1]), max[1]);
|
|
160
|
+
values[2] = Math.min(Math.max(parsed.values[2], min[2]), max[2]);
|
|
161
|
+
if (parsed.space[0] === "h") {
|
|
162
|
+
values = hsl.rgb(values);
|
|
163
|
+
}
|
|
164
|
+
values.push(Math.min(Math.max(parsed.alpha, 0), 1));
|
|
165
|
+
return values;
|
|
518
166
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
167
|
+
|
|
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;
|
|
171
|
+
var hexRegex = /^#(?:[\da-f]{3,4}|(?:[\da-f]{2}){3,4})$/iu;
|
|
172
|
+
var parseCallExpression = (callExp) => {
|
|
173
|
+
const fn = callExp.split("(", 1)[0].toLowerCase();
|
|
174
|
+
switch (fn) {
|
|
175
|
+
case "rgba":
|
|
176
|
+
case "rgb":
|
|
177
|
+
if (!rgbCallExpRegex.test(callExp)) {
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
case "hsla":
|
|
182
|
+
case "hsl":
|
|
183
|
+
if (!hslCallExpRegex.test(callExp)) {
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
const [r, g, b, alpha] = rgba(callExp);
|
|
191
|
+
return alpha !== void 0 && {
|
|
192
|
+
colorType: fn,
|
|
193
|
+
color: [r, g, b].map(Math.round),
|
|
194
|
+
alpha,
|
|
195
|
+
legacy: callExp.includes(","),
|
|
196
|
+
spaced: /\s/u.test(callExp)
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
var parseColorLiteral = (colorLiteral) => {
|
|
200
|
+
if (!hexRegex.test(colorLiteral)) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const [r, g, b, alpha] = rgba(colorLiteral), { length } = colorLiteral;
|
|
204
|
+
return alpha !== void 0 && {
|
|
205
|
+
colorType: "hex",
|
|
206
|
+
color: [r, g, b],
|
|
207
|
+
alpha,
|
|
208
|
+
legacy: length === 4 || length === 7,
|
|
209
|
+
spaced: false
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
var parseNamedColor = (colorName, colors) => {
|
|
213
|
+
const lcName = colorName.toLowerCase();
|
|
214
|
+
if (!colors || !Object.hasOwn(colors, lcName)) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
const color = colors[lcName];
|
|
218
|
+
return {
|
|
219
|
+
colorType: "named",
|
|
220
|
+
color,
|
|
221
|
+
alpha: 1,
|
|
222
|
+
legacy: true,
|
|
223
|
+
spaced: false
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
var getDelimiter = (legacy, spaced) => legacy ? `,${spaced ? " " : ""}` : " ";
|
|
227
|
+
var alphaToString = (alpha, legacy, spaced) => alpha === 1 ? "" : (legacy ? `,${spaced ? " " : ""}` : " / ") + String(alpha === 0 ? alpha : Number(alpha.toFixed(2)));
|
|
228
|
+
var colorToString = ({ color, alpha, colorType, legacy, spaced }, value, colors) => {
|
|
229
|
+
const currentColor = rgba(value).slice(0, 3);
|
|
230
|
+
if (currentColor.every((c, i) => c === Math.round(color[i]))) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
const delimiter = getDelimiter(legacy, spaced);
|
|
234
|
+
switch (colorType) {
|
|
235
|
+
case "rgba":
|
|
236
|
+
case "rgb":
|
|
237
|
+
return `${colorType}(${currentColor.join(delimiter)}${alphaToString(alpha, legacy, spaced)})`;
|
|
238
|
+
case "hsla":
|
|
239
|
+
case "hsl": {
|
|
240
|
+
const [h, s, l] = rgb2.hsl(currentColor.slice(0, 3));
|
|
241
|
+
return `${colorType}(${[Math.round(h), `${Math.round(s)}%`, `${Math.round(l)}%`].join(delimiter)}${alphaToString(alpha, legacy, spaced)})`;
|
|
549
242
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
243
|
+
case "named":
|
|
244
|
+
if (colors && alpha === 1) {
|
|
245
|
+
const colorName = Object.entries(colors).find(([, colorValues]) => colorValues.every((c, i) => c === currentColor[i]))?.[0];
|
|
246
|
+
if (colorName) {
|
|
247
|
+
return colorName;
|
|
553
248
|
}
|
|
249
|
+
}
|
|
250
|
+
// fall through
|
|
251
|
+
case "hex":
|
|
252
|
+
return value + (alpha === 1 ? "" : numToHex(alpha));
|
|
253
|
+
default:
|
|
254
|
+
throw new Error("Unknown color type");
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
var wrapperClassName = "cm-css-color-picker-wrapper";
|
|
259
|
+
var pickerState = /* @__PURE__ */ new WeakMap();
|
|
260
|
+
var ColorPickerWidget = class extends WidgetType {
|
|
261
|
+
/** @class */
|
|
262
|
+
constructor(state, readOnly) {
|
|
263
|
+
super();
|
|
264
|
+
this.state = state;
|
|
265
|
+
this.readonly = readOnly;
|
|
266
|
+
}
|
|
267
|
+
/** @override */
|
|
268
|
+
eq(other) {
|
|
269
|
+
return other.readonly === this.readonly && other.state.from === this.state.from && other.state.to === this.state.to && other.state.colorType === this.state.colorType && other.state.color === this.state.color && other.state.alpha === this.state.alpha && other.state.legacy === this.state.legacy && other.state.spaced === this.state.spaced;
|
|
270
|
+
}
|
|
271
|
+
/** @override */
|
|
272
|
+
toDOM() {
|
|
273
|
+
const picker = document.createElement("input");
|
|
274
|
+
picker.type = "color";
|
|
275
|
+
picker.value = `#${this.state.color.map((c) => intToHex(c)).join("")}`;
|
|
276
|
+
if (this.readonly || this.state.colorType === "unknown") {
|
|
277
|
+
picker.disabled = true;
|
|
554
278
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
279
|
+
pickerState.set(picker, this.state);
|
|
280
|
+
const wrapper = document.createElement("span");
|
|
281
|
+
wrapper.className = wrapperClassName;
|
|
282
|
+
wrapper.append(picker);
|
|
283
|
+
return wrapper;
|
|
284
|
+
}
|
|
285
|
+
/** @override */
|
|
286
|
+
ignoreEvent(e) {
|
|
287
|
+
return e.type !== "change";
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var colorPickersDecorations = (view, discoverColors, colors) => {
|
|
291
|
+
const widgets = [], { state, visibleRanges } = view, tree = syntaxTree(state);
|
|
292
|
+
for (const { from, to } of visibleRanges) {
|
|
293
|
+
tree.iterate({
|
|
294
|
+
from,
|
|
295
|
+
to,
|
|
296
|
+
enter(node) {
|
|
297
|
+
const widgetOptions = discoverColors(tree, node, state.doc);
|
|
298
|
+
if (!widgetOptions) {
|
|
299
|
+
return widgetOptions;
|
|
300
|
+
}
|
|
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);
|
|
577
311
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const [h, s, l] = rgbToHSL(r, g, b);
|
|
581
|
-
converted = `hsl(${h}, ${Math.round(s * 100)}%, ${Math.round(l * 100)}%${data.alpha})`;
|
|
312
|
+
if (!data) {
|
|
313
|
+
continue;
|
|
582
314
|
}
|
|
315
|
+
Object.assign(wo, data);
|
|
316
|
+
}
|
|
317
|
+
widgets.push(
|
|
318
|
+
Decoration.widget({
|
|
319
|
+
widget: new ColorPickerWidget(wo, state.readOnly),
|
|
320
|
+
side: 1
|
|
321
|
+
}).range(wo.from)
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
return void 0;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return Decoration.set(widgets);
|
|
329
|
+
};
|
|
330
|
+
var colorPickerTheme = EditorView.baseTheme({
|
|
331
|
+
[`.${wrapperClassName}`]: {
|
|
332
|
+
display: "inline-block",
|
|
333
|
+
marginLeft: "0.6ch",
|
|
334
|
+
marginRight: "0.6ch",
|
|
335
|
+
height: "1em",
|
|
336
|
+
width: "1em",
|
|
337
|
+
transform: "translateY(0.1em)",
|
|
338
|
+
'&>input[type="color"]': {
|
|
339
|
+
height: "100%",
|
|
340
|
+
width: "100%",
|
|
341
|
+
padding: 0,
|
|
342
|
+
appearance: "none",
|
|
343
|
+
border: "none",
|
|
344
|
+
borderRadius: 0,
|
|
345
|
+
outline: "1px solid #ddd",
|
|
346
|
+
"&:enabled": {
|
|
347
|
+
cursor: "pointer"
|
|
348
|
+
},
|
|
349
|
+
"&::-webkit-color-swatch-wrapper": {
|
|
350
|
+
padding: 0
|
|
351
|
+
},
|
|
352
|
+
"&::-webkit-color-swatch": {
|
|
353
|
+
border: "none",
|
|
354
|
+
borderRadius: 0
|
|
355
|
+
},
|
|
356
|
+
"&::-moz-color-swatch": {
|
|
357
|
+
border: "none",
|
|
358
|
+
borderRadius: 0
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
var makeColorPicker = (discoverColors, colors) => [
|
|
364
|
+
ViewPlugin.fromClass(
|
|
365
|
+
class ColorPickerViewPlugin {
|
|
366
|
+
/** @class */
|
|
367
|
+
constructor(view) {
|
|
368
|
+
this.readOnly = view.state.readOnly;
|
|
369
|
+
this.decorations = colorPickersDecorations(view, discoverColors, colors);
|
|
370
|
+
}
|
|
371
|
+
/** @implements */
|
|
372
|
+
update({ docChanged, viewportChanged, view }) {
|
|
373
|
+
const { readOnly } = view.state;
|
|
374
|
+
if (docChanged || viewportChanged || readOnly !== this.readOnly) {
|
|
375
|
+
this.readOnly = readOnly;
|
|
376
|
+
this.decorations = colorPickersDecorations(view, discoverColors, colors);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
decorations(v) {
|
|
382
|
+
return v.decorations;
|
|
383
|
+
},
|
|
384
|
+
eventHandlers: {
|
|
385
|
+
change(e, view) {
|
|
386
|
+
const target = e.target;
|
|
387
|
+
if (target.nodeName !== "INPUT" || target.type !== "color" || !target.parentElement?.classList.contains(wrapperClassName)) {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
const state = pickerState.get(target), insert = colorToString(state, target.value, colors);
|
|
391
|
+
if (insert) {
|
|
392
|
+
const { from, to } = state;
|
|
583
393
|
view.dispatch({
|
|
584
|
-
|
|
585
|
-
from: data.from,
|
|
586
|
-
to: data.to,
|
|
587
|
-
insert: converted,
|
|
588
|
-
},
|
|
394
|
+
changes: { from, to, insert }
|
|
589
395
|
});
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
namedColors,
|
|
598
|
-
}),
|
|
599
|
-
colorPickerTheme,
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
),
|
|
402
|
+
colorPickerTheme
|
|
600
403
|
];
|
|
601
|
-
|
|
602
|
-
export {
|
|
404
|
+
var colorPicker = /* @__PURE__ */ makeColorPicker(discoverColorsInCSS, namedColors);
|
|
405
|
+
export {
|
|
406
|
+
colorPicker,
|
|
407
|
+
makeColorPicker,
|
|
408
|
+
namedColors,
|
|
409
|
+
wrapperClassName
|
|
410
|
+
};
|