Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

refactor(ui): delete legacy CollectionView stack

esengine64248bbd5397
diff --git a/sdk/src/core.ts b/sdk/src/core.ts
index 56e4a1e01..3e628953e 100644
--- a/sdk/src/core.ts
+++ b/sdk/src/core.ts
@@ -339,33 +339,7 @@ export {
type RichTextRun,
type TextSegment,
type ImageSegment,
- CollectionView,
- CollectionItem,
- SelectionMode,
- setCollectionAdapter,
- getCollectionAdapter,
- removeCollectionAdapter,
- collectionViewPlugin,
- CollectionViewPlugin,
- registerLayoutProvider,
- getLayoutProvider,
- ScrollAlign,
- ItemPool,
- LinearLayout,
GridLayout,
- LinearLayoutProvider,
- GridLayoutProvider,
- collectionGetItemEntity,
- collectionRefreshItems,
- collectionRefreshItem,
- collectionInsertItems,
- collectionRemoveItems,
- type CollectionViewData,
- type CollectionItemData,
- type CollectionAdapter,
- type LayoutProvider,
- type CollectionLayoutResult,
- type LinearLayoutData,
type GridLayoutData,
intersectRects,
invertMatrix4,
diff --git a/sdk/src/systemLabels.ts b/sdk/src/systemLabels.ts
index 378d6baf7..f879f7d15 100644
--- a/sdk/src/systemLabels.ts
+++ b/sdk/src/systemLabels.ts
@@ -8,7 +8,6 @@ export const PluginName = {
UIInteraction: 'uiInteraction',
UIRenderOrder: 'uiRenderOrder',
UIMask: 'uiMask',
- CollectionView: 'collectionView',
Text: 'text',
Image: 'image',
Focus: 'focus',
@@ -21,11 +20,6 @@ export const PluginName = {
SafeArea: 'safeArea',
TextInput: 'textInput',
StateMachine: 'stateMachine',
- LayoutGroup: 'layoutGroup',
- FanLayout: 'fanLayout',
- Selectable: 'selectable',
- LinearLayout: 'linearLayout',
- GridLayout: 'gridLayout',
} as const;
export const SystemLabel = {
@@ -35,7 +29,6 @@ export const SystemLabel = {
UIInteraction: 'UIInteractionSystem',
Button: 'ButtonSystem',
ScrollView: 'ScrollViewSystem',
- CollectionView: 'CollectionViewSystem',
ListView: 'ListViewSystem',
Text: 'TextSystem',
Image: 'ImageSystem',
diff --git a/sdk/src/ui/CollectionAdapter.ts b/sdk/src/ui/CollectionAdapter.ts
deleted file mode 100644
index 70257943e..000000000
--- a/sdk/src/ui/CollectionAdapter.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type { Entity } from '../types';
-import type { World } from '../world';
-
-export interface CollectionAdapter {
- makeItem(entity: Entity, world: World): void;
- bindItem(entity: Entity, index: number, world: World): void;
- unbindItem?(entity: Entity, index: number, world: World): void;
- getItemType?(index: number): string;
-}
-
-const adapterMap = new Map<Entity, CollectionAdapter>();
-
-export function setCollectionAdapter(entity: Entity, adapter: CollectionAdapter): void {
- adapterMap.set(entity, adapter);
-}
-
-export function getCollectionAdapter(entity: Entity): CollectionAdapter | null {
- return adapterMap.get(entity) ?? null;
-}
-
-export function removeCollectionAdapter(entity: Entity): void {
- adapterMap.delete(entity);
-}
diff --git a/sdk/src/ui/CollectionView.ts b/sdk/src/ui/CollectionView.ts
deleted file mode 100644
index e03f442dd..000000000
--- a/sdk/src/ui/CollectionView.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { defineComponent } from '../component';
-import type { Entity } from '../types';
-
-export const SelectionMode = {
- None: 0,
- Single: 1,
- Multiple: 2,
-} as const;
-export type SelectionMode = (typeof SelectionMode)[keyof typeof SelectionMode];
-
-export interface CollectionViewData {
- itemCount: number;
- layout: string;
- virtualized: boolean;
- overscan: number;
- selectionMode: SelectionMode;
- selectedIndices: number[];
- itemPrefab: string;
-}
-
-export const CollectionView = defineComponent<CollectionViewData>('CollectionView', {
- itemCount: 0,
- layout: 'linear',
- virtualized: true,
- overscan: 2,
- selectionMode: SelectionMode.None,
- selectedIndices: [],
- itemPrefab: '',
-});
-
-export interface CollectionItemData {
- collectionEntity: Entity;
- dataIndex: number;
- selected: boolean;
-}
-
-export const CollectionItem = defineComponent<CollectionItemData>('CollectionItem', {
- collectionEntity: 0 as Entity,
- dataIndex: -1,
- selected: false,
-}, { entityFields: ['collectionEntity'] });
diff --git a/sdk/src/ui/CollectionViewAPI.ts b/sdk/src/ui/CollectionViewAPI.ts
deleted file mode 100644
index 1d4e4a362..000000000
--- a/sdk/src/ui/CollectionViewAPI.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import type { Entity } from '../types';
-import type { World } from '../world';
-import { CollectionView, CollectionItem, type CollectionViewData, type CollectionItemData } from './CollectionView';
-import { getCollectionAdapter } from './CollectionAdapter';
-import { getCollectionState } from './CollectionViewPlugin';
-
-export function collectionGetItemEntity(world: World, collectionEntity: Entity, index: number): Entity | null {
- const state = getCollectionState(collectionEntity);
- if (state) return state.activeItems.get(index) ?? null;
- return null;
-}
-
-export function collectionRefreshItems(world: World, collectionEntity: Entity): void {
- const state = getCollectionState(collectionEntity);
- if (state) state.dirty = true;
-}
-
-export function collectionRefreshItem(world: World, collectionEntity: Entity, index: number): void {
- const itemEntity = collectionGetItemEntity(world, collectionEntity, index);
- if (!itemEntity) return;
- const adapter = getCollectionAdapter(collectionEntity);
- if (adapter) {
- adapter.bindItem(itemEntity, index, world);
- }
-}
-
-export function collectionInsertItems(world: World, collectionEntity: Entity, startIndex: number, count: number): void {
- const cv = world.get(collectionEntity, CollectionView) as CollectionViewData;
- cv.itemCount += count;
- cv.selectedIndices = cv.selectedIndices
- .map(i => i >= startIndex ? i + count : i);
- world.insert(collectionEntity, CollectionView, cv);
-}
-
-export function collectionRemoveItems(world: World, collectionEntity: Entity, startIndex: number, count: number): void {
- const cv = world.get(collectionEntity, CollectionView) as CollectionViewData;
- cv.itemCount = Math.max(0, cv.itemCount - count);
- cv.selectedIndices = cv.selectedIndices
- .filter(i => i < startIndex || i >= startIndex + count)
- .map(i => i >= startIndex + count ? i - count : i);
- world.insert(collectionEntity, CollectionView, cv);
-}
diff --git a/sdk/src/ui/CollectionViewPlugin.ts b/sdk/src/ui/CollectionViewPlugin.ts
deleted file mode 100644
index ef2e3d7f1..000000000
--- a/sdk/src/ui/CollectionViewPlugin.ts
+++ /dev/null
@@ -1,257 +0,0 @@
-import type { App, Plugin } from '../app';
-import type { Entity } from '../types';
-import { defineSystem, Schedule } from '../system';
-import { registerComponent, Transform, type TransformData, Name, Sprite } from '../component';
-import { CollectionView, CollectionItem, type CollectionViewData } from './CollectionView';
-import { getCollectionAdapter, removeCollectionAdapter, type CollectionAdapter } from './CollectionAdapter';
-import { getLayoutProvider, registerLayoutProvider, type LayoutResult } from './LayoutProvider';
-import { LinearLayoutProvider } from './layouts/LinearLayoutProvider';
-import { LinearLayout } from './layouts/LinearLayout';
-import { GridLayoutProvider } from './layouts/GridLayoutProvider';
-import { GridLayout } from './layouts/GridLayout';
-import { FanLayoutProvider } from './layouts/FanLayoutProvider';
-import { FanLayout } from './layouts/FanLayout';
-import { ItemPool } from './ItemPool';
-import { UIRect, type UIRectData } from './UIRect';
-import { getEffectiveWidth, getEffectiveHeight } from './uiHelpers';
-import { Image as UIImage } from './Image';
-import { SystemLabel, PluginName } from '../systemLabels';
-
-export interface CollectionState {
- pool: ItemPool;
- activeItems: Map<number, Entity>;
- prevItemCount: number;
- dirty: boolean;
-}
-
-let activePlugin: CollectionViewPlugin | null = null;
-
-export function getCollectionState(entity: Entity): CollectionState | null {
- return activePlugin?.getState(entity) ?? null;
-}
-
-export class CollectionViewPlugin implements Plugin {
- name = PluginName.CollectionView;
- dependencies = [PluginName.UILayout];
-
- private states_: Map<Entity, CollectionState> | null = null;
- private cleanup_: (() => void) | null = null;
-
- getState(entity: Entity): CollectionState | null {
- return this.states_?.get(entity) ?? null;
- }
-
- build(app: App): void {
- registerComponent('CollectionView', CollectionView);
- registerComponent('CollectionItem', CollectionItem);
-
- registerLayoutProvider('linear', new LinearLayoutProvider());
- registerLayoutProvider('grid', new GridLayoutProvider());
- registerLayoutProvider('fan', new FanLayoutProvider());
-
- const world = app.world;
- const states = new Map<Entity, CollectionState>();
- this.states_ = states;
- activePlugin = this;
-
- app.addSystemToSchedule(Schedule.PostUpdate, defineSystem(
- [],
- () => {
- for (const [e, st] of states) {
- if (!world.valid(e) || !world.has(e, CollectionView)) {
- for (const item of st.activeItems.values()) {
- if (world.valid(item)) world.despawn(item);
- }
- st.pool.clear(world);
- states.delete(e);
- removeCollectionAdapter(e);
- }
- }
-
- const entities = world.getEntitiesWithComponents([CollectionView, UIRect]);
- for (const entity of entities) {
- const cv = world.get(entity, CollectionView) as CollectionViewData;
- const adapter = getCollectionAdapter(entity);
- const provider = getLayoutProvider(cv.layout);
- if (!adapter || !provider) continue;
-
- let state = states.get(entity);
- if (!state) {
- state = { pool: new ItemPool(), activeItems: new Map(), prevItemCount: -1, dirty: true };
- states.set(entity, state);
- }
-
- const rect = world.get(entity, UIRect) as UIRectData;
- const viewW = getEffectiveWidth(rect, entity);
- const viewH = getEffectiveHeight(rect, entity);
- const viewportSize = { x: viewW, y: viewH };
-
- const layoutConfig = this.getLayoutConfig_(world, entity, cv.layout);
- const selectedSet = new Set(cv.selectedIndices);
-
- if (cv.virtualized) {
- const scrollOffset = { x: 0, y: 0 };
-
- const visibleResults = provider.getVisibleRange(
- scrollOffset, viewportSize, cv.itemCount, cv.overscan, layoutConfig,
- );
-
- const newVisibleIndices = new Set(visibleResults.map(r => r.index));
-
- for (const [idx, itemEntity] of state.activeItems) {
- if (!newVisibleIndices.has(idx)) {
- const itemType = adapter.getItemType ? adapter.getItemType(idx) : 'default';
- if (adapter.unbindItem) adapter.unbindItem(itemEntity, idx, world);
- this.hideItem_(world, itemEntity);
- state.pool.release(itemEntity, itemType);
- state.activeItems.delete(idx);
- }
- }
-
- for (const result of visibleResults) {
- let itemEntity = state.activeItems.get(result.index);
- if (!itemEntity || !world.valid(itemEntity)) {
- const itemType = adapter.getItemType ? adapter.getItemType(result.index) : 'default';
- itemEntity = state.pool.acquire(itemType);
- if (itemEntity && world.valid(itemEntity)) {
- this.showItem_(world, itemEntity);
- } else {
- itemEntity = this.createItem_(world, entity);
- adapter.makeItem(itemEntity, world);
- }
- adapter.bindItem(itemEntity, result.index, world);
- world.insert(itemEntity, CollectionItem, {
- collectionEntity: entity,
- dataIndex: result.index,
- selected: selectedSet.has(result.index),
- });
- state.activeItems.set(result.index, itemEntity);
- }
-
- this.positionItem_(world, itemEntity, result);
- }
- } else {
- const needsRebuild = state.prevItemCount !== cv.itemCount || state.dirty;
- if (needsRebuild) {
- for (const [idx, itemEntity] of state.activeItems) {
- if (idx >= cv.itemCount) {
- if (adapter.unbindItem) adapter.unbindItem(itemEntity, idx, world);
- if (world.valid(itemEntity)) world.despawn(itemEntity);
- state.activeItems.delete(idx);
- }
- }
-
- for (let i = 0; i < cv.itemCount; i++) {
- if (!state.activeItems.has(i)) {
- const itemEntity = this.createItem_(world, entity);
- adapter.makeItem(itemEntity, world);
- adapter.bindItem(itemEntity, i, world);
- world.insert(itemEntity, CollectionItem, {
- collectionEntity: entity,
- dataIndex: i,
- selected: selectedSet.has(i),
- });
- state.activeItems.set(i, itemEntity);
- }
- }
- state.prevItemCount = cv.itemCount;
- state.dirty = false;
-
- const allResults = provider.getVisibleRange(
- { x: 0, y: 0 }, viewportSize, cv.itemCount, 0, layoutConfig,
- );
- for (const result of allResults) {
- const itemEntity = state.activeItems.get(result.index);
- if (itemEntity && world.valid(itemEntity)) {
- this.positionItem_(world, itemEntity, result);
- }
- }
- }
- }
- }
- },
- { name: 'CollectionViewSystem' },
- ), { runAfter: [SystemLabel.UILayoutLate], runBefore: [SystemLabel.UIRenderOrder] });
-
- this.cleanup_ = () => {
- for (const [, st] of states) {
- for (const item of st.activeItems.values()) {
- if (world.valid(item)) world.despawn(item);
- }
- st.pool.clear(world);
- }
- states.clear();
- this.states_ = null;
- activePlugin = null;
- };
- }
-
- private getLayoutConfig_(world: import('../world').World, entity: Entity, layout: string): unknown {
- switch (layout) {
- case 'linear':
- return world.has(entity, LinearLayout) ? world.get(entity, LinearLayout) : null;
- case 'grid':
- return world.has(entity, GridLayout) ? world.get(entity, GridLayout) : null;
- case 'fan':
- return world.has(entity, FanLayout) ? world.get(entity, FanLayout) : null;
- default:
- return null;
- }
- }
-
- private createItem_(world: import('../world').World, parent: Entity): Entity {
- const item = world.spawn();
- world.insert(item, Name, { value: 'CollectionItem' });
- world.insert(item, UIRect, {
- anchorMin: { x: 0, y: 1 },
- anchorMax: { x: 0, y: 1 },
- offsetMin: { x: 0, y: 0 },
- offsetMax: { x: 0, y: 0 },
- size: { x: 0, y: 0 },
- pivot: { x: 0, y: 1 },
- });
- world.setParent(item, parent);
- return item;
- }
-
- private positionItem_(
- world: import('../world').World,
- entity: Entity,
- result: LayoutResult,
- ): void {
- if (world.has(entity, UIRect)) {
- const rect = world.get(entity, UIRect) as UIRectData;
- rect.size = { x: result.size.x, y: result.size.y };
- world.insert(entity, UIRect, rect);
- }
- if (world.has(entity, Transform)) {
- const t = world.get(entity, Transform) as TransformData;
- t.position.x = result.position.x;
- t.position.y = -result.position.y;
- if (result.rotation !== undefined) {
- const rad = result.rotation * Math.PI / 180;
- t.rotation.z = Math.sin(rad / 2);
- t.rotation.w = Math.cos(rad / 2);
- }
- world.insert(entity, Transform, t);
- }
- }
-
- private hideItem_(world: import('../world').World, entity: Entity): void {
- if (world.has(entity, Transform)) {
- const t = world.get(entity, Transform) as TransformData;
- t.scale = { x: 0, y: 0, z: 0 };
- world.insert(entity, Transform, t);
- }
- }
-
- private showItem_(world: import('../world').World, entity: Entity): void {
- if (world.has(entity, Transform)) {
- const t = world.get(entity, Transform) as TransformData;
- t.scale = { x: 1, y: 1, z: 1 };
- world.insert(entity, Transform, t);
- }
- }
-}
-
-export const collectionViewPlugin = new CollectionViewPlugin();
diff --git a/sdk/src/ui/GridLayoutPlugin.ts b/sdk/src/ui/GridLayoutPlugin.ts
deleted file mode 100644
index 120e040b7..000000000
--- a/sdk/src/ui/GridLayoutPlugin.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import type { App, Plugin } from '../app';
-import { registerComponent } from '../component';
-import { GridLayout } from './layouts/GridLayout';
-import { PluginName } from '../systemLabels';
-
-export class GridLayoutPlugin implements Plugin {
- name = PluginName.GridLayout;
-
- build(_app: App): void {
- registerComponent('GridLayout', GridLayout);
- }
-}
-
-export const gridLayoutPlugin = new GridLayoutPlugin();
diff --git a/sdk/src/ui/ItemPool.ts b/sdk/src/ui/ItemPool.ts
deleted file mode 100644
index f483b64d6..000000000
--- a/sdk/src/ui/ItemPool.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import type { Entity } from '../types';
-import type { World } from '../world';
-
-export class ItemPool {
- private pools_ = new Map<string, Entity[]>();
-
- acquire(type: string = 'default'): Entity | undefined {
- const pool = this.pools_.get(type);
- return pool && pool.length > 0 ? pool.pop()! : undefined;
- }
-
- release(entity: Entity, type: string = 'default'): void {
- let pool = this.pools_.get(type);
- if (!pool) {
- pool = [];
- this.pools_.set(type, pool);
- }
- pool.push(entity);
- }
-
- clear(world: World): void {
- for (const pool of this.pools_.values()) {
- for (const entity of pool) {
- if (world.valid(entity)) {
- world.despawn(entity);
- }
- }
- }
- this.pools_.clear();
- }
-
- get size(): number {
- let total = 0;
- for (const pool of this.pools_.values()) {
- total += pool.length;
- }
- return total;
- }
-}
diff --git a/sdk/src/ui/LayoutProvider.ts b/sdk/src/ui/LayoutProvider.ts
deleted file mode 100644
index 0d859f43a..000000000
--- a/sdk/src/ui/LayoutProvider.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-export interface LayoutResult {
- index: number;
- position: { x: number; y: number };
- size: { x: number; y: number };
- rotation?: number;
-}
-
-export const ScrollAlign = {
- Start: 0,
- Center: 1,
- End: 2,
- Auto: 3,
-} as const;
-export type ScrollAlign = (typeof ScrollAlign)[keyof typeof ScrollAlign];
-
-export interface LayoutProvider {
- getContentSize(
- itemCount: number,
- viewportSize: { x: number; y: number },
- config: unknown,
- ): { width: number; height: number };
-
- getVisibleRange(
- scrollOffset: { x: number; y: number },
- viewportSize: { x: number; y: number },
- itemCount: number,
- overscan: number,
- config: unknown,
- ): LayoutResult[];
-
- getScrollOffsetForIndex(
- index: number,
- viewportSize: { x: number; y: number },
- itemCount: number,
- config: unknown,
- align: ScrollAlign,
- ): { x: number; y: number };
-}
-
-const providerRegistry = new Map<string, LayoutProvider>();
-
-export function registerLayoutProvider(name: string, provider: LayoutProvider): void {
- providerRegistry.set(name, provider);
-}
-
-export function getLayoutProvider(name: string): LayoutProvider | null {
- return providerRegistry.get(name) ?? null;
-}
diff --git a/sdk/src/ui/LinearLayoutPlugin.ts b/sdk/src/ui/LinearLayoutPlugin.ts
deleted file mode 100644
index 4d69f4c42..000000000
--- a/sdk/src/ui/LinearLayoutPlugin.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import type { App, Plugin } from '../app';
-import { registerComponent } from '../component';
-import { LinearLayout } from './layouts/LinearLayout';
-import { PluginName } from '../systemLabels';
-
-export class LinearLayoutPlugin implements Plugin {
- name = PluginName.LinearLayout;
-
- build(_app: App): void {
- registerComponent('LinearLayout', LinearLayout);
- }
-}
-
-export const linearLayoutPlugin = new LinearLayoutPlugin();
diff --git a/sdk/src/ui/UIRenderOrderPlugin.ts b/sdk/src/ui/UIRenderOrderPlugin.ts
index eb48231bb..e977d4d82 100644
--- a/sdk/src/ui/UIRenderOrderPlugin.ts
+++ b/sdk/src/ui/UIRenderOrderPlugin.ts
@@ -9,7 +9,6 @@ export class UIRenderOrderPlugin implements Plugin {
after = [
PluginName.Text, PluginName.Image, PluginName.UIMask,
PluginName.UIInteraction, PluginName.ScrollView,
- PluginName.CollectionView, PluginName.LayoutGroup,
];
build(app: App): void {
diff --git a/sdk/src/ui/index.ts b/sdk/src/ui/index.ts
index e2e2958f7..fc8905593 100644
--- a/sdk/src/ui/index.ts
+++ b/sdk/src/ui/index.ts
@@ -395,52 +395,12 @@ export {
type ResolvedImage,
} from './ImageResolver';
-// Collection View
+// GridLayout (C++-backed ECS component) — canonical in ui2
export {
- CollectionView,
- CollectionItem,
- SelectionMode,
- type CollectionViewData,
- type CollectionItemData,
-} from './CollectionView';
-
-export {
- setCollectionAdapter,
- getCollectionAdapter,
- removeCollectionAdapter,
- type CollectionAdapter,
-} from './CollectionAdapter';
-
-export {
- registerLayoutProvider,
- getLayoutProvider,
- ScrollAlign,
- type LayoutProvider,
- type LayoutResult as CollectionLayoutResult,
-} from './LayoutProvider';
-
-export { ItemPool } from './ItemPool';
-
-export {
- collectionViewPlugin,
- CollectionViewPlugin,
-} from './CollectionViewPlugin';
-
-export {
- collectionGetItemEntity,
- collectionRefreshItems,
- collectionRefreshItem,
- collectionInsertItems,
- collectionRemoveItems,
-} from './CollectionViewAPI';
-
-export { LinearLayout, type LinearLayoutData } from './layouts/LinearLayout';
-export { GridLayout, type GridLayoutData } from './layouts/GridLayout';
-export { LinearLayoutProvider } from './layouts/LinearLayoutProvider';
-export { GridLayoutProvider } from './layouts/GridLayoutProvider';
-
-export { LinearLayoutPlugin, linearLayoutPlugin } from './LinearLayoutPlugin';
-export { GridLayoutPlugin, gridLayoutPlugin } from './GridLayoutPlugin';
+ GridLayout,
+ GridLayoutDirection,
+ type GridLayoutData,
+} from '../ui2/layout/grid';
export const AnimOverride = {
POS_X: 1,
diff --git a/sdk/src/ui/layouts/FanLayout.ts b/sdk/src/ui/layouts/FanLayout.ts
deleted file mode 100644
index d0db2ecdc..000000000
--- a/sdk/src/ui/layouts/FanLayout.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { defineBuiltin } from '../../component';
-
-export interface FanLayoutData {
- radius: number;
- maxSpreadAngle: number;
- maxCardAngle: number;
- tiltFactor: number;
- cardSpacing: number;
- direction: number;
-}
-
-export const FanLayoutDirection = {
- Up: 0,
- Down: 1,
-} as const;
-
-export const FanLayout = defineBuiltin<FanLayoutData>('FanLayout', {
- radius: 600,
- maxSpreadAngle: 30,
- maxCardAngle: 8,
- tiltFactor: 1.0,
- cardSpacing: 0,
- direction: FanLayoutDirection.Up,
-});
diff --git a/sdk/src/ui/layouts/FanLayoutProvider.ts b/sdk/src/ui/layouts/FanLayoutProvider.ts
deleted file mode 100644
index 4a540dae5..000000000
--- a/sdk/src/ui/layouts/FanLayoutProvider.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-import type { LayoutProvider, LayoutResult, ScrollAlign } from '../LayoutProvider';
-import type { FanLayoutData } from './FanLayout';
-
-const DEG_TO_RAD = Math.PI / 180;
-
-export function computeFanPositions(
- itemCount: number,
- config: FanLayoutData,
- excludeIndices?: Set<number>,
-): LayoutResult[] {
- if (itemCount === 0) return [];
-
- const activeIndices: number[] = [];
- for (let i = 0; i < itemCount; i++) {
- if (!excludeIndices?.has(i)) activeIndices.push(i);
- }
- const n = activeIndices.length;
- if (n === 0) return [];
-
- const spreadAngle = Math.min(
- config.maxSpreadAngle,
- (n - 1) * config.maxCardAngle,
- );
- const dirSign = config.direction === 1 ? -1 : 1;
-
- const results: LayoutResult[] = [];
- for (let i = 0; i < n; i++) {
- const t = n === 1 ? 0 : (i / (n - 1) - 0.5);
- const angle = spreadAngle * t * DEG_TO_RAD;
-
- const useFixed = config.cardSpacing > 0 && n > 1;
- const x = useFixed
- ? (i - (n - 1) * 0.5) * config.cardSpacing
- : config.radius * Math.sin(angle);
- const y = config.radius * (1 - Math.cos(angle)) * dirSign;
- const rotation = angle * config.tiltFactor * (180 / Math.PI) * dirSign;
-
- results.push({
- index: activeIndices[i],
- position: { x, y },
- size: { x: 0, y: 0 },
- rotation,
- });
- }
-
- return results;
-}
-
-export class FanLayoutProvider implements LayoutProvider {
- getContentSize(
- itemCount: number,
- _viewportSize: { x: number; y: number },
- config: unknown,
- ): { width: number; height: number } {
- const c = config as FanLayoutData;
- const positions = computeFanPositions(itemCount, c);
- if (positions.length === 0) return { width: 0, height: 0 };
-
- let minX = Infinity, maxX = -Infinity;
- let minY = Infinity, maxY = -Infinity;
- for (const p of positions) {
- if (p.position.x < minX) minX = p.position.x;
- if (p.position.x > maxX) maxX = p.position.x;
- if (p.position.y < minY) minY = p.position.y;
- if (p.position.y > maxY) maxY = p.position.y;
- }
-
- return { width: maxX - minX, height: maxY - minY };
- }
-
- getVisibleRange(
- _scrollOffset: { x: number; y: number },
- _viewportSize: { x: number; y: number },
- itemCount: number,
- _overscan: number,
- config: unknown,
- ): LayoutResult[] {
- return computeFanPositions(itemCount, config as FanLayoutData);
- }
-
- getScrollOffsetForIndex(
- _index: number,
- _viewportSize: { x: number; y: number },
- _itemCount: number,
- _config: unknown,
- _align: ScrollAlign,
- ): { x: number; y: number } {
- return { x: 0, y: 0 };
- }
-}
diff --git a/sdk/src/ui/layouts/GridLayout.ts b/sdk/src/ui/layouts/GridLayout.ts
deleted file mode 100644
index a0792365d..000000000
--- a/sdk/src/ui/layouts/GridLayout.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export {
- GridLayout,
- GridLayoutDirection,
- type GridLayoutData,
-} from '../../ui2/layout/grid';
diff --git a/sdk/src/ui/layouts/GridLayoutProvider.ts b/sdk/src/ui/layouts/GridLayoutProvider.ts
deleted file mode 100644
index 7036cbef6..000000000
--- a/sdk/src/ui/layouts/GridLayoutProvider.ts
+++ /dev/null
@@ -1,119 +0,0 @@
-import { ScrollAlign, type LayoutProvider, type LayoutResult } from '../LayoutProvider';
-import type { GridLayoutData } from './GridLayout';
-
-export class GridLayoutProvider implements LayoutProvider {
- getContentSize(
- itemCount: number,
- viewportSize: { x: number; y: number },
- config: unknown,
- ): { width: number; height: number } {
- const c = config as GridLayoutData;
- if (itemCount === 0) return { width: 0, height: 0 };
- const isVertical = c.direction === 0;
- const cols = isVertical ? Math.min(c.crossAxisCount, itemCount) : Math.ceil(itemCount / c.crossAxisCount);
- const rows = isVertical ? Math.ceil(itemCount / c.crossAxisCount) : Math.min(c.crossAxisCount, itemCount);
-
- return {
- width: cols * c.itemSize.x + Math.max(0, cols - 1) * c.spacing.x,
- height: rows * c.itemSize.y + Math.max(0, rows - 1) * c.spacing.y,
- };
- }
-
- getVisibleRange(
- scrollOffset: { x: number; y: number },
- viewportSize: { x: number; y: number },
- itemCount: number,
- overscan: number,
- config: unknown,
- ): LayoutResult[] {
- if (itemCount === 0) return [];
-
- const c = config as GridLayoutData;
- const isVertical = c.direction === 0;
- const cols = c.crossAxisCount;
- const strideX = c.itemSize.x + c.spacing.x;
- const strideY = c.itemSize.y + c.spacing.y;
-
- if (isVertical) {
- const rowStride = strideY;
- if (rowStride <= 0) return [];
- let startRow = Math.floor(scrollOffset.y / rowStride) - overscan;
- let endRow = Math.ceil((scrollOffset.y + viewportSize.y) / rowStride) + overscan;
- const totalRows = Math.ceil(itemCount / cols);
- startRow = Math.max(0, startRow);
- endRow = Math.min(totalRows - 1, endRow);
-
- const results: LayoutResult[] = [];
- for (let row = startRow; row <= endRow; row++) {
- for (let col = 0; col < cols; col++) {
- const index = row * cols + col;
- if (index >= itemCount) break;
- results.push({
- index,
- position: { x: col * strideX, y: row * strideY },
- size: { x: c.itemSize.x, y: c.itemSize.y },
- });
- }
- }
- return results;
- } else {
- const colStride = strideX;
- if (colStride <= 0) return [];
- let startCol = Math.floor(scrollOffset.x / colStride) - overscan;
- let endCol = Math.ceil((scrollOffset.x + viewportSize.x) / colStride) + overscan;
- const totalCols = Math.ceil(itemCount / cols);
- startCol = Math.max(0, startCol);
- endCol = Math.min(totalCols - 1, endCol);
-
- const results: LayoutResult[] = [];
- for (let col = startCol; col <= endCol; col++) {
- for (let row = 0; row < cols; row++) {
- const index = col * cols + row;
- if (index >= itemCount) break;
- results.push({
- index,
- position: { x: col * strideX, y: row * strideY },
- size: { x: c.itemSize.x, y: c.itemSize.y },
- });
- }
- }
- return results;
- }
- }
-
- getScrollOffsetForIndex(
- index: number,
- viewportSize: { x: number; y: number },
- itemCount: number,
- config: unknown,
- align: ScrollAlign,
- ): { x: number; y: number } {
- const c = config as GridLayoutData;
- const isVertical = c.direction === 0;
- const cols = c.crossAxisCount;
- const strideY = c.itemSize.y + c.spacing.y;
- const strideX = c.itemSize.x + c.spacing.x;
-
- const row = isVertical ? Math.floor(index / cols) : index % cols;
- const col = isVertical ? index % cols : Math.floor(index / cols);
- const itemOffset = isVertical ? row * strideY : col * strideX;
- const itemSize = isVertical ? c.itemSize.y : c.itemSize.x;
- const viewLength = isVertical ? viewportSize.y : viewportSize.x;
-
- let scrollTo: number;
- switch (align) {
- case ScrollAlign.Start: scrollTo = itemOffset; break;
- case ScrollAlign.Center: scrollTo = itemOffset - (viewLength - itemSize) / 2; break;
- case ScrollAlign.End: scrollTo = itemOffset - viewLength + itemSize; break;
- default: scrollTo = itemOffset;
- }
-
- const contentSize = this.getContentSize(itemCount, viewportSize, config);
- const maxScroll = isVertical
- ? Math.max(0, contentSize.height - viewLength)
- : Math.max(0, contentSize.width - viewLength);
- scrollTo = Math.max(0, Math.min(scrollTo, maxScroll));
-
- return isVertical ? { x: 0, y: scrollTo } : { x: scrollTo, y: 0 };
- }
-}
diff --git a/sdk/src/ui/layouts/LinearLayout.ts b/sdk/src/ui/layouts/LinearLayout.ts
deleted file mode 100644
index 03abfa153..000000000
--- a/sdk/src/ui/layouts/LinearLayout.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { defineComponent } from '../../component';
-
-export interface LinearLayoutData {
- direction: number; // 0=Horizontal, 1=Vertical (matches LayoutGroup)
- itemSize: number;
- spacing: number;
- reverseOrder: boolean;
-}
-
-export const LinearLayout = defineComponent<LinearLayoutData>('LinearLayout', {
- direction: 1, // Vertical
- itemSize: 40,
- spacing: 0,
- reverseOrder: false,
-});
diff --git a/sdk/src/ui/layouts/LinearLayoutProvider.ts b/sdk/src/ui/layouts/LinearLayoutProvider.ts
deleted file mode 100644
index dafcb2966..000000000
--- a/sdk/src/ui/layouts/LinearLayoutProvider.ts
+++ /dev/null
@@ -1,114 +0,0 @@
-import { ScrollAlign, type LayoutProvider, type LayoutResult } from '../LayoutProvider';
-import type { LinearLayoutData } from './LinearLayout';
-
-export class LinearLayoutProvider implements LayoutProvider {
- getContentSize(
- itemCount: number,
- viewportSize: { x: number; y: number },
- config: unknown,
- ): { width: number; height: number } {
- const c = config as LinearLayoutData;
- const isVertical = c.direction === 1;
- const totalLength = itemCount > 0
- ? itemCount * c.itemSize + (itemCount - 1) * c.spacing
- : 0;
- return isVertical
- ? { width: viewportSize.x, height: totalLength }
- : { width: totalLength, height: viewportSize.y };
- }
-
- getVisibleRange(
- scrollOffset: { x: number; y: number },
- viewportSize: { x: number; y: number },
- itemCount: number,
- overscan: number,
- config: unknown,
- ): LayoutResult[] {
- if (itemCount === 0) return [];
-
- const c = config as LinearLayoutData;
- const isVertical = c.direction === 1;
- const stride = c.itemSize + c.spacing;
- if (stride <= 0) return [];
-
- const scroll = isVertical ? scrollOffset.y : scrollOffset.x;
- const viewLength = isVertical ? viewportSize.y : viewportSize.x;
-
- let startIdx = Math.floor(scroll / stride) - overscan;
- let endIdx = Math.ceil((scroll + viewLength) / stride) + overscan;
- startIdx = Math.max(0, startIdx);
- endIdx = Math.min(itemCount - 1, endIdx);
-
- if (c.reverseOrder) {
- const results: LayoutResult[] = [];
- for (let i = startIdx; i <= endIdx; i++) {
- const reversed = itemCount - 1 - i;
- const offset = i * stride;
- results.push({
- index: reversed,
- position: isVertical
- ? { x: 0, y: offset }
- : { x: offset, y: 0 },
- size: isVertical
- ? { x: viewportSize.x, y: c.itemSize }
- : { x: c.itemSize, y: viewportSize.y },
- });
- }
- return results;
- }
-
- const results: LayoutResult[] = [];
- for (let i = startIdx; i <= endIdx; i++) {
- const offset = i * stride;
- results.push({
- index: i,
- position: isVertical
- ? { x: 0, y: offset }
- : { x: offset, y: 0 },
- size: isVertical
- ? { x: viewportSize.x, y: c.itemSize }
- : { x: c.itemSize, y: viewportSize.y },
- });
- }
- return results;
- }
-
- getScrollOffsetForIndex(
- index: number,
- viewportSize: { x: number; y: number },
- itemCount: number,
- config: unknown,
- align: ScrollAlign,
- ): { x: number; y: number } {
- const c = config as LinearLayoutData;
- const isVertical = c.direction === 1;
- const stride = c.itemSize + c.spacing;
- const targetIdx = c.reverseOrder ? itemCount - 1 - index : index;
- const itemOffset = targetIdx * stride;
- const viewLength = isVertical ? viewportSize.y : viewportSize.x;
-
- let scrollTo: number;
- switch (align) {
- case ScrollAlign.Start:
- scrollTo = itemOffset;
- break;
- case ScrollAlign.Center:
- scrollTo = itemOffset - (viewLength - c.itemSize) / 2;
- break;
- case ScrollAlign.End:
- scrollTo = itemOffset - viewLength + c.itemSize;
- break;
- case ScrollAlign.Auto:
- default:
- scrollTo = itemOffset;
- }
-
- const contentLength = this.getContentSize(itemCount, viewportSize, config);
- const maxScroll = isVertical
- ? Math.max(0, contentLength.height - viewLength)
- : Math.max(0, contentLength.width - viewLength);
- scrollTo = Math.max(0, Math.min(scrollTo, maxScroll));
-
- return isVertical ? { x: 0, y: scrollTo } : { x: scrollTo, y: 0 };
- }
-}
diff --git a/sdk/src/uiPlugins.ts b/sdk/src/uiPlugins.ts
index 9593fb4dc..f9f5f1854 100644
--- a/sdk/src/uiPlugins.ts
+++ b/sdk/src/uiPlugins.ts
@@ -14,9 +14,6 @@ import { safeAreaPlugin } from './ui/SafeAreaPlugin';
import { dropdownPlugin } from './ui/DropdownPlugin';
import { uiRenderOrderPlugin } from './ui/UIRenderOrderPlugin';
import { stateMachinePlugin } from './ui/StateMachinePlugin';
-import { collectionViewPlugin } from './ui/CollectionViewPlugin';
-import { linearLayoutPlugin } from './ui/LinearLayoutPlugin';
-import { gridLayoutPlugin } from './ui/GridLayoutPlugin';
import type { Plugin } from './app';
export const uiPlugins: Plugin[] = [
@@ -25,7 +22,5 @@ export const uiPlugins: Plugin[] = [
uiInteractionPlugin, dragPlugin, scrollViewPlugin, sliderPlugin,
togglePlugin, textInputPlugin, stateMachinePlugin,
focusPlugin, safeAreaPlugin, dropdownPlugin,
- collectionViewPlugin,
- linearLayoutPlugin, gridLayoutPlugin,
uiRenderOrderPlugin,
];
diff --git a/sdk/tests/FanLayoutProvider.test.ts b/sdk/tests/FanLayoutProvider.test.ts
deleted file mode 100644
index 19fd39380..000000000
--- a/sdk/tests/FanLayoutProvider.test.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import { describe, it, expect } from 'vitest';
-import { FanLayoutProvider, computeFanPositions } from '../src/ui/layouts/FanLayoutProvider';
-import type { FanLayoutData } from '../src/ui/layouts/FanLayout';
-
-const defaults: FanLayoutData = {
- radius: 600,
- maxSpreadAngle: 30,
- maxCardAngle: 8,
- tiltFactor: 1,
- cardSpacing: 0,
- direction: 0,
-};
-
-describe('computeFanPositions', () => {
- it('single card is centered', () => {
- const results = computeFanPositions(1, defaults);
- expect(results).toHaveLength(1);
- expect(results[0].position.x).toBeCloseTo(0);
- expect(results[0].position.y).toBeCloseTo(0);
- expect(results[0].rotation).toBeCloseTo(0);
- });
-
- it('cards are symmetric', () => {
- const results = computeFanPositions(5, defaults);
- expect(results).toHaveLength(5);
- expect(results[0].position.x).toBeCloseTo(-results[4].position.x, 5);
- expect(results[0].position.y).toBeCloseTo(results[4].position.y, 5);
- expect(results[2].position.x).toBeCloseTo(0, 5);
- });
-
- it('spread is capped by maxSpreadAngle', () => {
- const results = computeFanPositions(3, { ...defaults, maxSpreadAngle: 10, maxCardAngle: 20 });
- const leftX = results[0].position.x;
- const rightX = results[2].position.x;
- const maxResults = computeFanPositions(3, { ...defaults, maxSpreadAngle: 10 });
- expect(Math.abs(rightX - leftX)).toBeCloseTo(Math.abs(maxResults[2].position.x - maxResults[0].position.x), 3);
- });
-
- it('spread is capped by maxCardAngle', () => {
- const results = computeFanPositions(3, { ...defaults, maxSpreadAngle: 100, maxCardAngle: 5 });
- const spread = Math.abs(results[2].position.x - results[0].position.x);
- const wideResults = computeFanPositions(3, { ...defaults, maxSpreadAngle: 100, maxCardAngle: 50 });
- expect(spread).toBeLessThan(Math.abs(wideResults[2].position.x - wideResults[0].position.x));
- });
-
- it('direction=down flips Y', () => {
- const upResults = computeFanPositions(5, { ...defaults, direction: 0 });
- const downResults = computeFanPositions(5, { ...defaults, direction: 1 });
- expect(upResults[0].position.y).toBeGreaterThanOrEqual(0);
- expect(downResults[0].position.y).toBeLessThanOrEqual(0);
- });
-
- it('excludeIndices removes cards', () => {
- const results = computeFanPositions(5, defaults, new Set([1, 3]));
- expect(results).toHaveLength(3);
- expect(results.map(r => r.index)).toEqual([0, 2, 4]);
- });
-
- it('tiltFactor=0 means no rotation', () => {
- const results = computeFanPositions(5, { ...defaults, tiltFactor: 0 });
- for (const r of results) {
- expect(r.rotation).toBeCloseTo(0);
- }
- });
-
- it('returns empty for zero items', () => {
- expect(computeFanPositions(0, defaults)).toEqual([]);
- });
-});
-
-describe('FanLayoutProvider', () => {
- const provider = new FanLayoutProvider();
-
- it('getVisibleRange returns all items (no virtual scroll)', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 800, y: 600 }, 7, 0, defaults,
- );
- expect(results).toHaveLength(7);
- });
-
- it('getScrollOffsetForIndex always returns zero', () => {
- expect(provider.getScrollOffsetForIndex(3, { x: 800, y: 600 }, 7, defaults, 0)).toEqual({ x: 0, y: 0 });
- });
-});
diff --git a/sdk/tests/GridLayoutProvider.test.ts b/sdk/tests/GridLayoutProvider.test.ts
deleted file mode 100644
index 72d6f4823..000000000
--- a/sdk/tests/GridLayoutProvider.test.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { describe, it, expect } from 'vitest';
-import { GridLayoutProvider } from '../src/ui/layouts/GridLayoutProvider';
-import type { GridLayoutData } from '../src/ui/layouts/GridLayout';
-
-const provider = new GridLayoutProvider();
-
-function vGrid(cols = 3, itemW = 100, itemH = 100, spX = 4, spY = 4): GridLayoutData {
- return { direction: 0, crossAxisCount: cols, itemSize: { x: itemW, y: itemH }, spacing: { x: spX, y: spY } };
-}
-
-describe('GridLayoutProvider', () => {
- describe('getContentSize', () => {
- it('calculates vertical grid size', () => {
- const size = provider.getContentSize(10, { x: 400, y: 400 }, vGrid(3, 100, 100, 4, 4));
- expect(size.width).toBe(3 * 100 + 2 * 4);
- expect(size.height).toBe(4 * 100 + 3 * 4);
- });
-
- it('handles exact fill', () => {
- const size = provider.getContentSize(9, { x: 400, y: 400 }, vGrid(3, 100, 100, 0, 0));
- expect(size).toEqual({ width: 300, height: 300 });
- });
-
- it('handles empty', () => {
- const size = provider.getContentSize(0, { x: 400, y: 400 }, vGrid());
- expect(size).toEqual({ width: 0, height: 0 });
- });
- });
-
- describe('getVisibleRange', () => {
- it('returns items in visible rows', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 400, y: 200 }, 12, 0, vGrid(3, 100, 100, 0, 0),
- );
- const indices = results.map(r => r.index);
- expect(indices).toContain(0);
- expect(indices).toContain(1);
- expect(indices).toContain(2);
- expect(indices).toContain(3);
- expect(indices).toContain(4);
- expect(indices).toContain(5);
- });
-
- it('positions items in grid pattern', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 400, y: 400 }, 9, 0, vGrid(3, 100, 100, 10, 10),
- );
- const item0 = results.find(r => r.index === 0)!;
- const item1 = results.find(r => r.index === 1)!;
- const item3 = results.find(r => r.index === 3)!;
- expect(item0.position).toEqual({ x: 0, y: 0 });
- expect(item1.position).toEqual({ x: 110, y: 0 });
- expect(item3.position).toEqual({ x: 0, y: 110 });
- });
-
- it('returns empty for zero items', () => {
- expect(provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 400, y: 400 }, 0, 0, vGrid(),
- )).toEqual([]);
- });
-
- it('clamps to item count', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 400, y: 10000 }, 5, 0, vGrid(3),
- );
- expect(results.length).toBe(5);
- });
- });
-
- describe('getScrollOffsetForIndex', () => {
- it('scrolls to row containing index', () => {
- const offset = provider.getScrollOffsetForIndex(6, { x: 400, y: 200 }, 12, vGrid(3, 100, 100, 0, 0), 0);
- expect(offset.y).toBe(200);
- });
- });
-});
diff --git a/sdk/tests/LinearLayoutProvider.test.ts b/sdk/tests/LinearLayoutProvider.test.ts
deleted file mode 100644
index 254514a9e..000000000
--- a/sdk/tests/LinearLayoutProvider.test.ts
+++ /dev/null
@@ -1,133 +0,0 @@
-import { describe, it, expect } from 'vitest';
-import { LinearLayoutProvider } from '../src/ui/layouts/LinearLayoutProvider';
-import type { LinearLayoutData } from '../src/ui/layouts/LinearLayout';
-
-const provider = new LinearLayoutProvider();
-
-function vConfig(itemSize = 40, spacing = 0, reverse = false): LinearLayoutData {
- return { direction: 1, itemSize, spacing, reverseOrder: reverse };
-}
-
-function hConfig(itemSize = 40, spacing = 0, reverse = false): LinearLayoutData {
- return { direction: 0, itemSize, spacing, reverseOrder: reverse };
-}
-
-const viewport = { x: 300, y: 400 };
-
-describe('LinearLayoutProvider', () => {
- describe('getContentSize', () => {
- it('calculates vertical content size', () => {
- const size = provider.getContentSize(10, viewport, vConfig(40, 4));
- expect(size).toEqual({ width: 300, height: 10 * 40 + 9 * 4 });
- });
-
- it('calculates horizontal content size', () => {
- const size = provider.getContentSize(5, viewport, hConfig(60, 10));
- expect(size).toEqual({ width: 5 * 60 + 4 * 10, height: 400 });
- });
-
- it('returns zero for empty list', () => {
- const size = provider.getContentSize(0, viewport, vConfig());
- expect(size).toEqual({ width: 300, height: 0 });
- });
-
- it('single item has no spacing', () => {
- const size = provider.getContentSize(1, viewport, vConfig(50, 10));
- expect(size).toEqual({ width: 300, height: 50 });
- });
- });
-
- describe('getVisibleRange', () => {
- it('returns items within viewport', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 300, y: 120 }, 100, 0, vConfig(40),
- );
- expect(results.length).toBeGreaterThanOrEqual(3);
- expect(results[0]).toEqual({ index: 0, position: { x: 0, y: 0 }, size: { x: 300, y: 40 } });
- expect(results[1]).toEqual({ index: 1, position: { x: 0, y: 40 }, size: { x: 300, y: 40 } });
- expect(results[2]).toEqual({ index: 2, position: { x: 0, y: 80 }, size: { x: 300, y: 40 } });
- });
-
- it('accounts for scroll offset', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 80 }, { x: 300, y: 100 }, 100, 0, vConfig(40),
- );
- expect(results[0].index).toBe(2);
- });
-
- it('includes overscan', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 80 }, { x: 300, y: 100 }, 100, 1, vConfig(40),
- );
- expect(results[0].index).toBe(1);
- expect(results[results.length - 1].index).toBe(6);
- });
-
- it('clamps to item count', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 300, y: 10000 }, 5, 0, vConfig(40),
- );
- expect(results.length).toBe(5);
- });
-
- it('handles horizontal direction', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 100, y: 300 }, 10, 0, hConfig(50),
- );
- expect(results[0].position).toEqual({ x: 0, y: 0 });
- expect(results[0].size).toEqual({ x: 50, y: 300 });
- });
-
- it('handles reverse order', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 300, y: 100 }, 10, 0, vConfig(40, 0, true),
- );
- expect(results[0].index).toBe(9);
- expect(results[1].index).toBe(8);
- });
-
- it('returns empty for zero items', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 300, y: 100 }, 0, 0, vConfig(),
- );
- expect(results).toEqual([]);
- });
-
- it('accounts for spacing in positions', () => {
- const results = provider.getVisibleRange(
- { x: 0, y: 0 }, { x: 300, y: 200 }, 10, 0, vConfig(40, 10),
- );
- expect(results[0].position.y).toBe(0);
- expect(results[1].position.y).toBe(50);
- expect(results[2].position.y).toBe(100);
- });
- });
-
- describe('getScrollOffsetForIndex', () => {
- it('scrolls to start alignment', () => {
- const offset = provider.getScrollOffsetForIndex(5, viewport, 100, vConfig(40), 0);
- expect(offset).toEqual({ x: 0, y: 200 });
- });
-
- it('scrolls to center alignment', () => {
- const offset = provider.getScrollOffsetForIndex(50, viewport, 100, vConfig(40), 1);
- expect(offset.y).toBe(50 * 40 - (400 - 40) / 2);
- });
-
- it('scrolls to end alignment', () => {
- const offset = provider.getScrollOffsetForIndex(50, viewport, 100, vConfig(40), 2);
- expect(offset.y).toBe(50 * 40 - 400 + 40);
- });
-
- it('clamps to zero', () => {
- const offset = provider.getScrollOffsetForIndex(0, viewport, 100, vConfig(40), 1);
- expect(offset.y).toBe(0);
- });
-
- it('clamps to max scroll', () => {
- const offset = provider.getScrollOffsetForIndex(99, viewport, 100, vConfig(40), 0);
- const maxScroll = 100 * 40 - 400;
- expect(offset.y).toBe(maxScroll);
- });
- });
-});