@molecule/app-feature-track-lane-svelte 0.0.0-stage → 1.1.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 +202 -0
- package/README.md +213 -2
- package/dist/TrackLane.svelte +235 -0
- package/dist/TrackLane.svelte.d.ts +5 -0
- package/dist/TrackLane.svelte.d.ts.map +1 -0
- package/dist/components.d.ts +8 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +7 -0
- package/dist/geometry.d.ts +43 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +48 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/package.json +77 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-16T18:57:57.979Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/app-feature-track-lane-svelte
|
|
10
|
+
|
|
11
|
+
Svelte horizontal track-lane primitive for multi-track timelines (music DAW,
|
|
12
|
+
video editor, animation tool). Renders one lane row of draggable + resizable
|
|
13
|
+
clip blocks on a `pixelsPerSecond` time axis.
|
|
14
|
+
|
|
15
|
+
Svelte counterpart of `@molecule/app-feature-track-lane-react`: the same props
|
|
16
|
+
(React names), the same DOM for the same input, and the same callback calls,
|
|
17
|
+
so an app switches framework by changing only the package name it imports.
|
|
18
|
+
|
|
19
|
+
Exports `<TrackLane>` and the `Clip` type, plus the pure-function helpers
|
|
20
|
+
`clipToPixels`, `pixelsToTime` and `clampClipMove` that back the
|
|
21
|
+
pointer-event drag/resize math.
|
|
22
|
+
|
|
23
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
24
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
25
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```svelte
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import { TrackLane, type Clip } from '@molecule/app-feature-track-lane-svelte'
|
|
32
|
+
|
|
33
|
+
let selected = $state<string>()
|
|
34
|
+
const clips: Clip[] = [
|
|
35
|
+
{ id: 'a', startTime: 0, duration: 2, color: '#0af', label: 'Kick' },
|
|
36
|
+
{ id: 'b', startTime: 4, duration: 1.5, label: 'Snare' },
|
|
37
|
+
]
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<TrackLane
|
|
41
|
+
name="Drums"
|
|
42
|
+
{clips}
|
|
43
|
+
pixelsPerSecond={20}
|
|
44
|
+
selectedClipId={selected}
|
|
45
|
+
onClipClick={(clipId) => (selected = clipId)}
|
|
46
|
+
/>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Type
|
|
50
|
+
|
|
51
|
+
`feature`
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install @molecule/app-feature-track-lane-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
### Interfaces
|
|
62
|
+
|
|
63
|
+
#### `Clip`
|
|
64
|
+
|
|
65
|
+
A single clip block on a track lane. `startTime` and `duration` are both in
|
|
66
|
+
seconds; `pixelsPerSecond` on the lane converts them to the on-screen
|
|
67
|
+
geometry. `id` is a stable identifier used as the row key and as the argument
|
|
68
|
+
passed back to all event handlers. `color` accents the body fill (defaults to
|
|
69
|
+
a neutral surface) and `label` is rendered inside the clip when given.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
interface Clip {
|
|
73
|
+
/** Stable identifier for the clip (used as the row key + handler arg). */
|
|
74
|
+
id: string
|
|
75
|
+
/** Clip start time on the lane in seconds. */
|
|
76
|
+
startTime: number
|
|
77
|
+
/** Clip duration in seconds. Always positive — minimum is enforced. */
|
|
78
|
+
duration: number
|
|
79
|
+
/** Optional accent color for the clip body (any valid CSS color). */
|
|
80
|
+
color?: string
|
|
81
|
+
/** Optional inline label rendered on top of the clip body (a snippet or text). */
|
|
82
|
+
label?: string | number | Snippet
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### `TrackLaneProps`
|
|
87
|
+
|
|
88
|
+
Props accepted by the {@link TrackLane} component — the same props React's
|
|
89
|
+
`TrackLane` accepts. A node-valued prop is a snippet (or plain text).
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface TrackLaneProps {
|
|
93
|
+
/** Optional lane name shown in the leading lane header. */
|
|
94
|
+
name?: string | number | Snippet
|
|
95
|
+
/** Clips on this lane. Order is preserved as-is. */
|
|
96
|
+
clips: Clip[]
|
|
97
|
+
/** Horizontal time scale, defaults to 20. */
|
|
98
|
+
pixelsPerSecond?: number
|
|
99
|
+
/**
|
|
100
|
+
* Optional opaque lane identifier. Forwarded to handlers and emitted as
|
|
101
|
+
* `data-lane` so multi-lane parents can tell lanes apart.
|
|
102
|
+
*/
|
|
103
|
+
lane?: string
|
|
104
|
+
/** Lane row height in pixels. Defaults to 44. */
|
|
105
|
+
height?: number
|
|
106
|
+
/** Called when a clip is dragged horizontally. */
|
|
107
|
+
onClipMove?: (clipId: string, startTime: number, lane?: string) => void
|
|
108
|
+
/** Called when a clip's right edge handle is dragged. */
|
|
109
|
+
onClipResize?: (clipId: string, duration: number, lane?: string) => void
|
|
110
|
+
/** Called when a clip body is clicked (no drag). */
|
|
111
|
+
onClipClick?: (clipId: string, lane?: string) => void
|
|
112
|
+
/** Currently-selected clip id (renders the selection ring on that clip). */
|
|
113
|
+
selectedClipId?: string
|
|
114
|
+
/** Extra classes merged onto the root element. */
|
|
115
|
+
className?: string
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Functions
|
|
120
|
+
|
|
121
|
+
#### `clipToPixels(clip, pixelsPerSecond)`
|
|
122
|
+
|
|
123
|
+
Convert a clip to its on-lane pixel geometry.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
function clipToPixels(
|
|
127
|
+
clip: { startTime: number; duration: number },
|
|
128
|
+
pixelsPerSecond: number,
|
|
129
|
+
): { left: number; width: number }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- `clip` — The clip to project (`startTime` + `duration` in seconds).
|
|
133
|
+
- `pixelsPerSecond` — Horizontal scale; zero or negative falls back to 1.
|
|
134
|
+
|
|
135
|
+
**Returns:** `{ left, width }` in pixels.
|
|
136
|
+
|
|
137
|
+
#### `pixelsToTime(pixels, pixelsPerSecond)`
|
|
138
|
+
|
|
139
|
+
Convert a pixel offset back to a time value, clamped to `>= 0`.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
function pixelsToTime(pixels: number, pixelsPerSecond: number): number
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- `pixels` — Offset in pixels.
|
|
146
|
+
- `pixelsPerSecond` — Horizontal scale; zero or negative falls back to 1.
|
|
147
|
+
|
|
148
|
+
**Returns:** Time in seconds (never negative).
|
|
149
|
+
|
|
150
|
+
#### `clampClipMove(proposedStartTime)`
|
|
151
|
+
|
|
152
|
+
Clamp the proposed new `startTime` for a clip move so the clip stays
|
|
153
|
+
non-negative. (No upper bound — the parent decides whether to clip to a song
|
|
154
|
+
length.)
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
function clampClipMove(proposedStartTime: number): number
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
- `proposedStartTime` — The candidate start time in seconds.
|
|
161
|
+
|
|
162
|
+
**Returns:** The clamped start time.
|
|
163
|
+
|
|
164
|
+
### Constants
|
|
165
|
+
|
|
166
|
+
#### `TrackLane`
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const TrackLane: LegacyComponentType
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### `MIN_CLIP_DURATION_SECONDS`
|
|
173
|
+
|
|
174
|
+
Minimum clip duration in seconds — clips can't be resized below this.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const MIN_CLIP_DURATION_SECONDS: 0.05
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### `DRAG_DISTANCE_THRESHOLD_PX`
|
|
181
|
+
|
|
182
|
+
Pointer-distance threshold (px) before a press becomes a drag.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
const DRAG_DISTANCE_THRESHOLD_PX: 3
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Injection Notes
|
|
189
|
+
|
|
190
|
+
### Requirements
|
|
191
|
+
|
|
192
|
+
Peer dependencies:
|
|
193
|
+
|
|
194
|
+
- `@molecule/app-svelte` ^3.5.0
|
|
195
|
+
- `@molecule/app-ui` ^1.0.1
|
|
196
|
+
- `@molecule/app-ui-svelte` ^1.1.0
|
|
197
|
+
- `svelte` ^5.0.0
|
|
198
|
+
|
|
199
|
+
### Runtime Dependencies
|
|
200
|
+
|
|
201
|
+
- `@molecule/app-svelte`
|
|
202
|
+
- `@molecule/app-ui`
|
|
203
|
+
- `@molecule/app-ui-svelte`
|
|
204
|
+
- `svelte`
|
|
205
|
+
|
|
206
|
+
- Requires a bonded ClassMap (`cm.flex`, `cm.cn`, …) — rendering throws
|
|
207
|
+
otherwise. No router dependency.
|
|
208
|
+
- Every visible string comes from `useTranslation()` (`trackLane.aria.*` and
|
|
209
|
+
`trackLane.header`), so a locale switch re-renders it.
|
|
210
|
+
- Node-valued props (`name`, a clip's `label`) are snippets (or plain text).
|
|
211
|
+
|
|
212
|
+
## Translations
|
|
213
|
+
|
|
214
|
+
Translation strings are provided by `@molecule/app-locales-feature-track-lane`.
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
TrackLane: the Svelte counterpart of `@molecule/app-feature-track-lane-react`'s
|
|
3
|
+
`TrackLane` — one row of a multi-track timeline with draggable + resizable clip
|
|
4
|
+
blocks on a `pixelsPerSecond` time axis. Same props (React names), same DOM for
|
|
5
|
+
the same input, same callback calls; every visible string comes from
|
|
6
|
+
`useTranslation()` so a locale switch re-renders it.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { useTranslation } from '@molecule/app-svelte'
|
|
10
|
+
import { getClassMap } from '@molecule/app-ui'
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
clampClipMove,
|
|
14
|
+
clipToPixels,
|
|
15
|
+
DRAG_DISTANCE_THRESHOLD_PX,
|
|
16
|
+
MIN_CLIP_DURATION_SECONDS,
|
|
17
|
+
pixelsToTime,
|
|
18
|
+
} from './geometry.js'
|
|
19
|
+
import type { Clip, TrackLaneProps } from './types.js'
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
name,
|
|
23
|
+
clips,
|
|
24
|
+
pixelsPerSecond,
|
|
25
|
+
lane,
|
|
26
|
+
height,
|
|
27
|
+
onClipMove,
|
|
28
|
+
onClipResize,
|
|
29
|
+
onClipClick,
|
|
30
|
+
selectedClipId,
|
|
31
|
+
className,
|
|
32
|
+
}: TrackLaneProps = $props()
|
|
33
|
+
|
|
34
|
+
const cm = $derived(getClassMap())
|
|
35
|
+
const { t } = useTranslation()
|
|
36
|
+
|
|
37
|
+
/** The pointer state of the drag in progress, or null. */
|
|
38
|
+
interface DragState {
|
|
39
|
+
clipId: string
|
|
40
|
+
mode: 'move' | 'resize'
|
|
41
|
+
pointerId: number
|
|
42
|
+
startX: number
|
|
43
|
+
originStartTime: number
|
|
44
|
+
originDuration: number
|
|
45
|
+
moved: boolean
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let drag: DragState | null = null
|
|
49
|
+
|
|
50
|
+
const scale = $derived(pixelsPerSecond ?? 20)
|
|
51
|
+
const rowHeight = $derived(height ?? 44)
|
|
52
|
+
const laneLabel = $derived(
|
|
53
|
+
t(
|
|
54
|
+
'trackLane.aria.lane',
|
|
55
|
+
{ name: typeof name === 'string' ? name : '' },
|
|
56
|
+
{ defaultValue: 'Track lane {{name}}' },
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
const headerLabel = $derived(t('trackLane.header', {}, { defaultValue: 'Track' }))
|
|
60
|
+
const resizeLabel = $derived(t('trackLane.aria.resize', {}, { defaultValue: 'Resize clip' }))
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The translated aria label of one clip (its label, or its id).
|
|
64
|
+
*
|
|
65
|
+
* @param clip - The clip.
|
|
66
|
+
* @returns The translated label.
|
|
67
|
+
*/
|
|
68
|
+
function clipLabel(clip: Clip): string {
|
|
69
|
+
return t(
|
|
70
|
+
'trackLane.aria.clip',
|
|
71
|
+
{
|
|
72
|
+
label: typeof clip.label === 'string' ? clip.label : clip.id,
|
|
73
|
+
startTime: clip.startTime.toFixed(2),
|
|
74
|
+
duration: clip.duration.toFixed(2),
|
|
75
|
+
},
|
|
76
|
+
{ defaultValue: 'Clip {{label}} starting at {{startTime}}s for {{duration}}s' },
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The clip block's inline geometry (React's `clipStyle`).
|
|
82
|
+
*
|
|
83
|
+
* @param clip - The clip.
|
|
84
|
+
* @param selected - Whether it is the selected clip.
|
|
85
|
+
* @returns The style declarations.
|
|
86
|
+
*/
|
|
87
|
+
function clipStyle(clip: Clip, selected: boolean): string {
|
|
88
|
+
const { left, width } = clipToPixels(clip, scale)
|
|
89
|
+
const background = clip.color ?? 'var(--mol-track-lane-clip-bg, rgba(0, 122, 204, 0.45))'
|
|
90
|
+
return [
|
|
91
|
+
'position: absolute',
|
|
92
|
+
`left: ${left}px`,
|
|
93
|
+
`width: ${width}px`,
|
|
94
|
+
'top: 4px',
|
|
95
|
+
'bottom: 4px',
|
|
96
|
+
`background: ${background}`,
|
|
97
|
+
'border-radius: 4px',
|
|
98
|
+
'box-sizing: border-box',
|
|
99
|
+
`outline: ${selected ? '2px solid currentColor' : 'none'}`,
|
|
100
|
+
'outline-offset: 1px',
|
|
101
|
+
'display: flex',
|
|
102
|
+
'align-items: center',
|
|
103
|
+
'padding-left: 6px',
|
|
104
|
+
'padding-right: 12px',
|
|
105
|
+
'overflow: hidden',
|
|
106
|
+
'user-select: none',
|
|
107
|
+
'touch-action: none',
|
|
108
|
+
].join('; ')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Native pointermove handler used during an active drag.
|
|
113
|
+
*
|
|
114
|
+
* @param event - Native pointer event.
|
|
115
|
+
*/
|
|
116
|
+
function onMove(event: PointerEvent): void {
|
|
117
|
+
const current = drag
|
|
118
|
+
if (!current || event.pointerId !== current.pointerId) return
|
|
119
|
+
const dx = event.clientX - current.startX
|
|
120
|
+
if (!current.moved && Math.abs(dx) < DRAG_DISTANCE_THRESHOLD_PX) return
|
|
121
|
+
current.moved = true
|
|
122
|
+
const dt = pixelsToTime(Math.abs(dx), scale) * (dx < 0 ? -1 : 1)
|
|
123
|
+
if (current.mode === 'move') {
|
|
124
|
+
onClipMove?.(current.clipId, clampClipMove(current.originStartTime + dt), lane)
|
|
125
|
+
} else {
|
|
126
|
+
onClipResize?.(
|
|
127
|
+
current.clipId,
|
|
128
|
+
Math.max(MIN_CLIP_DURATION_SECONDS, current.originDuration + dt),
|
|
129
|
+
lane,
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Native pointerup / pointercancel handler that closes the drag gesture.
|
|
136
|
+
*
|
|
137
|
+
* @param event - Native pointer event.
|
|
138
|
+
*/
|
|
139
|
+
function onUp(event: PointerEvent): void {
|
|
140
|
+
const current = drag
|
|
141
|
+
if (!current || event.pointerId !== current.pointerId) return
|
|
142
|
+
const wasClick = !current.moved
|
|
143
|
+
const finishedClipId = current.clipId
|
|
144
|
+
const finishedMode = current.mode
|
|
145
|
+
drag = null
|
|
146
|
+
if (wasClick && finishedMode === 'move') onClipClick?.(finishedClipId, lane)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
$effect(() => {
|
|
150
|
+
window.addEventListener('pointermove', onMove)
|
|
151
|
+
window.addEventListener('pointerup', onUp)
|
|
152
|
+
window.addEventListener('pointercancel', onUp)
|
|
153
|
+
return () => {
|
|
154
|
+
window.removeEventListener('pointermove', onMove)
|
|
155
|
+
window.removeEventListener('pointerup', onUp)
|
|
156
|
+
window.removeEventListener('pointercancel', onUp)
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Begin a drag gesture on a clip body or a resize handle.
|
|
162
|
+
*
|
|
163
|
+
* @param event - The pointer event from the clip element.
|
|
164
|
+
* @param clip - The clip being dragged.
|
|
165
|
+
* @param mode - `'move'` for body drags, `'resize'` for handle drags.
|
|
166
|
+
*/
|
|
167
|
+
function beginDrag(event: PointerEvent, clip: Clip, mode: DragState['mode']): void {
|
|
168
|
+
if (event.button !== undefined && event.button !== 0) return
|
|
169
|
+
event.stopPropagation()
|
|
170
|
+
drag = {
|
|
171
|
+
clipId: clip.id,
|
|
172
|
+
mode,
|
|
173
|
+
pointerId: event.pointerId,
|
|
174
|
+
startX: event.clientX,
|
|
175
|
+
originStartTime: clip.startTime,
|
|
176
|
+
originDuration: clip.duration,
|
|
177
|
+
moved: false,
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
</script>
|
|
181
|
+
|
|
182
|
+
<div
|
|
183
|
+
role="group"
|
|
184
|
+
aria-label={laneLabel}
|
|
185
|
+
data-mol-id="track-lane"
|
|
186
|
+
data-lane={lane}
|
|
187
|
+
class={cm.cn(cm.flex({ align: 'stretch', gap: 'sm' }), className)}
|
|
188
|
+
>
|
|
189
|
+
{#if name !== undefined || lane !== undefined}
|
|
190
|
+
<div
|
|
191
|
+
data-mol-id="track-lane-header"
|
|
192
|
+
class={cm.cn(cm.flex({ align: 'center' }), cm.sp('p', 2), cm.shrink0)}
|
|
193
|
+
style="width: 120px; min-width: 120px"
|
|
194
|
+
>
|
|
195
|
+
<span
|
|
196
|
+
class={cm.cn(cm.textSize('sm'), cm.fontWeight('semibold'))}
|
|
197
|
+
data-mol-id="track-lane-name"
|
|
198
|
+
>{#if typeof name === 'function'}{@render name()}{:else if name !== undefined && name !== null}{name}{:else}{headerLabel}{/if}</span
|
|
199
|
+
>
|
|
200
|
+
</div>
|
|
201
|
+
{/if}
|
|
202
|
+
<div
|
|
203
|
+
data-mol-id="track-lane-body"
|
|
204
|
+
style="position: relative; height: {rowHeight}px; min-height: {rowHeight}px; width: 100%; overflow: hidden; touch-action: pan-y"
|
|
205
|
+
>
|
|
206
|
+
{#each clips ?? [] as clip (clip.id)}
|
|
207
|
+
<div
|
|
208
|
+
role="button"
|
|
209
|
+
tabindex="0"
|
|
210
|
+
aria-label={clipLabel(clip)}
|
|
211
|
+
aria-pressed={selectedClipId === clip.id ? 'true' : undefined}
|
|
212
|
+
data-mol-id="track-lane-clip"
|
|
213
|
+
data-clip-id={clip.id}
|
|
214
|
+
data-selected={selectedClipId === clip.id ? 'true' : 'false'}
|
|
215
|
+
class={cm.cn(cm.cursorPointer)}
|
|
216
|
+
style={clipStyle(clip, selectedClipId === clip.id)}
|
|
217
|
+
onpointerdown={(event) => beginDrag(event, clip, 'move')}
|
|
218
|
+
>
|
|
219
|
+
{#if clip.label !== undefined}<span
|
|
220
|
+
data-mol-id="track-lane-clip-label"
|
|
221
|
+
class={cm.cn(cm.textSize('xs'))}
|
|
222
|
+
style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none"
|
|
223
|
+
>{#if typeof clip.label === 'function'}{@render clip.label()}{:else}{clip.label}{/if}</span
|
|
224
|
+
>{/if}
|
|
225
|
+
<div
|
|
226
|
+
role="separator"
|
|
227
|
+
aria-label={resizeLabel}
|
|
228
|
+
data-mol-id="track-lane-clip-handle"
|
|
229
|
+
style="position: absolute; top: 0px; right: 0px; bottom: 0px; width: 8px; cursor: ew-resize; touch-action: none"
|
|
230
|
+
onpointerdown={(event) => beginDrag(event, clip, 'resize')}
|
|
231
|
+
></div>
|
|
232
|
+
</div>
|
|
233
|
+
{/each}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackLane.svelte.d.ts","sourceRoot":"","sources":["../src/TrackLane.svelte"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAQ,cAAc,EAAE,MAAM,YAAY,CAAC;AA6LvD,QAAA,MAAM,SAAS,oDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package's components: one Svelte 5 component per React component in
|
|
3
|
+
* `@molecule/app-feature-track-lane-react`, under the same React name.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export { default as TrackLane } from './TrackLane.svelte';
|
|
8
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure geometry helpers of the track-lane primitive: the import path, the
|
|
3
|
+
* same constants and the same math `@molecule/app-feature-track-lane-react`
|
|
4
|
+
* exports.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/** Minimum clip duration in seconds — clips can't be resized below this. */
|
|
9
|
+
export declare const MIN_CLIP_DURATION_SECONDS = 0.05;
|
|
10
|
+
/** Pointer-distance threshold (px) before a press becomes a drag. */
|
|
11
|
+
export declare const DRAG_DISTANCE_THRESHOLD_PX = 3;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a clip to its on-lane pixel geometry.
|
|
14
|
+
*
|
|
15
|
+
* @param clip - The clip to project (`startTime` + `duration` in seconds).
|
|
16
|
+
* @param pixelsPerSecond - Horizontal scale; zero or negative falls back to 1.
|
|
17
|
+
* @returns `{ left, width }` in pixels.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clipToPixels(clip: {
|
|
20
|
+
startTime: number;
|
|
21
|
+
duration: number;
|
|
22
|
+
}, pixelsPerSecond: number): {
|
|
23
|
+
left: number;
|
|
24
|
+
width: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Convert a pixel offset back to a time value, clamped to `>= 0`.
|
|
28
|
+
*
|
|
29
|
+
* @param pixels - Offset in pixels.
|
|
30
|
+
* @param pixelsPerSecond - Horizontal scale; zero or negative falls back to 1.
|
|
31
|
+
* @returns Time in seconds (never negative).
|
|
32
|
+
*/
|
|
33
|
+
export declare function pixelsToTime(pixels: number, pixelsPerSecond: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Clamp the proposed new `startTime` for a clip move so the clip stays
|
|
36
|
+
* non-negative. (No upper bound — the parent decides whether to clip to a song
|
|
37
|
+
* length.)
|
|
38
|
+
*
|
|
39
|
+
* @param proposedStartTime - The candidate start time in seconds.
|
|
40
|
+
* @returns The clamped start time.
|
|
41
|
+
*/
|
|
42
|
+
export declare function clampClipMove(proposedStartTime: number): number;
|
|
43
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,yBAAyB,OAAO,CAAA;AAE7C,qEAAqE;AACrE,eAAO,MAAM,0BAA0B,IAAI,CAAA;AAE3C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC7C,eAAe,EAAE,MAAM,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAMjC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAI5E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAE/D"}
|
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure geometry helpers of the track-lane primitive: the import path, the
|
|
3
|
+
* same constants and the same math `@molecule/app-feature-track-lane-react`
|
|
4
|
+
* exports.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/** Minimum clip duration in seconds — clips can't be resized below this. */
|
|
9
|
+
export const MIN_CLIP_DURATION_SECONDS = 0.05;
|
|
10
|
+
/** Pointer-distance threshold (px) before a press becomes a drag. */
|
|
11
|
+
export const DRAG_DISTANCE_THRESHOLD_PX = 3;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a clip to its on-lane pixel geometry.
|
|
14
|
+
*
|
|
15
|
+
* @param clip - The clip to project (`startTime` + `duration` in seconds).
|
|
16
|
+
* @param pixelsPerSecond - Horizontal scale; zero or negative falls back to 1.
|
|
17
|
+
* @returns `{ left, width }` in pixels.
|
|
18
|
+
*/
|
|
19
|
+
export function clipToPixels(clip, pixelsPerSecond) {
|
|
20
|
+
const safeScale = pixelsPerSecond > 0 ? pixelsPerSecond : 1;
|
|
21
|
+
return {
|
|
22
|
+
left: clip.startTime * safeScale,
|
|
23
|
+
width: Math.max(1, clip.duration * safeScale),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convert a pixel offset back to a time value, clamped to `>= 0`.
|
|
28
|
+
*
|
|
29
|
+
* @param pixels - Offset in pixels.
|
|
30
|
+
* @param pixelsPerSecond - Horizontal scale; zero or negative falls back to 1.
|
|
31
|
+
* @returns Time in seconds (never negative).
|
|
32
|
+
*/
|
|
33
|
+
export function pixelsToTime(pixels, pixelsPerSecond) {
|
|
34
|
+
const safeScale = pixelsPerSecond > 0 ? pixelsPerSecond : 1;
|
|
35
|
+
const t = pixels / safeScale;
|
|
36
|
+
return t < 0 ? 0 : t;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Clamp the proposed new `startTime` for a clip move so the clip stays
|
|
40
|
+
* non-negative. (No upper bound — the parent decides whether to clip to a song
|
|
41
|
+
* length.)
|
|
42
|
+
*
|
|
43
|
+
* @param proposedStartTime - The candidate start time in seconds.
|
|
44
|
+
* @returns The clamped start time.
|
|
45
|
+
*/
|
|
46
|
+
export function clampClipMove(proposedStartTime) {
|
|
47
|
+
return proposedStartTime < 0 ? 0 : proposedStartTime;
|
|
48
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte horizontal track-lane primitive for multi-track timelines (music DAW,
|
|
3
|
+
* video editor, animation tool). Renders one lane row of draggable + resizable
|
|
4
|
+
* clip blocks on a `pixelsPerSecond` time axis.
|
|
5
|
+
*
|
|
6
|
+
* Svelte counterpart of `@molecule/app-feature-track-lane-react`: the same props
|
|
7
|
+
* (React names), the same DOM for the same input, and the same callback calls,
|
|
8
|
+
* so an app switches framework by changing only the package name it imports.
|
|
9
|
+
*
|
|
10
|
+
* Exports `<TrackLane>` and the `Clip` type, plus the pure-function helpers
|
|
11
|
+
* `clipToPixels`, `pixelsToTime` and `clampClipMove` that back the
|
|
12
|
+
* pointer-event drag/resize math.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```svelte
|
|
16
|
+
* <script lang="ts">
|
|
17
|
+
* import { TrackLane, type Clip } from '@molecule/app-feature-track-lane-svelte'
|
|
18
|
+
*
|
|
19
|
+
* let selected = $state<string>()
|
|
20
|
+
* const clips: Clip[] = [
|
|
21
|
+
* { id: 'a', startTime: 0, duration: 2, color: '#0af', label: 'Kick' },
|
|
22
|
+
* { id: 'b', startTime: 4, duration: 1.5, label: 'Snare' },
|
|
23
|
+
* ]
|
|
24
|
+
* </script>
|
|
25
|
+
*
|
|
26
|
+
* <TrackLane
|
|
27
|
+
* name="Drums"
|
|
28
|
+
* {clips}
|
|
29
|
+
* pixelsPerSecond={20}
|
|
30
|
+
* selectedClipId={selected}
|
|
31
|
+
* onClipClick={(clipId) => (selected = clipId)}
|
|
32
|
+
* />
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* - Requires a bonded ClassMap (`cm.flex`, `cm.cn`, …) — rendering throws
|
|
37
|
+
* otherwise. No router dependency.
|
|
38
|
+
* - Every visible string comes from `useTranslation()` (`trackLane.aria.*` and
|
|
39
|
+
* `trackLane.header`), so a locale switch re-renders it.
|
|
40
|
+
* - Node-valued props (`name`, a clip's `label`) are snippets (or plain text).
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
export * from './components.js';
|
|
45
|
+
export * from './geometry.js';
|
|
46
|
+
export * from './types.js';
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte horizontal track-lane primitive for multi-track timelines (music DAW,
|
|
3
|
+
* video editor, animation tool). Renders one lane row of draggable + resizable
|
|
4
|
+
* clip blocks on a `pixelsPerSecond` time axis.
|
|
5
|
+
*
|
|
6
|
+
* Svelte counterpart of `@molecule/app-feature-track-lane-react`: the same props
|
|
7
|
+
* (React names), the same DOM for the same input, and the same callback calls,
|
|
8
|
+
* so an app switches framework by changing only the package name it imports.
|
|
9
|
+
*
|
|
10
|
+
* Exports `<TrackLane>` and the `Clip` type, plus the pure-function helpers
|
|
11
|
+
* `clipToPixels`, `pixelsToTime` and `clampClipMove` that back the
|
|
12
|
+
* pointer-event drag/resize math.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```svelte
|
|
16
|
+
* <script lang="ts">
|
|
17
|
+
* import { TrackLane, type Clip } from '@molecule/app-feature-track-lane-svelte'
|
|
18
|
+
*
|
|
19
|
+
* let selected = $state<string>()
|
|
20
|
+
* const clips: Clip[] = [
|
|
21
|
+
* { id: 'a', startTime: 0, duration: 2, color: '#0af', label: 'Kick' },
|
|
22
|
+
* { id: 'b', startTime: 4, duration: 1.5, label: 'Snare' },
|
|
23
|
+
* ]
|
|
24
|
+
* </script>
|
|
25
|
+
*
|
|
26
|
+
* <TrackLane
|
|
27
|
+
* name="Drums"
|
|
28
|
+
* {clips}
|
|
29
|
+
* pixelsPerSecond={20}
|
|
30
|
+
* selectedClipId={selected}
|
|
31
|
+
* onClipClick={(clipId) => (selected = clipId)}
|
|
32
|
+
* />
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* - Requires a bonded ClassMap (`cm.flex`, `cm.cn`, …) — rendering throws
|
|
37
|
+
* otherwise. No router dependency.
|
|
38
|
+
* - Every visible string comes from `useTranslation()` (`trackLane.aria.*` and
|
|
39
|
+
* `trackLane.header`), so a locale switch re-renders it.
|
|
40
|
+
* - Node-valued props (`name`, a clip's `label`) are snippets (or plain text).
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
export * from './components.js';
|
|
45
|
+
export * from './geometry.js';
|
|
46
|
+
export * from './types.js';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of the Svelte track-lane primitive — the same props (React names) and
|
|
3
|
+
* the same DOM for the same input as
|
|
4
|
+
* `@molecule/app-feature-track-lane-react`.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
/**
|
|
10
|
+
* A single clip block on a track lane. `startTime` and `duration` are both in
|
|
11
|
+
* seconds; `pixelsPerSecond` on the lane converts them to the on-screen
|
|
12
|
+
* geometry. `id` is a stable identifier used as the row key and as the argument
|
|
13
|
+
* passed back to all event handlers. `color` accents the body fill (defaults to
|
|
14
|
+
* a neutral surface) and `label` is rendered inside the clip when given.
|
|
15
|
+
*/
|
|
16
|
+
export interface Clip {
|
|
17
|
+
/** Stable identifier for the clip (used as the row key + handler arg). */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Clip start time on the lane in seconds. */
|
|
20
|
+
startTime: number;
|
|
21
|
+
/** Clip duration in seconds. Always positive — minimum is enforced. */
|
|
22
|
+
duration: number;
|
|
23
|
+
/** Optional accent color for the clip body (any valid CSS color). */
|
|
24
|
+
color?: string;
|
|
25
|
+
/** Optional inline label rendered on top of the clip body (a snippet or text). */
|
|
26
|
+
label?: string | number | Snippet;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Props accepted by the {@link TrackLane} component — the same props React's
|
|
30
|
+
* `TrackLane` accepts. A node-valued prop is a snippet (or plain text).
|
|
31
|
+
*/
|
|
32
|
+
export interface TrackLaneProps {
|
|
33
|
+
/** Optional lane name shown in the leading lane header. */
|
|
34
|
+
name?: string | number | Snippet;
|
|
35
|
+
/** Clips on this lane. Order is preserved as-is. */
|
|
36
|
+
clips: Clip[];
|
|
37
|
+
/** Horizontal time scale, defaults to 20. */
|
|
38
|
+
pixelsPerSecond?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Optional opaque lane identifier. Forwarded to handlers and emitted as
|
|
41
|
+
* `data-lane` so multi-lane parents can tell lanes apart.
|
|
42
|
+
*/
|
|
43
|
+
lane?: string;
|
|
44
|
+
/** Lane row height in pixels. Defaults to 44. */
|
|
45
|
+
height?: number;
|
|
46
|
+
/** Called when a clip is dragged horizontally. */
|
|
47
|
+
onClipMove?: (clipId: string, startTime: number, lane?: string) => void;
|
|
48
|
+
/** Called when a clip's right edge handle is dragged. */
|
|
49
|
+
onClipResize?: (clipId: string, duration: number, lane?: string) => void;
|
|
50
|
+
/** Called when a clip body is clicked (no drag). */
|
|
51
|
+
onClipClick?: (clipId: string, lane?: string) => void;
|
|
52
|
+
/** Currently-selected clip id (renders the selection ring on that clip). */
|
|
53
|
+
selectedClipId?: string;
|
|
54
|
+
/** Extra classes merged onto the root element. */
|
|
55
|
+
className?: string;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACnB,0EAA0E;IAC1E,EAAE,EAAE,MAAM,CAAA;IACV,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAA;IACjB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAA;IAChB,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;IAChC,oDAAoD;IACpD,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kDAAkD;IAClD,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACvE,yDAAyD;IACzD,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACxE,oDAAoD;IACpD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACrD,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-feature-track-lane-svelte",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Horizontal track lane primitive for music-DAW, video-editor, animation-tool — a single row in a multi-track timeline rendering draggable/resizable clips on a time-base axis",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-feature-track-lane-svelte",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"svelte": "./dist/index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!dist/**/__tests__",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"!dist/**/*.spec.*",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
|
|
27
|
+
"dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"molecule",
|
|
33
|
+
"feature",
|
|
34
|
+
"track-lane",
|
|
35
|
+
"timeline",
|
|
36
|
+
"daw",
|
|
37
|
+
"video-editor",
|
|
38
|
+
"animation",
|
|
39
|
+
"clip",
|
|
40
|
+
"svelte"
|
|
41
|
+
],
|
|
42
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
43
|
+
"license": "Apache-2.0",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
47
|
+
"directory": "packages/app/features/feature-track-lane-svelte"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=20"
|
|
51
|
+
},
|
|
52
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@molecule/app-svelte": "^3.5.0",
|
|
58
|
+
"@molecule/app-ui": "^1.0.1",
|
|
59
|
+
"@molecule/app-ui-svelte": "^1.1.0",
|
|
60
|
+
"svelte": "^5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
64
|
+
"@molecule/app-i18n": "1.2.2",
|
|
65
|
+
"@molecule/app-icons": "1.0.4",
|
|
66
|
+
"@molecule/app-svelte": "3.7.2",
|
|
67
|
+
"@molecule/app-ui": "1.4.0",
|
|
68
|
+
"@molecule/app-ui-svelte": "1.1.7",
|
|
69
|
+
"@sveltejs/package": "3.0.2",
|
|
70
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
71
|
+
"@types/node": "26.6.5",
|
|
72
|
+
"jsdom": "30.1.3",
|
|
73
|
+
"svelte": "5.57.2",
|
|
74
|
+
"svelte-check": "4.7.7",
|
|
75
|
+
"typescript": "6.0.3",
|
|
76
|
+
"vite": "8.3.5",
|
|
77
|
+
"vitest": "4.1.12"
|
|
78
|
+
}
|
|
79
|
+
}
|