Files
NapCatQQ/.pnpm-store/v3/files/8c/3fe4fd7be43b78107904522e56ccd7b661c0dab6182fad737c78721239fc220c4d39c31ea46aeb8baf6d73a451393f37f1a0f5ee6dbe88cd06c9b805ef5ef0
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

62 lines
1.9 KiB
Plaintext

/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {getItemElement} from './utils';
import {Key, LayoutDelegate, Rect, RefObject, Size} from '@react-types/shared';
export class DOMLayoutDelegate implements LayoutDelegate {
private ref: RefObject<HTMLElement | null>;
constructor(ref: RefObject<HTMLElement | null>) {
this.ref = ref;
}
getItemRect(key: Key): Rect | null {
let container = this.ref.current;
if (!container) {
return null;
}
let item = key != null ? getItemElement(this.ref, key) : null;
if (!item) {
return null;
}
let containerRect = container.getBoundingClientRect();
let itemRect = item.getBoundingClientRect();
return {
x: itemRect.left - containerRect.left - container.clientLeft + container.scrollLeft,
y: itemRect.top - containerRect.top - container.clientTop + container.scrollTop,
width: itemRect.width,
height: itemRect.height
};
}
getContentSize(): Size {
let container = this.ref.current;
return {
width: container?.scrollWidth ?? 0,
height: container?.scrollHeight ?? 0
};
}
getVisibleRect(): Rect {
let container = this.ref.current;
return {
x: container?.scrollLeft ?? 0,
y: container?.scrollTop ?? 0,
width: container?.clientWidth ?? 0,
height: container?.clientHeight ?? 0
};
}
}