@qq1948037137/adminsmart-ui 0.1.23 → 0.1.25
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.cjs +70 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/styles/composites.css +13 -0
package/dist/index.cjs
CHANGED
|
@@ -626,6 +626,38 @@ function replayRange(totalTime, startOffsetMs = 0, endOffsetMs) {
|
|
|
626
626
|
// 内部转可见。
|
|
627
627
|
};
|
|
628
628
|
}
|
|
629
|
+
function replayPlaybackWindow(events, startOffsetMs = 0, endOffsetMs) {
|
|
630
|
+
const firstTimestamp = finiteReplayNumber(events[0]?.timestamp);
|
|
631
|
+
const originalTotal = Math.max(0, finiteReplayNumber(events.at(-1)?.timestamp) - firstTimestamp);
|
|
632
|
+
const range = replayRange(originalTotal, startOffsetMs, endOffsetMs);
|
|
633
|
+
if (endOffsetMs === void 0) return { events: structuredClone(events), range };
|
|
634
|
+
const endTimestamp = firstTimestamp + range.end;
|
|
635
|
+
const withinEnd = events.filter((event) => event.timestamp <= endTimestamp);
|
|
636
|
+
if (!withinEnd.some((event) => event.type === 2))
|
|
637
|
+
throw new Error("\u5F53\u524D\u56DE\u653E\u7A97\u53E3\u65E9\u4E8E\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762");
|
|
638
|
+
const completeEvents = withinEnd.filter((event, index) => {
|
|
639
|
+
if (event.type !== 4) return true;
|
|
640
|
+
for (let next = index + 1; next < withinEnd.length; next += 1) {
|
|
641
|
+
if (withinEnd[next].type === 2) return true;
|
|
642
|
+
if (withinEnd[next].type === 4) break;
|
|
643
|
+
}
|
|
644
|
+
return false;
|
|
645
|
+
});
|
|
646
|
+
const copied = structuredClone(completeEvents);
|
|
647
|
+
copied.push({
|
|
648
|
+
type: 5,
|
|
649
|
+
// 官方Custom事件只提供时间调度,不改变页面DOM。
|
|
650
|
+
timestamp: endTimestamp,
|
|
651
|
+
// 请求终点成为官方metadata真实终点,尾部观察时间不缩短。
|
|
652
|
+
data: {
|
|
653
|
+
tag: "adminsmart-replay-boundary",
|
|
654
|
+
// 内部固定标记,不承载业务信息或外部回调。
|
|
655
|
+
payload: null
|
|
656
|
+
// 空载荷不包含用户数据。
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
return { events: copied, range };
|
|
660
|
+
}
|
|
629
661
|
function inclusivePauseOffset(events, target) {
|
|
630
662
|
const logicalTarget = Math.max(0, finiteReplayNumber(target));
|
|
631
663
|
const baseline = finiteReplayNumber(events[0]?.timestamp) + logicalTarget;
|
|
@@ -653,6 +685,25 @@ function replayFit(stageWidth, stageHeight, contentWidth, contentHeight) {
|
|
|
653
685
|
// 垂直居中。
|
|
654
686
|
};
|
|
655
687
|
}
|
|
688
|
+
function replayWidthLayout(stageWidth, contentWidth, contentHeight) {
|
|
689
|
+
const width = finiteReplayNumber(stageWidth);
|
|
690
|
+
const recordedWidth = finiteReplayNumber(contentWidth);
|
|
691
|
+
const recordedHeight = finiteReplayNumber(contentHeight);
|
|
692
|
+
if (width <= 0 || recordedWidth <= 0 || recordedHeight <= 0) return null;
|
|
693
|
+
const scale = width / recordedWidth;
|
|
694
|
+
const height = recordedHeight * scale;
|
|
695
|
+
if (!Number.isFinite(scale) || !Number.isFinite(height) || height <= 0) return null;
|
|
696
|
+
return {
|
|
697
|
+
scale,
|
|
698
|
+
// 普通容器允许按可用宽度放大或缩小。
|
|
699
|
+
height,
|
|
700
|
+
// 官方视口完整占据舞台,业务抽屉负责正文滚动。
|
|
701
|
+
left: 0,
|
|
702
|
+
// 正常容器不增加左右背景留白。
|
|
703
|
+
top: 0
|
|
704
|
+
// 舞台高度与缩放画面一致,无需垂直居中。
|
|
705
|
+
};
|
|
706
|
+
}
|
|
656
707
|
function replayClock(timeMs) {
|
|
657
708
|
const seconds = Math.floor(Math.max(0, finiteReplayNumber(timeMs)) / 1e3);
|
|
658
709
|
return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`;
|
|
@@ -718,11 +769,13 @@ function useSessionReplay(options) {
|
|
|
718
769
|
publish(initialState("empty"));
|
|
719
770
|
return;
|
|
720
771
|
}
|
|
772
|
+
let playback;
|
|
721
773
|
let prepared;
|
|
722
774
|
try {
|
|
723
|
-
|
|
775
|
+
playback = replayPlaybackWindow(prepareReplayEvents(events), startOffsetMs, endOffsetMs);
|
|
776
|
+
prepared = playback.events;
|
|
724
777
|
} catch (reason) {
|
|
725
|
-
const knownMessages = ["\u5F53\u524D\u56DE\u653E\u6CA1\u6709\u8DB3\u591F\u7684\u9875\u9762\u4E8B\u4EF6", "\u5F53\u524D\u56DE\u653E\u4E8B\u4EF6\u65F6\u95F4\u65E0\u6548\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762", "\u5F53\u524D\u56DE\u653E\u7F3A\u5C11\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762"];
|
|
778
|
+
const knownMessages = ["\u5F53\u524D\u56DE\u653E\u6CA1\u6709\u8DB3\u591F\u7684\u9875\u9762\u4E8B\u4EF6", "\u5F53\u524D\u56DE\u653E\u4E8B\u4EF6\u65F6\u95F4\u65E0\u6548\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762", "\u5F53\u524D\u56DE\u653E\u7F3A\u5C11\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762", "\u5F53\u524D\u56DE\u653E\u7A97\u53E3\u65E9\u4E8E\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762"];
|
|
726
779
|
const problem = { code: "invalid-events", message: reason instanceof Error && knownMessages.includes(reason.message) ? reason.message : "\u5F53\u524D\u56DE\u653E\u6570\u636E\u65E0\u6CD5\u8FD8\u539F\u9875\u9762" };
|
|
727
780
|
publish(initialState("error"));
|
|
728
781
|
callbackRef.current.onError?.(problem);
|
|
@@ -760,6 +813,8 @@ function useSessionReplay(options) {
|
|
|
760
813
|
if (engineRef.current === player) engineRef.current = null;
|
|
761
814
|
player = null;
|
|
762
815
|
rootRef.current?.replaceChildren();
|
|
816
|
+
stageRef.current?.style.removeProperty("--adminsmart-replay-recorded-height");
|
|
817
|
+
stageRef.current?.removeAttribute("data-replay-viewport");
|
|
763
818
|
};
|
|
764
819
|
const fail = (code, message) => {
|
|
765
820
|
if (!current || failed) return;
|
|
@@ -773,7 +828,15 @@ function useSessionReplay(options) {
|
|
|
773
828
|
runtimeFailureRef.current = commandFailure;
|
|
774
829
|
const fit = () => {
|
|
775
830
|
if (!current || !player || !stageRef.current) return;
|
|
776
|
-
const
|
|
831
|
+
const stage = stageRef.current;
|
|
832
|
+
const recordedWidth = Number(player.iframe.width);
|
|
833
|
+
const recordedHeight = Number(player.iframe.height);
|
|
834
|
+
const widthLayout = replayWidthLayout(stage.clientWidth, recordedWidth, recordedHeight);
|
|
835
|
+
if (!widthLayout) return;
|
|
836
|
+
stage.style.setProperty("--adminsmart-replay-recorded-height", `${widthLayout.height}px`);
|
|
837
|
+
stage.setAttribute("data-replay-viewport", "recorded");
|
|
838
|
+
const fullscreen = document.fullscreenElement === stage.parentElement;
|
|
839
|
+
const dimensions = fullscreen ? replayFit(stage.clientWidth, stage.clientHeight, recordedWidth, recordedHeight) : widthLayout;
|
|
777
840
|
player.wrapper.style.position = "absolute";
|
|
778
841
|
player.wrapper.style.left = `${dimensions.left}px`;
|
|
779
842
|
player.wrapper.style.top = `${dimensions.top}px`;
|
|
@@ -781,6 +844,7 @@ function useSessionReplay(options) {
|
|
|
781
844
|
player.wrapper.style.transform = `scale(${dimensions.scale})`;
|
|
782
845
|
};
|
|
783
846
|
const scheduleFit = () => {
|
|
847
|
+
if (!current || failed) return;
|
|
784
848
|
if (fitFrame !== void 0) window.cancelAnimationFrame(fitFrame);
|
|
785
849
|
fitFrame = window.requestAnimationFrame(() => {
|
|
786
850
|
fitFrame = void 0;
|
|
@@ -828,7 +892,7 @@ function useSessionReplay(options) {
|
|
|
828
892
|
// 官方日志不会带事件进入控制台。
|
|
829
893
|
});
|
|
830
894
|
engineRef.current = player;
|
|
831
|
-
rangeRef.current =
|
|
895
|
+
rangeRef.current = playback.range;
|
|
832
896
|
const listen = (eventName, handler) => {
|
|
833
897
|
listeners.push([eventName, handler]);
|
|
834
898
|
player.on(eventName, handler);
|
|
@@ -881,6 +945,7 @@ function useSessionReplay(options) {
|
|
|
881
945
|
observer.observe(stageRef.current);
|
|
882
946
|
}
|
|
883
947
|
window.addEventListener("resize", onLayout);
|
|
948
|
+
document.addEventListener("fullscreenchange", onLayout);
|
|
884
949
|
loadReplayEngine().then((value) => {
|
|
885
950
|
if (!current) return;
|
|
886
951
|
Constructor = value;
|
|
@@ -890,6 +955,7 @@ function useSessionReplay(options) {
|
|
|
890
955
|
current = false;
|
|
891
956
|
observer?.disconnect();
|
|
892
957
|
window.removeEventListener("resize", onLayout);
|
|
958
|
+
document.removeEventListener("fullscreenchange", onLayout);
|
|
893
959
|
if (runtimeFailureRef.current === commandFailure) runtimeFailureRef.current = null;
|
|
894
960
|
if (replayEventsRef.current === prepared) replayEventsRef.current = [];
|
|
895
961
|
releaseEngine();
|