@waveform-playlist/ui-components 8.1.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +37 -40
- package/dist/index.d.ts +37 -40
- package/dist/index.js +163 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -17
package/dist/index.mjs
CHANGED
|
@@ -649,6 +649,40 @@ function useChunkedCanvasRefs() {
|
|
|
649
649
|
|
|
650
650
|
// src/components/Channel.tsx
|
|
651
651
|
import { MAX_CANVAS_WIDTH } from "@waveform-playlist/core";
|
|
652
|
+
|
|
653
|
+
// src/utils/peakRendering.ts
|
|
654
|
+
function aggregatePeaks(data, bits, startIndex, endIndex) {
|
|
655
|
+
if (startIndex * 2 + 1 >= data.length) {
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
const maxValue = 2 ** (bits - 1);
|
|
659
|
+
let minPeak = data[startIndex * 2] / maxValue;
|
|
660
|
+
let maxPeak = data[startIndex * 2 + 1] / maxValue;
|
|
661
|
+
for (let p = startIndex + 1; p < endIndex; p++) {
|
|
662
|
+
if (p * 2 + 1 >= data.length) break;
|
|
663
|
+
const pMin = data[p * 2] / maxValue;
|
|
664
|
+
const pMax = data[p * 2 + 1] / maxValue;
|
|
665
|
+
if (pMin < minPeak) minPeak = pMin;
|
|
666
|
+
if (pMax > maxPeak) maxPeak = pMax;
|
|
667
|
+
}
|
|
668
|
+
return { min: minPeak, max: maxPeak };
|
|
669
|
+
}
|
|
670
|
+
function calculateBarRects(x, barWidth, halfHeight, minPeak, maxPeak, drawMode) {
|
|
671
|
+
const min = Math.abs(minPeak * halfHeight);
|
|
672
|
+
const max = Math.abs(maxPeak * halfHeight);
|
|
673
|
+
if (drawMode === "normal") {
|
|
674
|
+
return [{ x, y: halfHeight - max, width: barWidth, height: max + min }];
|
|
675
|
+
}
|
|
676
|
+
return [
|
|
677
|
+
{ x, y: 0, width: barWidth, height: halfHeight - max },
|
|
678
|
+
{ x, y: halfHeight + min, width: barWidth, height: halfHeight - min }
|
|
679
|
+
];
|
|
680
|
+
}
|
|
681
|
+
function calculateFirstBarPosition(canvasStartGlobal, barWidth, step) {
|
|
682
|
+
return Math.floor((canvasStartGlobal - barWidth + step) / step) * step;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// src/components/Channel.tsx
|
|
652
686
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
653
687
|
function createCanvasFillStyle(ctx, color, width, height) {
|
|
654
688
|
if (!isWaveformGradient(color)) {
|
|
@@ -718,7 +752,6 @@ var Channel = (props) => {
|
|
|
718
752
|
const globalPixelOffset = canvasIdx * MAX_CANVAS_WIDTH;
|
|
719
753
|
const ctx = canvas.getContext("2d");
|
|
720
754
|
const h2 = Math.floor(waveHeight / 2);
|
|
721
|
-
const maxValue = 2 ** (bits - 1);
|
|
722
755
|
if (ctx) {
|
|
723
756
|
ctx.resetTransform();
|
|
724
757
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
@@ -734,21 +767,16 @@ var Channel = (props) => {
|
|
|
734
767
|
ctx.fillStyle = createCanvasFillStyle(ctx, fillColor, canvasWidth, waveHeight);
|
|
735
768
|
const canvasStartGlobal = globalPixelOffset;
|
|
736
769
|
const canvasEndGlobal = globalPixelOffset + canvasWidth;
|
|
737
|
-
const firstBarGlobal =
|
|
770
|
+
const firstBarGlobal = calculateFirstBarPosition(canvasStartGlobal, barWidth, step);
|
|
738
771
|
for (let barGlobal = Math.max(0, firstBarGlobal); barGlobal < canvasEndGlobal; barGlobal += step) {
|
|
739
772
|
const x = barGlobal - canvasStartGlobal;
|
|
740
773
|
if (x + barWidth <= 0) continue;
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
if (drawMode === "normal") {
|
|
748
|
-
ctx.fillRect(x, h2 - max, barWidth, max + min);
|
|
749
|
-
} else {
|
|
750
|
-
ctx.fillRect(x, 0, barWidth, h2 - max);
|
|
751
|
-
ctx.fillRect(x, h2 + min, barWidth, h2 - min);
|
|
774
|
+
const peakEnd = Math.min(barGlobal + step, length);
|
|
775
|
+
const peak = aggregatePeaks(data, bits, barGlobal, peakEnd);
|
|
776
|
+
if (peak) {
|
|
777
|
+
const rects = calculateBarRects(x, barWidth, h2, peak.min, peak.max, drawMode);
|
|
778
|
+
for (const rect of rects) {
|
|
779
|
+
ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
752
780
|
}
|
|
753
781
|
}
|
|
754
782
|
}
|
|
@@ -840,8 +868,7 @@ var PlaylistErrorBoundary = class extends React4.Component {
|
|
|
840
868
|
|
|
841
869
|
// src/components/Clip.tsx
|
|
842
870
|
import styled13 from "styled-components";
|
|
843
|
-
import { useDraggable } from "@dnd-kit/
|
|
844
|
-
import { CSS } from "@dnd-kit/utilities";
|
|
871
|
+
import { useDraggable } from "@dnd-kit/react";
|
|
845
872
|
|
|
846
873
|
// src/components/ClipHeader.tsx
|
|
847
874
|
import styled10 from "styled-components";
|
|
@@ -855,7 +882,7 @@ var HeaderContainer = styled10.div`
|
|
|
855
882
|
display: flex;
|
|
856
883
|
align-items: center;
|
|
857
884
|
padding: 0 8px;
|
|
858
|
-
cursor: ${(props) => props.$interactive ?
|
|
885
|
+
cursor: ${(props) => props.$interactive ? "grab" : "default"};
|
|
859
886
|
user-select: none;
|
|
860
887
|
z-index: 110;
|
|
861
888
|
flex-shrink: 0;
|
|
@@ -885,7 +912,7 @@ var ClipHeaderPresentational = ({
|
|
|
885
912
|
trackName,
|
|
886
913
|
isSelected = false
|
|
887
914
|
}) => {
|
|
888
|
-
return /* @__PURE__ */ jsx7(HeaderContainer, { $
|
|
915
|
+
return /* @__PURE__ */ jsx7(HeaderContainer, { $interactive: false, $isSelected: isSelected, children: /* @__PURE__ */ jsx7(TrackName, { children: trackName }) });
|
|
889
916
|
};
|
|
890
917
|
var ClipHeader = ({
|
|
891
918
|
clipId,
|
|
@@ -899,16 +926,14 @@ var ClipHeader = ({
|
|
|
899
926
|
if (disableDrag || !dragHandleProps) {
|
|
900
927
|
return /* @__PURE__ */ jsx7(ClipHeaderPresentational, { trackName, isSelected });
|
|
901
928
|
}
|
|
902
|
-
const {
|
|
929
|
+
const { handleRef } = dragHandleProps;
|
|
903
930
|
return /* @__PURE__ */ jsx7(
|
|
904
931
|
HeaderContainer,
|
|
905
932
|
{
|
|
906
|
-
ref:
|
|
933
|
+
ref: handleRef,
|
|
907
934
|
"data-clip-id": clipId,
|
|
908
935
|
$interactive: true,
|
|
909
936
|
$isSelected: isSelected,
|
|
910
|
-
...listeners,
|
|
911
|
-
...attributes,
|
|
912
937
|
children: /* @__PURE__ */ jsx7(TrackName, { children: trackName })
|
|
913
938
|
}
|
|
914
939
|
);
|
|
@@ -961,11 +986,11 @@ var ClipBoundary = ({
|
|
|
961
986
|
if (!dragHandleProps) {
|
|
962
987
|
return null;
|
|
963
988
|
}
|
|
964
|
-
const {
|
|
989
|
+
const { ref: boundaryRef, isDragging } = dragHandleProps;
|
|
965
990
|
return /* @__PURE__ */ jsx8(
|
|
966
991
|
BoundaryContainer,
|
|
967
992
|
{
|
|
968
|
-
ref:
|
|
993
|
+
ref: boundaryRef,
|
|
969
994
|
"data-clip-id": clipId,
|
|
970
995
|
"data-boundary-edge": edge,
|
|
971
996
|
$edge: edge,
|
|
@@ -973,9 +998,7 @@ var ClipBoundary = ({
|
|
|
973
998
|
$isHovered: isHovered,
|
|
974
999
|
$touchOptimized: touchOptimized,
|
|
975
1000
|
onMouseEnter: () => setIsHovered(true),
|
|
976
|
-
onMouseLeave: () => setIsHovered(false)
|
|
977
|
-
...listeners,
|
|
978
|
-
...attributes
|
|
1001
|
+
onMouseLeave: () => setIsHovered(false)
|
|
979
1002
|
}
|
|
980
1003
|
);
|
|
981
1004
|
};
|
|
@@ -1096,42 +1119,34 @@ var Clip = ({
|
|
|
1096
1119
|
const width = endPixel - left;
|
|
1097
1120
|
const enableDrag = showHeader && !disableHeaderDrag && !isOverlay;
|
|
1098
1121
|
const draggableId = `clip-${trackIndex}-${clipIndex}`;
|
|
1099
|
-
const {
|
|
1122
|
+
const {
|
|
1123
|
+
ref: clipRef,
|
|
1124
|
+
handleRef,
|
|
1125
|
+
isDragSource
|
|
1126
|
+
} = useDraggable({
|
|
1100
1127
|
id: draggableId,
|
|
1101
1128
|
data: { clipId, trackIndex, clipIndex },
|
|
1102
1129
|
disabled: !enableDrag
|
|
1103
1130
|
});
|
|
1104
1131
|
const leftBoundaryId = `clip-boundary-left-${trackIndex}-${clipIndex}`;
|
|
1105
|
-
const {
|
|
1106
|
-
attributes: leftBoundaryAttributes,
|
|
1107
|
-
listeners: leftBoundaryListeners,
|
|
1108
|
-
setActivatorNodeRef: setLeftBoundaryActivatorRef,
|
|
1109
|
-
isDragging: isLeftBoundaryDragging
|
|
1110
|
-
} = useDraggable({
|
|
1132
|
+
const { ref: leftBoundaryRef, isDragSource: isLeftBoundaryDragging } = useDraggable({
|
|
1111
1133
|
id: leftBoundaryId,
|
|
1112
1134
|
data: { clipId, trackIndex, clipIndex, boundary: "left" },
|
|
1113
|
-
disabled: !enableDrag
|
|
1135
|
+
disabled: !enableDrag,
|
|
1136
|
+
feedback: "none"
|
|
1114
1137
|
});
|
|
1115
1138
|
const rightBoundaryId = `clip-boundary-right-${trackIndex}-${clipIndex}`;
|
|
1116
|
-
const {
|
|
1117
|
-
attributes: rightBoundaryAttributes,
|
|
1118
|
-
listeners: rightBoundaryListeners,
|
|
1119
|
-
setActivatorNodeRef: setRightBoundaryActivatorRef,
|
|
1120
|
-
isDragging: isRightBoundaryDragging
|
|
1121
|
-
} = useDraggable({
|
|
1139
|
+
const { ref: rightBoundaryRef, isDragSource: isRightBoundaryDragging } = useDraggable({
|
|
1122
1140
|
id: rightBoundaryId,
|
|
1123
1141
|
data: { clipId, trackIndex, clipIndex, boundary: "right" },
|
|
1124
|
-
disabled: !enableDrag
|
|
1142
|
+
disabled: !enableDrag,
|
|
1143
|
+
feedback: "none"
|
|
1125
1144
|
});
|
|
1126
|
-
const style =
|
|
1127
|
-
transform: CSS.Translate.toString(transform),
|
|
1128
|
-
zIndex: isDragging ? 100 : void 0
|
|
1129
|
-
// Below controls (z-index: 999) but above other clips
|
|
1130
|
-
} : void 0;
|
|
1145
|
+
const style = isDragSource ? { zIndex: 100 } : void 0;
|
|
1131
1146
|
return /* @__PURE__ */ jsxs2(
|
|
1132
1147
|
ClipContainer,
|
|
1133
1148
|
{
|
|
1134
|
-
ref:
|
|
1149
|
+
ref: clipRef,
|
|
1135
1150
|
style,
|
|
1136
1151
|
className,
|
|
1137
1152
|
$left: left,
|
|
@@ -1150,7 +1165,7 @@ var Clip = ({
|
|
|
1150
1165
|
trackName,
|
|
1151
1166
|
isSelected,
|
|
1152
1167
|
disableDrag: disableHeaderDrag,
|
|
1153
|
-
dragHandleProps: enableDrag ? {
|
|
1168
|
+
dragHandleProps: enableDrag ? { handleRef } : void 0
|
|
1154
1169
|
}
|
|
1155
1170
|
),
|
|
1156
1171
|
/* @__PURE__ */ jsx10(ClipViewportOriginProvider, { originX: left, children: /* @__PURE__ */ jsxs2(ChannelsWrapper, { $isOverlay: isOverlay, children: [
|
|
@@ -1184,9 +1199,7 @@ var Clip = ({
|
|
|
1184
1199
|
edge: "left",
|
|
1185
1200
|
touchOptimized,
|
|
1186
1201
|
dragHandleProps: {
|
|
1187
|
-
|
|
1188
|
-
listeners: leftBoundaryListeners,
|
|
1189
|
-
setActivatorNodeRef: setLeftBoundaryActivatorRef,
|
|
1202
|
+
ref: leftBoundaryRef,
|
|
1190
1203
|
isDragging: isLeftBoundaryDragging
|
|
1191
1204
|
}
|
|
1192
1205
|
}
|
|
@@ -1200,9 +1213,7 @@ var Clip = ({
|
|
|
1200
1213
|
edge: "right",
|
|
1201
1214
|
touchOptimized,
|
|
1202
1215
|
dragHandleProps: {
|
|
1203
|
-
|
|
1204
|
-
listeners: rightBoundaryListeners,
|
|
1205
|
-
setActivatorNodeRef: setRightBoundaryActivatorRef,
|
|
1216
|
+
ref: rightBoundaryRef,
|
|
1206
1217
|
isDragging: isRightBoundaryDragging
|
|
1207
1218
|
}
|
|
1208
1219
|
}
|