Skip to content

Commit

Permalink
refactor(core): manager, renderer api (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 8, 2024
1 parent 9632b9f commit 0d5292c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
29 changes: 29 additions & 0 deletions packages/core/src/api/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IComment } from '@api/comment.js';

export interface CCLOptions {
global: {
scale: number;
opacity: number;
className: string;
};
scroll: {
scale: number;
opacity: number;
};
// scripting: {
// mode: Array<number>;
// engine: IScriptingEngine;
// };
}

export interface ICommentManager {
stage: HTMLElement;
width: number;
height: number;
options: CCLOptions;
start(): void;
stop(): void;
clear(): void;
setBounds(w?: number, h?: number): void;
finish(c: IComment): void;
}
7 changes: 7 additions & 0 deletions packages/core/src/api/renderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IComment } from '@api/comment.js';

export interface ISpaceAllocator {
add(c: IComment): void;
remove(c: IComment): void;
setBounds(w: number, h: number): void;
}
38 changes: 3 additions & 35 deletions packages/core/src/comment/manager.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
import { CommentData, CommentType, IComment } from '@api/comment.js';
import { ICommentFilter } from '@api/filter.js';
import { ICommentManager } from '@api/manager.js';
import { ICommentPreprocessor } from '@api/preprocessor.js';
import { ISpaceAllocator } from '@api/renderer.js';
import { binarySearch, insertByBinarySearch } from '@utils/array.js';
import { calcVideoRenderedSize } from '@utils/video.js';
import { commentComparator } from 'comment/utils.js';
import {
AnchorSpaceAllocator,
ISpaceAllocator,
SpaceAllocator,
} from 'renderer/allocator.js';
import { AnchorSpaceAllocator, SpaceAllocator } from 'renderer/allocator.js';
import { CommentFactory, ICommentFactory } from 'renderer/factory.js';

interface CCLOptions {
global: {
scale: number;
opacity: number;
className: string;
};
scroll: {
scale: number;
opacity: number;
};
// scripting: {
// mode: Array<number>;
// engine: IScriptingEngine;
// };
}

export interface ICommentManager {
stage: HTMLElement;
width: number;
height: number;
options: CCLOptions;
start(): void;
stop(): void;
clear(): void;
setBounds(w?: number, h?: number): void;
finish(c: IComment): void;
}

// ========================================================================== //

export class CommentManager implements ICommentManager {
readonly stage: HTMLElement;
private timer = 0;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from '@api/comment.js';
export * from '@api/filter.js';
export * from '@api/manager.js';
export * from '@api/preprocessor.js';
export * from '@api/renderer.js';
export * from '@api/types.js';

export * from 'comment/manager.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/renderer/allocator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { IComment } from '@api/comment.js';
import { ISpaceAllocator } from '@api/renderer.js';
import { insertByBinarySearch } from '@utils/array.js';

export interface ISpaceAllocator {
add(c: IComment): void;
remove(c: IComment): void;
setBounds(w: number, h: number): void;
}

export class SpaceAllocator implements ISpaceAllocator {
public width: number;
public height: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/renderer/classic/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
IMotion,
MotionRecord,
} from '@api/comment.js';
import { ICommentManager } from '@api/manager.js';
import { Tuple } from '@api/types.js';
import { Matrix3D } from '@utils/matrix3d.js';
import { ICommentManager } from 'comment/manager.js';

const linearEasing = (t: number, b: number, c: number, d: number) => {
return (t * c) / d + b;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/renderer/classic/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommentData, IComment } from '@api/comment.js';
import { ICommentManager } from 'comment/manager.js';
import { ICommentManager } from '@api/manager.js';
import { CoreComment } from 'renderer/classic/base.js';

export class ScrollComment extends CoreComment {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/renderer/factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommentData, CommentType, IComment } from '@api/comment.js';
import { ICommentManager } from '@api/manager.js';
import { Matrix3D } from '@utils/matrix3d.js';
import { ICommentManager } from 'comment/manager.js';
import { CoreComment } from 'renderer/classic/base.js';
import { ScrollComment } from 'renderer/classic/scroll.js';
import { CssScrollComment } from 'renderer/css/scroll.js';
Expand Down

0 comments on commit 0d5292c

Please sign in to comment.