33import type {
44 ComponentConstructorArguments ,
55 ComponentInterface ,
6+ ComponentLevels ,
67 ComponentRenderArguments ,
78} from '#lib/core/components/interfaces' ;
89import { Logger } from '#lib/logger' ;
@@ -11,46 +12,65 @@ import componentUtils from '#lib/core/components/utils/index';
1112
1213/** Incorporates the constructor arguments into itself. */
1314const Base = class Component implements ComponentConstructorArguments {
14- /** Utils related to components and their workings. */
15- // eslint-disable-next-line @typescript-eslint/naming-convention
16- public static readonly utils = Object . freeze ( { ...componentUtils } ) ;
17-
18- /** The levels of certain components. Used for selectors: `slyde-component[level=1]`. */
19- // eslint-disable-next-line @typescript-eslint/naming-convention
20- public static readonly level = Object . freeze ( {
21- /** The level at which the blocks can be placed. */
22- block : 2 ,
23- /** The level at which the presentation can be placed. */
24- presentation : 0 ,
25- /** The level at which the slides can be placed. */
26- slide : 1 ,
27- } ) ;
28-
29- public readonly name ;
30- public readonly attributes ;
31- public readonly focusMode ;
32- public readonly level ;
33- public readonly path ;
34- public readonly id ;
15+ readonly #name;
16+ readonly #attributes;
17+ readonly #focusMode;
18+ readonly #level;
19+ readonly #path;
20+ readonly #id;
3521
3622 /**
3723 * Creates a new `Component` from the arguments provided.
3824 */
3925 public constructor ( args : ComponentConstructorArguments ) {
40- this . name = new . target . name ;
4126 Logger . debug ( `constructing ${ new . target . name } at ${ args . path } ` ) ;
42- this . attributes = args . attributes ;
43- this . focusMode = args . focusMode ;
44- this . level = args . level ;
45- this . path = args . path ;
46- this . id = args . id ;
27+ this . #name = new . target . name ;
28+ this . #attributes = args . attributes ;
29+ this . #focusMode = args . focusMode ;
30+ this . #level = args . level ;
31+ this . #path = args . path ;
32+ this . #id = args . id ;
33+ }
34+
35+ /** Utils related to components and their workings. */
36+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
37+ public static get utils ( ) {
38+ return Object . freeze ( { ...componentUtils } ) ;
39+ }
40+
41+ /** The levels of certain components. Used for selectors: `slyde-component[level=1]`. */
42+ public static get level ( ) : ComponentLevels {
43+ return Object . freeze ( { block : 2 , presentation : 0 , slide : 1 } ) ;
44+ }
45+
46+ public get name ( ) : ComponentInterface [ 'name' ] {
47+ return this . #name;
48+ }
49+
50+ public get attributes ( ) : ComponentInterface [ 'attributes' ] {
51+ return this . #attributes;
52+ }
53+
54+ public get focusMode ( ) : ComponentInterface [ 'focusMode' ] {
55+ return this . #focusMode;
56+ }
57+
58+ public get level ( ) : ComponentInterface [ 'level' ] {
59+ return this . #level;
60+ }
61+
62+ public get path ( ) : ComponentInterface [ 'path' ] {
63+ return this . #path;
64+ }
65+
66+ public get id ( ) : ComponentInterface [ 'id' ] {
67+ return this . #id;
4768 }
4869} ;
4970
5071/** The `Component` base class before the registry is injected. */
5172abstract class Component extends Base implements ComponentInterface {
52- /** The width of this component. */
53- public readonly width = Component . utils . extract ( {
73+ readonly #width = Component . utils . extract ( {
5474 aliases : [ 'width' , 'w' ] ,
5575 context : this ,
5676 transform ( value , context , key ) {
@@ -61,8 +81,7 @@ abstract class Component extends Base implements ComponentInterface {
6181 } ,
6282 } ) ;
6383
64- /** The height of this component. */
65- public readonly height = Component . utils . extract ( {
84+ readonly #height = Component . utils . extract ( {
6685 aliases : [ 'height' , 'h' ] ,
6786 context : this ,
6887 transform ( value , context , key ) {
@@ -73,8 +92,7 @@ abstract class Component extends Base implements ComponentInterface {
7392 } ,
7493 } ) ;
7594
76- /** The maner of displaying this component. */
77- public readonly display = Component . utils . extract ( {
95+ readonly #display = Component . utils . extract ( {
7896 aliases : [ 'display' , 'd' ] ,
7997 context : this ,
8098 fallback : 'block' ,
@@ -96,8 +114,20 @@ abstract class Component extends Base implements ComponentInterface {
96114 }
97115 }
98116
117+ public get width ( ) : string | undefined {
118+ return this . #width;
119+ }
120+
121+ public get height ( ) : string | undefined {
122+ return this . #height;
123+ }
124+
125+ public get display ( ) : string {
126+ return this . #display;
127+ }
128+
99129 public canBeAtLevel ( level : number ) : ReturnType < ComponentInterface [ 'canBeAtLevel' ] > {
100- const hierarchy = ( this as Partial < Pick < this, 'hierarchy' > > ) . hierarchy ?.( ) ?? '*' ;
130+ const hierarchy = ( this as Partial < this> ) . hierarchy ?.( ) ?? '*' ;
101131 if ( hierarchy === '*' ) return true ;
102132 if ( hierarchy . includes ( level ) ) return true ;
103133
@@ -131,6 +161,9 @@ declare namespace ComponentWithRegistry {
131161 /** The type for an instance of a `MarkupRenderer`. */
132162 export type Instance = Component ;
133163
164+ /** The levels at which certain types of components live. */
165+ export type Levels = ComponentLevels ;
166+
134167 /**
135168 * The arguments to provide to the constructor of a component.
136169 */
0 commit comments