@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,445 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
createControlHistoryGroupId,
|
|
8
|
+
type ControlChangeMeta,
|
|
9
|
+
type ControlValueChangeHandler,
|
|
10
|
+
type CurveChannel,
|
|
11
|
+
type CurvePoint,
|
|
12
|
+
} from "../control-types";
|
|
13
|
+
import { ControlFieldLabel } from "../../control-layout";
|
|
14
|
+
import { ChannelTabs, CurveGraph, singleCurveChannels } from "./curve-graph";
|
|
15
|
+
import {
|
|
16
|
+
type CurveInterpolation,
|
|
17
|
+
constrainCurvePoint,
|
|
18
|
+
defaultCurveInterpolation,
|
|
19
|
+
getCurvePointAtX,
|
|
20
|
+
insertCurvePoint,
|
|
21
|
+
isPointNearCurve,
|
|
22
|
+
normalizeCurvePoints,
|
|
23
|
+
pointFromSvgEvent,
|
|
24
|
+
removeCurvePoint,
|
|
25
|
+
replaceCurvePoint,
|
|
26
|
+
} from "./curve-geometry";
|
|
27
|
+
|
|
28
|
+
const playControlAddSound = () => undefined;
|
|
29
|
+
const playControlDeleteSound = () => undefined;
|
|
30
|
+
const playControlDragEndSound = () => undefined;
|
|
31
|
+
const playControlDragStartSound = () => undefined;
|
|
32
|
+
const playControlSelectSound = () => undefined;
|
|
33
|
+
|
|
34
|
+
export type CurvesControlValue = {
|
|
35
|
+
activeChannel: CurveChannel;
|
|
36
|
+
points: Record<CurveChannel, readonly CurvePoint[]>;
|
|
37
|
+
selectedPointIndex?: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type CurvesControlVariant = "rgb" | "single";
|
|
41
|
+
|
|
42
|
+
export type CurvesControlProps = {
|
|
43
|
+
activeChannel?: CurveChannel;
|
|
44
|
+
interpolation?: CurveInterpolation;
|
|
45
|
+
name?: string;
|
|
46
|
+
onValueChange?: ControlValueChangeHandler<CurvesControlValue>;
|
|
47
|
+
points?: Record<CurveChannel, readonly CurvePoint[]>;
|
|
48
|
+
selectedPointIndex?: number;
|
|
49
|
+
variant?: CurvesControlVariant;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type CurveEditorProps = {
|
|
53
|
+
activeChannel: CurveChannel;
|
|
54
|
+
interpolation: CurveInterpolation;
|
|
55
|
+
onValueChange?: CurvesControlProps["onValueChange"];
|
|
56
|
+
points: Record<CurveChannel, readonly CurvePoint[]>;
|
|
57
|
+
selectedPointIndex?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type DraggingPoint = {
|
|
61
|
+
channel: CurveChannel;
|
|
62
|
+
hasMoved: boolean;
|
|
63
|
+
index: number;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function useCurveEditor({
|
|
67
|
+
activeChannel,
|
|
68
|
+
interpolation,
|
|
69
|
+
onValueChange,
|
|
70
|
+
points,
|
|
71
|
+
selectedPointIndex,
|
|
72
|
+
}: CurveEditorProps) {
|
|
73
|
+
const graphRef = useRef<SVGSVGElement>(null);
|
|
74
|
+
const dragHistoryGroupRef = useRef<string | null>(null);
|
|
75
|
+
const [draggingPoint, setDraggingPoint] = useState<DraggingPoint | null>(
|
|
76
|
+
null,
|
|
77
|
+
);
|
|
78
|
+
const activePoints = normalizeCurvePoints(points[activeChannel]);
|
|
79
|
+
|
|
80
|
+
function updateCurve(
|
|
81
|
+
nextPoints: readonly CurvePoint[],
|
|
82
|
+
nextSelectedIndex: number | null,
|
|
83
|
+
meta?: ControlChangeMeta,
|
|
84
|
+
): void {
|
|
85
|
+
onValueChange?.(
|
|
86
|
+
{
|
|
87
|
+
activeChannel,
|
|
88
|
+
points: { ...points, [activeChannel]: normalizeCurvePoints(nextPoints) },
|
|
89
|
+
selectedPointIndex: nextSelectedIndex ?? undefined,
|
|
90
|
+
},
|
|
91
|
+
meta,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function pointFromEvent(
|
|
96
|
+
event: Pick<PointerEvent, "clientX" | "clientY">,
|
|
97
|
+
): CurvePoint {
|
|
98
|
+
return pointFromSvgEvent(event, graphRef.current);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function movePoint(
|
|
102
|
+
index: number,
|
|
103
|
+
point: CurvePoint,
|
|
104
|
+
meta?: ControlChangeMeta,
|
|
105
|
+
): void {
|
|
106
|
+
updateCurve(
|
|
107
|
+
replaceCurvePoint(
|
|
108
|
+
activePoints,
|
|
109
|
+
index,
|
|
110
|
+
constrainCurvePoint(activePoints, index, point),
|
|
111
|
+
),
|
|
112
|
+
null,
|
|
113
|
+
meta,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function addPoint(event: React.PointerEvent<SVGRectElement>): void {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
const point = pointFromEvent(event);
|
|
120
|
+
|
|
121
|
+
if (!isPointNearCurve(activePoints, point, undefined, interpolation)) {
|
|
122
|
+
if (selectedPointIndex !== undefined) {
|
|
123
|
+
updateCurve(activePoints, null);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const nextCurve = insertCurvePoint(
|
|
129
|
+
activePoints,
|
|
130
|
+
getCurvePointAtX(activePoints, point.x, interpolation),
|
|
131
|
+
);
|
|
132
|
+
updateCurve(nextCurve.points, null);
|
|
133
|
+
setDraggingPoint({
|
|
134
|
+
channel: activeChannel,
|
|
135
|
+
hasMoved: true,
|
|
136
|
+
index: nextCurve.index,
|
|
137
|
+
});
|
|
138
|
+
playControlAddSound();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function removePoint(index: number): void {
|
|
142
|
+
if (index > 0 && index < activePoints.length - 1) {
|
|
143
|
+
updateCurve(removeCurvePoint(activePoints, index), null);
|
|
144
|
+
playControlDeleteSound();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
useCurveDragging({
|
|
149
|
+
activeChannel,
|
|
150
|
+
dragHistoryGroupRef,
|
|
151
|
+
draggingPoint,
|
|
152
|
+
movePoint,
|
|
153
|
+
pointFromEvent,
|
|
154
|
+
setDraggingPoint,
|
|
155
|
+
stopDragging: () => {
|
|
156
|
+
dragHistoryGroupRef.current = null;
|
|
157
|
+
setDraggingPoint(null);
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
useClearCurveSelectionOnOutsidePointerDown({
|
|
161
|
+
activePoints,
|
|
162
|
+
graphRef,
|
|
163
|
+
selectedPointIndex: selectedPointIndex ?? null,
|
|
164
|
+
updateCurve,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
function startDraggingPoint(index: number): void {
|
|
168
|
+
dragHistoryGroupRef.current = createControlHistoryGroupId(
|
|
169
|
+
`curves:${activeChannel}`,
|
|
170
|
+
);
|
|
171
|
+
setDraggingPoint({
|
|
172
|
+
channel: activeChannel,
|
|
173
|
+
hasMoved: false,
|
|
174
|
+
index,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
activePoints,
|
|
180
|
+
draggingPoint,
|
|
181
|
+
addPoint,
|
|
182
|
+
draggingPointIndex:
|
|
183
|
+
draggingPoint?.channel === activeChannel ? draggingPoint.index : null,
|
|
184
|
+
graphRef,
|
|
185
|
+
movePoint,
|
|
186
|
+
removePoint,
|
|
187
|
+
selectedPointIndex: selectedPointIndex ?? null,
|
|
188
|
+
startDraggingPoint,
|
|
189
|
+
selectPoint: (index: number, meta?: ControlChangeMeta) =>
|
|
190
|
+
updateCurve(activePoints, index, meta),
|
|
191
|
+
updateCurve,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const defaultActiveChannel = "RGB" satisfies CurveChannel;
|
|
196
|
+
const defaultName = "Curves";
|
|
197
|
+
const defaultCurvePoints = {
|
|
198
|
+
B: [
|
|
199
|
+
{ x: 0, y: 0 },
|
|
200
|
+
{ x: 0.5, y: 0.5 },
|
|
201
|
+
{ x: 1, y: 1 },
|
|
202
|
+
],
|
|
203
|
+
G: [
|
|
204
|
+
{ x: 0, y: 0 },
|
|
205
|
+
{ x: 0.5, y: 0.5 },
|
|
206
|
+
{ x: 1, y: 1 },
|
|
207
|
+
],
|
|
208
|
+
R: [
|
|
209
|
+
{ x: 0, y: 0 },
|
|
210
|
+
{ x: 0.5, y: 0.5 },
|
|
211
|
+
{ x: 1, y: 1 },
|
|
212
|
+
],
|
|
213
|
+
RGB: [
|
|
214
|
+
{ x: 0, y: 0 },
|
|
215
|
+
{ x: 0.5, y: 0.5 },
|
|
216
|
+
{ x: 1, y: 1 },
|
|
217
|
+
],
|
|
218
|
+
} satisfies Record<CurveChannel, readonly CurvePoint[]>;
|
|
219
|
+
const defaultSelectedPointIndex = 1;
|
|
220
|
+
|
|
221
|
+
function withDefaultCurvePoints(
|
|
222
|
+
points: Record<CurveChannel, readonly CurvePoint[]> | undefined,
|
|
223
|
+
): Record<CurveChannel, readonly CurvePoint[]> {
|
|
224
|
+
return { ...defaultCurvePoints, ...points };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function useClearCurveSelectionOnOutsidePointerDown({
|
|
228
|
+
activePoints,
|
|
229
|
+
graphRef,
|
|
230
|
+
selectedPointIndex,
|
|
231
|
+
updateCurve,
|
|
232
|
+
}: {
|
|
233
|
+
activePoints: readonly CurvePoint[];
|
|
234
|
+
graphRef: React.RefObject<SVGSVGElement | null>;
|
|
235
|
+
selectedPointIndex: number | null;
|
|
236
|
+
updateCurve: (
|
|
237
|
+
nextPoints: readonly CurvePoint[],
|
|
238
|
+
nextSelectedIndex: number | null,
|
|
239
|
+
) => void;
|
|
240
|
+
}): void {
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (selectedPointIndex === null) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function handlePointerDown(event: PointerEvent): void {
|
|
247
|
+
if (!graphRef.current?.contains(event.target as Node)) {
|
|
248
|
+
updateCurve(activePoints, null);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
window.addEventListener("pointerdown", handlePointerDown);
|
|
253
|
+
|
|
254
|
+
return () => {
|
|
255
|
+
window.removeEventListener("pointerdown", handlePointerDown);
|
|
256
|
+
};
|
|
257
|
+
}, [activePoints, graphRef, selectedPointIndex, updateCurve]);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function useCurveDragging({
|
|
261
|
+
activeChannel,
|
|
262
|
+
dragHistoryGroupRef,
|
|
263
|
+
draggingPoint,
|
|
264
|
+
movePoint,
|
|
265
|
+
pointFromEvent,
|
|
266
|
+
setDraggingPoint,
|
|
267
|
+
stopDragging,
|
|
268
|
+
}: {
|
|
269
|
+
activeChannel: CurveChannel;
|
|
270
|
+
dragHistoryGroupRef: React.MutableRefObject<string | null>;
|
|
271
|
+
draggingPoint: DraggingPoint | null;
|
|
272
|
+
movePoint: (
|
|
273
|
+
index: number,
|
|
274
|
+
point: CurvePoint,
|
|
275
|
+
meta?: ControlChangeMeta,
|
|
276
|
+
) => void;
|
|
277
|
+
pointFromEvent: (
|
|
278
|
+
event: Pick<PointerEvent, "clientX" | "clientY">,
|
|
279
|
+
) => CurvePoint;
|
|
280
|
+
setDraggingPoint: React.Dispatch<React.SetStateAction<DraggingPoint | null>>;
|
|
281
|
+
stopDragging: () => void;
|
|
282
|
+
}): void {
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
const currentDrag = draggingPoint;
|
|
285
|
+
if (!currentDrag) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const activeDrag: DraggingPoint = currentDrag;
|
|
290
|
+
|
|
291
|
+
function handlePointerMove(event: PointerEvent): void {
|
|
292
|
+
if (activeDrag.channel === activeChannel) {
|
|
293
|
+
dragHistoryGroupRef.current ??= createControlHistoryGroupId(
|
|
294
|
+
`curves:${activeChannel}`,
|
|
295
|
+
);
|
|
296
|
+
movePoint(activeDrag.index, pointFromEvent(event), {
|
|
297
|
+
history: "merge",
|
|
298
|
+
historyGroup: dragHistoryGroupRef.current,
|
|
299
|
+
});
|
|
300
|
+
setDraggingPoint((currentPoint) =>
|
|
301
|
+
currentPoint === activeDrag
|
|
302
|
+
? { ...currentPoint, hasMoved: true }
|
|
303
|
+
: currentPoint,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function handleStopDragging(): void {
|
|
309
|
+
playControlDragEndSound();
|
|
310
|
+
stopDragging();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
314
|
+
window.addEventListener("pointerup", handleStopDragging);
|
|
315
|
+
window.addEventListener("pointercancel", handleStopDragging);
|
|
316
|
+
|
|
317
|
+
return () => {
|
|
318
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
319
|
+
window.removeEventListener("pointerup", handleStopDragging);
|
|
320
|
+
window.removeEventListener("pointercancel", handleStopDragging);
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function CurvesControl(props: CurvesControlProps): React.JSX.Element {
|
|
326
|
+
const {
|
|
327
|
+
activeChannel: controlledActiveChannel,
|
|
328
|
+
interpolation: controlledInterpolation,
|
|
329
|
+
name = defaultName,
|
|
330
|
+
onValueChange,
|
|
331
|
+
points: controlledPoints,
|
|
332
|
+
selectedPointIndex: controlledSelectedPointIndex,
|
|
333
|
+
variant = "rgb",
|
|
334
|
+
} = props;
|
|
335
|
+
const singleCurve = variant === "single";
|
|
336
|
+
const interpolation =
|
|
337
|
+
controlledInterpolation ?? (singleCurve ? "monotone" : defaultCurveInterpolation);
|
|
338
|
+
const isActiveChannelControlled = "activeChannel" in props;
|
|
339
|
+
const isPointsControlled = controlledPoints !== undefined;
|
|
340
|
+
const isSelectedPointIndexControlled = "selectedPointIndex" in props;
|
|
341
|
+
const [uncontrolledActiveChannel, setUncontrolledActiveChannel] =
|
|
342
|
+
useState<CurveChannel>(defaultActiveChannel);
|
|
343
|
+
const [uncontrolledPoints, setUncontrolledPoints] =
|
|
344
|
+
useState<Record<CurveChannel, readonly CurvePoint[]>>(defaultCurvePoints);
|
|
345
|
+
const [uncontrolledSelectedPointIndex, setUncontrolledSelectedPointIndex] =
|
|
346
|
+
useState<number | undefined>(defaultSelectedPointIndex);
|
|
347
|
+
const activeChannel = singleCurve
|
|
348
|
+
? defaultActiveChannel
|
|
349
|
+
: controlledActiveChannel ?? uncontrolledActiveChannel;
|
|
350
|
+
const points = withDefaultCurvePoints(controlledPoints ?? uncontrolledPoints);
|
|
351
|
+
const selectedPointIndex = isSelectedPointIndexControlled
|
|
352
|
+
? controlledSelectedPointIndex
|
|
353
|
+
: uncontrolledSelectedPointIndex;
|
|
354
|
+
|
|
355
|
+
function handleValueChange(
|
|
356
|
+
value: CurvesControlValue,
|
|
357
|
+
meta?: ControlChangeMeta,
|
|
358
|
+
): void {
|
|
359
|
+
if (!isActiveChannelControlled) {
|
|
360
|
+
setUncontrolledActiveChannel(value.activeChannel);
|
|
361
|
+
}
|
|
362
|
+
if (!isPointsControlled) {
|
|
363
|
+
setUncontrolledPoints(value.points);
|
|
364
|
+
}
|
|
365
|
+
if (!isSelectedPointIndexControlled) {
|
|
366
|
+
setUncontrolledSelectedPointIndex(value.selectedPointIndex);
|
|
367
|
+
}
|
|
368
|
+
onValueChange?.(value, meta);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const editor = useCurveEditor({
|
|
372
|
+
activeChannel,
|
|
373
|
+
interpolation,
|
|
374
|
+
onValueChange: handleValueChange,
|
|
375
|
+
points,
|
|
376
|
+
selectedPointIndex,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
return (
|
|
380
|
+
<div className="flex min-w-0 flex-col gap-3" aria-label={name}>
|
|
381
|
+
{singleCurve ? (
|
|
382
|
+
<ControlFieldLabel>{name}</ControlFieldLabel>
|
|
383
|
+
) : (
|
|
384
|
+
<div className="flex min-w-0 flex-col gap-2">
|
|
385
|
+
<ChannelTabs
|
|
386
|
+
name={name}
|
|
387
|
+
onValueChange={(nextChannel) => {
|
|
388
|
+
handleValueChange({ activeChannel: nextChannel, points });
|
|
389
|
+
playControlSelectSound();
|
|
390
|
+
}}
|
|
391
|
+
value={activeChannel}
|
|
392
|
+
/>
|
|
393
|
+
</div>
|
|
394
|
+
)}
|
|
395
|
+
<CurveGraph
|
|
396
|
+
activeChannel={activeChannel}
|
|
397
|
+
activePoints={editor.activePoints}
|
|
398
|
+
ariaLabel={singleCurve ? `${name} curve editor` : "Color curves editor"}
|
|
399
|
+
channels={singleCurve ? singleCurveChannels : undefined}
|
|
400
|
+
draggingPointIndex={editor.draggingPointIndex}
|
|
401
|
+
graphRef={editor.graphRef}
|
|
402
|
+
interpolation={interpolation}
|
|
403
|
+
onBackgroundPointerDown={editor.addPoint}
|
|
404
|
+
onPointDoubleClick={(index, event) => {
|
|
405
|
+
event.stopPropagation();
|
|
406
|
+
editor.removePoint(index);
|
|
407
|
+
}}
|
|
408
|
+
onPointKeyDown={(index, event) => {
|
|
409
|
+
handlePointKeyDown(index, event, editor);
|
|
410
|
+
}}
|
|
411
|
+
onPointPointerDown={(index, event) => {
|
|
412
|
+
event.stopPropagation();
|
|
413
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
414
|
+
editor.selectPoint(index, { history: "skip" });
|
|
415
|
+
playControlDragStartSound();
|
|
416
|
+
editor.startDraggingPoint(index);
|
|
417
|
+
}}
|
|
418
|
+
onPointPointerUp={() => undefined}
|
|
419
|
+
points={points}
|
|
420
|
+
selectedPointIndex={editor.selectedPointIndex}
|
|
421
|
+
/>
|
|
422
|
+
</div>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function handlePointKeyDown(
|
|
427
|
+
index: number,
|
|
428
|
+
event: React.KeyboardEvent<HTMLButtonElement>,
|
|
429
|
+
editor: ReturnType<typeof useCurveEditor>,
|
|
430
|
+
): void {
|
|
431
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
432
|
+
event.preventDefault();
|
|
433
|
+
editor.updateCurve(editor.activePoints, index, { history: "skip" });
|
|
434
|
+
playControlSelectSound();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (
|
|
439
|
+
(event.key === "Backspace" || event.key === "Delete") &&
|
|
440
|
+
editor.selectedPointIndex === index
|
|
441
|
+
) {
|
|
442
|
+
event.preventDefault();
|
|
443
|
+
editor.removePoint(index);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { CloudArrowUpIcon, XIcon } from "@phosphor-icons/react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../../lib/utils";
|
|
7
|
+
import { Button, Field } from "../../primitives";
|
|
8
|
+
|
|
9
|
+
export type FileDropPreview = {
|
|
10
|
+
alt?: string;
|
|
11
|
+
size?: {
|
|
12
|
+
height: number;
|
|
13
|
+
width: number;
|
|
14
|
+
};
|
|
15
|
+
src: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type FileDropControlProps = {
|
|
19
|
+
accept: string;
|
|
20
|
+
onClear?: () => void;
|
|
21
|
+
onFileSelect?: (file: File) => void;
|
|
22
|
+
preview?: FileDropPreview;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function isDragLeavingCurrentTarget(event: React.DragEvent<HTMLElement>): boolean {
|
|
26
|
+
const nextTarget = event.relatedTarget;
|
|
27
|
+
|
|
28
|
+
return !(nextTarget instanceof Node && event.currentTarget.contains(nextTarget));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getFileInputAccept(accept: string): string {
|
|
32
|
+
return accept
|
|
33
|
+
.split(",")
|
|
34
|
+
.map((part) => part.trim().toLowerCase())
|
|
35
|
+
.flatMap((part) => {
|
|
36
|
+
switch (part) {
|
|
37
|
+
case "gif":
|
|
38
|
+
return [".gif", "image/gif"];
|
|
39
|
+
case "heic":
|
|
40
|
+
return [".heic", "image/heic"];
|
|
41
|
+
case "heif":
|
|
42
|
+
return [".heif", "image/heif"];
|
|
43
|
+
case "jpg":
|
|
44
|
+
case "jpeg":
|
|
45
|
+
return [".jpg", ".jpeg", "image/jpeg"];
|
|
46
|
+
case "png":
|
|
47
|
+
return [".png", "image/png"];
|
|
48
|
+
case "svg":
|
|
49
|
+
return [".svg", "image/svg+xml"];
|
|
50
|
+
case "tif":
|
|
51
|
+
case "tiff":
|
|
52
|
+
return [".tif", ".tiff", "image/tiff"];
|
|
53
|
+
case "webp":
|
|
54
|
+
return [".webp", "image/webp"];
|
|
55
|
+
default:
|
|
56
|
+
return part.startsWith(".") || part.includes("/") ? [part] : [];
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.join(",");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getPreviewImageStyle(size: FileDropPreview["size"]): React.CSSProperties {
|
|
63
|
+
if (!size || size.height <= 0 || size.width <= 0) {
|
|
64
|
+
return { width: "100%" };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const maxWidth = Math.max(1, (196 * size.width) / size.height);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
width: `min(100%, ${maxWidth.toFixed(2)}px)`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function FileDropControl({
|
|
75
|
+
accept,
|
|
76
|
+
onClear,
|
|
77
|
+
onFileSelect,
|
|
78
|
+
preview,
|
|
79
|
+
}: FileDropControlProps): React.JSX.Element {
|
|
80
|
+
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
81
|
+
const [dragOver, setDragOver] = React.useState(false);
|
|
82
|
+
const hasPreview = Boolean(preview?.src);
|
|
83
|
+
|
|
84
|
+
function handleFile(file: File | undefined): void {
|
|
85
|
+
if (!file) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onFileSelect?.(file);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function openFileDialog(): void {
|
|
93
|
+
inputRef.current?.click();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function handleDropTargetKeyDown(event: React.KeyboardEvent<HTMLDivElement>): void {
|
|
97
|
+
if (event.key !== "Enter" && event.key !== " ") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
openFileDialog();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Field className="min-w-0 gap-2">
|
|
107
|
+
<input
|
|
108
|
+
accept={getFileInputAccept(accept)}
|
|
109
|
+
aria-hidden="true"
|
|
110
|
+
className="hidden"
|
|
111
|
+
onChange={(event) => {
|
|
112
|
+
handleFile(event.currentTarget.files?.[0]);
|
|
113
|
+
event.currentTarget.value = "";
|
|
114
|
+
}}
|
|
115
|
+
ref={inputRef}
|
|
116
|
+
tabIndex={-1}
|
|
117
|
+
type="file"
|
|
118
|
+
/>
|
|
119
|
+
<div
|
|
120
|
+
aria-label={hasPreview ? "Replace image file" : "Browse image file"}
|
|
121
|
+
className={cn(
|
|
122
|
+
"group/file-upload relative flex min-h-16 w-full cursor-pointer flex-col items-center justify-center gap-1.5 rounded-lg border border-dashed border-[color:color-mix(in_oklab,var(--border)_18%,transparent)] bg-[color:color-mix(in_oklab,var(--foreground)_3%,transparent)] text-center shadow-none transition-[background-color,border-color,box-shadow] duration-150 ease-out hover:border-[color:color-mix(in_oklab,var(--border)_35%,transparent)] hover:bg-[color:color-mix(in_oklab,var(--foreground)_6%,transparent)] data-[drag-over=true]:border-[color:color-mix(in_oklab,var(--link)_28%,transparent)] data-[drag-over=true]:bg-[color:color-mix(in_oklab,var(--link)_13%,transparent)] data-[drag-over=true]:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-[color:var(--background)]",
|
|
123
|
+
hasPreview ? "overflow-hidden p-2" : "px-3 py-3",
|
|
124
|
+
)}
|
|
125
|
+
data-drag-over={dragOver}
|
|
126
|
+
onClick={openFileDialog}
|
|
127
|
+
onDragEnter={(event) => {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
setDragOver(true);
|
|
130
|
+
}}
|
|
131
|
+
onDragLeave={(event) => {
|
|
132
|
+
if (isDragLeavingCurrentTarget(event)) {
|
|
133
|
+
setDragOver(false);
|
|
134
|
+
}
|
|
135
|
+
}}
|
|
136
|
+
onDragOver={(event) => {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
setDragOver(true);
|
|
139
|
+
}}
|
|
140
|
+
onDrop={(event) => {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
setDragOver(false);
|
|
143
|
+
handleFile(event.dataTransfer?.files?.[0]);
|
|
144
|
+
}}
|
|
145
|
+
onKeyDown={handleDropTargetKeyDown}
|
|
146
|
+
role="button"
|
|
147
|
+
tabIndex={0}
|
|
148
|
+
>
|
|
149
|
+
{hasPreview ? (
|
|
150
|
+
<>
|
|
151
|
+
<img
|
|
152
|
+
alt={preview?.alt ?? ""}
|
|
153
|
+
className="block h-auto max-h-[196px] max-w-full rounded-[calc(var(--radius-lg)-4px)] object-contain"
|
|
154
|
+
draggable={false}
|
|
155
|
+
height={preview?.size?.height}
|
|
156
|
+
src={preview?.src}
|
|
157
|
+
style={getPreviewImageStyle(preview?.size)}
|
|
158
|
+
width={preview?.size?.width}
|
|
159
|
+
/>
|
|
160
|
+
{onClear ? (
|
|
161
|
+
<Button
|
|
162
|
+
aria-label="Remove image"
|
|
163
|
+
className="absolute top-3 right-3"
|
|
164
|
+
onClick={(event) => {
|
|
165
|
+
event.stopPropagation();
|
|
166
|
+
onClear();
|
|
167
|
+
}}
|
|
168
|
+
size="icon-sm"
|
|
169
|
+
type="button"
|
|
170
|
+
variant="ghost"
|
|
171
|
+
>
|
|
172
|
+
<XIcon className="drop-shadow-[0_2px_1px_color-mix(in_oklab,var(--background)_80%,transparent)]" />
|
|
173
|
+
</Button>
|
|
174
|
+
) : null}
|
|
175
|
+
</>
|
|
176
|
+
) : (
|
|
177
|
+
<>
|
|
178
|
+
<CloudArrowUpIcon
|
|
179
|
+
className="size-6 flex-none text-[color:var(--muted-foreground)] transition-colors duration-150 ease-out group-data-[drag-over=true]/file-upload:text-[color:var(--link)]"
|
|
180
|
+
weight="light"
|
|
181
|
+
/>
|
|
182
|
+
<p className="m-0 flex max-w-full flex-col text-xs leading-tight text-[color:color-mix(in_oklab,var(--foreground)_60%,transparent)] transition-colors duration-150 ease-out group-hover/file-upload:text-[color:color-mix(in_oklab,var(--foreground)_85%,transparent)] group-data-[drag-over=true]/file-upload:text-[color:var(--link)]">
|
|
183
|
+
<span>Click to upload an image</span>
|
|
184
|
+
<span>or drag it onto the canvas</span>
|
|
185
|
+
</p>
|
|
186
|
+
</>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
</Field>
|
|
190
|
+
);
|
|
191
|
+
}
|