@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.js
CHANGED
|
@@ -535,6 +535,38 @@ function replayRange(totalTime, startOffsetMs = 0, endOffsetMs) {
|
|
|
535
535
|
// 内部转可见。
|
|
536
536
|
};
|
|
537
537
|
}
|
|
538
|
+
function replayPlaybackWindow(events, startOffsetMs = 0, endOffsetMs) {
|
|
539
|
+
const firstTimestamp = finiteReplayNumber(events[0]?.timestamp);
|
|
540
|
+
const originalTotal = Math.max(0, finiteReplayNumber(events.at(-1)?.timestamp) - firstTimestamp);
|
|
541
|
+
const range = replayRange(originalTotal, startOffsetMs, endOffsetMs);
|
|
542
|
+
if (endOffsetMs === void 0) return { events: structuredClone(events), range };
|
|
543
|
+
const endTimestamp = firstTimestamp + range.end;
|
|
544
|
+
const withinEnd = events.filter((event) => event.timestamp <= endTimestamp);
|
|
545
|
+
if (!withinEnd.some((event) => event.type === 2))
|
|
546
|
+
throw new Error("\u5F53\u524D\u56DE\u653E\u7A97\u53E3\u65E9\u4E8E\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762");
|
|
547
|
+
const completeEvents = withinEnd.filter((event, index) => {
|
|
548
|
+
if (event.type !== 4) return true;
|
|
549
|
+
for (let next = index + 1; next < withinEnd.length; next += 1) {
|
|
550
|
+
if (withinEnd[next].type === 2) return true;
|
|
551
|
+
if (withinEnd[next].type === 4) break;
|
|
552
|
+
}
|
|
553
|
+
return false;
|
|
554
|
+
});
|
|
555
|
+
const copied = structuredClone(completeEvents);
|
|
556
|
+
copied.push({
|
|
557
|
+
type: 5,
|
|
558
|
+
// 官方Custom事件只提供时间调度,不改变页面DOM。
|
|
559
|
+
timestamp: endTimestamp,
|
|
560
|
+
// 请求终点成为官方metadata真实终点,尾部观察时间不缩短。
|
|
561
|
+
data: {
|
|
562
|
+
tag: "adminsmart-replay-boundary",
|
|
563
|
+
// 内部固定标记,不承载业务信息或外部回调。
|
|
564
|
+
payload: null
|
|
565
|
+
// 空载荷不包含用户数据。
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
return { events: copied, range };
|
|
569
|
+
}
|
|
538
570
|
function inclusivePauseOffset(events, target) {
|
|
539
571
|
const logicalTarget = Math.max(0, finiteReplayNumber(target));
|
|
540
572
|
const baseline = finiteReplayNumber(events[0]?.timestamp) + logicalTarget;
|
|
@@ -562,6 +594,25 @@ function replayFit(stageWidth, stageHeight, contentWidth, contentHeight) {
|
|
|
562
594
|
// 垂直居中。
|
|
563
595
|
};
|
|
564
596
|
}
|
|
597
|
+
function replayWidthLayout(stageWidth, contentWidth, contentHeight) {
|
|
598
|
+
const width = finiteReplayNumber(stageWidth);
|
|
599
|
+
const recordedWidth = finiteReplayNumber(contentWidth);
|
|
600
|
+
const recordedHeight = finiteReplayNumber(contentHeight);
|
|
601
|
+
if (width <= 0 || recordedWidth <= 0 || recordedHeight <= 0) return null;
|
|
602
|
+
const scale = width / recordedWidth;
|
|
603
|
+
const height = recordedHeight * scale;
|
|
604
|
+
if (!Number.isFinite(scale) || !Number.isFinite(height) || height <= 0) return null;
|
|
605
|
+
return {
|
|
606
|
+
scale,
|
|
607
|
+
// 普通容器允许按可用宽度放大或缩小。
|
|
608
|
+
height,
|
|
609
|
+
// 官方视口完整占据舞台,业务抽屉负责正文滚动。
|
|
610
|
+
left: 0,
|
|
611
|
+
// 正常容器不增加左右背景留白。
|
|
612
|
+
top: 0
|
|
613
|
+
// 舞台高度与缩放画面一致,无需垂直居中。
|
|
614
|
+
};
|
|
615
|
+
}
|
|
565
616
|
function replayClock(timeMs) {
|
|
566
617
|
const seconds = Math.floor(Math.max(0, finiteReplayNumber(timeMs)) / 1e3);
|
|
567
618
|
return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`;
|
|
@@ -627,11 +678,13 @@ function useSessionReplay(options) {
|
|
|
627
678
|
publish(initialState("empty"));
|
|
628
679
|
return;
|
|
629
680
|
}
|
|
681
|
+
let playback;
|
|
630
682
|
let prepared;
|
|
631
683
|
try {
|
|
632
|
-
|
|
684
|
+
playback = replayPlaybackWindow(prepareReplayEvents(events), startOffsetMs, endOffsetMs);
|
|
685
|
+
prepared = playback.events;
|
|
633
686
|
} catch (reason) {
|
|
634
|
-
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"];
|
|
687
|
+
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"];
|
|
635
688
|
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" };
|
|
636
689
|
publish(initialState("error"));
|
|
637
690
|
callbackRef.current.onError?.(problem);
|
|
@@ -669,6 +722,8 @@ function useSessionReplay(options) {
|
|
|
669
722
|
if (engineRef.current === player) engineRef.current = null;
|
|
670
723
|
player = null;
|
|
671
724
|
rootRef.current?.replaceChildren();
|
|
725
|
+
stageRef.current?.style.removeProperty("--adminsmart-replay-recorded-height");
|
|
726
|
+
stageRef.current?.removeAttribute("data-replay-viewport");
|
|
672
727
|
};
|
|
673
728
|
const fail = (code, message) => {
|
|
674
729
|
if (!current || failed) return;
|
|
@@ -682,7 +737,15 @@ function useSessionReplay(options) {
|
|
|
682
737
|
runtimeFailureRef.current = commandFailure;
|
|
683
738
|
const fit = () => {
|
|
684
739
|
if (!current || !player || !stageRef.current) return;
|
|
685
|
-
const
|
|
740
|
+
const stage = stageRef.current;
|
|
741
|
+
const recordedWidth = Number(player.iframe.width);
|
|
742
|
+
const recordedHeight = Number(player.iframe.height);
|
|
743
|
+
const widthLayout = replayWidthLayout(stage.clientWidth, recordedWidth, recordedHeight);
|
|
744
|
+
if (!widthLayout) return;
|
|
745
|
+
stage.style.setProperty("--adminsmart-replay-recorded-height", `${widthLayout.height}px`);
|
|
746
|
+
stage.setAttribute("data-replay-viewport", "recorded");
|
|
747
|
+
const fullscreen = document.fullscreenElement === stage.parentElement;
|
|
748
|
+
const dimensions = fullscreen ? replayFit(stage.clientWidth, stage.clientHeight, recordedWidth, recordedHeight) : widthLayout;
|
|
686
749
|
player.wrapper.style.position = "absolute";
|
|
687
750
|
player.wrapper.style.left = `${dimensions.left}px`;
|
|
688
751
|
player.wrapper.style.top = `${dimensions.top}px`;
|
|
@@ -690,6 +753,7 @@ function useSessionReplay(options) {
|
|
|
690
753
|
player.wrapper.style.transform = `scale(${dimensions.scale})`;
|
|
691
754
|
};
|
|
692
755
|
const scheduleFit = () => {
|
|
756
|
+
if (!current || failed) return;
|
|
693
757
|
if (fitFrame !== void 0) window.cancelAnimationFrame(fitFrame);
|
|
694
758
|
fitFrame = window.requestAnimationFrame(() => {
|
|
695
759
|
fitFrame = void 0;
|
|
@@ -737,7 +801,7 @@ function useSessionReplay(options) {
|
|
|
737
801
|
// 官方日志不会带事件进入控制台。
|
|
738
802
|
});
|
|
739
803
|
engineRef.current = player;
|
|
740
|
-
rangeRef.current =
|
|
804
|
+
rangeRef.current = playback.range;
|
|
741
805
|
const listen = (eventName, handler) => {
|
|
742
806
|
listeners.push([eventName, handler]);
|
|
743
807
|
player.on(eventName, handler);
|
|
@@ -790,6 +854,7 @@ function useSessionReplay(options) {
|
|
|
790
854
|
observer.observe(stageRef.current);
|
|
791
855
|
}
|
|
792
856
|
window.addEventListener("resize", onLayout);
|
|
857
|
+
document.addEventListener("fullscreenchange", onLayout);
|
|
793
858
|
loadReplayEngine().then((value) => {
|
|
794
859
|
if (!current) return;
|
|
795
860
|
Constructor = value;
|
|
@@ -799,6 +864,7 @@ function useSessionReplay(options) {
|
|
|
799
864
|
current = false;
|
|
800
865
|
observer?.disconnect();
|
|
801
866
|
window.removeEventListener("resize", onLayout);
|
|
867
|
+
document.removeEventListener("fullscreenchange", onLayout);
|
|
802
868
|
if (runtimeFailureRef.current === commandFailure) runtimeFailureRef.current = null;
|
|
803
869
|
if (replayEventsRef.current === prepared) replayEventsRef.current = [];
|
|
804
870
|
releaseEngine();
|