chroma-panel 0.2.0 → 1.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/README.md +46 -8
- package/dist/a11y/contrast.cjs +94 -0
- package/dist/a11y/contrast.d.cts +8 -0
- package/dist/a11y/contrast.d.ts +8 -0
- package/dist/a11y/contrast.js +93 -2
- package/dist/color/css4.cjs +397 -0
- package/dist/color/css4.d.cts +10 -0
- package/dist/color/css4.d.ts +10 -0
- package/dist/color/css4.js +392 -0
- package/dist/color/parse.cjs +3 -1
- package/dist/color/parse.js +3 -1
- package/dist/color/types.d.cts +16 -0
- package/dist/color/types.d.ts +16 -0
- package/dist/color/value.cjs +11 -0
- package/dist/color/value.d.cts +4 -0
- package/dist/color/value.d.ts +4 -0
- package/dist/color/value.js +12 -0
- package/dist/color.cjs +43 -0
- package/dist/color.d.cts +9 -0
- package/dist/color.d.ts +9 -0
- package/dist/color.js +8 -0
- package/dist/components/ChromaPanel.cjs +16 -6
- package/dist/components/ChromaPanel.d.cts +4 -2
- package/dist/components/ChromaPanel.d.ts +4 -2
- package/dist/components/ChromaPanel.js +16 -6
- package/dist/components/ColorInput.cjs +1 -1
- package/dist/components/ColorInput.js +1 -1
- package/dist/components/PanelFooter.cjs +4 -4
- package/dist/components/PanelFooter.js +4 -4
- package/dist/contrast.cjs +3 -0
- package/dist/contrast.d.cts +2 -2
- package/dist/contrast.d.ts +2 -2
- package/dist/contrast.js +2 -2
- package/dist/core/store.cjs +17 -9
- package/dist/core/store.d.cts +6 -6
- package/dist/core/store.d.ts +6 -6
- package/dist/core/store.js +17 -9
- package/dist/core.cjs +10 -0
- package/dist/core.d.cts +4 -2
- package/dist/core.d.ts +4 -2
- package/dist/core.js +3 -1
- package/dist/export/tokens.cjs +39 -0
- package/dist/export/tokens.d.cts +16 -0
- package/dist/export/tokens.d.ts +16 -0
- package/dist/export/tokens.js +37 -0
- package/dist/export.cjs +6 -0
- package/dist/export.d.cts +2 -0
- package/dist/export.d.ts +2 -0
- package/dist/export.js +2 -0
- package/dist/gradient/GradientEditor.cjs +196 -0
- package/dist/gradient/GradientEditor.d.cts +17 -0
- package/dist/gradient/GradientEditor.d.ts +17 -0
- package/dist/gradient/GradientEditor.js +195 -0
- package/dist/gradient/model.cjs +63 -0
- package/dist/gradient/model.d.cts +23 -0
- package/dist/gradient/model.d.ts +23 -0
- package/dist/gradient/model.js +60 -0
- package/dist/gradient.cjs +9 -0
- package/dist/gradient.d.cts +3 -0
- package/dist/gradient.d.ts +3 -0
- package/dist/gradient.js +3 -0
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/modes/image/index.cjs +65 -4
- package/dist/modes/image/index.d.cts +1 -0
- package/dist/modes/image/index.d.ts +1 -0
- package/dist/modes/image/index.js +65 -4
- package/dist/modes/registry.d.cts +1 -1
- package/dist/modes/registry.d.ts +1 -1
- package/dist/modes.cjs +30 -0
- package/dist/modes.d.cts +10 -0
- package/dist/modes.d.ts +10 -0
- package/dist/modes.js +17 -0
- package/dist/panel.cjs +10 -0
- package/dist/panel.d.cts +4 -2
- package/dist/panel.d.ts +4 -2
- package/dist/panel.js +3 -1
- package/dist/primitives/ChannelSlider.cjs +4 -4
- package/dist/primitives/ChannelSlider.js +4 -4
- package/dist/primitives/ColorArea.cjs +6 -6
- package/dist/primitives/ColorArea.js +6 -6
- package/dist/primitives/ColorDisc.cjs +6 -6
- package/dist/primitives/ColorDisc.js +6 -6
- package/dist/primitives/ColorField.cjs +2 -2
- package/dist/primitives/ColorField.js +2 -2
- package/dist/primitives/NumberField.cjs +2 -2
- package/dist/primitives/NumberField.js +2 -2
- package/dist/primitives/SwatchGrid.cjs +2 -2
- package/dist/primitives/SwatchGrid.js +2 -2
- package/package.json +46 -2
|
@@ -24,7 +24,7 @@ const FALLBACK = {
|
|
|
24
24
|
a: 1
|
|
25
25
|
};
|
|
26
26
|
function ChromaPanel(props) {
|
|
27
|
-
const { value, defaultValue = DEFAULT_COLOR, onChange, onChangeComplete, modes = [
|
|
27
|
+
const { value, defaultValue = DEFAULT_COLOR, onChange, onChangeComplete, onValueChange, onValueCommit, modes = [
|
|
28
28
|
"wheel",
|
|
29
29
|
"sliders",
|
|
30
30
|
"palettes",
|
|
@@ -62,13 +62,15 @@ function ChromaPanel(props) {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (sameRendered(parsed, store.get())) return;
|
|
65
|
-
store.ingest(parsed);
|
|
65
|
+
store.ingest(parsed, "programmatic");
|
|
66
66
|
}, [value, store]);
|
|
67
67
|
const [internalRecents, setInternalRecents] = React.useState(() => defaultRecentColors ?? []);
|
|
68
68
|
const activeRecents = recentColors ?? internalRecents;
|
|
69
69
|
const callbacks = React.useRef({
|
|
70
70
|
onChange,
|
|
71
71
|
onChangeComplete,
|
|
72
|
+
onValueChange,
|
|
73
|
+
onValueCommit,
|
|
72
74
|
format,
|
|
73
75
|
activeRecents,
|
|
74
76
|
onRecentColorsChange,
|
|
@@ -78,16 +80,24 @@ function ChromaPanel(props) {
|
|
|
78
80
|
callbacks.current = {
|
|
79
81
|
onChange,
|
|
80
82
|
onChangeComplete,
|
|
83
|
+
onValueChange,
|
|
84
|
+
onValueCommit,
|
|
81
85
|
format,
|
|
82
86
|
activeRecents,
|
|
83
87
|
onRecentColorsChange,
|
|
84
88
|
controlled: recentColors !== void 0
|
|
85
89
|
};
|
|
86
90
|
});
|
|
87
|
-
React.useEffect(() => store.subscribe((c) =>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
React.useEffect(() => store.subscribe((c, meta) => {
|
|
92
|
+
const result = toResult(c, callbacks.current.format);
|
|
93
|
+
callbacks.current.onChange?.(result);
|
|
94
|
+
callbacks.current.onValueChange?.(result, meta);
|
|
95
|
+
}), [store]);
|
|
96
|
+
React.useEffect(() => store.subscribeCommit((c, meta) => {
|
|
97
|
+
const { onChangeComplete: done, format: fmt, activeRecents: recents, onValueCommit: commit, onRecentColorsChange: notify, controlled } = callbacks.current;
|
|
98
|
+
const result = toResult(c, fmt);
|
|
99
|
+
done?.(result);
|
|
100
|
+
commit?.(result, meta);
|
|
91
101
|
const next = pushRecent(recents, toHex(c));
|
|
92
102
|
if (!controlled) setInternalRecents(next);
|
|
93
103
|
notify?.(next);
|
|
@@ -58,7 +58,7 @@ function ColorInput(props) {
|
|
|
58
58
|
});
|
|
59
59
|
require_useFormControl.useFormReset(hiddenRef, () => {
|
|
60
60
|
const parsed = typeof defaultValue === "string" ? require_parse.parse(defaultValue) : defaultValue;
|
|
61
|
-
if (parsed !== null && parsed !== void 0) store.ingest(parsed);
|
|
61
|
+
if (parsed !== null && parsed !== void 0) store.ingest(parsed, "programmatic");
|
|
62
62
|
});
|
|
63
63
|
require_useFormControl.useConstraintValidation(hiddenRef, {
|
|
64
64
|
behavior: validationBehavior,
|
|
@@ -56,7 +56,7 @@ function ColorInput(props) {
|
|
|
56
56
|
});
|
|
57
57
|
useFormReset(hiddenRef, () => {
|
|
58
58
|
const parsed = typeof defaultValue === "string" ? parse(defaultValue) : defaultValue;
|
|
59
|
-
if (parsed !== null && parsed !== void 0) store.ingest(parsed);
|
|
59
|
+
if (parsed !== null && parsed !== void 0) store.ingest(parsed, "programmatic");
|
|
60
60
|
});
|
|
61
61
|
useConstraintValidation(hiddenRef, {
|
|
62
62
|
behavior: validationBehavior,
|
|
@@ -33,8 +33,8 @@ function PanelFooter() {
|
|
|
33
33
|
if (hex === null) return;
|
|
34
34
|
const parsed = require_parse.parse(hex);
|
|
35
35
|
if (parsed === null) return;
|
|
36
|
-
store.ingest(parsed);
|
|
37
|
-
store.commit();
|
|
36
|
+
store.ingest(parsed, "eyedropper");
|
|
37
|
+
store.commit("eyedropper");
|
|
38
38
|
};
|
|
39
39
|
const recentsRef = react.useRef(null);
|
|
40
40
|
const [current, setCurrent] = react.useState(null);
|
|
@@ -66,8 +66,8 @@ function PanelFooter() {
|
|
|
66
66
|
onClick: () => {
|
|
67
67
|
const parsed = require_parse.parse(color);
|
|
68
68
|
if (parsed === null) return;
|
|
69
|
-
store.ingest(parsed);
|
|
70
|
-
store.commit();
|
|
69
|
+
store.ingest(parsed, "recent");
|
|
70
|
+
store.commit("recent");
|
|
71
71
|
}
|
|
72
72
|
}) }, `${color}-${index}`))
|
|
73
73
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "cp-footer-spacer" }),
|
|
@@ -31,8 +31,8 @@ function PanelFooter() {
|
|
|
31
31
|
if (hex === null) return;
|
|
32
32
|
const parsed = parse(hex);
|
|
33
33
|
if (parsed === null) return;
|
|
34
|
-
store.ingest(parsed);
|
|
35
|
-
store.commit();
|
|
34
|
+
store.ingest(parsed, "eyedropper");
|
|
35
|
+
store.commit("eyedropper");
|
|
36
36
|
};
|
|
37
37
|
const recentsRef = React.useRef(null);
|
|
38
38
|
const [current, setCurrent] = React.useState(null);
|
|
@@ -64,8 +64,8 @@ function PanelFooter() {
|
|
|
64
64
|
onClick: () => {
|
|
65
65
|
const parsed = parse(color);
|
|
66
66
|
if (parsed === null) return;
|
|
67
|
-
store.ingest(parsed);
|
|
68
|
-
store.commit();
|
|
67
|
+
store.ingest(parsed, "recent");
|
|
68
|
+
store.commit("recent");
|
|
69
69
|
}
|
|
70
70
|
}) }, `${color}-${index}`))
|
|
71
71
|
}) : /* @__PURE__ */ jsx("div", { className: "cp-footer-spacer" }),
|
package/dist/contrast.cjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_contrast = require("./a11y/contrast.cjs");
|
|
3
3
|
exports.apcaContrast = require_contrast.apcaContrast;
|
|
4
|
+
exports.compositeColor = require_contrast.compositeColor;
|
|
4
5
|
exports.contrastRatio = require_contrast.contrastRatio;
|
|
6
|
+
exports.contrastRatioWithAlpha = require_contrast.contrastRatioWithAlpha;
|
|
5
7
|
exports.contrastReport = require_contrast.contrastReport;
|
|
6
8
|
exports.meetsContrast = require_contrast.meetsContrast;
|
|
7
9
|
exports.meetsNonTextContrast = require_contrast.meetsNonTextContrast;
|
|
8
10
|
exports.readableTextColor = require_contrast.readableTextColor;
|
|
9
11
|
exports.relativeLuminance = require_contrast.relativeLuminance;
|
|
12
|
+
exports.suggestAccessibleColor = require_contrast.suggestAccessibleColor;
|
|
10
13
|
exports.wcagLevel = require_contrast.wcagLevel;
|
package/dist/contrast.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ContrastOptions, ContrastReport, TextSize, WcagLevel, apcaContrast, contrastRatio, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, wcagLevel } from "./a11y/contrast.cjs";
|
|
2
|
-
export { type ContrastOptions, type ContrastReport, type TextSize, type WcagLevel, apcaContrast, contrastRatio, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, wcagLevel };
|
|
1
|
+
import { AccessibleColorSuggestion, ContrastOptions, ContrastReport, TextSize, WcagLevel, apcaContrast, compositeColor, contrastRatio, contrastRatioWithAlpha, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, suggestAccessibleColor, wcagLevel } from "./a11y/contrast.cjs";
|
|
2
|
+
export { type AccessibleColorSuggestion, type ContrastOptions, type ContrastReport, type TextSize, type WcagLevel, apcaContrast, compositeColor, contrastRatio, contrastRatioWithAlpha, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, suggestAccessibleColor, wcagLevel };
|
package/dist/contrast.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ContrastOptions, ContrastReport, TextSize, WcagLevel, apcaContrast, contrastRatio, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, wcagLevel } from "./a11y/contrast.js";
|
|
2
|
-
export { type ContrastOptions, type ContrastReport, type TextSize, type WcagLevel, apcaContrast, contrastRatio, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, wcagLevel };
|
|
1
|
+
import { AccessibleColorSuggestion, ContrastOptions, ContrastReport, TextSize, WcagLevel, apcaContrast, compositeColor, contrastRatio, contrastRatioWithAlpha, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, suggestAccessibleColor, wcagLevel } from "./a11y/contrast.js";
|
|
2
|
+
export { type AccessibleColorSuggestion, type ContrastOptions, type ContrastReport, type TextSize, type WcagLevel, apcaContrast, compositeColor, contrastRatio, contrastRatioWithAlpha, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, suggestAccessibleColor, wcagLevel };
|
package/dist/contrast.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { apcaContrast, contrastRatio, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, wcagLevel } from "./a11y/contrast.js";
|
|
2
|
-
export { apcaContrast, contrastRatio, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, wcagLevel };
|
|
1
|
+
import { apcaContrast, compositeColor, contrastRatio, contrastRatioWithAlpha, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, suggestAccessibleColor, wcagLevel } from "./a11y/contrast.js";
|
|
2
|
+
export { apcaContrast, compositeColor, contrastRatio, contrastRatioWithAlpha, contrastReport, meetsContrast, meetsNonTextContrast, readableTextColor, relativeLuminance, suggestAccessibleColor, wcagLevel };
|
package/dist/core/store.cjs
CHANGED
|
@@ -2,26 +2,34 @@ const require_sticky = require("../color/sticky.cjs");
|
|
|
2
2
|
//#region src/core/store.ts
|
|
3
3
|
function createColorStore(initial) {
|
|
4
4
|
let state = initial;
|
|
5
|
+
let lastSource = "unknown";
|
|
5
6
|
const listeners = /* @__PURE__ */ new Set();
|
|
6
7
|
const commitListeners = /* @__PURE__ */ new Set();
|
|
7
|
-
function emit() {
|
|
8
|
-
for (const listener of Array.from(listeners)) listener(state
|
|
8
|
+
function emit(source) {
|
|
9
|
+
for (const listener of Array.from(listeners)) listener(state, {
|
|
10
|
+
phase: "change",
|
|
11
|
+
source
|
|
12
|
+
});
|
|
9
13
|
}
|
|
10
|
-
function set(next) {
|
|
14
|
+
function set(next, source = "unknown") {
|
|
11
15
|
if (require_sticky.sameHsva(state, next)) return;
|
|
12
16
|
state = next;
|
|
13
|
-
|
|
17
|
+
lastSource = source;
|
|
18
|
+
emit(source);
|
|
14
19
|
}
|
|
15
20
|
return {
|
|
16
21
|
get: () => state,
|
|
17
22
|
set,
|
|
18
|
-
patch: (partial) => set({
|
|
23
|
+
patch: (partial, source) => set({
|
|
19
24
|
...state,
|
|
20
25
|
...partial
|
|
21
|
-
}),
|
|
22
|
-
ingest: (next) => set(require_sticky.ingest(next, state)),
|
|
23
|
-
commit: () => {
|
|
24
|
-
for (const listener of Array.from(commitListeners)) listener(state
|
|
26
|
+
}, source),
|
|
27
|
+
ingest: (next, source) => set(require_sticky.ingest(next, state), source),
|
|
28
|
+
commit: (source = lastSource) => {
|
|
29
|
+
for (const listener of Array.from(commitListeners)) listener(state, {
|
|
30
|
+
phase: "commit",
|
|
31
|
+
source
|
|
32
|
+
});
|
|
25
33
|
},
|
|
26
34
|
subscribe: (listener) => {
|
|
27
35
|
listeners.add(listener);
|
package/dist/core/store.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Hsva } from "../color/types.cjs";
|
|
1
|
+
import { ColorChangeMeta, ColorChangeSource, Hsva } from "../color/types.cjs";
|
|
2
2
|
//#region src/core/store.d.ts
|
|
3
|
-
export type ColorListener = (color: Hsva) => void;
|
|
3
|
+
export type ColorListener = (color: Hsva, meta: ColorChangeMeta) => void;
|
|
4
4
|
export type Unsubscribe = () => void;
|
|
5
5
|
export interface ColorStore {
|
|
6
6
|
get(): Hsva;
|
|
7
|
-
set(next: Hsva): void;
|
|
8
|
-
patch(partial: Partial<Hsva
|
|
9
|
-
ingest(next: Hsva): void;
|
|
10
|
-
commit(): void;
|
|
7
|
+
set(next: Hsva, source?: ColorChangeSource): void;
|
|
8
|
+
patch(partial: Partial<Hsva>, source?: ColorChangeSource): void;
|
|
9
|
+
ingest(next: Hsva, source?: ColorChangeSource): void;
|
|
10
|
+
commit(source?: ColorChangeSource): void;
|
|
11
11
|
subscribe(listener: ColorListener): Unsubscribe;
|
|
12
12
|
subscribeCommit(listener: ColorListener): Unsubscribe;
|
|
13
13
|
getSnapshot(): Hsva;
|
package/dist/core/store.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Hsva } from "../color/types.js";
|
|
1
|
+
import { ColorChangeMeta, ColorChangeSource, Hsva } from "../color/types.js";
|
|
2
2
|
//#region src/core/store.d.ts
|
|
3
|
-
export type ColorListener = (color: Hsva) => void;
|
|
3
|
+
export type ColorListener = (color: Hsva, meta: ColorChangeMeta) => void;
|
|
4
4
|
export type Unsubscribe = () => void;
|
|
5
5
|
export interface ColorStore {
|
|
6
6
|
get(): Hsva;
|
|
7
|
-
set(next: Hsva): void;
|
|
8
|
-
patch(partial: Partial<Hsva
|
|
9
|
-
ingest(next: Hsva): void;
|
|
10
|
-
commit(): void;
|
|
7
|
+
set(next: Hsva, source?: ColorChangeSource): void;
|
|
8
|
+
patch(partial: Partial<Hsva>, source?: ColorChangeSource): void;
|
|
9
|
+
ingest(next: Hsva, source?: ColorChangeSource): void;
|
|
10
|
+
commit(source?: ColorChangeSource): void;
|
|
11
11
|
subscribe(listener: ColorListener): Unsubscribe;
|
|
12
12
|
subscribeCommit(listener: ColorListener): Unsubscribe;
|
|
13
13
|
getSnapshot(): Hsva;
|
package/dist/core/store.js
CHANGED
|
@@ -2,26 +2,34 @@ import { ingest, sameHsva } from "../color/sticky.js";
|
|
|
2
2
|
//#region src/core/store.ts
|
|
3
3
|
function createColorStore(initial) {
|
|
4
4
|
let state = initial;
|
|
5
|
+
let lastSource = "unknown";
|
|
5
6
|
const listeners = /* @__PURE__ */ new Set();
|
|
6
7
|
const commitListeners = /* @__PURE__ */ new Set();
|
|
7
|
-
function emit() {
|
|
8
|
-
for (const listener of Array.from(listeners)) listener(state
|
|
8
|
+
function emit(source) {
|
|
9
|
+
for (const listener of Array.from(listeners)) listener(state, {
|
|
10
|
+
phase: "change",
|
|
11
|
+
source
|
|
12
|
+
});
|
|
9
13
|
}
|
|
10
|
-
function set(next) {
|
|
14
|
+
function set(next, source = "unknown") {
|
|
11
15
|
if (sameHsva(state, next)) return;
|
|
12
16
|
state = next;
|
|
13
|
-
|
|
17
|
+
lastSource = source;
|
|
18
|
+
emit(source);
|
|
14
19
|
}
|
|
15
20
|
return {
|
|
16
21
|
get: () => state,
|
|
17
22
|
set,
|
|
18
|
-
patch: (partial) => set({
|
|
23
|
+
patch: (partial, source) => set({
|
|
19
24
|
...state,
|
|
20
25
|
...partial
|
|
21
|
-
}),
|
|
22
|
-
ingest: (next) => set(ingest(next, state)),
|
|
23
|
-
commit: () => {
|
|
24
|
-
for (const listener of Array.from(commitListeners)) listener(state
|
|
26
|
+
}, source),
|
|
27
|
+
ingest: (next, source) => set(ingest(next, state), source),
|
|
28
|
+
commit: (source = lastSource) => {
|
|
29
|
+
for (const listener of Array.from(commitListeners)) listener(state, {
|
|
30
|
+
phase: "commit",
|
|
31
|
+
source
|
|
32
|
+
});
|
|
25
33
|
},
|
|
26
34
|
subscribe: (listener) => {
|
|
27
35
|
listeners.add(listener);
|
package/dist/core.cjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_convert = require("./color/convert.cjs");
|
|
3
|
+
const require_css4 = require("./color/css4.cjs");
|
|
3
4
|
const require_parse = require("./color/parse.cjs");
|
|
4
5
|
const require_serialize = require("./color/serialize.cjs");
|
|
5
6
|
const require_sticky = require("./color/sticky.cjs");
|
|
6
7
|
const require_store = require("./core/store.cjs");
|
|
8
|
+
const require_value = require("./color/value.cjs");
|
|
7
9
|
exports.clamp = require_convert.clamp;
|
|
8
10
|
exports.clearNamedColors = require_parse.clearNamedColors;
|
|
11
|
+
exports.colorValueToHsva = require_css4.colorValueToHsva;
|
|
12
|
+
exports.convertColor = require_css4.convertColor;
|
|
9
13
|
exports.createColorStore = require_store.createColorStore;
|
|
10
14
|
exports.hslaToHsva = require_convert.hslaToHsva;
|
|
15
|
+
exports.hsvaToColorValue = require_css4.hsvaToColorValue;
|
|
11
16
|
exports.hsvaToHsl = require_convert.hsvaToHsl;
|
|
12
17
|
exports.hsvaToHsla = require_convert.hsvaToHsla;
|
|
13
18
|
exports.hsvaToHwba = require_convert.hsvaToHwba;
|
|
@@ -15,14 +20,19 @@ exports.hsvaToRgb = require_convert.hsvaToRgb;
|
|
|
15
20
|
exports.hsvaToRgba = require_convert.hsvaToRgba;
|
|
16
21
|
exports.hwbaToHsva = require_convert.hwbaToHsva;
|
|
17
22
|
exports.ingest = require_sticky.ingest;
|
|
23
|
+
exports.isInGamut = require_css4.isInGamut;
|
|
18
24
|
exports.isValidColor = require_parse.isValidColor;
|
|
25
|
+
exports.mapToGamut = require_css4.mapToGamut;
|
|
19
26
|
exports.normalizeHue = require_convert.normalizeHue;
|
|
20
27
|
exports.parse = require_parse.parse;
|
|
28
|
+
exports.parseColor = require_value.parseColor;
|
|
29
|
+
exports.parseCss4Color = require_css4.parseCss4Color;
|
|
21
30
|
exports.registerNamedColors = require_parse.registerNamedColors;
|
|
22
31
|
exports.rgbaToHsva = require_convert.rgbaToHsva;
|
|
23
32
|
exports.roundRgba = require_convert.roundRgba;
|
|
24
33
|
exports.sameHsva = require_sticky.sameHsva;
|
|
25
34
|
exports.sameRendered = require_sticky.sameRendered;
|
|
35
|
+
exports.serializeColor = require_css4.serializeColor;
|
|
26
36
|
exports.toFormat = require_serialize.toFormat;
|
|
27
37
|
exports.toHex = require_serialize.toHex;
|
|
28
38
|
exports.toHexa = require_serialize.toHexa;
|
package/dist/core.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ColorChangeResult, ColorFormat, Hsl, Hsla, Hsva, Hwb, Hwba, Rgb, Rgba } from "./color/types.cjs";
|
|
1
|
+
import { ColorChangeMeta, ColorChangeResult, ColorChangeSource, ColorFormat, ColorValue, Hsl, Hsla, Hsva, Hwb, Hwba, ModernColorSpace, Rgb, Rgba, SerializeColorOptions } from "./color/types.cjs";
|
|
2
2
|
import { clamp, hslaToHsva, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, normalizeHue, rgbaToHsva, roundRgba } from "./color/convert.cjs";
|
|
3
3
|
import { clearNamedColors, isValidColor, parse, registerNamedColors } from "./color/parse.cjs";
|
|
4
|
+
import { parseColor } from "./color/value.cjs";
|
|
5
|
+
import { colorValueToHsva, convertColor, hsvaToColorValue, isInGamut, mapToGamut, parseCss4Color, serializeColor } from "./color/css4.cjs";
|
|
4
6
|
import { toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString } from "./color/serialize.cjs";
|
|
5
7
|
import { ingest, sameHsva, sameRendered } from "./color/sticky.cjs";
|
|
6
8
|
import { ColorListener, ColorStore, Unsubscribe, createColorStore } from "./core/store.cjs";
|
|
7
|
-
export { ColorChangeResult, ColorFormat, type ColorListener, type ColorStore, Hsl, Hsla, Hsva, Hwb, Hwba, Rgb, Rgba, type Unsubscribe, clamp, clearNamedColors, createColorStore, hslaToHsva, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, ingest, isValidColor, normalizeHue, parse, registerNamedColors, rgbaToHsva, roundRgba, sameHsva, sameRendered, toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString };
|
|
9
|
+
export { ColorChangeMeta, ColorChangeResult, ColorChangeSource, ColorFormat, type ColorListener, type ColorStore, ColorValue, Hsl, Hsla, Hsva, Hwb, Hwba, ModernColorSpace, Rgb, Rgba, SerializeColorOptions, type Unsubscribe, clamp, clearNamedColors, colorValueToHsva, convertColor, createColorStore, hslaToHsva, hsvaToColorValue, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, ingest, isInGamut, isValidColor, mapToGamut, normalizeHue, parse, parseColor, parseCss4Color, registerNamedColors, rgbaToHsva, roundRgba, sameHsva, sameRendered, serializeColor, toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ColorChangeResult, ColorFormat, Hsl, Hsla, Hsva, Hwb, Hwba, Rgb, Rgba } from "./color/types.js";
|
|
1
|
+
import { ColorChangeMeta, ColorChangeResult, ColorChangeSource, ColorFormat, ColorValue, Hsl, Hsla, Hsva, Hwb, Hwba, ModernColorSpace, Rgb, Rgba, SerializeColorOptions } from "./color/types.js";
|
|
2
2
|
import { clamp, hslaToHsva, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, normalizeHue, rgbaToHsva, roundRgba } from "./color/convert.js";
|
|
3
3
|
import { clearNamedColors, isValidColor, parse, registerNamedColors } from "./color/parse.js";
|
|
4
|
+
import { parseColor } from "./color/value.js";
|
|
5
|
+
import { colorValueToHsva, convertColor, hsvaToColorValue, isInGamut, mapToGamut, parseCss4Color, serializeColor } from "./color/css4.js";
|
|
4
6
|
import { toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString } from "./color/serialize.js";
|
|
5
7
|
import { ingest, sameHsva, sameRendered } from "./color/sticky.js";
|
|
6
8
|
import { ColorListener, ColorStore, Unsubscribe, createColorStore } from "./core/store.js";
|
|
7
|
-
export { ColorChangeResult, ColorFormat, type ColorListener, type ColorStore, Hsl, Hsla, Hsva, Hwb, Hwba, Rgb, Rgba, type Unsubscribe, clamp, clearNamedColors, createColorStore, hslaToHsva, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, ingest, isValidColor, normalizeHue, parse, registerNamedColors, rgbaToHsva, roundRgba, sameHsva, sameRendered, toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString };
|
|
9
|
+
export { ColorChangeMeta, ColorChangeResult, ColorChangeSource, ColorFormat, type ColorListener, type ColorStore, ColorValue, Hsl, Hsla, Hsva, Hwb, Hwba, ModernColorSpace, Rgb, Rgba, SerializeColorOptions, type Unsubscribe, clamp, clearNamedColors, colorValueToHsva, convertColor, createColorStore, hslaToHsva, hsvaToColorValue, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, ingest, isInGamut, isValidColor, mapToGamut, normalizeHue, parse, parseColor, parseCss4Color, registerNamedColors, rgbaToHsva, roundRgba, sameHsva, sameRendered, serializeColor, toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString };
|
package/dist/core.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { clamp, hslaToHsva, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, normalizeHue, rgbaToHsva, roundRgba } from "./color/convert.js";
|
|
2
|
+
import { colorValueToHsva, convertColor, hsvaToColorValue, isInGamut, mapToGamut, parseCss4Color, serializeColor } from "./color/css4.js";
|
|
2
3
|
import { clearNamedColors, isValidColor, parse, registerNamedColors } from "./color/parse.js";
|
|
3
4
|
import { toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString } from "./color/serialize.js";
|
|
4
5
|
import { ingest, sameHsva, sameRendered } from "./color/sticky.js";
|
|
5
6
|
import { createColorStore } from "./core/store.js";
|
|
6
|
-
|
|
7
|
+
import { parseColor } from "./color/value.js";
|
|
8
|
+
export { clamp, clearNamedColors, colorValueToHsva, convertColor, createColorStore, hslaToHsva, hsvaToColorValue, hsvaToHsl, hsvaToHsla, hsvaToHwba, hsvaToRgb, hsvaToRgba, hwbaToHsva, ingest, isInGamut, isValidColor, mapToGamut, normalizeHue, parse, parseColor, parseCss4Color, registerNamedColors, rgbaToHsva, roundRgba, sameHsva, sameRendered, serializeColor, toFormat, toHex, toHexa, toHslString, toHslaString, toResult, toRgbString, toRgbaString };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_css4 = require("../color/css4.cjs");
|
|
2
|
+
const require_value = require("../color/value.cjs");
|
|
3
|
+
//#region src/export/tokens.ts
|
|
4
|
+
function safeName(name) {
|
|
5
|
+
return name.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "color";
|
|
6
|
+
}
|
|
7
|
+
function formatColor(color, format) {
|
|
8
|
+
if (format === "preserve") return color;
|
|
9
|
+
const parsed = require_value.parseColor(color);
|
|
10
|
+
return parsed === null ? color : require_css4.serializeColor(parsed, {
|
|
11
|
+
format,
|
|
12
|
+
gamut: format === "display-p3" ? "display-p3" : "preserve"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function toCssVariables(tokens, options = {}) {
|
|
16
|
+
const prefix = safeName(options.prefix ?? "color");
|
|
17
|
+
const format = options.format ?? "preserve";
|
|
18
|
+
const lines = Object.entries(tokens).map(([name, color]) => ` --${prefix}-${safeName(name)}: ${formatColor(color, format)};`);
|
|
19
|
+
return `${options.selector ?? ":root"} {\n${lines.join("\n")}\n}`;
|
|
20
|
+
}
|
|
21
|
+
function toScssVariables(tokens, options = {}) {
|
|
22
|
+
const prefix = safeName(options.prefix ?? "color");
|
|
23
|
+
const format = options.format ?? "preserve";
|
|
24
|
+
return Object.entries(tokens).map(([name, color]) => `$${prefix}-${safeName(name)}: ${formatColor(color, format)};`).join("\n");
|
|
25
|
+
}
|
|
26
|
+
function toTailwindColors(tokens) {
|
|
27
|
+
return Object.fromEntries(Object.entries(tokens).map(([name, color]) => [safeName(name), color]));
|
|
28
|
+
}
|
|
29
|
+
function toDesignTokens(tokens) {
|
|
30
|
+
return Object.fromEntries(Object.entries(tokens).map(([name, color]) => [safeName(name), {
|
|
31
|
+
$type: "color",
|
|
32
|
+
$value: color
|
|
33
|
+
}]));
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.toCssVariables = toCssVariables;
|
|
37
|
+
exports.toDesignTokens = toDesignTokens;
|
|
38
|
+
exports.toScssVariables = toScssVariables;
|
|
39
|
+
exports.toTailwindColors = toTailwindColors;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ModernColorSpace } from "../color/types.cjs";
|
|
2
|
+
//#region src/export/tokens.d.ts
|
|
3
|
+
export type ColorTokenMap = Record<string, string>;
|
|
4
|
+
export interface TokenExportOptions {
|
|
5
|
+
prefix?: string;
|
|
6
|
+
format?: ModernColorSpace | "preserve";
|
|
7
|
+
selector?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function toCssVariables(tokens: ColorTokenMap, options?: TokenExportOptions): string;
|
|
10
|
+
export declare function toScssVariables(tokens: ColorTokenMap, options?: Omit<TokenExportOptions, "selector">): string;
|
|
11
|
+
export declare function toTailwindColors(tokens: ColorTokenMap): Record<string, string>;
|
|
12
|
+
export declare function toDesignTokens(tokens: ColorTokenMap): Record<string, {
|
|
13
|
+
$type: "color";
|
|
14
|
+
$value: string;
|
|
15
|
+
}>;
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ModernColorSpace } from "../color/types.js";
|
|
2
|
+
//#region src/export/tokens.d.ts
|
|
3
|
+
export type ColorTokenMap = Record<string, string>;
|
|
4
|
+
export interface TokenExportOptions {
|
|
5
|
+
prefix?: string;
|
|
6
|
+
format?: ModernColorSpace | "preserve";
|
|
7
|
+
selector?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function toCssVariables(tokens: ColorTokenMap, options?: TokenExportOptions): string;
|
|
10
|
+
export declare function toScssVariables(tokens: ColorTokenMap, options?: Omit<TokenExportOptions, "selector">): string;
|
|
11
|
+
export declare function toTailwindColors(tokens: ColorTokenMap): Record<string, string>;
|
|
12
|
+
export declare function toDesignTokens(tokens: ColorTokenMap): Record<string, {
|
|
13
|
+
$type: "color";
|
|
14
|
+
$value: string;
|
|
15
|
+
}>;
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { serializeColor } from "../color/css4.js";
|
|
2
|
+
import { parseColor } from "../color/value.js";
|
|
3
|
+
//#region src/export/tokens.ts
|
|
4
|
+
function safeName(name) {
|
|
5
|
+
return name.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "color";
|
|
6
|
+
}
|
|
7
|
+
function formatColor(color, format) {
|
|
8
|
+
if (format === "preserve") return color;
|
|
9
|
+
const parsed = parseColor(color);
|
|
10
|
+
return parsed === null ? color : serializeColor(parsed, {
|
|
11
|
+
format,
|
|
12
|
+
gamut: format === "display-p3" ? "display-p3" : "preserve"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function toCssVariables(tokens, options = {}) {
|
|
16
|
+
const prefix = safeName(options.prefix ?? "color");
|
|
17
|
+
const format = options.format ?? "preserve";
|
|
18
|
+
const lines = Object.entries(tokens).map(([name, color]) => ` --${prefix}-${safeName(name)}: ${formatColor(color, format)};`);
|
|
19
|
+
return `${options.selector ?? ":root"} {\n${lines.join("\n")}\n}`;
|
|
20
|
+
}
|
|
21
|
+
function toScssVariables(tokens, options = {}) {
|
|
22
|
+
const prefix = safeName(options.prefix ?? "color");
|
|
23
|
+
const format = options.format ?? "preserve";
|
|
24
|
+
return Object.entries(tokens).map(([name, color]) => `$${prefix}-${safeName(name)}: ${formatColor(color, format)};`).join("\n");
|
|
25
|
+
}
|
|
26
|
+
function toTailwindColors(tokens) {
|
|
27
|
+
return Object.fromEntries(Object.entries(tokens).map(([name, color]) => [safeName(name), color]));
|
|
28
|
+
}
|
|
29
|
+
function toDesignTokens(tokens) {
|
|
30
|
+
return Object.fromEntries(Object.entries(tokens).map(([name, color]) => [safeName(name), {
|
|
31
|
+
$type: "color",
|
|
32
|
+
$value: color
|
|
33
|
+
}]));
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { toCssVariables, toDesignTokens, toScssVariables, toTailwindColors };
|
|
37
|
+
|
package/dist/export.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_tokens = require("./export/tokens.cjs");
|
|
3
|
+
exports.toCssVariables = require_tokens.toCssVariables;
|
|
4
|
+
exports.toDesignTokens = require_tokens.toDesignTokens;
|
|
5
|
+
exports.toScssVariables = require_tokens.toScssVariables;
|
|
6
|
+
exports.toTailwindColors = require_tokens.toTailwindColors;
|
package/dist/export.d.ts
ADDED
package/dist/export.js
ADDED