@pixel-point/toolcraft 0.0.2
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.md +98 -0
- package/README.md +41 -0
- package/bin/create-toolcraft-app.mjs +8 -0
- package/bin/toolcraft.mjs +8 -0
- package/package.json +24 -0
- package/scripts/prepare-pack.mjs +29 -0
- package/src/cli.mjs +392 -0
- package/src/cli.test.mjs +284 -0
- package/src/copy-recursive.mjs +86 -0
- package/src/generate.mjs +212 -0
- package/src/generate.test.mjs +322 -0
- package/src/import-map.mjs +14 -0
- package/src/package-json.mjs +80 -0
- package/src/package-json.test.mjs +67 -0
- package/src/rewrite-imports.mjs +85 -0
- package/src/rewrite-imports.test.mjs +58 -0
- package/templates/runtime/contracts/component-contracts.test.ts +1165 -0
- package/templates/runtime/contracts/component-contracts.ts +1340 -0
- package/templates/runtime/contracts/decision-contracts.test.ts +206 -0
- package/templates/runtime/contracts/decision-contracts.ts +283 -0
- package/templates/runtime/contracts/index.test.ts +14 -0
- package/templates/runtime/contracts/index.ts +3 -0
- package/templates/runtime/contracts/types.ts +56 -0
- package/templates/runtime/export/export.test.ts +203 -0
- package/templates/runtime/export/export.ts +132 -0
- package/templates/runtime/export/index.ts +1 -0
- package/templates/runtime/index.ts +14 -0
- package/templates/runtime/react/canvas-shell.test.tsx +424 -0
- package/templates/runtime/react/canvas-shell.tsx +408 -0
- package/templates/runtime/react/control-renderers.ts +31 -0
- package/templates/runtime/react/controls-panel.test.tsx +3736 -0
- package/templates/runtime/react/controls-panel.tsx +2327 -0
- package/templates/runtime/react/curve-geometry.test.ts +70 -0
- package/templates/runtime/react/index.ts +15 -0
- package/templates/runtime/react/layer-tree.ts +96 -0
- package/templates/runtime/react/layers-panel.test.tsx +487 -0
- package/templates/runtime/react/layers-panel.tsx +1348 -0
- package/templates/runtime/react/media-file.ts +82 -0
- package/templates/runtime/react/panel-host-config.ts +80 -0
- package/templates/runtime/react/panel-host-geometry.test.ts +66 -0
- package/templates/runtime/react/panel-host-geometry.ts +109 -0
- package/templates/runtime/react/panel-host-types.ts +74 -0
- package/templates/runtime/react/panel-host.test.tsx +102 -0
- package/templates/runtime/react/panel-host.tsx +353 -0
- package/templates/runtime/react/runtime-public-api.test.tsx +132 -0
- package/templates/runtime/react/settings-transfer.test.ts +150 -0
- package/templates/runtime/react/settings-transfer.ts +279 -0
- package/templates/runtime/react/storage-key-migration.ts +48 -0
- package/templates/runtime/react/theme-runtime.tsx +177 -0
- package/templates/runtime/react/timeline-panel.test.tsx +668 -0
- package/templates/runtime/react/timeline-panel.tsx +2953 -0
- package/templates/runtime/react/toolbar-panel.test.tsx +212 -0
- package/templates/runtime/react/toolbar-panel.tsx +205 -0
- package/templates/runtime/react/toolcraft-app.integration.test.tsx +350 -0
- package/templates/runtime/react/toolcraft-app.test.tsx +339 -0
- package/templates/runtime/react/toolcraft-app.tsx +81 -0
- package/templates/runtime/react/toolcraft-root.test.tsx +347 -0
- package/templates/runtime/react/toolcraft-root.tsx +203 -0
- package/templates/runtime/react/use-toolcraft.ts +41 -0
- package/templates/runtime/schema/define-toolcraft.test.ts +1524 -0
- package/templates/runtime/schema/define-toolcraft.ts +1442 -0
- package/templates/runtime/schema/keyframe-capability.test.ts +90 -0
- package/templates/runtime/schema/keyframe-capability.ts +51 -0
- package/templates/runtime/schema/runtime-targets.ts +40 -0
- package/templates/runtime/schema/types.ts +370 -0
- package/templates/runtime/state/canvas-zoom.ts +8 -0
- package/templates/runtime/state/create-template-state.test.ts +242 -0
- package/templates/runtime/state/create-template-state.ts +95 -0
- package/templates/runtime/state/keyframe-evaluation.test.ts +141 -0
- package/templates/runtime/state/keyframe-evaluation.ts +203 -0
- package/templates/runtime/state/persistence.test.ts +217 -0
- package/templates/runtime/state/persistence.ts +511 -0
- package/templates/runtime/state/reducer.test.ts +937 -0
- package/templates/runtime/state/reducer.ts +1212 -0
- package/templates/runtime/state/timeline-readiness.ts +43 -0
- package/templates/runtime/state/types.ts +242 -0
- package/templates/runtime/styles.css +125 -0
- package/templates/runtime/testing/performance.test.ts +1058 -0
- package/templates/runtime/testing/performance.ts +1078 -0
- package/templates/starter/AGENTS.md +186 -0
- package/templates/starter/LICENSE.md +98 -0
- package/templates/starter/NOTICE.md +8 -0
- package/templates/starter/docs/toolcraft/README.md +41 -0
- package/templates/starter/docs/toolcraft/acceptance-testing.md +205 -0
- package/templates/starter/docs/toolcraft/agent-worklog.md +81 -0
- package/templates/starter/docs/toolcraft/assembly-workflow.md +206 -0
- package/templates/starter/docs/toolcraft/component-rules.md +299 -0
- package/templates/starter/docs/toolcraft/custom-controls.md +71 -0
- package/templates/starter/docs/toolcraft/decision-contract.md +71 -0
- package/templates/starter/docs/toolcraft/performance.md +112 -0
- package/templates/starter/docs/toolcraft/renderer-technique.md +48 -0
- package/templates/starter/docs/toolcraft/schema-reference.md +265 -0
- package/templates/starter/docs/toolcraft/workflow.md +87 -0
- package/templates/starter/e2e/app-browser-acceptance.spec.ts +785 -0
- package/templates/starter/e2e/app-controls.spec.ts +41 -0
- package/templates/starter/e2e/app-performance.spec.ts +326 -0
- package/templates/starter/e2e/canvas-handle-helpers.ts +244 -0
- package/templates/starter/e2e/performance-helpers.ts +612 -0
- package/templates/starter/e2e/product-observable-helpers.ts +170 -0
- package/templates/starter/index.html +12 -0
- package/templates/starter/package.json +52 -0
- package/templates/starter/playwright.config.ts +43 -0
- package/templates/starter/scripts/check-ai-skills.mjs +95 -0
- package/templates/starter/scripts/check-toolcraft-docs.mjs +159 -0
- package/templates/starter/scripts/check-toolcraft-integrity.mjs +232 -0
- package/templates/starter/scripts/run-vite-on-free-port.mjs +48 -0
- package/templates/starter/scripts/toolcraft-port.mjs +54 -0
- package/templates/starter/scripts/toolcraft-port.test.mjs +73 -0
- package/templates/starter/src/app/starter-acceptance.test.ts +5959 -0
- package/templates/starter/src/app/starter-acceptance.ts +2646 -0
- package/templates/starter/src/app/starter-performance.test.ts +1390 -0
- package/templates/starter/src/app/starter-performance.ts +12 -0
- package/templates/starter/src/app/starter-schema.test.ts +70 -0
- package/templates/starter/src/app/starter-schema.ts +15 -0
- package/templates/starter/src/main.tsx +18 -0
- package/templates/starter/src/router.tsx +16 -0
- package/templates/starter/src/routes/index.tsx +7 -0
- package/templates/starter/src/routes/root.tsx +19 -0
- package/templates/starter/src/styles.css +120 -0
- package/templates/starter/tsconfig.json +11 -0
- package/templates/starter/vite.config.ts +13 -0
- package/templates/ui/components/composites/accordion.tsx +73 -0
- package/templates/ui/components/composites/alert-dialog.tsx +190 -0
- package/templates/ui/components/composites/alert.tsx +74 -0
- package/templates/ui/components/composites/aspect-ratio.tsx +22 -0
- package/templates/ui/components/composites/avatar.tsx +98 -0
- package/templates/ui/components/composites/badge.tsx +69 -0
- package/templates/ui/components/composites/breadcrumb.tsx +106 -0
- package/templates/ui/components/composites/card.tsx +91 -0
- package/templates/ui/components/composites/combobox.tsx +486 -0
- package/templates/ui/components/composites/command.tsx +296 -0
- package/templates/ui/components/composites/context-menu.tsx +247 -0
- package/templates/ui/components/composites/dialog.tsx +282 -0
- package/templates/ui/components/composites/dropdown-menu.tsx +299 -0
- package/templates/ui/components/composites/empty.tsx +110 -0
- package/templates/ui/components/composites/hover-card.tsx +44 -0
- package/templates/ui/components/composites/index.ts +30 -0
- package/templates/ui/components/composites/menubar.tsx +214 -0
- package/templates/ui/components/composites/navigation-menu.tsx +167 -0
- package/templates/ui/components/composites/pagination.tsx +131 -0
- package/templates/ui/components/composites/progress.tsx +72 -0
- package/templates/ui/components/composites/radio-group.tsx +84 -0
- package/templates/ui/components/composites/resizable.tsx +42 -0
- package/templates/ui/components/composites/sheet.tsx +153 -0
- package/templates/ui/components/composites/sidebar-structural.tsx +310 -0
- package/templates/ui/components/composites/sidebar.tsx +431 -0
- package/templates/ui/components/composites/sonner.tsx +35 -0
- package/templates/ui/components/composites/spinner.tsx +43 -0
- package/templates/ui/components/composites/table.tsx +108 -0
- package/templates/ui/components/composites/tabs.tsx +83 -0
- package/templates/ui/components/control-layout/index.tsx +437 -0
- package/templates/ui/components/controls/actions/actions-control.tsx +139 -0
- package/templates/ui/components/controls/actions/index.ts +9 -0
- package/templates/ui/components/controls/anchor-grid/anchor-grid-control.tsx +107 -0
- package/templates/ui/components/controls/anchor-grid/index.ts +4 -0
- package/templates/ui/components/controls/boolean/boolean-controls.tsx +79 -0
- package/templates/ui/components/controls/boolean/index.ts +4 -0
- package/templates/ui/components/controls/channel-mixer/channel-mixer-control.tsx +95 -0
- package/templates/ui/components/controls/channel-mixer/index.ts +4 -0
- package/templates/ui/components/controls/channel-tabs/channel-tabs.tsx +42 -0
- package/templates/ui/components/controls/channel-tabs/index.ts +6 -0
- package/templates/ui/components/controls/code-textarea/code-textarea-control.tsx +90 -0
- package/templates/ui/components/controls/code-textarea/index.ts +4 -0
- package/templates/ui/components/controls/color/color-control.tsx +571 -0
- package/templates/ui/components/controls/color/color-picker-popover.tsx +104 -0
- package/templates/ui/components/controls/color/index.ts +41 -0
- package/templates/ui/components/controls/color/palette-control-data.ts +436 -0
- package/templates/ui/components/controls/color/palette-control.tsx +535 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-channel-utils.ts +162 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-interactions.ts +190 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-logic.ts +485 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-parts.tsx +710 -0
- package/templates/ui/components/controls/color/style-guide-color-picker.tsx +503 -0
- package/templates/ui/components/controls/control-types.ts +43 -0
- package/templates/ui/components/controls/curves/curve-geometry.ts +355 -0
- package/templates/ui/components/controls/curves/curve-graph.tsx +390 -0
- package/templates/ui/components/controls/curves/curves-control.tsx +445 -0
- package/templates/ui/components/controls/curves/index.ts +6 -0
- package/templates/ui/components/controls/file-drop/file-drop-control.tsx +191 -0
- package/templates/ui/components/controls/file-drop/index.ts +5 -0
- package/templates/ui/components/controls/font-picker/font-catalog.json +15360 -0
- package/templates/ui/components/controls/font-picker/font-catalog.ts +116 -0
- package/templates/ui/components/controls/font-picker/font-picker-control.tsx +1202 -0
- package/templates/ui/components/controls/font-picker/font-preview-loader.ts +336 -0
- package/templates/ui/components/controls/font-picker/index.ts +24 -0
- package/templates/ui/components/controls/font-picker/use-hover-intent.ts +46 -0
- package/templates/ui/components/controls/gradient/gradient-control-utils.ts +190 -0
- package/templates/ui/components/controls/gradient/gradient-control.tsx +612 -0
- package/templates/ui/components/controls/gradient/gradient-stop-list.tsx +400 -0
- package/templates/ui/components/controls/gradient/gradient-toolbar.tsx +152 -0
- package/templates/ui/components/controls/gradient/index.ts +4 -0
- package/templates/ui/components/controls/image-picker/image-picker-control.tsx +139 -0
- package/templates/ui/components/controls/image-picker/index.ts +7 -0
- package/templates/ui/components/controls/index.ts +192 -0
- package/templates/ui/components/controls/range-input/index.ts +4 -0
- package/templates/ui/components/controls/range-input/range-input-control.tsx +173 -0
- package/templates/ui/components/controls/range-slider/index.ts +4 -0
- package/templates/ui/components/controls/range-slider/range-slider-control.tsx +122 -0
- package/templates/ui/components/controls/range-slider/range-slider-value.ts +61 -0
- package/templates/ui/components/controls/segmented/index.ts +8 -0
- package/templates/ui/components/controls/segmented/segmented-control.tsx +94 -0
- package/templates/ui/components/controls/select/index.ts +4 -0
- package/templates/ui/components/controls/select/select-control.tsx +223 -0
- package/templates/ui/components/controls/slider/index.ts +4 -0
- package/templates/ui/components/controls/slider/slider-control.tsx +150 -0
- package/templates/ui/components/controls/slider/slider-value.ts +56 -0
- package/templates/ui/components/controls/text-input/index.ts +4 -0
- package/templates/ui/components/controls/text-input/text-input-control.tsx +158 -0
- package/templates/ui/components/controls/use-measured-element-width.ts +42 -0
- package/templates/ui/components/controls/vector/index.ts +8 -0
- package/templates/ui/components/controls/vector/vector-control.tsx +401 -0
- package/templates/ui/components/panel/index.ts +19 -0
- package/templates/ui/components/panel/panel-actions.tsx +165 -0
- package/templates/ui/components/panel/panel-header.tsx +61 -0
- package/templates/ui/components/panel/panel-icon-button.tsx +96 -0
- package/templates/ui/components/panel/panel-section.tsx +168 -0
- package/templates/ui/components/panel/panel-surface.tsx +206 -0
- package/templates/ui/components/panel/panel.tsx +210 -0
- package/templates/ui/components/primitives/animated-loader.tsx +61 -0
- package/templates/ui/components/primitives/button-group.tsx +134 -0
- package/templates/ui/components/primitives/button.tsx +429 -0
- package/templates/ui/components/primitives/checkbox.tsx +62 -0
- package/templates/ui/components/primitives/editable-slider-value-label.tsx +337 -0
- package/templates/ui/components/primitives/field.tsx +225 -0
- package/templates/ui/components/primitives/index.ts +82 -0
- package/templates/ui/components/primitives/input-group.tsx +298 -0
- package/templates/ui/components/primitives/input.tsx +61 -0
- package/templates/ui/components/primitives/internal/button-loading.tsx +178 -0
- package/templates/ui/components/primitives/label.tsx +16 -0
- package/templates/ui/components/primitives/popover.tsx +126 -0
- package/templates/ui/components/primitives/portal-layer-context.tsx +33 -0
- package/templates/ui/components/primitives/primitive-arrow-icon.tsx +38 -0
- package/templates/ui/components/primitives/scroll-fade-logic.ts +441 -0
- package/templates/ui/components/primitives/scroll-fade-render.tsx +75 -0
- package/templates/ui/components/primitives/scroll-fade-types.ts +41 -0
- package/templates/ui/components/primitives/scroll-fade.tsx +72 -0
- package/templates/ui/components/primitives/select.tsx +408 -0
- package/templates/ui/components/primitives/selection-state.ts +31 -0
- package/templates/ui/components/primitives/separator.tsx +21 -0
- package/templates/ui/components/primitives/slider/index.ts +4 -0
- package/templates/ui/components/primitives/slider/slider-interaction.tsx +96 -0
- package/templates/ui/components/primitives/slider/slider-parts.tsx +303 -0
- package/templates/ui/components/primitives/slider/slider-reset.ts +152 -0
- package/templates/ui/components/primitives/slider/slider-value.ts +114 -0
- package/templates/ui/components/primitives/slider/slider.tsx +511 -0
- package/templates/ui/components/primitives/switch.tsx +35 -0
- package/templates/ui/components/primitives/textarea.tsx +49 -0
- package/templates/ui/components/primitives/toggle-group.tsx +114 -0
- package/templates/ui/components/primitives/toggle.tsx +46 -0
- package/templates/ui/components/primitives/tooltip.tsx +100 -0
- package/templates/ui/hooks/use-mobile.ts +21 -0
- package/templates/ui/index.ts +31 -0
- package/templates/ui/lib/control-outline.ts +3 -0
- package/templates/ui/lib/input-control-style.ts +131 -0
- package/templates/ui/lib/style-guide-color-utils.ts +111 -0
- package/templates/ui/lib/utils.ts +6 -0
- package/templates/ui/styles.css +291 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { useId } from "react";
|
|
2
|
+
|
|
3
|
+
import type { CurveChannel, CurvePoint } from "../control-types";
|
|
4
|
+
import {
|
|
5
|
+
ChannelTabs as SharedChannelTabs,
|
|
6
|
+
channelMeta as sharedChannelMeta,
|
|
7
|
+
} from "../channel-tabs";
|
|
8
|
+
import {
|
|
9
|
+
type CurveInterpolation,
|
|
10
|
+
curveGraphMax,
|
|
11
|
+
curveGraphSize,
|
|
12
|
+
curveGridStops,
|
|
13
|
+
curveInset,
|
|
14
|
+
defaultCurveInterpolation,
|
|
15
|
+
getCurvePath,
|
|
16
|
+
mapPointToSvg,
|
|
17
|
+
normalizeCurvePoints,
|
|
18
|
+
} from "./curve-geometry";
|
|
19
|
+
|
|
20
|
+
export const curveChannels = [
|
|
21
|
+
"RGB",
|
|
22
|
+
"R",
|
|
23
|
+
"G",
|
|
24
|
+
"B",
|
|
25
|
+
] as const satisfies readonly CurveChannel[];
|
|
26
|
+
export const singleCurveChannels = ["RGB"] as const satisfies readonly CurveChannel[];
|
|
27
|
+
export const channelMeta = sharedChannelMeta;
|
|
28
|
+
const curveGraphRadius = 6;
|
|
29
|
+
const curvePointHandleViewportSize = 20;
|
|
30
|
+
const curvePointHandleViewportRadius = curvePointHandleViewportSize / 2;
|
|
31
|
+
|
|
32
|
+
export function ChannelTabs({
|
|
33
|
+
name,
|
|
34
|
+
onValueChange,
|
|
35
|
+
value,
|
|
36
|
+
}: {
|
|
37
|
+
name: string;
|
|
38
|
+
onValueChange: (value: CurveChannel) => void;
|
|
39
|
+
value: CurveChannel;
|
|
40
|
+
}): React.JSX.Element {
|
|
41
|
+
return (
|
|
42
|
+
<SharedChannelTabs
|
|
43
|
+
ariaLabel={name}
|
|
44
|
+
channels={curveChannels}
|
|
45
|
+
name={name}
|
|
46
|
+
onValueChange={onValueChange}
|
|
47
|
+
value={value}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function CurveGraph({
|
|
53
|
+
activeChannel,
|
|
54
|
+
activePoints,
|
|
55
|
+
ariaLabel = "Color curves editor",
|
|
56
|
+
channels = curveChannels,
|
|
57
|
+
draggingPointIndex,
|
|
58
|
+
graphRef,
|
|
59
|
+
interpolation = defaultCurveInterpolation,
|
|
60
|
+
onBackgroundPointerDown,
|
|
61
|
+
onPointDoubleClick,
|
|
62
|
+
onPointKeyDown,
|
|
63
|
+
onPointPointerDown,
|
|
64
|
+
onPointPointerUp,
|
|
65
|
+
points,
|
|
66
|
+
selectedPointIndex,
|
|
67
|
+
}: CurveGraphProps): React.JSX.Element {
|
|
68
|
+
const clipPathId = `curve-graph-${useId().replaceAll(":", "")}`;
|
|
69
|
+
const showReferenceLine = shouldShowReferenceLine(points, channels);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<svg
|
|
73
|
+
aria-label={ariaLabel}
|
|
74
|
+
className="app-no-drag group/curve-graph block aspect-square w-full overflow-visible select-none"
|
|
75
|
+
ref={graphRef}
|
|
76
|
+
role="img"
|
|
77
|
+
style={{ overflow: "visible", touchAction: "none" }}
|
|
78
|
+
viewBox={`${curveInset} ${curveInset} ${curveGraphSize} ${curveGraphSize}`}
|
|
79
|
+
>
|
|
80
|
+
<defs>
|
|
81
|
+
<clipPath id={clipPathId}>
|
|
82
|
+
<rect
|
|
83
|
+
height={curveGraphSize}
|
|
84
|
+
rx={curveGraphRadius}
|
|
85
|
+
width={curveGraphSize}
|
|
86
|
+
x={curveInset}
|
|
87
|
+
y={curveInset}
|
|
88
|
+
/>
|
|
89
|
+
</clipPath>
|
|
90
|
+
</defs>
|
|
91
|
+
<rect
|
|
92
|
+
fill="transparent"
|
|
93
|
+
height={curveGraphSize}
|
|
94
|
+
onPointerDown={onBackgroundPointerDown}
|
|
95
|
+
width={curveGraphSize}
|
|
96
|
+
x={curveInset}
|
|
97
|
+
y={curveInset}
|
|
98
|
+
/>
|
|
99
|
+
<CurveGrid
|
|
100
|
+
clipPathId={clipPathId}
|
|
101
|
+
showReferenceLine={showReferenceLine}
|
|
102
|
+
/>
|
|
103
|
+
<CurvePaths
|
|
104
|
+
activeChannel={activeChannel}
|
|
105
|
+
channels={channels}
|
|
106
|
+
clipPathId={clipPathId}
|
|
107
|
+
interpolation={interpolation}
|
|
108
|
+
points={points}
|
|
109
|
+
/>
|
|
110
|
+
<CurvePointHandles
|
|
111
|
+
activeChannel={activeChannel}
|
|
112
|
+
activePoints={activePoints}
|
|
113
|
+
draggingPointIndex={draggingPointIndex}
|
|
114
|
+
onPointDoubleClick={onPointDoubleClick}
|
|
115
|
+
onPointKeyDown={onPointKeyDown}
|
|
116
|
+
onPointPointerDown={onPointPointerDown}
|
|
117
|
+
onPointPointerUp={onPointPointerUp}
|
|
118
|
+
selectedPointIndex={selectedPointIndex}
|
|
119
|
+
/>
|
|
120
|
+
</svg>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type CurveGraphProps = {
|
|
125
|
+
activeChannel: CurveChannel;
|
|
126
|
+
activePoints: readonly CurvePoint[];
|
|
127
|
+
ariaLabel?: string;
|
|
128
|
+
channels?: readonly CurveChannel[];
|
|
129
|
+
draggingPointIndex: number | null;
|
|
130
|
+
graphRef: React.RefObject<SVGSVGElement | null>;
|
|
131
|
+
interpolation?: CurveInterpolation;
|
|
132
|
+
onBackgroundPointerDown: React.PointerEventHandler<SVGRectElement>;
|
|
133
|
+
onPointDoubleClick: (
|
|
134
|
+
index: number,
|
|
135
|
+
event: React.MouseEvent<HTMLButtonElement>,
|
|
136
|
+
) => void;
|
|
137
|
+
onPointKeyDown: (
|
|
138
|
+
index: number,
|
|
139
|
+
event: React.KeyboardEvent<HTMLButtonElement>,
|
|
140
|
+
) => void;
|
|
141
|
+
onPointPointerDown: (
|
|
142
|
+
index: number,
|
|
143
|
+
event: React.PointerEvent<HTMLButtonElement>,
|
|
144
|
+
) => void;
|
|
145
|
+
onPointPointerUp: (
|
|
146
|
+
index: number,
|
|
147
|
+
event: React.PointerEvent<HTMLButtonElement>,
|
|
148
|
+
) => void;
|
|
149
|
+
points: Record<CurveChannel, readonly CurvePoint[]>;
|
|
150
|
+
selectedPointIndex: number | null;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
function shouldShowReferenceLine(
|
|
154
|
+
points: Record<CurveChannel, readonly CurvePoint[]>,
|
|
155
|
+
channels: readonly CurveChannel[] = curveChannels,
|
|
156
|
+
): boolean {
|
|
157
|
+
return channels.every((channel) => !isIdentityCurve(points[channel]));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function isIdentityCurve(points: readonly CurvePoint[]): boolean {
|
|
161
|
+
const normalizedPoints = normalizeCurvePoints(points);
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
normalizedPoints.length > 0 &&
|
|
165
|
+
normalizedPoints.every((point) => Math.abs(point.x - point.y) < 0.0001)
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function CurveGrid({
|
|
170
|
+
clipPathId,
|
|
171
|
+
showReferenceLine,
|
|
172
|
+
}: {
|
|
173
|
+
clipPathId: string;
|
|
174
|
+
showReferenceLine: boolean;
|
|
175
|
+
}): React.JSX.Element {
|
|
176
|
+
return (
|
|
177
|
+
<g pointerEvents="none">
|
|
178
|
+
<rect
|
|
179
|
+
fill="color-mix(in oklab, var(--background) 20%, transparent)"
|
|
180
|
+
height={curveGraphSize}
|
|
181
|
+
rx={curveGraphRadius}
|
|
182
|
+
width={curveGraphSize}
|
|
183
|
+
x={curveInset}
|
|
184
|
+
y={curveInset}
|
|
185
|
+
/>
|
|
186
|
+
<g clipPath={`url(#${clipPathId})`}>
|
|
187
|
+
{curveGridStops.map((stop) => {
|
|
188
|
+
const position = curveInset + stop * curveGraphSize;
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<g key={stop}>
|
|
192
|
+
<line
|
|
193
|
+
stroke="color-mix(in oklab, var(--foreground) 5%, transparent)"
|
|
194
|
+
strokeWidth="1"
|
|
195
|
+
x1={position}
|
|
196
|
+
x2={position}
|
|
197
|
+
y1={curveInset}
|
|
198
|
+
y2={curveGraphMax}
|
|
199
|
+
/>
|
|
200
|
+
<line
|
|
201
|
+
stroke="color-mix(in oklab, var(--foreground) 5%, transparent)"
|
|
202
|
+
strokeWidth="1"
|
|
203
|
+
x1={curveInset}
|
|
204
|
+
x2={curveGraphMax}
|
|
205
|
+
y1={position}
|
|
206
|
+
y2={position}
|
|
207
|
+
/>
|
|
208
|
+
</g>
|
|
209
|
+
);
|
|
210
|
+
})}
|
|
211
|
+
{showReferenceLine ? (
|
|
212
|
+
<path
|
|
213
|
+
d={`M ${curveInset} ${curveGraphMax} L ${curveGraphMax} ${curveInset}`}
|
|
214
|
+
data-curve-reference-line=""
|
|
215
|
+
fill="none"
|
|
216
|
+
stroke="color-mix(in oklab, var(--foreground) 16%, transparent)"
|
|
217
|
+
strokeDasharray="4 5"
|
|
218
|
+
strokeWidth="1"
|
|
219
|
+
/>
|
|
220
|
+
) : null}
|
|
221
|
+
</g>
|
|
222
|
+
<rect
|
|
223
|
+
fill="none"
|
|
224
|
+
height={curveGraphSize}
|
|
225
|
+
rx={curveGraphRadius}
|
|
226
|
+
stroke="color-mix(in oklab, var(--border) 15%, transparent)"
|
|
227
|
+
strokeWidth="1"
|
|
228
|
+
width={curveGraphSize}
|
|
229
|
+
x={curveInset}
|
|
230
|
+
y={curveInset}
|
|
231
|
+
/>
|
|
232
|
+
</g>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function CurvePaths({
|
|
237
|
+
activeChannel,
|
|
238
|
+
channels,
|
|
239
|
+
clipPathId,
|
|
240
|
+
interpolation,
|
|
241
|
+
points,
|
|
242
|
+
}: {
|
|
243
|
+
activeChannel: CurveChannel;
|
|
244
|
+
channels: readonly CurveChannel[];
|
|
245
|
+
clipPathId: string;
|
|
246
|
+
interpolation: CurveInterpolation;
|
|
247
|
+
points: Record<CurveChannel, readonly CurvePoint[]>;
|
|
248
|
+
}): React.JSX.Element {
|
|
249
|
+
return (
|
|
250
|
+
<g clipPath={`url(#${clipPathId})`} pointerEvents="none">
|
|
251
|
+
{channels.map((channel) => (
|
|
252
|
+
<path
|
|
253
|
+
d={getCurvePath(points[channel], interpolation)}
|
|
254
|
+
data-curve-interpolation={interpolation}
|
|
255
|
+
fill="none"
|
|
256
|
+
key={channel}
|
|
257
|
+
opacity={channel === activeChannel ? 1 : 0.15}
|
|
258
|
+
stroke={channelMeta[channel].color}
|
|
259
|
+
strokeLinecap="round"
|
|
260
|
+
strokeLinejoin="round"
|
|
261
|
+
strokeWidth={channel === activeChannel ? 2 : 1.5}
|
|
262
|
+
/>
|
|
263
|
+
))}
|
|
264
|
+
</g>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function CurvePointHandles({
|
|
269
|
+
activeChannel,
|
|
270
|
+
activePoints,
|
|
271
|
+
draggingPointIndex,
|
|
272
|
+
onPointDoubleClick,
|
|
273
|
+
onPointKeyDown,
|
|
274
|
+
onPointPointerDown,
|
|
275
|
+
onPointPointerUp,
|
|
276
|
+
selectedPointIndex,
|
|
277
|
+
}: {
|
|
278
|
+
activeChannel: CurveChannel;
|
|
279
|
+
activePoints: readonly CurvePoint[];
|
|
280
|
+
draggingPointIndex: number | null;
|
|
281
|
+
onPointDoubleClick: (
|
|
282
|
+
index: number,
|
|
283
|
+
event: React.MouseEvent<HTMLButtonElement>,
|
|
284
|
+
) => void;
|
|
285
|
+
onPointKeyDown: (
|
|
286
|
+
index: number,
|
|
287
|
+
event: React.KeyboardEvent<HTMLButtonElement>,
|
|
288
|
+
) => void;
|
|
289
|
+
onPointPointerDown: (
|
|
290
|
+
index: number,
|
|
291
|
+
event: React.PointerEvent<HTMLButtonElement>,
|
|
292
|
+
) => void;
|
|
293
|
+
onPointPointerUp: (
|
|
294
|
+
index: number,
|
|
295
|
+
event: React.PointerEvent<HTMLButtonElement>,
|
|
296
|
+
) => void;
|
|
297
|
+
selectedPointIndex: number | null;
|
|
298
|
+
}): React.JSX.Element {
|
|
299
|
+
const handlesVisible =
|
|
300
|
+
selectedPointIndex !== null || draggingPointIndex !== null;
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<g
|
|
304
|
+
className={
|
|
305
|
+
handlesVisible
|
|
306
|
+
? "opacity-100 transition-opacity duration-150 ease-out"
|
|
307
|
+
: "opacity-0 transition-opacity duration-150 ease-out group-hover/curve-graph:opacity-100 group-focus-within/curve-graph:opacity-100"
|
|
308
|
+
}
|
|
309
|
+
data-curve-point-handles=""
|
|
310
|
+
>
|
|
311
|
+
{activePoints.map((point, index) => (
|
|
312
|
+
<CurvePointHandle
|
|
313
|
+
activeChannel={activeChannel}
|
|
314
|
+
index={index}
|
|
315
|
+
dragging={draggingPointIndex === index}
|
|
316
|
+
key={`${activeChannel}-${point.x}-${point.y}-${index}`}
|
|
317
|
+
onPointDoubleClick={onPointDoubleClick}
|
|
318
|
+
onPointKeyDown={onPointKeyDown}
|
|
319
|
+
onPointPointerDown={onPointPointerDown}
|
|
320
|
+
onPointPointerUp={onPointPointerUp}
|
|
321
|
+
point={point}
|
|
322
|
+
selected={selectedPointIndex === index}
|
|
323
|
+
/>
|
|
324
|
+
))}
|
|
325
|
+
</g>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function CurvePointHandle({
|
|
330
|
+
activeChannel,
|
|
331
|
+
dragging,
|
|
332
|
+
index,
|
|
333
|
+
onPointDoubleClick,
|
|
334
|
+
onPointKeyDown,
|
|
335
|
+
onPointPointerDown,
|
|
336
|
+
onPointPointerUp,
|
|
337
|
+
point,
|
|
338
|
+
selected,
|
|
339
|
+
}: {
|
|
340
|
+
activeChannel: CurveChannel;
|
|
341
|
+
dragging: boolean;
|
|
342
|
+
index: number;
|
|
343
|
+
onPointDoubleClick: (
|
|
344
|
+
index: number,
|
|
345
|
+
event: React.MouseEvent<HTMLButtonElement>,
|
|
346
|
+
) => void;
|
|
347
|
+
onPointKeyDown: (
|
|
348
|
+
index: number,
|
|
349
|
+
event: React.KeyboardEvent<HTMLButtonElement>,
|
|
350
|
+
) => void;
|
|
351
|
+
onPointPointerDown: (
|
|
352
|
+
index: number,
|
|
353
|
+
event: React.PointerEvent<HTMLButtonElement>,
|
|
354
|
+
) => void;
|
|
355
|
+
onPointPointerUp: (
|
|
356
|
+
index: number,
|
|
357
|
+
event: React.PointerEvent<HTMLButtonElement>,
|
|
358
|
+
) => void;
|
|
359
|
+
point: CurvePoint;
|
|
360
|
+
selected: boolean;
|
|
361
|
+
}): React.JSX.Element {
|
|
362
|
+
const [pointX, pointY] = mapPointToSvg(point);
|
|
363
|
+
const color = channelMeta[activeChannel].color;
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<foreignObject
|
|
367
|
+
className="overflow-visible"
|
|
368
|
+
height={curvePointHandleViewportSize}
|
|
369
|
+
width={curvePointHandleViewportSize}
|
|
370
|
+
x={pointX - curvePointHandleViewportRadius}
|
|
371
|
+
y={pointY - curvePointHandleViewportRadius}
|
|
372
|
+
>
|
|
373
|
+
<div className="flex size-full items-center justify-center">
|
|
374
|
+
<button
|
|
375
|
+
aria-label={`Curve point ${index + 1}`}
|
|
376
|
+
aria-pressed={selected ? true : undefined}
|
|
377
|
+
data-dragging={dragging}
|
|
378
|
+
data-selected={selected}
|
|
379
|
+
className="m-0 flex size-2.5 cursor-grab items-center justify-center rounded-full border-2 bg-[color:var(--background)] p-0 shadow-[0_1px_4px_color-mix(in_oklab,var(--background)_70%,transparent)] outline-none transition-[background-color,width,height] duration-150 ease-out hover:size-3 hover:bg-[color:var(--background)] active:size-3 active:cursor-grabbing active:bg-[color:var(--background)] data-[dragging=true]:size-3 data-[selected=true]:size-3 data-[selected=true]:bg-[color:var(--foreground)]"
|
|
380
|
+
onDoubleClick={(event) => onPointDoubleClick(index, event)}
|
|
381
|
+
onKeyDown={(event) => onPointKeyDown(index, event)}
|
|
382
|
+
onPointerDown={(event) => onPointPointerDown(index, event)}
|
|
383
|
+
onPointerUp={(event) => onPointPointerUp(index, event)}
|
|
384
|
+
style={{ borderColor: selected ? "var(--foreground)" : color }}
|
|
385
|
+
type="button"
|
|
386
|
+
/>
|
|
387
|
+
</div>
|
|
388
|
+
</foreignObject>
|
|
389
|
+
);
|
|
390
|
+
}
|