Skip to content

Commit

Permalink
feat: 🎸 re-export conditional types for options and objects
Browse files Browse the repository at this point in the history
Conditional types that were created for finding the appropriate type for
specific animation or shape type are re-exported from the slide now
  • Loading branch information
ghaiklor committed Apr 20, 2020
1 parent b621c43 commit bdcaafe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
18 changes: 10 additions & 8 deletions packages/kittik-slide/src/slide/Slide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ import { SlideDeclaration } from './SlideDeclaration';

export { AnimationBuilder } from '../animation/AnimationBuilder';
export { AnimationDeclaration } from '../animation/AnimationDeclaration';
export { AnimationType } from '../animation/Animations';
export { AnimationType, AnimationObject, AnimationOptions } from '../animation/Animations';
export { OrderDeclaration } from './OrderDeclaration';
export { ShapeBuilder } from '../shape/ShapeBuilder';
export { ShapeDeclaration } from '../shape/ShapeDeclaration';
export { ShapeType } from '../shape/Shapes';
export { ShapeType, ShapeObject, ShapeOptions } from '../shape/Shapes';
export { SlideBuilder } from './SlideBuilder';
export { SlideDeclaration } from './SlideDeclaration';

export class Slide {
public canvas: Canvas = Canvas.create();
export class Slide<
C extends Canvas = Canvas
> {
public canvas: C = Canvas.create() as C;
public name = 'Untitled Slide';
public readonly shapes: Map<string, ShapeRenderable> = new Map<string, ShapeRenderable>();
public readonly animations: Map<string, Animationable> = new Map<string, Animationable>();
public readonly order: OrderDeclaration[] = [];

public constructor (canvas?: Canvas, declaration?: SlideDeclaration) {
public constructor (canvas?: C, declaration?: SlideDeclaration) {
if (typeof canvas !== 'undefined') {
this.canvas = canvas;
}
Expand All @@ -47,15 +49,15 @@ export class Slide {
}
}

public static create (canvas?: Canvas, declaration?: SlideDeclaration): Slide {
public static create <C extends Canvas>(canvas?: C, declaration?: SlideDeclaration): Slide<C> {
return new this(canvas, declaration);
}

public static fromObject (obj: SlideDeclaration, canvas?: Canvas): Slide {
public static fromObject <C extends Canvas>(obj: SlideDeclaration, canvas?: C): Slide<C> {
return this.create(canvas, obj);
}

public static fromJSON (json: string, canvas?: Canvas): Slide {
public static fromJSON <C extends Canvas>(json: string, canvas?: C): Slide<C> {
return this.fromObject(JSON.parse(json), canvas);
}

Expand Down
15 changes: 5 additions & 10 deletions packages/kittik-slide/src/slide/SlideBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,39 @@ import { Canvas } from 'terminal-canvas';
import { ShapeRenderable } from 'kittik-shape-basic';
import { Slide } from './Slide';

export class SlideBuilder {
private readonly slide: Slide = new Slide();
export class SlideBuilder<C extends Canvas> {
private readonly slide: Slide<C> = new Slide();

public static start (): SlideBuilder {
public static start <C extends Canvas>(): SlideBuilder<C> {
return new this();
}

public withName (name: string): this {
this.slide.name = name;

return this;
}

public withCanvas (canvas: Readonly<Canvas>): this {
public withCanvas (canvas: Readonly<C>): this {
this.slide.canvas = canvas;

return this;
}

public withShape (name: string, shape: ShapeRenderable): this {
this.slide.addShape(name, shape);

return this;
}

public withAnimation (name: string, animation: Animationable): this {
this.slide.addAnimation(name, animation);

return this;
}

public withOrder (shape: string, animations?: string[]): this {
this.slide.addOrder(shape, animations);

return this;
}

public end (): Slide {
public end (): Slide<C> {
return this.slide;
}
}

0 comments on commit bdcaafe

Please sign in to comment.