|
1 |
| -import { SHAPES, ShapeType } from './Shapes'; |
2 |
| -import { ShapeObject, ShapeOptions, ShapeRenderable } from 'kittik-shape-basic'; |
| 1 | +import { SHAPES, ShapeOptions, ShapeType } from './Shapes'; |
| 2 | +import { ShapeObject, ShapeRenderable } from 'kittik-shape-basic'; |
3 | 3 |
|
4 |
| -export class ShapeBuilder implements ShapeObject { |
5 |
| - public type: ShapeType; |
6 |
| - public options?: Partial<ShapeOptions>; |
| 4 | +export class ShapeBuilder<T extends ShapeType, O extends ShapeOptions<T>> implements ShapeObject { |
| 5 | + public type: T; |
| 6 | + public options: Partial<O>; |
7 | 7 |
|
8 |
| - public constructor (type: ShapeType) { |
| 8 | + public constructor (type: T) { |
9 | 9 | this.type = type;
|
| 10 | + this.options = {}; |
10 | 11 | }
|
11 | 12 |
|
12 |
| - public static start (type: ShapeType): ShapeBuilder { |
| 13 | + public static start <T extends ShapeType, O extends ShapeOptions<T>>(type: T): ShapeBuilder<T, O> { |
13 | 14 | return new this(type);
|
14 | 15 | }
|
15 | 16 |
|
16 |
| - public withType (type: ShapeType): this { |
| 17 | + public withType (type: T): this { |
17 | 18 | this.type = type;
|
18 |
| - |
19 | 19 | return this;
|
20 | 20 | }
|
21 | 21 |
|
22 |
| - public withOptions (options: Partial<ShapeOptions>): this { |
| 22 | + public withOptions (options: Partial<O>): this { |
23 | 23 | this.options = { ...this.options, ...options };
|
24 |
| - |
25 | 24 | return this;
|
26 | 25 | }
|
27 | 26 |
|
28 |
| - public withText (text: string): this { |
29 |
| - this.options = { ...this.options, text }; |
30 |
| - |
| 27 | + public withText (text: O['text']): this { |
| 28 | + this.options.text = text; |
31 | 29 | return this;
|
32 | 30 | }
|
33 | 31 |
|
34 |
| - public withX (x: string): this { |
35 |
| - this.options = { ...this.options, x }; |
36 |
| - |
| 32 | + public withX (x: O['x']): this { |
| 33 | + this.options.x = x; |
37 | 34 | return this;
|
38 | 35 | }
|
39 | 36 |
|
40 |
| - public withY (y: string): this { |
41 |
| - this.options = { ...this.options, y }; |
42 |
| - |
| 37 | + public withY (y: O['y']): this { |
| 38 | + this.options.y = y; |
43 | 39 | return this;
|
44 | 40 | }
|
45 | 41 |
|
46 |
| - public withWidth (width: string): this { |
47 |
| - this.options = { ...this.options, width }; |
48 |
| - |
| 42 | + public withWidth (width: O['width']): this { |
| 43 | + this.options.width = width; |
49 | 44 | return this;
|
50 | 45 | }
|
51 | 46 |
|
52 |
| - public withHeight (height: string): this { |
53 |
| - this.options = { ...this.options, height }; |
54 |
| - |
| 47 | + public withHeight (height: O['height']): this { |
| 48 | + this.options.height = height; |
55 | 49 | return this;
|
56 | 50 | }
|
57 | 51 |
|
58 |
| - public withBackground (background: string): this { |
59 |
| - this.options = { ...this.options, background }; |
60 |
| - |
| 52 | + public withBackground (background: O['background']): this { |
| 53 | + this.options.background = background; |
61 | 54 | return this;
|
62 | 55 | }
|
63 | 56 |
|
64 |
| - public withForeground (foreground: string): this { |
65 |
| - this.options = { ...this.options, foreground }; |
66 |
| - |
| 57 | + public withForeground (foreground: O['foreground']): this { |
| 58 | + this.options.foreground = foreground; |
67 | 59 | return this;
|
68 | 60 | }
|
69 | 61 |
|
|
0 commit comments