@destyler/color-picker 0.1.0 → 0.2.0-beta.5
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/dist/{index.d.ts → index.d.mts} +1 -1
- package/dist/{index.js → index.mjs} +33 -65
- package/package.json +22 -13
|
@@ -332,4 +332,4 @@ declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Mac
|
|
|
332
332
|
//#region src/parse.d.ts
|
|
333
333
|
declare function parse(colorString: string): Color$1;
|
|
334
334
|
//#endregion
|
|
335
|
-
export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type Color, type ColorAxes, type ColorChannel, type ColorFormat, type ColorType, type UserDefinedContext as Context, type ElementIds, type FocusOutsideEvent, type FormatChangeDetails, type InteractOutsideEvent, type OpenChangeDetails, type PointerDownOutsideEvent, type PositioningOptions, type Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
|
|
335
|
+
export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type Color, type ColorAxes, type ColorChannel, type ColorFormat, type ColorType, type UserDefinedContext as Context, type ElementIds, type FocusOutsideEvent, type FormatChangeDetails, type InteractOutsideEvent, type MachineState, type OpenChangeDetails, type PointerDownOutsideEvent, type PositioningOptions, type Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
|
|
@@ -130,7 +130,7 @@ function getChannelRange(color, channel) {
|
|
|
130
130
|
pageSize: 10,
|
|
131
131
|
step: 1
|
|
132
132
|
};
|
|
133
|
-
case "css": return
|
|
133
|
+
case "css": return;
|
|
134
134
|
case "hue":
|
|
135
135
|
case "saturation":
|
|
136
136
|
case "lightness": return color.toFormat("hsla").getChannelRange(channel);
|
|
@@ -155,22 +155,13 @@ function getSliderBackground(props) {
|
|
|
155
155
|
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
156
156
|
switch (channel) {
|
|
157
157
|
case "hue": return `linear-gradient(to ${bgDirection}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
|
|
158
|
-
case "lightness": {
|
|
159
|
-
const start = value.withChannelValue(channel, minValue).toString("css");
|
|
160
|
-
const middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
161
|
-
const end = value.withChannelValue(channel, maxValue).toString("css");
|
|
162
|
-
return `linear-gradient(to ${bgDirection}, ${start}, ${middle}, ${end})`;
|
|
163
|
-
}
|
|
158
|
+
case "lightness": return `linear-gradient(to ${bgDirection}, ${value.withChannelValue(channel, minValue).toString("css")}, ${value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css")}, ${value.withChannelValue(channel, maxValue).toString("css")})`;
|
|
164
159
|
case "saturation":
|
|
165
160
|
case "brightness":
|
|
166
161
|
case "red":
|
|
167
162
|
case "green":
|
|
168
163
|
case "blue":
|
|
169
|
-
case "alpha": {
|
|
170
|
-
const start = value.withChannelValue(channel, minValue).toString("css");
|
|
171
|
-
const end = value.withChannelValue(channel, maxValue).toString("css");
|
|
172
|
-
return `linear-gradient(to ${bgDirection}, ${start}, ${end})`;
|
|
173
|
-
}
|
|
164
|
+
case "alpha": return `linear-gradient(to ${bgDirection}, ${value.withChannelValue(channel, minValue).toString("css")}, ${value.withChannelValue(channel, maxValue).toString("css")})`;
|
|
174
165
|
default: throw new Error(`Unknown color channel: ${channel}`);
|
|
175
166
|
}
|
|
176
167
|
}
|
|
@@ -230,28 +221,25 @@ function connect(state, send, normalize) {
|
|
|
230
221
|
return value.formatChannelValue(channel, locale);
|
|
231
222
|
},
|
|
232
223
|
setChannelValue(channel, channelValue) {
|
|
233
|
-
const color = value.withChannelValue(channel, channelValue);
|
|
234
224
|
send({
|
|
235
225
|
type: "VALUE.SET",
|
|
236
|
-
value:
|
|
226
|
+
value: value.withChannelValue(channel, channelValue),
|
|
237
227
|
src: "set-channel"
|
|
238
228
|
});
|
|
239
229
|
},
|
|
240
230
|
format: state.context.format,
|
|
241
231
|
setFormat(format) {
|
|
242
|
-
const formatValue = value.toFormat(format);
|
|
243
232
|
send({
|
|
244
233
|
type: "VALUE.SET",
|
|
245
|
-
value:
|
|
234
|
+
value: value.toFormat(format),
|
|
246
235
|
src: "set-format"
|
|
247
236
|
});
|
|
248
237
|
},
|
|
249
238
|
alpha: value.getChannelValue("alpha"),
|
|
250
239
|
setAlpha(alphaValue) {
|
|
251
|
-
const color = value.withChannelValue("alpha", alphaValue);
|
|
252
240
|
send({
|
|
253
241
|
type: "VALUE.SET",
|
|
254
|
-
value:
|
|
242
|
+
value: value.withChannelValue("alpha", alphaValue),
|
|
255
243
|
src: "set-alpha"
|
|
256
244
|
});
|
|
257
245
|
},
|
|
@@ -278,8 +266,7 @@ function connect(state, send, normalize) {
|
|
|
278
266
|
"data-focus": dataAttr(focused),
|
|
279
267
|
onClick(event) {
|
|
280
268
|
event.preventDefault();
|
|
281
|
-
|
|
282
|
-
inputEl?.focus({ preventScroll: true });
|
|
269
|
+
query(dom.getControlEl(state.context), "[data-channel=hex]")?.focus({ preventScroll: true });
|
|
283
270
|
}
|
|
284
271
|
});
|
|
285
272
|
},
|
|
@@ -367,15 +354,13 @@ function connect(state, send, normalize) {
|
|
|
367
354
|
if (!interactive) return;
|
|
368
355
|
if (!isLeftClick(event)) return;
|
|
369
356
|
if (isModifierKey(event)) return;
|
|
370
|
-
const point = getEventPoint(event);
|
|
371
|
-
const channel = {
|
|
372
|
-
xChannel,
|
|
373
|
-
yChannel
|
|
374
|
-
};
|
|
375
357
|
send({
|
|
376
358
|
type: "AREA.POINTER_DOWN",
|
|
377
|
-
point,
|
|
378
|
-
channel
|
|
359
|
+
point: getEventPoint(event),
|
|
360
|
+
channel: {
|
|
361
|
+
xChannel,
|
|
362
|
+
yChannel
|
|
363
|
+
},
|
|
379
364
|
id: "area"
|
|
380
365
|
});
|
|
381
366
|
event.preventDefault();
|
|
@@ -457,7 +442,7 @@ function connect(state, send, normalize) {
|
|
|
457
442
|
if (event.defaultPrevented) return;
|
|
458
443
|
if (!interactive) return;
|
|
459
444
|
const step = getEventStep(event);
|
|
460
|
-
const
|
|
445
|
+
const exec = {
|
|
461
446
|
ArrowUp() {
|
|
462
447
|
send({
|
|
463
448
|
type: "AREA.ARROW_UP",
|
|
@@ -503,8 +488,7 @@ function connect(state, send, normalize) {
|
|
|
503
488
|
Escape(event$1) {
|
|
504
489
|
event$1.stopPropagation();
|
|
505
490
|
}
|
|
506
|
-
};
|
|
507
|
-
const exec = keyMap[getEventKey(event, state.context)];
|
|
491
|
+
}[getEventKey(event, state.context)];
|
|
508
492
|
if (exec) {
|
|
509
493
|
exec(event);
|
|
510
494
|
event.preventDefault();
|
|
@@ -541,12 +525,11 @@ function connect(state, send, normalize) {
|
|
|
541
525
|
if (!interactive) return;
|
|
542
526
|
if (!isLeftClick(event)) return;
|
|
543
527
|
if (isModifierKey(event)) return;
|
|
544
|
-
const point = getEventPoint(event);
|
|
545
528
|
send({
|
|
546
529
|
type: "CHANNEL_SLIDER.POINTER_DOWN",
|
|
547
530
|
channel,
|
|
548
531
|
format,
|
|
549
|
-
point,
|
|
532
|
+
point: getEventPoint(event),
|
|
550
533
|
id: channel,
|
|
551
534
|
orientation
|
|
552
535
|
});
|
|
@@ -647,7 +630,7 @@ function connect(state, send, normalize) {
|
|
|
647
630
|
if (event.defaultPrevented) return;
|
|
648
631
|
if (!interactive) return;
|
|
649
632
|
const step = getEventStep(event) * channelRange.step;
|
|
650
|
-
const
|
|
633
|
+
const exec = {
|
|
651
634
|
ArrowUp() {
|
|
652
635
|
send({
|
|
653
636
|
type: "CHANNEL_SLIDER.ARROW_UP",
|
|
@@ -703,8 +686,7 @@ function connect(state, send, normalize) {
|
|
|
703
686
|
Escape(event$1) {
|
|
704
687
|
event$1.stopPropagation();
|
|
705
688
|
}
|
|
706
|
-
};
|
|
707
|
-
const exec = keyMap[getEventKey(event, state.context)];
|
|
689
|
+
}[getEventKey(event, state.context)];
|
|
708
690
|
if (exec) {
|
|
709
691
|
exec(event);
|
|
710
692
|
event.preventDefault();
|
|
@@ -728,15 +710,14 @@ function connect(state, send, normalize) {
|
|
|
728
710
|
"data-disabled": dataAttr(disabled),
|
|
729
711
|
"data-invalid": dataAttr(state.context.invalid),
|
|
730
712
|
"data-readonly": dataAttr(state.context.readOnly),
|
|
731
|
-
|
|
713
|
+
...state.context.readOnly ? { readOnly: true } : {},
|
|
732
714
|
"defaultValue": getChannelValue(value, channel),
|
|
733
715
|
"min": channelRange?.minValue,
|
|
734
716
|
"max": channelRange?.maxValue,
|
|
735
717
|
"step": channelRange?.step,
|
|
736
718
|
onBeforeInput(event) {
|
|
737
719
|
if (isTextField || !interactive) return;
|
|
738
|
-
|
|
739
|
-
if (value$1.match(/[^0-9.]/g)) event.preventDefault();
|
|
720
|
+
if (event.currentTarget.value.match(/[^0-9.]/g)) event.preventDefault();
|
|
740
721
|
},
|
|
741
722
|
onFocus(event) {
|
|
742
723
|
if (!interactive) return;
|
|
@@ -748,11 +729,10 @@ function connect(state, send, normalize) {
|
|
|
748
729
|
},
|
|
749
730
|
onBlur(event) {
|
|
750
731
|
if (!interactive) return;
|
|
751
|
-
const value$1 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
752
732
|
send({
|
|
753
733
|
type: "CHANNEL_INPUT.BLUR",
|
|
754
734
|
channel,
|
|
755
|
-
value: value
|
|
735
|
+
value: isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber,
|
|
756
736
|
isTextField
|
|
757
737
|
});
|
|
758
738
|
},
|
|
@@ -760,11 +740,10 @@ function connect(state, send, normalize) {
|
|
|
760
740
|
if (event.defaultPrevented) return;
|
|
761
741
|
if (!interactive) return;
|
|
762
742
|
if (event.key === "Enter") {
|
|
763
|
-
const value$1 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
764
743
|
send({
|
|
765
744
|
type: "CHANNEL_INPUT.CHANGE",
|
|
766
745
|
channel,
|
|
767
|
-
value: value
|
|
746
|
+
value: isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber,
|
|
768
747
|
isTextField
|
|
769
748
|
});
|
|
770
749
|
event.preventDefault();
|
|
@@ -783,7 +762,7 @@ function connect(state, send, normalize) {
|
|
|
783
762
|
disabled,
|
|
784
763
|
name: state.context.name,
|
|
785
764
|
tabIndex: -1,
|
|
786
|
-
|
|
765
|
+
...state.context.readOnly ? { readOnly: true } : {},
|
|
787
766
|
required: state.context.required,
|
|
788
767
|
id: dom.getHiddenInputId(state.context),
|
|
789
768
|
style: visuallyHiddenStyle,
|
|
@@ -869,10 +848,9 @@ function connect(state, send, normalize) {
|
|
|
869
848
|
"aria-label": `change color format to ${getNextFormat(state.context.format)}`,
|
|
870
849
|
onClick(event) {
|
|
871
850
|
if (event.currentTarget.disabled) return;
|
|
872
|
-
const nextFormat = getNextFormat(state.context.format);
|
|
873
851
|
send({
|
|
874
852
|
type: "FORMAT.SET",
|
|
875
|
-
format:
|
|
853
|
+
format: getNextFormat(state.context.format),
|
|
876
854
|
src: "format-trigger"
|
|
877
855
|
});
|
|
878
856
|
}
|
|
@@ -886,10 +864,9 @@ function connect(state, send, normalize) {
|
|
|
886
864
|
"defaultValue": state.context.format,
|
|
887
865
|
"disabled": disabled,
|
|
888
866
|
onChange(event) {
|
|
889
|
-
const format = assertFormat(event.currentTarget.value);
|
|
890
867
|
send({
|
|
891
868
|
type: "FORMAT.SET",
|
|
892
|
-
format,
|
|
869
|
+
format: assertFormat(event.currentTarget.value),
|
|
893
870
|
src: "format-select"
|
|
894
871
|
});
|
|
895
872
|
}
|
|
@@ -904,8 +881,7 @@ const formats = [
|
|
|
904
881
|
];
|
|
905
882
|
const formatRegex = /* @__PURE__ */ new RegExp(`^(${formats.join("|")})$`);
|
|
906
883
|
function getNextFormat(format) {
|
|
907
|
-
|
|
908
|
-
return formats[index + 1] ?? formats[0];
|
|
884
|
+
return formats[formats.indexOf(format) + 1] ?? formats[0];
|
|
909
885
|
}
|
|
910
886
|
function assertFormat(format) {
|
|
911
887
|
if (formatRegex.test(format)) return format;
|
|
@@ -1249,8 +1225,7 @@ function machine(userContext) {
|
|
|
1249
1225
|
});
|
|
1250
1226
|
},
|
|
1251
1227
|
trackFormControl(ctx$1, _evt, { send, initialContext }) {
|
|
1252
|
-
|
|
1253
|
-
return trackFormControl(inputEl, {
|
|
1228
|
+
return trackFormControl(dom.getHiddenInputEl(ctx$1), {
|
|
1254
1229
|
onFieldsetDisabledChange(disabled) {
|
|
1255
1230
|
ctx$1.fieldsetDisabled = disabled;
|
|
1256
1231
|
},
|
|
@@ -1266,16 +1241,14 @@ function machine(userContext) {
|
|
|
1266
1241
|
trackPointerMove(ctx$1, evt, { send }) {
|
|
1267
1242
|
return trackPointerMove(dom.getDoc(ctx$1), {
|
|
1268
1243
|
onPointerMove({ point }) {
|
|
1269
|
-
const type = ctx$1.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
|
|
1270
1244
|
send({
|
|
1271
|
-
type,
|
|
1245
|
+
type: ctx$1.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE",
|
|
1272
1246
|
point,
|
|
1273
1247
|
format: evt.format
|
|
1274
1248
|
});
|
|
1275
1249
|
},
|
|
1276
1250
|
onPointerUp() {
|
|
1277
|
-
|
|
1278
|
-
send({ type });
|
|
1251
|
+
send({ type: ctx$1.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP" });
|
|
1279
1252
|
}
|
|
1280
1253
|
});
|
|
1281
1254
|
},
|
|
@@ -1288,11 +1261,8 @@ function machine(userContext) {
|
|
|
1288
1261
|
},
|
|
1289
1262
|
actions: {
|
|
1290
1263
|
openEyeDropper(ctx$1) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
const win = dom.getWin(ctx$1);
|
|
1294
|
-
const picker = new win.EyeDropper();
|
|
1295
|
-
picker.open().then(({ sRGBHex }) => {
|
|
1264
|
+
if (!("EyeDropper" in dom.getWin(ctx$1))) return;
|
|
1265
|
+
new (dom.getWin(ctx$1)).EyeDropper().open().then(({ sRGBHex }) => {
|
|
1296
1266
|
const format = ctx$1.value.getFormat();
|
|
1297
1267
|
const color = parseColor(sRGBHex).toFormat(format);
|
|
1298
1268
|
set.value(ctx$1, color);
|
|
@@ -1327,8 +1297,7 @@ function machine(userContext) {
|
|
|
1327
1297
|
const normalizedValue = evt.format ? ctx$1.value.toFormat(evt.format) : ctx$1.areaValue;
|
|
1328
1298
|
const percent = dom.getChannelSliderValueFromPoint(ctx$1, evt.point, channel);
|
|
1329
1299
|
if (!percent) return;
|
|
1330
|
-
const
|
|
1331
|
-
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
|
1300
|
+
const channelPercent = (ctx$1.activeOrientation || "horizontal") === "horizontal" ? percent.x : percent.y;
|
|
1332
1301
|
const value = normalizedValue.getChannelPercentValue(channel, channelPercent);
|
|
1333
1302
|
const color = normalizedValue.withChannelValue(channel, value);
|
|
1334
1303
|
set.value(ctx$1, color);
|
|
@@ -1413,11 +1382,10 @@ function machine(userContext) {
|
|
|
1413
1382
|
setInitialFocus(ctx$1) {
|
|
1414
1383
|
if (!ctx$1.openAutoFocus) return;
|
|
1415
1384
|
raf(() => {
|
|
1416
|
-
|
|
1385
|
+
getInitialFocus({
|
|
1417
1386
|
root: dom.getContentEl(ctx$1),
|
|
1418
1387
|
getInitialEl: ctx$1.initialFocusEl
|
|
1419
|
-
});
|
|
1420
|
-
element?.focus({ preventScroll: true });
|
|
1388
|
+
})?.focus({ preventScroll: true });
|
|
1421
1389
|
});
|
|
1422
1390
|
},
|
|
1423
1391
|
setReturnFocus(ctx$1) {
|
package/package.json
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/color-picker",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0-beta.5",
|
|
5
5
|
"description": "a component that allows users to select a color from a color picker.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/destyler/destyler",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/destyler/destyler.git",
|
|
12
|
+
"directory": "packages/components/color-picker"
|
|
13
|
+
},
|
|
8
14
|
"exports": {
|
|
9
|
-
".": "./dist/index.
|
|
15
|
+
".": "./dist/index.mjs"
|
|
10
16
|
},
|
|
11
|
-
"main": "dist/index.
|
|
12
|
-
"module": "dist/index.
|
|
13
|
-
"types": "dist/index.d.
|
|
17
|
+
"main": "dist/index.mjs",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.mts",
|
|
14
20
|
"files": [
|
|
15
21
|
"*.d.ts",
|
|
16
22
|
"dist"
|
|
17
23
|
],
|
|
18
24
|
"dependencies": {
|
|
19
|
-
"@destyler/anatomy": "0.
|
|
20
|
-
"@destyler/dismissable": "0.
|
|
21
|
-
"@destyler/
|
|
22
|
-
"@destyler/
|
|
23
|
-
"@destyler/
|
|
24
|
-
"@destyler/
|
|
25
|
-
"@destyler/
|
|
26
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.0-beta.5",
|
|
26
|
+
"@destyler/dismissable": "0.2.0-beta.5",
|
|
27
|
+
"@destyler/color": "0.2.0-beta.5",
|
|
28
|
+
"@destyler/types": "0.2.0-beta.5",
|
|
29
|
+
"@destyler/dom": "0.2.0-beta.5",
|
|
30
|
+
"@destyler/popper": "0.2.0-beta.5",
|
|
31
|
+
"@destyler/utils": "0.2.0-beta.5",
|
|
32
|
+
"@destyler/xstate": "0.2.0-beta.5"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
27
36
|
},
|
|
28
37
|
"scripts": {
|
|
29
38
|
"clear": "rimraf ./dist",
|