@deepseek-ai/dsh-client-ui-trajectory 0.2.1-alpha.2 → 0.2.1-alpha.4

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/lib/client.js CHANGED
@@ -4,33 +4,10 @@ window.__ModuleLoader__.load({
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
- //#region \0rolldown/runtime.js
8
- var __create = Object.create;
9
- var __defProp = Object.defineProperty;
10
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
- var __getOwnPropNames = Object.getOwnPropertyNames;
12
- var __getProtoOf = Object.getPrototypeOf;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
16
- key = keys[i];
17
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
- get: ((k) => from[k]).bind(null, key),
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
- value: mod,
26
- enumerable: true
27
- }) : target, mod));
28
- //#endregion
29
7
  let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
30
8
  let react_jsx_runtime = require("react/jsx-runtime");
31
9
  let react = require("react");
32
- react = __toESM(react, 1);
33
- let react_dom = require("react-dom");
10
+ let _tanstack_react_virtual = require("@tanstack/react-virtual");
34
11
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
35
12
  //#region lib/types/client/duration-store.js
36
13
  /**
@@ -2538,1191 +2515,6 @@ window.__ModuleLoader__.load({
2538
2515
  ctx.uiConversation.events.register(trajectoryToolDefinition);
2539
2516
  }
2540
2517
  //#endregion
2541
- //#region ../../../node_modules/.pnpm/@tanstack+virtual-core@3.17.8/node_modules/@tanstack/virtual-core/dist/esm/lazy-measurements.js
2542
- function createLazyMeasurementsView(count, flat, getItemKey) {
2543
- const cache = new Array(count);
2544
- return new Proxy(cache, { get(target, prop, receiver) {
2545
- if (typeof prop === "string") {
2546
- const c = prop.charCodeAt(0);
2547
- if (c >= 48 && c <= 57) {
2548
- const i = +prop;
2549
- if (Number.isInteger(i) && i >= 0 && i < count) {
2550
- let v = target[i];
2551
- if (!v) {
2552
- const s = flat[i * 2];
2553
- v = target[i] = {
2554
- index: i,
2555
- key: getItemKey(i),
2556
- start: s,
2557
- size: flat[i * 2 + 1],
2558
- end: s + flat[i * 2 + 1],
2559
- lane: 0
2560
- };
2561
- }
2562
- return v;
2563
- }
2564
- }
2565
- if (prop === "length") return count;
2566
- }
2567
- return Reflect.get(target, prop, receiver);
2568
- } });
2569
- }
2570
- //#endregion
2571
- //#region ../../../node_modules/.pnpm/@tanstack+virtual-core@3.17.8/node_modules/@tanstack/virtual-core/dist/esm/utils.js
2572
- function memo$1(getDeps, fn, opts) {
2573
- let deps = opts.initialDeps ?? [];
2574
- let result;
2575
- let isInitial = true;
2576
- function memoizedFunction() {
2577
- const newDeps = getDeps();
2578
- if (!(newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep))) return result;
2579
- deps = newDeps;
2580
- result = fn(...newDeps);
2581
- if ((opts == null ? void 0 : opts.onChange) && !(isInitial && opts.skipInitialOnChange)) opts.onChange(result);
2582
- isInitial = false;
2583
- return result;
2584
- }
2585
- memoizedFunction.updateDeps = (newDeps) => {
2586
- deps = newDeps;
2587
- };
2588
- return memoizedFunction;
2589
- }
2590
- function notUndefined(value, msg) {
2591
- if (value === void 0) throw new Error(`Unexpected undefined${msg ? `: ${msg}` : ""}`);
2592
- else return value;
2593
- }
2594
- const approxEqual = (a, b) => Math.abs(a - b) < 1.01;
2595
- const debounce = (targetWindow, fn, ms) => {
2596
- let timeoutId;
2597
- return Object.assign(function(...args) {
2598
- targetWindow.clearTimeout(timeoutId);
2599
- timeoutId = targetWindow.setTimeout(() => fn.apply(this, args), ms);
2600
- }, { cancel: () => {
2601
- targetWindow.clearTimeout(timeoutId);
2602
- } });
2603
- };
2604
- //#endregion
2605
- //#region ../../../node_modules/.pnpm/@tanstack+virtual-core@3.17.8/node_modules/@tanstack/virtual-core/dist/esm/index.js
2606
- let _isIOSResult;
2607
- const isIOSWebKit = () => {
2608
- if (_isIOSResult !== void 0) return _isIOSResult;
2609
- if (typeof navigator === "undefined") return _isIOSResult = false;
2610
- if (/iP(hone|od|ad)/.test(navigator.userAgent)) return _isIOSResult = true;
2611
- const mtp = navigator.maxTouchPoints;
2612
- return _isIOSResult = navigator.platform === "MacIntel" && mtp !== void 0 && mtp > 0;
2613
- };
2614
- const getRect = (element) => {
2615
- const { offsetWidth, offsetHeight } = element;
2616
- return {
2617
- width: offsetWidth,
2618
- height: offsetHeight
2619
- };
2620
- };
2621
- const defaultKeyExtractor = (index) => index;
2622
- const defaultRangeExtractor = (range) => {
2623
- const start = Math.max(range.startIndex - range.overscan, 0);
2624
- const len = Math.min(range.endIndex + range.overscan, range.count - 1) - start + 1;
2625
- const arr = new Array(len);
2626
- for (let i = 0; i < len; i++) arr[i] = start + i;
2627
- return arr;
2628
- };
2629
- const observeElementRect = (instance, cb) => {
2630
- const element = instance.scrollElement;
2631
- if (!element) return;
2632
- const targetWindow = instance.targetWindow;
2633
- if (!targetWindow) return;
2634
- const handler = (rect) => {
2635
- const { width, height } = rect;
2636
- cb({
2637
- width: Math.round(width),
2638
- height: Math.round(height)
2639
- });
2640
- };
2641
- handler(getRect(element));
2642
- if (!targetWindow.ResizeObserver) return () => {};
2643
- const observer = new targetWindow.ResizeObserver((entries) => {
2644
- const run = () => {
2645
- const entry = entries[0];
2646
- if (entry == null ? void 0 : entry.borderBoxSize) {
2647
- const box = entry.borderBoxSize[0];
2648
- if (box) {
2649
- handler({
2650
- width: box.inlineSize,
2651
- height: box.blockSize
2652
- });
2653
- return;
2654
- }
2655
- }
2656
- handler(getRect(element));
2657
- };
2658
- instance.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
2659
- });
2660
- observer.observe(element, { box: "border-box" });
2661
- return () => {
2662
- observer.unobserve(element);
2663
- };
2664
- };
2665
- const addEventListenerOptions = { passive: true };
2666
- const supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
2667
- const observeOffset = (instance, cb, readOffset) => {
2668
- const element = instance.scrollElement;
2669
- if (!element) return;
2670
- const targetWindow = instance.targetWindow;
2671
- if (!targetWindow) return;
2672
- const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
2673
- let offset = 0;
2674
- const fallback = registerScrollendEvent ? null : debounce(targetWindow, () => cb(offset, false), instance.options.isScrollingResetDelay);
2675
- const createHandler = (isScrolling) => () => {
2676
- offset = readOffset(element);
2677
- fallback?.();
2678
- cb(offset, isScrolling);
2679
- };
2680
- const handler = createHandler(true);
2681
- const endHandler = createHandler(false);
2682
- element.addEventListener("scroll", handler, addEventListenerOptions);
2683
- if (registerScrollendEvent) element.addEventListener("scrollend", endHandler, addEventListenerOptions);
2684
- return () => {
2685
- element.removeEventListener("scroll", handler);
2686
- if (registerScrollendEvent) element.removeEventListener("scrollend", endHandler);
2687
- fallback?.cancel();
2688
- };
2689
- };
2690
- const observeElementOffset = (instance, cb) => observeOffset(instance, cb, (el) => {
2691
- const { horizontal, isRtl } = instance.options;
2692
- return horizontal ? el.scrollLeft * (isRtl && -1 || 1) : el.scrollTop;
2693
- });
2694
- const measureElement = (element, entry, instance) => {
2695
- if (instance.options.useCachedMeasurements) {
2696
- const index = instance.indexFromElement(element);
2697
- const key = instance.options.getItemKey(index);
2698
- return instance.itemSizeCache.get(key) ?? instance.options.estimateSize(index);
2699
- }
2700
- if (entry == null ? void 0 : entry.borderBoxSize) {
2701
- const box = entry.borderBoxSize[0];
2702
- if (box) return Math.round(box[instance.options.horizontal ? "inlineSize" : "blockSize"]);
2703
- }
2704
- if (!entry) {
2705
- const index = instance.indexFromElement(element);
2706
- const key = instance.options.getItemKey(index);
2707
- const cachedSize = instance.itemSizeCache.get(key);
2708
- if (cachedSize !== void 0) return cachedSize;
2709
- }
2710
- return element[instance.options.horizontal ? "offsetWidth" : "offsetHeight"];
2711
- };
2712
- const scrollWithAdjustments = (offset, { adjustments = 0, behavior }, instance) => {
2713
- var _a, _b;
2714
- (_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null || _b.call(_a, {
2715
- [instance.options.horizontal ? "left" : "top"]: offset + adjustments,
2716
- behavior
2717
- });
2718
- };
2719
- const elementScroll = scrollWithAdjustments;
2720
- var Virtualizer = class {
2721
- constructor(opts) {
2722
- this.unsubs = [];
2723
- this.scrollElement = null;
2724
- this.targetWindow = null;
2725
- this.isScrolling = false;
2726
- this.scrollState = null;
2727
- this.measurementsCache = [];
2728
- this._flatMeasurements = null;
2729
- this.itemSizeCache = /* @__PURE__ */ new Map();
2730
- this.itemSizeCacheVersion = 0;
2731
- this.laneAssignments = /* @__PURE__ */ new Map();
2732
- this.pendingMin = null;
2733
- this.prevLanes = void 0;
2734
- this.lanesChangedFlag = false;
2735
- this.lanesSettling = false;
2736
- this.pendingScrollAnchor = null;
2737
- this.scrollRect = null;
2738
- this.scrollOffset = null;
2739
- this.scrollDirection = null;
2740
- this.scrollAdjustments = 0;
2741
- this._iosDeferredAdjustment = 0;
2742
- this._iosTouching = false;
2743
- this._iosJustTouchEnded = false;
2744
- this._iosTouchEndTimerId = null;
2745
- this._intendedScrollOffset = null;
2746
- this.elementsCache = /* @__PURE__ */ new Map();
2747
- this.now = () => {
2748
- var _a, _b, _c;
2749
- return ((_c = (_b = (_a = this.targetWindow) == null ? void 0 : _a.performance) == null ? void 0 : _b.now) == null ? void 0 : _c.call(_b)) ?? Date.now();
2750
- };
2751
- this.observer = /* @__PURE__ */ (() => {
2752
- let _ro = null;
2753
- const get = () => {
2754
- if (_ro) return _ro;
2755
- if (!this.targetWindow || !this.targetWindow.ResizeObserver) return null;
2756
- return _ro = new this.targetWindow.ResizeObserver((entries) => {
2757
- entries.forEach((entry) => {
2758
- const run = () => {
2759
- const node = entry.target;
2760
- const index = this.indexFromElement(node);
2761
- if (!node.isConnected) {
2762
- this.observer.unobserve(node);
2763
- for (const [cacheKey, cachedNode] of this.elementsCache) if (cachedNode === node) {
2764
- this.elementsCache.delete(cacheKey);
2765
- break;
2766
- }
2767
- return;
2768
- }
2769
- if (!this.isIndexInRange(index)) return;
2770
- if (this.shouldMeasureDuringScroll(index)) this.resizeItem(index, this.options.measureElement(node, entry, this));
2771
- };
2772
- this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
2773
- });
2774
- });
2775
- };
2776
- return {
2777
- disconnect: () => {
2778
- var _a;
2779
- (_a = get()) == null || _a.disconnect();
2780
- _ro = null;
2781
- },
2782
- observe: (target) => {
2783
- var _a;
2784
- return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
2785
- },
2786
- unobserve: (target) => {
2787
- var _a;
2788
- return (_a = get()) == null ? void 0 : _a.unobserve(target);
2789
- }
2790
- };
2791
- })();
2792
- this.range = null;
2793
- this.setOptions = (opts2) => {
2794
- var _a, _b;
2795
- const merged = {
2796
- debug: false,
2797
- initialOffset: 0,
2798
- overscan: 1,
2799
- paddingStart: 0,
2800
- paddingEnd: 0,
2801
- scrollPaddingStart: 0,
2802
- scrollPaddingEnd: 0,
2803
- horizontal: false,
2804
- getItemKey: defaultKeyExtractor,
2805
- rangeExtractor: defaultRangeExtractor,
2806
- onChange: () => {},
2807
- measureElement,
2808
- initialRect: {
2809
- width: 0,
2810
- height: 0
2811
- },
2812
- scrollMargin: 0,
2813
- gap: 0,
2814
- indexAttribute: "data-index",
2815
- initialMeasurementsCache: [],
2816
- lanes: 1,
2817
- anchorTo: "start",
2818
- followOnAppend: false,
2819
- scrollEndThreshold: 1,
2820
- isScrollingResetDelay: 150,
2821
- enabled: true,
2822
- isRtl: false,
2823
- useScrollendEvent: false,
2824
- useAnimationFrameWithResizeObserver: false,
2825
- laneAssignmentMode: "estimate",
2826
- useCachedMeasurements: false
2827
- };
2828
- for (const key in opts2) {
2829
- const v = opts2[key];
2830
- if (v !== void 0) merged[key] = v;
2831
- }
2832
- const prevOptions = this.options;
2833
- let anchor = null;
2834
- let followOnAppend = null;
2835
- let edgeKeysChanged = false;
2836
- if (prevOptions !== void 0 && prevOptions.enabled && merged.enabled && merged.anchorTo === "end" && this.scrollElement !== null) {
2837
- const prevCount = prevOptions.count;
2838
- const nextCount = merged.count;
2839
- const measurements = this.getMeasurements();
2840
- const prevFirstKey = prevCount > 0 ? ((_a = measurements[0]) == null ? void 0 : _a.key) ?? prevOptions.getItemKey(0) : null;
2841
- const prevLastKey = prevCount > 0 ? ((_b = measurements[prevCount - 1]) == null ? void 0 : _b.key) ?? prevOptions.getItemKey(prevCount - 1) : null;
2842
- if (nextCount !== prevCount || prevCount > 0 && nextCount > 0 && (merged.getItemKey(0) !== prevFirstKey || merged.getItemKey(nextCount - 1) !== prevLastKey)) {
2843
- edgeKeysChanged = true;
2844
- const item = prevCount > 0 ? this.getVirtualItemForOffset(this.getScrollOffset()) ?? measurements[0] : null;
2845
- if (item) anchor = [item.key, this.getScrollOffset() - item.start];
2846
- const behavior = merged.followOnAppend === true ? "auto" : merged.followOnAppend || null;
2847
- if (behavior && nextCount > prevCount && this.isAtEnd(prevOptions.scrollEndThreshold) && (prevCount === 0 || merged.getItemKey(nextCount - 1) !== prevLastKey)) followOnAppend = behavior;
2848
- }
2849
- }
2850
- this.options = merged;
2851
- if (edgeKeysChanged) {
2852
- this.pendingMin = 0;
2853
- this.itemSizeCacheVersion++;
2854
- }
2855
- let anchorResolved = false;
2856
- let anchorDelta = 0;
2857
- if (anchor && this.scrollOffset !== null) {
2858
- const [anchorKey, anchorOffset] = anchor;
2859
- const newMeasurements = this.getMeasurements();
2860
- const { count, getItemKey } = this.options;
2861
- let idx = 0;
2862
- while (idx < count && getItemKey(idx) !== anchorKey) idx++;
2863
- if (idx < count) {
2864
- const anchorItem = newMeasurements[idx];
2865
- if (anchorItem) {
2866
- const newOffset = Math.max(0, anchorItem.start + anchorOffset);
2867
- if (newOffset !== this.scrollOffset) {
2868
- anchorDelta = newOffset - this.scrollOffset;
2869
- this.scrollOffset = newOffset;
2870
- anchorResolved = true;
2871
- }
2872
- }
2873
- }
2874
- }
2875
- if (anchorResolved || followOnAppend) this.pendingScrollAnchor = [
2876
- anchorResolved ? anchor[0] : null,
2877
- anchorResolved ? anchor[1] : 0,
2878
- followOnAppend,
2879
- anchorDelta
2880
- ];
2881
- };
2882
- this.notify = (sync) => {
2883
- var _a, _b;
2884
- (_b = (_a = this.options).onChange) == null || _b.call(_a, this, sync);
2885
- };
2886
- this.maybeNotify = memo$1(() => {
2887
- this.calculateRange();
2888
- return [
2889
- this.isScrolling,
2890
- this.range ? this.range.startIndex : null,
2891
- this.range ? this.range.endIndex : null
2892
- ];
2893
- }, (isScrolling) => {
2894
- this.notify(isScrolling);
2895
- }, {
2896
- key: false,
2897
- debug: () => this.options.debug,
2898
- initialDeps: [
2899
- this.isScrolling,
2900
- this.range ? this.range.startIndex : null,
2901
- this.range ? this.range.endIndex : null
2902
- ]
2903
- });
2904
- this.cleanup = () => {
2905
- this.unsubs.filter(Boolean).forEach((d) => d());
2906
- this.unsubs = [];
2907
- this.observer.disconnect();
2908
- if (this.rafId != null && this.targetWindow) {
2909
- this.targetWindow.cancelAnimationFrame(this.rafId);
2910
- this.rafId = null;
2911
- }
2912
- this.scrollState = null;
2913
- this.isScrolling = false;
2914
- this.scrollDirection = null;
2915
- this._iosDeferredAdjustment = 0;
2916
- this._iosTouching = false;
2917
- this._iosJustTouchEnded = false;
2918
- this.scrollElement = null;
2919
- this.targetWindow = null;
2920
- };
2921
- this._didMount = () => {
2922
- return () => {
2923
- this.cleanup();
2924
- };
2925
- };
2926
- this._willUpdate = () => {
2927
- var _a;
2928
- const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
2929
- if (this.scrollElement !== scrollElement) {
2930
- this.cleanup();
2931
- if (!scrollElement) {
2932
- this.maybeNotify();
2933
- return;
2934
- }
2935
- this.scrollElement = scrollElement;
2936
- if (this.scrollElement && "ownerDocument" in this.scrollElement) this.targetWindow = this.scrollElement.ownerDocument.defaultView;
2937
- else this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
2938
- this.elementsCache.forEach((cached) => {
2939
- this.observer.observe(cached);
2940
- });
2941
- this.unsubs.push(this.options.observeElementRect(this, (rect) => {
2942
- this.scrollRect = rect;
2943
- this.maybeNotify();
2944
- }));
2945
- this.unsubs.push(this.options.observeElementOffset(this, (offset, isScrolling) => {
2946
- if (isScrolling && this._intendedScrollOffset === null && offset === this.scrollOffset) return;
2947
- if (this._intendedScrollOffset !== null && Math.abs(offset - this._intendedScrollOffset) < 1.5) offset = this._intendedScrollOffset;
2948
- this._intendedScrollOffset = null;
2949
- this.scrollAdjustments = 0;
2950
- const prevOffset = this.getScrollOffset();
2951
- this.scrollDirection = isScrolling ? prevOffset === offset ? this.scrollDirection : prevOffset < offset ? "forward" : "backward" : null;
2952
- this.scrollOffset = offset;
2953
- this.isScrolling = isScrolling;
2954
- this._flushIosDeferredIfReady();
2955
- if (this.scrollState) this.scheduleScrollReconcile();
2956
- this.maybeNotify();
2957
- }));
2958
- if ("addEventListener" in this.scrollElement) {
2959
- const scrollEl = this.scrollElement;
2960
- const onTouchStart = () => {
2961
- this._iosTouching = true;
2962
- this._iosJustTouchEnded = false;
2963
- if (this._iosTouchEndTimerId !== null && this.targetWindow != null) {
2964
- this.targetWindow.clearTimeout(this._iosTouchEndTimerId);
2965
- this._iosTouchEndTimerId = null;
2966
- }
2967
- };
2968
- const onTouchEnd = () => {
2969
- this._iosTouching = false;
2970
- if (!isIOSWebKit() || this.targetWindow == null) return;
2971
- this._iosJustTouchEnded = true;
2972
- this._iosTouchEndTimerId = this.targetWindow.setTimeout(() => {
2973
- this._iosJustTouchEnded = false;
2974
- this._iosTouchEndTimerId = null;
2975
- this._flushIosDeferredIfReady();
2976
- }, 150);
2977
- };
2978
- scrollEl.addEventListener("touchstart", onTouchStart, addEventListenerOptions);
2979
- scrollEl.addEventListener("touchend", onTouchEnd, addEventListenerOptions);
2980
- this.unsubs.push(() => {
2981
- scrollEl.removeEventListener("touchstart", onTouchStart);
2982
- scrollEl.removeEventListener("touchend", onTouchEnd);
2983
- if (this._iosTouchEndTimerId !== null && this.targetWindow != null) {
2984
- this.targetWindow.clearTimeout(this._iosTouchEndTimerId);
2985
- this._iosTouchEndTimerId = null;
2986
- }
2987
- });
2988
- }
2989
- this._scrollToOffset(this.getScrollOffset(), {
2990
- adjustments: void 0,
2991
- behavior: void 0
2992
- });
2993
- }
2994
- const anchor = this.pendingScrollAnchor;
2995
- this.pendingScrollAnchor = null;
2996
- if (anchor && this.scrollElement && this.options.enabled) {
2997
- const [key, _offset, followOnAppend, anchorDelta] = anchor;
2998
- if (key !== null && !followOnAppend) if (isIOSWebKit() && (this.isScrolling || this._iosTouching || this._iosJustTouchEnded)) {
2999
- if (anchorDelta !== 0) this._iosDeferredAdjustment += anchorDelta;
3000
- } else this._scrollToOffset(this.getScrollOffset(), {
3001
- adjustments: void 0,
3002
- behavior: void 0
3003
- });
3004
- if (followOnAppend) this.scrollToEnd({ behavior: followOnAppend });
3005
- }
3006
- };
3007
- this._flushIosDeferredIfReady = () => {
3008
- if (this._iosDeferredAdjustment === 0) return;
3009
- if (this.isScrolling) return;
3010
- if (this._iosTouching) return;
3011
- if (this._iosJustTouchEnded) return;
3012
- const cur = this.getScrollOffset();
3013
- const max = this.getMaxScrollOffset();
3014
- if (cur < 0 || cur > max) return;
3015
- if (this._iosDeferredAdjustment < 0 && cur >= max - 1) {
3016
- this._iosDeferredAdjustment = 0;
3017
- return;
3018
- }
3019
- const delta = this._iosDeferredAdjustment;
3020
- this._iosDeferredAdjustment = 0;
3021
- this._scrollToOffset(cur, {
3022
- adjustments: this.scrollAdjustments += delta,
3023
- behavior: void 0
3024
- });
3025
- };
3026
- this.rafId = null;
3027
- this.getSize = () => {
3028
- if (!this.options.enabled) {
3029
- this.scrollRect = null;
3030
- return 0;
3031
- }
3032
- this.scrollRect = this.scrollRect ?? this.options.initialRect;
3033
- return this.scrollRect[this.options.horizontal ? "width" : "height"];
3034
- };
3035
- this.getScrollOffset = () => {
3036
- if (!this.options.enabled) {
3037
- this.scrollOffset = null;
3038
- return 0;
3039
- }
3040
- this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
3041
- return this.scrollOffset;
3042
- };
3043
- this.getMeasurementOptions = memo$1(() => [
3044
- this.options.count,
3045
- this.options.paddingStart,
3046
- this.options.scrollMargin,
3047
- this.options.getItemKey,
3048
- this.options.enabled,
3049
- this.options.lanes,
3050
- this.options.laneAssignmentMode,
3051
- this.options.gap
3052
- ], (count, paddingStart, scrollMargin, getItemKey, enabled, lanes, laneAssignmentMode, gap) => {
3053
- if (this.prevLanes !== void 0 && this.prevLanes !== lanes) this.lanesChangedFlag = true;
3054
- this.prevLanes = lanes;
3055
- this.pendingMin = null;
3056
- return {
3057
- count,
3058
- paddingStart,
3059
- scrollMargin,
3060
- getItemKey,
3061
- enabled,
3062
- lanes,
3063
- laneAssignmentMode,
3064
- gap
3065
- };
3066
- }, { key: false });
3067
- this.isIndexInRange = (index) => index >= 0 && index < this.options.count;
3068
- this.getMeasurements = memo$1(() => [this.getMeasurementOptions(), this.itemSizeCacheVersion], ({ count, paddingStart, scrollMargin, getItemKey, enabled, lanes, laneAssignmentMode, gap }, _itemSizeCacheVersion) => {
3069
- const itemSizeCache = this.itemSizeCache;
3070
- if (!enabled) {
3071
- this.measurementsCache = [];
3072
- this.itemSizeCache.clear();
3073
- this.laneAssignments.clear();
3074
- return [];
3075
- }
3076
- if (this.laneAssignments.size > count) {
3077
- for (const index of this.laneAssignments.keys()) if (index >= count) this.laneAssignments.delete(index);
3078
- }
3079
- if (this.lanesChangedFlag) {
3080
- this.lanesChangedFlag = false;
3081
- this.lanesSettling = true;
3082
- this.measurementsCache = [];
3083
- this.itemSizeCache.clear();
3084
- this.laneAssignments.clear();
3085
- this.pendingMin = null;
3086
- }
3087
- if (this.measurementsCache.length === 0 && !this.lanesSettling) {
3088
- this.measurementsCache = this.options.initialMeasurementsCache;
3089
- this.measurementsCache.forEach((item) => {
3090
- this.itemSizeCache.set(item.key, item.size);
3091
- });
3092
- }
3093
- const min = this.lanesSettling ? 0 : this.pendingMin ?? 0;
3094
- this.pendingMin = null;
3095
- if (this.lanesSettling && this.measurementsCache.length === count) this.lanesSettling = false;
3096
- if (lanes === 1) {
3097
- const need = count * 2;
3098
- let flat = this._flatMeasurements;
3099
- if (!flat || flat.length < need) {
3100
- const next = new Float64Array(need);
3101
- if (flat && min > 0) next.set(flat.subarray(0, min * 2));
3102
- flat = next;
3103
- this._flatMeasurements = flat;
3104
- }
3105
- let runningStart;
3106
- if (min === 0) runningStart = paddingStart + scrollMargin;
3107
- else {
3108
- const prevIdx = min - 1;
3109
- runningStart = flat[prevIdx * 2] + flat[prevIdx * 2 + 1] + gap;
3110
- }
3111
- for (let i = min; i < count; i++) {
3112
- const key = getItemKey(i);
3113
- const measuredSize = itemSizeCache.get(key);
3114
- const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
3115
- flat[i * 2] = runningStart;
3116
- flat[i * 2 + 1] = size;
3117
- runningStart += size + gap;
3118
- }
3119
- const view = createLazyMeasurementsView(count, flat, getItemKey);
3120
- this.measurementsCache = view;
3121
- return view;
3122
- }
3123
- const measurements = this.measurementsCache.slice(0, min);
3124
- const laneLastIndex = new Array(lanes).fill(void 0);
3125
- const laneEnds = new Float64Array(lanes);
3126
- let filledLanes = 0;
3127
- for (let m = 0; m < min; m++) {
3128
- const item = measurements[m];
3129
- if (item) {
3130
- if (laneLastIndex[item.lane] === void 0) filledLanes++;
3131
- laneLastIndex[item.lane] = m;
3132
- laneEnds[item.lane] = item.end;
3133
- }
3134
- }
3135
- for (let i = min; i < count; i++) {
3136
- const key = getItemKey(i);
3137
- const cachedLane = this.laneAssignments.get(i);
3138
- let lane;
3139
- let start;
3140
- const shouldCacheLane = laneAssignmentMode === "estimate" || itemSizeCache.has(key);
3141
- if (cachedLane !== void 0 && this.options.lanes > 1) {
3142
- lane = cachedLane;
3143
- const prevIndex = laneLastIndex[lane];
3144
- const prevInLane = prevIndex !== void 0 ? measurements[prevIndex] : void 0;
3145
- start = prevInLane ? prevInLane.end + gap : paddingStart + scrollMargin;
3146
- } else if (filledLanes === lanes) {
3147
- let bestLane = 0;
3148
- let bestEnd = laneEnds[0];
3149
- let bestIdx = laneLastIndex[0];
3150
- for (let l = 1; l < lanes; l++) {
3151
- const e = laneEnds[l];
3152
- if (e < bestEnd || e === bestEnd && laneLastIndex[l] < bestIdx) {
3153
- bestLane = l;
3154
- bestEnd = e;
3155
- bestIdx = laneLastIndex[l];
3156
- }
3157
- }
3158
- lane = bestLane;
3159
- start = bestEnd + gap;
3160
- if (shouldCacheLane) this.laneAssignments.set(i, lane);
3161
- } else {
3162
- lane = i % this.options.lanes;
3163
- start = paddingStart + scrollMargin;
3164
- if (shouldCacheLane) this.laneAssignments.set(i, lane);
3165
- }
3166
- const measuredSize = itemSizeCache.get(key);
3167
- const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
3168
- const end = start + size;
3169
- measurements[i] = {
3170
- index: i,
3171
- start,
3172
- size,
3173
- end,
3174
- key,
3175
- lane
3176
- };
3177
- if (laneLastIndex[lane] === void 0) filledLanes++;
3178
- laneLastIndex[lane] = i;
3179
- laneEnds[lane] = end;
3180
- }
3181
- this.measurementsCache = measurements;
3182
- return measurements;
3183
- }, {
3184
- key: false,
3185
- debug: () => this.options.debug
3186
- });
3187
- this.calculateRange = memo$1(() => [
3188
- this.getMeasurements(),
3189
- this.getSize(),
3190
- this.getScrollOffset(),
3191
- this.options.lanes
3192
- ], (measurements, outerSize, scrollOffset, lanes) => {
3193
- if (measurements.length === 0 || outerSize === 0) {
3194
- this.range = null;
3195
- return null;
3196
- }
3197
- this.range = calculateRangeImpl(measurements, outerSize, scrollOffset, lanes, lanes === 1 && this._flatMeasurements != null ? this._flatMeasurements : null);
3198
- return this.range;
3199
- }, {
3200
- key: false,
3201
- debug: () => this.options.debug
3202
- });
3203
- this.getVirtualIndexes = memo$1(() => {
3204
- let startIndex = null;
3205
- let endIndex = null;
3206
- const range = this.calculateRange();
3207
- if (range) {
3208
- startIndex = range.startIndex;
3209
- endIndex = range.endIndex;
3210
- }
3211
- this.maybeNotify.updateDeps([
3212
- this.isScrolling,
3213
- startIndex,
3214
- endIndex
3215
- ]);
3216
- return [
3217
- this.options.rangeExtractor,
3218
- this.options.overscan,
3219
- this.options.count,
3220
- startIndex,
3221
- endIndex
3222
- ];
3223
- }, (rangeExtractor, overscan, count, startIndex, endIndex) => {
3224
- return startIndex === null || endIndex === null ? [] : rangeExtractor({
3225
- startIndex,
3226
- endIndex,
3227
- overscan,
3228
- count
3229
- });
3230
- }, {
3231
- key: false,
3232
- debug: () => this.options.debug
3233
- });
3234
- this.indexFromElement = (node) => {
3235
- const attributeName = this.options.indexAttribute;
3236
- const indexStr = node.getAttribute(attributeName);
3237
- if (!indexStr) {
3238
- console.warn(`Missing attribute name '${attributeName}={index}' on measured element.`);
3239
- return -1;
3240
- }
3241
- return parseInt(indexStr, 10);
3242
- };
3243
- this.shouldMeasureDuringScroll = (index) => {
3244
- var _a;
3245
- if (!this.scrollState || this.scrollState.behavior !== "smooth") return true;
3246
- const scrollIndex = this.scrollState.index ?? ((_a = this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)) == null ? void 0 : _a.index);
3247
- if (scrollIndex !== void 0 && this.range) {
3248
- const bufferSize = Math.max(this.options.overscan, Math.ceil((this.range.endIndex - this.range.startIndex) / 2));
3249
- const minIndex = Math.max(0, scrollIndex - bufferSize);
3250
- const maxIndex = Math.min(this.options.count - 1, scrollIndex + bufferSize);
3251
- return index >= minIndex && index <= maxIndex;
3252
- }
3253
- return true;
3254
- };
3255
- this.measureElement = (node) => {
3256
- if (!node) {
3257
- this.elementsCache.forEach((cached, key2) => {
3258
- if (!cached.isConnected) {
3259
- this.observer.unobserve(cached);
3260
- this.elementsCache.delete(key2);
3261
- }
3262
- });
3263
- return;
3264
- }
3265
- const index = this.indexFromElement(node);
3266
- if (!this.isIndexInRange(index)) return;
3267
- const key = this.options.getItemKey(index);
3268
- const prevNode = this.elementsCache.get(key);
3269
- if (prevNode !== node) {
3270
- if (prevNode) this.observer.unobserve(prevNode);
3271
- this.observer.observe(node);
3272
- this.elementsCache.set(key, node);
3273
- }
3274
- if ((!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) this.resizeItem(index, this.options.measureElement(node, void 0, this));
3275
- };
3276
- this.resizeItem = (index, size) => {
3277
- var _a, _b;
3278
- if (!this.isIndexInRange(index)) return;
3279
- let cachedSize;
3280
- let itemStart;
3281
- let key;
3282
- const flat = this._flatMeasurements;
3283
- if (this.options.lanes === 1 && flat !== null) {
3284
- key = this.options.getItemKey(index);
3285
- itemStart = flat[index * 2];
3286
- cachedSize = flat[index * 2 + 1];
3287
- } else {
3288
- const item = this.measurementsCache[index];
3289
- if (!item) return;
3290
- key = item.key;
3291
- itemStart = item.start;
3292
- cachedSize = item.size;
3293
- }
3294
- const itemSize = this.itemSizeCache.get(key) ?? cachedSize;
3295
- const delta = size - itemSize;
3296
- if (delta !== 0) {
3297
- const wasAtEnd = this.options.anchorTo === "end" && ((_a = this.scrollState) == null ? void 0 : _a.behavior) !== "smooth" && this.getVirtualDistanceFromEnd() <= this.options.scrollEndThreshold;
3298
- const prevTotalSize = wasAtEnd ? this.getTotalSize() : 0;
3299
- const scrollOffsetWithAdj = this.getScrollOffset() + this.scrollAdjustments;
3300
- const defaultShouldAdjust = !this.itemSizeCache.has(key) ? itemStart < scrollOffsetWithAdj : itemStart + itemSize <= scrollOffsetWithAdj && this.scrollDirection !== "backward";
3301
- const shouldAdjustScroll = ((_b = this.scrollState) == null ? void 0 : _b.behavior) !== "smooth" && (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[index] ?? {
3302
- index,
3303
- key,
3304
- start: itemStart,
3305
- size: cachedSize,
3306
- end: itemStart + cachedSize,
3307
- lane: 0
3308
- }, delta, this) : defaultShouldAdjust);
3309
- if (this.pendingMin === null || index < this.pendingMin) this.pendingMin = index;
3310
- this.itemSizeCache.set(key, size);
3311
- this.itemSizeCacheVersion++;
3312
- let adjustedSync = false;
3313
- if (wasAtEnd) adjustedSync = this.applyScrollAdjustment(this.getTotalSize() - prevTotalSize);
3314
- else if (shouldAdjustScroll) adjustedSync = this.applyScrollAdjustment(delta);
3315
- this.notify(adjustedSync);
3316
- }
3317
- };
3318
- this.getVirtualItems = memo$1(() => [this.getVirtualIndexes(), this.getMeasurements()], (indexes, measurements) => {
3319
- const virtualItems = [];
3320
- for (let k = 0, len = indexes.length; k < len; k++) {
3321
- const measurement = measurements[indexes[k]];
3322
- virtualItems.push(measurement);
3323
- }
3324
- return virtualItems;
3325
- }, {
3326
- key: false,
3327
- debug: () => this.options.debug
3328
- });
3329
- this.getVirtualItemForOffset = (offset) => {
3330
- const measurements = this.getMeasurements();
3331
- if (measurements.length === 0) return;
3332
- const flat = this._flatMeasurements;
3333
- const useFlat = this.options.lanes === 1 && flat != null;
3334
- return notUndefined(measurements[findNearestBinarySearch(0, measurements.length - 1, useFlat ? (i) => flat[i * 2] : (i) => notUndefined(measurements[i]).start, offset)]);
3335
- };
3336
- this.getMaxScrollOffset = () => {
3337
- if (!this.scrollElement) return 0;
3338
- if ("scrollHeight" in this.scrollElement) return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
3339
- else {
3340
- const doc = this.scrollElement.document.documentElement;
3341
- return this.options.horizontal ? doc.scrollWidth - this.scrollElement.innerWidth : doc.scrollHeight - this.scrollElement.innerHeight;
3342
- }
3343
- };
3344
- this.getVirtualDistanceFromEnd = () => {
3345
- return Math.max(this.getTotalSize() - this.getSize() - this.getScrollOffset(), 0);
3346
- };
3347
- this.getDistanceFromEnd = () => {
3348
- return Math.max(this.getMaxScrollOffset() - this.getScrollOffset(), 0);
3349
- };
3350
- this.isAtEnd = (threshold = this.options.scrollEndThreshold) => {
3351
- return this.getDistanceFromEnd() <= threshold;
3352
- };
3353
- this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
3354
- if (!this.scrollElement) return 0;
3355
- const size = this.getSize();
3356
- const scrollOffset = this.getScrollOffset();
3357
- if (align === "auto") align = toOffset >= scrollOffset + size ? "end" : "start";
3358
- if (align === "center") toOffset += (itemSize - size) / 2;
3359
- else if (align === "end") toOffset -= size;
3360
- const maxOffset = this.getMaxScrollOffset();
3361
- return Math.max(Math.min(maxOffset, toOffset), 0);
3362
- };
3363
- this.getOffsetForIndex = (index, align = "auto") => {
3364
- index = Math.max(0, Math.min(index, this.options.count - 1));
3365
- const size = this.getSize();
3366
- const scrollOffset = this.getScrollOffset();
3367
- const item = this.measurementsCache[index];
3368
- if (!item) return;
3369
- if (align === "auto") if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) align = "end";
3370
- else if (item.start <= scrollOffset + this.options.scrollPaddingStart) align = "start";
3371
- else return [scrollOffset, align];
3372
- if (align === "end" && index === this.options.count - 1) return [this.getMaxScrollOffset(), align];
3373
- const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
3374
- return [this.getOffsetForAlignment(toOffset, align, item.size), align];
3375
- };
3376
- this.scrollToOffset = (toOffset, { align = "start", behavior = "auto" } = {}) => {
3377
- this._iosDeferredAdjustment = 0;
3378
- const offset = this.getOffsetForAlignment(toOffset, align);
3379
- const now = this.now();
3380
- this.scrollState = {
3381
- index: null,
3382
- align,
3383
- behavior,
3384
- startedAt: now,
3385
- lastTargetOffset: offset,
3386
- stableFrames: 0
3387
- };
3388
- this._scrollToOffset(offset, {
3389
- adjustments: void 0,
3390
- behavior
3391
- });
3392
- this.scheduleScrollReconcile();
3393
- };
3394
- this.scrollToIndex = (index, { align: initialAlign = "auto", behavior = "auto" } = {}) => {
3395
- this._iosDeferredAdjustment = 0;
3396
- index = Math.max(0, Math.min(index, this.options.count - 1));
3397
- const offsetInfo = this.getOffsetForIndex(index, initialAlign);
3398
- if (!offsetInfo) return;
3399
- const [offset, align] = offsetInfo;
3400
- const now = this.now();
3401
- this.scrollState = {
3402
- index,
3403
- align,
3404
- behavior,
3405
- startedAt: now,
3406
- lastTargetOffset: offset,
3407
- stableFrames: 0
3408
- };
3409
- this._scrollToOffset(offset, {
3410
- adjustments: void 0,
3411
- behavior
3412
- });
3413
- this.scheduleScrollReconcile();
3414
- };
3415
- this.scrollBy = (delta, { behavior = "auto" } = {}) => {
3416
- const offset = this.getScrollOffset() + delta;
3417
- const now = this.now();
3418
- this.scrollState = {
3419
- index: null,
3420
- align: "start",
3421
- behavior,
3422
- startedAt: now,
3423
- lastTargetOffset: offset,
3424
- stableFrames: 0
3425
- };
3426
- this._scrollToOffset(offset, {
3427
- adjustments: void 0,
3428
- behavior
3429
- });
3430
- this.scheduleScrollReconcile();
3431
- };
3432
- this.scrollToEnd = ({ behavior = "auto" } = {}) => {
3433
- if (this.options.count > 0) {
3434
- this.scrollToIndex(this.options.count - 1, {
3435
- align: "end",
3436
- behavior
3437
- });
3438
- return;
3439
- }
3440
- this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), { behavior });
3441
- };
3442
- this.getTotalSize = () => {
3443
- var _a;
3444
- const measurements = this.getMeasurements();
3445
- let end;
3446
- if (measurements.length === 0) end = this.options.paddingStart;
3447
- else if (this.options.lanes === 1) {
3448
- const lastIdx = measurements.length - 1;
3449
- const flat = this._flatMeasurements;
3450
- if (flat != null) end = flat[lastIdx * 2] + flat[lastIdx * 2 + 1];
3451
- else end = ((_a = measurements[lastIdx]) == null ? void 0 : _a.end) ?? 0;
3452
- } else {
3453
- const endByLane = Array(this.options.lanes).fill(null);
3454
- let endIndex = measurements.length - 1;
3455
- while (endIndex >= 0 && endByLane.some((val) => val === null)) {
3456
- const item = measurements[endIndex];
3457
- if (endByLane[item.lane] === null) endByLane[item.lane] = item.end;
3458
- endIndex--;
3459
- }
3460
- end = Math.max(...endByLane.filter((val) => val !== null));
3461
- }
3462
- return Math.max(end - this.options.scrollMargin + this.options.paddingEnd, 0);
3463
- };
3464
- this.takeSnapshot = () => {
3465
- const snapshot = [];
3466
- if (this.itemSizeCache.size === 0) return snapshot;
3467
- const m = this.getMeasurements();
3468
- for (const item of m) if (item && this.itemSizeCache.has(item.key)) snapshot.push({
3469
- index: item.index,
3470
- key: item.key,
3471
- start: item.start,
3472
- size: item.size,
3473
- end: item.end,
3474
- lane: item.lane
3475
- });
3476
- return snapshot;
3477
- };
3478
- this._scrollToOffset = (offset, { adjustments, behavior }) => {
3479
- this._intendedScrollOffset = offset + (adjustments ?? 0);
3480
- this.options.scrollToFn(offset, {
3481
- behavior,
3482
- adjustments
3483
- }, this);
3484
- };
3485
- this.measure = () => {
3486
- this.pendingMin = null;
3487
- this.itemSizeCache.clear();
3488
- this.laneAssignments.clear();
3489
- this.itemSizeCacheVersion++;
3490
- this.notify(false);
3491
- };
3492
- this.setOptions(opts);
3493
- }
3494
- applyScrollAdjustment(delta, behavior) {
3495
- if (delta === 0) return false;
3496
- if (isIOSWebKit() && (this.isScrolling || this._iosTouching || this._iosJustTouchEnded)) {
3497
- this._iosDeferredAdjustment += delta;
3498
- return false;
3499
- } else {
3500
- this._scrollToOffset(this.getScrollOffset(), {
3501
- adjustments: this.scrollAdjustments += delta,
3502
- behavior
3503
- });
3504
- if (this.scrollOffset !== null) {
3505
- this.scrollOffset += this.scrollAdjustments;
3506
- if (this.scrollOffset < 0) this.scrollOffset = 0;
3507
- this.scrollAdjustments = 0;
3508
- }
3509
- return true;
3510
- }
3511
- }
3512
- scheduleScrollReconcile() {
3513
- if (!this.targetWindow) {
3514
- this.scrollState = null;
3515
- return;
3516
- }
3517
- if (this.rafId != null) return;
3518
- this.rafId = this.targetWindow.requestAnimationFrame(() => {
3519
- this.rafId = null;
3520
- this.reconcileScroll();
3521
- });
3522
- }
3523
- reconcileScroll() {
3524
- if (!this.scrollState) return;
3525
- if (!this.scrollElement) return;
3526
- if (this.now() - this.scrollState.startedAt > 5e3) {
3527
- this.scrollState = null;
3528
- return;
3529
- }
3530
- const offsetInfo = this.scrollState.index != null ? this.getOffsetForIndex(this.scrollState.index, this.scrollState.align) : void 0;
3531
- const targetOffset = offsetInfo ? offsetInfo[0] : this.scrollState.lastTargetOffset;
3532
- const STABLE_FRAMES = 1;
3533
- const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
3534
- if (!targetChanged && approxEqual(targetOffset, this.getScrollOffset())) {
3535
- this.scrollState.stableFrames++;
3536
- if (this.scrollState.stableFrames >= STABLE_FRAMES) {
3537
- if (this.getScrollOffset() !== targetOffset) this._scrollToOffset(targetOffset, {
3538
- adjustments: void 0,
3539
- behavior: "auto"
3540
- });
3541
- this.scrollState = null;
3542
- return;
3543
- }
3544
- } else {
3545
- this.scrollState.stableFrames = 0;
3546
- if (targetChanged) {
3547
- const viewport = this.getSize() || 600;
3548
- const distance = Math.abs(targetOffset - this.getScrollOffset());
3549
- const keepSmooth = this.scrollState.behavior === "smooth" && distance > viewport;
3550
- this.scrollState.lastTargetOffset = targetOffset;
3551
- if (!keepSmooth) this.scrollState.behavior = "auto";
3552
- this._scrollToOffset(targetOffset, {
3553
- adjustments: void 0,
3554
- behavior: keepSmooth ? "smooth" : "auto"
3555
- });
3556
- }
3557
- }
3558
- this.scheduleScrollReconcile();
3559
- }
3560
- };
3561
- const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
3562
- while (low <= high) {
3563
- const middle = (low + high) / 2 | 0;
3564
- const currentValue = getCurrentValue(middle);
3565
- if (currentValue < value) low = middle + 1;
3566
- else if (currentValue > value) high = middle - 1;
3567
- else return middle;
3568
- }
3569
- if (low > 0) return low - 1;
3570
- else return 0;
3571
- };
3572
- function findNearestBinarySearchFlat(flat, high, value) {
3573
- let low = 0;
3574
- while (low <= high) {
3575
- const middle = (low + high) / 2 | 0;
3576
- const currentValue = flat[middle * 2];
3577
- if (currentValue < value) low = middle + 1;
3578
- else if (currentValue > value) high = middle - 1;
3579
- else return middle;
3580
- }
3581
- return low > 0 ? low - 1 : 0;
3582
- }
3583
- function calculateRangeImpl(measurements, outerSize, scrollOffset, lanes, flat) {
3584
- const lastIndex = measurements.length - 1;
3585
- if (measurements.length <= lanes) return {
3586
- startIndex: 0,
3587
- endIndex: lastIndex
3588
- };
3589
- if (lanes === 1 && flat !== null) {
3590
- const startIndex2 = findNearestBinarySearchFlat(flat, lastIndex, scrollOffset);
3591
- let endIndex2 = startIndex2;
3592
- const limit = scrollOffset + outerSize;
3593
- while (endIndex2 < lastIndex && flat[endIndex2 * 2] + flat[endIndex2 * 2 + 1] < limit) endIndex2++;
3594
- return {
3595
- startIndex: startIndex2,
3596
- endIndex: endIndex2
3597
- };
3598
- }
3599
- const getStart = (index) => measurements[index].start;
3600
- let startIndex = findNearestBinarySearch(0, lastIndex, getStart, scrollOffset);
3601
- let endIndex = startIndex;
3602
- if (lanes === 1) while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) endIndex++;
3603
- else if (lanes > 1) {
3604
- const endPerLane = Array(lanes).fill(0);
3605
- while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
3606
- const item = measurements[endIndex];
3607
- endPerLane[item.lane] = item.end;
3608
- endIndex++;
3609
- }
3610
- const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
3611
- while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
3612
- const item = measurements[startIndex];
3613
- startPerLane[item.lane] = item.start;
3614
- startIndex--;
3615
- }
3616
- startIndex = Math.max(0, startIndex - startIndex % lanes);
3617
- endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
3618
- }
3619
- return {
3620
- startIndex,
3621
- endIndex
3622
- };
3623
- }
3624
- //#endregion
3625
- //#region ../../../node_modules/.pnpm/@tanstack+react-virtual@3.14.10_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-virtual/dist/esm/index.js
3626
- const useIsomorphicLayoutEffect = typeof document !== "undefined" ? react.useLayoutEffect : react.useEffect;
3627
- function useVirtualizerBase({ useFlushSync = true, directDomUpdates = false, directDomUpdatesMode = "transform", ...options }) {
3628
- const rerender = react.useReducer((x) => x + 1, 0)[1];
3629
- const directRef = react.useRef({
3630
- enabled: directDomUpdates,
3631
- mode: directDomUpdatesMode,
3632
- container: null,
3633
- lastSize: null,
3634
- lastPositions: /* @__PURE__ */ new WeakMap(),
3635
- prevRange: null
3636
- });
3637
- directRef.current.enabled = directDomUpdates;
3638
- directRef.current.mode = directDomUpdatesMode;
3639
- const applyContainerSize = (instance2) => {
3640
- const state = directRef.current;
3641
- if (!state.enabled || !state.container) return;
3642
- const totalSize = instance2.getTotalSize();
3643
- if (totalSize !== state.lastSize) {
3644
- state.lastSize = totalSize;
3645
- const sizeAxis = instance2.options.horizontal ? "width" : "height";
3646
- state.container.style[sizeAxis] = `${totalSize}px`;
3647
- }
3648
- };
3649
- const applyDirectStyles = (instance2) => {
3650
- const state = directRef.current;
3651
- if (!state.enabled || !state.container) return;
3652
- applyContainerSize(instance2);
3653
- const horizontal = !!instance2.options.horizontal;
3654
- const useTransform = state.mode === "transform";
3655
- const posAxis = horizontal ? "left" : "top";
3656
- const scrollMargin = instance2.options.scrollMargin;
3657
- const items = instance2.getVirtualItems();
3658
- for (const item of items) {
3659
- const next = item.start - scrollMargin;
3660
- const el = instance2.elementsCache.get(item.key);
3661
- if (!el) continue;
3662
- if (state.lastPositions.get(el) === next) continue;
3663
- state.lastPositions.set(el, next);
3664
- if (useTransform) el.style.transform = horizontal ? `translate3d(${next}px, 0, 0)` : `translate3d(0, ${next}px, 0)`;
3665
- else el.style[posAxis] = `${next}px`;
3666
- }
3667
- };
3668
- const resolvedOptions = {
3669
- ...options,
3670
- onChange: (instance2, sync) => {
3671
- var _a;
3672
- const state = directRef.current;
3673
- let shouldRerender = true;
3674
- if (state.enabled) {
3675
- applyDirectStyles(instance2);
3676
- const range = instance2.range;
3677
- const prev = state.prevRange;
3678
- shouldRerender = !prev || prev.isScrolling !== instance2.isScrolling || prev.startIndex !== (range == null ? void 0 : range.startIndex) || prev.endIndex !== (range == null ? void 0 : range.endIndex);
3679
- if (shouldRerender) state.prevRange = range ? {
3680
- startIndex: range.startIndex,
3681
- endIndex: range.endIndex,
3682
- isScrolling: instance2.isScrolling
3683
- } : null;
3684
- }
3685
- if (shouldRerender) if (useFlushSync && sync) (0, react_dom.flushSync)(rerender);
3686
- else rerender();
3687
- (_a = options.onChange) == null || _a.call(options, instance2, sync);
3688
- }
3689
- };
3690
- const [instance] = react.useState(() => {
3691
- const v = new Virtualizer(resolvedOptions);
3692
- return Object.assign(v, { containerRef: (node) => {
3693
- const state = directRef.current;
3694
- state.container = node;
3695
- state.lastSize = null;
3696
- if (node && state.enabled) {
3697
- const total = v.getTotalSize();
3698
- state.lastSize = total;
3699
- const axis = v.options.horizontal ? "width" : "height";
3700
- node.style[axis] = `${total}px`;
3701
- }
3702
- } });
3703
- });
3704
- instance.setOptions(resolvedOptions);
3705
- useIsomorphicLayoutEffect(() => {
3706
- return instance._didMount();
3707
- }, []);
3708
- useIsomorphicLayoutEffect(() => {
3709
- applyContainerSize(instance);
3710
- return instance._willUpdate();
3711
- });
3712
- useIsomorphicLayoutEffect(() => {
3713
- applyDirectStyles(instance);
3714
- });
3715
- return instance;
3716
- }
3717
- function useVirtualizer(options) {
3718
- return useVirtualizerBase({
3719
- observeElementRect,
3720
- observeElementOffset,
3721
- scrollToFn: elementScroll,
3722
- ...options
3723
- });
3724
- }
3725
- //#endregion
3726
2518
  //#region ../../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/base.js
3727
2519
  var Diff = class {
3728
2520
  diff(oldStr, newStr, options = {}) {
@@ -5439,7 +4231,7 @@ window.__ModuleLoader__.load({
5439
4231
  }];
5440
4232
  });
5441
4233
  }
5442
- function RecordAttachments({ blocks, preview, renderImages, t }) {
4234
+ function RecordAttachments({ blocks, preview, renderSlot, loadImage, t }) {
5443
4235
  const attachments = recordAttachments(blocks, t);
5444
4236
  if (attachments.length === 0) return null;
5445
4237
  return (0, react_jsx_runtime.jsx)("ul", {
@@ -5447,13 +4239,14 @@ window.__ModuleLoader__.load({
5447
4239
  "aria-label": t("attachment.list"),
5448
4240
  children: attachments.map(({ block, index, name, metadata }) => (0, react_jsx_runtime.jsxs)("li", {
5449
4241
  className: TrajectoryTable_module_css_default.attachmentRow,
5450
- children: [block.attachment !== void 0 ? renderImages({
4242
+ children: [block.attachment !== void 0 ? renderSlot("conversation.trajectory.images", {
5451
4243
  images: [{
5452
4244
  attachment: block.attachment,
5453
4245
  label: name
5454
4246
  }],
5455
4247
  align: "start",
5456
- thumbnail: true
4248
+ thumbnail: true,
4249
+ loadImage
5457
4250
  }) : (0, react_jsx_runtime.jsx)("span", {
5458
4251
  className: TrajectoryTable_module_css_default.attachmentIcon,
5459
4252
  children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.FileTypeIcon, { path: name })
@@ -5629,7 +4422,7 @@ window.__ModuleLoader__.load({
5629
4422
  })]
5630
4423
  });
5631
4424
  }
5632
- function ToolOutputBlocks({ blocks, error, errorDetail, preview, renderImages }) {
4425
+ function ToolOutputBlocks({ blocks, error, errorDetail, preview, renderSlot, loadImage }) {
5633
4426
  return (0, react_jsx_runtime.jsxs)("div", {
5634
4427
  className: [
5635
4428
  TrajectoryTable_module_css_default.resultBlocks,
@@ -5641,9 +4434,10 @@ window.__ModuleLoader__.load({
5641
4434
  children: errorDetail
5642
4435
  }), blocks.map((block, index) => block.attachment !== void 0 ? (0, react_jsx_runtime.jsx)("div", {
5643
4436
  className: TrajectoryTable_module_css_default.messageImages,
5644
- children: renderImages({
4437
+ children: renderSlot("conversation.trajectory.images", {
5645
4438
  images: [{ attachment: block.attachment }],
5646
- align: "start"
4439
+ align: "start",
4440
+ loadImage
5647
4441
  })
5648
4442
  }, index) : block.content !== "" ? (0, react_jsx_runtime.jsx)("pre", {
5649
4443
  className: TrajectoryTable_module_css_default.resultBlockText,
@@ -5651,7 +4445,7 @@ window.__ModuleLoader__.load({
5651
4445
  }, index) : null)]
5652
4446
  });
5653
4447
  }
5654
- function MarkdownRecordContent({ record, rendered, preview = false, thinkingExpanded, onThinkingExpandedChange, onOpenCall, renderImages, t }) {
4448
+ function MarkdownRecordContent({ record, rendered, preview = false, thinkingExpanded, onThinkingExpandedChange, onOpenCall, renderSlot, loadImage, t }) {
5655
4449
  if (record.cell.sourceBlocks?.length && record.cell.sourceBlocks.every((block) => block.type === "tool-addition" || block.type === "tool-removal")) return (0, react_jsx_runtime.jsx)("pre", {
5656
4450
  className: `${TrajectoryTable_module_css_default.payload} ${TrajectoryTable_module_css_default.toolUpdatePayload}`,
5657
4451
  children: record.cell.inputDetail
@@ -5710,7 +4504,8 @@ window.__ModuleLoader__.load({
5710
4504
  (0, react_jsx_runtime.jsx)(RecordAttachments, {
5711
4505
  blocks: record.cell.sourceBlocks,
5712
4506
  preview,
5713
- renderImages,
4507
+ renderSlot,
4508
+ loadImage,
5714
4509
  t
5715
4510
  })
5716
4511
  ]
@@ -5748,7 +4543,8 @@ window.__ModuleLoader__.load({
5748
4543
  (0, react_jsx_runtime.jsx)(RecordAttachments, {
5749
4544
  blocks: record.cell.sourceBlocks,
5750
4545
  preview,
5751
- renderImages,
4546
+ renderSlot,
4547
+ loadImage,
5752
4548
  t
5753
4549
  })
5754
4550
  ] });
@@ -5797,7 +4593,7 @@ window.__ModuleLoader__.load({
5797
4593
  })] }), (0, react_jsx_runtime.jsxs)("div", { children: [(0, react_jsx_runtime.jsx)("dt", { children: t("timing.duration") }), (0, react_jsx_runtime.jsx)("dd", { children: formatElapsedSeconds(null, t) })] })]
5798
4594
  });
5799
4595
  }
5800
- function RecordPayload({ record, direction, preview = false, renderImages, stringWrapping, t }) {
4596
+ function RecordPayload({ record, direction, preview = false, renderSlot, loadImage, stringWrapping, t }) {
5801
4597
  const value = direction === "input" ? record.cell.inputDetail : record.cell.outputDetail;
5802
4598
  const missing = direction === "input" ? t("record.noPayload") : t("record.noResult");
5803
4599
  if (!value) return (0, react_jsx_runtime.jsx)("p", {
@@ -5821,7 +4617,8 @@ window.__ModuleLoader__.load({
5821
4617
  error,
5822
4618
  errorDetail: error ? value : void 0,
5823
4619
  preview,
5824
- renderImages
4620
+ renderSlot,
4621
+ loadImage
5825
4622
  });
5826
4623
  if (direction === "input" && (record.cell.kind === "user" || record.cell.kind === "context") || direction === "output" && record.cell.kind === "message") return (0, react_jsx_runtime.jsx)("div", {
5827
4624
  className: [preview ? TrajectoryTable_module_css_default.markdownPreview : TrajectoryTable_module_css_default.markdownPayload, error ? TrajectoryTable_module_css_default.errorPayload : void 0].filter((className) => className !== void 0).join(" "),
@@ -6112,7 +4909,7 @@ window.__ModuleLoader__.load({
6112
4909
  * @param props - Grouped trajectory data and whole-ledger fold state.
6113
4910
  * @returns The ledger and an optional local record inspector.
6114
4911
  */
6115
- function TrajectoryTable({ t, stringWrapping, renderImages, requestNumbers: sessionRequestNumbers, turns, streamingCells = [], timelineFocusIndexes = null, searchMatchIndexes = null, onSelectedIndexChange, onRecordSelect, recordSelection = null, recordFocus = null, historyLoading = false, olderHistoryLoading = false, historyStartSeq, hasOlderRecords = false, onLoadOlder, onClearSelection, collapsedTurns, onToggleTurn, collapsedAssistants, onToggleAssistant, inspectCallId = null, onInspectApplied }) {
4912
+ function TrajectoryTable({ t, stringWrapping, renderSlot, loadImage, requestNumbers: sessionRequestNumbers, turns, streamingCells = [], timelineFocusIndexes = null, searchMatchIndexes = null, onSelectedIndexChange, onRecordSelect, recordSelection = null, recordFocus = null, historyLoading = false, olderHistoryLoading = false, historyStartSeq, hasOlderRecords = false, onLoadOlder, onClearSelection, collapsedTurns, onToggleTurn, collapsedAssistants, onToggleAssistant, inspectCallId = null, onInspectApplied }) {
6116
4913
  const [selectedRecordId, setSelectedRecordId] = (0, react.useState)(null);
6117
4914
  const [selectedRequest, setSelectedRequest] = (0, react.useState)(null);
6118
4915
  const [activeTab, setActiveTab] = (0, react.useState)("overview");
@@ -6178,7 +4975,7 @@ window.__ModuleLoader__.load({
6178
4975
  const estimateVirtualRowSize = (0, react.useCallback)((index) => virtualRowStructure[index]?.height ?? 30, [virtualRowStructure]);
6179
4976
  const getVirtualRowKey = (0, react.useCallback)((index) => virtualRowStructure[index]?.key ?? index, [virtualRowStructure]);
6180
4977
  const getTableScrollElement = (0, react.useCallback)(() => tablePaneRef.current, []);
6181
- const rowVirtualizer = useVirtualizer({
4978
+ const rowVirtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
6182
4979
  count: virtualizationEnabled ? virtualRowStructure.length : 0,
6183
4980
  enabled: virtualizationEnabled,
6184
4981
  estimateSize: estimateVirtualRowSize,
@@ -6985,7 +5782,8 @@ window.__ModuleLoader__.load({
6985
5782
  "data-summary-scroll-region": "",
6986
5783
  children: (0, react_jsx_runtime.jsx)(MarkdownRecordContent, {
6987
5784
  record: selected,
6988
- renderImages,
5785
+ renderSlot,
5786
+ loadImage,
6989
5787
  rendered: true,
6990
5788
  thinkingExpanded,
6991
5789
  onThinkingExpandedChange: setThinkingExpanded,
@@ -7090,7 +5888,8 @@ window.__ModuleLoader__.load({
7090
5888
  },
7091
5889
  children: (0, react_jsx_runtime.jsx)(MarkdownRecordContent, {
7092
5890
  record: selected,
7093
- renderImages,
5891
+ renderSlot,
5892
+ loadImage,
7094
5893
  rendered: true,
7095
5894
  preview: true,
7096
5895
  thinkingExpanded,
@@ -7108,7 +5907,8 @@ window.__ModuleLoader__.load({
7108
5907
  record: selected,
7109
5908
  direction: "input",
7110
5909
  preview: true,
7111
- renderImages,
5910
+ renderSlot,
5911
+ loadImage,
7112
5912
  stringWrapping,
7113
5913
  t
7114
5914
  })
@@ -7122,7 +5922,8 @@ window.__ModuleLoader__.load({
7122
5922
  record: selected,
7123
5923
  direction: "output",
7124
5924
  preview: true,
7125
- renderImages,
5925
+ renderSlot,
5926
+ loadImage,
7126
5927
  stringWrapping,
7127
5928
  t
7128
5929
  })
@@ -7167,7 +5968,8 @@ window.__ModuleLoader__.load({
7167
5968
  ] }),
7168
5969
  !promptSelected && selected !== void 0 && activeTab === "rendered" && (0, react_jsx_runtime.jsx)(MarkdownRecordContent, {
7169
5970
  record: selected,
7170
- renderImages,
5971
+ renderSlot,
5972
+ loadImage,
7171
5973
  rendered: true,
7172
5974
  thinkingExpanded,
7173
5975
  onThinkingExpandedChange: setThinkingExpanded,
@@ -7176,7 +5978,8 @@ window.__ModuleLoader__.load({
7176
5978
  }),
7177
5979
  !promptSelected && selected !== void 0 && activeTab === "raw" && (0, react_jsx_runtime.jsx)(MarkdownRecordContent, {
7178
5980
  record: selected,
7179
- renderImages,
5981
+ renderSlot,
5982
+ loadImage,
7180
5983
  rendered: false,
7181
5984
  thinkingExpanded,
7182
5985
  onThinkingExpandedChange: setThinkingExpanded,
@@ -7191,7 +5994,8 @@ window.__ModuleLoader__.load({
7191
5994
  !promptSelected && selected !== void 0 && activeTab === "input" && (selectedProgram === void 0 ? (0, react_jsx_runtime.jsx)(RecordPayload, {
7192
5995
  record: selected,
7193
5996
  direction: "input",
7194
- renderImages,
5997
+ renderSlot,
5998
+ loadImage,
7195
5999
  stringWrapping,
7196
6000
  t
7197
6001
  }) : (0, react_jsx_runtime.jsx)(ProgramInput, {
@@ -7203,7 +6007,8 @@ window.__ModuleLoader__.load({
7203
6007
  !promptSelected && selected !== void 0 && activeTab === "output" && (selectedProgram === void 0 ? (0, react_jsx_runtime.jsx)(RecordPayload, {
7204
6008
  record: selected,
7205
6009
  direction: "output",
7206
- renderImages,
6010
+ renderSlot,
6011
+ loadImage,
7207
6012
  stringWrapping,
7208
6013
  t
7209
6014
  }) : (0, react_jsx_runtime.jsx)(ProgramOutput, {
@@ -8979,10 +7784,6 @@ window.__ModuleLoader__.load({
8979
7784
  }
8980
7785
  function TrajectoryView({ useSession, useTrajectory, useDuration, loadOlder, loadImage, setActualDuration, viewRequest, completeViewRequest, renderSlot, t, jsonStringWrapping }) {
8981
7786
  const [collapsedTurns, setCollapsedTurns] = (0, react.useState)(EMPTY_TURN_IDS);
8982
- const renderImages = (0, react.useCallback)((owner) => renderSlot("conversation.trajectory.images", {
8983
- ...owner,
8984
- loadImage
8985
- }), [loadImage, renderSlot]);
8986
7787
  const [collapsedAssistants, setCollapsedAssistants] = (0, react.useState)(EMPTY_RECORD_IDS);
8987
7788
  const [timelineSelection, setTimelineSelection] = (0, react.useState)(null);
8988
7789
  const actualDuration = useDuration((value) => value);
@@ -9325,7 +8126,8 @@ window.__ModuleLoader__.load({
9325
8126
  ...jsonStringWrapping,
9326
8127
  label: t("record.wrapLines")
9327
8128
  },
9328
- renderImages,
8129
+ renderSlot,
8130
+ loadImage,
9329
8131
  requestNumbers,
9330
8132
  turns: timelineTurns,
9331
8133
  streamingCells,