@molecule/app-adjustment-slider-react 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +115 -0
- package/dist/AdjustmentSlider.d.ts +36 -0
- package/dist/AdjustmentSlider.d.ts.map +1 -0
- package/dist/AdjustmentSlider.js +95 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/utilities.d.ts +45 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +78 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { AdjustmentSliderProps } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Bipolar (zero-center) adjustment slider — a labelled `<input type="range">`
|
|
5
|
+
* tuned for photo-editor / DAW / animation parameter controls (brightness,
|
|
6
|
+
* contrast, saturation, exposure, gain, pan, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Behaviour:
|
|
9
|
+
* - When `bipolar` is `true` (default), a center mark is rendered at zero
|
|
10
|
+
* and the reset target is `0`. When `false`, the slider is unipolar and
|
|
11
|
+
* the reset target is `min`.
|
|
12
|
+
* - Double-clicking the input resets the value (calling `onReset` if
|
|
13
|
+
* provided, otherwise emitting `defaultResetValue(min, bipolar)` via
|
|
14
|
+
* `onChange`).
|
|
15
|
+
* - Up/Right arrows nudge by `step`; Down/Left arrows nudge by `-step`.
|
|
16
|
+
* Holding Shift multiplies the nudge by 10.
|
|
17
|
+
* - The numeric value display is formatted via `format` if supplied,
|
|
18
|
+
* otherwise via `value + (unit || '')`.
|
|
19
|
+
*
|
|
20
|
+
* @param props - Component props.
|
|
21
|
+
* @param props.label - Visible control label.
|
|
22
|
+
* @param props.value - Current numeric value.
|
|
23
|
+
* @param props.onChange - Called whenever the value changes.
|
|
24
|
+
* @param props.min - Lower bound (default `-100`).
|
|
25
|
+
* @param props.max - Upper bound (default `100`).
|
|
26
|
+
* @param props.step - Step increment (default `1`).
|
|
27
|
+
* @param props.bipolar - Bipolar / zero-center mode (default `true`).
|
|
28
|
+
* @param props.unit - Optional unit suffix appended to the default formatter.
|
|
29
|
+
* @param props.format - Optional custom value formatter.
|
|
30
|
+
* @param props.onReset - Optional reset handler (overrides default reset).
|
|
31
|
+
* @param props.className - Optional extra classes for the outer container.
|
|
32
|
+
* @param props.dataMolId - Optional `data-mol-id` for the outer container.
|
|
33
|
+
* @returns The rendered adjustment slider.
|
|
34
|
+
*/
|
|
35
|
+
export declare function AdjustmentSlider({ label, value, onChange, min, max, step, bipolar, unit, format, onReset, className, dataMolId, }: AdjustmentSliderProps): ReactElement;
|
|
36
|
+
//# sourceMappingURL=AdjustmentSlider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdjustmentSlider.d.ts","sourceRoot":"","sources":["../src/AdjustmentSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,YAAY,EAAE,MAAM,OAAO,CAAA;AAMrE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,KAAK,EACL,QAAQ,EACR,GAAU,EACV,GAAS,EACT,IAAQ,EACR,OAAc,EACd,IAAI,EACJ,MAAM,EACN,OAAO,EACP,SAAS,EACT,SAAS,GACV,EAAE,qBAAqB,GAAG,YAAY,CA6GtC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useRef } from 'react';
|
|
3
|
+
import { useTranslation } from '@molecule/app-react';
|
|
4
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
5
|
+
import { clampStep, defaultFormatter, defaultResetValue, keyboardNudge } from './utilities.js';
|
|
6
|
+
/**
|
|
7
|
+
* Bipolar (zero-center) adjustment slider — a labelled `<input type="range">`
|
|
8
|
+
* tuned for photo-editor / DAW / animation parameter controls (brightness,
|
|
9
|
+
* contrast, saturation, exposure, gain, pan, etc.).
|
|
10
|
+
*
|
|
11
|
+
* Behaviour:
|
|
12
|
+
* - When `bipolar` is `true` (default), a center mark is rendered at zero
|
|
13
|
+
* and the reset target is `0`. When `false`, the slider is unipolar and
|
|
14
|
+
* the reset target is `min`.
|
|
15
|
+
* - Double-clicking the input resets the value (calling `onReset` if
|
|
16
|
+
* provided, otherwise emitting `defaultResetValue(min, bipolar)` via
|
|
17
|
+
* `onChange`).
|
|
18
|
+
* - Up/Right arrows nudge by `step`; Down/Left arrows nudge by `-step`.
|
|
19
|
+
* Holding Shift multiplies the nudge by 10.
|
|
20
|
+
* - The numeric value display is formatted via `format` if supplied,
|
|
21
|
+
* otherwise via `value + (unit || '')`.
|
|
22
|
+
*
|
|
23
|
+
* @param props - Component props.
|
|
24
|
+
* @param props.label - Visible control label.
|
|
25
|
+
* @param props.value - Current numeric value.
|
|
26
|
+
* @param props.onChange - Called whenever the value changes.
|
|
27
|
+
* @param props.min - Lower bound (default `-100`).
|
|
28
|
+
* @param props.max - Upper bound (default `100`).
|
|
29
|
+
* @param props.step - Step increment (default `1`).
|
|
30
|
+
* @param props.bipolar - Bipolar / zero-center mode (default `true`).
|
|
31
|
+
* @param props.unit - Optional unit suffix appended to the default formatter.
|
|
32
|
+
* @param props.format - Optional custom value formatter.
|
|
33
|
+
* @param props.onReset - Optional reset handler (overrides default reset).
|
|
34
|
+
* @param props.className - Optional extra classes for the outer container.
|
|
35
|
+
* @param props.dataMolId - Optional `data-mol-id` for the outer container.
|
|
36
|
+
* @returns The rendered adjustment slider.
|
|
37
|
+
*/
|
|
38
|
+
export function AdjustmentSlider({ label, value, onChange, min = -100, max = 100, step = 1, bipolar = true, unit, format, onReset, className, dataMolId, }) {
|
|
39
|
+
const cm = getClassMap();
|
|
40
|
+
const { t } = useTranslation();
|
|
41
|
+
const inputRef = useRef(null);
|
|
42
|
+
const formatter = useMemo(() => format ?? defaultFormatter(unit), [format, unit]);
|
|
43
|
+
const resetTarget = useMemo(() => defaultResetValue(min, bipolar), [min, bipolar]);
|
|
44
|
+
const emit = useCallback((next) => {
|
|
45
|
+
const normalized = clampStep(next, min, max, step);
|
|
46
|
+
if (normalized !== value)
|
|
47
|
+
onChange(normalized);
|
|
48
|
+
}, [max, min, onChange, step, value]);
|
|
49
|
+
const performReset = useCallback(() => {
|
|
50
|
+
if (onReset) {
|
|
51
|
+
onReset();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
emit(resetTarget);
|
|
55
|
+
}, [emit, onReset, resetTarget]);
|
|
56
|
+
const handleChange = useCallback((e) => {
|
|
57
|
+
emit(Number(e.target.value));
|
|
58
|
+
}, [emit]);
|
|
59
|
+
const handleKeyDown = useCallback((e) => {
|
|
60
|
+
// Native <input type="range"> handles arrows already, but it ignores
|
|
61
|
+
// the Shift modifier — intercept and apply our 10x nudge.
|
|
62
|
+
if (!e.shiftKey)
|
|
63
|
+
return;
|
|
64
|
+
const delta = keyboardNudge(step, true);
|
|
65
|
+
let next;
|
|
66
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowRight')
|
|
67
|
+
next = value + delta;
|
|
68
|
+
else if (e.key === 'ArrowDown' || e.key === 'ArrowLeft')
|
|
69
|
+
next = value - delta;
|
|
70
|
+
if (next === undefined)
|
|
71
|
+
return;
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
emit(next);
|
|
74
|
+
}, [emit, step, value]);
|
|
75
|
+
const handleDoubleClick = useCallback(() => {
|
|
76
|
+
performReset();
|
|
77
|
+
}, [performReset]);
|
|
78
|
+
const display = formatter(value);
|
|
79
|
+
const showCenterMark = bipolar && min < 0 && max > 0;
|
|
80
|
+
// Position center mark proportionally between min..max (0..100%).
|
|
81
|
+
const centerPct = showCenterMark ? ((0 - min) / (max - min)) * 100 : 50;
|
|
82
|
+
const resetAria = t('adjustmentSlider.reset.aria', { label }, { defaultValue: `Reset ${label}` });
|
|
83
|
+
const sliderAria = t('adjustmentSlider.aria', { label }, { defaultValue: label });
|
|
84
|
+
return (_jsxs("div", { className: cm.cn(cm.stack(1), className), "data-mol-id": dataMolId ?? 'adjustment-slider', children: [_jsxs("div", { className: cm.flex({ align: 'center', justify: 'between', gap: 'sm' }), children: [_jsx("span", { className: cm.cn(cm.textSize('sm'), cm.fontWeight('medium')), children: label }), _jsx("button", { type: "button", onClick: performReset, "aria-label": resetAria, className: cm.cn(cm.textSize('xs')), "data-mol-id": "adjustment-slider-reset", style: { background: 'transparent', border: 'none', cursor: 'pointer' }, children: display })] }), _jsxs("div", { style: { position: 'relative' }, children: [showCenterMark && (_jsx("span", { "aria-hidden": "true", "data-mol-id": "adjustment-slider-center-mark", style: {
|
|
85
|
+
position: 'absolute',
|
|
86
|
+
left: `${centerPct}%`,
|
|
87
|
+
top: '50%',
|
|
88
|
+
width: 1,
|
|
89
|
+
height: 8,
|
|
90
|
+
transform: 'translate(-50%, -50%)',
|
|
91
|
+
background: 'currentColor',
|
|
92
|
+
opacity: 0.5,
|
|
93
|
+
pointerEvents: 'none',
|
|
94
|
+
} })), _jsx("input", { ref: inputRef, type: "range", min: min, max: max, step: step, value: value, onChange: handleChange, onKeyDown: handleKeyDown, onDoubleClick: handleDoubleClick, "aria-label": sliderAria, "data-mol-id": "adjustment-slider-input", style: { width: '100%' } })] })] }));
|
|
95
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adjustment slider feature for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Bipolar (zero-center) numeric slider tuned for photo-editor / DAW /
|
|
5
|
+
* animation parameter controls (brightness, contrast, saturation, exposure,
|
|
6
|
+
* gain, pan, etc.). Pairs well with `@molecule/app-feature-image-canvas-react`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { AdjustmentSlider } from '@molecule/app-adjustment-slider-react'
|
|
11
|
+
*
|
|
12
|
+
* <AdjustmentSlider
|
|
13
|
+
* label="Exposure"
|
|
14
|
+
* value={exposure}
|
|
15
|
+
* onChange={setExposure}
|
|
16
|
+
* min={-100}
|
|
17
|
+
* max={100}
|
|
18
|
+
* step={1}
|
|
19
|
+
* bipolar
|
|
20
|
+
* unit="%"
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
export * from './AdjustmentSlider.js';
|
|
27
|
+
export * from './types.js';
|
|
28
|
+
export * from './utilities.js';
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adjustment slider feature for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Bipolar (zero-center) numeric slider tuned for photo-editor / DAW /
|
|
5
|
+
* animation parameter controls (brightness, contrast, saturation, exposure,
|
|
6
|
+
* gain, pan, etc.). Pairs well with `@molecule/app-feature-image-canvas-react`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { AdjustmentSlider } from '@molecule/app-adjustment-slider-react'
|
|
11
|
+
*
|
|
12
|
+
* <AdjustmentSlider
|
|
13
|
+
* label="Exposure"
|
|
14
|
+
* value={exposure}
|
|
15
|
+
* onChange={setExposure}
|
|
16
|
+
* min={-100}
|
|
17
|
+
* max={100}
|
|
18
|
+
* step={1}
|
|
19
|
+
* bipolar
|
|
20
|
+
* unit="%"
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
export * from './AdjustmentSlider.js';
|
|
27
|
+
export * from './types.js';
|
|
28
|
+
export * from './utilities.js';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the AdjustmentSlider feature package.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Function signature used to format the rendered numeric value. */
|
|
7
|
+
export type AdjustmentSliderFormatter = (value: number) => string;
|
|
8
|
+
/** Public props for `<AdjustmentSlider>`. */
|
|
9
|
+
export interface AdjustmentSliderProps {
|
|
10
|
+
/** Visible label (rendered to the left of the slider). */
|
|
11
|
+
label: string;
|
|
12
|
+
/** Current numeric value. */
|
|
13
|
+
value: number;
|
|
14
|
+
/** Called whenever the slider value changes. */
|
|
15
|
+
onChange: (value: number) => void;
|
|
16
|
+
/** Lower bound. Defaults to `-100`. */
|
|
17
|
+
min?: number;
|
|
18
|
+
/** Upper bound. Defaults to `100`. */
|
|
19
|
+
max?: number;
|
|
20
|
+
/** Step increment. Defaults to `1`. */
|
|
21
|
+
step?: number;
|
|
22
|
+
/**
|
|
23
|
+
* When `true` (default), the slider is bipolar with a center mark at zero
|
|
24
|
+
* and double-click / Reset returns the value to `0`. When `false`, the
|
|
25
|
+
* slider is unipolar (a normal range slider) and double-click resets to
|
|
26
|
+
* `min`.
|
|
27
|
+
*/
|
|
28
|
+
bipolar?: boolean;
|
|
29
|
+
/** Optional unit suffix (e.g. `'%'`, `'dB'`) appended to the default formatter. */
|
|
30
|
+
unit?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional formatter overriding the default `value + (unit || '')` display.
|
|
33
|
+
* Useful for rendering e.g. `+12` (signed) or `1.4 EV`.
|
|
34
|
+
*/
|
|
35
|
+
format?: AdjustmentSliderFormatter;
|
|
36
|
+
/**
|
|
37
|
+
* Optional reset handler. When provided, double-clicking the slider OR
|
|
38
|
+
* pressing the visual Reset button calls this instead of resetting to
|
|
39
|
+
* the default reset value.
|
|
40
|
+
*/
|
|
41
|
+
onReset?: () => void;
|
|
42
|
+
/** Optional extra class names appended to the outer container. */
|
|
43
|
+
className?: string;
|
|
44
|
+
/** Optional `data-mol-id` for AI-agent / E2E targeting. */
|
|
45
|
+
dataMolId?: string;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oEAAoE;AACpE,MAAM,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AAEjE,6CAA6C;AAC7C,MAAM,WAAW,qBAAqB;IACpC,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAA;IACb,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,uCAAuC;IACvC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,MAAM,CAAC,EAAE,yBAAyB,CAAA;IAClC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the AdjustmentSlider component.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { AdjustmentSliderFormatter } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Clamp a numeric value to the inclusive `[min, max]` range, snapping to the
|
|
9
|
+
* nearest multiple of `step` measured from `min`. Does not assume `min === 0`
|
|
10
|
+
* (so bipolar `[-100, 100]` works correctly with non-integer steps).
|
|
11
|
+
*
|
|
12
|
+
* @param value - The raw value to normalise.
|
|
13
|
+
* @param min - Inclusive lower bound.
|
|
14
|
+
* @param max - Inclusive upper bound.
|
|
15
|
+
* @param step - Step increment (must be > 0).
|
|
16
|
+
* @returns The clamped + step-snapped value.
|
|
17
|
+
*/
|
|
18
|
+
export declare function clampStep(value: number, min: number, max: number, step: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Compute the value the slider should reset to when double-clicked.
|
|
21
|
+
*
|
|
22
|
+
* @param min - Inclusive lower bound.
|
|
23
|
+
* @param bipolar - Whether the slider is in bipolar (zero-center) mode.
|
|
24
|
+
* @returns `0` for bipolar sliders, `min` otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export declare function defaultResetValue(min: number, bipolar: boolean): number;
|
|
27
|
+
/**
|
|
28
|
+
* Build the default value formatter — appends an optional unit suffix.
|
|
29
|
+
*
|
|
30
|
+
* @param unit - Optional unit string (e.g. `'%'`).
|
|
31
|
+
* @returns A formatter producing `"<value><unit>"`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function defaultFormatter(unit?: string): AdjustmentSliderFormatter;
|
|
34
|
+
/**
|
|
35
|
+
* Compute the keyboard nudge step for arrow keys.
|
|
36
|
+
*
|
|
37
|
+
* Plain arrow → `step`. Shift-modifier → `step * 10` so users can move in
|
|
38
|
+
* coarser increments. Always at least `step`.
|
|
39
|
+
*
|
|
40
|
+
* @param step - The base step increment.
|
|
41
|
+
* @param shift - Whether the Shift modifier is held.
|
|
42
|
+
* @returns The effective per-keypress delta.
|
|
43
|
+
*/
|
|
44
|
+
export declare function keyboardNudge(step: number, shift: boolean): number;
|
|
45
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAUvF;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,yBAAyB,CAGzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAElE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the AdjustmentSlider component.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Clamp a numeric value to the inclusive `[min, max]` range, snapping to the
|
|
8
|
+
* nearest multiple of `step` measured from `min`. Does not assume `min === 0`
|
|
9
|
+
* (so bipolar `[-100, 100]` works correctly with non-integer steps).
|
|
10
|
+
*
|
|
11
|
+
* @param value - The raw value to normalise.
|
|
12
|
+
* @param min - Inclusive lower bound.
|
|
13
|
+
* @param max - Inclusive upper bound.
|
|
14
|
+
* @param step - Step increment (must be > 0).
|
|
15
|
+
* @returns The clamped + step-snapped value.
|
|
16
|
+
*/
|
|
17
|
+
export function clampStep(value, min, max, step) {
|
|
18
|
+
if (!Number.isFinite(value))
|
|
19
|
+
return min;
|
|
20
|
+
const clamped = Math.min(Math.max(value, min), max);
|
|
21
|
+
if (!(step > 0))
|
|
22
|
+
return clamped;
|
|
23
|
+
const snapped = min + Math.round((clamped - min) / step) * step;
|
|
24
|
+
// Re-clamp in case rounding pushed us across max.
|
|
25
|
+
const reclamped = Math.min(Math.max(snapped, min), max);
|
|
26
|
+
// Trim float drift so e.g. step=0.1 doesn't surface 0.30000000000000004.
|
|
27
|
+
const decimals = decimalsForStep(step);
|
|
28
|
+
return Number(reclamped.toFixed(decimals));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compute the value the slider should reset to when double-clicked.
|
|
32
|
+
*
|
|
33
|
+
* @param min - Inclusive lower bound.
|
|
34
|
+
* @param bipolar - Whether the slider is in bipolar (zero-center) mode.
|
|
35
|
+
* @returns `0` for bipolar sliders, `min` otherwise.
|
|
36
|
+
*/
|
|
37
|
+
export function defaultResetValue(min, bipolar) {
|
|
38
|
+
return bipolar ? 0 : min;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Build the default value formatter — appends an optional unit suffix.
|
|
42
|
+
*
|
|
43
|
+
* @param unit - Optional unit string (e.g. `'%'`).
|
|
44
|
+
* @returns A formatter producing `"<value><unit>"`.
|
|
45
|
+
*/
|
|
46
|
+
export function defaultFormatter(unit) {
|
|
47
|
+
const suffix = unit ?? '';
|
|
48
|
+
return (n) => `${n}${suffix}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compute the keyboard nudge step for arrow keys.
|
|
52
|
+
*
|
|
53
|
+
* Plain arrow → `step`. Shift-modifier → `step * 10` so users can move in
|
|
54
|
+
* coarser increments. Always at least `step`.
|
|
55
|
+
*
|
|
56
|
+
* @param step - The base step increment.
|
|
57
|
+
* @param shift - Whether the Shift modifier is held.
|
|
58
|
+
* @returns The effective per-keypress delta.
|
|
59
|
+
*/
|
|
60
|
+
export function keyboardNudge(step, shift) {
|
|
61
|
+
return shift ? step * 10 : step;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Number of decimal places implied by the step value (for fixed-format
|
|
65
|
+
* snapping).
|
|
66
|
+
*
|
|
67
|
+
* @param step - Step increment.
|
|
68
|
+
* @returns Decimal-place count to round to.
|
|
69
|
+
*/
|
|
70
|
+
function decimalsForStep(step) {
|
|
71
|
+
if (!Number.isFinite(step) || step <= 0)
|
|
72
|
+
return 0;
|
|
73
|
+
const s = String(step);
|
|
74
|
+
const dot = s.indexOf('.');
|
|
75
|
+
if (dot === -1)
|
|
76
|
+
return 0;
|
|
77
|
+
return Math.min(s.length - dot - 1, 12);
|
|
78
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-adjustment-slider-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Bipolar (zero-center) adjustment slider for photo-editor / DAW / animation parameters (brightness, exposure, gain, etc.) with double-click reset and arrow-key nudging",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"adjustment",
|
|
25
|
+
"slider",
|
|
26
|
+
"bipolar",
|
|
27
|
+
"photo-editor",
|
|
28
|
+
"react"
|
|
29
|
+
],
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@molecule/app-react": "^1.0.0",
|
|
33
|
+
"@molecule/app-ui": "^1.0.0",
|
|
34
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@molecule/app-i18n": "1.0.0",
|
|
38
|
+
"@molecule/app-react": "1.0.0",
|
|
39
|
+
"@molecule/app-ui": "1.0.0",
|
|
40
|
+
"@testing-library/react": "16.3.2",
|
|
41
|
+
"@types/node": "26.1.2",
|
|
42
|
+
"@types/react": "19.2.17",
|
|
43
|
+
"jsdom": "30.0.1",
|
|
44
|
+
"react": "19.2.8",
|
|
45
|
+
"react-dom": "19.2.8",
|
|
46
|
+
"typescript": "6.0.3",
|
|
47
|
+
"vitest": "4.1.10"
|
|
48
|
+
}
|
|
49
|
+
}
|