@tremolo-ui/svelte 0.7.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 +21 -0
- package/README.md +13 -0
- package/dist/actions/drag-value.d.ts +22 -0
- package/dist/actions/drag-value.d.ts.map +1 -0
- package/dist/actions/drag-value.js +30 -0
- package/dist/actions/drag.d.ts +14 -0
- package/dist/actions/drag.d.ts.map +1 -0
- package/dist/actions/drag.js +22 -0
- package/dist/actions/drop-zone.d.ts +12 -0
- package/dist/actions/drop-zone.d.ts.map +1 -0
- package/dist/actions/drop-zone.js +20 -0
- package/dist/actions/long-press.d.ts +11 -0
- package/dist/actions/long-press.d.ts.map +1 -0
- package/dist/actions/long-press.js +24 -0
- package/dist/actions/wheel.d.ts +15 -0
- package/dist/actions/wheel.d.ts.map +1 -0
- package/dist/actions/wheel.js +32 -0
- package/dist/components/AnimationCanvas/AnimationCanvas.svelte +69 -0
- package/dist/components/AnimationCanvas/AnimationCanvas.svelte.d.ts +7 -0
- package/dist/components/AnimationCanvas/AnimationCanvas.svelte.d.ts.map +1 -0
- package/dist/components/AnimationCanvas/types.d.ts +46 -0
- package/dist/components/AnimationCanvas/types.d.ts.map +1 -0
- package/dist/components/AnimationCanvas/types.js +1 -0
- package/dist/components/DropZone/Root.svelte +47 -0
- package/dist/components/DropZone/Root.svelte.d.ts +7 -0
- package/dist/components/DropZone/Root.svelte.d.ts.map +1 -0
- package/dist/components/DropZone/index.d.ts +2 -0
- package/dist/components/DropZone/index.d.ts.map +1 -0
- package/dist/components/DropZone/index.js +1 -0
- package/dist/components/DropZone/types.d.ts +26 -0
- package/dist/components/DropZone/types.d.ts.map +1 -0
- package/dist/components/DropZone/types.js +1 -0
- package/dist/components/FileInput/Root.svelte +68 -0
- package/dist/components/FileInput/Root.svelte.d.ts +7 -0
- package/dist/components/FileInput/Root.svelte.d.ts.map +1 -0
- package/dist/components/FileInput/Trigger.svelte +28 -0
- package/dist/components/FileInput/Trigger.svelte.d.ts +11 -0
- package/dist/components/FileInput/Trigger.svelte.d.ts.map +1 -0
- package/dist/components/FileInput/context.d.ts +10 -0
- package/dist/components/FileInput/context.d.ts.map +1 -0
- package/dist/components/FileInput/context.js +5 -0
- package/dist/components/FileInput/index.d.ts +3 -0
- package/dist/components/FileInput/index.d.ts.map +1 -0
- package/dist/components/FileInput/index.js +2 -0
- package/dist/components/FileInput/types.d.ts +28 -0
- package/dist/components/FileInput/types.d.ts.map +1 -0
- package/dist/components/FileInput/types.js +1 -0
- package/dist/components/Knob/ActiveLine.svelte +29 -0
- package/dist/components/Knob/ActiveLine.svelte.d.ts +6 -0
- package/dist/components/Knob/ActiveLine.svelte.d.ts.map +1 -0
- package/dist/components/Knob/InactiveLine.svelte +41 -0
- package/dist/components/Knob/InactiveLine.svelte.d.ts +6 -0
- package/dist/components/Knob/InactiveLine.svelte.d.ts.map +1 -0
- package/dist/components/Knob/Root.svelte +189 -0
- package/dist/components/Knob/Root.svelte.d.ts +10 -0
- package/dist/components/Knob/Root.svelte.d.ts.map +1 -0
- package/dist/components/Knob/SVGRoot.svelte +28 -0
- package/dist/components/Knob/SVGRoot.svelte.d.ts +13 -0
- package/dist/components/Knob/SVGRoot.svelte.d.ts.map +1 -0
- package/dist/components/Knob/Thumb.svelte +43 -0
- package/dist/components/Knob/Thumb.svelte.d.ts +7 -0
- package/dist/components/Knob/Thumb.svelte.d.ts.map +1 -0
- package/dist/components/Knob/context.d.ts +22 -0
- package/dist/components/Knob/context.d.ts.map +1 -0
- package/dist/components/Knob/context.js +5 -0
- package/dist/components/Knob/index.d.ts +6 -0
- package/dist/components/Knob/index.d.ts.map +1 -0
- package/dist/components/Knob/index.js +5 -0
- package/dist/components/Knob/types.d.ts +139 -0
- package/dist/components/Knob/types.d.ts.map +1 -0
- package/dist/components/Knob/types.js +1 -0
- package/dist/components/NumberInput/DecrementStepper.svelte +11 -0
- package/dist/components/NumberInput/DecrementStepper.svelte.d.ts +9 -0
- package/dist/components/NumberInput/DecrementStepper.svelte.d.ts.map +1 -0
- package/dist/components/NumberInput/IncrementStepper.svelte +11 -0
- package/dist/components/NumberInput/IncrementStepper.svelte.d.ts +9 -0
- package/dist/components/NumberInput/IncrementStepper.svelte.d.ts.map +1 -0
- package/dist/components/NumberInput/InputField.svelte +134 -0
- package/dist/components/NumberInput/InputField.svelte.d.ts +8 -0
- package/dist/components/NumberInput/InputField.svelte.d.ts.map +1 -0
- package/dist/components/NumberInput/Root.svelte +209 -0
- package/dist/components/NumberInput/Root.svelte.d.ts +10 -0
- package/dist/components/NumberInput/Root.svelte.d.ts.map +1 -0
- package/dist/components/NumberInput/Stepper.svelte +61 -0
- package/dist/components/NumberInput/Stepper.svelte.d.ts +10 -0
- package/dist/components/NumberInput/Stepper.svelte.d.ts.map +1 -0
- package/dist/components/NumberInput/StepperButton.svelte +63 -0
- package/dist/components/NumberInput/StepperButton.svelte.d.ts +10 -0
- package/dist/components/NumberInput/StepperButton.svelte.d.ts.map +1 -0
- package/dist/components/NumberInput/context.d.ts +48 -0
- package/dist/components/NumberInput/context.d.ts.map +1 -0
- package/dist/components/NumberInput/context.js +8 -0
- package/dist/components/NumberInput/index.d.ts +6 -0
- package/dist/components/NumberInput/index.d.ts.map +1 -0
- package/dist/components/NumberInput/index.js +5 -0
- package/dist/components/NumberInput/types.d.ts +104 -0
- package/dist/components/NumberInput/types.d.ts.map +1 -0
- package/dist/components/NumberInput/types.js +1 -0
- package/dist/components/Piano/Root.svelte +177 -0
- package/dist/components/Piano/Root.svelte.d.ts +10 -0
- package/dist/components/Piano/Root.svelte.d.ts.map +1 -0
- package/dist/components/Piano/index.d.ts +2 -0
- package/dist/components/Piano/index.d.ts.map +1 -0
- package/dist/components/Piano/index.js +1 -0
- package/dist/components/Piano/types.d.ts +90 -0
- package/dist/components/Piano/types.d.ts.map +1 -0
- package/dist/components/Piano/types.js +1 -0
- package/dist/components/PointsEditor/Background.svelte +14 -0
- package/dist/components/PointsEditor/Background.svelte.d.ts +9 -0
- package/dist/components/PointsEditor/Background.svelte.d.ts.map +1 -0
- package/dist/components/PointsEditor/Container.svelte +82 -0
- package/dist/components/PointsEditor/Container.svelte.d.ts +10 -0
- package/dist/components/PointsEditor/Container.svelte.d.ts.map +1 -0
- package/dist/components/PointsEditor/Point.svelte +213 -0
- package/dist/components/PointsEditor/Point.svelte.d.ts +7 -0
- package/dist/components/PointsEditor/Point.svelte.d.ts.map +1 -0
- package/dist/components/PointsEditor/Root.svelte +107 -0
- package/dist/components/PointsEditor/Root.svelte.d.ts +7 -0
- package/dist/components/PointsEditor/Root.svelte.d.ts.map +1 -0
- package/dist/components/PointsEditor/SelectionBox.svelte +32 -0
- package/dist/components/PointsEditor/SelectionBox.svelte.d.ts +9 -0
- package/dist/components/PointsEditor/SelectionBox.svelte.d.ts.map +1 -0
- package/dist/components/PointsEditor/context.d.ts +28 -0
- package/dist/components/PointsEditor/context.d.ts.map +1 -0
- package/dist/components/PointsEditor/context.js +5 -0
- package/dist/components/PointsEditor/index.d.ts +6 -0
- package/dist/components/PointsEditor/index.d.ts.map +1 -0
- package/dist/components/PointsEditor/index.js +5 -0
- package/dist/components/PointsEditor/types.d.ts +84 -0
- package/dist/components/PointsEditor/types.d.ts.map +1 -0
- package/dist/components/PointsEditor/types.js +1 -0
- package/dist/components/Slider/Marks.svelte +42 -0
- package/dist/components/Slider/Marks.svelte.d.ts +7 -0
- package/dist/components/Slider/Marks.svelte.d.ts.map +1 -0
- package/dist/components/Slider/MarksOption.svelte +63 -0
- package/dist/components/Slider/MarksOption.svelte.d.ts +7 -0
- package/dist/components/Slider/MarksOption.svelte.d.ts.map +1 -0
- package/dist/components/Slider/Root.svelte +217 -0
- package/dist/components/Slider/Root.svelte.d.ts +10 -0
- package/dist/components/Slider/Root.svelte.d.ts.map +1 -0
- package/dist/components/Slider/Thumb.svelte +84 -0
- package/dist/components/Slider/Thumb.svelte.d.ts +10 -0
- package/dist/components/Slider/Thumb.svelte.d.ts.map +1 -0
- package/dist/components/Slider/Track.svelte +51 -0
- package/dist/components/Slider/Track.svelte.d.ts +7 -0
- package/dist/components/Slider/Track.svelte.d.ts.map +1 -0
- package/dist/components/Slider/context.d.ts +28 -0
- package/dist/components/Slider/context.d.ts.map +1 -0
- package/dist/components/Slider/context.js +5 -0
- package/dist/components/Slider/index.d.ts +6 -0
- package/dist/components/Slider/index.d.ts.map +1 -0
- package/dist/components/Slider/index.js +5 -0
- package/dist/components/Slider/types.d.ts +138 -0
- package/dist/components/Slider/types.d.ts.map +1 -0
- package/dist/components/Slider/types.js +1 -0
- package/dist/components/XYPad/Area.svelte +29 -0
- package/dist/components/XYPad/Area.svelte.d.ts +10 -0
- package/dist/components/XYPad/Area.svelte.d.ts.map +1 -0
- package/dist/components/XYPad/Root.svelte +238 -0
- package/dist/components/XYPad/Root.svelte.d.ts +10 -0
- package/dist/components/XYPad/Root.svelte.d.ts.map +1 -0
- package/dist/components/XYPad/Thumb.svelte +109 -0
- package/dist/components/XYPad/Thumb.svelte.d.ts +10 -0
- package/dist/components/XYPad/Thumb.svelte.d.ts.map +1 -0
- package/dist/components/XYPad/context.d.ts +25 -0
- package/dist/components/XYPad/context.d.ts.map +1 -0
- package/dist/components/XYPad/context.js +5 -0
- package/dist/components/XYPad/index.d.ts +4 -0
- package/dist/components/XYPad/index.d.ts.map +1 -0
- package/dist/components/XYPad/index.js +3 -0
- package/dist/components/XYPad/types.d.ts +80 -0
- package/dist/components/XYPad/types.d.ts.map +1 -0
- package/dist/components/XYPad/types.js +1 -0
- package/dist/components/_util/VisuallyHiddenRangeInput.svelte +17 -0
- package/dist/components/_util/VisuallyHiddenRangeInput.svelte.d.ts +8 -0
- package/dist/components/_util/VisuallyHiddenRangeInput.svelte.d.ts.map +1 -0
- package/dist/components/_util/check-steps.svelte.d.ts +10 -0
- package/dist/components/_util/check-steps.svelte.d.ts.map +1 -0
- package/dist/components/_util/check-steps.svelte.js +17 -0
- package/dist/components/_util/placement.d.ts +15 -0
- package/dist/components/_util/placement.d.ts.map +1 -0
- package/dist/components/_util/placement.js +30 -0
- package/dist/components/_util/style.d.ts +5 -0
- package/dist/components/_util/style.d.ts.map +1 -0
- package/dist/components/_util/style.js +9 -0
- package/dist/hooks/useMIDIAccess.svelte.d.ts +29 -0
- package/dist/hooks/useMIDIAccess.svelte.d.ts.map +1 -0
- package/dist/hooks/useMIDIAccess.svelte.js +62 -0
- package/dist/hooks/useMIDIInput.svelte.d.ts +18 -0
- package/dist/hooks/useMIDIInput.svelte.d.ts.map +1 -0
- package/dist/hooks/useMIDIInput.svelte.js +31 -0
- package/dist/hooks/useMIDIMessage.svelte.d.ts +9 -0
- package/dist/hooks/useMIDIMessage.svelte.d.ts.map +1 -0
- package/dist/hooks/useMIDIMessage.svelte.js +23 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 mimoz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type DragValueOptions } from '@tremolo-ui/dom';
|
|
2
|
+
import type { Action } from 'svelte/action';
|
|
3
|
+
/**
|
|
4
|
+
* Drive a value with a pointer drag. See `createDragValue` in
|
|
5
|
+
* `@tremolo-ui/dom` for the options; `elementMapping` and `relativeMapping`
|
|
6
|
+
* from there choose how the pointer becomes a value.
|
|
7
|
+
*
|
|
8
|
+
* `mapping` is fixed when the action starts. Everything else is handed to the
|
|
9
|
+
* drag in place, so changing it does not end a drag in progress.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <div
|
|
13
|
+
* use:dragValue={{
|
|
14
|
+
* axis: { min: 0, max: 100 },
|
|
15
|
+
* mapping: relativeMapping({ pixelRange: 200 }),
|
|
16
|
+
* getValue: () => [value, value],
|
|
17
|
+
* onChange: ([, y]) => (value = y),
|
|
18
|
+
* }}
|
|
19
|
+
* ></div>
|
|
20
|
+
*/
|
|
21
|
+
export declare const dragValue: Action<Element, DragValueOptions>;
|
|
22
|
+
//# sourceMappingURL=drag-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag-value.d.ts","sourceRoot":"","sources":["../../src/actions/drag-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAUvD,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createDragValue, replaceOptions, } from '@tremolo-ui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Drive a value with a pointer drag. See `createDragValue` in
|
|
4
|
+
* `@tremolo-ui/dom` for the options; `elementMapping` and `relativeMapping`
|
|
5
|
+
* from there choose how the pointer becomes a value.
|
|
6
|
+
*
|
|
7
|
+
* `mapping` is fixed when the action starts. Everything else is handed to the
|
|
8
|
+
* drag in place, so changing it does not end a drag in progress.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <div
|
|
12
|
+
* use:dragValue={{
|
|
13
|
+
* axis: { min: 0, max: 100 },
|
|
14
|
+
* mapping: relativeMapping({ pixelRange: 200 }),
|
|
15
|
+
* getValue: () => [value, value],
|
|
16
|
+
* onChange: ([, y]) => (value = y),
|
|
17
|
+
* }}
|
|
18
|
+
* ></div>
|
|
19
|
+
*/
|
|
20
|
+
export const dragValue = (node, options) => {
|
|
21
|
+
const instance = createDragValue(node, options);
|
|
22
|
+
let current = options;
|
|
23
|
+
return {
|
|
24
|
+
update: (next) => {
|
|
25
|
+
instance.update(replaceOptions(current, next));
|
|
26
|
+
current = next;
|
|
27
|
+
},
|
|
28
|
+
destroy: () => instance.destroy(),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DragOptions } from '@tremolo-ui/dom';
|
|
2
|
+
import type { Action } from 'svelte/action';
|
|
3
|
+
/**
|
|
4
|
+
* Track a pointer drag on the element. See `createDrag` in `@tremolo-ui/dom`
|
|
5
|
+
* for the options.
|
|
6
|
+
*
|
|
7
|
+
* New options are handed to the drag in place, so changing them — a handler
|
|
8
|
+
* that closes over state, say — does not end a drag in progress.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <div use:drag={{ onDrag: (state) => (x += state.deltaX) }}></div>
|
|
12
|
+
*/
|
|
13
|
+
export declare const drag: Action<Element, DragOptions | undefined>;
|
|
14
|
+
//# sourceMappingURL=drag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag.d.ts","sourceRoot":"","sources":["../../src/actions/drag.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAazD,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createDrag, replaceOptions } from '@tremolo-ui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Track a pointer drag on the element. See `createDrag` in `@tremolo-ui/dom`
|
|
4
|
+
* for the options.
|
|
5
|
+
*
|
|
6
|
+
* New options are handed to the drag in place, so changing them — a handler
|
|
7
|
+
* that closes over state, say — does not end a drag in progress.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* <div use:drag={{ onDrag: (state) => (x += state.deltaX) }}></div>
|
|
11
|
+
*/
|
|
12
|
+
export const drag = (node, options) => {
|
|
13
|
+
const instance = createDrag(node, options);
|
|
14
|
+
let current = options;
|
|
15
|
+
return {
|
|
16
|
+
update: (next) => {
|
|
17
|
+
instance.update(replaceOptions(current, next));
|
|
18
|
+
current = next;
|
|
19
|
+
},
|
|
20
|
+
destroy: () => instance.destroy(),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DropZoneOptions } from '@tremolo-ui/dom';
|
|
2
|
+
import type { Action } from 'svelte/action';
|
|
3
|
+
/**
|
|
4
|
+
* Take files dropped on the element. See `createDropZone` in
|
|
5
|
+
* `@tremolo-ui/dom` for the options; `onStateChange` reports whether files
|
|
6
|
+
* are over it, for styling the element while they are.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* <div use:dropZone={{ accept: 'audio/*', onDrop: (files) => load(files) }}></div>
|
|
10
|
+
*/
|
|
11
|
+
export declare const dropZone: Action<Element, DropZoneOptions | undefined>;
|
|
12
|
+
//# sourceMappingURL=drop-zone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-zone.d.ts","sourceRoot":"","sources":["../../src/actions/drop-zone.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAajE,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createDropZone, replaceOptions, } from '@tremolo-ui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Take files dropped on the element. See `createDropZone` in
|
|
4
|
+
* `@tremolo-ui/dom` for the options; `onStateChange` reports whether files
|
|
5
|
+
* are over it, for styling the element while they are.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <div use:dropZone={{ accept: 'audio/*', onDrop: (files) => load(files) }}></div>
|
|
9
|
+
*/
|
|
10
|
+
export const dropZone = (node, options) => {
|
|
11
|
+
const instance = createDropZone(node, options);
|
|
12
|
+
let current = options;
|
|
13
|
+
return {
|
|
14
|
+
update: (next) => {
|
|
15
|
+
instance.update(replaceOptions(current, next));
|
|
16
|
+
current = next;
|
|
17
|
+
},
|
|
18
|
+
destroy: () => instance.destroy(),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LongPressOptions } from '@tremolo-ui/dom';
|
|
2
|
+
import type { Action } from 'svelte/action';
|
|
3
|
+
/**
|
|
4
|
+
* Repeat `onPress` while the element is held down: once on the press, then
|
|
5
|
+
* every `interval` after `delay`. See `createLongPress` in `@tremolo-ui/dom`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <button use:longPress={{ onPress: () => value++ }}>+</button>
|
|
9
|
+
*/
|
|
10
|
+
export declare const longPress: Action<HTMLElement, LongPressOptions>;
|
|
11
|
+
//# sourceMappingURL=long-press.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"long-press.d.ts","sourceRoot":"","sources":["../../src/actions/long-press.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAkB3D,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createLongPress, replaceOptions, } from '@tremolo-ui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Repeat `onPress` while the element is held down: once on the press, then
|
|
4
|
+
* every `interval` after `delay`. See `createLongPress` in `@tremolo-ui/dom`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* <button use:longPress={{ onPress: () => value++ }}>+</button>
|
|
8
|
+
*/
|
|
9
|
+
export const longPress = (node, options) => {
|
|
10
|
+
const instance = createLongPress(options);
|
|
11
|
+
const onPointerDown = (event) => instance.start(event);
|
|
12
|
+
node.addEventListener('pointerdown', onPointerDown);
|
|
13
|
+
let current = options;
|
|
14
|
+
return {
|
|
15
|
+
update: (next) => {
|
|
16
|
+
instance.update(replaceOptions(current, next));
|
|
17
|
+
current = next;
|
|
18
|
+
},
|
|
19
|
+
destroy: () => {
|
|
20
|
+
node.removeEventListener('pointerdown', onPointerDown);
|
|
21
|
+
instance.destroy();
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type WheelOptions } from '@tremolo-ui/dom';
|
|
2
|
+
import type { Action } from 'svelte/action';
|
|
3
|
+
export interface WheelActionOptions extends WheelOptions {
|
|
4
|
+
onWheel: (event: WheelEvent) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Listen to the wheel on the element, as a non-passive listener so that
|
|
8
|
+
* `preventDefault()` can keep the page from scrolling. See `createWheel` in
|
|
9
|
+
* `@tremolo-ui/dom`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <div use:wheel={{ onWheel: (e) => { e.preventDefault(); … }, requireFocus: true }}></div>
|
|
13
|
+
*/
|
|
14
|
+
export declare const wheel: Action<Element, WheelActionOptions>;
|
|
15
|
+
//# sourceMappingURL=wheel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wheel.d.ts","sourceRoot":"","sources":["../../src/actions/wheel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEhF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;CACrC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,kBAAkB,CAWrD,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { createWheel, replaceOptions } from '@tremolo-ui/dom';
|
|
13
|
+
/**
|
|
14
|
+
* Listen to the wheel on the element, as a non-passive listener so that
|
|
15
|
+
* `preventDefault()` can keep the page from scrolling. See `createWheel` in
|
|
16
|
+
* `@tremolo-ui/dom`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <div use:wheel={{ onWheel: (e) => { e.preventDefault(); … }, requireFocus: true }}></div>
|
|
20
|
+
*/
|
|
21
|
+
export const wheel = (node, options) => {
|
|
22
|
+
const { onWheel } = options, rest = __rest(options, ["onWheel"]);
|
|
23
|
+
const instance = createWheel(node, onWheel, rest);
|
|
24
|
+
let current = options;
|
|
25
|
+
return {
|
|
26
|
+
update: (next) => {
|
|
27
|
+
instance.update(replaceOptions(current, next));
|
|
28
|
+
current = next;
|
|
29
|
+
},
|
|
30
|
+
destroy: () => instance.destroy(),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
createAnimationCanvas,
|
|
4
|
+
type AnimationCanvasInstance,
|
|
5
|
+
} from '@tremolo-ui/dom'
|
|
6
|
+
import { untrack } from 'svelte'
|
|
7
|
+
|
|
8
|
+
import type { AnimationCanvasProps } from './types.js'
|
|
9
|
+
|
|
10
|
+
import type { HTMLCanvasAttributes } from 'svelte/elements'
|
|
11
|
+
|
|
12
|
+
type Props = AnimationCanvasProps &
|
|
13
|
+
Omit<HTMLCanvasAttributes, keyof AnimationCanvasProps>
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
draw,
|
|
17
|
+
init,
|
|
18
|
+
animate = true,
|
|
19
|
+
options,
|
|
20
|
+
reduceFlickering = true,
|
|
21
|
+
resizable = false,
|
|
22
|
+
width = 100,
|
|
23
|
+
height = 100,
|
|
24
|
+
ref = $bindable(null),
|
|
25
|
+
oncontextmenu = (event: MouseEvent) => event.preventDefault(),
|
|
26
|
+
...rest
|
|
27
|
+
}: Props = $props()
|
|
28
|
+
|
|
29
|
+
let instance: AnimationCanvasInstance | null = null
|
|
30
|
+
|
|
31
|
+
// Only `resizable` decides how the instance is wired, so it is the one
|
|
32
|
+
// setting that rebuilds it. Everything else is pushed with update() below,
|
|
33
|
+
// and the handlers are read at call time.
|
|
34
|
+
$effect(() => {
|
|
35
|
+
const canvas = ref
|
|
36
|
+
const wired = resizable
|
|
37
|
+
if (!canvas) return
|
|
38
|
+
// All of it untracked, the call included: without animating, the core
|
|
39
|
+
// draws the first frame right here, and reading `draw` would make every
|
|
40
|
+
// state it reads tear the canvas down.
|
|
41
|
+
const current = untrack(() =>
|
|
42
|
+
createAnimationCanvas(canvas, {
|
|
43
|
+
draw: (context, frame) => draw(context, frame),
|
|
44
|
+
init: (context, size) => init?.(context, size),
|
|
45
|
+
animate,
|
|
46
|
+
size: { width, height },
|
|
47
|
+
reduceFlickering,
|
|
48
|
+
resizable: wired,
|
|
49
|
+
contextAttributes: options,
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
instance = current
|
|
53
|
+
return () => {
|
|
54
|
+
instance = null
|
|
55
|
+
current.destroy()
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Also run when `draw` or `init` change: without a loop running, update()
|
|
60
|
+
// is what paints a new handler's frame, so a canvas driven by state rather
|
|
61
|
+
// than by time shows the change.
|
|
62
|
+
$effect(() => {
|
|
63
|
+
void draw
|
|
64
|
+
void init
|
|
65
|
+
instance?.update({ animate, size: { width, height }, reduceFlickering })
|
|
66
|
+
})
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<canvas bind:this={ref} {oncontextmenu} {...rest}></canvas>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnimationCanvasProps } from './types.js';
|
|
2
|
+
import type { HTMLCanvasAttributes } from 'svelte/elements';
|
|
3
|
+
type Props = AnimationCanvasProps & Omit<HTMLCanvasAttributes, keyof AnimationCanvasProps>;
|
|
4
|
+
declare const AnimationCanvas: import("svelte").Component<Props, {}, "ref">;
|
|
5
|
+
type AnimationCanvas = ReturnType<typeof AnimationCanvas>;
|
|
6
|
+
export default AnimationCanvas;
|
|
7
|
+
//# sourceMappingURL=AnimationCanvas.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimationCanvas.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/AnimationCanvas/AnimationCanvas.svelte.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,KAAK,KAAK,GAAG,oBAAoB,GAC/B,IAAI,CAAC,oBAAoB,EAAE,MAAM,oBAAoB,CAAC,CAAC;AAoE3D,QAAA,MAAM,eAAe,8CAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AnimationFrame } from '@tremolo-ui/dom';
|
|
2
|
+
/** Called once the canvas is ready, and again whenever it is resized. */
|
|
3
|
+
export type InitFunction = (context: CanvasRenderingContext2D, size: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}) => void;
|
|
7
|
+
/** Called on every frame while `animate` is on, and once otherwise. */
|
|
8
|
+
export type DrawFunction = (context: CanvasRenderingContext2D, frame: AnimationFrame) => void;
|
|
9
|
+
export interface AnimationCanvasProps {
|
|
10
|
+
/** Draws a frame. */
|
|
11
|
+
draw: DrawFunction;
|
|
12
|
+
/** Sets the canvas up before the first frame and after a resize. */
|
|
13
|
+
init?: InitFunction;
|
|
14
|
+
/**
|
|
15
|
+
* Draw on every animation frame. Off, `draw` runs once and again after a
|
|
16
|
+
* resize.
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
animate?: boolean;
|
|
20
|
+
/** Settings for the 2D context. Read once, when the canvas is created. */
|
|
21
|
+
options?: CanvasRenderingContext2DSettings;
|
|
22
|
+
/**
|
|
23
|
+
* Keep the drawing while the canvas is resized, rather than letting it
|
|
24
|
+
* flash blank until the next frame.
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
reduceFlickering?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Follow the size of the parent element. `width` and `height` are ignored.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
resizable?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Width in CSS pixels, while not `resizable`.
|
|
35
|
+
* @default 100
|
|
36
|
+
*/
|
|
37
|
+
width?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Height in CSS pixels, while not `resizable`.
|
|
40
|
+
* @default 100
|
|
41
|
+
*/
|
|
42
|
+
height?: number;
|
|
43
|
+
/** The canvas, bound with `bind:ref`. */
|
|
44
|
+
ref?: HTMLCanvasElement | null;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/AnimationCanvas/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,wBAAwB,EACjC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KACpC,IAAI,CAAA;AAET,uEAAuE;AACvE,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,wBAAwB,EACjC,KAAK,EAAE,cAAc,KAClB,IAAI,CAAA;AAET,MAAM,WAAW,oBAAoB;IACnC,qBAAqB;IACrB,IAAI,EAAE,YAAY,CAAA;IAClB,oEAAoE;IACpE,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,gCAAgC,CAAA;IAC1C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,GAAG,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { dropZone } from '../../actions/drop-zone.js'
|
|
3
|
+
|
|
4
|
+
import type { DropZoneProps } from './types.js'
|
|
5
|
+
|
|
6
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
7
|
+
|
|
8
|
+
type Props = DropZoneProps &
|
|
9
|
+
Omit<HTMLAttributes<HTMLDivElement>, keyof DropZoneProps>
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
accept,
|
|
13
|
+
multiple = false,
|
|
14
|
+
disabled = false,
|
|
15
|
+
onDrop,
|
|
16
|
+
onReject,
|
|
17
|
+
ref = $bindable(null),
|
|
18
|
+
children,
|
|
19
|
+
...rest
|
|
20
|
+
}: Props = $props()
|
|
21
|
+
|
|
22
|
+
let over = $state(false)
|
|
23
|
+
let invalid = $state(false)
|
|
24
|
+
|
|
25
|
+
const options = $derived({
|
|
26
|
+
accept,
|
|
27
|
+
multiple,
|
|
28
|
+
disabled,
|
|
29
|
+
onDrop: (files: File[], event: DragEvent) => onDrop?.(files, event),
|
|
30
|
+
onReject: (files: File[], event: DragEvent) => onReject?.(files, event),
|
|
31
|
+
onStateChange: (state: { over: boolean; invalid: boolean }) => {
|
|
32
|
+
over = state.over
|
|
33
|
+
invalid = state.invalid
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
bind:this={ref}
|
|
40
|
+
data-dragover={over ? '' : undefined}
|
|
41
|
+
data-invalid={invalid ? '' : undefined}
|
|
42
|
+
data-disabled={disabled ? '' : undefined}
|
|
43
|
+
use:dropZone={options}
|
|
44
|
+
{...rest}
|
|
45
|
+
>
|
|
46
|
+
{@render children()}
|
|
47
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DropZoneProps } from './types.js';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
type Props = DropZoneProps & Omit<HTMLAttributes<HTMLDivElement>, keyof DropZoneProps>;
|
|
4
|
+
declare const Root: import("svelte").Component<Props, {}, "ref">;
|
|
5
|
+
type Root = ReturnType<typeof Root>;
|
|
6
|
+
export default Root;
|
|
7
|
+
//# sourceMappingURL=Root.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Root.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/DropZone/Root.svelte.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGpD,KAAK,KAAK,GAAG,aAAa,GACxB,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,aAAa,CAAC,CAAC;AA0C9D,QAAA,MAAM,IAAI,8CAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DropZone/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Root } from './Root.svelte';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface DropZoneProps {
|
|
3
|
+
/**
|
|
4
|
+
* Which files to take, written the way the `accept` attribute of a file
|
|
5
|
+
* input is.
|
|
6
|
+
*/
|
|
7
|
+
accept?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Take every file dropped, rather than the first.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
multiple?: boolean;
|
|
13
|
+
/** Ignore drops. The zone carries `data-disabled`. */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Called with the dropped files that satisfy `accept`. */
|
|
16
|
+
onDrop?: (files: File[], event: DragEvent) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Called with the dropped files that do not satisfy `accept`, after `onDrop`
|
|
19
|
+
* for the same drop.
|
|
20
|
+
*/
|
|
21
|
+
onReject?: (files: File[], event: DragEvent) => void;
|
|
22
|
+
/** The root element, bound with `bind:ref`. */
|
|
23
|
+
ref?: HTMLDivElement | null;
|
|
24
|
+
children: Snippet;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/DropZone/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IAClD;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IACpD,+CAA+C;IAC/C,GAAG,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,OAAO,CAAA;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { partitionByAccept } from '@tremolo-ui/dom'
|
|
3
|
+
|
|
4
|
+
import { visuallyHidden } from '../_util/style.js'
|
|
5
|
+
|
|
6
|
+
import { setFileInputContext } from './context.js'
|
|
7
|
+
import type { FileInputProps } from './types.js'
|
|
8
|
+
|
|
9
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
10
|
+
|
|
11
|
+
type Props = FileInputProps &
|
|
12
|
+
Omit<HTMLAttributes<HTMLDivElement>, keyof FileInputProps>
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
accept,
|
|
16
|
+
multiple = false,
|
|
17
|
+
disabled = false,
|
|
18
|
+
onChange,
|
|
19
|
+
onReject,
|
|
20
|
+
ref = $bindable(null),
|
|
21
|
+
children,
|
|
22
|
+
'aria-label': ariaLabel,
|
|
23
|
+
'aria-labelledby': ariaLabelledby,
|
|
24
|
+
'aria-describedby': ariaDescribedby,
|
|
25
|
+
...rest
|
|
26
|
+
}: Props = $props()
|
|
27
|
+
|
|
28
|
+
const inputId = $props.id()
|
|
29
|
+
|
|
30
|
+
setFileInputContext({
|
|
31
|
+
inputId,
|
|
32
|
+
get disabled() {
|
|
33
|
+
return disabled
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
function handleChange(event: Event & { currentTarget: HTMLInputElement }) {
|
|
38
|
+
const input = event.currentTarget
|
|
39
|
+
const { accepted, rejected } = partitionByAccept(
|
|
40
|
+
Array.from(input.files ?? []),
|
|
41
|
+
accept,
|
|
42
|
+
)
|
|
43
|
+
// Picking the same file twice fires no second change while the value is
|
|
44
|
+
// still on the input, so it is cleared as soon as it is read.
|
|
45
|
+
input.value = ''
|
|
46
|
+
if (accepted.length > 0) onChange?.(accepted)
|
|
47
|
+
if (rejected.length > 0) onReject?.(rejected)
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<!-- The control is the native file input: out of sight but in the tab order,
|
|
52
|
+
with `Trigger` as its label, so the click reaching the picker and the name
|
|
53
|
+
are the browser's job. -->
|
|
54
|
+
<div bind:this={ref} data-disabled={disabled ? '' : undefined} {...rest}>
|
|
55
|
+
<input
|
|
56
|
+
id={inputId}
|
|
57
|
+
type="file"
|
|
58
|
+
{accept}
|
|
59
|
+
{multiple}
|
|
60
|
+
{disabled}
|
|
61
|
+
style={visuallyHidden}
|
|
62
|
+
aria-label={ariaLabel}
|
|
63
|
+
aria-labelledby={ariaLabelledby}
|
|
64
|
+
aria-describedby={ariaDescribedby}
|
|
65
|
+
onchange={handleChange}
|
|
66
|
+
/>
|
|
67
|
+
{@render children()}
|
|
68
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FileInputProps } from './types.js';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
type Props = FileInputProps & Omit<HTMLAttributes<HTMLDivElement>, keyof FileInputProps>;
|
|
4
|
+
declare const Root: import("svelte").Component<Props, {}, "ref">;
|
|
5
|
+
type Root = ReturnType<typeof Root>;
|
|
6
|
+
export default Root;
|
|
7
|
+
//# sourceMappingURL=Root.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Root.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/FileInput/Root.svelte.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGpD,KAAK,KAAK,GAAG,cAAc,GACzB,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,cAAc,CAAC,CAAC;AAyD/D,QAAA,MAAM,IAAI,8CAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useFileInputContext } from './context.js'
|
|
3
|
+
|
|
4
|
+
import type { Snippet } from 'svelte'
|
|
5
|
+
import type { HTMLLabelAttributes } from 'svelte/elements'
|
|
6
|
+
|
|
7
|
+
type Props = Omit<HTMLLabelAttributes, 'for'> & {
|
|
8
|
+
ref?: HTMLLabelElement | null
|
|
9
|
+
/** What the trigger reads. It is the accessible name of the file input. */
|
|
10
|
+
children: Snippet
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let { ref = $bindable(null), children, ...rest }: Props = $props()
|
|
14
|
+
|
|
15
|
+
const fileInput = useFileInputContext()
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<!-- A label rather than a button: the browser forwards the click to the
|
|
19
|
+
input, the input stays the one thing in the tab order, and its name comes
|
|
20
|
+
from this text. -->
|
|
21
|
+
<label
|
|
22
|
+
bind:this={ref}
|
|
23
|
+
for={fileInput.inputId}
|
|
24
|
+
data-disabled={fileInput.disabled ? '' : undefined}
|
|
25
|
+
{...rest}
|
|
26
|
+
>
|
|
27
|
+
{@render children()}
|
|
28
|
+
</label>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLLabelAttributes } from 'svelte/elements';
|
|
3
|
+
type Props = Omit<HTMLLabelAttributes, 'for'> & {
|
|
4
|
+
ref?: HTMLLabelElement | null;
|
|
5
|
+
/** What the trigger reads. It is the accessible name of the file input. */
|
|
6
|
+
children: Snippet;
|
|
7
|
+
};
|
|
8
|
+
declare const Trigger: import("svelte").Component<Props, {}, "ref">;
|
|
9
|
+
type Trigger = ReturnType<typeof Trigger>;
|
|
10
|
+
export default Trigger;
|
|
11
|
+
//# sourceMappingURL=Trigger.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Trigger.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/FileInput/Trigger.svelte.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,KAAK,KAAK,GAAG,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,GAAG;IAC9C,GAAG,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAC7B,2EAA2E;IAC3E,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAC;AAoBJ,QAAA,MAAM,OAAO,8CAAwC,CAAC;AACtD,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** What `FileInput.Root` shares with `FileInput.Trigger`. */
|
|
2
|
+
export interface FileInputContextValue {
|
|
3
|
+
/** The id of the file input, for the trigger's `for`. */
|
|
4
|
+
readonly inputId: string;
|
|
5
|
+
readonly disabled: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** The context of the enclosing `FileInput.Root`, for a part of your own. */
|
|
8
|
+
export declare const useFileInputContext: () => FileInputContextValue;
|
|
9
|
+
export declare const setFileInputContext: (context: FileInputContextValue) => FileInputContextValue;
|
|
10
|
+
//# sourceMappingURL=context.d.ts.map
|