@newtone-dev/ui-react-web 0.44.0 → 0.46.1
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 +5 -3
- package/dist/app-frame/app-frame.css +77 -25
- package/dist/app-frame/app-frame.d.ts +2 -1
- package/dist/app-frame/app-frame.d.ts.map +1 -1
- package/dist/app-frame/app-frame.js +2 -1
- package/dist/app-frame/app-frame.js.map +1 -1
- package/dist/app-frame/index.d.ts +1 -1
- package/dist/app-frame/index.d.ts.map +1 -1
- package/dist/app-frame/launcher/launcher.d.ts.map +1 -1
- package/dist/app-frame/launcher/launcher.js +5 -3
- package/dist/app-frame/launcher/launcher.js.map +1 -1
- package/dist/app-frame/main-menu/main-menu.js +5 -1
- package/dist/app-frame/main-menu/main-menu.js.map +1 -1
- package/dist/app-frame/parts.d.ts +26 -1
- package/dist/app-frame/parts.d.ts.map +1 -1
- package/dist/app-frame/parts.js +17 -3
- package/dist/app-frame/parts.js.map +1 -1
- package/dist/ask-button/ask-button.css +7 -1
- package/dist/beside/beside.css +4 -0
- package/dist/button/button.css +14 -4
- package/dist/button/button.d.ts +12 -1
- package/dist/button/button.d.ts.map +1 -1
- package/dist/button/button.js +49 -3
- package/dist/button/button.js.map +1 -1
- package/dist/canvas/canvas.css +20 -5
- package/dist/canvas/cells/cells.d.ts +12 -1
- package/dist/canvas/cells/cells.d.ts.map +1 -1
- package/dist/canvas/cells/cells.js +16 -2
- package/dist/canvas/cells/cells.js.map +1 -1
- package/dist/canvas/cells/grid.d.ts +8 -2
- package/dist/canvas/cells/grid.d.ts.map +1 -1
- package/dist/canvas/cells/grid.js +8 -5
- package/dist/canvas/cells/grid.js.map +1 -1
- package/dist/canvas/dock/dock.d.ts +2 -2
- package/dist/canvas/dock/dock.js +2 -2
- package/dist/canvas/dock/dock.js.map +1 -1
- package/dist/card-box/card-box.css +8 -2
- package/dist/card-box/card-box.d.ts.map +1 -1
- package/dist/card-box/card-box.js +1 -1
- package/dist/card-box/card-box.js.map +1 -1
- package/dist/color/index.d.ts +4 -4
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +17 -15
- package/dist/color/index.js.map +1 -1
- package/dist/color/oklch.d.ts +6 -27
- package/dist/color/oklch.d.ts.map +1 -1
- package/dist/color/oklch.js +23 -61
- package/dist/color/oklch.js.map +1 -1
- package/dist/color/scale.d.ts +3 -18
- package/dist/color/scale.d.ts.map +1 -1
- package/dist/color/scale.js +13 -70
- package/dist/color/scale.js.map +1 -1
- package/dist/color/seeds.d.ts +51 -11
- package/dist/color/seeds.d.ts.map +1 -1
- package/dist/color/seeds.js +127 -41
- package/dist/color/seeds.js.map +1 -1
- package/dist/curve-field/curve-field.css +280 -0
- package/dist/curve-field/curve-field.d.ts +105 -0
- package/dist/curve-field/curve-field.d.ts.map +1 -0
- package/dist/curve-field/curve-field.js +532 -0
- package/dist/curve-field/curve-field.js.map +1 -0
- package/dist/curve-field/index.d.ts +3 -0
- package/dist/curve-field/index.d.ts.map +1 -0
- package/dist/curve-field/index.js +2 -0
- package/dist/curve-field/index.js.map +1 -0
- package/dist/diagram/diagram.css +63 -0
- package/dist/diagram/diagram.d.ts +63 -0
- package/dist/diagram/diagram.d.ts.map +1 -0
- package/dist/diagram/diagram.js +73 -0
- package/dist/diagram/diagram.js.map +1 -0
- package/dist/diagram/geometry.d.ts +60 -0
- package/dist/diagram/geometry.d.ts.map +1 -0
- package/dist/diagram/geometry.js +93 -0
- package/dist/diagram/geometry.js.map +1 -0
- package/dist/diagram/index.d.ts +7 -0
- package/dist/diagram/index.d.ts.map +1 -0
- package/dist/diagram/index.js +4 -0
- package/dist/diagram/index.js.map +1 -0
- package/dist/diagram/layout.d.ts +41 -0
- package/dist/diagram/layout.d.ts.map +1 -0
- package/dist/diagram/layout.js +157 -0
- package/dist/diagram/layout.js.map +1 -0
- package/dist/document/document.d.ts +7 -2
- package/dist/document/document.d.ts.map +1 -1
- package/dist/document/document.js +22 -4
- package/dist/document/document.js.map +1 -1
- package/dist/dynamic-range/dynamic-range.css +100 -0
- package/dist/dynamic-range/dynamic-range.d.ts +27 -0
- package/dist/dynamic-range/dynamic-range.d.ts.map +1 -0
- package/dist/dynamic-range/dynamic-range.js +20 -0
- package/dist/dynamic-range/dynamic-range.js.map +1 -0
- package/dist/dynamic-range/index.d.ts +3 -0
- package/dist/dynamic-range/index.d.ts.map +1 -0
- package/dist/dynamic-range/index.js +2 -0
- package/dist/dynamic-range/index.js.map +1 -0
- package/dist/file-grid/file-grid.css +65 -0
- package/dist/file-grid/file-grid.d.ts +35 -2
- package/dist/file-grid/file-grid.d.ts.map +1 -1
- package/dist/file-grid/file-grid.js +64 -3
- package/dist/file-grid/file-grid.js.map +1 -1
- package/dist/file-grid/index.d.ts +2 -2
- package/dist/file-grid/index.d.ts.map +1 -1
- package/dist/file-grid/index.js +1 -1
- package/dist/file-grid/index.js.map +1 -1
- package/dist/floating-bar/floating-bar.css +122 -32
- package/dist/floating-bar/floating-bar.d.ts +21 -2
- package/dist/floating-bar/floating-bar.d.ts.map +1 -1
- package/dist/floating-bar/floating-bar.js +64 -20
- package/dist/floating-bar/floating-bar.js.map +1 -1
- package/dist/floating-bar/index.d.ts +1 -1
- package/dist/floating-bar/index.d.ts.map +1 -1
- package/dist/font-picker/font-picker.css +4 -2
- package/dist/font-picker/font-picker.d.ts +34 -4
- package/dist/font-picker/font-picker.d.ts.map +1 -1
- package/dist/font-picker/font-picker.js +45 -9
- package/dist/font-picker/font-picker.js.map +1 -1
- package/dist/font-picker/index.d.ts +2 -2
- package/dist/font-picker/index.d.ts.map +1 -1
- package/dist/font-picker/index.js +1 -1
- package/dist/font-picker/index.js.map +1 -1
- package/dist/hint/hint.css +2 -6
- package/dist/icon/glyphs.d.ts +18 -0
- package/dist/icon/glyphs.d.ts.map +1 -0
- package/dist/icon/glyphs.js +17 -0
- package/dist/icon/glyphs.js.map +1 -0
- package/dist/icon/index.d.ts +2 -0
- package/dist/icon/index.d.ts.map +1 -1
- package/dist/icon/index.js +1 -0
- package/dist/icon/index.js.map +1 -1
- package/dist/identity/identity.d.ts +11 -3
- package/dist/identity/identity.d.ts.map +1 -1
- package/dist/identity/identity.js +8 -4
- package/dist/identity/identity.js.map +1 -1
- package/dist/index.d.ts +33 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/inspector/index.d.ts +1 -1
- package/dist/inspector/index.d.ts.map +1 -1
- package/dist/inspector/inspector.css +368 -7
- package/dist/inspector/inspector.d.ts +182 -5
- package/dist/inspector/inspector.d.ts.map +1 -1
- package/dist/inspector/inspector.js +85 -7
- package/dist/inspector/inspector.js.map +1 -1
- package/dist/look-picker/look-picker.css +62 -2
- package/dist/look-picker/look-picker.d.ts +34 -2
- package/dist/look-picker/look-picker.d.ts.map +1 -1
- package/dist/look-picker/look-picker.js +51 -42
- package/dist/look-picker/look-picker.js.map +1 -1
- package/dist/material/material.css +128 -57
- package/dist/number-field/number-field.css +34 -0
- package/dist/number-field/number-field.d.ts +29 -3
- package/dist/number-field/number-field.d.ts.map +1 -1
- package/dist/number-field/number-field.js +61 -10
- package/dist/number-field/number-field.js.map +1 -1
- package/dist/page-editor/page-editor.css +2 -6
- package/dist/picker/picker.css +42 -0
- package/dist/picker/picker.d.ts +10 -1
- package/dist/picker/picker.d.ts.map +1 -1
- package/dist/picker/picker.js +40 -5
- package/dist/picker/picker.js.map +1 -1
- package/dist/pop-menu/index.d.ts +7 -0
- package/dist/pop-menu/index.d.ts.map +1 -0
- package/dist/pop-menu/index.js +6 -0
- package/dist/pop-menu/index.js.map +1 -0
- package/dist/{floating-bar/menu.d.ts → pop-menu/pop-menu.d.ts} +10 -2
- package/dist/pop-menu/pop-menu.d.ts.map +1 -0
- package/dist/{floating-bar/menu.js → pop-menu/pop-menu.js} +35 -12
- package/dist/pop-menu/pop-menu.js.map +1 -0
- package/dist/prompt-field/prompt-field.css +3 -3
- package/dist/prompt-field/prompt-field.d.ts +3 -3
- package/dist/prompt-field/prompt-field.d.ts.map +1 -1
- package/dist/prompt-field/prompt-field.js +10 -4
- package/dist/prompt-field/prompt-field.js.map +1 -1
- package/dist/quick-action/quick-action.css +1 -1
- package/dist/seed-color-field/seed-color-field.css +8 -10
- package/dist/seed-color-field/seed-color-field.d.ts +9 -0
- package/dist/seed-color-field/seed-color-field.d.ts.map +1 -1
- package/dist/seed-color-field/seed-color-field.js +37 -10
- package/dist/seed-color-field/seed-color-field.js.map +1 -1
- package/dist/seed-contrast-field/index.d.ts +5 -0
- package/dist/seed-contrast-field/index.d.ts.map +1 -0
- package/dist/seed-contrast-field/index.js +3 -0
- package/dist/seed-contrast-field/index.js.map +1 -0
- package/dist/seed-contrast-field/seed-contrast-field.css +11 -0
- package/dist/seed-contrast-field/seed-contrast-field.d.ts +36 -0
- package/dist/seed-contrast-field/seed-contrast-field.d.ts.map +1 -0
- package/dist/seed-contrast-field/seed-contrast-field.js +18 -0
- package/dist/seed-contrast-field/seed-contrast-field.js.map +1 -0
- package/dist/seed-contrast-field/seed-contrast-slider.css +112 -0
- package/dist/seed-contrast-field/seed-contrast-slider.d.ts +22 -0
- package/dist/seed-contrast-field/seed-contrast-slider.d.ts.map +1 -0
- package/dist/seed-contrast-field/seed-contrast-slider.js +75 -0
- package/dist/seed-contrast-field/seed-contrast-slider.js.map +1 -0
- package/dist/seed-roundness-field/index.d.ts +3 -0
- package/dist/seed-roundness-field/index.d.ts.map +1 -0
- package/dist/seed-roundness-field/index.js +2 -0
- package/dist/seed-roundness-field/index.js.map +1 -0
- package/dist/seed-roundness-field/seed-roundness-field.css +23 -0
- package/dist/seed-roundness-field/seed-roundness-field.d.ts +39 -0
- package/dist/seed-roundness-field/seed-roundness-field.d.ts.map +1 -0
- package/dist/seed-roundness-field/seed-roundness-field.js +15 -0
- package/dist/seed-roundness-field/seed-roundness-field.js.map +1 -0
- package/dist/seed-steps/index.d.ts +8 -0
- package/dist/seed-steps/index.d.ts.map +1 -0
- package/dist/seed-steps/index.js +7 -0
- package/dist/seed-steps/index.js.map +1 -0
- package/dist/seed-steps/reset-focus.d.ts +16 -0
- package/dist/seed-steps/reset-focus.d.ts.map +1 -0
- package/dist/seed-steps/reset-focus.js +53 -0
- package/dist/seed-steps/reset-focus.js.map +1 -0
- package/dist/seed-steps/seed-steps.css +83 -0
- package/dist/seed-steps/seed-steps.d.ts +47 -0
- package/dist/seed-steps/seed-steps.d.ts.map +1 -0
- package/dist/seed-steps/seed-steps.js +95 -0
- package/dist/seed-steps/seed-steps.js.map +1 -0
- package/dist/shell/shell.css +31 -33
- package/dist/slide-list/slide-list.css +23 -2
- package/dist/slide-list/slide-list.d.ts +11 -2
- package/dist/slide-list/slide-list.d.ts.map +1 -1
- package/dist/slide-list/slide-list.js +6 -6
- package/dist/slide-list/slide-list.js.map +1 -1
- package/dist/split/split.css +11 -8
- package/dist/split/split.d.ts +2 -0
- package/dist/split/split.d.ts.map +1 -1
- package/dist/split/split.js +21 -3
- package/dist/split/split.js.map +1 -1
- package/dist/stage/stage.d.ts +11 -4
- package/dist/stage/stage.d.ts.map +1 -1
- package/dist/stage/stage.js +30 -9
- package/dist/stage/stage.js.map +1 -1
- package/dist/step-list/index.d.ts +3 -0
- package/dist/step-list/index.d.ts.map +1 -0
- package/dist/step-list/index.js +2 -0
- package/dist/step-list/index.js.map +1 -0
- package/dist/step-list/step-list.css +224 -0
- package/dist/step-list/step-list.d.ts +211 -0
- package/dist/step-list/step-list.d.ts.map +1 -0
- package/dist/step-list/step-list.js +242 -0
- package/dist/step-list/step-list.js.map +1 -0
- package/dist/step-strip/index.d.ts +3 -0
- package/dist/step-strip/index.d.ts.map +1 -0
- package/dist/step-strip/index.js +2 -0
- package/dist/step-strip/index.js.map +1 -0
- package/dist/step-strip/step-strip.css +118 -0
- package/dist/step-strip/step-strip.d.ts +52 -0
- package/dist/step-strip/step-strip.d.ts.map +1 -0
- package/dist/step-strip/step-strip.js +47 -0
- package/dist/step-strip/step-strip.js.map +1 -0
- package/dist/suggestion/index.d.ts +3 -0
- package/dist/suggestion/index.d.ts.map +1 -0
- package/dist/suggestion/index.js +2 -0
- package/dist/suggestion/index.js.map +1 -0
- package/dist/suggestion/suggestion.css +45 -0
- package/dist/suggestion/suggestion.d.ts +23 -0
- package/dist/suggestion/suggestion.d.ts.map +1 -0
- package/dist/suggestion/suggestion.js +45 -0
- package/dist/suggestion/suggestion.js.map +1 -0
- package/dist/surface/surface.css +112 -0
- package/dist/switch/switch.css +1 -6
- package/dist/text-field/text-field.css +11 -2
- package/dist/thread/thread.css +2 -10
- package/dist/thread/thread.js +1 -1
- package/dist/thread/thread.js.map +1 -1
- package/dist/tile-picker/index.d.ts +1 -1
- package/dist/tile-picker/index.d.ts.map +1 -1
- package/dist/tile-picker/tile-picker.css +56 -10
- package/dist/tile-picker/tile-picker.d.ts +64 -7
- package/dist/tile-picker/tile-picker.d.ts.map +1 -1
- package/dist/tile-picker/tile-picker.js +79 -47
- package/dist/tile-picker/tile-picker.js.map +1 -1
- package/dist/tile-search/index.d.ts +7 -0
- package/dist/tile-search/index.d.ts.map +1 -0
- package/dist/tile-search/index.js +7 -0
- package/dist/tile-search/index.js.map +1 -0
- package/dist/tile-search/narrow.d.ts +22 -0
- package/dist/tile-search/narrow.d.ts.map +1 -0
- package/dist/tile-search/narrow.js +62 -0
- package/dist/tile-search/narrow.js.map +1 -0
- package/dist/tile-search/search-box.d.ts +19 -0
- package/dist/tile-search/search-box.d.ts.map +1 -0
- package/dist/tile-search/search-box.js +47 -0
- package/dist/tile-search/search-box.js.map +1 -0
- package/dist/tooltip/tooltip.css +13 -20
- package/dist/tooltip/tooltip.d.ts +2 -2
- package/dist/tooltip/tooltip.d.ts.map +1 -1
- package/dist/tooltip/tooltip.js +15 -2
- package/dist/tooltip/tooltip.js.map +1 -1
- package/dist/workbench/workbench.css +128 -4
- package/dist/workbench/workbench.d.ts +28 -1
- package/dist/workbench/workbench.d.ts.map +1 -1
- package/dist/workbench/workbench.js +13 -4
- package/dist/workbench/workbench.js.map +1 -1
- package/package.json +43 -1
- package/dist/color/gamut.d.ts +0 -20
- package/dist/color/gamut.d.ts.map +0 -1
- package/dist/color/gamut.js +0 -72
- package/dist/color/gamut.js.map +0 -1
- package/dist/floating-bar/menu.d.ts.map +0 -1
- package/dist/floating-bar/menu.js.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
/** A value that changes across the ladder: its Start (step 0), its End (the last step), and how it goes between. */
|
|
3
|
+
export interface CurveFieldEnds {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
/**
|
|
7
|
+
* Absent, Linear: a straight line from Start to End. Given, a Curve: how far along the ladder its Start handle and
|
|
8
|
+
* its End handle sit, each 0 to 1 in two decimals (`[0.42, 0.58]`). `[0, 1]` is a straight line, told as Linear.
|
|
9
|
+
*/
|
|
10
|
+
curve?: [number, number];
|
|
11
|
+
}
|
|
12
|
+
/** One number, the same at every step (flat); else its two ends. */
|
|
13
|
+
export type CurveFieldValue = number | CurveFieldEnds;
|
|
14
|
+
/** A line across the steps: a limit the value cannot pass (the most chroma the gamut holds at each step). */
|
|
15
|
+
export interface CurveFieldGuide {
|
|
16
|
+
/** Its name, in the list under the plot: "sRGB ceiling". */
|
|
17
|
+
label: string;
|
|
18
|
+
/** Its value at each step, in the field's units; one value is the same at every step. */
|
|
19
|
+
values: number[];
|
|
20
|
+
}
|
|
21
|
+
export interface CurveFieldLabels {
|
|
22
|
+
/** Start's word: its number's short label and, with the field's name, its point's and number's name ("Start: Chroma"). */
|
|
23
|
+
start: string;
|
|
24
|
+
/** End's word, as `start`. */
|
|
25
|
+
end: string;
|
|
26
|
+
/** The choice's two words. */
|
|
27
|
+
linear: string;
|
|
28
|
+
curve: string;
|
|
29
|
+
/** The handles' names, with the field's name ("Start handle: Chroma"). */
|
|
30
|
+
startHandle: string;
|
|
31
|
+
endHandle: string;
|
|
32
|
+
/** Said where the value follows `inherited`, and on the press that makes it follow again: "Same as Sunset". */
|
|
33
|
+
same?: string;
|
|
34
|
+
/** The press's words, where they differ from `same`: "Reset to Sunset's". */
|
|
35
|
+
reset?: string;
|
|
36
|
+
/** Said beside the name while the value departs from `inherited`: "Changed here". Not shown unless given. */
|
|
37
|
+
changed?: string;
|
|
38
|
+
}
|
|
39
|
+
interface CurveFieldOwn extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'children'> {
|
|
40
|
+
/** The field's name: Hue, Chroma. With the words, it names each point, handle and number, and the choice. */
|
|
41
|
+
label: string;
|
|
42
|
+
/**
|
|
43
|
+
* The value set here; null where it is not set (it follows `inherited`; with none, the plot is empty). A Start or
|
|
44
|
+
* End that is not a finite number is read as no value.
|
|
45
|
+
*/
|
|
46
|
+
value: CurveFieldValue | null;
|
|
47
|
+
/** What a null value follows: the style's. */
|
|
48
|
+
inherited?: CurveFieldValue;
|
|
49
|
+
/** A change ended, with its value: a drag let go, the arrow keys let go, a number settled, a choice, set back. */
|
|
50
|
+
onCommit?: (value: CurveFieldValue | null) => void;
|
|
51
|
+
/** Start's and End's bounds, and the plot's value axis, `min` at the foot. */
|
|
52
|
+
min: number;
|
|
53
|
+
max: number;
|
|
54
|
+
/** What a drag snaps to and an arrow key moves: 1 for a hue, 0.01 for a chroma. */
|
|
55
|
+
step: number;
|
|
56
|
+
/** The decimals shown and told. */
|
|
57
|
+
precision: number;
|
|
58
|
+
/** After each number, and in what each point says: °. */
|
|
59
|
+
unit?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Where a value turns round: 360 for a hue. Start and End are kept in [0, wrap), typed and stepped numbers too, and
|
|
62
|
+
* End is drawn the shorter way from Start (the exact opposite going up), so the plot is unwrapped from Start.
|
|
63
|
+
*/
|
|
64
|
+
wrap?: number;
|
|
65
|
+
/** The ladder's count of steps: 51. */
|
|
66
|
+
steps?: number;
|
|
67
|
+
/** Per step, what an engine produced, in the field's units (null where it says nothing): a dot each. */
|
|
68
|
+
measured?: (number | null)[];
|
|
69
|
+
/** Lines across the steps, each named in a list under the plot. */
|
|
70
|
+
guides?: CurveFieldGuide[];
|
|
71
|
+
/**
|
|
72
|
+
* Read-only, keeping the focus: every point, handle and radio `aria-disabled`, the numbers `NumberField`'s
|
|
73
|
+
* `disabledFocusable`, the press back Button's; presses, drags and keys ignored, every Tab stop kept.
|
|
74
|
+
*/
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The plot alone (2026-11-14, HuevOS's Colors panel): no name over it (`label` still names it to a screen reader), and,
|
|
78
|
+
* unless read-only, still set by dragging its points and handles, with no Start and End numbers, no Linear or Curve
|
|
79
|
+
* choice and no press back, where the page sets those in its own rows beside the plot.
|
|
80
|
+
*/
|
|
81
|
+
plotOnly?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* What each value looks like, painted behind the plot (2026-11-14, HuevOS's Colors panel: a point's height reads as a
|
|
84
|
+
* color, so a drag says what it is moving to). Rows of colors from `min` at the foot to `max` at the top, evenly
|
|
85
|
+
* spaced, each one color for every step or one color per step (its columns from the first step to the last). With
|
|
86
|
+
* `wrap`, the rows span one turn from 0 (0 included, `wrap` not), and turn with the axis. Any CSS color.
|
|
87
|
+
*/
|
|
88
|
+
ground?: (string | readonly string[])[];
|
|
89
|
+
labels: CurveFieldLabels;
|
|
90
|
+
}
|
|
91
|
+
/** Shown, not set (`readOnly`): the plot alone, and nothing is told, so `onChange` is not taken. */
|
|
92
|
+
export type CurveFieldChange = {
|
|
93
|
+
/** The plot alone, a picture named by `label` with its Start and End: no points, handles, numbers or choice. */
|
|
94
|
+
readOnly: true;
|
|
95
|
+
onChange?: (value: CurveFieldValue | null) => void;
|
|
96
|
+
} | {
|
|
97
|
+
readOnly?: false;
|
|
98
|
+
/** Told each change, in the one spelling; null when it is set back to follow `inherited`. */
|
|
99
|
+
onChange: (value: CurveFieldValue | null) => void;
|
|
100
|
+
};
|
|
101
|
+
export type CurveFieldProps = CurveFieldOwn & CurveFieldChange;
|
|
102
|
+
/** A value across a palette's ladder of steps. Blueprint components/curve-field.md. */
|
|
103
|
+
export declare function CurveField(props: CurveFieldProps): import("react").JSX.Element;
|
|
104
|
+
export {};
|
|
105
|
+
//# sourceMappingURL=curve-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curve-field.d.ts","sourceRoot":"","sources":["../../src/curve-field/curve-field.tsx"],"names":[],"mappings":"AASA,OAAO,EAMH,KAAK,cAAc,EAGtB,MAAM,OAAO,CAAA;AAMd,oHAAoH;AACpH,MAAM,WAAW,cAAc;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC3B;AAED,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,cAAc,CAAA;AAErD,6GAA6G;AAC7G,MAAM,WAAW,eAAe;IAC5B,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAA;IACb,yFAAyF;IACzF,MAAM,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC7B,0HAA0H;IAC1H,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,+GAA+G;IAC/G,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6GAA6G;IAC7G,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,UAAU,aAAc,SAAQ,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IACzF,6GAA6G;IAC7G,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,KAAK,EAAE,eAAe,GAAG,IAAI,CAAA;IAC7B,8CAA8C;IAC9C,SAAS,CAAC,EAAE,eAAe,CAAA;IAC3B,kHAAkH;IAClH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAA;IAClD,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAA;IACZ,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wGAAwG;IACxG,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;IAC5B,mEAAmE;IACnE,MAAM,CAAC,EAAE,eAAe,EAAE,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,EAAE,CAAA;IACvC,MAAM,EAAE,gBAAgB,CAAA;CAC3B;AAED,oGAAoG;AACpG,MAAM,MAAM,gBAAgB,GACtB;IACI,gHAAgH;IAChH,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAA;CACrD,GACD;IACI,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,6FAA6F;IAC7F,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAA;CACpD,CAAA;AAEP,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,gBAAgB,CAAA;AA6J9D,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BAmlBhD"}
|
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// One value across a palette's ladder of steps (2026-11-14): a palette's hue or chroma from its Start (step 0, the light
|
|
4
|
+
// end, at the left) to its End (the last step), Linear or a Curve whose two handles slide along the caps; or, read-only,
|
|
5
|
+
// a value per step shown (a palette's lightness). What a curve is lives in the HuevOS Core, page newtone-color: this
|
|
6
|
+
// draws it and tells it. A value is told one way each: a number where Start and End are the same, `{ start, end }` for
|
|
7
|
+
// Linear, `{ start, end, curve: [x1, x2] }` for a Curve, and `[0, 1]` is Linear. The Curve drawn is the cubic Bézier
|
|
8
|
+
// through (0, Start), (x1, Start), (x2, End), (1, End), in (share of the ladder, value). Every word is the consumer's.
|
|
9
|
+
// Blueprint components/curve-field.md; contract _blueprint/contracts/curve-field.md.
|
|
10
|
+
import { useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
11
|
+
import { Button } from '../button/index.js';
|
|
12
|
+
import { NumberField } from '../number-field/index.js';
|
|
13
|
+
import { useResetFocus } from '../seed-steps/index.js';
|
|
14
|
+
import { Text } from '../text/index.js';
|
|
15
|
+
// The plot's lengths, in CSS pixels, as curve-field.css sets them.
|
|
16
|
+
const INSET = 12; // the frame's inset at the sides and the top: half a knob's reach, so a knob at an end keeps it whole
|
|
17
|
+
const FOOT = 24; // under the frame: the step numbers, and the lower half of a knob's reach
|
|
18
|
+
const TALL = 156; // the plot's height
|
|
19
|
+
const WIDE = 264; // its width until it is measured (a server render, a page with no layout)
|
|
20
|
+
const REACH = 12; // how far round its middle a knob takes a press: its sheet's 24px box
|
|
21
|
+
const DECIDE = 4; // how far a press that a point and a handle both reach moves before it is the one's or the other's
|
|
22
|
+
// Choosing Curve from Linear starts here (Joshua, 2026-11-14).
|
|
23
|
+
const CURVE = [0.42, 0.58];
|
|
24
|
+
// How far each key moves a slider, in steps.
|
|
25
|
+
const BY = { ArrowUp: 1, ArrowRight: 1, PageUp: 10, ArrowDown: -1, ArrowLeft: -1, PageDown: -10 };
|
|
26
|
+
// `+ 0`: a rounded negative zero is told as 0.
|
|
27
|
+
const fix = (n, places) => Number(n.toFixed(places)) + 0;
|
|
28
|
+
const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
|
|
29
|
+
const r2 = (n) => Math.round(n * 100) / 100;
|
|
30
|
+
/** A Start or End as it is told: wrapped into [0, wrap) or kept in its bounds, in `precision` decimals. */
|
|
31
|
+
function settle(v, s) {
|
|
32
|
+
if (s.wrap) {
|
|
33
|
+
const t = fix(((v % s.wrap) + s.wrap) % s.wrap, s.precision);
|
|
34
|
+
return t >= s.wrap ? 0 : t;
|
|
35
|
+
}
|
|
36
|
+
return fix(clamp(v, s.min, s.max), s.precision);
|
|
37
|
+
}
|
|
38
|
+
/** The shorter way from `a` to `b` round a turn of `w`: in (−w/2, w/2], the exact opposite going up. */
|
|
39
|
+
function shorter(a, b, w, precision) {
|
|
40
|
+
const d = fix((((b - a) % w) + w) % w, precision);
|
|
41
|
+
return d > w / 2 ? d - w : d;
|
|
42
|
+
}
|
|
43
|
+
/** A value in its one spelling: a number where Start and End meet, no curve for Linear, `[0, 1]` told as Linear. */
|
|
44
|
+
function spell(start, end, curve, s) {
|
|
45
|
+
const a = settle(start, s);
|
|
46
|
+
const b = settle(end, s);
|
|
47
|
+
if (a === b)
|
|
48
|
+
return a;
|
|
49
|
+
if (!curve)
|
|
50
|
+
return { start: a, end: b };
|
|
51
|
+
const c = [fix(clamp(curve[0], 0, 1), 2), fix(clamp(curve[1], 0, 1), 2)];
|
|
52
|
+
return c[0] === 0 && c[1] === 1 ? { start: a, end: b } : { start: a, end: b, curve: c };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A value read: its two ends (wrapped, with `wrap`) and its curve where it bends, kept in 0 to 1; null where there is
|
|
56
|
+
* none, or where an end is not a finite number (a grey's `NaN` hue, a value half written).
|
|
57
|
+
*/
|
|
58
|
+
function read(v, s) {
|
|
59
|
+
if (v === null || v === undefined)
|
|
60
|
+
return null;
|
|
61
|
+
const turn = (n) => (s.wrap ? ((n % s.wrap) + s.wrap) % s.wrap : n);
|
|
62
|
+
if (typeof v === 'number')
|
|
63
|
+
return Number.isFinite(v) ? { start: turn(v), end: turn(v) } : null;
|
|
64
|
+
if (typeof v !== 'object' || !Number.isFinite(v.start) || !Number.isFinite(v.end))
|
|
65
|
+
return null;
|
|
66
|
+
const given = Array.isArray(v.curve) && v.curve.length === 2 && v.curve.every((x) => Number.isFinite(x));
|
|
67
|
+
const c = given ? [clamp(v.curve[0], 0, 1), clamp(v.curve[1], 0, 1)] : undefined;
|
|
68
|
+
return { start: turn(v.start), end: turn(v.end), curve: c && !(c[0] === 0 && c[1] === 1) ? c : undefined };
|
|
69
|
+
}
|
|
70
|
+
/** Where a value's two ends stand, as one string: the value a drag let go on. */
|
|
71
|
+
const endsAt = (e) => (e ? `${e.start} ${e.end}` : '');
|
|
72
|
+
/**
|
|
73
|
+
* A control that may go while it holds the focus (a handle as its value turns Linear, the choice as it turns flat):
|
|
74
|
+
* once a render shows it gone, a focus it held, now on the page, goes to `to`. Its handlers go on the control, or on a
|
|
75
|
+
* box of them: moving between them inside the box keeps the hold. A box taken off the page as it goes may say it
|
|
76
|
+
* blurred, so the clearing waits a microtask and asks whether it is still there (as the seed rows' press back).
|
|
77
|
+
*/
|
|
78
|
+
function useHandOn(shown, to) {
|
|
79
|
+
const holds = useRef(false);
|
|
80
|
+
useLayoutEffect(() => {
|
|
81
|
+
if (shown)
|
|
82
|
+
return;
|
|
83
|
+
const was = holds.current;
|
|
84
|
+
holds.current = false;
|
|
85
|
+
if (!was)
|
|
86
|
+
return;
|
|
87
|
+
const at = document.activeElement;
|
|
88
|
+
if (!at || at === document.body)
|
|
89
|
+
to()?.focus();
|
|
90
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
|
+
}, [shown]);
|
|
92
|
+
return {
|
|
93
|
+
onFocus: () => {
|
|
94
|
+
holds.current = true;
|
|
95
|
+
},
|
|
96
|
+
onBlur: (event) => {
|
|
97
|
+
const box = event.currentTarget;
|
|
98
|
+
queueMicrotask(() => {
|
|
99
|
+
if (box.isConnected && !box.contains(document.activeElement))
|
|
100
|
+
holds.current = false;
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The ground's columns, each a vertical gradient across the frame (left and width in % of it): one for rows of one color,
|
|
107
|
+
* else one per step, centred on its step. Each row is a stop at its value's height on the axis shown (`lo` at the foot,
|
|
108
|
+
* `hi` at the top); a value that wraps repeats its rows on every turn in view. Null with no rows.
|
|
109
|
+
*/
|
|
110
|
+
function groundOf(rows, lo, hi, min, max, wrap) {
|
|
111
|
+
if (!rows || rows.length === 0 || !(hi > lo))
|
|
112
|
+
return null;
|
|
113
|
+
const count = rows.length;
|
|
114
|
+
const stops = [];
|
|
115
|
+
if (wrap) {
|
|
116
|
+
const gap = wrap / count;
|
|
117
|
+
for (let k = 0; k < count; k++) {
|
|
118
|
+
const base = k * gap;
|
|
119
|
+
for (let m = Math.floor((lo - gap - base) / wrap); base + m * wrap <= hi + gap; m++) {
|
|
120
|
+
const v = base + m * wrap;
|
|
121
|
+
if (v >= lo - gap)
|
|
122
|
+
stops.push({ v, k });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
for (let k = 0; k < count; k++)
|
|
128
|
+
stops.push({ v: count === 1 ? min : min + (k * (max - min)) / (count - 1), k });
|
|
129
|
+
}
|
|
130
|
+
stops.sort((a, b) => b.v - a.v);
|
|
131
|
+
const columns = Math.max(...rows.map((r) => (typeof r === 'string' ? 1 : Math.max(1, r.length))));
|
|
132
|
+
const colorOf = (r, i) => (typeof r === 'string' ? r : r[Math.min(i, r.length - 1)]);
|
|
133
|
+
const image = (i) => stops.length === 1
|
|
134
|
+
? `linear-gradient(${colorOf(rows[stops[0].k], i)}, ${colorOf(rows[stops[0].k], i)})`
|
|
135
|
+
: `linear-gradient(to bottom, ${stops.map((s) => `${colorOf(rows[s.k], i)} ${r2(((hi - s.v) / (hi - lo)) * 100)}%`).join(', ')})`;
|
|
136
|
+
if (columns === 1)
|
|
137
|
+
return [{ left: 0, width: 100, image: image(0) }];
|
|
138
|
+
const out = [];
|
|
139
|
+
for (let i = 0; i < columns; i++) {
|
|
140
|
+
const a = Math.max(0, (i - 0.5) / (columns - 1));
|
|
141
|
+
const b = Math.min(1, (i + 0.5) / (columns - 1));
|
|
142
|
+
out.push({ left: r2(a * 100), width: r2((b - a) * 100), image: image(i) });
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
/** A value across a palette's ladder of steps. Blueprint components/curve-field.md. */
|
|
147
|
+
export function CurveField(props) {
|
|
148
|
+
const { label, value, inherited, onChange, onCommit, min, max, step, precision, unit, wrap, steps = 51, measured, guides, readOnly, disabled, plotOnly, ground, labels, className, ...rest } = props;
|
|
149
|
+
const scale = {
|
|
150
|
+
min,
|
|
151
|
+
max,
|
|
152
|
+
step,
|
|
153
|
+
precision,
|
|
154
|
+
wrap: wrap !== undefined && Number.isFinite(wrap) && wrap > 0 ? wrap : undefined,
|
|
155
|
+
};
|
|
156
|
+
const id = useId();
|
|
157
|
+
const stateId = `${id}state`;
|
|
158
|
+
const clipId = `newtone-curve-field-${id.replace(/[^a-zA-Z0-9_-]/g, '')}`;
|
|
159
|
+
const plot = useRef(null);
|
|
160
|
+
const row = useRef(null);
|
|
161
|
+
const forms = useRef(null);
|
|
162
|
+
const startPoint = useRef(null);
|
|
163
|
+
const endPoint = useRef(null);
|
|
164
|
+
const startHandleEl = useRef(null);
|
|
165
|
+
const endHandleEl = useRef(null);
|
|
166
|
+
const knobEl = { start: startPoint, end: endPoint, startHandle: startHandleEl, endHandle: endHandleEl };
|
|
167
|
+
// The plot's size as measured; the knob a pointer holds, and the one arrow keys are moving until they are let go;
|
|
168
|
+
// for a value that wraps, the middle of the turn shown while something holds it there (null: centred between the
|
|
169
|
+
// ends), and the ends a drag let go on, which a turn it left there holds for.
|
|
170
|
+
const [box, setBox] = useState({ w: WIDE, h: TALL });
|
|
171
|
+
const [held, setHeld] = useState(null);
|
|
172
|
+
const [keyed, setKeyed] = useState(null);
|
|
173
|
+
const [middle, setMiddle] = useState(null);
|
|
174
|
+
const [rested, setRested] = useState(null);
|
|
175
|
+
const drag = useRef(null);
|
|
176
|
+
// A change told and not yet ended; arrow keys pressed in a row; the curve a drag, a run of keys or a number's change
|
|
177
|
+
// began with, so a curve passed through flat (where it has no curve to keep) comes back as the value leaves flat.
|
|
178
|
+
const pending = useRef(null);
|
|
179
|
+
const nudging = useRef(false);
|
|
180
|
+
const kept = useRef(undefined);
|
|
181
|
+
// The plot fills its row; it is drawn to its own size, measured as it changes.
|
|
182
|
+
useLayoutEffect(() => {
|
|
183
|
+
const el = plot.current;
|
|
184
|
+
if (!el)
|
|
185
|
+
return;
|
|
186
|
+
const measure = () => {
|
|
187
|
+
const r = el.getBoundingClientRect();
|
|
188
|
+
if (r.width > 0 && r.height > 0)
|
|
189
|
+
setBox((b) => (b.w === r.width && b.h === r.height ? b : { w: r.width, h: r.height }));
|
|
190
|
+
};
|
|
191
|
+
measure();
|
|
192
|
+
if (typeof ResizeObserver === 'undefined')
|
|
193
|
+
return;
|
|
194
|
+
const watch = new ResizeObserver(measure);
|
|
195
|
+
watch.observe(el);
|
|
196
|
+
return () => watch.disconnect();
|
|
197
|
+
}, []);
|
|
198
|
+
const same = value === null && inherited !== undefined;
|
|
199
|
+
const departs = value !== null && inherited !== undefined;
|
|
200
|
+
const shown = read(value ?? inherited ?? null, scale);
|
|
201
|
+
const flat = !shown || shown.start === shown.end;
|
|
202
|
+
// The value's own curve; and the curve drawn, which is [0, 1] while a handle held (by a pointer, or by keys until
|
|
203
|
+
// they are let go) has made the value Linear: the handle stays where it is moved, and goes once it is let go.
|
|
204
|
+
const bent = shown && !flat ? shown.curve : undefined;
|
|
205
|
+
const handleHeld = [held, keyed].some((k) => k === 'startHandle' || k === 'endHandle');
|
|
206
|
+
const bend = flat ? undefined : (bent ?? (handleHeld ? [0, 1] : undefined));
|
|
207
|
+
const knobsShown = !readOnly && shown !== null;
|
|
208
|
+
const formsShown = knobsShown && !flat;
|
|
209
|
+
const handlesShown = knobsShown && bend !== undefined;
|
|
210
|
+
// The value axis: `min` to `max`; for a value that wraps, one turn, unwrapped from Start and centred between the
|
|
211
|
+
// ends. A drag holds the turn still from its press to its letting go, and a run of keys until an end would leave it.
|
|
212
|
+
// Let go, a drag leaves it where it was while the value is the one it let go on and both ends stand within a
|
|
213
|
+
// quarter-turn of its middle (nothing moves under the pointer, and the next drag still has room); any other change
|
|
214
|
+
// (a number typed, a run of keys let go, a value from outside) centres it.
|
|
215
|
+
let lo = min;
|
|
216
|
+
let hi = max;
|
|
217
|
+
let sd = shown?.start ?? 0;
|
|
218
|
+
let ed = shown?.end ?? 0;
|
|
219
|
+
let mid = null;
|
|
220
|
+
if (scale.wrap && shown) {
|
|
221
|
+
const w = scale.wrap;
|
|
222
|
+
const d = shorter(shown.start, shown.end, w, precision);
|
|
223
|
+
let c = middle;
|
|
224
|
+
if (c !== null) {
|
|
225
|
+
sd = shown.start + w * Math.round((c - shown.start) / w);
|
|
226
|
+
ed = sd + d;
|
|
227
|
+
const off = Math.max(Math.abs(sd - c), Math.abs(ed - c));
|
|
228
|
+
if (held === null && (keyed !== null ? off > w / 2 : rested !== endsAt(shown) || off > w / 4))
|
|
229
|
+
c = null;
|
|
230
|
+
}
|
|
231
|
+
if (c === null) {
|
|
232
|
+
sd = shown.start;
|
|
233
|
+
ed = sd + d;
|
|
234
|
+
c = (sd + ed) / 2;
|
|
235
|
+
}
|
|
236
|
+
mid = c;
|
|
237
|
+
// Kept between renders: set while rendering, as React's own pattern for state that follows the props.
|
|
238
|
+
const pin = held !== null || keyed !== null || c === middle ? c : null;
|
|
239
|
+
if (!Object.is(pin, middle))
|
|
240
|
+
setMiddle(pin);
|
|
241
|
+
lo = c - w / 2;
|
|
242
|
+
hi = c + w / 2;
|
|
243
|
+
}
|
|
244
|
+
const n = Math.max(2, Math.round(steps));
|
|
245
|
+
const aw = Math.max(1, box.w - 2 * INSET);
|
|
246
|
+
const ah = Math.max(1, box.h - INSET - FOOT);
|
|
247
|
+
const X = (f) => INSET + f * aw;
|
|
248
|
+
const Y = (v) => INSET + ((hi - v) / (hi - lo || 1)) * ah;
|
|
249
|
+
const at = (i) => i / (n - 1);
|
|
250
|
+
// A measured or guide value, at the turn nearest the value drawn at its step (a line between the ends is near enough).
|
|
251
|
+
const unwrap = (v, i) => scale.wrap ? v + scale.wrap * Math.round((sd + (ed - sd) * at(i) - v) / scale.wrap) : v;
|
|
252
|
+
// Where a knob stands on the plot: a point over its end of the ladder, a handle at its share, each on its end's level.
|
|
253
|
+
const place = (k) => {
|
|
254
|
+
const f = k === 'start' ? 0 : k === 'end' ? 1 : (bend ?? [0, 1])[k === 'startHandle' ? 0 : 1];
|
|
255
|
+
return [X(f), Y(k === 'start' || k === 'startHandle' ? sd : ed)];
|
|
256
|
+
};
|
|
257
|
+
const line = shown
|
|
258
|
+
? bend
|
|
259
|
+
? `M${r2(X(0))} ${r2(Y(sd))} C${r2(X(bend[0]))} ${r2(Y(sd))} ${r2(X(bend[1]))} ${r2(Y(ed))} ${r2(X(1))} ${r2(Y(ed))}`
|
|
260
|
+
: `M${r2(X(0))} ${r2(Y(sd))} L${r2(X(1))} ${r2(Y(ed))}`
|
|
261
|
+
: null;
|
|
262
|
+
// No grid (Joshua 2026-11-14): the frame, the step numbers and a ground say where a value stands.
|
|
263
|
+
const dots = (measured ?? [])
|
|
264
|
+
.slice(0, n)
|
|
265
|
+
.flatMap((m, i) => (m === null || m === undefined || !Number.isFinite(m) ? [] : [{ i, x: X(at(i)), y: Y(unwrap(m, i)) }]));
|
|
266
|
+
const guideLines = (guides ?? []).map((g) => {
|
|
267
|
+
const points = [];
|
|
268
|
+
for (let i = 0; i < n; i++) {
|
|
269
|
+
const v = g.values.length === 1 ? g.values[0] : g.values[i];
|
|
270
|
+
if (v !== undefined && Number.isFinite(v))
|
|
271
|
+
points.push(`${r2(X(at(i)))},${r2(Y(unwrap(v, i)))}`);
|
|
272
|
+
}
|
|
273
|
+
return points.join(' ');
|
|
274
|
+
});
|
|
275
|
+
const numbered = [...new Set([0, Math.round((n - 1) / 2), n - 1])];
|
|
276
|
+
const painted = groundOf(ground, lo, hi, min, max, scale.wrap);
|
|
277
|
+
// Words: every one is the consumer's; a number is said as NumberField says it, with its unit.
|
|
278
|
+
const say = (v) => (unit ? `${fix(v, precision)} ${unit}` : String(fix(v, precision)));
|
|
279
|
+
const along = (f) => `${Math.round(f * 100)} %`;
|
|
280
|
+
const state = same ? labels.same : departs ? labels.changed : undefined;
|
|
281
|
+
const back = labels.reset ?? labels.same;
|
|
282
|
+
const pictured = !shown
|
|
283
|
+
? label
|
|
284
|
+
: flat
|
|
285
|
+
? `${label}: ${say(shown.start)}`
|
|
286
|
+
: `${label}: ${labels.start} ${say(shown.start)}, ${labels.end} ${say(shown.end)}, ${bent ? labels.curve : labels.linear}`;
|
|
287
|
+
// What is shown now, in its one spelling: a change that tells it again is not told.
|
|
288
|
+
const now = shown ? spell(shown.start, shown.end, bent, scale) : null;
|
|
289
|
+
const tell = (next) => {
|
|
290
|
+
if (readOnly || !onChange)
|
|
291
|
+
return;
|
|
292
|
+
if (JSON.stringify(next) === JSON.stringify(pending.current ? pending.current.value : now))
|
|
293
|
+
return;
|
|
294
|
+
pending.current = { value: next };
|
|
295
|
+
onChange(next);
|
|
296
|
+
};
|
|
297
|
+
// A change ended (a drag let go, the keys let go, a number settled): said once, with the value it ended on.
|
|
298
|
+
const commit = () => {
|
|
299
|
+
const p = pending.current;
|
|
300
|
+
pending.current = null;
|
|
301
|
+
kept.current = undefined;
|
|
302
|
+
if (p)
|
|
303
|
+
onCommit?.(p.value);
|
|
304
|
+
};
|
|
305
|
+
// Nothing drops the focus to the page (as the seed rows, 2026-11-13). The first Tab stop is the Start point, else
|
|
306
|
+
// (nothing shown) the Start number.
|
|
307
|
+
const home = () => startPoint.current ?? row.current?.querySelector('input') ?? null;
|
|
308
|
+
const { resetting, press: pressBack } = useResetFocus(departs, home);
|
|
309
|
+
const startHandleGoes = useHandOn(handlesShown, () => startPoint.current ?? home());
|
|
310
|
+
const endHandleGoes = useHandOn(handlesShown, () => endPoint.current ?? home());
|
|
311
|
+
const formsGo = useHandOn(formsShown, home);
|
|
312
|
+
const knobsGo = useHandOn(knobsShown, () => row.current?.querySelector('input'));
|
|
313
|
+
// A drag whose knob went from the page under it (its value cleared from outside) ends there, as if let go.
|
|
314
|
+
useLayoutEffect(() => {
|
|
315
|
+
const d = drag.current;
|
|
316
|
+
if (!d || d.el.isConnected)
|
|
317
|
+
return;
|
|
318
|
+
drag.current = null;
|
|
319
|
+
setHeld(null);
|
|
320
|
+
commit();
|
|
321
|
+
});
|
|
322
|
+
// Where a drag has taken a knob: a point by how far the pointer moved up or down, snapped to `step`, kept in its
|
|
323
|
+
// bounds; a handle by how far it moved along, kept in 0 to 1, in two decimals.
|
|
324
|
+
const dragged = (d, cx, cy, cur) => {
|
|
325
|
+
// The line itself (2026-11-14, HuevOS's Colors panel): both ends move together by how far the pointer moved up or
|
|
326
|
+
// down, snapped to `step`, its shape kept; kept in bounds as a whole (a value that wraps turns round).
|
|
327
|
+
if (d.knob === 'line') {
|
|
328
|
+
const tall = Math.max(1, d.h - INSET - FOOT);
|
|
329
|
+
let by = Math.round((((d.y - cy) * (d.hi - d.lo)) / tall) / step) * step;
|
|
330
|
+
if (!scale.wrap)
|
|
331
|
+
by = clamp(by, min - Math.min(d.sd, d.ed), max - Math.max(d.sd, d.ed));
|
|
332
|
+
return spell(d.sd + by, d.ed + by, bent ?? kept.current, scale);
|
|
333
|
+
}
|
|
334
|
+
if (d.knob === 'start' || d.knob === 'end') {
|
|
335
|
+
const tall = Math.max(1, d.h - INSET - FOOT);
|
|
336
|
+
const base = scale.wrap ? 0 : min;
|
|
337
|
+
let u = (d.knob === 'start' ? d.sd : d.ed) + ((d.y - cy) * (d.hi - d.lo)) / tall;
|
|
338
|
+
u = base + Math.round((u - base) / step) * step;
|
|
339
|
+
if (scale.wrap) {
|
|
340
|
+
// On the turn shown, and never past the point opposite the other end, where the shorter way turns round.
|
|
341
|
+
const w = scale.wrap;
|
|
342
|
+
const other = d.knob === 'start' ? d.ed : d.sd;
|
|
343
|
+
const from = d.knob === 'start' ? other - w / 2 : other - w / 2 + step;
|
|
344
|
+
const to = d.knob === 'start' ? other + w / 2 - step : other + w / 2;
|
|
345
|
+
u = clamp(u, Math.max(d.lo + step, from), Math.min(d.hi - step, to));
|
|
346
|
+
}
|
|
347
|
+
else
|
|
348
|
+
u = clamp(u, min, max);
|
|
349
|
+
const curve = bent ?? kept.current;
|
|
350
|
+
return d.knob === 'start' ? spell(u, cur.end, curve, scale) : spell(cur.start, u, curve, scale);
|
|
351
|
+
}
|
|
352
|
+
const wide = Math.max(1, d.w - 2 * INSET);
|
|
353
|
+
const from = d.bend ?? [0, 1];
|
|
354
|
+
const i = d.knob === 'startHandle' ? 0 : 1;
|
|
355
|
+
const f = fix(clamp(from[i] + (cx - d.x) / wide, 0, 1), 2);
|
|
356
|
+
return spell(cur.start, cur.end, i === 0 ? [f, from[1]] : [from[0], f], scale);
|
|
357
|
+
};
|
|
358
|
+
const letGo = (e) => {
|
|
359
|
+
const d = drag.current;
|
|
360
|
+
if (!d || d.id !== e.pointerId)
|
|
361
|
+
return;
|
|
362
|
+
// A press handed from one knob to another: the one it left loses the pointer, which ends nothing.
|
|
363
|
+
if (e.type === 'lostpointercapture' && e.currentTarget !== d.el)
|
|
364
|
+
return;
|
|
365
|
+
drag.current = null;
|
|
366
|
+
if (d.el.hasPointerCapture(e.pointerId))
|
|
367
|
+
d.el.releasePointerCapture(e.pointerId);
|
|
368
|
+
setRested(endsAt(pending.current ? read(pending.current.value, scale) : shown));
|
|
369
|
+
setHeld(null);
|
|
370
|
+
commit();
|
|
371
|
+
};
|
|
372
|
+
const grab = (knob) => ({
|
|
373
|
+
onPointerDown: (e) => {
|
|
374
|
+
if (disabled || e.button !== 0 || !shown)
|
|
375
|
+
return;
|
|
376
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
377
|
+
const r = plot.current?.getBoundingClientRect();
|
|
378
|
+
// A press that a point and a handle both reach (a handle on or near its point) is either's until its first
|
|
379
|
+
// move says which. The knob pressed comes first, then the nearest.
|
|
380
|
+
const px = e.clientX - (r?.left ?? 0);
|
|
381
|
+
const py = e.clientY - (r?.top ?? 0);
|
|
382
|
+
const far = (k) => (k === knob ? -1 : Math.hypot(px - place(k)[0], py - place(k)[1]));
|
|
383
|
+
const nearest = (ks) => ks.filter((k) => far(k) <= REACH).sort((a, b) => far(a) - far(b))[0];
|
|
384
|
+
// The line is the line's alone: a press on it is never a point's or a handle's (those lie over it).
|
|
385
|
+
const point = knob === 'line' ? undefined : nearest(['start', 'end']);
|
|
386
|
+
const handle = knob === 'line' || !handlesShown ? undefined : nearest(['startHandle', 'endHandle']);
|
|
387
|
+
drag.current = {
|
|
388
|
+
knob,
|
|
389
|
+
open: point && handle ? { point, handle } : undefined,
|
|
390
|
+
el: e.currentTarget,
|
|
391
|
+
id: e.pointerId,
|
|
392
|
+
x: e.clientX,
|
|
393
|
+
y: e.clientY,
|
|
394
|
+
w: r && r.width > 0 ? r.width : box.w,
|
|
395
|
+
h: r && r.height > 0 ? r.height : box.h,
|
|
396
|
+
sd,
|
|
397
|
+
ed,
|
|
398
|
+
lo,
|
|
399
|
+
hi,
|
|
400
|
+
bend,
|
|
401
|
+
};
|
|
402
|
+
kept.current = bent;
|
|
403
|
+
if (mid !== null)
|
|
404
|
+
setMiddle(mid);
|
|
405
|
+
setHeld(knob);
|
|
406
|
+
},
|
|
407
|
+
onPointerMove: (e) => {
|
|
408
|
+
const d = drag.current;
|
|
409
|
+
// Made read-only mid-drag, it stops changing (as NumberField's scrub); letting go still ends the change made.
|
|
410
|
+
if (!d || d.id !== e.pointerId || disabled || !shown)
|
|
411
|
+
return;
|
|
412
|
+
if (d.open) {
|
|
413
|
+
// Its first move says which: mostly up or down, the point; mostly along, the handle.
|
|
414
|
+
const dx = e.clientX - d.x;
|
|
415
|
+
const dy = e.clientY - d.y;
|
|
416
|
+
if (Math.hypot(dx, dy) < DECIDE)
|
|
417
|
+
return;
|
|
418
|
+
const to = Math.abs(dy) > Math.abs(dx) ? d.open.point : d.open.handle;
|
|
419
|
+
d.knob = to;
|
|
420
|
+
d.open = undefined;
|
|
421
|
+
// The pointer and the focus go to the knob it moves, so its keys move what was dragged.
|
|
422
|
+
const el = knobEl[to].current;
|
|
423
|
+
if (el) {
|
|
424
|
+
if (el !== d.el) {
|
|
425
|
+
if (d.el.hasPointerCapture(e.pointerId))
|
|
426
|
+
d.el.releasePointerCapture(e.pointerId);
|
|
427
|
+
el.setPointerCapture(e.pointerId);
|
|
428
|
+
d.el = el;
|
|
429
|
+
}
|
|
430
|
+
el.focus({ preventScroll: true });
|
|
431
|
+
}
|
|
432
|
+
setHeld(d.knob);
|
|
433
|
+
}
|
|
434
|
+
tell(dragged(d, e.clientX, e.clientY, shown));
|
|
435
|
+
},
|
|
436
|
+
onPointerUp: letGo,
|
|
437
|
+
onPointerCancel: letGo,
|
|
438
|
+
onLostPointerCapture: letGo,
|
|
439
|
+
});
|
|
440
|
+
// A slider's keys: one step (a handle 0.01), Shift or Page Up and Down ten, Home and End to its bounds.
|
|
441
|
+
const keys = (knob) => (e) => {
|
|
442
|
+
const by = BY[e.key] ?? 0;
|
|
443
|
+
const toward = e.key === 'Home' ? -1 : e.key === 'End' ? 1 : 0;
|
|
444
|
+
if (!by && !toward)
|
|
445
|
+
return;
|
|
446
|
+
// Kept from the page, read-only too (as NumberField's are); read-only, they change nothing.
|
|
447
|
+
e.preventDefault();
|
|
448
|
+
if (disabled || !shown)
|
|
449
|
+
return;
|
|
450
|
+
if (!nudging.current) {
|
|
451
|
+
kept.current = bent;
|
|
452
|
+
if (mid !== null)
|
|
453
|
+
setMiddle(mid);
|
|
454
|
+
setRested(null);
|
|
455
|
+
setKeyed(knob);
|
|
456
|
+
}
|
|
457
|
+
nudging.current = true;
|
|
458
|
+
const times = e.shiftKey && Math.abs(by) === 1 ? by * 10 : by;
|
|
459
|
+
if (knob === 'start' || knob === 'end') {
|
|
460
|
+
const top = scale.wrap && max >= scale.wrap ? scale.wrap - step : max;
|
|
461
|
+
const v = knob === 'start' ? shown.start : shown.end;
|
|
462
|
+
const u = toward ? (toward < 0 ? min : top) : v + times * step;
|
|
463
|
+
const curve = bent ?? kept.current;
|
|
464
|
+
tell(knob === 'start' ? spell(u, shown.end, curve, scale) : spell(shown.start, u, curve, scale));
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const c = bend ?? [0, 1];
|
|
468
|
+
const i = knob === 'startHandle' ? 0 : 1;
|
|
469
|
+
const f = toward ? (toward < 0 ? 0 : 1) : fix(clamp(c[i] + times * 0.01, 0, 1), 2);
|
|
470
|
+
tell(spell(shown.start, shown.end, i === 0 ? [f, c[1]] : [c[0], f], scale));
|
|
471
|
+
};
|
|
472
|
+
// Arrow keys held or pressed in a row are one change, ended as they are let go or the focus leaves.
|
|
473
|
+
const nudged = () => {
|
|
474
|
+
if (!nudging.current)
|
|
475
|
+
return;
|
|
476
|
+
nudging.current = false;
|
|
477
|
+
setKeyed(null);
|
|
478
|
+
commit();
|
|
479
|
+
};
|
|
480
|
+
// A number typed, stepped or scrubbed: with nothing shown, a flat value. A scrub is told as it moves and ended as it
|
|
481
|
+
// is let go, so a curve it passes through flat comes back, as under a drag.
|
|
482
|
+
const typed = (which, v) => {
|
|
483
|
+
if (disabled)
|
|
484
|
+
return;
|
|
485
|
+
if (!shown)
|
|
486
|
+
return tell(spell(v, v, undefined, scale));
|
|
487
|
+
if (!pending.current)
|
|
488
|
+
kept.current = bent;
|
|
489
|
+
const curve = bent ?? kept.current;
|
|
490
|
+
tell(which === 'start' ? spell(v, shown.end, curve, scale) : spell(shown.start, v, curve, scale));
|
|
491
|
+
};
|
|
492
|
+
// Linear or Curve, one press: Curve starts at [0.42, 0.58].
|
|
493
|
+
const choose = (curved) => {
|
|
494
|
+
if (disabled || !shown || flat || curved === (bent !== undefined))
|
|
495
|
+
return;
|
|
496
|
+
tell(spell(shown.start, shown.end, curved ? CURVE : undefined, scale));
|
|
497
|
+
commit();
|
|
498
|
+
};
|
|
499
|
+
// A radio group: one Tab stop, the arrow keys move and choose (two words: any arrow goes to the other), Home and End.
|
|
500
|
+
const formKeys = (e) => {
|
|
501
|
+
if (!/^(Arrow(Left|Right|Up|Down)|Home|End)$/.test(e.key))
|
|
502
|
+
return;
|
|
503
|
+
e.preventDefault();
|
|
504
|
+
if (disabled)
|
|
505
|
+
return;
|
|
506
|
+
const curved = e.key === 'Home' ? false : e.key === 'End' ? true : bent === undefined;
|
|
507
|
+
choose(curved);
|
|
508
|
+
forms.current?.querySelectorAll('[role="radio"]')[curved ? 1 : 0]?.focus();
|
|
509
|
+
};
|
|
510
|
+
const knobOf = (k) => {
|
|
511
|
+
const point = k === 'start' || k === 'end';
|
|
512
|
+
const v = k === 'start' || k === 'startHandle' ? shown.start : shown.end;
|
|
513
|
+
const f = k === 'start' ? 0 : k === 'end' ? 1 : bend[k === 'startHandle' ? 0 : 1];
|
|
514
|
+
const [left, top] = place(k);
|
|
515
|
+
const name = { start: labels.start, end: labels.end, startHandle: labels.startHandle, endHandle: labels.endHandle }[k];
|
|
516
|
+
const goes = k === 'startHandle' ? startHandleGoes : k === 'endHandle' ? endHandleGoes : null;
|
|
517
|
+
return (_jsx("div", { ref: knobEl[k], role: "slider", tabIndex: 0, className: "newtone-curve-field-knob", "data-knob": point ? 'point' : 'handle', "data-held": held === k ? '' : undefined, "aria-label": `${name}: ${label}`, "aria-orientation": point ? 'vertical' : 'horizontal', "aria-valuemin": point ? min : 0, "aria-valuemax": point ? max : 1, "aria-valuenow": point ? v : f, "aria-valuetext": point ? say(v) : along(f), "aria-disabled": disabled || undefined, "aria-describedby": state ? stateId : undefined, style: { left: r2(left), top: r2(top) }, onKeyDown: keys(k), onKeyUp: nudged, onFocus: goes?.onFocus, onBlur: (e) => {
|
|
518
|
+
nudged();
|
|
519
|
+
goes?.onBlur(e);
|
|
520
|
+
}, ...grab(k) }));
|
|
521
|
+
};
|
|
522
|
+
const curved = bent !== undefined;
|
|
523
|
+
return (_jsxs("div", { ...rest, className: ['newtone-curve-field', className].filter(Boolean).join(' '), "data-same": same ? '' : undefined, "data-disabled": disabled ? '' : undefined, "data-read-only": readOnly ? '' : undefined, "data-ground": painted ? '' : undefined, children: [plotOnly ? null : (_jsxs("div", { className: "newtone-curve-field-head", children: [_jsx(Text, { as: "span", scale: "body-sm", weight: "medium", lines: 1, children: label }), state ? (_jsx(Text, { as: "span", scale: "caption", tone: "secondary", lines: 1, id: stateId, children: state })) : null] })), _jsxs("div", { ref: plot, className: "newtone-curve-field-plot", role: readOnly ? 'img' : undefined, "aria-label": readOnly ? pictured : undefined, onFocus: knobsShown ? knobsGo.onFocus : undefined, onBlur: knobsShown ? knobsGo.onBlur : undefined, children: [_jsx("div", { className: "newtone-curve-field-frame", children: painted
|
|
524
|
+
? painted.map((c, i) => (_jsx("div", { className: "newtone-curve-field-ground", "aria-hidden": "true", style: { left: `${c.left}%`, width: c.left + c.width >= 100 ? `${c.width}%` : `calc(${c.width}% + 1px)`, backgroundImage: c.image } }, i)))
|
|
525
|
+
: null }), _jsxs("svg", { className: "newtone-curve-field-drawing", "aria-hidden": "true", focusable: "false", children: [_jsx("defs", { children: _jsx("clipPath", { id: clipId, children: _jsx("rect", { x: INSET, y: INSET, width: aw, height: ah }) }) }), _jsx("g", { clipPath: `url(#${clipId})`, children: guideLines.map((points, i) => (_jsx("polyline", { className: "newtone-curve-field-guide", "data-guide": i % 3, points: points }, i))) }), line && painted ? _jsx("path", { className: "newtone-curve-field-halo", d: line }) : null, line ? _jsx("path", { className: "newtone-curve-field-line", d: line }) : null, line && knobsShown ? (_jsx("path", { className: "newtone-curve-field-hit", d: line, "data-held": held === 'line' ? '' : undefined, ...grab('line') })) : null, _jsx("g", { clipPath: `url(#${clipId})`, children: dots.map((d) => (_jsx("circle", { className: "newtone-curve-field-dot", cx: r2(d.x), cy: r2(d.y), r: 1.5 }, d.i))) }), handlesShown && bend ? (_jsxs("g", { className: "newtone-curve-field-arms", children: [_jsx("line", { x1: r2(X(0)), y1: r2(Y(sd)), x2: r2(X(bend[0])), y2: r2(Y(sd)) }), _jsx("line", { x1: r2(X(1)), y1: r2(Y(ed)), x2: r2(X(bend[1])), y2: r2(Y(ed)) })] })) : null] }), _jsx("div", { className: "newtone-curve-field-steps", "aria-hidden": "true", children: numbered.map((i) => (_jsx(Text, { as: "span", scale: "caption", tone: "secondary", figures: "tabular", className: "newtone-curve-field-step", style: { left: r2(X(at(i))), top: INSET + ah + 4 }, children: i }, i))) }), knobsShown ? (_jsxs(_Fragment, { children: [knobOf('start'), handlesShown ? knobOf('startHandle') : null, handlesShown ? knobOf('endHandle') : null, knobOf('end')] })) : null] }), guides && guides.length ? (_jsx("ul", { className: "newtone-curve-field-guides", children: guides.map((g, i) => (_jsxs("li", { className: "newtone-curve-field-guide-name", children: [_jsx("svg", { className: "newtone-curve-field-sample", width: "16", height: "8", "aria-hidden": "true", focusable: "false", children: _jsx("line", { className: "newtone-curve-field-guide", "data-guide": i % 3, x1: "0", x2: "16", y1: "4.5", y2: "4.5" }) }), _jsx(Text, { as: "span", scale: "caption", tone: "secondary", children: g.label })] }, i))) })) : null, readOnly || plotOnly ? null : (_jsxs("div", { ref: row, className: "newtone-curve-field-row", children: [_jsx(NumberField, { className: "newtone-curve-field-number", label: labels.start, name: `${labels.start}: ${label}`, value: shown ? shown.start : null, min: min, max: max, step: step, precision: precision, wrap: scale.wrap, unit: unit, disabledFocusable: disabled, onChange: (v) => typed('start', v), onCommit: commit }), _jsx(NumberField, { className: "newtone-curve-field-number", label: labels.end, name: `${labels.end}: ${label}`, value: shown ? shown.end : null, min: min, max: max, step: step, precision: precision, wrap: scale.wrap, unit: unit, disabledFocusable: disabled, onChange: (v) => typed('end', v), onCommit: commit }), formsShown ? (_jsx("div", { ref: forms, role: "radiogroup", "aria-label": label, "aria-disabled": disabled || undefined, className: "newtone-curve-field-forms", onKeyDown: formKeys, onFocus: formsGo.onFocus, onBlur: formsGo.onBlur, children: [false, true].map((c) => (_jsx("button", { type: "button", role: "radio", "aria-checked": c === curved, tabIndex: c === curved ? 0 : -1, "aria-disabled": disabled || undefined, className: "newtone-curve-field-form", onClick: () => choose(c), children: _jsx(Text, { as: "span", scale: "body-sm", lines: 1, children: c ? labels.curve : labels.linear }) }, c ? 'curve' : 'linear'))) })) : null, departs && back ? (_jsx(Button, { size: "sm", variant: "tertiary", className: "newtone-curve-field-reset", disabledFocusable: disabled, "aria-label": `${back}: ${label}`, ...pressBack, onClick: () => {
|
|
526
|
+
resetting();
|
|
527
|
+
pending.current = null;
|
|
528
|
+
onChange?.(null);
|
|
529
|
+
onCommit?.(null);
|
|
530
|
+
}, children: back })) : null] }))] }));
|
|
531
|
+
}
|
|
532
|
+
//# sourceMappingURL=curve-field.js.map
|