@newtonedev/editor 0.1.11 → 0.2.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/dist/Editor.d.ts.map +1 -1
- package/dist/components/CodeBlock.d.ts.map +1 -1
- package/dist/components/ConfiguratorPanel.d.ts +6 -3
- package/dist/components/ConfiguratorPanel.d.ts.map +1 -1
- package/dist/components/EditorHeader.d.ts +3 -2
- package/dist/components/EditorHeader.d.ts.map +1 -1
- package/dist/components/EditorShell.d.ts.map +1 -1
- package/dist/components/PresetSelector.d.ts +3 -2
- package/dist/components/PresetSelector.d.ts.map +1 -1
- package/dist/components/PreviewWindow.d.ts.map +1 -1
- package/dist/components/RightSidebar.d.ts.map +1 -1
- package/dist/components/Sidebar.d.ts +8 -1
- package/dist/components/Sidebar.d.ts.map +1 -1
- package/dist/components/TableOfContents.d.ts.map +1 -1
- package/dist/components/sections/ColorsSection.d.ts +6 -3
- package/dist/components/sections/ColorsSection.d.ts.map +1 -1
- package/dist/components/sections/DynamicRangeSection.d.ts +2 -2
- package/dist/components/sections/DynamicRangeSection.d.ts.map +1 -1
- package/dist/components/sections/FontsSection.d.ts +2 -2
- package/dist/components/sections/FontsSection.d.ts.map +1 -1
- package/dist/components/sections/IconsSection.d.ts +2 -2
- package/dist/components/sections/IconsSection.d.ts.map +1 -1
- package/dist/components/sections/OthersSection.d.ts +2 -2
- package/dist/components/sections/OthersSection.d.ts.map +1 -1
- package/dist/components/sections/ScalePlots.d.ts +11 -0
- package/dist/components/sections/ScalePlots.d.ts.map +1 -0
- package/dist/components/sections/index.d.ts +1 -0
- package/dist/components/sections/index.d.ts.map +1 -1
- package/dist/configurator/bridge/toCSS.d.ts +7 -0
- package/dist/configurator/bridge/toCSS.d.ts.map +1 -0
- package/dist/configurator/bridge/toJSON.d.ts +15 -0
- package/dist/configurator/bridge/toJSON.d.ts.map +1 -0
- package/dist/configurator/bridge/toThemeConfig.d.ts +8 -0
- package/dist/configurator/bridge/toThemeConfig.d.ts.map +1 -0
- package/dist/configurator/constants.d.ts +13 -0
- package/dist/configurator/constants.d.ts.map +1 -0
- package/dist/configurator/hex-conversion.d.ts +21 -0
- package/dist/configurator/hex-conversion.d.ts.map +1 -0
- package/dist/configurator/hooks/useConfigurator.d.ts +11 -0
- package/dist/configurator/hooks/useConfigurator.d.ts.map +1 -0
- package/dist/configurator/hooks/usePreviewColors.d.ts +8 -0
- package/dist/configurator/hooks/usePreviewColors.d.ts.map +1 -0
- package/dist/configurator/hooks/useWcagValidation.d.ts +20 -0
- package/dist/configurator/hooks/useWcagValidation.d.ts.map +1 -0
- package/dist/configurator/hue-conversion.d.ts +10 -0
- package/dist/configurator/hue-conversion.d.ts.map +1 -0
- package/dist/configurator/state/actions.d.ts +107 -0
- package/dist/configurator/state/actions.d.ts.map +1 -0
- package/dist/configurator/state/defaults.d.ts +7 -0
- package/dist/configurator/state/defaults.d.ts.map +1 -0
- package/dist/configurator/state/reducer.d.ts +19 -0
- package/dist/configurator/state/reducer.d.ts.map +1 -0
- package/dist/configurator/types.d.ts +60 -0
- package/dist/configurator/types.d.ts.map +1 -0
- package/dist/hooks/useEditorState.d.ts +8 -6
- package/dist/hooks/useEditorState.d.ts.map +1 -1
- package/dist/hooks/usePresets.d.ts +7 -6
- package/dist/hooks/usePresets.d.ts.map +1 -1
- package/dist/index.cjs +30380 -828
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30359 -819
- package/dist/index.js.map +1 -1
- package/dist/preview/CategoryView.d.ts.map +1 -1
- package/dist/preview/ComponentDetailView.d.ts.map +1 -1
- package/dist/preview/ComponentRenderer.d.ts.map +1 -1
- package/dist/preview/IconBrowserView.d.ts.map +1 -1
- package/dist/preview/OverviewView.d.ts.map +1 -1
- package/dist/preview/PaletteScaleView.d.ts +11 -0
- package/dist/preview/PaletteScaleView.d.ts.map +1 -0
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -4
- package/src/Editor.tsx +43 -19
- package/src/components/CodeBlock.tsx +7 -11
- package/src/components/ConfiguratorPanel.tsx +25 -18
- package/src/components/EditorHeader.tsx +29 -39
- package/src/components/EditorShell.tsx +17 -29
- package/src/components/FontPicker.tsx +7 -7
- package/src/components/PresetSelector.tsx +211 -129
- package/src/components/PreviewWindow.tsx +5 -12
- package/src/components/PrimaryNav.tsx +6 -6
- package/src/components/RightSidebar.tsx +24 -25
- package/src/components/Sidebar.tsx +54 -60
- package/src/components/TableOfContents.tsx +4 -5
- package/src/components/sections/ColorsSection.tsx +118 -147
- package/src/components/sections/DynamicRangeSection.tsx +61 -75
- package/src/components/sections/FontsSection.tsx +17 -28
- package/src/components/sections/IconsSection.tsx +2 -2
- package/src/components/sections/OthersSection.tsx +4 -5
- package/src/components/sections/ScalePlots.tsx +221 -0
- package/src/components/sections/index.ts +1 -0
- package/src/configurator/bridge/toCSS.ts +44 -0
- package/src/configurator/bridge/toJSON.ts +24 -0
- package/src/configurator/bridge/toThemeConfig.ts +114 -0
- package/src/configurator/constants.ts +13 -0
- package/src/configurator/hex-conversion.ts +67 -0
- package/src/configurator/hooks/useConfigurator.ts +33 -0
- package/src/configurator/hooks/usePreviewColors.ts +47 -0
- package/src/configurator/hooks/useWcagValidation.ts +133 -0
- package/src/configurator/hue-conversion.ts +25 -0
- package/src/configurator/state/actions.ts +43 -0
- package/src/configurator/state/defaults.ts +107 -0
- package/src/configurator/state/reducer.ts +399 -0
- package/src/configurator/types.ts +65 -0
- package/src/hooks/useEditorState.ts +25 -11
- package/src/hooks/usePresets.ts +54 -33
- package/src/index.ts +33 -0
- package/src/preview/CategoryView.tsx +8 -11
- package/src/preview/ComponentDetailView.tsx +24 -54
- package/src/preview/ComponentRenderer.tsx +2 -4
- package/src/preview/IconBrowserView.tsx +9 -10
- package/src/preview/OverviewView.tsx +9 -12
- package/src/preview/PaletteScaleView.tsx +122 -0
- package/src/types.ts +4 -3
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useTokens } from "@newtonedev/components";
|
|
2
|
-
import { srgbToHex } from "newtone";
|
|
3
2
|
import { CATEGORIES, getComponentsByCategory } from "@newtonedev/components";
|
|
4
3
|
import { ComponentRenderer } from "./ComponentRenderer";
|
|
5
4
|
import { useHover } from "../hooks/useHover";
|
|
@@ -21,7 +20,7 @@ export function OverviewView({
|
|
|
21
20
|
style={{
|
|
22
21
|
fontSize: 22,
|
|
23
22
|
fontWeight: 700,
|
|
24
|
-
color:
|
|
23
|
+
color: tokens.colors.primary.main.fontPrimary,
|
|
25
24
|
margin: 0,
|
|
26
25
|
marginBottom: 4,
|
|
27
26
|
}}
|
|
@@ -31,7 +30,7 @@ export function OverviewView({
|
|
|
31
30
|
<p
|
|
32
31
|
style={{
|
|
33
32
|
fontSize: 14,
|
|
34
|
-
color:
|
|
33
|
+
color: tokens.colors.primary.main.fontTertiary,
|
|
35
34
|
margin: 0,
|
|
36
35
|
marginBottom: 32,
|
|
37
36
|
}}
|
|
@@ -61,7 +60,7 @@ export function OverviewView({
|
|
|
61
60
|
style={{
|
|
62
61
|
fontSize: 16,
|
|
63
62
|
fontWeight: 600,
|
|
64
|
-
color:
|
|
63
|
+
color: tokens.colors.primary.main.fontPrimary,
|
|
65
64
|
}}
|
|
66
65
|
>
|
|
67
66
|
{category.name}
|
|
@@ -69,7 +68,7 @@ export function OverviewView({
|
|
|
69
68
|
<span
|
|
70
69
|
style={{
|
|
71
70
|
fontSize: 13,
|
|
72
|
-
color:
|
|
71
|
+
color: tokens.colors.primary.main.fontTertiary,
|
|
73
72
|
marginLeft: 8,
|
|
74
73
|
}}
|
|
75
74
|
>
|
|
@@ -127,10 +126,8 @@ function ComponentCard({
|
|
|
127
126
|
flexDirection: "column",
|
|
128
127
|
padding: 20,
|
|
129
128
|
borderRadius: 12,
|
|
130
|
-
border: `1px solid ${
|
|
131
|
-
|
|
132
|
-
)}`,
|
|
133
|
-
backgroundColor: srgbToHex(tokens.backgroundElevated.srgb),
|
|
129
|
+
border: `1px solid ${isHovered ? tokens.colors.secondary.emphasis.fontPrimary : tokens.colors.primary.main.fontDisabled}`,
|
|
130
|
+
backgroundColor: tokens.colors.primary.main.divider,
|
|
134
131
|
cursor: "pointer",
|
|
135
132
|
textAlign: "left",
|
|
136
133
|
transform: isHovered ? "translateY(-1px)" : "none",
|
|
@@ -147,7 +144,7 @@ function ComponentCard({
|
|
|
147
144
|
padding: 16,
|
|
148
145
|
marginBottom: 16,
|
|
149
146
|
borderRadius: 8,
|
|
150
|
-
backgroundColor:
|
|
147
|
+
backgroundColor: tokens.colors.primary.main.background,
|
|
151
148
|
minHeight: 60,
|
|
152
149
|
}}
|
|
153
150
|
>
|
|
@@ -157,7 +154,7 @@ function ComponentCard({
|
|
|
157
154
|
style={{
|
|
158
155
|
fontSize: 14,
|
|
159
156
|
fontWeight: 600,
|
|
160
|
-
color:
|
|
157
|
+
color: tokens.colors.primary.main.fontPrimary,
|
|
161
158
|
marginBottom: 4,
|
|
162
159
|
}}
|
|
163
160
|
>
|
|
@@ -166,7 +163,7 @@ function ComponentCard({
|
|
|
166
163
|
<span
|
|
167
164
|
style={{
|
|
168
165
|
fontSize: 12,
|
|
169
|
-
color:
|
|
166
|
+
color: tokens.colors.primary.main.fontTertiary,
|
|
170
167
|
lineHeight: 1.4,
|
|
171
168
|
}}
|
|
172
169
|
>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { srgbToHex } from "newtone";
|
|
3
|
+
import type { ColorResult } from "newtone";
|
|
4
|
+
import { oklchToP3 } from "@newtonedev/colors";
|
|
5
|
+
import { useNewtoneTheme } from "@newtonedev/components";
|
|
6
|
+
import type { ConfiguratorState } from "../configurator/types";
|
|
7
|
+
|
|
8
|
+
interface PaletteScaleViewProps {
|
|
9
|
+
readonly state: ConfiguratorState;
|
|
10
|
+
readonly previewColors: readonly (readonly ColorResult[])[];
|
|
11
|
+
readonly useP3: boolean;
|
|
12
|
+
readonly onUseP3Change: (useP3: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function colorToCss(color: ColorResult, useP3: boolean): string {
|
|
16
|
+
if (!useP3) return srgbToHex(color.srgb);
|
|
17
|
+
const p3 = oklchToP3(color.oklch);
|
|
18
|
+
const r = Math.max(0, Math.min(1, p3.r));
|
|
19
|
+
const g = Math.max(0, Math.min(1, p3.g));
|
|
20
|
+
const b = Math.max(0, Math.min(1, p3.b));
|
|
21
|
+
return `color(display-p3 ${r.toFixed(5)} ${g.toFixed(5)} ${b.toFixed(5)})`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function PaletteScaleView({ state, previewColors, useP3, onUseP3Change }: PaletteScaleViewProps) {
|
|
25
|
+
const { gamut } = useNewtoneTheme();
|
|
26
|
+
const deviceSupportsP3 = gamut === "p3";
|
|
27
|
+
const primary = previewColors[0];
|
|
28
|
+
const lightBg = primary ? colorToCss(primary[0], useP3) : "#ffffff";
|
|
29
|
+
const darkBg = primary ? colorToCss(primary[primary.length - 1], useP3) : "#000000";
|
|
30
|
+
|
|
31
|
+
const [hovered, setHovered] = useState(false);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div
|
|
35
|
+
style={{
|
|
36
|
+
position: "relative",
|
|
37
|
+
display: "flex",
|
|
38
|
+
flexDirection: "column",
|
|
39
|
+
flex: 1,
|
|
40
|
+
background: `linear-gradient(to right, ${lightBg} 50%, ${darkBg} 50%)`,
|
|
41
|
+
padding: 48,
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
{/* sRGB/P3 Gamut Toggle */}
|
|
45
|
+
<div
|
|
46
|
+
style={{
|
|
47
|
+
position: "absolute",
|
|
48
|
+
top: 12,
|
|
49
|
+
right: 12,
|
|
50
|
+
display: "flex",
|
|
51
|
+
alignItems: "center",
|
|
52
|
+
gap: 8,
|
|
53
|
+
zIndex: 1,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{!deviceSupportsP3 && (
|
|
57
|
+
<span
|
|
58
|
+
style={{
|
|
59
|
+
fontSize: 11,
|
|
60
|
+
color: "rgba(255,255,255,0.6)",
|
|
61
|
+
whiteSpace: "nowrap",
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
P3 not available on this display
|
|
65
|
+
</span>
|
|
66
|
+
)}
|
|
67
|
+
<button
|
|
68
|
+
onClick={deviceSupportsP3 ? () => onUseP3Change(!useP3) : undefined}
|
|
69
|
+
onMouseEnter={() => setHovered(true)}
|
|
70
|
+
onMouseLeave={() => setHovered(false)}
|
|
71
|
+
aria-label={
|
|
72
|
+
!deviceSupportsP3
|
|
73
|
+
? "Display P3 not supported on this display"
|
|
74
|
+
: useP3
|
|
75
|
+
? "Switch to sRGB"
|
|
76
|
+
: "Switch to Display P3"
|
|
77
|
+
}
|
|
78
|
+
aria-disabled={!deviceSupportsP3}
|
|
79
|
+
style={{
|
|
80
|
+
display: "flex",
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
padding: "4px 10px",
|
|
83
|
+
borderRadius: 6,
|
|
84
|
+
border: "1px solid rgba(255,255,255,0.3)",
|
|
85
|
+
background: hovered && deviceSupportsP3 ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.3)",
|
|
86
|
+
cursor: deviceSupportsP3 ? "pointer" : "default",
|
|
87
|
+
fontSize: 12,
|
|
88
|
+
fontWeight: 500,
|
|
89
|
+
color: deviceSupportsP3 ? "#fff" : "rgba(255,255,255,0.4)",
|
|
90
|
+
transition: "background-color 150ms ease",
|
|
91
|
+
opacity: deviceSupportsP3 ? 1 : 0.7,
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{deviceSupportsP3 ? (useP3 ? "P3" : "sRGB") : "sRGB"}
|
|
95
|
+
</button>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
{state.palettes.map((_palette, index) => {
|
|
99
|
+
const scale = previewColors[index];
|
|
100
|
+
if (!scale || scale.length === 0) return null;
|
|
101
|
+
|
|
102
|
+
const trimmed = scale.slice(1, -1);
|
|
103
|
+
if (trimmed.length === 0) return null;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div key={index} style={{ display: "flex", flex: 1 }}>
|
|
107
|
+
{trimmed.map((color, i) => (
|
|
108
|
+
<div
|
|
109
|
+
key={i}
|
|
110
|
+
title={srgbToHex(color.srgb)}
|
|
111
|
+
style={{
|
|
112
|
+
flex: 1,
|
|
113
|
+
backgroundColor: colorToCss(color, useP3),
|
|
114
|
+
}}
|
|
115
|
+
/>
|
|
116
|
+
))}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
})}
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConfiguratorState } from "
|
|
1
|
+
import type { ConfiguratorState } from "./configurator/types";
|
|
2
2
|
import type { NewtoneThemeConfig } from "@newtonedev/components";
|
|
3
3
|
import type { FontRuntimeMetrics, GoogleFontEntry } from "@newtonedev/fonts";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
@@ -47,11 +47,12 @@ export interface EditorPersistence {
|
|
|
47
47
|
readonly presets: readonly Preset[];
|
|
48
48
|
}) => Promise<{ error?: unknown }>;
|
|
49
49
|
|
|
50
|
-
/** Publish
|
|
50
|
+
/** Publish all presets as variants. */
|
|
51
51
|
readonly onPublish: (params: {
|
|
52
52
|
readonly state: ConfiguratorState;
|
|
53
53
|
readonly presets: readonly Preset[];
|
|
54
54
|
readonly activePresetId: string;
|
|
55
|
+
readonly defaultVariantId: string;
|
|
55
56
|
readonly calibrations?: Record<string, number>;
|
|
56
57
|
readonly fontMetrics?: Record<string, FontRuntimeMetrics>;
|
|
57
58
|
}) => Promise<{ error?: unknown }>;
|
|
@@ -60,7 +61,7 @@ export interface EditorPersistence {
|
|
|
60
61
|
readonly persistPresets: (params: {
|
|
61
62
|
readonly presets: readonly Preset[];
|
|
62
63
|
readonly activePresetId: string;
|
|
63
|
-
readonly
|
|
64
|
+
readonly defaultVariantId: string | null;
|
|
64
65
|
}) => Promise<void>;
|
|
65
66
|
}
|
|
66
67
|
|